Usage:
jmap [option]
(to connect to running process)(连接到本地进程)
jmap [option]
(to connect to a core file)(连接到 core file)
jmap [option] [server_id@]
(to connect to remote debug server)(连接到远程 debug 服务)
where
is one of:
to print same info as Solaris pmap //等同于 Solaris 的 pmap 命令
-heap to print java heap summary //打印 Java 堆内存汇总信息
-histo[:live] to print histogram of java object heap; if the "live" //打印 Java 堆内存对象的直方图统计信息,如果指定了 "live" 选项则只统计存活对象,强制触发一次 GC
suboption is specified, only count live objects
-clstats to print class loader statistics //打印 class loader 统计信息
-finalizerinfo to print information on objects awaiting finalization //打印等待 finalization 的对象信息
-dump: to dump java heap in hprof binary format //将堆内存 dump 为 hprof 二进制格式
dump-options:
live dump only live objects; if not specified, //只 dump 存活对象,不指定则导出全部。
all objects in the heap are dumped.
format=b binary format //二进制格式(binary format)
file= dump heap to //二进制格式(binary format)
Example: jmap -dump:live,format=b,file=heap.bin //示例:jmap -dump:live,format=b,file=heap.bin
-F force. Use with -dump: or -histo //强制导出,若 jmap 被 hang 住不响应,可断开后使用此选项。强制导出,若 jmap 被 hang 住不响应,可断开后使用此选项。其中 "live" 选项不支持强制导出。
to force a heap dump or histogram when does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J to pass directly to the runtime system
常用选项就 3 个:
-heap:打印堆内存(/内存池)的配置和使用信息。
-histo:看哪些类占用的空间最多,直方图。
-dump:format=b,file=xxxx.hprof:Dump 堆内存。
示例:看堆内存统计信息。
jmap -heap 57032
cmd显示
Attaching to process ID 57032, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 4263510016 (4066.0MB)
NewSize = 89128960 (85.0MB)
MaxNewSize = 1420820480 (1355.0MB)
OldSize = 179306496 (171.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 67108864 (64.0MB)
used = 25561280 (24.37713623046875MB)
free = 41547584 (39.62286376953125MB)
38.08927536010742% used
From Space:
capacity = 11010048 (10.5MB)
used = 0 (0.0MB)
free = 11010048 (10.5MB)
0.0% used
To Space:
capacity = 11010048 (10.5MB)
used = 0 (0.0MB)
free = 11010048 (10.5MB)
0.0% used
PS Old Generation
capacity = 179306496 (171.0MB)
used = 0 (0.0MB)
free = 179306496 (171.0MB)
0.0% used
4676 interned Strings occupying 380808 bytes.
Usage: jcmd class>
or: jcmd -l
or: jcmd -h
command must be a valid jcmd command for the selected jvm.//command 必须是指定 JVM 可用的有效 jcmd 命令。
Use the command "help" to see which commands are available.//可以使用 "help" 命令查看该 JVM 支持哪些命令。
If the pid is 0, commands will be sent to all Java processes.//如果指定 pid 部分的值为 0,则会将 commands 发送给所有可见的 Java 进程。
The main class argument will be used to match (either partially //指定 main class 则用来匹配启动类。可以部分匹配。(适用同一个类启动多实例)。
or fully) the class used to start Java.
If no options are given, lists Java processes (same as -p).
PerfCounter.print display the counters exposed by this process //命令可以展示该进程暴露的各种计数器
-f read and execute commands from the file //从文件读取可执行命令
-l list JVM processes on the local machine //列出(list)本机上可见的 JVM 进程
-h this help
14596:
GC.heap_dump
Generate a HPROF format dump of the Java heap.
Impact: High: Depends on Java heap size and content. Request a full GC unless the '-all' option is specified.
Permission: java.lang.management.ManagementPermission(monitor)
Syntax : GC.heap_dump [options]
Arguments:
filename : Name of the dump file (STRING, no default value)
Options: (options must be specified using the or = syntax)
-all : [optional] Dump all objects, including unreachable objects (BOOLEAN, false)
Usage:
jstack [-l]
(to connect to running process)
jstack -F [-m] [-l]
(to connect to a hung process)
jstack [-m] [-l]
(to connect to a core file)
jstack [-m] [-l] [server_id@]
(to connect to a remote debug server)
Options:
-F to force a thread dump. Use when jstack does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.66-b18 mixed mode):
"Service Thread" #10 daemon prio=9 os_prio=0 tid=0x0000000014a88800 nid=0x2b50 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"C1 CompilerThread2" #9 daemon prio=9 os_prio=2 tid=0x0000000014a13000 nid=0x1c14 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"C2 CompilerThread1" #8 daemon prio=9 os_prio=2 tid=0x0000000014a11000 nid=0x72e8 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"C2 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x00000000149e4800 nid=0x7a30 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x00000000149a3000 nid=0x5488 runnable [0x0000000014f0e000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
- locked <0x00000000ff97bc10> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
- locked <0x00000000ff97bc10> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:61)
Locked ownable synchronizers:
- None
"Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x0000000012e20800 nid=0x7018 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x0000000012e2e800 nid=0x5fe4 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000002a49800 nid=0x6abc in Object.wait() [0x000000001478f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000ff9506a0> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x00000000ff9506a0> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
Locked ownable synchronizers:
- None
"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x0000000002a43000 nid=0x1f14 in Object.wait() [0x000000001468f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000ff975d60> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157)
- locked <0x00000000ff975d60> (a java.lang.ref.Reference$Lock)
Locked ownable synchronizers:
- None
"main" #1 prio=5 os_prio=0 tid=0x0000000002952800 nid=0x3374 waiting on condition [0x00000000024af000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at com.fhj.jvm.JvmTest.main(JvmTest.java:13)
Locked ownable synchronizers:
- None
"VM Thread" os_prio=2 tid=0x0000000012dd8000 nid=0x7b08 runnable
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000002968800 nid=0x4140 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x000000000296a000 nid=0x37a8 runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x000000000296b800 nid=0x682c runnable
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x000000000296d000 nid=0x2798 runnable
"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x000000000296f800 nid=0x6c48 runnable
"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x0000000002970800 nid=0x6914 runnable
"VM Periodic Task Thread" os_prio=2 tid=0x0000000014ac5000 nid=0x67c waiting on condition
JNI global references: 17
死锁的原因一般是锁定多个资源的顺序出了问题(交叉依赖)。
jinfo 工具
诊断工具:jinfo 用来查看具体生效的配置信息以及系统属性,还支持动态增加一部分参数。
看看帮助信息:
jinfo -help
Usage:
jinfo [option]
(to connect to running process)
jinfo [option]
(to connect to a core file)
jinfo [option] [server_id@]
(to connect to remote debug server)
where
is one of:
-flag to print the value of the named VM flag
-flag [+|-] to enable or disable the named VM flag
-flag = to set the named VM flag to the given value
-flags to print VM flags
-sysprops to print Java system properties
to print both of the above
-h | -help to print this help message
使用示例:
jinfo 1556
jinfo -flags 1556
不加参数过滤,则打印所有信息。
Attaching to process ID 1556, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.66-b18
Java System Properties:
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.66-b18
sun.boot.library.path = D:\Java\jdk1.8.0_66\jre\bin
java.vendor.url = http://java.oracle.com/。。。。。。
java.ext.dirs = D:\Java\jdk1.8.0_66\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path = D:\Java\jdk1.8.0_66\jre\lib\resources.jar;D:\Java\jdk1.8.0_66\jre\lib\rt.jar;D:\Java\jdk1.8.0_66\jre\lib\sunrsasign.jar;D:\Java\jdk1.8.0_66\jre\lib\jsse.jar;D:\Java\jdk1.8.0_66\jre\lib\jce.jar;D:\Java\jdk1.8.0_66\jre\lib\charsets.jar;D:\Java\jdk1.8.0_66\jre\lib\jfr.jar;D:\Java\jdk1.8.0_66\jre\classes
java.vendor = Oracle Corporation
file.separator = \
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
sun.desktop = windows
sun.cpu.isalist = amd64
VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=8388608 -XX:MaxHeapSize=8388608 -XX:MaxNewSize=2621440 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=2621440 -XX:OldSize=5767168 -XX:+PrintGC -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
Command line: -Xmx8m -XX:+PrintGC -Dfile.encoding=UTF-8
可以看到所有的系统属性和启动使用的 VM 参数、命令行参数。非常有利于我们排查问题,特别是去排查一个已经运行的 JVM 里问题,通过 jinfo 我们就知道它依赖了哪些库,用了哪些参数启动。