SlideShare ist ein Scribd-Unternehmen logo
1 von 23
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 ?

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (12)

Raptor web application firewall
Raptor web application firewallRaptor web application firewall
Raptor web application firewall
 
Phpactor and VIM
Phpactor and VIMPhpactor and VIM
Phpactor and VIM
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Ever Present Persistence - Established Footholds Seen in the Wild
Ever Present Persistence - Established Footholds Seen in the WildEver Present Persistence - Established Footholds Seen in the Wild
Ever Present Persistence - Established Footholds Seen in the Wild
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....
 
Deja vu JavaZone 2013
Deja vu  JavaZone 2013Deja vu  JavaZone 2013
Deja vu JavaZone 2013
 
Violent python
Violent pythonViolent python
Violent python
 
Egress-Assess and Owning Data Exfiltration
Egress-Assess and Owning Data ExfiltrationEgress-Assess and Owning Data Exfiltration
Egress-Assess and Owning Data Exfiltration
 
0d1n
0d1n0d1n
0d1n
 
Puppet Camp NYC 2014: Safely storing secrets and credentials in Git for use b...
Puppet Camp NYC 2014: Safely storing secrets and credentials in Git for use b...Puppet Camp NYC 2014: Safely storing secrets and credentials in Git for use b...
Puppet Camp NYC 2014: Safely storing secrets and credentials in Git for use b...
 
Profile all the things! - Capital Go 2017
 Profile all the things! - Capital Go 2017 Profile all the things! - Capital Go 2017
Profile all the things! - Capital Go 2017
 

Andere mochten auch

Concurrency: Best Practices
Concurrency: Best PracticesConcurrency: Best Practices
Concurrency: Best Practices
IndicThreads
 

Andere mochten auch (20)

Nginx+tomcat https 配置
Nginx+tomcat  https 配置Nginx+tomcat  https 配置
Nginx+tomcat https 配置
 
Java多线程技术
Java多线程技术Java多线程技术
Java多线程技术
 
Git基础培训
Git基础培训Git基础培训
Git基础培训
 
App开发过程的演变之路
App开发过程的演变之路App开发过程的演变之路
App开发过程的演变之路
 
Save JVM by Yourself: Real War Experiences of OOM
Save JVM by Yourself: Real War Experiences of OOMSave JVM by Yourself: Real War Experiences of OOM
Save JVM by Yourself: Real War Experiences of OOM
 
如何更好地设计测试用例-BQConf
如何更好地设计测试用例-BQConf如何更好地设计测试用例-BQConf
如何更好地设计测试用例-BQConf
 
自己的JVM自己救: 解救 OOM 實務經驗談 (JCConf 2015)
自己的JVM自己救: 解救 OOM 實務經驗談  (JCConf 2015)自己的JVM自己救: 解救 OOM 實務經驗談  (JCConf 2015)
自己的JVM自己救: 解救 OOM 實務經驗談 (JCConf 2015)
 
Recipe 黃佳伶 葉愛慧
Recipe 黃佳伶 葉愛慧Recipe 黃佳伶 葉愛慧
Recipe 黃佳伶 葉愛慧
 
大型网站架构演变
大型网站架构演变大型网站架构演变
大型网站架构演变
 
Lock Interface in Java
Lock Interface in JavaLock Interface in Java
Lock Interface in Java
 
浅谈项目管理(诸葛B2B电商研发部版改)
浅谈项目管理(诸葛B2B电商研发部版改)浅谈项目管理(诸葛B2B电商研发部版改)
浅谈项目管理(诸葛B2B电商研发部版改)
 
Thrift+scribe实现分布式日志收集,并与log4j集成
Thrift+scribe实现分布式日志收集,并与log4j集成Thrift+scribe实现分布式日志收集,并与log4j集成
Thrift+scribe实现分布式日志收集,并与log4j集成
 
Performance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionPerformance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage Collection
 
Concurrency: Best Practices
Concurrency: Best PracticesConcurrency: Best Practices
Concurrency: Best Practices
 
[Java concurrency]02.basic thread synchronization
[Java concurrency]02.basic thread synchronization[Java concurrency]02.basic thread synchronization
[Java concurrency]02.basic thread synchronization
 
JVM及其调优
JVM及其调优JVM及其调优
JVM及其调优
 
Java concurrency - Thread pools
Java concurrency - Thread poolsJava concurrency - Thread pools
Java concurrency - Thread pools
 
淺談 Java GC 原理、調教和 新發展
淺談 Java GC 原理、調教和新發展淺談 Java GC 原理、調教和新發展
淺談 Java GC 原理、調教和 新發展
 
On heap cache vs off-heap cache
On heap cache vs off-heap cacheOn heap cache vs off-heap cache
On heap cache vs off-heap cache
 
Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission Control
 

Ähnlich wie Building a lock profiler on the JVM

CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CanSecWest
 

Ähnlich wie Building a lock profiler on the JVM (20)

Java 8 and beyond, a scala story
Java 8 and beyond, a scala storyJava 8 and beyond, a scala story
Java 8 and beyond, a scala story
 
0507 057 01 98 * Adana Klima Servisleri
0507 057 01 98 * Adana Klima Servisleri0507 057 01 98 * Adana Klima Servisleri
0507 057 01 98 * Adana Klima Servisleri
 
Shall we play a game
Shall we play a gameShall we play a game
Shall we play a game
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
Configuring Syslog by Octavio
Configuring Syslog by OctavioConfiguring Syslog by Octavio
Configuring Syslog by Octavio
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge Solution
 
Suricata: A Decade Under the Influence (of packet sniffing)
Suricata: A Decade Under the Influence (of packet sniffing)Suricata: A Decade Under the Influence (of packet sniffing)
Suricata: A Decade Under the Influence (of packet sniffing)
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
Sonar qube to impove code quality
Sonar qube   to impove code qualitySonar qube   to impove code quality
Sonar qube to impove code quality
 
Having fun with Raspberry(s) and Apache projects
Having fun with Raspberry(s) and Apache projectsHaving fun with Raspberry(s) and Apache projects
Having fun with Raspberry(s) and Apache projects
 
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
 
Wonderful world of (distributed) SCM or VCS
Wonderful world of (distributed) SCM or VCSWonderful world of (distributed) SCM or VCS
Wonderful world of (distributed) SCM or VCS
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9
 
Ruxmon feb 2013 what happened to rails
Ruxmon feb 2013   what happened to railsRuxmon feb 2013   what happened to rails
Ruxmon feb 2013 what happened to rails
 
Understanding Non Blocking I/O with Python
Understanding Non Blocking I/O with PythonUnderstanding Non Blocking I/O with Python
Understanding Non Blocking I/O with Python
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.org
 
Introducing OWASP OWTF Workshop BruCon 2012
Introducing OWASP OWTF Workshop BruCon 2012Introducing OWASP OWTF Workshop BruCon 2012
Introducing OWASP OWTF Workshop BruCon 2012
 
Super Fast Gevent Introduction
Super Fast Gevent IntroductionSuper Fast Gevent Introduction
Super Fast Gevent Introduction
 

Mehr von Pierre Laporte

Mehr von Pierre Laporte (7)

Leveraging chaos mesh in Astra Serverless testing
Leveraging chaos mesh in Astra Serverless testingLeveraging chaos mesh in Astra Serverless testing
Leveraging chaos mesh in Astra Serverless testing
 
Les race conditions, nos très chères amies
Les race conditions, nos très chères amiesLes race conditions, nos très chères amies
Les race conditions, nos très chères amies
 
Devoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingDevoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarking
 
Lyon jug-how-to-fail-at-benchmarking
Lyon jug-how-to-fail-at-benchmarkingLyon jug-how-to-fail-at-benchmarking
Lyon jug-how-to-fail-at-benchmarking
 
La BDD, l'enfant gâté des SI
La BDD, l'enfant gâté des SILa BDD, l'enfant gâté des SI
La BDD, l'enfant gâté des SI
 
How to fail at benchmarking?
How to fail at benchmarking?How to fail at benchmarking?
How to fail at benchmarking?
 
Pimp my gc - Supersonic Scala
Pimp my gc - Supersonic ScalaPimp my gc - Supersonic Scala
Pimp my gc - Supersonic Scala
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Building a lock profiler on the JVM

  • 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 ?