jmap
打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量)。
语法
jmap [ option ] pid
jmap [ option ] executable core
jmap [ option ] [server-id@]remote-hostname-or-IP
-dump:[live,]format=b,file=<filename>
使用hprof二进制形式,输出jvm的heap内容到文件=. live子选项是可选的,假如指定live选项,那么只输出活的对象到文件.-finalizerinfo
打印正等候回收的对象的信息.-heap
打印heap的概要信息,GC使用的算法,heap的配置及wise heap的使用情况.-histo[:live]
打印每个class的实例数目,内存占用,类全名信息. VM的内部类名字开头会加上前缀”*”. 如果live子参数加上后,只统计活的对象数量.-permstat
打印classload和jvm heap长久层的信息. 包含每个classloader的名字,活泼性,地址,父classloader和加载的class数量. 另外,内部String的数量和占用内存数也会打印出来.-F
强迫.在pid没有相应的时候使用-dump或者-histo参数. 在这个模式下,live子参数无效.-h | -help
打印辅助信息-
常用参数
-histo
jmap -histo pid 展示class的内存情况 ```shell $ jmap -histo 17948 Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
num #instances #bytes class name
1: 41173 17906640 [B 2: 457459 14638688 java.util.concurrent.locks.AbstractQueuedSynchronizer$Node 3: 98229 11211472 [C 4: 10284 11136880 [I 5: 155842 8727152 java.util.concurrent.ConcurrentHashMap$KeyIterator 6: 253325 8106400 java.util.ArrayList$Itr 7: 155935 6237400 java.util.HashMap$KeyIterator 8: 194915 4677960 java.util.LinkedList$Node 9: 194699 4672776 com.intellij.rt.debugger.agent.CaptureStorage$HardKey 10: 156076 3745824 java.util.Collections$UnmodifiableCollection$1 11: 79073 3162920 java.util.TreeMap$Entry 12: 62396 2495840 java.util.HashMap$ValueIterator 13: 78240 1877760 java.util.concurrent.CopyOnWriteArrayList$COWIterator ….
<a name="weFBP"></a>
#### -finalizerinfo
打印等待回收的对象信息
```shell
$ jmap -finalizerinfo 17948
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Attaching to process ID 17948, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.45-b02
Number of objects pending for finalization: 0
-heap
jmap -heap pid 展示pid的整体堆信息
$ jmap -heap 17948
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Attaching to process ID 17948, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.45-b02
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0 #-XX:MinHeapFreeRatio设置JVM堆最小空闲比率
MaxHeapFreeRatio = 100 #-XX:MaxHeapFreeRatio设置JVM堆最大空闲比率
MaxHeapSize = 4271898624 (4074.0MB) #-XX:MaxHeapSize=设置JVM堆的最大大小
NewSize = 89128960 (85.0MB) #-XX:NewSize=设置JVM堆的‘新生代’的默认大小
MaxNewSize = 1423966208 (1358.0MB) #-XX:MaxNewSize=设置JVM堆的‘新生代’的最大大小
OldSize = 179306496 (171.0MB) #-XX:OldSize=设置JVM堆的‘老生代’的大小
NewRatio = 2 #-XX:NewRatio=:‘新生代’和‘老生代’的大小比率
SurvivorRatio = 8 #-XX:SurvivorRatio=设置年轻代中Eden区与Survivor区的大小比值
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space: :#Eden区内存分布
capacity = 123207680 (117.5MB)
used = 104699296 (99.84902954101562MB)
free = 18508384 (17.650970458984375MB)
84.97789748171543% used
From Space: #其中一个Survivor区的内存分布
capacity = 8388608 (8.0MB)
used = 7976216 (7.606712341308594MB)
free = 412392 (0.39328765869140625MB)
95.08390426635742% used
To Space: #另一个Survivor区的内存分布
capacity = 11010048 (10.5MB)
used = 0 (0.0MB)
free = 11010048 (10.5MB)
0.0% used
PS Old Generation #当前的Old区内存分布
capacity = 83886080 (80.0MB)
used = 5990344 (5.712837219238281MB)
free = 77895736 (74.28716278076172MB)
7.141046524047852% used
13040 interned Strings occupying 1135008 bytes.