1、介紹
打印出某個java進程(使用pid)內(nèi)存內(nèi)的,所有‘對象’的情況(如:產(chǎn)生那些對象,及其數(shù)量)。
可以輸出所有內(nèi)存中對象的工具,甚至可以將VM 中的heap,以二進制輸出成文本。使用方法 jmap -histo pid。
如果連用SHELL jmap -histo pid>a.log可以將其保存到文本中去,在一段時間后,使用文本對比工具,可以對比
出GC回收了哪些對象。jmap -dump:format=b,file=outfile 3024可以將3024進程的內(nèi)存heap輸出出來到outfile文
件里,再配合MAT(內(nèi)存分析工具(Memory Analysis Tool),使用參見:
http://blog.csdn.net/fenglibing/archive/2011/04/02/6298326.aspx)
或與jhat (Java Heap Analysis Tool)一起使用,能夠以圖像的形式直觀的展示當前內(nèi)存是否有問題。
64位機上使用需要使用如下方式:
jmap -J-d64 -heap pid
2、命令格式
命令行輸入【jmap】幫助提示如下:
C:\>jmap
Usage:
jmap [option] <pid>
(to connect to running process)
jmap [option] <executable <core>
(to connect to a core file)
jmap [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
<none> to print same info as Solaris pmap
-heap to print java heap summary
-histo[:live] to print histogram of java object heap; if the "live"
suboption is specified, only count live objects
-permstat to print permanent generation statistics
-finalizerinfo to print information on objects awaiting finalization
-dump:<dump-options> to dump java heap in hprof binary format
dump-options:
live dump only live objects; if not specified
,
all objects in the heap are dumped.
format=b binary format
file=<file> dump heap to <file>
Example: jmap -dump:live,format=b,file=heap.bin <pid>
-F force. Use with -dump:<dump-options> <pid> or -histo
to force a heap dump or histogram when <pid> does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J<flag> to pass <flag> directly to the runtime system
簡單說明:SYNOPSISjmap [ option ] pid
jmap [ option ] executable core
jmap [ option ] [server-id@]remote-hostname-or-IP
3、參數(shù)說明
1)options:
executable Java executable from which the core dump was produced.
(可能是產(chǎn)生core dump的java可執(zhí)行程序)
core 將被打印信息的core dump文件
remote-hostname-or-IP 遠程debug服務(wù)的主機名或ip
server-id 唯一id,假如一臺主機上多個遠程debug服務(wù)
2)基本參數(shù):
-dump:[live,]format=b,file=<filename> 使用hprof二進制形式,輸出jvm的heap內(nèi)容到文件;
live子選項是可選的,假如指定live選項,那么只輸出活的對象到文件.
-finalizerinfo 打印正等候回收的對象的信息.
-heap 打印heap的概要信息,GC使用的算法,heap的配置及wise heap的使用情況.
-histo[:live] 打印每個class的實例數(shù)目,內(nèi)存占用,類全名信息. VM的內(nèi)部類名字開頭會加上前綴”*”.
如果live子參數(shù)加上后,只統(tǒng)計活的對象數(shù)量.
-permstat 打印classload和jvm heap長久層的信息. 包含每個classloader的名字,活潑性,地址,父classloader
和加載的class數(shù)量. 另外,內(nèi)部String的數(shù)量和占用內(nèi)存數(shù)也會打印出來.
-F **.在pid沒有相應(yīng)的時候使用-dump或者-histo參數(shù). 在這個模式下,live子參數(shù)無效.
-h | -help 打印輔助信息
-J 傳遞參數(shù)給jmap啟動的jvm.
pid 需要被打印配相信息的java進程id,可以用jps查問.
4、使用示例
1)[fenglb@ccbu-156-5 ~]$ jmap -histo 4939
2)[fenglb@ccbu-156-5 ~]$ jmap -dump:format=b,file=test.bin 4939
Dumping heap to /home/fenglb/test.bin ...
Heap dump file created