JVM常用命令之-----jmap

Jamp

1、命令基本概述
Jmap是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本。打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量)。

使用方法 jmap -histo pid。如果使用SHELL ,可采用jmap -histo pid>a.log日志将其保存到文件中,在一段时间后,使用文本对比工具,可以对比出GC回收了哪些对象。jmap -dump:format=b,file=outfile 3024可以将3024进程的内存heap输出出来到outfile文件里,再配合MAT(内存分析工具)。

64位机上使用需要使用如下方式:
jmap -J-d64 -heap pid

2、命令格式
l jmap [ option ] pid
l jmap [ option ] executable core
l jmap [ option ] [server-id@]remote-hostname-or-IP

3、参数说明
1)、options:
l executable :产生core dump的java可执行程序;
l core 将被打印信息的core dump文件;
l remote-hostname-or-IP 远程debug服务的主机名或ip;
l server-id 唯一id,假如一台主机上多个远程debug服务;

2)、基本参数:
Ø -dump:[live,]format=b,file= 使用hprof二进制形式,输出jvm的heap内容到文件=. live子选项是可选的,假如指定live选项,那么只输出活的对象到文件.
$jmap–dump:live,format=b,file=aaa.bin 3772

Ø -finalizerinfo 打印正等候回收的对象的信息
$jmap -finalizerinfo 3772

| Attaching to process ID 3772, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.0-b11
Number of objects pending for finalization: 0 (等候回收的对象为0个)

|Ø -heap 打印heap的概要信息,GC使用的算法,heap的配置及wise heap的使用情况.
$jmap –heap 3772

| 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区大小
Heap Usage: ##堆使用情况
New Generation (Eden + 1 Survivor Space): ##新生代(伊甸区 + survior空间)
capacity = 241631232 (230.4375MB) ##伊甸区容量
used = 77776272 (74.17323303222656MB) ##已经使用大小
free = 163854960 (156.26426696777344MB) ##剩余容量
32.188004570534986% used ##使用比例
Eden Space: ##伊甸区
capacity = 214827008 (204.875MB) ##伊甸区容量
used = 74442288 (70.99369812011719MB) ##伊甸区使用
free = 140384720 (133.8813018798828MB) ##伊甸区当前剩余容量
34.65220164496263% used ##伊甸区使用情况
From Space: ##survior1区
capacity = 26804224 (25.5625MB) ##survior1区容量
used = 3333984 (3.179534912109375MB) ##surviror1区已使用情况
free = 23470240 (22.382965087890625MB) ##surviror1区剩余容量
12.43827838477995% used ##survior1区使用比例
To Space: ##survior2 区
capacity = 26804224 (25.5625MB) ##survior2区容量
used = 0 (0.0MB) ##survior2区已使用情况
free = 26804224 (25.5625MB) ##survior2区剩余容量
0.0% used ## survior2区使用比例
concurrent mark-sweep generation: ##老生代使用情况
capacity = 1879048192 (1792.0MB) ##老生代容量
used = 30847928 (29.41887664794922MB) ##老生代已使用容量
free = 1848200264 (1762.5811233520508MB) ##老生代剩余容量
1.6416783843721663% used ##老生代使用比例
Perm Generation: ##perm区使用情况
capacity = 134217728 (128.0MB) ##perm区容量
used = 47303016 (45.111671447753906MB) ##perm区已使用容量
free = 86914712 (82.8883285522461MB) ##perm区剩余容量
35.24349331855774% used ##perm区使用比例|

Ø -histo[:live] 打印每个class的实例数目,内存占用,类全名信息. VM的内部类名字开头会加上前缀”*”. 如果live子参数加上后,只统计活的对象数量.
$jmap –histo:live 3772
| num #instances #bytes class name


1: 65220 9755240
2: 65220 8880384
3: 11721 8252112 [B
4: 6300 6784040
5: 75224 6218208 [C
6: 93969 5163280
7: 6300 4854440
8: 5482 4203152
9: 72097 2307104 java.lang.String
10: 15102 2289912 [I
11: 4089 2227728
12: 28887 1386576 org.apache.velocity.runtime.parser.Token
13: 6792 706368 java.lang.Class
14: 7445 638312 [Ljava.util.HashMapEntry
21: 3730 358080 org.apache.velocity.runtime.parser.node.ASTReference
22: 4373 279872 org.apache.velocity.runtime.parser.node.ASTText
23: 463 270392
24: 6695 267800 java.lang.ref.SoftReference
25: 5198 249504 java.util.HashMap
26: 2871 206712 org.apache.velocity.runtime.parser.node.ASTIdentifier
27: 7526 180624 org.apache.velocity.util.introspection.Info
28: 4441 177640 java.util.LinkedHashMapNonfairSync
30: 5723 175272 [Lorg.apache.velocity.runtime.parser.node.Node;
31: 4473 156904 [Ljava.lang.String;
32: 2773 155288 java.beans.MethodDescriptor
33: 6264 150336 java.util.ArrayList |

Ø -permstat 打印classload和jvm heap长久层的信息. 包含每个classloader的名字,活泼性,地址,父classloader和加载的class数量. 另外,内部String的数量和占用内存数也会打印出来.
$jmap -permstat 3772

| class_loader classes bytes parent_loader alive? type
2172 13144040 null live
0x00000007882d7ab8 0 0 0x0000000788106c00 dead java/util/ResourceBundle$RBClassLoader@0x00000007f83b0388
0x0000000788c15ca8 1 3136 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x0000000788fb1718 1 1968 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x00000007882d0f08 1 2008 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x0000000788176c60 1 3112 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x0000000788a7e018 1 3144 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x0000000788f515d0 1 1984 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x000000078829a2c8 1 3112 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x0000000788fab478 1 3128 null dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x0000000788030fd8 1 3112 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x0000000788d46048 1 3144 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0
0x000000078816f6f0 1 3144 null dead sun/reflect/DelegatingClassLoader@0x00000007f80686e
0x0000000788c18850 1 3112 0x00000007880213d8 dead sun/reflect/DelegatingClassLoader@0x00000007f80686e0 |

Ø -F 强迫.在pid没有相应的时候使用-dump或者-histo参数. 在这个模式下,live子参数无效.
Ø -h | -help 打印辅助信息
Ø -J 传递参数给jmap启动的jvm.

参考文献:
[http://docs.oracle.com/javase/6/docs/technotes/tools/share/jmap.html]
http://blog.csdn.net/fenglibing/article/details/6411953

你可能感兴趣的:(JVM常用命令之-----jmap)