SlideShare a Scribd company logo
Exploring Java Heap
Dumps
Ryan Cuprak
Java Heap Review
• Java objects are stored in the heap
• All objects are globally reachable in the heap
• Heap is created when an application starts
• Size of heap is configured using –Xmx and –Xmx
• Garbage collection prunes the heap and removes objects
no longer reachable
• Stack memory - variable values are stored when their
methods are invoked
Heap Contains Everything and can be DUMPED to DISK
Why Analyze Heaps?
• IT reports Java EE/Spring server memory footprint has
grown to 9 gigs
• Server app logs contain OutOfMemoryExceptions
• Connections to queueing or database are exhausted
• Serialized Java objects in queue are unreasonably large
• Desktop application becomes unresponsive
• Excessive amount of garbage collection
Java Heap Analysis
MAT
Profiler
All you need is a profiler right?
Memory Leaks
Textbook memory
leaks - easy to find
and fix.
JConsole
Production Heap Dumps
• 9 gigs of data
• 13k classes loaded
• ~ 136 million instances
• ~6,000 GC roots
Production Heap Dumps
Capture the
Heap Dump
and…
Production Heap Dumps
Heap Dump Panic
Too much data!
• Impossible to comprehend
• No human way to explore the data
• Application data model is too
complicated
Real Memory Leaks
Bank Account:
1231209
Owner
Bob
Owner
JulieReport
January 2018
Bank Account:
1231210
Bank Account:
1231209
Report
January 2018
Owner
Bob
Challenge:
Data looks good
everywhere…
Real Memory Leaks
Causes:
• Faulty clone methods
• Duplicate singletons
• Accidently cached data
• Cache logic bugs
Complications
• May NOT GROW over time (leaks gets cleaned-up)
• More than one non-trivial memory leak
What about OQL?
• OQL
• Object Query Language – used for querying heaps
• SQL-like language
• Supports JavaScript expressions
• Supported in NetBeans and VisualVM
• Downside
• Poorly documented and hard to use
• Easy to create runaway queries
Heap Analysis Solution
NetBeans Profiler
• NetBeans is open source IDE/platform
• Modular architecture
• Clean code base
Profiler GUI
Profiler API
NetBeans Profiler API
• Parses hprof files
• Creates an object model representing the hprof file
• Pages data in from disk
• Simple API (master in about 10 minutes)
• Independent of NetBeans
• Can be extract and use in any IDE – Plain old Java
Talk is really about how to build a custom heap analysis tool:
• To answer specific data model questions
• With custom logic for your data model
Generating Heap Dumps
Generating Heap Dumps
• Command line parameter:
• -XX +HeapDumpOnOutOfMemoryError
• Command line:
• jmap –dump:format=b,file=dump.hprof <pid>
• jhsdb jmap --binaryheap --pid <pid>
• jcmd <pid> GC.heap_dump <file name>
• Ctrl-Break
Command Line
Generating Heap Dumps
Programmatic
Generating Heap Dumps
JMX
Heap Dump Warning
Dumping the heap:
• Takes time
• Consumes diskspace
• Negatively affects performance
Targeted Heap Dumps
• Serialize object graphs from application to a file.
• Read the serialized data into another tool and then
programmatically create a heap dump.
Building a Profiler
Building Custom Profiler
Create NetBeans
Platform App
Copy API src out of
NetBeans
NetBeans Platform App
NetBeans Platform App
Add dependency on
“Java Profiler (JFluid)”
Profiler Sources
Checkout source:
https://github.com/apache/incubator-netbeans.git
Profiler code:
netbeans/profiler/lib.profiler/src/netbeans/lib.profiler/heap
Copy heap directory
Which Approach?
• Copying sources easiest
• Most analysis apps are command line (one-offs)
- Note -
You don’t need the classpath of the application from which
the heap was generated.
NetBeans Profiler API
Opening a Heap
That’s All!
Heap Object Methods
getJavaClassByName(String fqn) : JavaClass
getAllClasses() : List
getBiggestObjectsByRetainedSize(int number) : List
getGCRoots(): GCRoot
getInstanceByID(long instanceId) : Instance
getJavaClassByID(long javaclassId) : JavaClass
getJavaClassesByRegExp(String regexp) : HeapSummary
getSummary() : Properties
System Properties
Heap Summary
• getTotalLiveInstances() : long
• getTime() : long
• getTotalAllocatedBytes() : long
• getTotalAllocatedInstances() : long
• getTotalLiveBytes() : long
Exploration Starting Points
• GCRoots
• Threads (really GCRoots)
• Class Types
GC Roots
• Garbage Collection Root is an object that is accessible from
outside the heap.
• Objects that aren’t accessible from a GC Root are garbage
collected
• GC root categorization:
• Class loaded by system class loader
• Thread
• Stack Local
• Monitor
• JNI Reference
• Held by JVM
Garbage Collection Roots
Java frame: 44
thread object: 5
JNI global: 29
sticky class: 1284
GCRoot Objects
GC Roots
JNI_GLOBAL = "JNI global";
JNI_LOCAL = "JNI local";
JAVA_FRAME = "Java frame";
NATIVE_STACK = "native stack";
STICKY_CLASS = "sticky class";
THREAD_BLOCK = "thread block";
MONITOR_USED = "monitor used";
THREAD_OBJECT = "thread object";
UNKNOWN = "unknown";
INTERNED_STRING = "interned string";
FINALIZING = "finalizing";
DEBUGGER = "debugger";
REFERENCE_CLEANUP = "reference cleanup";
VM_INTERNAL = "VM internal";
JNI_MONITOR = "JNI monitor";
root.getKind() : String
Finding Classes
• Can perform lookup using:
• Fully qualified class name (ex. java.lang.String)
• Class ID
• Instance ID
• IDs are unique to heap dump
• Hash codes are not available!
Profiler Data Model
JavaClass
Instance B
Value
Value
Instance A
Value
Value
Class
Java.lang.String
Java.util.List
Instances
From an instance:
• Who references the instance
• Who does the instance
reference
Perform instanceof to find out:
• ObjectArray
• PrimitiveArray
GCRoot can take forever…
Values
If you ask an instance for its
references, you get a list of Value
objects.
Example: Member Variables
Iterates over all Person objects and prints member variables.
Example: Static Variables
Example: References
String Implementation
String Extraction
Strings are objects – array of characters
LinkedList Implementation
LinkedList Implementation
LinkedList Extract
ArrayList
ArrayList
Thread Extraction
Noise: Ignore Internal Classes
Ignore internal JVM classes
Puzzler
Prints: Count: 231
• 230 entries have 1 are referenced by one other object
• 1 entry is “owned” by 822 other objects
Demo App Exploration
Demo App
Note: Used HashSets, Arrays[][], Lists, and Vectors
Demo App
Demo App
Demo App
String Utilization
• 5159 Strings in heap dump
• 15 associated with data model
String Utilization
Output
Data Model Leak
Add logic to fire an employee:
Data Model Leak
Fired Adam – shouldn’t be in the
system!
Data Model Leak
Found!
Data Model Leak
Leaking here!
Best Practices
• Be mindful of your heap
• Cache analysis on disk when processing large heaps
• Heap processing is I/O bound
• Not all profiler calls are the same
• Look for Javadoc: Speed: normal
• Maintain a list of processed objects
• Easy to run in circles
• Exclude JVM internal classes from analysis
• Revisit graph algorithms!
Summary
• Heap snapshot can be easily explored
• Excellent way to verify application logic
• Only way to identify deep data model/logic errors
• Can be used to recover data
• Generate a heap snapshot from a frozen/corrupted application and
then mine
Q&A
Twitter: @ctjava
Email: rcuprak@gmail.com / r5k@3ds.com
Blog: cuprak.info
Linkedin: www.linkedin.com/in/rcuprak
Slides: www.slideshare.net/rcuprak/presentations

More Related Content

What's hot (20)

PPTX
Microservices Part 3 Service Mesh and Kafka
Araf Karsh Hamid
 
PPTX
CQRS and Event Sourcing, An Alternative Architecture for DDD
Dennis Doomen
 
PDF
Scalability, Availability & Stability Patterns
Jonas Bonér
 
PPTX
Dynamic Rule-based Real-time Market Data Alerts
Flink Forward
 
PDF
Orchestrating workflows Apache Airflow on GCP & AWS
Derrick Qin
 
PDF
Introduction SQL Analytics on Lakehouse Architecture
Databricks
 
PDF
Building Data Quality pipelines with Apache Spark and Delta Lake
Databricks
 
PPT
Domain Driven Design (DDD)
Tom Kocjan
 
PPTX
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
PPTX
Apache Kafka Best Practices
DataWorks Summit/Hadoop Summit
 
PDF
Producer Performance Tuning for Apache Kafka
Jiangjie Qin
 
PPTX
Domain Driven Design
Nader Albert
 
PPTX
Domain Driven Design
Araf Karsh Hamid
 
PPTX
Databricks Platform.pptx
Alex Ivy
 
PDF
Transparent Data Encryption in PostgreSQL and Integration with Key Management...
Masahiko Sawada
 
PDF
Apache Spark on K8S Best Practice and Performance in the Cloud
Databricks
 
PDF
Apache Iceberg Presentation for the St. Louis Big Data IDEA
Adam Doyle
 
PDF
Intro to Delta Lake
Databricks
 
PDF
Azure Data Platform Overview.pdf
Dustin Vannoy
 
PPTX
What’s New in Oracle Database 19c - Part 1
Satishbabu Gunukula
 
Microservices Part 3 Service Mesh and Kafka
Araf Karsh Hamid
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
Dennis Doomen
 
Scalability, Availability & Stability Patterns
Jonas Bonér
 
Dynamic Rule-based Real-time Market Data Alerts
Flink Forward
 
Orchestrating workflows Apache Airflow on GCP & AWS
Derrick Qin
 
Introduction SQL Analytics on Lakehouse Architecture
Databricks
 
Building Data Quality pipelines with Apache Spark and Delta Lake
Databricks
 
Domain Driven Design (DDD)
Tom Kocjan
 
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
Apache Kafka Best Practices
DataWorks Summit/Hadoop Summit
 
Producer Performance Tuning for Apache Kafka
Jiangjie Qin
 
Domain Driven Design
Nader Albert
 
Domain Driven Design
Araf Karsh Hamid
 
Databricks Platform.pptx
Alex Ivy
 
Transparent Data Encryption in PostgreSQL and Integration with Key Management...
Masahiko Sawada
 
Apache Spark on K8S Best Practice and Performance in the Cloud
Databricks
 
Apache Iceberg Presentation for the St. Louis Big Data IDEA
Adam Doyle
 
Intro to Delta Lake
Databricks
 
Azure Data Platform Overview.pdf
Dustin Vannoy
 
What’s New in Oracle Database 19c - Part 1
Satishbabu Gunukula
 

Similar to Exploring Java Heap Dumps (Oracle Code One 2018) (20)

PDF
Hp java heap dump analysis Workshop
Madhavan Marimuthu
 
PDF
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Ashish Bhasin
 
PPTX
Heap Dump Analysis - AEM: Real World Issues
Kanika Gera
 
PPTX
Java performance tuning
Mohammed Fazuluddin
 
PDF
Java Memory Analysis: Problems and Solutions
"Mikhail "Misha"" Dmitriev
 
PPTX
Java profiling Do It Yourself
aragozin
 
PPT
Eclipse Memory Analyzer
nayashkova
 
PDF
Debugging Java from Dumps
Chris Bailey
 
PPT
Sporar
oscon2007
 
PPT
Eclipse Memory Analyzer - More Than Just a Heap Walker
guest62fd60c
 
PPTX
Memory Analyzer Tool (MAT)
Samiullah Farooqui
 
PPTX
DIY Java Profiling
Roman Elizarov
 
PDF
Sperasoft‬ talks j point 2015
Sperasoft
 
PDF
Java Performance and Profiling
WSO2
 
PPT
Heap & thread dump
Nishit Charania
 
PPT
Practical lessons in memory analysis
AJohnson1
 
PDF
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
Yuji Kubota
 
ODP
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
jaxLondonConference
 
PDF
Ps ts 4118-304118_230-1_fin_v1
AJohnson1
 
PPT
Javaforum looking into the memory
Squeed
 
Hp java heap dump analysis Workshop
Madhavan Marimuthu
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Ashish Bhasin
 
Heap Dump Analysis - AEM: Real World Issues
Kanika Gera
 
Java performance tuning
Mohammed Fazuluddin
 
Java Memory Analysis: Problems and Solutions
"Mikhail "Misha"" Dmitriev
 
Java profiling Do It Yourself
aragozin
 
Eclipse Memory Analyzer
nayashkova
 
Debugging Java from Dumps
Chris Bailey
 
Sporar
oscon2007
 
Eclipse Memory Analyzer - More Than Just a Heap Walker
guest62fd60c
 
Memory Analyzer Tool (MAT)
Samiullah Farooqui
 
DIY Java Profiling
Roman Elizarov
 
Sperasoft‬ talks j point 2015
Sperasoft
 
Java Performance and Profiling
WSO2
 
Heap & thread dump
Nishit Charania
 
Practical lessons in memory analysis
AJohnson1
 
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
Yuji Kubota
 
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
jaxLondonConference
 
Ps ts 4118-304118_230-1_fin_v1
AJohnson1
 
Javaforum looking into the memory
Squeed
 
Ad

More from Ryan Cuprak (20)

PPTX
Jakarta EE Test Strategies (2022)
Ryan Cuprak
 
PPTX
DIY Home Weather Station (Devoxx Poland 2023)
Ryan Cuprak
 
PPTX
Why jakarta ee matters (ConFoo 2021)
Ryan Cuprak
 
PDF
Polygot Java EE on the GraalVM
Ryan Cuprak
 
PPTX
Node.js Development with Apache NetBeans
Ryan Cuprak
 
PPTX
Preparing for java 9 modules upload
Ryan Cuprak
 
PPTX
Faster Java EE Builds with Gradle
Ryan Cuprak
 
PPTX
Java EE 8
Ryan Cuprak
 
PPTX
Faster Java EE Builds with Gradle
Ryan Cuprak
 
PPTX
Containerless in the Cloud with AWS Lambda
Ryan Cuprak
 
PPTX
Java EE 8 Update
Ryan Cuprak
 
PPTX
Batching and Java EE (jdk.io)
Ryan Cuprak
 
PPTX
Faster java ee builds with gradle [con4921]
Ryan Cuprak
 
PPTX
Java script nirvana in netbeans [con5679]
Ryan Cuprak
 
PPTX
Jms deep dive [con4864]
Ryan Cuprak
 
PPTX
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 
PPTX
Developing in the Cloud
Ryan Cuprak
 
PPTX
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
Ryan Cuprak
 
PPTX
Hybrid Mobile Development with Apache Cordova and
Ryan Cuprak
 
PPTX
JavaFX Versus HTML5 - JavaOne 2014
Ryan Cuprak
 
Jakarta EE Test Strategies (2022)
Ryan Cuprak
 
DIY Home Weather Station (Devoxx Poland 2023)
Ryan Cuprak
 
Why jakarta ee matters (ConFoo 2021)
Ryan Cuprak
 
Polygot Java EE on the GraalVM
Ryan Cuprak
 
Node.js Development with Apache NetBeans
Ryan Cuprak
 
Preparing for java 9 modules upload
Ryan Cuprak
 
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Java EE 8
Ryan Cuprak
 
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Containerless in the Cloud with AWS Lambda
Ryan Cuprak
 
Java EE 8 Update
Ryan Cuprak
 
Batching and Java EE (jdk.io)
Ryan Cuprak
 
Faster java ee builds with gradle [con4921]
Ryan Cuprak
 
Java script nirvana in netbeans [con5679]
Ryan Cuprak
 
Jms deep dive [con4864]
Ryan Cuprak
 
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 
Developing in the Cloud
Ryan Cuprak
 
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
Ryan Cuprak
 
Hybrid Mobile Development with Apache Cordova and
Ryan Cuprak
 
JavaFX Versus HTML5 - JavaOne 2014
Ryan Cuprak
 
Ad

Recently uploaded (20)

PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 

Exploring Java Heap Dumps (Oracle Code One 2018)

Editor's Notes