SlideShare a Scribd company logo
JFokus Java 9 contended locking performance
About Me
Java/JVM/GC performance person
Current Life:
Consultant who solves Managed Runtime performance issues
Past Life:
Worked with Oracle, Sun,AMD…
©2017 CodeKaram1
Agenda
• Setting the stage
• A quick glance at JDK 9 JEPs
• Building a problem statement
• Studying JEP 143 – Improve contended locking
©2017 CodeKaram2
Agenda
• Quick overview of top-down and bottom-up performance
approaches
• Choosing the right approach!
• Building our arsenal!
©2017 CodeKaram3
Agenda
• Observing the targeted improvements
• Demo comparing JDK 9 with JDK 8
• Summarizing the observations
©2017 CodeKaram4
Setting The Stage
©2017 CodeKaram5
JEPs in JDK 9
©2017 CodeKaram6
There are 89 total JEPs in JDK 9
JEPs in JDK 9
…and contended locking performanceimprovement (JEP143) is
one of them J
©2017 CodeKaram7
What is JEP 143?
©2017 CodeKaram8
JEP 143 brings about improvements to contended locks*
*In the past (Java 6) we have alreadyseen improvements to uncontendedlocksusing
BiasedLockingtechnique.
Building A Problem
Statement
©2017 CodeKaram9
Summary of JEP 143
©2017 CodeKaram10
“Improve the performance of contended Java object monitors”
©2017 CodeKaram11
“Improve the performance of contended Java object monitors”
Summary of JEP 143
Uncontended Locks
©2017 CodeKaram12
A single thread ‘t’ is executing a synchronized method
Contended Locks
©2017 CodeKaram13
A different thread ‘u’ wants to enter the synchronized method
that is already locked by thread ‘t’
Contended Locks
©2017 CodeKaram14
This is a heavy weight lock also known as inflated lock
Object Monitor maintains “WaitSet” for threads waiting for the
contended lock
Java Monitors
©2017 CodeKaram15
Wait
Q
Object
Monitor
Enter
Exit
Q
Wait Set
©2017 CodeKaram16
• A set of threads
• At creation – empty set of threads
• Can be manipulated only by:
• Object.wait, Object.notify, Object.notifyAll
Java Monitors
©2017 CodeKaram17
Wait
Q
Object
Monitor
Enter
Exit
Q
Wait
Notify
Top-Down
Performance Approach
©2017 CodeKaram18
What areYouTrying to Achieve?
©2017 CodeKaram19
Improve application?
Top-Down Approach
©2017 CodeKaram20
OS
Hardware
Application Ecosystem
Application
JRE
JVM
Top Down Approach - Process
•Step 1Monitor
•Step 2 Profile
•Step 3Analyze
•Step 4 Tune +
Apply
Bottom-Up
Performance Approach
©2017 CodeKaram22
What areYouTrying to Achieve?
©2017 CodeKaram23
Improve the platform?
Bottom-Up Approach
©2017 CodeKaram24
OS
Hardware
Application Ecosystem
Application
JRE
JVM
Bottom Up Approach - Process
•Step 1Monitor
•Step 2 Profile
•Step 3Analyze
•Step 4 Tune +
Apply
Choosing The Right
Approach …
©2017 CodeKaram26
Improve the JVM
What AreWeTryingTo Do?
©2017 CodeKaram27
The Bottom-Up
Approach
HenceWeChoose…
©2017 CodeKaram28
Bottom Up Approach
©2017 CodeKaram29
I NEED the power!!
… to stress the platform
Setting Up For
Benchmarking
©2017 CodeKaram30
Where to Start?
©2017 CodeKaram31
• Know what you are stressing
• Get/ write the appropriate workload/ application
• Get/write the appropriate tools
Know What You’re
Stressing…
©2017 CodeKaram32
Speed UpTargets
©2017 CodeKaram33
• PlatformEvent::unpark()
• Java monitor enter operations
• Java monitor exit operations
• Java monitor notify/notifyAll operations
Get/Write The
Appropriate
Workload/Application
…
©2017 CodeKaram34
FromThe JEP …
©2017 CodeKaram35
LockLoops-JSR166-Doug-Sept2009 (was LockLoops):
The benchmark compares multiple locking techniques
For our purpose, we just need to test the contended locks.
Contended Locking Test
©2017 CodeKaram36
private static class BuiltinLockLoop extends LockLoop {
final int loop(int n) {
int sum = 0;
while (n-- > 0) {
synchronized (this) {
v = LoopHelpers.compute1(v);
}
sum += LoopHelpers.compute2(v);
}
return sum;
}
}
Contended Locking Test
©2017 CodeKaram37
private static class BuiltinLockLoop extends LockLoop {
final int loop(int n) {
int sum = 0;
while (n-- > 0) {
synchronized (this) {
v = LoopHelpers.compute1(v);
}
sum += LoopHelpers.compute2(v);
}
return sum;
}
}
Where to Next?
©2017 CodeKaram38
Ensure that you are in fact measuring contended object monitor
performance!
How DoWe DoThat?
©2017 CodeKaram39
Bypass biased locking: Use -XX:-UseBiasedLocking
Bypass stack based locking: Use -XX:+UseHeavyMonitors
Get/Write The
Appropriate Tools …
©2017 CodeKaram40
Oracle Developer
Studio Performance
Tool
©2017 CodeKaram41
Profiling with ‘collect’
©2017 CodeKaram42
• -j on: default for when target is Java
• -p on: default clock-profiling rate of ~100 samples/second
• -H on: heap tracing
• -t <duration>: time over which to record data
• -h <ctr_def>…: specify HW counter profiling
Observing The
Targeted
Improvements
©2017 CodeKaram43
Speed UpTargets
©2017 CodeKaram44
• PlatformEvent::unpark()
• Java monitor enter operations
• Java monitor exit operations
• Java monitor notify/notifyAll operations
Demo - Comparing
Contended Locking in
JDK 9 to JDK 8
©2017 CodeKaram45
Summarizing the
Observations
©2017 CodeKaram46
Speed UpTargets
©2017 CodeKaram47
•PlatformEvent::unpark()
• Java monitor enter operations
• Java monitor exit operations
• Java monitor notify/notifyAll operations
©2017 CodeKaram48
JDK 9 ExclusiveTime JDK8 ExclusiveTime Method Name
0.400 0.941 os::PlatformEvent::unpark()
Unpark
ImprovementTargets
©2017 CodeKaram49
• PlatformEvent::unpark()
•Java monitor enter operations
• Java monitor exit operations
• Java monitor notify/notifyAll operations
©2017 CodeKaram50
JDK 9 ExclusiveTime JDK8 ExclusiveTime Method Name
97.678 187.001 ObjectMonitor::enter(Thread*)
2.462 3.432 ObjectMonitor::EnterI(Thread*)
Monitor Enter
Speed UpTargets
©2017 CodeKaram51
• PlatformEvent::unpark()
• Java monitor enter operations
•Java monitor exit operations
• Java monitor notify/notifyAll operations
©2017 CodeKaram52
JDK 9 ExclusiveTime JDK8 ExclusiveTime Method Name
2.302 2.352 ObjectMonitor::exit(bool,…)
0.000 0.961 ObjectMonitor::ExitEpilog(Thread*
,…)
Monitor Exit
Speed UpTargets
©2017 CodeKaram53
• PlatformEvent::unpark()
• Java monitor enter operations
• Java monitor exit operations
•Java monitor notify/notifyAll operations
©2017 CodeKaram54
I’ll leave that as a take-home exercise for you all! J
Notify/ NotifyAll
Further Reading
©2017 CodeKaram55
http://openjdk.java.net/jeps/143
https://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html
https://wiki.openjdk.java.net/display/HotSpot/Synchronization
https://blogs.oracle.com/dave/entry/biased_locking_in_hotspot
http://extremeperformance.expert
©2017 CodeKaram56

More Related Content

PDF
Java Performance Engineer's Survival Guide
PDF
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
PDF
GC Tuning Confessions Of A Performance Engineer - Improved :)
PDF
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
PDF
Garbage First Garbage Collector: Where the Rubber Meets the Road!
PDF
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
PDF
GC Tuning Confessions Of A Performance Engineer
PDF
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
Java Performance Engineer's Survival Guide
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
GC Tuning Confessions Of A Performance Engineer - Improved :)
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Garbage First Garbage Collector: Where the Rubber Meets the Road!
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
GC Tuning Confessions Of A Performance Engineer
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...

What's hot (20)

PDF
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
PDF
Game of Performance: A Song of JIT and GC
PPTX
Enabling Java: Windows on Arm64 - A Success Story!
PPTX
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
PPTX
G1 collector and tuning and Cassandra
PDF
Java 9: The (G1) GC Awakens!
PPTX
JVM memory management & Diagnostics
PDF
Java Performance Tuning
PDF
The 2nd half. Scaling to the next^2
PPTX
Building a Better JVM
PDF
Chaos is a ladder !
PDF
Modern Monitoring [ with Prometheus ]
PDF
Cloud TiDB deep dive
PDF
SFO15-110: Toolchain Collaboration
PDF
Tuning the g1gc
PDF
Trouble with memory
PDF
Garbage First and you
PDF
Developing PostgreSQL Performance, Simon Riggs
PPTX
Stacking up with OpenStack: Building for High Availability
PDF
TSC BoF: OSS Toolchain Discussion - SFO17-409
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
Game of Performance: A Song of JIT and GC
Enabling Java: Windows on Arm64 - A Success Story!
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
G1 collector and tuning and Cassandra
Java 9: The (G1) GC Awakens!
JVM memory management & Diagnostics
Java Performance Tuning
The 2nd half. Scaling to the next^2
Building a Better JVM
Chaos is a ladder !
Modern Monitoring [ with Prometheus ]
Cloud TiDB deep dive
SFO15-110: Toolchain Collaboration
Tuning the g1gc
Trouble with memory
Garbage First and you
Developing PostgreSQL Performance, Simon Riggs
Stacking up with OpenStack: Building for High Availability
TSC BoF: OSS Toolchain Discussion - SFO17-409
Ad

Viewers also liked (16)

PPTX
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
PDF
Embracing Reactive Streams with Java 9 and Spring 5
PDF
JVM JIT-compiler overview @ JavaOne Moscow 2013
PDF
Performance tesing coding standards & best practice guidelines v1
PPTX
Modularization With Project Jigsaw in JDK 9
PPT
Performance testing and reporting with JMeter
PDF
Client-Side Performance Testing
PDF
Project Jigsaw in JDK 9: Modularity Comes To Java
PDF
Concurrent Mark-Sweep Garbage Collection #jjug_ccc
PDF
SAP Performance Testing Best Practice Guide v1.0
KEY
JavaOne 2012 - JVM JIT for Dummies
PDF
Patterns of a “good” test automation framework
PPT
Performance testing jmeter
PDF
What is tackled in the Java EE Security API (Java EE 8)
PDF
OpenCredo: "A Guide to Becoming Famous within IT"
PPTX
55 New Features in JDK 9
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Embracing Reactive Streams with Java 9 and Spring 5
JVM JIT-compiler overview @ JavaOne Moscow 2013
Performance tesing coding standards & best practice guidelines v1
Modularization With Project Jigsaw in JDK 9
Performance testing and reporting with JMeter
Client-Side Performance Testing
Project Jigsaw in JDK 9: Modularity Comes To Java
Concurrent Mark-Sweep Garbage Collection #jjug_ccc
SAP Performance Testing Best Practice Guide v1.0
JavaOne 2012 - JVM JIT for Dummies
Patterns of a “good” test automation framework
Performance testing jmeter
What is tackled in the Java EE Security API (Java EE 8)
OpenCredo: "A Guide to Becoming Famous within IT"
55 New Features in JDK 9
Ad

Similar to JFokus Java 9 contended locking performance (20)

PDF
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
PDF
The Art Of Performance Tuning - with presenter notes!
PPTX
JavaMicroBenchmarkpptm
PDF
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
PPTX
Java performance tuning
PDF
Java >= 9
PDF
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
PDF
Java Concurrency and Performance | Multi Threading | Concurrency | Java Conc...
PDF
What to expect from Java 9
PDF
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
PDF
Optimizing Java Chris Newland James Gough Benjamin J Evans
KEY
Modern Java Concurrency (OSCON 2012)
PDF
Java 9-10 What's New
PPT
Optimizing your java applications for multi core hardware
PDF
Software Profiling: Java Performance, Profiling and Flamegraphs
PDF
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
PDF
JVM Under the Hood
PPTX
Jvm memory model
PDF
Java Performance and Using Java Flight Recorder
PPT
Performance Analysis of Idle Programs
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
The Art Of Performance Tuning - with presenter notes!
JavaMicroBenchmarkpptm
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Java performance tuning
Java >= 9
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
Java Concurrency and Performance | Multi Threading | Concurrency | Java Conc...
What to expect from Java 9
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
Optimizing Java Chris Newland James Gough Benjamin J Evans
Modern Java Concurrency (OSCON 2012)
Java 9-10 What's New
Optimizing your java applications for multi core hardware
Software Profiling: Java Performance, Profiling and Flamegraphs
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
JVM Under the Hood
Jvm memory model
Java Performance and Using Java Flight Recorder
Performance Analysis of Idle Programs

More from Monica Beckwith (7)

PPTX
The ilities of software engineering.pptx
PPTX
A G1GC Saga-KCJUG.pptx
PDF
ZGC-SnowOne.pdf
PDF
QCon London.pdf
PDF
Applying Concurrency Cookbook Recipes to SPEC JBB
PPTX
Intro to Garbage Collection
PPTX
OpenJDK Concurrent Collectors
The ilities of software engineering.pptx
A G1GC Saga-KCJUG.pptx
ZGC-SnowOne.pdf
QCon London.pdf
Applying Concurrency Cookbook Recipes to SPEC JBB
Intro to Garbage Collection
OpenJDK Concurrent Collectors

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
ai tools demonstartion for schools and inter college
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Introduction to Artificial Intelligence
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
System and Network Administration Chapter 2
PPTX
history of c programming in notes for students .pptx
PDF
AI in Product Development-omnex systems
PDF
top salesforce developer skills in 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
ai tools demonstartion for schools and inter college
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Introduction to Artificial Intelligence
CHAPTER 2 - PM Management and IT Context
2025 Textile ERP Trends: SAP, Odoo & Oracle
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
VVF-Customer-Presentation2025-Ver1.9.pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Design an Analysis of Algorithms II-SECS-1021-03
Wondershare Filmora 15 Crack With Activation Key [2025
Understanding Forklifts - TECH EHS Solution
Odoo Companies in India – Driving Business Transformation.pdf
System and Network Administration Chapter 2
history of c programming in notes for students .pptx
AI in Product Development-omnex systems
top salesforce developer skills in 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
PTS Company Brochure 2025 (1).pdf.......

JFokus Java 9 contended locking performance