Building a lock profiler on the JVM
Upcoming SlideShare
Loading in...5
×
 

Building a lock profiler on the JVM

on

  • 433 views

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

Statistics

Views

Total Views
433
Slideshare-icon Views on SlideShare
433
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Building a lock profiler on the JVM Building a lock profiler on the JVM Presentation Transcript

    • Writing a simple lock profiler on the JVM
    • Me ● Pierre Laporte – Java guy at Xebia France – JVM internals since oct-2012 – Java Performance Tuning ● @pingtimeout ● pierre@pingtimeout.fr ● http://www.pingtimeout.fr/
    • This talk ● Tyrion – Lock Profiler – Prototype – Open Source (GPL) – https://github.com/pingtimeout/tyrion – Be critical !
    • 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 ?
    • 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
    • Additional goals ● Follow the GC logs approach – Generate a log file – Information density – Parse & analyse it after
    • Big Picture ● Java Agent – Bytecode manipulation (ASM) – JSON output (Jackson) ● Analyser – Console only (for now)
    • 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
    • Before/After : Synchronized blocks synchronized(obj) { /* Stuff */ } synchronized(obj) { Interceptor.enteredCriticalSection(obj); /* Stuff */ Interceptor.leavingCriticalSection(obj); }
    • Before : Synchronized blocks ALOAD_1 MONITORENTER /*...*/ ALOAD_1 MONITOREXIT
    • 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
    • Before/After : Synchronized methods synchronized void foo() { /* Stuff */ } synchronized void foo() { Interceptor.enteredCriticalSection(this); /* Stuff */ Interceptor.leavingCriticalSection(this); }
    • Before : Synchronized methods ● Nothing special – Regular methods – Synchronization done by the JVM ● No MONITORENTER / MONITOREXIT – Cannot intercept lock before it is held
    • 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
    • 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); }
    • Before : Static methods ● Nothing special – Regular methods – Synchronization done by the JVM ● No MONITORENTER / MONITOREXIT – Cannot intercept lock before it is held
    • 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
    • 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
    • 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 ?
    • Demo ● Hello World ● Cassandra Startup
    • 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
    • Roadmap ● Build a fancy GUI – JavaFX ? Swing+JFreecharts ? … ? ● Use System.nanoTime() ● Densify output ● … ?
    • Thanks ! ● Code on Github : https://github.com/pingtimeout/tyrion ● Slides posted online http://fr.slideshare.net/PierreLaporte ● Any questions ?