Java Platform, Standard Edition Troubleshooting Guide
Contents    Previous    Next

2.14 The jmap Utility

The jmap command-line utility prints memory-related statistics for a running VM or core file.

The utility can also use the jsadebugd daemon to query a process or core file on a remote machine. Note: The output takes longer to print in this case.

The release of JDK 8 introduced Java Mission Control, Java Flight Recorder, and jcmd utility for diagnosing problems with JVM and Java applications. It is suggested to use the latest utility, jcmd instead of the previous jmap utility for enhanced diagnostics and reduced performance overhead.

If jmap is used with a process or core file without any command-line options, then it prints the list of shared objects loaded (the output is similar to the pmap utility on Oracle Solaris operating system). For more specific information, you can use the options -heap, -histo, or -permstat. These options are described in the subsections that follow.

In addition, the JDK 7 release introduced the -dump:format=b,file=filename option, which causes jmap to dump the Java heap in binary HPROF format to a specified file. This file can then be analyzed with the jhat tool.

If the jmap pid command does not respond because of a hung process, then the -F option can be used (on Oracle Solaris and Linux operating systems only) to force the use of the Serviceability Agent.

For more details on the jmap utility, see the jmap command man page.

The following sections describe jmap command usage and troubleshooting techniques with examples that print memory-related statistics for a running VM or a core file.

2.14.1 Heap Configuration and Usage

The -heap option is used to obtain the following Java heap information:

  • Information specific to the garbage collection (GC) algorithm, including the name of the GC algorithm (for example, parallel GC) and algorithm-specific details (such as number of threads for parallel GC).

  • Heap configuration that might have been specified as command-line options or selected by the VM based on the machine configuration.

  • Heap usage summary: For each generation (area of the heap), the tool prints the total heap capacity, in-use memory, and available free memory. If a generation is organized as a collection of spaces (for example, the new generation), then a space specific memory size summary is included.

Example 2-22 shows output from the jmap -heap command.

2.14.2 Heap Histogram

The jmap command with the -histo option can be used to obtain a class specific histogram of the heap. Depending on the parameter specified, the jmap -histo command can print out the heap histogram for a running process or a core file.

When the command is executed on a running process, the tool prints the number of objects, memory size in bytes, and fully qualified class name for each class. Internal classes in the Java HotSpot VM are enclosed in angle brackets. The histogram is useful in understanding how the heap is used. To get the size of an object, you must divide the total size by the count of that object type.

Example 2-23 shows output from the jmap -histo command when it is executed on a process with PID number 29620.

When the jmap -histo command is executed on a core file, the tool prints the size, count, and class name for each class. Internal classes in the Java HotSpot VM are prefixed with an asterisk (*).

Example 2-24 shows output of the jmap -histo command when it is executed on a core file.

2.14.3 Class Loader Statistics

Use the jmap command with the -clstats option to print class loader statistics for the Java heap.

The jmap command connects to a running process using the process ID and prints detailed information about classes loaded in the Metaspace:

  • class_loader: The address of the class loader object at the snapshot when the utility was run
  • classes: The number of classes loaded
  • bytes: The approximate number of bytes consumed by metadata for all classes loaded by this class loader
  • parent_loader: The address of the parent class loader (if any)
  • alive?: A live or dead indication of whether the loader object will be garbage collected in the future
  • type: The class name of this class loader

The following example shows the output from the jmap -clstats command when it is executed on a process with PID number 16624.

$ jmap -clstats 16624
Attaching to process ID 16624, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.211-b12
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness.liveness analysis may be inaccurate ...
class_loader    classes bytes   parent_loader   alive?  type

<bootstrap>     982     1845411   null          live    <internal>
0x000000076f5081e0      1948    3133806   null          dead    sun/misc/Launcher$ExtClassLoader@0x00000007c000fc80
0x000000076e13d3d0      1       1481      null          dead    sun/reflect/DelegatingClassLoader@0x00000007c000a028
0x000000076ca9e100      0       0       0x000000076f510178      dead    java/util/ResourceBundle$RBClassLoader@0x00000007c01ade48
0x000000076f510178      38      94160   0x000000076f5081e0      dead    sun/misc/Launcher$AppClassLoader@0x00000007c000f8d8

total = 5       2969    5074858     N/A         alive=1, dead=4     N/A
Contents    Previous    Next

Copyright © 1993, 2024, Oracle and/or its affiliates. All rights reserved.