jdk安装后会自带一些小工具,jmap命令(Java Memory Map)是其中之一。主要用于打印指定Java进程(或核心文件、远程调试服务器)的共享对象内存映射或堆内存细节。
例1:
命令:jmap -heap pid
描述:显示Java堆详细信息
打印一个堆的摘要信息,包括使用的GC算法、堆配置信息和各内存区域内存使用信息
jmap -heap 5611
Attaching to process ID 5611, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 25.271-b09
using thread-local object allocation.
Mark Sweep Compact GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 268435456 (256.0MB)
NewSize = 5570560 (5.3125MB)
MaxNewSize = 89456640 (85.3125MB)
OldSize = 11206656 (10.6875MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 12582912 (12.0MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 4294963200 (4095.99609375MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 5046272 (4.8125MB)
used = 1646832 (1.5705413818359375MB)
free = 3399440 (3.2419586181640625MB)
32.63462611607143% used
Eden Space:
capacity = 4521984 (4.3125MB)
used = 1614560 (1.539764404296875MB)
free = 2907424 (2.772735595703125MB)
35.70468183876812% used
From Space:
capacity = 524288 (0.5MB)
used = 32272 (0.0307769775390625MB)
free = 492016 (0.4692230224609375MB)
6.1553955078125% used
To Space:
capacity = 524288 (0.5MB)
used = 0 (0.0MB)
free = 524288 (0.5MB)
0.0% used
tenured generation:
capacity = 11206656 (10.6875MB)
used = 7409520 (7.0662689208984375MB)
free = 3797136 (3.6212310791015625MB)
66.11713610197368% used
5109 interned Strings occupying 397496 bytes.
例2
命令:jmap -histo:live pid
描述:显示堆中对象的统计信息
其中包括每个Java类、对象数量、内存大小(单位:字节)、完全限定的类名。打印的虚拟机内部的类名称将会带有一个’*’前缀。如果指定了live子选项,则只计算活动的对象。
num #instances #bytes class name
----------------------------------------------
1: 2580 2986640 [B
2: 27304 2316368 [C
3: 7626 1577272 [I
4: 8714 418272 java.util.concurrent.ConcurrentHashMap$EntryIterator
5: 25061 400976 java.lang.String
6: 6301 296872 [Ljava.lang.Object;
7: 2981 284776 java.lang.Class
8: 8714 209136 java.util.concurrent.ConcurrentHashMap$MapEntry
9: 8679 208296 java.util.HashMap$Node
10: 4289 171560 java.util.HashMap
11: 3617 146984 [Ljava.util.HashMap$Node;
12: 1425 125400 java.lang.reflect.Method
13: 1676 120672 java.lang.reflect.Constructor
14: 1776 113664 java.util.regex.Matcher
15: 3480 83520 java.util.Hashtable$Entry
16: 3046 73104 java.util.concurrent.ConcurrentHashMap$Node
17: 687 71448 java.io.ObjectStreamClass
18: 723 63816 [Ljava.util.Hashtable$Entry;
19: 155 58280 java.lang.Thread
20: 1750 56000 java.io.ObjectStreamClass$WeakClassKey