SlideShare a Scribd company logo
© 2011 IBM Corporation 
Chris Bailey – Java Support Architect 
Debugging from Dumps 
Debugging Applications and Products from Dumps
© 2011 IBM Corporation 
Debugging Strategies 
■ Two common strategies for debugging: 
– 
■ Debugging from Trace: Log or print relevant data at runtime 
– Typical approach used on distributed platforms 
– Pros: History is available, showing how the failure point was reached 
Collected data usually has context via the trace point 
– Cons: only specified data is collected, often resulting in multiple iterations 
ongoing performance overhead to running application 
■ Debugging from “Dumps”: Collect all available data on failure 
– Used widely on on System Z 
– Pros: All available data is collected 
No ongoing performance overhead to application 
– Cons: Very limited history of how the failure point was reached: only current thread stacks 
Limited context around data: only Object or structure types 
■ Using a combination of the two provides powerful debugging capabilities 
– Note: in-memory trace buffers are in the dumps, so can aid with trace data collection!
© 2011 IBM Corporation 
Dump Types 
■ Three different dump types: 
Dump 
Format 
Approx. 
Size on 
Disk 
Objects, 
Classes, 
Class 
Loaders 
Thread 
Details 
Field 
Names 
Field and 
Array 
References 
Primitive 
Fields 
Primitive 
Array 
Contents 
Accurate 
GC Roots 
Native 
Memory 
and 
Threads 
IBM 
PHD 
20% of 
Java heap 
size  with 
Javacore 
*       
HPROF Java heap 
size         
System 
dump 
Java heap 
size + 30%        
© 2011 IBM Corporation 
Dump Generation 
■ Interactive Methods 
– Using a SIGQUIT or Ctrl-Break: 
● When a Ctrl-Break or SIGQUIT (usually generated using "kill -3") is sent to the IBM 
runtime 
● a "user" event is generated in the IBM dump engine 
● can however be configured to generate either a PHD format dump, or a System dump 
using the following command line options to the Java application 
● -Xdump:heap:events=user (PHD Heap Dump) 
● -Xdump:system:events=user (System dump) 
– Using the operating system to produce a system dump: 
● AIX: gencore (or the destructive kill -6 or kill -11) 
● Linux/Solaris: gcore (or the destructive kill -6 or kill -11) 
● Windows: userdump.exe 
● z/OS: SVCDUMP/Console Dump 
– Using IBM Monitoring and Diagnostics Tools for Java - Health Center: 
● The Health Center tool provides a menu option to request dumps from a running Java 
process 
● can request either a PHD or system dump
© 2011 IBM Corporation 
Dump Generation 
■ Interactive Methods 
– Using the wsadmin scripting client: (using Jython with the -lang jython option): 
● Thread dump: 
AdminControl.invoke(AdminControl.completeObjectName("type=JVM,proc 
ess=server1,*"), "dumpThreads") 
● System dump: 
AdminControl.invoke(AdminControl.completeObjectName("type=JVM,proc 
ess=server1,*"), "generateSystemDump") 
● Portable heap dump (PHD): 
AdminControl.invoke(AdminControl.completeObjectName("type=JVM,proc 
ess=server1,*"), "generateHeapDump")
load Class load class name -Xdump:system:events=load,filter=com/ibm/example/Example 
unload Class unload class name -Xdump:system:events=unload,filter=com/ibm/example/Example 
throw An exception being thrown exception name -Xdump:system:events=throw,filter=java/net/ConnectException 
catch An exception being caught exception name -Xdump:system:events=catch,filter=java/net/ConnectException 
systhrow A Java exception is about 
© 2011 IBM Corporation 
Dump Generation 
■ Event Based Methods 
– Using the IBM dump engine: 
● The dump engine provides a large number of events on which you can produce a "heap" 
or "system" dump 
● 
Event Description Filtering Example 
● 
gpf GPF (Crash) -Xdump:system:events=gpf 
● 
user ● 
User generated signal 
● 
vmstop ● 
VM shutdown, including 
● 
● 
● 
● 
● 
● 
● 
● 
allocation A Java object is allocated size of object -Xdump:system:events=allocate,filter=#5m 
● 
(SIGQUIT or Ctrl-Break) 
-Xdump:system:events=user 
call to System.exit() 
exit code -Xdump:system:events=vmstop,filter=#0..#10 
to be thrown by the JVM 
exception name -Xdump:system:events=systhrow, 
filter=java/lang/OutOfMemoryError,range=1..4 
● Exceptions can also be filtered on throwing method using '#' 
– -Xdump:system:events=throw,filter=java/lang/NullPointerException#com/ibm/example/Example.bad
© 2011 IBM Corporation 
Generating Dumps 
■ Event Based Methods 
– Using the IBM trace engine: 
● the trace engine allows PHD and system dumps to be triggered on method entry or exit 
● achieved using the following command line option to the application: 
● produces a system dump when the Example.trigger() method is called 
– -Xtrace:maximal=mt,trigger=method{com/ibm/example/Example.trigger,sysdump} 
● produces a PHD dump when the Example.trigger() method is called 
– -Xtrace:maximal=mt,trigger=method{com/ibm/example/Example.trigger,heapdump} 
● set a range so that you don't create dumps every time the method is called 
– -Xtrace:maximal=mt,trigger=method{com/ibm/example/Example.trigger,sysdump,,5,1} 
– 
■ Programmatic Methods: 
● provide a com.ibm.jvm.Dump class with three methods: 
– javaDump(), heapDump() and systemDump()
© 2011 IBM Corporation 
Generating Dumps 
■ Memory Analyzer also provides an "Acquire 
Heap Dump" option that allows you to trigger 
and load a snapshot dump from a Java process 
running on the same machine as Memory 
Analyzer. 
■ On HotSpot based runtimes the Memory 
Analyzer generates the dump using JMap. 
■ For the IBM runtimes the dump is generated 
using the "late attach" functionality and the the 
programmatic API.
© 2011 IBM Corporation 
0 5000000000 10000000000 15000000000 
350000 
300000 
250000 
200000 
150000 
100000 
50000 
0 
Phil (Linux 64 bit PPC) 
Same Disk 
RAM Disk 
GB Netw ork 
Core Size (bytes) 
Time to Generate (ms) 
Dump Generation 
■ Dump writing speed is relatively quick: 
– ~10s per GB providing physical memory is available 
– Otherwise dictated by disk write speed 
– Can be minimized by good configuration of system: 
● Memory assigned to file caching 
● Use of ramdisks 
■ System dumps compress very well: 
– Usually to 10% of original size
© 2011 IBM Corporation 
IBM Monitoring and Diagnostic Tools for Java – Memory Analyzer 
■ Originally a tool for identifying memory leaks in Java applications 
■ Works with dumps from all major Java vendors: IBM and HotSpot (Oracle, HP-UX, Mac OSX) 
■ Provides a number of functions: 
– Memory leak detection and footprint analysis 
– Memory efficiency analysis 
– Thread stack traces with Object references 
– 
■ Provides extension points to write analysis plugins 
– Used by IBM Extensions for Memory Analyzer
IBM Extensions for Memory Analyzer (IEMA) 
■ Goal: 
build product and subject matter expert knowledge into Memory Analyzer to allow 
users and support to visualize and debug IBM SWG product applications 
■ Development project that extends Memory Analyzer 
– Individual plug-ins for each product 
– 
■ Adoption from multiple products: 
– Java SE 
– WebSphere Application Server 
– WebSphere ESB 
– WebSphere Portal Server 
– CICS Transaction Gateway 
– 40 query plug-ins/custom reports created 
– many more name resolvers (object annotations) 
11 © 2010 IBM Corporation
IBM Extensions for Memory Analyzer – WebSphere Application Server 
© 2011 IBM Corporation 
■ WebSphere Application Server Overview: 
– Install information 
● Version, build level, install directory 
– Server information 
● Server, Node and Cell name, startup and dump times 
– Applications status 
● Applications status: started/stopped/leaking 
– Memory breakdown 
● Applications, HTTP Sessions, WAS Runtime, SIB etc 
■ Thread Pool Analysis: 
– All threads 
● WebSphere thread pools and Java thread groups 
– Thread pool configuration 
● Min and max sizes, ability to grow 
– Current thread count 
– Presence of hung threads 
■ Plus a number of other reports, including: 
– Application Class Loader Leaks and Hung Thread Analysis 
– HA Manager status, HTTP Session details, Web Containter Analysis, Cache status, etc
© 2011 IBM Corporation 
Memory Analyzer Extension Points 
■ See:http://wiki.eclipse.org/MemoryAnalyzer/Extending_Memory_Analyzer 
■ org.eclipse.mat.api.nameResolver 
– Provides readable description of an object in some of MAT's view (like toString()) 
– Annotates object types with detail about an object 
● eg. hostname and port for a Socket object 
■ org.eclipse.mat.report.query 
– Adds a menu item that executes your plug-in code 
– Creates report style output in any form you want: Tree, Text, HTML, Pie Charts, etc.
© 2011 IBM Corporation 
Memory Analyzer API 
■ ISnapshot – Represent one dump 
– Each object and class has a unique Integer ID. Most methods will return an int or array of ints. 
Then you can call snapshot.getObject with the int to get an IObject representing the item 
– 
– getGCRoots – List of all GC roots 
– getClasses – List of all classes (or search by name) 
– getInboundRefererIds – List of incoming references 
– getOutboundReferentIds – List of outgoing references 
– getHeapSize – Shallow heap size of the object 
– getRetainedHeapSize – Retained heap size of the object 
– 
■ IObject – represents an item in the heap 
– getObjectAddress – This is the address of the object in the Java heap 
– getClazz – Get the class of an object 
– getUsedHeapSize/getRetainedHeapSize – Same as ISnapshot 
– getDisplayName – The class, address, and name resolver 
– resolveValue – For an IBM system dump or HPROF dump, given a name of a field, find the 
object representing that field. This identifier can have periods which separate going down that 
tree of items.
Get the String name of the object field 
© 2011 IBM Corporation 
Memory Analyzer Extension Points: nameResolver 
import org.eclipse.mat.SnapshotException; 
import org.eclipse.mat.snapshot.extension.IClassSpecificNameResolver; 
import org.eclipse.mat.snapshot.extension.Subject; 
import org.eclipse.mat.snapshot.model.IObject; 
@Subject("com.ibm.ws.webcontainer.webapp.WebAppImpl") 
public class WebApp implements IClassSpecificNameResolver { 
public String resolve(IObject object){ 
String result = null; 
try { 
Lookup field value 
IObject appName = (IObject)object.resolveValue("applicationName"); 
IObject contextPath = (IObject)object.resolveValue("contextPath"); 
if (appName != null && contextPath != null) { 
result = appName.getClassSpecificName() + " at " + 
contextPath.getClassSpecificName(); 
} 
} catch (SnapshotException e) { 
e.printStackTrace(); 
} 
return result; 
} 
} 
■ NameResolvers “annotate” objects with a line of text: 
Select object type to “annotate” 
Return String with text to annotate
© 2011 IBM Corporation 
Memory Analyzer API 
■ IResult – What a query returns 
– TextResult – Plain text or HTML content 
– ObjectListResult – Grid of results with in/outbound refs 
– SectionSpec – Separate results into sections 
● Add QuerySpecs 
– PieFactory...build() - Generate a pie chart 
– ListResult – Table of items 
– CompositeResult – Display results in separate tabs
Find the Hung Threads 
© 2011 IBM Corporation 
Memory Analyzer Extensions: query 
import org.eclipse.mat.SnapshotException; 
import org.eclipse.mat.snapshot.extension.IClassSpecificNameResolver; 
import org.eclipse.mat.snapshot.extension.Subject; 
import org.eclipse.mat.snapshot.model.IObject; 
Set name of query in menu 
@Name("Hung Thread Stacks") 
@Category(WASHelper.WAS_CATEGORY + WASHelper.HUNGTHREADS_SUBCATEGORY) 
@Help("List any threads that may be hung.nn") 
public class HungThreadsList extends BasePlugin { 
public IResult execute(IProgressListener listener) throws Exception { 
int[] hungThreadIds = HungThreads.getHungThreadIds(snapshot); 
return new HungThreadsListOutgoingReferencesTree( 
hungThreadIds, listener); 
} 
■ Queries produce “reports” available from pull down menus: 
Set category in menu 
Return “IResult” report
© 2011 IBM Corporation 
Finding the Hung Threads 
public static int[] getHungThreadIds(ISnapshot snapshot) 
throws SnapshotException { 
int[] threadIds = findObjects(snapshot, "java.lang.Thread"); 
List<Integer> hungThreads = new ArrayList<Integer>(); 
for (int thr : threadIds) { 
IObject thrObj = snapshot.getObject(thr); 
if (isThreadHung(thrObj)) { 
hungThreads.add(thr); 
} 
} 
int[] hungThreadObjectIds = getArrayIntegers(hungThreads); 
return hungThreadObjectIds; 
} 
■ findObjects() makes it easy to find all objects of a give type 
■ Returns a list of ObjectIds (ints) for the hung threads 
Find all Threads 
Check if the Thread is hung 
Return the hung threads
© 2011 IBM Corporation 
Checking if the Thread is hung 
public static boolean isThreadHung(IObject thread) throws SnapshotException { 
boolean result = false; 
boolean isHung = MATHelper.resolveValueBool(thread, "isHung"); 
if (isHung != null && isHung.booleanValue()) { 
result = true; 
} 
return result; 
} 
■ Hung thread status found by checking boolean field “isHung” 
Get isHung field 
Check value of field 
Return field value
© 2011 IBM Corporation 
Displaying the Hung Threads 
public class HungThreadsListOutgoingReferencesTree extends OutgoingReferencesTree { 
private static final int sortIndex = COLUMN_INDEX_MAX_BUILTIN + 2; 
public HungThreadsListOutgoingReferencesTree(ISnapshot snapshot, 
int[] roots, IProgressListener listener) 
throws SnapshotException { 
super(snapshot, roots, listener); 
} 
■ Customization used to add additional columns to output report: 
– Last Dispatch Time and Estimated Time Hung 
■ Displays a Tree view of outgoing references, from the hung threads 
Customized 
OutgoingReferencesTree
© 2011 IBM Corporation 
IBM Monitoring and Diagnostic Tools for Java – IDDE 
■ Interactive Diagnostic Data Explorer (IDDE) 
■ Provides a visual representation of your set of dump files 
■ An investigation log editor in which you run commands. This editor provides the following features: 
– Command assistance 
– Auto-completion of text 
– The ability to save commands and output, which you can then send to other people 
– Highlighted text and flagging of issues 
– The ability to add your own comments 
■ An outline view to help you navigate the commands and output in the log editor 
■ The ability to create your own commands, as plug-ins, and import plug-ins created by others

More Related Content

What's hot (20)

PPTX
Modern Java Workshop
Simon Ritter
 
PPT
Find bottleneck and tuning in Java Application
guest1f2740
 
PDF
From Java code to Java heap: Understanding and optimizing your application's ...
Chris Bailey
 
PPTX
Magento 2 Workflows
Ryan Street
 
PDF
Practicing Continuous Deployment
zeeg
 
PDF
[NYC Meetup] Docker at Nuxeo
Nuxeo
 
PPTX
Gruntwork Executive Summary
Yevgeniy Brikman
 
PDF
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ColdFusionConference
 
PDF
Using GPUs to handle Big Data with Java by Adam Roberts.
J On The Beach
 
PPTX
Ch10.애플리케이션 서버의 병목_발견_방법
Minchul Jung
 
PDF
Using GPUs to Handle Big Data with Java
Tim Ellison
 
PDF
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
Ji-Woong Choi
 
PDF
Java MySQL Connector & Connection Pool Features & Optimization
Kenny Gryp
 
PDF
Performance Benchmarking of Clouds Evaluating OpenStack
Pradeep Kumar
 
PDF
Javascript TDD with Jasmine, Karma, and Gulp
All Things Open
 
ODP
Nagios Conference 2014 - Troy Lea - Monitoring VMware Virtualization Using vMA
Nagios
 
PPTX
Nagios Conference 2014 - Jeff Mendoza - Monitoring Microsoft Azure with Nagios
Nagios
 
PDF
D2
taobao.com
 
PPT
Hazelcast
Jeevesh Pandey
 
PDF
Apache Commons Pool and DBCP - Version 2 Update
Phil Steitz
 
Modern Java Workshop
Simon Ritter
 
Find bottleneck and tuning in Java Application
guest1f2740
 
From Java code to Java heap: Understanding and optimizing your application's ...
Chris Bailey
 
Magento 2 Workflows
Ryan Street
 
Practicing Continuous Deployment
zeeg
 
[NYC Meetup] Docker at Nuxeo
Nuxeo
 
Gruntwork Executive Summary
Yevgeniy Brikman
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ColdFusionConference
 
Using GPUs to handle Big Data with Java by Adam Roberts.
J On The Beach
 
Ch10.애플리케이션 서버의 병목_발견_방법
Minchul Jung
 
Using GPUs to Handle Big Data with Java
Tim Ellison
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
Ji-Woong Choi
 
Java MySQL Connector & Connection Pool Features & Optimization
Kenny Gryp
 
Performance Benchmarking of Clouds Evaluating OpenStack
Pradeep Kumar
 
Javascript TDD with Jasmine, Karma, and Gulp
All Things Open
 
Nagios Conference 2014 - Troy Lea - Monitoring VMware Virtualization Using vMA
Nagios
 
Nagios Conference 2014 - Jeff Mendoza - Monitoring Microsoft Azure with Nagios
Nagios
 
Hazelcast
Jeevesh Pandey
 
Apache Commons Pool and DBCP - Version 2 Update
Phil Steitz
 

Similar to Debugging Java from Dumps (20)

ODP
Windows Debugging Tools - JavaOne 2013
MattKilner
 
PDF
A165 tools for java and javascript
Toby Corbin
 
PDF
WebSphere Technical University: Introduction to the Java Diagnostic Tools
Chris Bailey
 
PPT
Eclipse Memory Analyzer - More Than Just a Heap Walker
guest62fd60c
 
PDF
Web Sphere Problem Determination Ext
Rohit Kelapure
 
PPT
Eclipse Memory Analyzer
nayashkova
 
PDF
Impact2014: Introduction to the IBM Java Tools
Chris Bailey
 
PDF
Introduction to the IBM Java Tools
Chris Bailey
 
PPTX
How to build a debuggle runtime
Tobi Ajila
 
PPTX
Memory Analyzer Tool (MAT)
Samiullah Farooqui
 
PDF
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
Chris Bailey
 
PDF
Hp java heap dump analysis Workshop
Madhavan Marimuthu
 
PPTX
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
PPTX
Heap Dump Analysis - AEM: Real World Issues
Kanika Gera
 
PDF
What Your Jvm Has Been Trying To Tell You
John Pape
 
PPT
Using and Extending Memory Analyzer into Uncharted Waters
Vladimir Pavlov
 
ODP
Debugging Native heap OOM - JavaOne 2013
MattKilner
 
PDF
Java performance - not so scary after all
Holly Cummins
 
PDF
Java Performance and Profiling
WSO2
 
PDF
Java Performance and Using Java Flight Recorder
Isuru Perera
 
Windows Debugging Tools - JavaOne 2013
MattKilner
 
A165 tools for java and javascript
Toby Corbin
 
WebSphere Technical University: Introduction to the Java Diagnostic Tools
Chris Bailey
 
Eclipse Memory Analyzer - More Than Just a Heap Walker
guest62fd60c
 
Web Sphere Problem Determination Ext
Rohit Kelapure
 
Eclipse Memory Analyzer
nayashkova
 
Impact2014: Introduction to the IBM Java Tools
Chris Bailey
 
Introduction to the IBM Java Tools
Chris Bailey
 
How to build a debuggle runtime
Tobi Ajila
 
Memory Analyzer Tool (MAT)
Samiullah Farooqui
 
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
Chris Bailey
 
Hp java heap dump analysis Workshop
Madhavan Marimuthu
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
Heap Dump Analysis - AEM: Real World Issues
Kanika Gera
 
What Your Jvm Has Been Trying To Tell You
John Pape
 
Using and Extending Memory Analyzer into Uncharted Waters
Vladimir Pavlov
 
Debugging Native heap OOM - JavaOne 2013
MattKilner
 
Java performance - not so scary after all
Holly Cummins
 
Java Performance and Profiling
WSO2
 
Java Performance and Using Java Flight Recorder
Isuru Perera
 
Ad

More from Chris Bailey (20)

PDF
NodeJS Interactive 2019: FaaS meets Frameworks
Chris Bailey
 
PDF
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Chris Bailey
 
PDF
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Chris Bailey
 
PDF
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
Chris Bailey
 
PDF
AltConf 2019: Server-Side Swift State of the Union
Chris Bailey
 
PDF
Server-side Swift with Swagger
Chris Bailey
 
PDF
Node Summit 2018: Cloud Native Node.js
Chris Bailey
 
PDF
Index - BFFs vs GraphQL
Chris Bailey
 
PDF
Swift Cloud Workshop - Swift Microservices
Chris Bailey
 
PDF
Swift Cloud Workshop - Codable, the key to Fullstack Swift
Chris Bailey
 
PDF
Try!Swift India 2017: All you need is Swift
Chris Bailey
 
PDF
Swift Summit 2017: Server Swift State of the Union
Chris Bailey
 
PDF
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
Chris Bailey
 
PDF
IBM Cloud University: Java, Node.js and Swift
Chris Bailey
 
PDF
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Chris Bailey
 
PDF
FrenchKit 2017: Server(less) Swift
Chris Bailey
 
PDF
AltConf 2017: Full Stack Swift in 30 Minutes
Chris Bailey
 
PDF
InterConnect: Server Side Swift for Java Developers
Chris Bailey
 
PDF
InterConnect: Java, Node.js and Swift - Which, Why and When
Chris Bailey
 
PDF
Playgrounds: Mobile + Swift = BFF
Chris Bailey
 
NodeJS Interactive 2019: FaaS meets Frameworks
Chris Bailey
 
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Chris Bailey
 
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Chris Bailey
 
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
Chris Bailey
 
AltConf 2019: Server-Side Swift State of the Union
Chris Bailey
 
Server-side Swift with Swagger
Chris Bailey
 
Node Summit 2018: Cloud Native Node.js
Chris Bailey
 
Index - BFFs vs GraphQL
Chris Bailey
 
Swift Cloud Workshop - Swift Microservices
Chris Bailey
 
Swift Cloud Workshop - Codable, the key to Fullstack Swift
Chris Bailey
 
Try!Swift India 2017: All you need is Swift
Chris Bailey
 
Swift Summit 2017: Server Swift State of the Union
Chris Bailey
 
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
Chris Bailey
 
IBM Cloud University: Java, Node.js and Swift
Chris Bailey
 
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Chris Bailey
 
FrenchKit 2017: Server(less) Swift
Chris Bailey
 
AltConf 2017: Full Stack Swift in 30 Minutes
Chris Bailey
 
InterConnect: Server Side Swift for Java Developers
Chris Bailey
 
InterConnect: Java, Node.js and Swift - Which, Why and When
Chris Bailey
 
Playgrounds: Mobile + Swift = BFF
Chris Bailey
 
Ad

Recently uploaded (20)

PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 

Debugging Java from Dumps

  • 1. © 2011 IBM Corporation Chris Bailey – Java Support Architect Debugging from Dumps Debugging Applications and Products from Dumps
  • 2. © 2011 IBM Corporation Debugging Strategies ■ Two common strategies for debugging: – ■ Debugging from Trace: Log or print relevant data at runtime – Typical approach used on distributed platforms – Pros: History is available, showing how the failure point was reached Collected data usually has context via the trace point – Cons: only specified data is collected, often resulting in multiple iterations ongoing performance overhead to running application ■ Debugging from “Dumps”: Collect all available data on failure – Used widely on on System Z – Pros: All available data is collected No ongoing performance overhead to application – Cons: Very limited history of how the failure point was reached: only current thread stacks Limited context around data: only Object or structure types ■ Using a combination of the two provides powerful debugging capabilities – Note: in-memory trace buffers are in the dumps, so can aid with trace data collection!
  • 3. © 2011 IBM Corporation Dump Types ■ Three different dump types: Dump Format Approx. Size on Disk Objects, Classes, Class Loaders Thread Details Field Names Field and Array References Primitive Fields Primitive Array Contents Accurate GC Roots Native Memory and Threads IBM PHD 20% of Java heap size  with Javacore *       HPROF Java heap size         System dump Java heap size + 30%        
  • 4. © 2011 IBM Corporation Dump Generation ■ Interactive Methods – Using a SIGQUIT or Ctrl-Break: ● When a Ctrl-Break or SIGQUIT (usually generated using "kill -3") is sent to the IBM runtime ● a "user" event is generated in the IBM dump engine ● can however be configured to generate either a PHD format dump, or a System dump using the following command line options to the Java application ● -Xdump:heap:events=user (PHD Heap Dump) ● -Xdump:system:events=user (System dump) – Using the operating system to produce a system dump: ● AIX: gencore (or the destructive kill -6 or kill -11) ● Linux/Solaris: gcore (or the destructive kill -6 or kill -11) ● Windows: userdump.exe ● z/OS: SVCDUMP/Console Dump – Using IBM Monitoring and Diagnostics Tools for Java - Health Center: ● The Health Center tool provides a menu option to request dumps from a running Java process ● can request either a PHD or system dump
  • 5. © 2011 IBM Corporation Dump Generation ■ Interactive Methods – Using the wsadmin scripting client: (using Jython with the -lang jython option): ● Thread dump: AdminControl.invoke(AdminControl.completeObjectName("type=JVM,proc ess=server1,*"), "dumpThreads") ● System dump: AdminControl.invoke(AdminControl.completeObjectName("type=JVM,proc ess=server1,*"), "generateSystemDump") ● Portable heap dump (PHD): AdminControl.invoke(AdminControl.completeObjectName("type=JVM,proc ess=server1,*"), "generateHeapDump")
  • 6. load Class load class name -Xdump:system:events=load,filter=com/ibm/example/Example unload Class unload class name -Xdump:system:events=unload,filter=com/ibm/example/Example throw An exception being thrown exception name -Xdump:system:events=throw,filter=java/net/ConnectException catch An exception being caught exception name -Xdump:system:events=catch,filter=java/net/ConnectException systhrow A Java exception is about © 2011 IBM Corporation Dump Generation ■ Event Based Methods – Using the IBM dump engine: ● The dump engine provides a large number of events on which you can produce a "heap" or "system" dump ● Event Description Filtering Example ● gpf GPF (Crash) -Xdump:system:events=gpf ● user ● User generated signal ● vmstop ● VM shutdown, including ● ● ● ● ● ● ● ● allocation A Java object is allocated size of object -Xdump:system:events=allocate,filter=#5m ● (SIGQUIT or Ctrl-Break) -Xdump:system:events=user call to System.exit() exit code -Xdump:system:events=vmstop,filter=#0..#10 to be thrown by the JVM exception name -Xdump:system:events=systhrow, filter=java/lang/OutOfMemoryError,range=1..4 ● Exceptions can also be filtered on throwing method using '#' – -Xdump:system:events=throw,filter=java/lang/NullPointerException#com/ibm/example/Example.bad
  • 7. © 2011 IBM Corporation Generating Dumps ■ Event Based Methods – Using the IBM trace engine: ● the trace engine allows PHD and system dumps to be triggered on method entry or exit ● achieved using the following command line option to the application: ● produces a system dump when the Example.trigger() method is called – -Xtrace:maximal=mt,trigger=method{com/ibm/example/Example.trigger,sysdump} ● produces a PHD dump when the Example.trigger() method is called – -Xtrace:maximal=mt,trigger=method{com/ibm/example/Example.trigger,heapdump} ● set a range so that you don't create dumps every time the method is called – -Xtrace:maximal=mt,trigger=method{com/ibm/example/Example.trigger,sysdump,,5,1} – ■ Programmatic Methods: ● provide a com.ibm.jvm.Dump class with three methods: – javaDump(), heapDump() and systemDump()
  • 8. © 2011 IBM Corporation Generating Dumps ■ Memory Analyzer also provides an "Acquire Heap Dump" option that allows you to trigger and load a snapshot dump from a Java process running on the same machine as Memory Analyzer. ■ On HotSpot based runtimes the Memory Analyzer generates the dump using JMap. ■ For the IBM runtimes the dump is generated using the "late attach" functionality and the the programmatic API.
  • 9. © 2011 IBM Corporation 0 5000000000 10000000000 15000000000 350000 300000 250000 200000 150000 100000 50000 0 Phil (Linux 64 bit PPC) Same Disk RAM Disk GB Netw ork Core Size (bytes) Time to Generate (ms) Dump Generation ■ Dump writing speed is relatively quick: – ~10s per GB providing physical memory is available – Otherwise dictated by disk write speed – Can be minimized by good configuration of system: ● Memory assigned to file caching ● Use of ramdisks ■ System dumps compress very well: – Usually to 10% of original size
  • 10. © 2011 IBM Corporation IBM Monitoring and Diagnostic Tools for Java – Memory Analyzer ■ Originally a tool for identifying memory leaks in Java applications ■ Works with dumps from all major Java vendors: IBM and HotSpot (Oracle, HP-UX, Mac OSX) ■ Provides a number of functions: – Memory leak detection and footprint analysis – Memory efficiency analysis – Thread stack traces with Object references – ■ Provides extension points to write analysis plugins – Used by IBM Extensions for Memory Analyzer
  • 11. IBM Extensions for Memory Analyzer (IEMA) ■ Goal: build product and subject matter expert knowledge into Memory Analyzer to allow users and support to visualize and debug IBM SWG product applications ■ Development project that extends Memory Analyzer – Individual plug-ins for each product – ■ Adoption from multiple products: – Java SE – WebSphere Application Server – WebSphere ESB – WebSphere Portal Server – CICS Transaction Gateway – 40 query plug-ins/custom reports created – many more name resolvers (object annotations) 11 © 2010 IBM Corporation
  • 12. IBM Extensions for Memory Analyzer – WebSphere Application Server © 2011 IBM Corporation ■ WebSphere Application Server Overview: – Install information ● Version, build level, install directory – Server information ● Server, Node and Cell name, startup and dump times – Applications status ● Applications status: started/stopped/leaking – Memory breakdown ● Applications, HTTP Sessions, WAS Runtime, SIB etc ■ Thread Pool Analysis: – All threads ● WebSphere thread pools and Java thread groups – Thread pool configuration ● Min and max sizes, ability to grow – Current thread count – Presence of hung threads ■ Plus a number of other reports, including: – Application Class Loader Leaks and Hung Thread Analysis – HA Manager status, HTTP Session details, Web Containter Analysis, Cache status, etc
  • 13. © 2011 IBM Corporation Memory Analyzer Extension Points ■ See:http://wiki.eclipse.org/MemoryAnalyzer/Extending_Memory_Analyzer ■ org.eclipse.mat.api.nameResolver – Provides readable description of an object in some of MAT's view (like toString()) – Annotates object types with detail about an object ● eg. hostname and port for a Socket object ■ org.eclipse.mat.report.query – Adds a menu item that executes your plug-in code – Creates report style output in any form you want: Tree, Text, HTML, Pie Charts, etc.
  • 14. © 2011 IBM Corporation Memory Analyzer API ■ ISnapshot – Represent one dump – Each object and class has a unique Integer ID. Most methods will return an int or array of ints. Then you can call snapshot.getObject with the int to get an IObject representing the item – – getGCRoots – List of all GC roots – getClasses – List of all classes (or search by name) – getInboundRefererIds – List of incoming references – getOutboundReferentIds – List of outgoing references – getHeapSize – Shallow heap size of the object – getRetainedHeapSize – Retained heap size of the object – ■ IObject – represents an item in the heap – getObjectAddress – This is the address of the object in the Java heap – getClazz – Get the class of an object – getUsedHeapSize/getRetainedHeapSize – Same as ISnapshot – getDisplayName – The class, address, and name resolver – resolveValue – For an IBM system dump or HPROF dump, given a name of a field, find the object representing that field. This identifier can have periods which separate going down that tree of items.
  • 15. Get the String name of the object field © 2011 IBM Corporation Memory Analyzer Extension Points: nameResolver import org.eclipse.mat.SnapshotException; import org.eclipse.mat.snapshot.extension.IClassSpecificNameResolver; import org.eclipse.mat.snapshot.extension.Subject; import org.eclipse.mat.snapshot.model.IObject; @Subject("com.ibm.ws.webcontainer.webapp.WebAppImpl") public class WebApp implements IClassSpecificNameResolver { public String resolve(IObject object){ String result = null; try { Lookup field value IObject appName = (IObject)object.resolveValue("applicationName"); IObject contextPath = (IObject)object.resolveValue("contextPath"); if (appName != null && contextPath != null) { result = appName.getClassSpecificName() + " at " + contextPath.getClassSpecificName(); } } catch (SnapshotException e) { e.printStackTrace(); } return result; } } ■ NameResolvers “annotate” objects with a line of text: Select object type to “annotate” Return String with text to annotate
  • 16. © 2011 IBM Corporation Memory Analyzer API ■ IResult – What a query returns – TextResult – Plain text or HTML content – ObjectListResult – Grid of results with in/outbound refs – SectionSpec – Separate results into sections ● Add QuerySpecs – PieFactory...build() - Generate a pie chart – ListResult – Table of items – CompositeResult – Display results in separate tabs
  • 17. Find the Hung Threads © 2011 IBM Corporation Memory Analyzer Extensions: query import org.eclipse.mat.SnapshotException; import org.eclipse.mat.snapshot.extension.IClassSpecificNameResolver; import org.eclipse.mat.snapshot.extension.Subject; import org.eclipse.mat.snapshot.model.IObject; Set name of query in menu @Name("Hung Thread Stacks") @Category(WASHelper.WAS_CATEGORY + WASHelper.HUNGTHREADS_SUBCATEGORY) @Help("List any threads that may be hung.nn") public class HungThreadsList extends BasePlugin { public IResult execute(IProgressListener listener) throws Exception { int[] hungThreadIds = HungThreads.getHungThreadIds(snapshot); return new HungThreadsListOutgoingReferencesTree( hungThreadIds, listener); } ■ Queries produce “reports” available from pull down menus: Set category in menu Return “IResult” report
  • 18. © 2011 IBM Corporation Finding the Hung Threads public static int[] getHungThreadIds(ISnapshot snapshot) throws SnapshotException { int[] threadIds = findObjects(snapshot, "java.lang.Thread"); List<Integer> hungThreads = new ArrayList<Integer>(); for (int thr : threadIds) { IObject thrObj = snapshot.getObject(thr); if (isThreadHung(thrObj)) { hungThreads.add(thr); } } int[] hungThreadObjectIds = getArrayIntegers(hungThreads); return hungThreadObjectIds; } ■ findObjects() makes it easy to find all objects of a give type ■ Returns a list of ObjectIds (ints) for the hung threads Find all Threads Check if the Thread is hung Return the hung threads
  • 19. © 2011 IBM Corporation Checking if the Thread is hung public static boolean isThreadHung(IObject thread) throws SnapshotException { boolean result = false; boolean isHung = MATHelper.resolveValueBool(thread, "isHung"); if (isHung != null && isHung.booleanValue()) { result = true; } return result; } ■ Hung thread status found by checking boolean field “isHung” Get isHung field Check value of field Return field value
  • 20. © 2011 IBM Corporation Displaying the Hung Threads public class HungThreadsListOutgoingReferencesTree extends OutgoingReferencesTree { private static final int sortIndex = COLUMN_INDEX_MAX_BUILTIN + 2; public HungThreadsListOutgoingReferencesTree(ISnapshot snapshot, int[] roots, IProgressListener listener) throws SnapshotException { super(snapshot, roots, listener); } ■ Customization used to add additional columns to output report: – Last Dispatch Time and Estimated Time Hung ■ Displays a Tree view of outgoing references, from the hung threads Customized OutgoingReferencesTree
  • 21. © 2011 IBM Corporation IBM Monitoring and Diagnostic Tools for Java – IDDE ■ Interactive Diagnostic Data Explorer (IDDE) ■ Provides a visual representation of your set of dump files ■ An investigation log editor in which you run commands. This editor provides the following features: – Command assistance – Auto-completion of text – The ability to save commands and output, which you can then send to other people – Highlighted text and flagging of issues – The ability to add your own comments ■ An outline view to help you navigate the commands and output in the log editor ■ The ability to create your own commands, as plug-ins, and import plug-ins created by others