Definitions: <option> An option reported by the -options option <vmid> Virtual Machine Identifier. A vmid takes the following form: <lvmid>[@<hostname>[:<port>]] Where <lvmid> is the local vm identifier for the target Java virtual machine, typically a process id; <hostname> is the name of the host running the target Java virtual machine; and <port> is the port number for the rmiregistry on the target host. See the jvmstat documentation for a more complete description of the Virtual Machine Identifier. <lines> Number of samples between header lines. <interval> Sampling interval. The following forms are allowed: <n>["ms"|"s"] Where <n> is an integer and the suffix specifies the units as milliseconds("ms") or seconds("s"). The default units are "ms". <count> Number of samples to take before terminating. -J<flag> Pass <flag> directly to the runtime system. [root@iz2ze2e5wmatyx36v5jw5lz ~]# jstat -options -class -compiler -gc -gccapacity -gccause -gcmetacapacity -gcnew -gcnewcapacity -gcold -gcoldcapacity -gcutil -printcompilation
[root@iz2ze2e5wmatyx36v5jw5lz ~]# jmap -help 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
[root@iz2ze2e5wmatyx36v5jw5lz ~]# jmap -finalizerinfo 1701 Attaching to process ID 1701, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.201-b09 Number of objects pending for finalization: 0
[root@iz2ze2e5wmatyx36v5jw5lz ~]# jmap -heap 1701 Attaching to process ID 1701, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.201-b09
using thread-local object allocation. Mark Sweep Compact GC //GC 方式
➜ ~ jmap -help Usage: jmap -clstats <pid> to connect to running process and print class loader statistics jmap -finalizerinfo <pid> to connect to running process and print information on objects awaiting finalization jmap -histo[:live] <pid> to connect to running process and print histogram of java object heap if the "live" suboption is specified, only count live objects jmap -dump:<dump-options> <pid> to connect to running process and dump java heap jmap -? -h --help to print this help message
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>
➜ Desktop jhsdb jmap -helo You have to set --pid or --exe or --connect. <no option> To print same info as Solaris pmap. --heap To print java heap summary. --binaryheap To dump java heap in hprof binary format. --dumpfile <name> The name of the dump file. --histo To print histogram of java object heap. --clstats To print class loader statistics. --finalizerinfo To print information on objects awaiting finalization. --pid <pid> To attach to and operate on the given live process. --core <corefile> To operate on the given core file. --exe <executable for corefile> --connect [<id>@]<host> To connect to a remote debug server (debugd).
The --core and --exe options must be set together to give the core file, and associated executable, to operate on. They can use absolute or relative paths. The --pid option can be set to operate on a live process. The --connect option can be set to connect to a debug server (debugd). --core, --pid, and --connect are mutually exclusive.
Examples: jhsdb jmap --pid 1234 or jhsdb jmap --core ./core.1234 --exe ./myexe or jhsdb jmap --connect debugserver or jhsdb jmap --connect id@debugserver
[root@iz2ze2e5wmatyx36v5jw5lz ~]# jstack -help Usage: jstack [-l] <pid> (to connect to running process) jstack -F [-m] [-l] <pid> (to connect to a hung process) jstack [-m] [-l] <executable> <core> (to connect to a core file) jstack [-m] [-l] [server_id@]<remote server IP or hostname> (to connect to a remote debug server)
Options: -F to force a thread dump. Use when jstack <pid> 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
线程 A 通过 synchronized (resource1) 获得 resource1 的监视器锁,然后通过Thread.sleep(1000);让线程 A 休眠 1s 为的是让线程 B 得到执行然后获取到 resource2 的监视器锁。线程 A 和线程 B 休眠结束了都开始企图请求获取对方的资源,然后这两个线程就会陷入互相等待的状态,这也就产生了死锁。
"线程 2" #14 prio=5 os_prio=31 tid=0x00007ff498836800 nid=0x5903 waiting for monitor entry [0x0000700005b7e000] java.lang.Thread.State: BLOCKED (on object monitor) at com.javaedge.concurrency.example.deadLock.DeadLockDemo.lambda$main$1(DeadLockDemo.java:34) - waiting to lock <0x000000076af91968> (a java.lang.Object) - locked <0x000000076af91978> (a java.lang.Object) at com.javaedge.concurrency.example.deadLock.DeadLockDemo$$Lambda$2/194494468.run(Unknown Source) at java.lang.Thread.run(Thread.java:748)
"线程 1" #13 prio=5 os_prio=31 tid=0x00007ff499876000 nid=0xa703 waiting for monitor entry [0x0000700005a7b000] java.lang.Thread.State: BLOCKED (on object monitor) at com.javaedge.concurrency.example.deadLock.DeadLockDemo.lambda$main$0(DeadLockDemo.java:19) - waiting to lock <0x000000076af91978> (a java.lang.Object) - locked <0x000000076af91968> (a java.lang.Object) at com.javaedge.concurrency.example.deadLock.DeadLockDemo$$Lambda$1/972765878.run(Unknown Source) at java.lang.Thread.run(Thread.java:748)
"Finalizer" #3 daemon prio=8 os_prio=31 tid=0x00007ff497005800 nid=0x4b03 in Object.wait() [0x0000700004e54000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076ab08ed0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144) - locked <0x000000076ab08ed0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
"Reference Handler" #2 daemon prio=10 os_prio=31 tid=0x00007ff496835000 nid=0x4d03 in Object.wait() [0x0000700004d51000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076ab06bf8> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:502) at java.lang.ref.Reference.tryHandlePending(Reference.java:191) - locked <0x000000076ab06bf8> (a java.lang.ref.Reference$Lock) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
"VM Periodic Task Thread" os_prio=31 tid=0x00007ff498824800 nid=0x5703 waiting on condition
JNI global references: 2505
Found one Java-level deadlock: ============================= "线程 2": waiting to lock monitor 0x00007ff4998056a8 (object 0x000000076af91968, a java.lang.Object), which is held by "线程 1" "线程 1": waiting to lock monitor 0x00007ff499801608 (object 0x000000076af91978, a java.lang.Object), which is held by "线程 2"
Java stack information for the threads listed above: =================================================== "线程 2": at com.javaedge.concurrency.example.deadLock.DeadLockDemo.lambda$main$1(DeadLockDemo.java:34) - waiting to lock <0x000000076af91968> (a java.lang.Object) - locked <0x000000076af91978> (a java.lang.Object) at com.javaedge.concurrency.example.deadLock.DeadLockDemo$$Lambda$2/194494468.run(Unknown Source) at java.lang.Thread.run(Thread.java:748) "线程 1": at com.javaedge.concurrency.example.deadLock.DeadLockDemo.lambda$main$0(DeadLockDemo.java:19) - waiting to lock <0x000000076af91978> (a java.lang.Object) - locked <0x000000076af91968> (a java.lang.Object) at com.javaedge.concurrency.example.deadLock.DeadLockDemo$$Lambda$1/972765878.run(Unknown Source) at java.lang.Thread.run(Thread.java:748)
[root@iz2ze2e5wmatyx36v5jw5lz ~]# jinfo -help Usage: jinfo [option] <pid> (to connect to running process) jinfo [option] <executable <core> (to connect to a core file) jinfo [option] [server_id@]<remote server IP or hostname> (to connect to remote debug server)
where <option> is one of: -flag <name> to print the value of the named VM flag -flag [+|-]<name> to enable or disable the named VM flag -flag <name>=<value> to set the named VM flag to the given value -flags to print VM flags -sysprops to print Java system properties <no option> to print both of the above -h | -help to print this help message