SlideShare a Scribd company logo
JVM Profiling
Under da Hood
Richard Warburton - @RichardWarburto
Nitsan Wakart - @nitsanw
Why Profile?
Lies, Damn Lies and Statistical Profiling
Under the Hood
Conclusion
Jvm profiling under the hood
Jvm profiling under the hood
Measure data from your application
Exploratory Profiling
Execution Profiling
=
Where in code is my application
spending time?
CPU Profiling Limitations
● Finds CPU bound bottlenecks
● Many problems not CPU Bound
○ Networking
○ Database or External Service
○ I/O
○ Garbage Collection
○ Insufficient Parallelism
○ Blocking & Queuing Effects
Why Profile?
Lies, Damn Lies and Statistical Profiling
Under the Hood
Conclusion
Jvm profiling under the hood
Different Execution Profilers
● Instrumenting
○ Adds timing code to application
● Sampling
○ Collects thread dumps periodically
Sampling Profilers
WebServerThread.run()
Controller.doSomething() Controller.next()
Repo.readPerson()
new Person()
View.printHtml()
Periodicity Bias
● Bias from sampling at a fixed interval
● Periodic operations with the same frequency
as the samples
● Timed operations
Periodicity Bias
a() ??? a() ??? a() ??? a() ???
Stack Trace Sampling
● JVMTI interface: GetCallTrace
○ Trigger a global safepoint(not on Zing)
○ Collect stack trace
● Large impact on application
● Samples only at safepoints
Example
private static void outer()
{
for (int i = 0; i < OUTER; i++)
{
hotMethod(i);
}
}
// https://github.com/RichardWarburton/profiling-samples
Example (2)
private static void hotMethod(final int i)
{
for (int k = 0; k < N; k++)
{
final int[] array = SafePointBias. array;
final int index = i % SIZE;
for (int j = index; j < SIZE; j++)
{
array[index] += array[j];
}
}
}
Jvm profiling under the hood
-XX:+PrintSafepointStatistics
ThreadDump 48
Maximum sync time 985 ms
Whats a safepoint?
● Java threads poll global flag
○ At ‘uncounted’ loops back edge
○ At method exit/enter
● A safepoint poll can be delayed by:
○ Large methods
○ Long running ‘counted’ loops
○ BONUS: Page faults/thread suspension
Jvm profiling under the hood
Safepoint Bias
WebServerThread.run()
Controller.doSomething() Controller.next()
Repo.readPerson()
new Person()
View.printHtml() ???
Jvm profiling under the hood
Let sleeping dogs lie?
● ‘GetCallTrace’ profilers will sample ALL
threads
● Even sleeping threads...
This Application Mostly Sleeps
JVisualVM snapshot
No CPU? No profile!
JMC profile
Why Profile?
Lies, Damn Lies and Statistical Profiling
Under the Hood
Conclusion
Honest Profiler
https://github.com/richardwarburton/honest-profiler
Jvm profiling under the hood
AsyncGetCallTrace
● Used by Oracle Solaris Studio
● Adapted to open source prototype by
Google’s Jeremy Manson
● Unsupported, Undocumented …
Underestimated
SIGPROF - Interrupt Handlers
● OS Managed timing based interrupt
● Interrupts the thread and directly calls an
event handler
● Used by profilers we’ll be talking about
Design
Log File
Processor
Thread Graphical UI
Console UI
Signal
Handler
Signal
Handler
Os Timer Thread
“You are in a maze of twisty little stack frames,
all alike”
AsyncGetCallTrace under the hood
● A Java thread is ‘possessed’
● You have the PC/FP/SP
● What is the call trace?
○ jmethodId - Java Method Identifier
○ bci - Byte Code Index -> used to find line number
Where Am I?
● Given a PC what is the current method?
● Is this a Java method?
○ Each method ‘lives’ in a range of addresses
● If not, what do we do?
Java Method? Which line?
● Given a PC, what is the current line?
○ Not all instructions map directly to a source line
● Given super-scalar CPUs what does PC
mean?
● What are the limits of PC accuracy?
“> I think Andi mentioned this to me last year --
> that instruction profiling was no longer reliable.
It never was.”
http://permalink.gmane.org/gmane.linux.kernel.perf.user/1948
Exchange between Brenden Gregg and Andi Kleen
Skid
● PC indicated will be >= to PC at sample time
● Known limitation of instruction profiling
● Leads to harder ‘blame analysis’
Limits of line number accuracy:
Line number (derived from BCI) is the closest
attributable BCI to the PC (-XX:+DebugNonSafepoint)
The PC itself is within some skid distance from
actual sampled instruction
● Divided into frames
○ frame { sender*, stack*, pc }
● A single linked list:
root(null, s0, pc1) <- call1 (root, s1, pc2) <- call2(call1, s2, pc2)
● Convert to: (jmethodId,lineno)
The Stack
A typical stack
● JVM Thread runner infra:
○ JavaThread::run to JavaCalls::call_helper
● Interleaved Java frames:
○ Interpreted
○ Compiled
○ Java to Native and back
● Top frame may be Java or Native
Native frames
● Ignored, but need to navigate through
● Use a dedicated FP register to find sender
● But only if compiled to do so…
● Use a last remembered Java frame instead
See: http://duartes.org/gustavo/blog/post/journey-to-the-stack/
Java Compiled Frames
● C1/C2 produce native code
● No FP register: use set frame size
● Challenge: methods can move (GC)
● Challenge: methods can get recompiled
Java Interpreter frames
● Separately managed by the runtime
● Make an effort to look like normal frames
● Challenge: may be interrupted half-way
through construction...
Virtual Frames
● C1/C2 inline code (intrinsics/other methods)
● No data on stack
● Must use JVM debug info
AsyncGetCallTrace Limitations
● Only profiles running threads
● Accuracy of line info limited by reality
● Only reports Java frames/threads
● Must lookup debug info during call
Compilers: Friend or Fiend?
void safe_reset(void *start, size_t size) {
char *base = reinterpret_cast<char *>(start);
char *end = base + size;
for (char *p = base; p < end; p++) {
*p = 0;
}
}
Compilers: Friend or Fiend?
safe_reset(void*, unsigned long):
lea rdx, [rdi+rsi]
cmp rdi, rdx
jae .L3
sub rdx, rdi
xor esi, esi
jmp memset
.L3:
rep ret
Concurrency Bug
● Even simple concurrency bugs are hard to
spot
● Unspotted race condition in the ring buffer
● Spotted thanks to open source & Rajiv
Signal
Writer
Reader
Writer
Reader
Extra Credit!
Native Profiling Tools
● Profile native methods
● Profile at the instruction level
● Profile hardware counters
Perf
● A Linux profiling tool
● Can be made to work with Java
● JMH integration
● Ongoing integration efforts
Solaris Studio
● Works on Linux!
● Secret Weapon!
● Give it a go!
ZVision
● Works for Zing
● No HWC support
● Very informative
Why Profile?
Lies, Damn Lies and Statistical Profiling
Under the Hood
Conclusion
What did we cover?
● Biases in Profilers
● More accurate sampling
● Alternative Profiling Approaches
Don’t just blindly trust your tooling.
Test your measuring instruments
Open Source enables implementation review
Q & A
@nitsanw
psy-lob-saw.blogspot.co.uk
@richardwarburto
insightfullogic.com
java8training.com
www.pluralsight.
com/author/richard-
warburton
Slides after here just for reference,
don’t delete or show
Jvm profiling under the hood

More Related Content

PDF
Performance and predictability
RichardWarburton
 
PDF
Performance and predictability (1)
RichardWarburton
 
PDF
JCConf 2020 - New Java Features Released in 2020
Joseph Kuo
 
ODP
Java Garbage Collection, Monitoring, and Tuning
Carol McDonald
 
ODP
Quick introduction to Java Garbage Collector (JVM GC)
Marcos García
 
PPT
Jvm Performance Tunning
guest1f2740
 
PDF
Effective testing for spark programs Strata NY 2015
Holden Karau
 
PPTX
Optimizing Communicating Event-Loop Languages with Truffle
Stefan Marr
 
Performance and predictability
RichardWarburton
 
Performance and predictability (1)
RichardWarburton
 
JCConf 2020 - New Java Features Released in 2020
Joseph Kuo
 
Java Garbage Collection, Monitoring, and Tuning
Carol McDonald
 
Quick introduction to Java Garbage Collector (JVM GC)
Marcos García
 
Jvm Performance Tunning
guest1f2740
 
Effective testing for spark programs Strata NY 2015
Holden Karau
 
Optimizing Communicating Event-Loop Languages with Truffle
Stefan Marr
 

What's hot (20)

PDF
Statistical Learning and Text Classification with NLTK and scikit-learn
Olivier Grisel
 
PPTX
java memory management & gc
exsuns
 
PPTX
Fm wtm12-v2
Miguel Gamboa
 
PPTX
opt-mem-trx
Miguel Gamboa
 
PPTX
The Java Memory Model
CA Technologies
 
PPT
Reactive programming with examples
Peter Lawrey
 
PDF
Advanced Spark and TensorFlow Meetup May 26, 2016
Chris Fregly
 
PDF
Java Memory Model
Łukasz Koniecki
 
PPTX
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
KEY
Know yourengines velocity2011
Demis Bellot
 
PPTX
JVM Memory Model - Yoav Abrahami, Wix
Codemotion Tel Aviv
 
PPT
An Introduction to JVM Internals and Garbage Collection in Java
Abhishek Asthana
 
PPT
Os Reindersfinal
oscon2007
 
PPT
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Emery Berger
 
PPTX
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Stefan Marr
 
PDF
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Jian-Hong Pan
 
PPT
Heap & thread dump
Nishit Charania
 
PDF
JCConf 2018 - Retrospect and Prospect of Java
Joseph Kuo
 
PDF
Attention mechanisms with tensorflow
Keon Kim
 
PDF
NANO266 - Lecture 9 - Tools of the Modeling Trade
University of California, San Diego
 
Statistical Learning and Text Classification with NLTK and scikit-learn
Olivier Grisel
 
java memory management & gc
exsuns
 
Fm wtm12-v2
Miguel Gamboa
 
opt-mem-trx
Miguel Gamboa
 
The Java Memory Model
CA Technologies
 
Reactive programming with examples
Peter Lawrey
 
Advanced Spark and TensorFlow Meetup May 26, 2016
Chris Fregly
 
Java Memory Model
Łukasz Koniecki
 
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
Know yourengines velocity2011
Demis Bellot
 
JVM Memory Model - Yoav Abrahami, Wix
Codemotion Tel Aviv
 
An Introduction to JVM Internals and Garbage Collection in Java
Abhishek Asthana
 
Os Reindersfinal
oscon2007
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Emery Berger
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Stefan Marr
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Jian-Hong Pan
 
Heap & thread dump
Nishit Charania
 
JCConf 2018 - Retrospect and Prospect of Java
Joseph Kuo
 
Attention mechanisms with tensorflow
Keon Kim
 
NANO266 - Lecture 9 - Tools of the Modeling Trade
University of California, San Diego
 
Ad

Similar to Jvm profiling under the hood (20)

PPTX
Secure coding for developers
sluge
 
PDF
Parallel program design
ZongYing Lyu
 
PPTX
DIY Java Profiling
Roman Elizarov
 
PDF
Address/Thread/Memory Sanitizer
Platonov Sergey
 
PDF
Computer Graphics - Lecture 01 - 3D Programming I
💻 Anton Gerdelan
 
PDF
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
Linaro
 
PDF
Cryptography and secure systems
Vsevolod Stakhov
 
ODP
Linux kernel tracing superpowers in the cloud
Andrea Righi
 
PPTX
Dpdk applications
Vipin Varghese
 
PDF
[grcpp] Refactoring for testability c++
Dimitrios Platis
 
PDF
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
Xiaozhe Wang
 
PDF
Unmanaged Parallelization via P/Invoke
Dmitri Nesteruk
 
PDF
Skiron - Experiments in CPU Design in D
Mithun Hunsur
 
PDF
Building source code level profiler for C++.pdf
ssuser28de9e
 
PDF
Mirko Damiani - An Embedded soft real time distributed system in Go
linuxlab_conf
 
PDF
E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)
Valeriy Kravchuk
 
PPTX
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Spark Summit
 
PDF
RAT - Repurposing Adversarial Tradecraft
⭕Alexander Rymdeko-Harvey
 
PPTX
Robust C++ Task Systems Through Compile-time Checks
Stoyan Nikolov
 
PDF
DevSecCon London 2019: A Kernel of Truth: Intrusion Detection and Attestation...
DevSecCon
 
Secure coding for developers
sluge
 
Parallel program design
ZongYing Lyu
 
DIY Java Profiling
Roman Elizarov
 
Address/Thread/Memory Sanitizer
Platonov Sergey
 
Computer Graphics - Lecture 01 - 3D Programming I
💻 Anton Gerdelan
 
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
Linaro
 
Cryptography and secure systems
Vsevolod Stakhov
 
Linux kernel tracing superpowers in the cloud
Andrea Righi
 
Dpdk applications
Vipin Varghese
 
[grcpp] Refactoring for testability c++
Dimitrios Platis
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
Xiaozhe Wang
 
Unmanaged Parallelization via P/Invoke
Dmitri Nesteruk
 
Skiron - Experiments in CPU Design in D
Mithun Hunsur
 
Building source code level profiler for C++.pdf
ssuser28de9e
 
Mirko Damiani - An Embedded soft real time distributed system in Go
linuxlab_conf
 
E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)
Valeriy Kravchuk
 
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Spark Summit
 
RAT - Repurposing Adversarial Tradecraft
⭕Alexander Rymdeko-Harvey
 
Robust C++ Task Systems Through Compile-time Checks
Stoyan Nikolov
 
DevSecCon London 2019: A Kernel of Truth: Intrusion Detection and Attestation...
DevSecCon
 
Ad

More from RichardWarburton (20)

PDF
Fantastic performance and where to find it
RichardWarburton
 
PDF
Production profiling what, why and how technical audience (3)
RichardWarburton
 
PDF
Production profiling: What, Why and How
RichardWarburton
 
PDF
Production profiling what, why and how (JBCN Edition)
RichardWarburton
 
PDF
Production Profiling: What, Why and How
RichardWarburton
 
PDF
Java collections the force awakens
RichardWarburton
 
PDF
Generics Past, Present and Future (Latest)
RichardWarburton
 
PDF
Collections forceawakens
RichardWarburton
 
PDF
Generics past, present and future
RichardWarburton
 
PDF
How to run a hackday
RichardWarburton
 
PDF
Generics Past, Present and Future
RichardWarburton
 
PDF
Pragmatic functional refactoring with java 8 (1)
RichardWarburton
 
PDF
Twins: Object Oriented Programming and Functional Programming
RichardWarburton
 
PDF
Pragmatic functional refactoring with java 8
RichardWarburton
 
PDF
Introduction to lambda behave
RichardWarburton
 
PDF
Introduction to lambda behave
RichardWarburton
 
PDF
Performance and predictability
RichardWarburton
 
PDF
Simplifying java with lambdas (short)
RichardWarburton
 
PDF
Twins: OOP and FP
RichardWarburton
 
PDF
Twins: OOP and FP
RichardWarburton
 
Fantastic performance and where to find it
RichardWarburton
 
Production profiling what, why and how technical audience (3)
RichardWarburton
 
Production profiling: What, Why and How
RichardWarburton
 
Production profiling what, why and how (JBCN Edition)
RichardWarburton
 
Production Profiling: What, Why and How
RichardWarburton
 
Java collections the force awakens
RichardWarburton
 
Generics Past, Present and Future (Latest)
RichardWarburton
 
Collections forceawakens
RichardWarburton
 
Generics past, present and future
RichardWarburton
 
How to run a hackday
RichardWarburton
 
Generics Past, Present and Future
RichardWarburton
 
Pragmatic functional refactoring with java 8 (1)
RichardWarburton
 
Twins: Object Oriented Programming and Functional Programming
RichardWarburton
 
Pragmatic functional refactoring with java 8
RichardWarburton
 
Introduction to lambda behave
RichardWarburton
 
Introduction to lambda behave
RichardWarburton
 
Performance and predictability
RichardWarburton
 
Simplifying java with lambdas (short)
RichardWarburton
 
Twins: OOP and FP
RichardWarburton
 
Twins: OOP and FP
RichardWarburton
 

Recently uploaded (20)

PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Doc9.....................................
SofiaCollazos
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 

Jvm profiling under the hood