Java Heapdump
Generate
Heapdump for Sun JDK:
-XX:+HeapDumpOnOutOfMemoryError
Generate
Heapdump for IBM JDK
1.4
http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=/com.ibm.java.doc.diagnostics.60/html/env_jvm.html
set
IBM_HEAP_DUMP=true
set IBM_HEAPDUMP=true
set
IBM_HEAPDUMP_OUTOFMEMORY=true
set
IBM_JAVADUMP_OUTOFMEMORY=true
set IBM_JAVA_HEAPDUMP_TEXT=true
IBM_HEAPDUMP
or IBM_HEAP_DUMP:
Setting either of these to any value
(such as true) enables heap dump production by means of
signals.
IBM_HEAPDUMP_OUTOFMEMORY:
When
set to TRUE or 1 - generates a heapdump each time an out-of-memory
exception is thrown, even if it is
handled.
IBM_JAVADUMP_OUTOFMEMORY:
When
set to TRUE or 1 - generates a Javadump each time an out-of-memory
exception is thrown, even if it is handled.
IBM_HEAPDUMPDIR:
Specify
an alternative location for Heapdump files.
IBM_JAVACOREDIR:
Specify
an alternative location for Javadump files
IBM_JAVA_HEAPDUMP_TEXT:
Use
this environment variable to cause the JVM to generate a text (human
readable) Heapdump.
JAVA_DUMP_OPTS:
Use
this environment variable to control the conditions under which
Heapdumps (and other dumps) are produced.
The
recommended way of controlling the production of diagnostic data is
the -Xdump command-line option. However, if you do use
JAVA_DUMP_OPTS, the recommended default value is:
JAVA_DUMP_OPTS="ONERROR (JAVADUMP,SYSDUMP) ONEXCEPTION
(JAVADUMP,SYSDUMP), ONDUMP (JAVADUMP)"
see Using
Heapdump
Using Heapdump
Heapdump
is an IBM JVM facility that generates a dump of all the reachable
objects that are on the Java heap. It shows the objects that are
using large amounts of memory on the Java heap, and what is
preventing them from being collected by the Garbage Collector.
You
can generate a Heapdump in either of two ways:
Explicit
generation
JVM-triggered generation
Explicit
generation of a Heapdump
You can explicitly generate a
Heapdump in either of the following ways:
By sending a signal to
the JVM from the operating system
By using the HeapDump() method
inside Java code that is being executed
For
Linux and AIX, send the JVM the signal SIGQUIT (kill -QUIT or -3, or
Ctrl+\ in the console window): kill -3 proceessID
For Windows,
generate a SIGINT (press the Ctrl+Break keys simultaneously).
You
can explicitly request a Heapdump from a Java method. The class
com.ibm.jvm.Dump contains a static HeapDump() method that causes Java
code to initiate a Heapdump, provided that the IBM_HEAPDUMP
environment variable is set.
Triggered
generation of a Heapdump
The following events
automatically trigger the JVM to produce a Heapdump:
A fatal
native exception occurs in the JVM (not a Java Exception)
An
OutOfMemory or heap exhaustion condition occurs (optional)
Location
of the generated Heapdump
The location that is
specified by the IBM_HEAPDUMPDIR environment variable,if set
(_CEE_DMPTARG on z/OS).
The current working directory of the JVM
processes
The location that is specified by the TMPDIR environment
variable, if set
The /tmp directory (X:\tmp for Windows, where X
is the current working drive)
Format of
Heapdump filenames
Windows
heapdump.YYYYMMDD.HHMMSS.PID.txt
Linux & AIX
heapdumpPID.TIME.txt
z/OS HEAPDUMP.YYYYMMDD.HHMMSS.PID.txt
Note:
PID is the process ID. TIME is the number of seconds since
1/1/1970
Using VerboseGC to obtain heap
information
Use the VerboseGC utility to obtain
information about the Java Object heap in real time while running
your Java applications. To activate this utility, run Java with the
-verbosegc option:
java -verbosegc
JVM
environment settings -- general options
Heap
size
The maximum heap size is controlled by the -Xmx
option.
The initial size of the heap is controlled by the -Xms
option.
CLASSPATH
A list
of directories for the JVM to find user class files, paths, or both
to individual Java archive or .compressed files that contain class
files
Heapdump or JavaCore Analyze
Tools:
Eclipse
Memory Analyzer (MAT)
The Eclipse Memory Analyzer is a fast
and feature-rich Java heap analyzer that helps you find memory leaks
and reduce memory consumption.
IBM
HeapAnalyzer
HeapAnalyzer analyzes Java heap dumps by parsing
the Java heap dump, creating directional graphs, transforming them
into directional trees, and executing the heuristic search engine.
IBM Thread and
Monitor Dump Analyzer for Java:jca
A tool that allows
identification of hangs, deadlocks, resource contention, and
bottlenecks in Java threads.