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)
Ad

More Related Content

What's hot (20)

Steelcon 2015 - 0wning the internet of trash
Steelcon 2015 - 0wning the internet of trashSteelcon 2015 - 0wning the internet of trash
Steelcon 2015 - 0wning the internet of trash
infodox
 
BSides Hannover 2015 - Shell on Wheels
BSides Hannover 2015 - Shell on WheelsBSides Hannover 2015 - Shell on Wheels
BSides Hannover 2015 - Shell on Wheels
infodox
 
Steelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with PythonSteelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with Python
infodox
 
Follow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachina
Follow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachinaFollow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachina
Follow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachina
Priyanka Aash
 
Rainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could ExpectRainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could Expect
Peter Hlavaty
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Nikita Lipsky
 
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration DisastersBSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
infodox
 
Java platform
Java platformJava platform
Java platform
Universidade de São Paulo
 
Medical Image Processing Strategies for multi-core CPUs
Medical Image Processing Strategies for multi-core CPUsMedical Image Processing Strategies for multi-core CPUs
Medical Image Processing Strategies for multi-core CPUs
Daniel Blezek
 
Nullcon Hack IM 2011 walk through
Nullcon Hack IM 2011 walk throughNullcon Hack IM 2011 walk through
Nullcon Hack IM 2011 walk through
Anant Shrivastava
 
Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!
Peter Hlavaty
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
Exploitation and State Machines
Exploitation and State MachinesExploitation and State Machines
Exploitation and State Machines
Michael Scovetta
 
Racing with Droids
Racing with DroidsRacing with Droids
Racing with Droids
Peter Hlavaty
 
Node.js Patterns and Opinions
Node.js Patterns and OpinionsNode.js Patterns and Opinions
Node.js Patterns and Opinions
IsaacSchlueter
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
VeilFramework
 
Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)
Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)
Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)
Shih-Kun Huang
 
Back to the CORE
Back to the COREBack to the CORE
Back to the CORE
Peter Hlavaty
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
Chun-Yu Wang
 
Hacking - high school intro
Hacking - high school introHacking - high school intro
Hacking - high school intro
Peter Hlavaty
 
Steelcon 2015 - 0wning the internet of trash
Steelcon 2015 - 0wning the internet of trashSteelcon 2015 - 0wning the internet of trash
Steelcon 2015 - 0wning the internet of trash
infodox
 
BSides Hannover 2015 - Shell on Wheels
BSides Hannover 2015 - Shell on WheelsBSides Hannover 2015 - Shell on Wheels
BSides Hannover 2015 - Shell on Wheels
infodox
 
Steelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with PythonSteelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with Python
infodox
 
Follow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachina
Follow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachinaFollow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachina
Follow the White Rabbit: Simplifying Fuzz Testing Using FuzzExMachina
Priyanka Aash
 
Rainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could ExpectRainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could Expect
Peter Hlavaty
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Nikita Lipsky
 
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration DisastersBSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
BSides Edinburgh 2017 - TR-06FAIL and other CPE Configuration Disasters
infodox
 
Medical Image Processing Strategies for multi-core CPUs
Medical Image Processing Strategies for multi-core CPUsMedical Image Processing Strategies for multi-core CPUs
Medical Image Processing Strategies for multi-core CPUs
Daniel Blezek
 
Nullcon Hack IM 2011 walk through
Nullcon Hack IM 2011 walk throughNullcon Hack IM 2011 walk through
Nullcon Hack IM 2011 walk through
Anant Shrivastava
 
Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!
Peter Hlavaty
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
Exploitation and State Machines
Exploitation and State MachinesExploitation and State Machines
Exploitation and State Machines
Michael Scovetta
 
Node.js Patterns and Opinions
Node.js Patterns and OpinionsNode.js Patterns and Opinions
Node.js Patterns and Opinions
IsaacSchlueter
 
Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)
Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)
Baab (Bug as a Backdoor) through automatic exploit generation (CRAX)
Shih-Kun Huang
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
Chun-Yu Wang
 
Hacking - high school intro
Hacking - high school introHacking - high school intro
Hacking - high school intro
Peter Hlavaty
 

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

mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profiling
Haim Yadid
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
chen yuki
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptx
madan r
 
Jvm2
Jvm2Jvm2
Jvm2
Mykola Bova
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
jexp
 
How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)
Felix Geisendörfer
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf Linz
Ivan Krylov
 
Here comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfHere comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdf
Krystian Zybała
 
Advanced Production Debugging
Advanced Production DebuggingAdvanced Production Debugging
Advanced Production Debugging
Takipi
 
In Vogue Dynamic
In Vogue DynamicIn Vogue Dynamic
In Vogue Dynamic
Alexander Shopov
 
Codemotion 2015 spock_workshop
Codemotion 2015 spock_workshopCodemotion 2015 spock_workshop
Codemotion 2015 spock_workshop
Fernando Redondo Ramírez
 
Multi Threading
Multi ThreadingMulti Threading
Multi Threading
Ferdin Joe John Joseph PhD
 
web programming-Multithreading concept in Java.ppt
web programming-Multithreading concept in Java.pptweb programming-Multithreading concept in Java.ppt
web programming-Multithreading concept in Java.ppt
mcjaya2024
 
Non blocking programming and waiting
Non blocking programming and waitingNon blocking programming and waiting
Non blocking programming and waiting
Roman Elizarov
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
Serge Stinckwich
 
A tour on Spur for non-VM experts
A tour on Spur for non-VM expertsA tour on Spur for non-VM experts
A tour on Spur for non-VM experts
ESUG
 
Lifecycle of a JIT compiled code
Lifecycle of a JIT compiled codeLifecycle of a JIT compiled code
Lifecycle of a JIT compiled code
J On The Beach
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
JiandSon
 
Design for Test [DFT]-1 (1).pdf DESIGN DFT
Design for Test [DFT]-1 (1).pdf DESIGN DFTDesign for Test [DFT]-1 (1).pdf DESIGN DFT
Design for Test [DFT]-1 (1).pdf DESIGN DFT
jayasreenimmakuri777
 
Computer Operating Systems Concurrency Slide
Computer Operating Systems Concurrency SlideComputer Operating Systems Concurrency Slide
Computer Operating Systems Concurrency Slide
yasarcereen
 
mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profiling
Haim Yadid
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
chen yuki
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptx
madan r
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
jexp
 
How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)
Felix Geisendörfer
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf Linz
Ivan Krylov
 
Here comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfHere comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdf
Krystian Zybała
 
Advanced Production Debugging
Advanced Production DebuggingAdvanced Production Debugging
Advanced Production Debugging
Takipi
 
web programming-Multithreading concept in Java.ppt
web programming-Multithreading concept in Java.pptweb programming-Multithreading concept in Java.ppt
web programming-Multithreading concept in Java.ppt
mcjaya2024
 
Non blocking programming and waiting
Non blocking programming and waitingNon blocking programming and waiting
Non blocking programming and waiting
Roman Elizarov
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
Serge Stinckwich
 
A tour on Spur for non-VM experts
A tour on Spur for non-VM expertsA tour on Spur for non-VM experts
A tour on Spur for non-VM experts
ESUG
 
Lifecycle of a JIT compiled code
Lifecycle of a JIT compiled codeLifecycle of a JIT compiled code
Lifecycle of a JIT compiled code
J On The Beach
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
JiandSon
 
Design for Test [DFT]-1 (1).pdf DESIGN DFT
Design for Test [DFT]-1 (1).pdf DESIGN DFTDesign for Test [DFT]-1 (1).pdf DESIGN DFT
Design for Test [DFT]-1 (1).pdf DESIGN DFT
jayasreenimmakuri777
 
Computer Operating Systems Concurrency Slide
Computer Operating Systems Concurrency SlideComputer Operating Systems Concurrency Slide
Computer Operating Systems Concurrency Slide
yasarcereen
 
Ad

Recently uploaded (20)

TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Ad

Testing multithreaded java applications for synchronization problems

  • 1. Testing Multithreaded Java Applications for Synchronization Problems Vassil Popovski [email protected] 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