概述
Jmap是java简单的查看内存使用情况工具,可以对一些使用情况进行查询。
可以生成heap dump文件,也可以使用-XX:+HeapDumpOnOutOfMemoryError
参数让虚拟机出现OOM的时候自动生成dump文件。
命令格式
- jmap [ option ] pid
- jmap [ option ] executable core
- jmap [ option ] [server-id@]remote-hostname-or-IP
常用命令
jmap -heap pid
说明:打印heap空间的概要信息
using parallel threads in the new generation. ##新生代采用的是并行线程处理方式
using thread-local object allocation.
Concurrent Mark-Sweep GC ##同步并行垃圾回收
Heap Configuration: ##堆配置情况
MinHeapFreeRatio = 40 ##最小堆使用比例
MaxHeapFreeRatio = 70 ##最大堆可用比例
MaxHeapSize = 2147483648 (2048.0MB) ##最大堆空间大小
NewSize = 268435456 (256.0MB) ##新生代分配大小
MaxNewSize = 268435456 (256.0MB) ##最大可新生代分配大小
OldSize = 5439488 (5.1875MB) ##老生代大小
NewRatio = 2 ##新生代比例
SurvivorRatio = 8 ##新生代与suvivor的比例
PermSize = 134217728 (128.0MB) ##perm区大小
MaxPermSize = 134217728 (128.0MB) ##最大可分配perm区大小
...
jmap -dump:live,format=b,file=xxx 2657
说明:此方式能够产生指定存活的对象结果
dump堆到文件,format指定输出格式,live指明是活着的对象,file指定文件名。
jmap -histo:live pid
说明:查看实例内容
num #instances #bytes class name
----------------------------------------------
1: 51844 7793984 [C
2: 17515 1541320 java.lang.reflect.Method
3: 50676 1216224 java.lang.String
4: 8309 928304 java.lang.Class
5: 28187 901984 java.util.concurrent.ConcurrentHashMap$Node
6: 12532 501280 java.util.LinkedHashMap$Entry
7: 8037 454800 [Ljava.lang.Object;
注:
第一列:编号id
第二列:实例个数
第三列:所有实例大小
第四列:类名
显示前几条
显示类是否加载
命令后面加上| grep className
显示类是否加载
-permstat:打印一些持久代上的内存使用状态
实例
1.打印实际线程输出结果:
[nobody@aliyun-APP-170-10 logs]$ jmap -heap 11399
Attaching to process ID 11399, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.65-b04
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 536870912 (512.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 21757952 (20.75MB)
MaxPermSize = 134217728 (128.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 44040192 (42.0MB)
used = 35082336 (33.457122802734375MB)
free = 8957856 (8.542877197265625MB)
79.65981619698661% used
From Space:
capacity = 524288 (0.5MB)
used = 327680 (0.3125MB)
free = 196608 (0.1875MB)
62.5% used
To Space:
capacity = 524288 (0.5MB)
used = 0 (0.0MB)
free = 524288 (0.5MB)
0.0% used
PS Old Generation
capacity = 89653248 (85.5MB)
used = 75464792 (71.96883392333984MB)
free = 14188456 (13.531166076660156MB)
84.17407476414017% used
PS Perm Generation
capacity = 63963136 (61.0MB)
used = 58953904 (56.22282409667969MB)
free = 5009232 (4.7771759033203125MB)
92.16856409291752% used
27397 interned Strings occupying 3112776 bytes.
- 打印出永久带的内容:
[nobody@aliyun-APP-170-10 logs]$ jmap -permstat 11399
Attaching to process ID 11399, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.65-b04
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> 3637 20196224 null live <internal>
0x00000000e3895908 1 3048 null dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e3661fa0 1 3048 null dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e230c920 0 0 0x00000000e017b5e8 dead
com/alibaba/fastjson/util/ASMClassLoader@0x00000000daa4c500
0x00000000e1172830 29 368864 0x00000000e037c0c8 live com/alibaba/fastjson/util/ASMClassLoader@0x00000000d92261a0
0x00000000e3892a98 1 3048 0x00000000e037c0c8 dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e2754380 45 394184 0x00000000e037c0c8 live org/apache/jasper/servlet/JasperLoader@0x00000000db147870
0x00000000e38951d8 1 3048 null dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e017b5e8 117 1172624 0x00000000e017b638 live sun/misc/Launcher$AppClassLoader@0x00000000d8213318
0x00000000e1fc73f0 1 6680 0x00000000e017b598 live org/apache/catalina/loader/WebappClassLoader@0x00000000d8db2618
0x00000000e1fcca80 0 0 0x00000000e037c0c8 live com/alibaba/fastjson/util/ASMClassLoader@0x00000000d92261a0
0x00000000e3892700 1 3048 0x00000000e037c0c8 dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e2224558 1 6680 0x00000000e017b598 live org/apache/catalina/loader/WebappClassLoader@0x00000000d8db2618
0x00000000e22ac0c8 49 332968 0x00000000e017b598 live org/apache/catalina/loader/WebappClassLoader@0x00000000d8db2618
0x00000000e366dbf8 1 3048 null dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e1fd7890 0 0 0x00000000e037c0c8 live com/alibaba/fastjson/util/ASMClassLoader@0x00000000d92261a0
0x00000000e001c408 0 0 0x00000000e017b5e8 dead java/util/ResourceBundle$RBClassLoader@0x00000000d8408280
0x00000000e3892e30 1 3048 0x00000000e037c0c8 dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e017b638 115 642528 null live sun/misc/Launcher$ExtClassLoader@0x00000000d81ba4f8
0x00000000e027a778 4 13776 null dead javax/management/remote/rmi/NoCallStackClassLoader@0x00000000d8757bb8
0x00000000e3895570 1 3048 0x00000000e037c0c8 dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e1a6b7e8 85 724464 0x00000000e037c0c8 live com/alibaba/fastjson/util/ASMClassLoader@0x00000000d92261a0
0x00000000e1a89ce8 0 0 0x00000000e037c0c8 live com/alibaba/fastjson/util/ASMClassLoader@0x00000000d92261a0
0x00000000e1a811e8 0 0 0x00000000e037c0c8 live com/alibaba/fastjson/util/ASMClassLoader@0x00000000d92261a0
0x00000000e1fc0ab0 0 0 0x00000000e037c0c8 live com/alibaba/fastjson/util/ASMClassLoader@0x00000000d92261a0
0x00000000e027a840 2 32144 null dead javax/management/remote/rmi/NoCallStackClassLoader@0x00000000d8757bb8
0x00000000e3892368 1 3048 null dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e3662320 1 3048 null dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e037c0c8 4804 27974784 0x00000000e017b598 live org/apache/catalina/loader/WebappClassLoader@0x00000000d8db2618
0x00000000e3661c20 1 3048 0x00000000e037c0c8 dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e017b598 1546 13312232 0x00000000e017b5e8 live org/apache/catalina/loader/StandardClassLoader@0x00000000d8803c68
0x00000000e36618a0 1 3048 null dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e3661520 1 3048 null dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e36611a0 1 3048 0x00000000e037c0c8 dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e3891fd0 1 3048 0x00000000e037c0c8 dead sun/reflect/DelegatingClassLoader@0x00000000d804fc00
0x00000000e1a74290 0 0 0x00000000e037c0c8 live com/alibaba/fastjson/util/ASMClassLoader@0x00000000d92261a0
0x00000000e21436b0 1 6680 0x00000000e017b598 live org/apache/catalina/loader/WebappClassLoader@0x00000000d8db2618
total = 37 10451 65230552 N/A alive=18, dead=19 N/A