java 对象内存分析工具 jmap
jmap — 打印指定进程的共享对象内存映射或堆内存细节
jmap
命令可以获得运行中的jvm的堆的快照,从而可以离线分析堆,以检查内存泄漏,检查一些严重影响性能的大对象的创建,检查系统中什么对象最多,各种对象所占内存的大小等等。可以使用jmap生成Heap Dump
java memory = direct memory(直接内存) + jvm memory(MaxPermSize +Xmx)
命令简介
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
重要参数说明
-heap
:打印jvm heap的情况-histo
:打印jvm heap的直方图。其输出信息包括类名,对象数量,对象占用大小。-histo:live
:同上,但是只答应存活对象的情况-permstat
:打印permanent generation heap情况
具体使用
首先查询出一个java 运行的程序 的pid
如下pid 15665
查看对象内存情况
jmap -histo 15665
排序查询
jmap -histo:live 15665
还可以过滤
jmap -histo:live 15665 |grep ArrayList
查询出来的信息比较多,重定向到文件中
jmap -histo:live 15665 |grep ArrayList > a.log