JVM command line monitoring tool jmap (JVM Memory Map)

Introduction to jmap

On the one hand, jmap (JVM Memory Map) can obtain dump files (heap dump snapshot files, binary files), and it can also obtain memory-related information of the target Java process, including the usage of each area of ​​the Java heap and the statistics of objects in the heap. , class loading information, etc.
insert image description here

Options effect
-dump Generate dump file
-finalizerinfo Use ClassLoader as the statistical caliber to output the memory status information of the permanent generation
-heap Output detailed information of the entire heap space, including GC usage, heap configuration information, and memory usage information, etc.
-histo Output statistics of objects in heap space, including class, number of instances, and total capacity
-permstat Use ClassLoader as the statistical caliber to output the memory status information of the permanent generation
-F Force the generation of a dump file when the virtual machine process does not respond to the -dump option

1) Export the memory image file

Heap dump, also known as heap dump file, refers to a memory snapshot of a Java process at a certain point in time.
Note: Usually, a Full GC is performed before the heap dump file is written, so the heap dump saves all the object information left after the Full GC.

Manual export

insert image description here

[root@bogon ~]# jmap -dump:format=b,file=/opt/1.hprof 12023
Dumping heap to /opt/1.hprof ...
Heap dump file created
[root@bogon ~]# jmap -dump:live,format=b,file=/opt/2.hprof 12023
Dumping heap to /opt/2.hprof ...
Heap dump file created

automatic export

The following parameters are configured in the JVM. When OOM occurs, the current heap snapshot of the application will be exported.

-XX:+HeapDumpOnOutOfMemoryError 
-XX:HeapDumpPath=/opt/3.hprof

2) Display heap memory related information

jmap -heap

[root@bogon ~]# jmap -heap 12023
Attaching to process ID 12023, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.144-b01

using thread-local object allocation.
Mark Sweep Compact GC

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 90
   MaxHeapSize              = 8388608 (8.0MB)
   NewSize                  = 2752512 (2.625MB)
   MaxNewSize               = 2752512 (2.625MB)
   OldSize                  = 5636096 (5.375MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 2490368 (2.375MB)
   used     = 0 (0.0MB)
   free     = 2490368 (2.375MB)
   0.0% used
Eden Space:
   capacity = 2228224 (2.125MB)
   used     = 0 (0.0MB)
   free     = 2228224 (2.125MB)
   0.0% used
From Space:
   capacity = 262144 (0.25MB)
   used     = 0 (0.0MB)
   free     = 262144 (0.25MB)
   0.0% used
To Space:
   capacity = 262144 (0.25MB)
   used     = 0 (0.0MB)
   free     = 262144 (0.25MB)
   0.0% used
tenured generation:
   capacity = 5636096 (5.375MB)
   used     = 283800 (0.27065277099609375MB)
   free     = 5352296 (5.104347229003906MB)
   5.035400390625% used

749 interned Strings occupying 50616 bytes.

jmap -histo

insert image description here

jmap -histo  12023

Since jmap will access all objects in the heap, in order to ensure that it will not be disturbed by application threads during this process, jmap needs to use the safety point mechanism to keep all threads in a state where the data in the heap is not changed. That is to say, the heap snapshot exported by jmap must be at the safepoint location. This can lead to biased analysis results based on the pair of snapshots.

For example, suppose some heap objects have lifetimes between two safepoints in the compiled machine code, then the :live option will not detect these objects.

In addition, if a thread cannot run to the safe point for a long time, jmap will wait forever. Unlike jstat, the garbage collector will actively save the summary data required by jstat to a fixed location, while jstat only needs to read it directly .

3) View the ClassLoader information of the system

jmap -clstats 14237

insert image description here

4) View the objects accumulated in the finalizer queue

insert image description here

Guess you like

Origin blog.csdn.net/fengsheng5210/article/details/123666894