Heap dump

Heap dumps contain a snapshot of all the live objects that are being used by a running Java™ application on the Java heap. You can obtain detailed information for each object instance, such as the address, type, class name, or size, and whether the instance has references to other objects.

There are two formats for heap dumps; the classic format and the Portable Heap Dump (PHD) format, which is the default. Whilst the classic format is generated in ascii text and can be read, the PHD format is binary and and must be processed for analysis.

Obtaining dumps

Heap dumps are generated by default in PHD format when the Java heap runs out of space. If you want to trigger the production of a heap dump in response to other situations, or in classic format, you can use one of the following options:

Analyzing dumps

The best method to analyze a PHD heap dump is to use the Eclipse Memory Analyzer™ tool (MAT) or the IBM Memory Analyzer tool. These tools process the dump file and provide a visual representation of the objects in the Java Heap. Both tools require the Diagnostic Tool Framework for Java (DTFJ) plugin. To install the DTFJ plugin in the Eclipse IDE, select the following menu items:

Help > Install New Software > Work with "IBM Diagnostic Tool Framework for Java" > IBM Monitoring and Diagnostic Tools > Diagnostic Tool Framework for Java   

The following sections contain detailed information about the content of each type of heap dump file.

Portable Heap Dump (PHD) format

A PHD format dump file contains a header section and a body section. The body section can contain information about object, array, or class records. Primitive numbers are used to describe the file format, as detailed in the following table:

Primitive number Length in bytes
byte 1
short 2
int 4
long 8
word 4 (32-bit platforms) or 8 (64-bit platforms)

General structure

The following structure comprises the header section of a PHD file:

The body of a PHD file is indicated by a byte that contains a tag with a value of 2, after which there are a number of dump records. Dump records are preceded by a 1 byte tag with the following record types:

These records are described in more detail in the sections that follow.

The end of the PHD body is indicated by a byte that contains a tag with a value of 3.

Object records

Object records can be short, medium, or long, depending on the number of object references in the heap dump.

1. Short object record

The following information is contained within the tag byte:

2. Medium object record

These records provide the actual address of the class rather than a cache index. The following format is used:

3. Long object record

This record format is used when there are more than 7 references, or if there are extra flags or a hash code. The following format is used:

Array records

PHD arrays can be primitive arrays or object arrays, as described in the sections that follow.

1. Primitive array record

The following information is contained in an array record:

2. Long primitive array record

This type of record is used when a primitive array has been hashed.

3. Object array record

The following format applies:

Class records

The PHD class record encodes a class object and contains the following format:

Classic Heap Dump format

Classic heap dumps are produced in ascii text on all platforms except z/OS, which are encoded in EBCDIC. The dump is divided into the following sections:

Header record

A single string containing information about the runtime environment, platform, and build levels, similar to the following example:

// Version: JRE 1.8.0 Linux amd64-64 (build 1.8.0_232-b09)

Object records

A record of each object instance in the heap with the following format:

<object address, in hexadecimal> [<length in bytes of object instance, in decimal>] OBJ <object type>
<heap reference, in hexadecimal> <heap reference, in hexadecimal> ...

The following object types (object type) might be shown:

These types are abbreviated in the record. To determine the type, see the Java VM Type Signature table.

Any references found are also listed, excluding references to an object's class or NULL references.

The following example shows an object instance (16 bytes in length) of type java/lang/String, with a reference to a char array:

0x00000000E0000AF0 [16] OBJ java/lang/String
    0x00000000E0000B00

The object instance (length 32 bytes) of type char array, as referenced from the java/lang/String, is shown in the following example:

0x00000000E0000B00 [32] OBJ [C

The following example shows an object instance (24 bytes in length) of type array of java/lang/String:

0x00000000FFF07498 [24] OBJ [Ljava/lang/String;
    0x00000000E0005D78 0x00000000E0005D50 0x00000000E0005D28 0x00000000E0005D00

Class records

A record of each class in the following format:

<class object address, in hexadecimal> [<length in bytes of class object, in decimal>] CLS <class type>
<heap reference, in hexadecimal> <heap reference, in hexadecimal>...

The following class types (<class type>) might be shown:

These types are abbreviated in the record. To determine the type, see the Java VM Type Signature table.

Any references found in the class block are also listed, excluding NULL references.

The following example shows a class object (80 bytes in length) for java/util/Date, with heap references:

0x00000000E00174F0 [80] CLS java/util/Date
    0x00000000FFF1BB60 0x00000000FFF29630

Trailer record 1

A single record containing record counts, in decimal.

For example:

// Breakdown - Classes: 630, Objects: 3692, ObjectArrays: 576, PrimitiveArrays: 2249

Trailer record 2

A single record containing totals, in decimal.

For example:

// EOF:  Total 'Objects',Refs(null) : 7147,22040(12379)

The values in the example reflect the following counts:

Java VM Type Signatures

The following table shows the abbreviations used for different Java types in the heap dump records:

Java VM Type Signature Java Type
Z boolean
B byte
C char
S short
I int
J long
F float
D double
L<fully-qualified class>; <fully-qualified class>
[<type> <type>[](array of <type>)
(<arg-types>)<ret-type> method

See also