Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Understanding of Java Heap and Thread Dump

What is a Heap Dump

A heap dump is a snapshot of the memory of all the objects in the Java Virtual Machine (JVM) heap at a
certain point in time.

The snapshot contains information about the Java objects and classes in the heap at the moment the
snapshot is triggered. Because there are different formats for persisting this data, there might be some
differences in the information provided. Typically, a full garbage collection is triggered before the heap
dump is written, so the dump contains information about the remaining objects in the heap.

The JVM software allocates memory for objects from the heap for all class instances and arrays. The
garbage collector reclaims the heap memory when an object is no longer needed and there are no
references to the object.

What is a Thread Dump

A thread dump is a snapshot of the state of all threads that are part of the process. The state of each
thread is presented with a so called stack trace, which shows the contents of a thread’s stack. Some of
the threads belong to the Java application you are running, while others are JVM internal threads.

A thread dump reveals information about an application’s thread activity that can help you diagnose
problems and better optimize application and JVM performance; for example, thread dumps
automatically show the occurrence of a deadlock. Deadlocks bring some or all of an application to a
complete halt.

A Java thread dump is a way of finding out what every thread in the JVM is doing at a particular point in
time. This is especially useful if your Java application sometimes seems to hang when running under
load, as an analysis of the dump will show where the threads are stuck.

The thread dump is a snapshot of exactly what's executing at a moment in time.

An explanation of terms that relate to the Java™ heap.

The following terms are used to describe objects in the Java heap:

Shallow heap

The amount of memory that is consumed by one object. An object requires different amounts of
memory depending on the operating system architecture.

Retained set
One or more objects plus any objects that are referenced, directly or indirectly, only from those original
objects. The retained set is the set of objects that would be removed by garbage collection when an
object, or multiple objects, is garbage collected.

The following diagram represents objects in the Java heap. Objects A and B are garbage collection roots,
for example method parameters, locally created objects, or objects that are used for wait(), notify(), or
synchronized() methods. The set of objects A and B has a retained set consisting of objects A, B, C, D, E,
F, G, and H.

If, for example, object G was referenced by a garbage collection root other than A or B, then object G
would remain if objects A and B were removed during garbage collection. Object G would therefore not
be in the retained set of objects A and B.

Retained heap, or retained size

The total heap size of all the objects in the retained set. This value is the amount of memory that is
consumed by all the objects that are kept alive by the objects at the root of the retained set.

Further Reading:

https://dzone.com/articles/eclipse-mat-shallow-heap-retained-heap

You might also like