SlideShare a Scribd company logo
Testing Multithreaded Java
           Applications for
     Synchronization Problems

                 Vassil Popovski
             vpopovski@vmware.com



www.vmware.com
Why multithreading?


                      core 1                   core N
                                     …
                      cache                    cache


                               shared memory


A modern CPU
Why multithreading?


                      Thread 1
                      thread           …           Thread N
                                                   thread

                                 synchronization

                                   Java heap


A modern Java
Application
Chuck Norris can write multi-threaded Java applications with a
single thread
Image source: http://4.bp.blogspot.com/-RhqCAgEyhxs/T7CqtsC0RUI/AAAAAAAAJuw/LnkKl4xBcFA/s1600/ChuckNorris.png
New concept -> new problems

Multithreading leads to:

   • Non-determinism


   • New types of defects exist such as deadlocks,
     livelocks, thread contentions and race conditions
Threads interleaving
   Thread 1      Thread 2

   T1: Block A



                 T2: Block 1


                 T2: Block 2


   T1: Block B
Threads interleaving
   Thread 1      Thread 2

                 T2: Block 1


   T1: Block A


                 T2: Block 2


   T1: Block B
T1: Block A       T1: Block A       T1: Block A


T1: Block B           T2: Block 1       T2: Block 1


    T2: Block 1   T1: Block B           T2: Block 2


    T2: Block 2       T2: Block 2   T1: Block B



    T2: Block 1       T2: Block 1       T2: Block 1

    T2: Block 2   T1: Block A       T1: Block A

T1: Block A           T2: Block 2   T1: Block B

T1: Block B       T1: Block B           T2: Block 2
Number of different thread interleavings
QUIZ
Q: What is the number of all interleavings for 3
threads with 3 blocks each?
QUIZ#2
Q: What is the number of all interleavings for 100
threads with 5 blocks each?
A: 65425664332523564432322
424953034168268979855850496989515584307752298932760805211068470651079402188475376110921674489441757
100735903402821009297053297794211809385509051615356527155445783425009164096533350469391547252484286
352170768347268799054153532042868164413927778850486516865333071658697094887692175873537666079346686
842361469250698011080482809500911511130491996847437245286443821625843666165114941515090783620437429
415942216292191680146737140994107899459749143795942309665194029514713124663377783172923345131361940
229192120804703412493451507233690788801188111838709132087076627314402580265097945582570927195669521
598427700259644897641650396932627145510414432349054625767654125966166480949639718802313608310300009
569524993138782412735779520574624492099944487052157575950286282799011493381356627940388478077680384
306582854732555208087863968812536837179492786875593176275633769413252546329077858090833823115446889
102306231699826529926420707529253684105656295906933999334649790703077726680609672178258148765366567
390695607298478918976308327339329621077231101219394256694201487015134200730008353085104356877584247
630194547240102504944587886157078430944582189784261271608483330872723017090959069769287306115617186
352177030505501663380710718097318392846079061230267394203670163609062726137904455998424717036312138
754515697607350323258954538452071707071282635719375409459015826288484347553786552736926086009976292
360046325376069078312201822678281992756614855571919537160977811910388279229176987762264097262002703
425073318544671121015763363797279655888433399855420190892643324103098493700405493206195043772398231
236266443176076877706895863803891037350530509973799077521555018278731597362632766739808771841037553
742905870882213799310132964516518399560481797842812543528613844661728630365645349106177833375046753
439848225204235068908502565168578778645210878189710308017886705257632553314025472000000000000000000
0000000000000000000000000000000
What to test for?
• safety: nothing bad happens

• liveness: something good eventually happens
Example 1: Single Lane Bridge




 Image source: http://www.doc.ic.ac.uk/~jnm/book/ppt/ch7.ppt



• safety:
   – no car crash
• liveness:
   – every car eventually get an opportunity to cross the bridge
Example 2: BoundedBuffer or
            Producer/Consumer
 Producer 1
                                                            Consumer 1
 Producer 2
                                                            Consumer 2
 Producer 3
                                                                …
      …
                                                           Consumer M
 Producer N


• safety:
    – head and tail of the queue must not over run each other
• liveness:
    – when the queue contains an item, the consumer process must be able
      to access the queue and when the queue contains space for another
      item, the producer process must be able to access the queue
How to test for synchronization issues?

• Load/Stress testing (blackbox, whitebox)
• Specific interleavings testing (whitebox)
• All interleavings testing (whitebox)

• Instrumentation (blackbox, whitebox)
Load/Stress testing
• A lot of threads and operations to exercise
  different interleavings
Demo!
Deadlock example
      Thread 1                 Thread 2


synchronized ( A ) {

                         synchronized ( B ) {


  synchronized ( B ) {

                            synchronized ( A ) {




                               Deadlock !!!
Load/Stress testing
• Tools
  – ExecutorService -
    http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Execu
  – TestNG -
    http://testng.org/doc/documentation-main.html#annotations
  – JUnit -
    http://www.junit.org/apidocs/junit/extensions/ActiveTestSuite.html
     • JUnitPerf -
       http://testng.org/doc/documentation-main.html#annotations
  – GroboUtils -
    http://groboutils.sourceforge.net/testing-junit/using_mtt.html
  – Custom Threading
Specific interleavings testing
• Deterministic and repeatable tests
MultithreadedTC
• Based on internal clock

  – Tick increases when all threads are blocked

  – waitForTick(tick) – blocks the thread until tick reaches
    certain value

  – assertTick(tick) – asserts the current tick


• Methods that start with “thread” are executed in
  separate threads
MultithreadedTC
BoundedBuffer with size = 1


                Thread 1      Thread 2

                  put 42


                  put 17
                 (blocks)
                               get 42


                               get 17
MultithreadedTC
BoundedBuffer with size = 1


                 Thread 1          Thread 2
                                                  Tick 0
                   put 42        waitForTick(1)


                   put 17                         Tick 1
                  (blocks)
                                     get 42
              assertForTick(1)

                                     get 17
Demo!
IMUnit
• Events based

  – IMUnit.fireEvent(“event1”)

  – @Schedule(“event1 -> event2”)

  – @Schedule(“[event1] -> event2”)
Demo!
ThreadWeaver
• Two threads only – Main and Secondary

• By default: For each line of Main thread (T1) ->
  block and execute fully Secondary thread (T2)


     T2: Block 1       T1: Block A         T1: Block A


     T2: Block 2           T2: Block 1     T1: Block B


 T1: Block A               T2: Block 2          T2: Block 1


 T1: Block B           T1: Block B              T2: Block 2
ThreadWeaver
• Two threads only – Main and Secondary

• By default: For each line of Main thread (T1) ->
  block and execute fully Secondary thread (T2)

• Powerful Breakpoints
Demo!
Specific interleavings testing
• Tools
  – MultithreadedTC -
    http://code.google.com/p/multithreadedtc/
     • Enhanced version for Junit 4 -
       http://code.google.com/p/multithreadedtc-junit4/
  – IMUnit - http://mir.cs.illinois.edu/imunit/
  – ThreadWeaver -
    http://code.google.com/p/thread-weaver/
  – Awaitility - http://code.google.com/p/awaitility/
All interleavings testing
• Exercise all possible interleavings
JavaPathFinder
Traditional testing


                                                                             OK
        Code
                                                Testing

                                                                             error
       Image source: http://javapathfinder.sourceforge.net/events/JPF-workshop-050108/tutorial.ppt
JavaPathFinder
Model Checking with JavaPathFinder


      Code
                                                                           OK
                                       Model Checking

                                                                      error trace
             properties                                                    Line   5: …
                                                                           Line   12: …
                                                                           …
                                                                           Line   41:…
                                                                           Line   47:…


      Image source: http://javapathfinder.sourceforge.net/events/JPF-workshop-050108/tutorial.ppt
JavaPathFinder


Program testing can be used to show the presence
of bugs, but never to show their absence!

--Edsger Dijkstra
Demo!
All interleavings testing
• Tools
  – JavaPathFinder (JPF) -
    http://babelfish.arc.nasa.gov/trac/jpf


     • JavaRaceFinder -
       http://www.cise.ufl.edu/research/JavaRacefinder/Java_Rac
       eFinder/JRF_Home.html
Instrumentation
• Instrument the code to catch problems easier
AspectJ


                 AspectJ Compiler
Original code                        Instrumented .
.class or .jar                       class or .jar




                 Aspect Definition
                        .aj
Demo!
Instrumentation
• Tools
  – AspectJ - www.eclipse.org/aspectj/
     • RacerAJ - http://www.bodden.de/tools/raceraj/
  – CalFuzzer - http://srl.cs.berkeley.edu/~ksen/calfuzzer/
  – (commercial) Flashlight / Jsure -
    http://www.surelogic.com/concurrency-tools.html
Other tools
• CHESS (native DLLs & managed executables) -
  http://research.microsoft.com/en-
  us/projects/chess/
• MoonWalker (.NET)-
  http://code.google.com/p/moonwalker/
Recommended books
Thank you!
Q&A
Source code packages (1)
•   org.java2days2012.multithreaded.common
    – Several implementations of AccountManager, Counter, BounderBuffer and
      MultipleReadersSingleWriter
•   org.java2days2012.multithreaded.executorservice
    – Load/stress tests using ExecutorService
•   org.java2days2012.multithreaded.testng
    – Load/stress tests using TestNG
•   org.java2days2012.multithreaded.mtc
    – MultithreadedTC tests
•   org.java2days2012.multithreaded.imunit
    – IMUnit tests
•   org.java2days2012.multithreaded.threadweaver
    – ThreadWeaver tests
Source code packages (2)
•   org.java2days2012.multithreaded.javapathfinder
    – JavaPathFinder examples
•   ca.mcgill.sable.racer
    – RacerAJ source code
•   org.java2days2012.multithreaded.aspectj
    – Custom aspect that increase the chance of hitting multithreading problem
      during testing
•   org.java2days2012.multithreaded.blockbox.*
    – Rest based AccountManager client/test and server (in .server package)

More Related Content

PPT
Testing Multithreaded Java Applications for Synchronization Problems, ISTA 2011
PPTX
Ahead-Of-Time Compilation of Java Applications
PDF
Everything can be a bundle - making OSGi bundles of Java legacy code - Gunnar...
PPTX
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
PDF
44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...
PDF
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
PDF
Us 16-subverting apple-graphics_practical_approaches_to_remotely_gaining_root...
PDF
Testing Multithreaded Java Applications for Synchronization Problems, ISTA 2011
Ahead-Of-Time Compilation of Java Applications
Everything can be a bundle - making OSGi bundles of Java legacy code - Gunnar...
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
Us 16-subverting apple-graphics_practical_approaches_to_remotely_gaining_root...

What's hot (20)

PPTX
Steelcon 2015 - 0wning the internet of trash
PPTX
BSides Hannover 2015 - Shell on Wheels
PPTX
Steelcon 2014 - Process Injection with Python
PDF
Follow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachina
PDF
Rainbow Over the Windows: More Colors Than You Could Expect
PPTX
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
PPTX
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
PDF
PPTX
Medical Image Processing Strategies for multi-core CPUs
PDF
Nullcon Hack IM 2011 walk through
PPTX
Ice Age melting down: Intel features considered usefull!
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
PDF
Exploitation and State Machines
PPTX
Racing with Droids
PDF
Node.js Patterns and Opinions
PPTX
The Veil-Framework
PPTX
Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)
PPTX
Back to the CORE
PPTX
How to implement a simple dalvik virtual machine
PPTX
Hacking - high school intro
Steelcon 2015 - 0wning the internet of trash
BSides Hannover 2015 - Shell on Wheels
Steelcon 2014 - Process Injection with Python
Follow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachina
Rainbow Over the Windows: More Colors Than You Could Expect
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
Medical Image Processing Strategies for multi-core CPUs
Nullcon Hack IM 2011 walk through
Ice Age melting down: Intel features considered usefull!
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Exploitation and State Machines
Racing with Droids
Node.js Patterns and Opinions
The Veil-Framework
Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)
Back to the CORE
How to implement a simple dalvik virtual machine
Hacking - high school intro
Ad

Similar to Testing multithreaded java applications for synchronization problems (20)

PDF
mjprof: Monadic approach for JVM profiling
PDF
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
PPTX
U4 JAVA.pptx
PPTX
PDF
Looming Marvelous - Virtual Threads in Java Javaland.pdf
PDF
How to Test Asynchronous Code (v2)
PDF
Code lifecycle in the jvm - TopConf Linz
PDF
Here comes the Loom - Ya!vaConf.pdf
PDF
Advanced Production Debugging
PDF
In Vogue Dynamic
PDF
Codemotion 2015 spock_workshop
PPTX
PPT
web programming-Multithreading concept in Java.ppt
PPTX
Non blocking programming and waiting
KEY
Using Smalltalk for controlling robotics systems
PDF
A tour on Spur for non-VM experts
PDF
Lifecycle of a JIT compiled code
PDF
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
PDF
Design for Test [DFT]-1 (1).pdf DESIGN DFT
PPTX
Computer Operating Systems Concurrency Slide
mjprof: Monadic approach for JVM profiling
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
U4 JAVA.pptx
Looming Marvelous - Virtual Threads in Java Javaland.pdf
How to Test Asynchronous Code (v2)
Code lifecycle in the jvm - TopConf Linz
Here comes the Loom - Ya!vaConf.pdf
Advanced Production Debugging
In Vogue Dynamic
Codemotion 2015 spock_workshop
web programming-Multithreading concept in Java.ppt
Non blocking programming and waiting
Using Smalltalk for controlling robotics systems
A tour on Spur for non-VM experts
Lifecycle of a JIT compiled code
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
Design for Test [DFT]-1 (1).pdf DESIGN DFT
Computer Operating Systems Concurrency Slide
Ad

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
Teaching material agriculture food technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Machine learning based COVID-19 study performance prediction
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Modernizing your data center with Dell and AMD
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Approach and Philosophy of On baking technology
NewMind AI Monthly Chronicles - July 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Teaching material agriculture food technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Electronic commerce courselecture one. Pdf
Machine learning based COVID-19 study performance prediction
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Testing multithreaded java applications for synchronization problems

  • 1. Testing Multithreaded Java Applications for Synchronization Problems Vassil Popovski vpopovski@vmware.com www.vmware.com
  • 2. Why multithreading? core 1 core N … cache cache shared memory A modern CPU
  • 3. Why multithreading? Thread 1 thread … Thread N thread synchronization Java heap A modern Java Application
  • 4. Chuck Norris can write multi-threaded Java applications with a single thread Image source: http://4.bp.blogspot.com/-RhqCAgEyhxs/T7CqtsC0RUI/AAAAAAAAJuw/LnkKl4xBcFA/s1600/ChuckNorris.png
  • 5. New concept -> new problems Multithreading leads to: • Non-determinism • New types of defects exist such as deadlocks, livelocks, thread contentions and race conditions
  • 6. Threads interleaving Thread 1 Thread 2 T1: Block A T2: Block 1 T2: Block 2 T1: Block B
  • 7. Threads interleaving Thread 1 Thread 2 T2: Block 1 T1: Block A T2: Block 2 T1: Block B
  • 8. T1: Block A T1: Block A T1: Block A T1: Block B T2: Block 1 T2: Block 1 T2: Block 1 T1: Block B T2: Block 2 T2: Block 2 T2: Block 2 T1: Block B T2: Block 1 T2: Block 1 T2: Block 1 T2: Block 2 T1: Block A T1: Block A T1: Block A T2: Block 2 T1: Block B T1: Block B T1: Block B T2: Block 2
  • 9. Number of different thread interleavings
  • 10. QUIZ Q: What is the number of all interleavings for 3 threads with 3 blocks each?
  • 11. QUIZ#2 Q: What is the number of all interleavings for 100 threads with 5 blocks each? A: 65425664332523564432322 424953034168268979855850496989515584307752298932760805211068470651079402188475376110921674489441757 100735903402821009297053297794211809385509051615356527155445783425009164096533350469391547252484286 352170768347268799054153532042868164413927778850486516865333071658697094887692175873537666079346686 842361469250698011080482809500911511130491996847437245286443821625843666165114941515090783620437429 415942216292191680146737140994107899459749143795942309665194029514713124663377783172923345131361940 229192120804703412493451507233690788801188111838709132087076627314402580265097945582570927195669521 598427700259644897641650396932627145510414432349054625767654125966166480949639718802313608310300009 569524993138782412735779520574624492099944487052157575950286282799011493381356627940388478077680384 306582854732555208087863968812536837179492786875593176275633769413252546329077858090833823115446889 102306231699826529926420707529253684105656295906933999334649790703077726680609672178258148765366567 390695607298478918976308327339329621077231101219394256694201487015134200730008353085104356877584247 630194547240102504944587886157078430944582189784261271608483330872723017090959069769287306115617186 352177030505501663380710718097318392846079061230267394203670163609062726137904455998424717036312138 754515697607350323258954538452071707071282635719375409459015826288484347553786552736926086009976292 360046325376069078312201822678281992756614855571919537160977811910388279229176987762264097262002703 425073318544671121015763363797279655888433399855420190892643324103098493700405493206195043772398231 236266443176076877706895863803891037350530509973799077521555018278731597362632766739808771841037553 742905870882213799310132964516518399560481797842812543528613844661728630365645349106177833375046753 439848225204235068908502565168578778645210878189710308017886705257632553314025472000000000000000000 0000000000000000000000000000000
  • 12. What to test for? • safety: nothing bad happens • liveness: something good eventually happens
  • 13. Example 1: Single Lane Bridge Image source: http://www.doc.ic.ac.uk/~jnm/book/ppt/ch7.ppt • safety: – no car crash • liveness: – every car eventually get an opportunity to cross the bridge
  • 14. Example 2: BoundedBuffer or Producer/Consumer Producer 1 Consumer 1 Producer 2 Consumer 2 Producer 3 … … Consumer M Producer N • safety: – head and tail of the queue must not over run each other • liveness: – when the queue contains an item, the consumer process must be able to access the queue and when the queue contains space for another item, the producer process must be able to access the queue
  • 15. How to test for synchronization issues? • Load/Stress testing (blackbox, whitebox) • Specific interleavings testing (whitebox) • All interleavings testing (whitebox) • Instrumentation (blackbox, whitebox)
  • 16. Load/Stress testing • A lot of threads and operations to exercise different interleavings
  • 17. Demo!
  • 18. Deadlock example Thread 1 Thread 2 synchronized ( A ) { synchronized ( B ) { synchronized ( B ) { synchronized ( A ) { Deadlock !!!
  • 19. Load/Stress testing • Tools – ExecutorService - http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Execu – TestNG - http://testng.org/doc/documentation-main.html#annotations – JUnit - http://www.junit.org/apidocs/junit/extensions/ActiveTestSuite.html • JUnitPerf - http://testng.org/doc/documentation-main.html#annotations – GroboUtils - http://groboutils.sourceforge.net/testing-junit/using_mtt.html – Custom Threading
  • 20. Specific interleavings testing • Deterministic and repeatable tests
  • 21. MultithreadedTC • Based on internal clock – Tick increases when all threads are blocked – waitForTick(tick) – blocks the thread until tick reaches certain value – assertTick(tick) – asserts the current tick • Methods that start with “thread” are executed in separate threads
  • 22. MultithreadedTC BoundedBuffer with size = 1 Thread 1 Thread 2 put 42 put 17 (blocks) get 42 get 17
  • 23. MultithreadedTC BoundedBuffer with size = 1 Thread 1 Thread 2 Tick 0 put 42 waitForTick(1) put 17 Tick 1 (blocks) get 42 assertForTick(1) get 17
  • 24. Demo!
  • 25. IMUnit • Events based – IMUnit.fireEvent(“event1”) – @Schedule(“event1 -> event2”) – @Schedule(“[event1] -> event2”)
  • 26. Demo!
  • 27. ThreadWeaver • Two threads only – Main and Secondary • By default: For each line of Main thread (T1) -> block and execute fully Secondary thread (T2) T2: Block 1 T1: Block A T1: Block A T2: Block 2 T2: Block 1 T1: Block B T1: Block A T2: Block 2 T2: Block 1 T1: Block B T1: Block B T2: Block 2
  • 28. ThreadWeaver • Two threads only – Main and Secondary • By default: For each line of Main thread (T1) -> block and execute fully Secondary thread (T2) • Powerful Breakpoints
  • 29. Demo!
  • 30. Specific interleavings testing • Tools – MultithreadedTC - http://code.google.com/p/multithreadedtc/ • Enhanced version for Junit 4 - http://code.google.com/p/multithreadedtc-junit4/ – IMUnit - http://mir.cs.illinois.edu/imunit/ – ThreadWeaver - http://code.google.com/p/thread-weaver/ – Awaitility - http://code.google.com/p/awaitility/
  • 31. All interleavings testing • Exercise all possible interleavings
  • 32. JavaPathFinder Traditional testing OK Code Testing error Image source: http://javapathfinder.sourceforge.net/events/JPF-workshop-050108/tutorial.ppt
  • 33. JavaPathFinder Model Checking with JavaPathFinder Code OK Model Checking error trace properties Line 5: … Line 12: … … Line 41:… Line 47:… Image source: http://javapathfinder.sourceforge.net/events/JPF-workshop-050108/tutorial.ppt
  • 34. JavaPathFinder Program testing can be used to show the presence of bugs, but never to show their absence! --Edsger Dijkstra
  • 35. Demo!
  • 36. All interleavings testing • Tools – JavaPathFinder (JPF) - http://babelfish.arc.nasa.gov/trac/jpf • JavaRaceFinder - http://www.cise.ufl.edu/research/JavaRacefinder/Java_Rac eFinder/JRF_Home.html
  • 37. Instrumentation • Instrument the code to catch problems easier
  • 38. AspectJ AspectJ Compiler Original code Instrumented . .class or .jar class or .jar Aspect Definition .aj
  • 39. Demo!
  • 40. Instrumentation • Tools – AspectJ - www.eclipse.org/aspectj/ • RacerAJ - http://www.bodden.de/tools/raceraj/ – CalFuzzer - http://srl.cs.berkeley.edu/~ksen/calfuzzer/ – (commercial) Flashlight / Jsure - http://www.surelogic.com/concurrency-tools.html
  • 41. Other tools • CHESS (native DLLs & managed executables) - http://research.microsoft.com/en- us/projects/chess/ • MoonWalker (.NET)- http://code.google.com/p/moonwalker/
  • 44. Q&A
  • 45. Source code packages (1) • org.java2days2012.multithreaded.common – Several implementations of AccountManager, Counter, BounderBuffer and MultipleReadersSingleWriter • org.java2days2012.multithreaded.executorservice – Load/stress tests using ExecutorService • org.java2days2012.multithreaded.testng – Load/stress tests using TestNG • org.java2days2012.multithreaded.mtc – MultithreadedTC tests • org.java2days2012.multithreaded.imunit – IMUnit tests • org.java2days2012.multithreaded.threadweaver – ThreadWeaver tests
  • 46. Source code packages (2) • org.java2days2012.multithreaded.javapathfinder – JavaPathFinder examples • ca.mcgill.sable.racer – RacerAJ source code • org.java2days2012.multithreaded.aspectj – Custom aspect that increase the chance of hitting multithreading problem during testing • org.java2days2012.multithreaded.blockbox.* – Rest based AccountManager client/test and server (in .server package)

Editor's Notes

  • #7: Block is atomic piece of code that is not affected by multithreading. This is usually a block that starts or ends with accessing a shared variable Blocks can overlap
  • #11: Answer = 1680
  • #12: Answer = 1680
  • #19: NASA’s spacecraft fly to Mars (Deep Space 2) – deadlock due to missing critical section, almost failed the whole mission. Remote Agent in AI for controlling the spacecraft without any human interactions. It was great that the control center from Earth took control and restarted the module. Therac-25, massive radiation overdose due to data race, 5 deaths, more injured
  • #22: ExecutorService/TestCounter ExecutorService/TestAccountManager
  • #26: Created at the University of Maryland by Bill Pugh
  • #27: Created at the University of Maryland by Bill Pugh
  • #28: Created at the University of Maryland by Bill Pugh
  • #29: mtc / TestInterleavings mtc / TestBounderBufferLocking mtc / TestAccountManagerForDeadlock mtc / TestReadersWriterLiveness
  • #30: Imunit / TestInterleavings - Show also block event – [] brackets for 12AB schedule
  • #34: Threadweaver / TestInterleaving Talk about @ThreadedBefore, @ThreadedAfter, @ThreadedMain and @ThreadedSecondary Threadweaver / TestAccountManager - Show the deadlock