verse-lab / hippodrome Goto Github PK
View Code? Open in Web Editor NEWAn automatic program repair tool for data races in Java programs.
An automatic program repair tool for data races in Java programs.
For a bug (snapshot, stmt_{from}, stmt_{to}), regenerate the update snapshot corresponding to stmt_{to} and just check the deadlock locally instead of calling infer all over again.
Error: No patch could be generated for attempt ID
linkedlist/MyLinkedList.java:49: warning: Thread Safety Violation 2
Read/Write race. Non-private method MyLinkedList.insert(...)
reads with synchronization from p._current._next
. Potentially races with unsynchronized write in method MyLinkedList.insert(...)
.
Reporting because this access may occur on a background thread.
47. // Delete the synch block for the unsynch case
48. synchronized (this) {
49. > tmp = new MyListNode(x, p._current._next);
50. } // Extend the synch block one stmt to eliminate the bug
51. p._current._next = tmp;
linkedlist/MyLinkedList.java:51: warning: Thread Safety Violation 2
Unprotected write. Non-private method MyLinkedList.insert(...)
writes to field p._current._next
outside of synchronization.
Reporting because this access may occur on a background thread.
49. tmp = new MyListNode(x, p._current._next);
50. } // Extend the synch block one stmt to eliminate the bug
51. > p._current._next = tmp;
52. }
53. }
Found 2 issues
Issue Type(ISSUED_TYPE_ID): #
Thread Safety Violation 2(THREAD_SAFETY_VIOLATION_2): 2
**************** BUGS: , d7392eae2e6c045714ff854fa171b1e1, ef2fe6c07d14332d6809ca1cea6e153c *************
************* GENERATE PATCH *************
No patch could be generated for attempt ID
No patch could be generated for attempt ID
Capturing in javac mode...
Found 1 source file to analyze in /Users/tiwari/Documents/PostDoc/Paper2/Evaluation/RQ1/infer-out
linkedlist/MyLinkedList.java starting
linkedlist/MyLinkedList.java DONE
linkedlist/MyLinkedList.java:50: warning: Thread Safety Violation 2
Read/Write race. Non-private method MyLinkedList.insert(...)
reads with synchronization from p._current._next
. Potentially races with unsynchronized write in method MyLinkedList.insert(...)
.
Reporting because this access may occur on a background thread.
48. // Delete the synch block for the unsynch case
49. synchronized (this) {
50. > tmp = new MyListNode(x, p._current._next);
51. } // Extend the synch block one stmt to eliminate the bug
52. p._current._next = tmp;
linkedlist/MyLinkedList.java:52: warning: Thread Safety Violation 2
Unprotected write. Non-private method MyLinkedList.insert(...)
writes to field p._current._next
outside of synchronization.
Reporting because this access may occur on a background thread.
50. tmp = new MyListNode(x, p._current._next);
51. } // Extend the synch block one stmt to eliminate the bug
52. > p._current._next = tmp;
53. }
54. }
Found 2 issues
Issue Type(ISSUED_TYPE_ID): #
Thread Safety Violation 2(THREAD_SAFETY_VIOLATION_2): 2
New bugs detected during validation phase. Rerun RacerDFix? (Y/n)
The fixes should be performed after the patches for all the bugs are generated (outside the iteration through the bugs). The rewrite
chokes otherwise due to inconsistent line numbers.
compute the time to generate the ast separate from the one for patch generation
src/test/java/alarmclock/AlarmClock.java:191: warning: Thread Safety Violation 2
Read/Write race. Non-private method Monitor.wakeme(...)
indirectly reads without synchronization from this.waitList.list.[_]
. Potentially races with write in method Monitor.tick()
.
Reporting because this access may occur on a background thread.
189. */
190. try {
191. > synchronized (waitList.getLock(waketime)) {
192. try {
193. waitList.getLock(waketime).wait();
airline:
if (Num_Of_Seats_Sold > Maximum_Capacity)
synchronized(obj6) { throw new RuntimeException("bug found"); }
Patch ID: 5
Replace (INSERT) lines: 12 - 65
+: Object obj6 = new Object();
Replace (INSERT) lines: 53 - 53
-: throw new RuntimeException("bug found");
+: synchronized(obj6) { throw new RuntimeException("bug found"); }
Need to collect the type of the lock, otherwise we might end up creating locks on non-reference types leading to a type error in Java.
For:
protected void haha(int x){
// synchronized(myA2){
myA.f = x;
// }
}
we currently generate:
protected void haha(int x){
// synchronized(myA2){
synchronized(myA.f) {myA.f = x;}
// }
}
when we actually should generate:
we currently generate:
protected void haha(int x){
// synchronized(myA2){
synchronized(myA) {myA.f = x;}
// }
}
Data race involving the Num_Of_Seats_Sold variable was not fixed in Airline program. Running the infer still gives this warning. The RacerDFix seemed to have terminated normally:
Found 4 issues
Issue Type(ISSUED_TYPE_ID): #
Thread Safety Violation 2(THREAD_SAFETY_VIOLATION_2): 4
New bugs detected during validation phase. Rerun RacerDFix? (Y/n)
Y
Capturing in javac mode...
Found 1 source file to analyze in /Users/tiwari/Documents/PostDoc/Paper2/Evaluation/RQ1/infer-out
airline/Main.java starting
airline/Main.java DONE
ANDREEA: report
No issues found
Capturing in javac mode...
Found 1 source file to analyze in /Users/tiwari/Documents/PostDoc/Paper2/Evaluation/RQ1/infer-out
airline/Main.java starting
airline/Main.java DONE
ANDREEA: report
No issues found
Synchronized blocks with different lock objects are created for the race involving the same object.
For example, in Airline program, run the RacerDFix one time (do not select the Y option) and observe the lock object at line 42, 55, 65, and 66. All locks are protecting Num_Of_Seats_Sold, but locks are not the same at these places. Making locks the same at all four places removes the infer's warning for good.
Need to ensure well scoped synchronised:
't var = offending_statement;
_block_
==>
't var;
synchronised(L) {offending_statement;}
_block_
RacerDFix failed to generate any patch for BuggyProgram. Following are the execution traces:
buggyprogram/BuggyProgram.java starting
buggyprogram/BuggyProgram.java DONE
buggyprogram/BuggyProgram.java:317: warning: Thread Safety Violation 2
Read/Write race. Non-private method BuggyProgram$User.run()
reads without synchronization from buggyprogram.BuggyProgram.history.[_]
. Potentially races with write in method BuggyProgram$User.record()
.
Reporting because the current class is annotated @ThreadSafe
, so we assume that this method can run in parallel with other non-private methods in the class (including itself).
315.
316. for (i = 0; i < numOfUsers; ++i) {
317. > if (history[i] == randomNumber) {
318. break;
319. }
Found 1 issue
Issue Type(ISSUED_TYPE_ID): #
Thread Safety Violation 2(THREAD_SAFETY_VIOLATION_2): 1
**************** BUGS: , 83436a5e932ee5cf6e5ff2146eab6bc2 *************
************* GENERATE PATCH *************
No patch could be generated for attempt ID
Capturing in javac mode...
Found 1 source file to analyze in /Users/tiwari/Documents/PostDoc/Paper2/Evaluation/RQ1/infer-out
buggyprogram/BuggyProgram.java starting
buggyprogram/BuggyProgram.java DONE
buggyprogram/BuggyProgram.java:318: warning: Thread Safety Violation 2
Read/Write race. Non-private method BuggyProgram$User.run()
reads without synchronization from buggyprogram.BuggyProgram.history.[_]
. Potentially races with write in method BuggyProgram$User.record()
.
Reporting because the current class is annotated @ThreadSafe
, so we assume that this method can run in parallel with other non-private methods in the class (including itself).
316.
317. for (i = 0; i < numOfUsers; ++i) {
318. > if (history[i] == randomNumber) {
319. break;
320. }
Found 1 issue
Issue Type(ISSUED_TYPE_ID): #
Thread Safety Violation 2(THREAD_SAFETY_VIOLATION_2): 1
New bugs detected during validation phase. Rerun RacerDFix? (Y/n)
Currently we are removing one of the overlapping patches. Need to find a solution which allows us to merge such patches.
eg
if(cond) stmt1 else stms2
patch1 : synchronized(obj1) {if(cond) stmt1 else stms2 }
patch2 : if(cond) stmt1 else synchronized(obj2) {stms2 }
One of the above patches will be removed
While running AlarmClock example from PFix benchmark, an additional } is added for the below statement:
Initial Code: synchronized(list) {list[size - 1] = null;}
Code after added Lock: synchronized(list) {synchronized(size) {list[size - 1] = null;}}}
This causes compilation failure and halts further fixing.
If a file needs multiple iterations of patch generation, the latter should be performed automatically by default (for the end user). We can still keep the interactive feature for testing purposes.
Multiple lock objects were created during the execution on the Airline program:
Object obj3 = new Object(); Object obj6 = new Object(); Object obj9 = new Object(); Object obj12 = new Object(); Object obj15 = new Object();
However, the only lock object used in this case was obj12.
In checkfield program, a synchronized block is added in main method "ex = new InstanceExample();". As the lock object is non-static, java compilation fails with non-static variable cannot be referenced from a static context. There are two ways, I think we should address this:
Patch ID: 2
Replace (INSERT) lines: 6 - 41
+: Object objR1 = new Object();
Replace (INSERT) lines: 39 - 39
-: return accounts[accountNumber].getBalance() == amount;
+: synchronized(objR1) { return accounts[accountNumber].getBalance() == amount; }
Replace (INSERT) lines: 31 - 33
-: int temp = accounts[accountNumber].getBalance();
temp = temp + amount;
accounts[accountNumber].setBalance(temp);
+: synchronized(objR1) { int temp = accounts[accountNumber].getBalance();
temp = temp + amount;
accounts[accountNumber].setBalance(temp); }
Replace (INSERT) lines: 23 - 25
-: int temp = accounts[accountNumber].getBalance();
temp = temp - amount;
accounts[accountNumber].setBalance(temp);
+: synchronized(objR1) { int temp = accounts[accountNumber].getBalance();
temp = temp - amount;
accounts[accountNumber].setBalance(temp); }
If infer detects multiple bugs involving the same access snapshot, we should attempt to solve them sequentially:
When multiple runs of the main algo are triggered on the same file, the .orig file is overwritten with the previous fix.
File created after running the RacerDFix is 'racerdfix_sumaaries.json'. However, while reporting it expects 'racerdfix_summaries.json'. I think this issue is due to the spelling inconsistency. Following is the error trace:
Found 3 issues
Issue Type(ISSUED_TYPE_ID): #
Thread Safety Violation 2(THREAD_SAFETY_VIOLATION_2): 3
Exception in thread "main" java.io.FileNotFoundException: ./infer-out/racerdfix_summaries.json (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at scala.io.Source$.fromFile(Source.scala:92)
at scala.io.Source$.fromFile(Source.scala:77)
at scala.io.Source$.fromFile(Source.scala:55)
at org.racerdfix.utils.FileManipulation.fileToString(FileManipulation.scala:37)
at org.racerdfix.inferAPI.InterpretJson.getJsonSummaries(InterpretJson.scala:307)
at org.racerdfix.RacerDFix$.runPatchAndFix(RacerDFix.scala:117)
at org.racerdfix.RacerDFix$.handleInput(RacerDFix.scala:92)
at org.racerdfix.RacerDFix$.main(RacerDFix.scala:166)
at org.racerdfix.RacerDFix.main(RacerDFix.scala)
Check mergesort with --atomicity=true
Seems like we could have fixed this interface non-thread-safe easily:
https://fbinfer.com/docs/racerd/#interface-not-thread-safe
This seems like a very interesting project, and from what I gathered, it builds on top of Infer to maybe detect race conditions? Maybe even generate examples?
A one paragraph description of the project in the readme would be useful for others who are curious about developments in this space.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.