JVM tool guide · jvm cli

jmap: Inspect the JVM Heap and Dump It for Analysis

jmap (Java Memory Map) is the bundled tool for inspecting a running JVM's heap: it prints heap summaries, histograms of object counts by class, the process memory map, and — most importantly — can capture a full heap dump to a file for offline analysis.

Since JDK 9, the recommended way to dump a heap is jcmd GC.heap_dump, but jmap remains widely deployed and its -histo output is a fast way to see 'which classes dominate this heap' without opening a GUI.

Official jmap project

Use it when

• You want a quick histogram of what is in the heap (top object counts / sizes by class).

• You need a heap dump file for Eclipse MAT, JProfiler, or YourKit.

• You need the process memory map or class-loader data from a live JVM.

Skip it when

• You prefer jcmd's unified interface — jcmd GC.heap_dump is the modern replacement for jmap -dump.

• The JVM has attach disabled (same limitation as jcmd).

Histogram of objects in the heap

-histo counts instances and total size per class. The output is sorted by instance count or total size depending on the flag; -histo:live restricts to reachable objects.

# Count and size of each class on the heap
jmap -histo:live <pid>

# Limit to the top 30 by total size
jmap -histo:live <pid> | sort -k3 -n -r | head -30

Heap summary

-heap prints a compact summary of the heap configuration and usage, plus a per-generation breakdown. Great first signal for 'is this thing out of heap'.

jmap -heap <pid>

Capture a heap dump

-dump writes a .hprof file you can open in Eclipse MAT. -dump:live only serializes reachable objects, making the dump smaller and usually the right choice.

# Dump live heap to file
jmap -dump:live,file=/tmp/heap.hprof <pid>

# Dump everything
jmap -dump:file=/tmp/heap-full.hprof <pid>

Process memory map

-clstats and -finalizerinfo give class-loader statistics and pending finalizers; for the raw address map use the OS tools (pmap on Linux).

# Class-loader statistics
jmap -clstats <pid>

# Pending finalizer info
jmap -finalizerinfo <pid>
Quick start

Get productive in minutes

Fastest look + a dump

In under a minute you get a histogram and a dump you can hand to MAT.

jmap -histo:live <pid> | head -30
jmap -dump:live,file=/tmp/heap.hprof <pid>

Frequently asked questions

jmap vs jcmd GC.heap_dump — which is better?

jcmd GC.heap_dump is the modern, recommended path and works uniformly with other jcmd commands. jmap's -dump is functionally equivalent and perfectly fine. Use whichever you remember.

Why do my -histo numbers differ between runs?

The heap changes between the point the count is taken and when you read it; GC can run between the object snapshot and the size computation. Treat -histo as a strong signal, not a precise audit.

Can jmap cause pauses?

Capturing a heap dump is not free: the JVM must serialize the object graph, which can pause GC and raise memory pressure. Do it in a quiet window and prefer -dump:live to keep the dump smaller.

Last updated August 2026 · JVM Tools is independent and not affiliated with Oracle.