Thread Safety Violations Fully Automatic and Precise Detection...
Transcript of Thread Safety Violations Fully Automatic and Precise Detection...
![Page 1: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/1.jpg)
1
Fully Automatic and Precise Detection ofThread Safety Violations
Michael Pradel and Thomas R. Gross
Department of Computer ScienceETH Zurich
![Page 2: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/2.jpg)
2
Motivation
Thread-safe classes:Building blocks for concurrent programs
![Page 3: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/3.jpg)
2
Motivation
Thread-safe classes:Building blocks for concurrent programs
![Page 4: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/4.jpg)
2
Motivation
Thread-safe classes:Building blocks for concurrent programs
![Page 5: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/5.jpg)
3
Example from JDK
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
![Page 6: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/6.jpg)
3
Example from JDK
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
IndexOutOfBoundsException
Confirmed as bug: Issue #7100996
!
![Page 7: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/7.jpg)
3
Example from JDK
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
IndexOutOfBoundsException
Confirmed as bug: Issue #7100996
!
How to testthread safety?
![Page 8: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/8.jpg)
4
Goal
Automatic and precise bug detection
ClassThreadsafetyviolations
Tool
![Page 9: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/9.jpg)
4
Goal
Automatic and precise bug detection
ClassThreadsafetyviolations
Tests
Falsepositives
Formalspecs
Tool
![Page 10: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/10.jpg)
4
Goal
Automatic and precise bug detection
ClassThreadsafetyviolations
Tool
![Page 11: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/11.jpg)
5
Thread-Safe Classes
“behaves correctly when accessedfrom multiple threads ... with noadditional synchronization ... (inthe) calling code” page 18
![Page 12: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/12.jpg)
5
Thread-Safe Classes
“behaves correctly when accessedfrom multiple threads ... with noadditional synchronization ... (inthe) calling code” page 18
![Page 13: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/13.jpg)
5
Thread-Safe Classes
“behaves correctly when accessedfrom multiple threads ... with noadditional synchronization ... (inthe) calling code” page 18
![Page 14: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/14.jpg)
5
Thread-Safe Classes
“behaves correctly when accessedfrom multiple threads ... with noadditional synchronization ... (inthe) calling code”
“operations ... behave as if they occurin some serial order that is consistentwith the order of the method callsmade by each of the individualthreads”
page 18
StringBuffer API documentation, JDK 6
![Page 15: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/15.jpg)
5
Thread-Safe Classes
“behaves correctly when accessedfrom multiple threads ... with noadditional synchronization ... (inthe) calling code”
“operations ... behave as if they occurin some serial order that is consistentwith the order of the method callsmade by each of the individualthreads”
page 18
StringBuffer API documentation, JDK 6
![Page 16: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/16.jpg)
6
Example
StringBuffer b = new StringBuffer()
b.append("a")
b.append("b")
b.append("c")
Thread 1 Thread 2
![Page 17: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/17.jpg)
6
Example
StringBuffer b = new StringBuffer()
b.append("a")
b.append("b")
b.append("c")
Thread 1 Thread 2
"abc" 3 "cab" 3 "acb" 3 "ac" 7
![Page 18: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/18.jpg)
6
Example
StringBuffer b = new StringBuffer()
b.append("a")
b.append("b")
b.append("c")
Thread 1 Thread 2
"abc" 3 "cab" 3 "acb" 3 "ac" 7
![Page 19: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/19.jpg)
6
Example
StringBuffer b = new StringBuffer()
b.append("a")
b.append("b")
b.append("c")
Thread 1 Thread 2
"abc" 3 "cab" 3 "acb" 3 "ac" 7
![Page 20: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/20.jpg)
6
Example
StringBuffer b = new StringBuffer()
b.append("a")
b.append("b")
b.append("c")
Thread 1 Thread 2
"abc" 3 "cab" 3 "acb" 3 "ac" 7
![Page 21: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/21.jpg)
6
Example
StringBuffer b = new StringBuffer()
b.append("a")
b.append("b")
b.append("c")
Thread 1 Thread 2
"abc" 3 "cab" 3 "acb" 3 "ac" 7
![Page 22: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/22.jpg)
7
Approach
Bug
Classundertest(CUT)
Execute
Thread safetyoracle
Generate aconcurrent test
![Page 23: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/23.jpg)
7
Approach
Bug
Classundertest(CUT)
Execute
Thread safetyoracle
Generate aconcurrent test
![Page 24: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/24.jpg)
7
Approach
Bug
Classundertest(CUT)
Execute
Thread safetyoracle
Generate aconcurrent test
![Page 25: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/25.jpg)
8
Generating Concurrent Tests
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Example:
![Page 26: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/26.jpg)
8
Generating Concurrent Tests
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Sequential prefix:
Create and set upCUT instance
Example:
![Page 27: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/27.jpg)
8
Generating Concurrent Tests
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Concurrent suffixes:
Use shared CUTinstance
Example:
![Page 28: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/28.jpg)
9
Test Generation Algorithm
1. Create prefix� Instantiate CUT
� Call methods
2. Create suffixes for prefix� Call methods on shared CUT instance
3. Prefix + two suffixes = test
![Page 29: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/29.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
![Page 30: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/30.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Randomlyselect aconstructor
![Page 31: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/31.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Randomlyselect aconstructor
![Page 32: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/32.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
After adding a call:Execute
![Page 33: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/33.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
After adding a call:Execute
3
![Page 34: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/34.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Randomlyselect amethod
![Page 35: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/35.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Randomlyselect amethod
b.append(/* String */)
![Page 36: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/36.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
b.append(/* String */)
Arguments:a) Take available objectb) Call method returning
required typec) Random value
![Page 37: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/37.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Arguments:a) Take available objectb) Call method returning
required typec) Random value
![Page 38: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/38.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
After adding a call:Execute
![Page 39: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/39.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
After adding a call:Execute
3
![Page 40: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/40.jpg)
10
Creating a Prefix
1. Create prefix� Instantiate CUT
� Call methods
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
![Page 41: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/41.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
![Page 42: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/42.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)
![Page 43: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/43.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)
Randomlyselect amethod
![Page 44: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/44.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)
Randomlyselect amethod
b.insert(/* int */, /* CharSequence */)
![Page 45: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/45.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)b.insert(/* int */, /* CharSequence */)
Arguments:a) Take available objectb) Call method returning
required typec) Random value
![Page 46: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/46.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)b.insert(-5, b)
Arguments:a) Take available objectb) Call method returning
required typec) Random value
![Page 47: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/47.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)b.insert(-5, b)
After adding a call:Execute
![Page 48: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/48.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)b.insert(-5, b)
After adding a call:Execute
!
![Page 49: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/49.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)b.insert(/* int */, /* CharSequence */)
Arguments:a) Take available objectb) Call method returning
required typec) Random value
![Page 50: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/50.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)
Arguments:a) Take available objectb) Call method returning
required typec) Random value
![Page 51: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/51.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)
After adding a call:Execute
![Page 52: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/52.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)
After adding a call:Execute
3
![Page 53: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/53.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b)
![Page 54: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/54.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
![Page 55: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/55.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
After adding a call:Execute
![Page 56: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/56.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
After adding a call:Execute
3
![Page 57: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/57.jpg)
11
Creating Suffixes
2. Create suffixesfor prefix
� Call methods onshared CUT instance
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
![Page 58: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/58.jpg)
12
Creating a Test
3. Prefix + two suffixes = test
![Page 59: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/59.jpg)
12
Creating a Test
3. Prefix + two suffixes = test
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
![Page 60: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/60.jpg)
12
Creating a Test
3. Prefix + two suffixes = test
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
Spawn new threadfor each suffix
![Page 61: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/61.jpg)
13
Approach
Bug
Classundertest(CUT)
Execute
Thread safetyoracle
Generate aconcurrent test
![Page 62: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/62.jpg)
13
Approach
Bug
Classundertest(CUT)
Execute
Thread safetyoracle
Generate aconcurrent test
![Page 63: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/63.jpg)
14
Thread Safety Oracle
Does the test executionexpose a thread safetyviolation?
� Focus on exceptionsand deadlocks
� Compare concurrentexecution tolinearizations
![Page 64: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/64.jpg)
15
Assumptions
Concurrency-only crashes are undesired� Matches definition of thread safety
Control over all input to tests� Sequential execution: Deterministic
![Page 65: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/65.jpg)
16
Linearizations
� Put all calls into one thread� Preserve order of calls within a thread
![Page 66: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/66.jpg)
16
Linearizations
213
2
13
21
3
� Put all calls into one thread� Preserve order of calls within a thread
21 3
![Page 67: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/67.jpg)
17
The Oracle
Exception ordeadlock?
Execute concurrently
No
Yes
Yes
No Thread safetyviolation
Samefailure?
Execute linearization All linearizationschecked
![Page 68: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/68.jpg)
17
The Oracle
Exception ordeadlock?
Execute concurrently
No
Yes
Yes
No Thread safetyviolation
Samefailure?
Execute linearization All linearizationschecked
Execute concurrently
![Page 69: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/69.jpg)
17
The Oracle
Exception ordeadlock?
Execute concurrently
No
Yes
Yes
No Thread safetyviolation
Samefailure?
Execute linearization All linearizationschecked
Exception ordeadlock?
![Page 70: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/70.jpg)
17
The Oracle
Exception ordeadlock?
Execute concurrently
No
Yes
Yes
No Thread safetyviolation
Samefailure?
Execute linearization All linearizationschecked
Execute linearization
![Page 71: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/71.jpg)
17
The Oracle
Exception ordeadlock?
Execute concurrently
No
Yes
Yes
No Thread safetyviolation
Samefailure?
Execute linearization All linearizationschecked
Samefailure?
![Page 72: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/72.jpg)
17
The Oracle
Exception ordeadlock?
Execute concurrently
No
Yes
Yes
No Thread safetyviolation
Samefailure?
Execute linearization All linearizationschecked
Execute linearization
![Page 73: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/73.jpg)
17
The Oracle
Exception ordeadlock?
Execute concurrently
No
Yes
Yes
No Thread safetyviolation
Samefailure?
Execute linearization All linearizationschecked
Samefailure?
![Page 74: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/74.jpg)
17
The Oracle
Exception ordeadlock?
Execute concurrently
No
Yes
Yes
No Thread safetyviolation
Samefailure?
Execute linearization All linearizationschecked
Thread safetyviolation
![Page 75: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/75.jpg)
18
Example
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
![Page 76: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/76.jpg)
18
Example
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
Thread 1 Thread 2
!
![Page 77: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/77.jpg)
18
Example
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
StringBuffer b = ..
b.append("abc")
b.insert(1, b)
b.deleteCharAt(1) 3
Thread 1 Thread 2
!
![Page 78: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/78.jpg)
18
Example
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
StringBuffer b = ..
b.append("abc")
b.insert(1, b)
b.deleteCharAt(1) 3
Thread 1 Thread 2
StringBuffer b = ..
b.append("abc")
b.deleteCharAt(1)
b.insert(1, b) 3
!
![Page 79: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/79.jpg)
18
Example
StringBuffer b = new StringBuffer()
b.append("abc")
b.insert(1, b) b.deleteCharAt(1)
StringBuffer b = ..
b.append("abc")
b.insert(1, b)
b.deleteCharAt(1) 3
Thread 1 Thread 2
StringBuffer b = ..
b.append("abc")
b.deleteCharAt(1)
b.insert(1, b) 3
!Thread safety violation
![Page 80: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/80.jpg)
19
Properties of the Oracle
Sound but incomplete *
� All reported violations are real� Cannot guarantee thread safety
Independent of bug type� Data races� Atomicity violations� Deadlocks
* with respect to incorrectness
![Page 81: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/81.jpg)
20
Implementation
![Page 82: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/82.jpg)
21
Evaluation
1. Effectiveness in finding bugs
2. Performance
Setup:
� Thread-safe classes from six Javalibraries (e.g., JDK, Apache DBCP)
� Intel Xeon (8x3GHz)
![Page 83: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/83.jpg)
22
Bugs
Found 15 bugs and 0 false positives
� 9 known bugs
� 6 previously unknown bugs� E.g., in JDK and Apache DBCP
![Page 84: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/84.jpg)
23
Example: Apache DBCP
DataSource ds = new DataSource()
ds.setDataSourceName("a") ds.close()
Thread 1 Thread 2
![Page 85: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/85.jpg)
23
Example: Apache DBCP
DataSource ds = new DataSource()
ds.setDataSourceName("a") ds.close()
Thread 1 Thread 2
ConcurrentModificationException
Reason: Unsynchronized use ofthread-unsafe collection
Confirmed as bug: Issue #369
!
![Page 86: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/86.jpg)
24
Kinds of Failures
12 of 15 failures are implicit (VM or JDK)
Most common:
� NullPointerException� ConcurrentModificationException
![Page 87: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/87.jpg)
25
Performance
![Page 88: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/88.jpg)
25
Performance
8 hours
![Page 89: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/89.jpg)
26
Conclusion
Concurrency: More and more important
Need tools to test thread-safe classes
This work:� Fully automatic testing� Only real bugs reported
![Page 90: Thread Safety Violations Fully Automatic and Precise Detection ofmp.binaervarianz.de/pldi2012_slides.pdf · 2013. 10. 4. · Thread Safety Violations Michael Pradel and Thomas R.](https://reader034.fdocuments.in/reader034/viewer/2022052011/60260a25d726a224333beb79/html5/thumbnails/90.jpg)
27
Thank you!
Try it:
Fully Automatic and Precise Detection of Thread Safety ViolationsMichael Pradel and Thomas R. Gross, ETH Zurich