Your SlideShare is downloading. ×
  • Like
Building a lock profiler on the JVM
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Building a lock profiler on the JVM

  • 278 views
Published

This presentation is a feedback of how I wrote a simple lock profiler on the JVM, including architectural overview, limits of the current approach and roadmap for future versions

This presentation is a feedback of how I wrote a simple lock profiler on the JVM, including architectural overview, limits of the current approach and roadmap for future versions

Published in Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
278
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Writing a simple lock profiler on the JVM
  • 2. Me ● Pierre Laporte – Java guy at Xebia France – JVM internals since oct-2012 – Java Performance Tuning ● @pingtimeout ● pierre@pingtimeout.fr ● http://www.pingtimeout.fr/
  • 3. This talk ● Tyrion – Lock Profiler – Prototype – Open Source (GPL) – https://github.com/pingtimeout/tyrion – Be critical !
  • 4. Why a lock profiler ? ● Initial idea : GC logs parser – for science (and fun) ● Challenged by Kirk – Write a lock profiler – Harder, even more fun ● My skills ? – No idea of bytecode manipulation – ASM means “The Assembly language”, right ?
  • 5. Goals ● Create an open-source lock-profiler ● First prototype should : – List the locks that are never accessed – List the locks accessed by only one thread – List the locks accessed by more than one thread
  • 6. Additional goals ● Follow the GC logs approach – Generate a log file – Information density – Parse & analyse it after
  • 7. Big Picture ● Java Agent – Bytecode manipulation (ASM) – JSON output (Jackson) ● Analyser – Console only (for now)
  • 8. Implementation ● Instrument synchronized blocks/methods – Call profiler inside critical sections ● Before the first instruction (record entry) ● After the last instruction (record exit) – Store events per thread – Events collection and dump ● Asynchronously ● Dedicated thread
  • 9. Before/After : Synchronized blocks synchronized(obj) { /* Stuff */ } synchronized(obj) { Interceptor.enteredCriticalSection(obj); /* Stuff */ Interceptor.leavingCriticalSection(obj); }
  • 10. Before : Synchronized blocks ALOAD_1 MONITORENTER /*...*/ ALOAD_1 MONITOREXIT
  • 11. After : Synchronized blocks ALOAD_1 DUP MONITORENTER INVOKESTATIC #3 Method fr/pingtimeout/tyrion/Interceptor .enteredCriticalSection:(Ljava/lang/Object;)V /*...*/ ALOAD_1 DUP INVOKESTATIC #4 Method fr/pingtimeout/tyrion/Interceptor .leavingCriticalSection (Ljava/lang/Object;)V MONITOREXIT
  • 12. Before/After : Synchronized methods synchronized void foo() { /* Stuff */ } synchronized void foo() { Interceptor.enteredCriticalSection(this); /* Stuff */ Interceptor.leavingCriticalSection(this); }
  • 13. Before : Synchronized methods ● Nothing special – Regular methods – Synchronization done by the JVM ● No MONITORENTER / MONITOREXIT – Cannot intercept lock before it is held
  • 14. After : Synchronized methods // Method beginning ALOAD_0 INVOKESTATIC #3 // Method fr/pingtimeout/tyrion/Interceptor enteredCriticalSection:(Ljava/lang/Object;)V /*...*/ ALOAD_0 INVOKESTATIC #4 // Method fr/pingtimeout/tyrion/Interceptor leavingCriticalSection (Ljava/lang/Object;)V // Method end
  • 15. Before/After : Static methods static synchronized void bar() { /* Stuff */ } static synchronized void bar() { Class<?> clazz = Class.forName("FQN"); Interceptor.enteredCriticalSection(clazz); /* Stuff */ Interceptor.leavingCriticalSection(clazz); }
  • 16. Before : Static methods ● Nothing special – Regular methods – Synchronization done by the JVM ● No MONITORENTER / MONITOREXIT – Cannot intercept lock before it is held
  • 17. After : Static methods LDC #4 // Current class name known by ASM INVOKESTATIC #2 // Method java.lang.Class.forName: (Ljava/lang/String;)Ljava/lang/Class; INVOKESTATIC #3 // Method fr/pingtimeout/tyrion/Interceptor enteredCriticalSection:(Ljava/lang/Object;)V /*...*/ LDC #4 // Current class name known by ASM INVOKESTATIC #2 // Method java.lang.Class.forName: (Ljava/lang/String;)Ljava/lang/Class; INVOKESTATIC #4 // Method fr/pingtimeout/tyrion/Interceptor leavingCriticalSection (Ljava/lang/Object;)V
  • 18. After : Static methods LDC #4 ● // Current class name known by ASM INVOKESTATIC #2 ● // Method java.lang.Class.forName: (Ljava/lang/String;)Ljava/lang/Class; INVOKESTATIC #3 ● // Method fr/pingtimeout/tyrion/Interceptor enteredCriticalSection:(Ljava/lang/Object;)V
  • 19. Drawbacks ● Only time spent inside critical section – No "waiting on monitor" time – Simplest (fastest) solution ● Infer "likely contended" locks – Locks accessed by several threads – Within millis/micros/nanos ?
  • 20. Demo ● Hello World ● Cassandra Startup
  • 21. Fun stuff ● Store events in a shared data structure Map<Thread, Set<Event>> accesses; ● Infinite interception loop synchronized(accesses) {…} ● Has to be lock-free ! – Map<Thread, AtomicReference<Set<Event>>> ● Immutable ConsList<Event> – CAS possible
  • 22. Roadmap ● Build a fancy GUI – JavaFX ? Swing+JFreecharts ? … ? ● Use System.nanoTime() ● Densify output ● … ?
  • 23. Thanks ! ● Code on Github : https://github.com/pingtimeout/tyrion ● Slides posted online http://fr.slideshare.net/PierreLaporte ● Any questions ?