jmap
输出进程、核心文件或远程调试服务器的共享对象内存或者堆内存的相关信息。
语法
jmap [ options ] pid
jmap [ options ] executable core
jmap [ options ] [ pid ] server-id@ ] remote-hostname-or-IP
解释
executable
产生核心转储的Java可执行文件
core
打印内存信息的核心文件
remote-hostname-or-IP
远程调试服务器的hostname或者IP地址。查看jsadebug
server-id
远程服务器上有多个调试服务器时,提供的调式服务器唯一ID
通过``-J-d64可以指定jmap`运行在64位JVM上
jmap -J-d64 -heap pid
Options
没有option参数,jmap命令输出共享对象映射信息。会输出JVM中所有共享对象的起始地址、映射大小、文件的全路径
$ jmap 5208
Attaching to process ID 5208, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
0x0000000056140000 8716K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\server\jvm.dll
0x00000000569d0000 840K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\msvcr100.dll
0x0000000056e10000 52K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\management.dll
0x0000000056e20000 68K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\nio.dll
0x0000000056e40000 104K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\net.dll
0x0000000056e60000 88K D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\zip.dll
-dump:[live,] format=b, file=*filename*
将Java堆信息存入filename指定文件名的hprof二进制文件中;
live 是可选操作,指定live表示只保存活跃对象;
使用jhat命令可以读取文件;
$ jmap -dump:live,format=b,file=test 5208
Dumping heap to C:\user\username\Desktop\test ...
Heap dump file created
$ jhat C:\\Users\\username\\Desktop\\test
Reading from C:\Users\username\Desktop\test...
Dump file created Fri Dec 27 13:20:01 CST 2019
Snapshot read, resolving...
Resolving 502739 objects...
Chasing references, expect 100 dots....................................................................................................
Eliminating duplicate references....................................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
finalizerinfo
$ jmap -finalizerinfo 10864
Attaching to process ID 10864, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
Number of objects pending for finalization: 0
heap
输出堆垃圾回收的摘要信息,配置信息,各年代的堆使用信息以及 interned Strings的是数量和大小。
$ jmap -heap 10864
Attaching to process ID 10864, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25