jmap
Dump Java heap memory information
TLDR
Print shared object mappings for a Java process (output like pmap)
Print heap summary information
Print histogram of heap usage by type
Dump contents of the heap into a binary file for analysis with jhat
Dump live objects of the heap into a binary file for analysis with jhat
SYNOPSIS
jmap [ options ] <pid>
PARAMETERS
-dump[:live,format=b,file=<filename>]
Dump heap to file (format=b for binary hprof; live filters to live objects only)
-finalizerinfo
Print information on objects awaiting finalization
-heap
Show summary of heap configuration and usage
-histo[:live]
Print histogram of heap objects (live shows only live objects)
-clstats | -permstat
Print classloader statistics (permstat deprecated)
-F
Force use of ClassAttachedNativeMemoryCounting for heap dump
-h | -help
Display help message
-J<flag>
Pass JVM flag directly to the runtime
DESCRIPTION
jmap is a command-line utility included with the JDK for inspecting the memory usage of Java Virtual Machine (JVM) processes. It provides detailed information about the heap, object histograms, finalizable objects, and class loader statistics, making it invaluable for diagnosing memory leaks, out-of-memory errors, and performance issues in Java applications.
By specifying a process ID (pid), jmap connects to the target JVM and generates reports on memory allocation. Common use cases include generating heap dumps for analysis with tools like Eclipse MAT or VisualVM, viewing live object histograms to identify dominant classes consuming memory, or summarizing heap configuration and usage. It operates non-intrusively in most cases but can pause the application briefly during heap dumps.
jmap requires the JVM attach mechanism to be enabled (default since JDK 8) and is best used with the same JDK version as the target process for compatibility. It's particularly useful in production environments where full GC pauses need monitoring or when troubleshooting high memory footprints.
CAVEATS
Requires JVM attach listener enabled (-XX:+EnableDynamicAgentLoading); may pause application during operations; use same JDK bitness and version as target JVM; full heap dumps can be large and I/O intensive.
USAGE EXAMPLE
jmap -dump:live,format=b,file=heap.hprof <pid>
jmap -heap <pid>
jmap -histo:live <pid>
HISTORY
Introduced in JDK 1.5 as part of jvmtools; enhanced in JDK 8+ with better attach mechanism and histo:live support; largely superseded by jcmd in JDK 11+ but remains available.


