一、命令概述
jmap 用于生成堆 dump文件,查看堆内对象统计信息、classloader 信息、 finalizer 队列
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
-clstats to print class loader 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
二、示例
1、查看进程的内存映像信息
jmap 28025
2、显示 Java 堆详细信息
jmap -heap 28025
3、显示堆中对象的统计信息(各对象占用大小)
注:最好导出堆快照,用MAT或者Jprofile分析大对象引用。
jmap -histo:live 28025
4、生成堆 dump 文件
注:dump内存快照时,会对服务造成一定影响,线上慎用。
jmap -dump:format=b,file=heapdump.hprof 28025
本文转载自:http://mousycoder.com/thinking-in-jvm/46/