Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.
Java Boot Camp - Debugging Java OOM Using Memory Analyzer
-
Upload
jayamma-venkat -
Category
Documents
-
view
53 -
download
7
Transcript of Java Boot Camp - Debugging Java OOM Using Memory Analyzer
© 2011 IBM Corporation
Java Runtime Problem Determination & Tooling Boot Camp Series:
Debugging Java OOM issues using Memory Analyzer
2 © 2011 IBM Corporation
Important Disclaimers
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES.
ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.
IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.
IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION.
NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:
- CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS
© 2011 IBM Corporation3
Agenda
■ What is java heap OOM– Diagnostic data to be collected
■ How to interpret the memory leak analysis results?
■ Understanding Shallow & Retained Size
■ Why Memory Analyzer?
■ Memory Analyzer features Overview:– Overview– Leak Suspects– System Overview– Top Consumers– Thread details/attributes– Object Query Language
■ Memory Analyzer Extension Plug-ins
■ Running Memory Analyzer in “Batch” Mode
© 2011 IBM Corporation4
What is Java heap OOM
The Java application receives Java OutOfMemory exception when the process has exhaused all the space available in Java heap
The causes for Java heap OOM can be
● Incorrect heap settings
● Fragmentation
● Memory leaks
Diagnostics data to be collected:
● output of -verbose:gc
● heapdumps/system dumps collected in a interval of time
© 2011 IBM Corporation5
How to interpret the Memory Leak Analysis Results?
Monitoring GC activity from the verbose GC using GCMV tool
6 © 2011 IBM Corporation
How to interpret the memory leak analysis results?
■ Not an exact science, analysis will point out suspects■ Likelihood of leak depends on the
– Size of leaking data structure– Drop size– Number of leaking units– Number of instances of objects in Ownership Context Graph Nodes
■ Better comparative analysis results, if baseline heap dump is taken early and primary heap dump is taken after a large increase in the occupied heap size
■ Better single dump analysis, if primary heap dump is taken after a large increase in the occupied heap size
7 © 2011 IBM Corporation
How to interpret the Memory Leak Analysis Results?
What is leaking?■ What is the object (e.g. a HashMap) holding all the leaking objects i.e. leak container?■ What are the objects getting added to the leak container i.e. leak unit?■ Who is holding the leak container in memory? What are the object types and package
names of objects on the chain of references from a root object to the leak container i.e. owner chain?
8 © 2011 IBM Corporation
View of the leaking data structure
Significant entities
– An owner chain– A leak root– A container– The unit of the leak– Leak contents
9 © 2011 IBM Corporation
Understanding Shallow & Retained Size
■ A is the root object
■ A has outgoing references (Children) to B and C
■ B has an incoming reference (Parent) from A and outgoing reference (Children) to B1 and B2
Shallow size = Size of an object
Retained Size = Total size of the subtree
10 © 2011 IBM Corporation
Understanding Shallow & Retained Size
Size of A = 100 (Shallow Size)Total Size of A = 140 (Retained Size)(A+B+B1+B2+C+C1+C2)
11 © 2011 IBM Corporation
Understanding Shallow Size & Retained Size
Consider the Size of B1 = 1000 (Shallow Size)
Total Size of A (root object) = 1135 (Retained Size)
Here B1 is the biggest in size and is a suspect
12 © 2011 IBM Corporation
What is Memory Analyzer ?
■ The Eclipse Memory Analyzer (MA) is a powerful, feature rich, interactive tool which helps developers find and fix memory leaks quickly in simple steps.
■ Uses less memory to analyze millions of objects quickly and helps you find who is preventing the GC from collecting an object
✔ Allows developers to track the memory leaks in java applications during runtime✔ Graphical representation of memory utilization✔ Ability to filter and view graphical reports of specific criteria✔ Provision to view the trace details and reference class for a particular class instance
13 © 2011 IBM Corporation
Memory Analyzer features -Overview
Memory Analyzer provides an overview report that provides information on the Java heap usage.
A default report which shows how the java heap is used by the objects.
14 © 2011 IBM Corporation
Memory Analyzer features -Leak Suspects
A default report which shows probable leak suspects: large objects or collections of objects that contribute significantly to the Java heap usage, and displays information about those suspects:
● memory utilization
● number of instances
● total memory usage
● owning class details
15 © 2011 IBM Corporation
Memory Analyzer features -System Overview
This view gives a general understanding of the Java application being analyzed.
● The Java heap usage
● System property settings
● Thread details
● Class histogram of the memory usage.
16 © 2011 IBM Corporation
Memory Analyzer features - Top Consumers
This view gives a breakdown of the Java heap usage by
● largest objects
● class loaders
● classes
Provides a high level insight into which
J2EE application is contributing most
to the overall memory footprint.
17 © 2011 IBM Corporation
Memory Analyzer features - Class Loader Explorer query
This view generates a table showing
● class loader name
● defined classes
● number of live instances.
18 © 2011 IBM Corporation
Memory Analyzer features - Thread details/attributes
The “Threads overview” gives an overview of all the threads in the heap, showing properties that include the
● Name
● Object
● context class loader
19 © 2011 IBM Corporation
Memory Analyzer features - Query Language
Very similar to SQL:
Consider classes as tables, objects as rows and attributes as columns.
● SELECT * FROM java.lang.String
● SELECT * FROM java.lang.String s WHERE s.length < 1024
● SELECT * FROM java.lang.String s WHERE dominatorof(s) != NULL and classof(dominatorof(s)).@name = "com.test.Test“
Produces table of results from which you can do interactive analysis
20 © 2011 IBM Corporation
Memory Analyzer -Other features
Other built-in features include
● Finalizer Overview query
● Java Collections queries
● Path To GC Roots query
● Show retained set query
21 © 2011 IBM Corporation
Memory Analyzer Extension Plug-ins
Memory Analyzer provides an extension point for writing analysis plug-ins
■ It provides a public API for accessing Java objects, classes and fields on the Java heap
■ Provides APIs for looking at relationships between objects
■ Provides APIs for generating reports and charts
22 © 2011 IBM Corporation
Memory Analyzer Extension Plug-ins
The IBM Extensions for Memory Analyzer (IEMA) include the set of free plugins available for download
● These plugins extend Memory Analyzer tool with product-specific knowledge.
● Some of the plugins are already available for different products including for WAS,CICS.
23 © 2011 IBM Corporation
Running Memory Analyzer in “Batch” Mode
Batch processing of dumps is possible with MA■ Allows initial processing and report generation to be handled on higher end boxes■ Produces standard reports: Leak Suspects, System Overview, Top Components■ Produces “index” files
Command to run in Batch Mode
[JAVA_HOME]\jre\bin\java –Xmx[nnnnM] -Dosgi.bundles=org.eclipse.mat.dtfj@4:start,org.eclipse.equinox.common@2:start,org.eclipse.update.configurator@3:start,org.eclipse.core.runtime@start -jar [MA_HOME]\plugins\org.eclipse.equinox.launcher*.jar -consoleLog -application org.eclipse.mat.api.parse [heapdump] [MA_Reports]
Where MA_Reports can be
● Overview – "org.eclipse.mat.api:overview"
● Leak Suspects - "org.eclipse.mat.api:suspects"
● Top Components - "org.eclipse.mat.api:top_components“