[root@node1 ~]# jmap -finalizerinfo 3446 Attaching to process ID 3446, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.191-b12 Number of objects pending for finalization: 0
[root@node1 ~]# jmap -heap 3446 Attaching to process ID 3446, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.191-b12
using thread-local object allocation. Mark Sweep Compact GC
[root@node1 ~]# jmap -clstats 3446 Attaching to process ID 3446, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.191-b12 finding classloader instances ..done. computing per loader stat ..done. please wait.. computing liveness..................................liveness analysis may be inaccurate ...
#加载器名称 已加载类个数 占用空间 父类加载器 是否存活? 类型信息 class_loader classes bytes parent_loader alive? type <bootstrap> 16772995244null live <internal> 0x00000000d6680e1860211179830x00000000d6680f40 live sun/misc/Launcher$AppClassLoader@0x000000010000f8d8 0x00000000d6680e781880null dead sun/reflect/DelegatingClassLoader@0x000000010000a028 0x00000000d66813381773null dead javax/management/remote/rmi/NoCallStackClassLoader@0x00000001000c96e8 0x00000000d66d6dd8000x00000000d6680e18 live java/util/ResourceBundle$RBClassLoader@0x0000000100100828 0x00000000d677e7d011474null dead sun/reflect/DelegatingClassLoader@0x000000010000a028 0x00000000d677e9601880null dead sun/reflect/DelegatingClassLoader@0x000000010000a028 0x00000000d6680f4044572null live sun/misc/Launcher$ExtClassLoader@0x000000010000fc80 0x00000000d66814101742null dead javax/management/remote/rmi/NoCallStackClassLoader@0x00000001000c96e8 0x00000000d677e8981880null dead sun/reflect/DelegatingClassLoader@0x000000010000a028 0x00000000d677ea281880null dead sun/reflect/DelegatingClassLoader@0x000000010000a028
[root@node1 opt]# jmap -dump:live,format=b,file=/opt/jamp_live_dump2.hprof -F 3446 Attaching to process ID 3446, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.191-b12 Dumping heap to /opt/jamp_live_dump2.hprof ...
|关闭对象分配调用栈跟踪(tracking object allocation call stack)。 如果分配位置信息在堆转储中不可用. 则必须将此标志设置为 false. 默认值为 true.>
-refs false or true |关闭对象引用跟踪(tracking of references to objects)。 默认值为 true. 默认情况下, 返回的指针是指向其他特定对象的对象,如反向链接或输入引用(referrers or incoming references), 会统计/计算堆中的所有对象。>
-exclude exclude-file |指定对象查询时需要排除的数据成员列表文件(a file that lists data members that should be excluded from the reachable objects query)。 例如, 如果文件列列出了 java.lang.String.value , 那么当从某个特定对象 Object o 计算可达的对象列表时, 引用路径涉及 java.lang.String.value 的都会被排除。>
-baseline exclude-file |指定一个基准堆转储(baseline heap dump)。 在两个 heap dumps 中有相同 object ID 的对象会被标记为不是新的(marked as not being new). 其他对象被标记为新的(new). 在比较两个不同的堆转储时很有用.>
-debug int |设置 debug 级别. 0 表示不输出调试信息。 值越大则表示输出更详细的 debug 信息.>
2.3 使用示例
2.3.1 jhat -J
1 2 3 4 5 6 7 8 9 10 11
hnbiandeMacBook-Pro:MyJava hnbian$ jhat -J-Xmx256m -port 7001 /Users/hnbian/Desktop/jamp_live_dump.hprof Reading from jamp_live_dump.hprof... Dump file created Thu Jan 30 21:12:03 GMT+08:00 2020 Snapshot read, resolving... Resolving 50639 objects... Chasing references, expect 10 dots.......... Eliminating duplicate references.......... Snapshot resolved. Started HTTP server on port 7000 Server is ready.
All classes including platform Show all members of the rootset Show instance counts for all classes (including platform) Show instance counts for all classes (excluding platform) Show heap histogram Show finalizer summary Execute Object Query Language (OQL) query
2.3.2 jhat -port
1 2 3 4 5 6 7 8 9 10
hnbiandeMacBook-Pro:MyJava hnbian$ jhat -J-Xmx256m -port 7001 /Users/hnbian/Desktop/jamp_live_dump.hprof Reading from /Users/hnbian/Desktop/jamp_live_dump.hprof... Dump file created Thu Jan 30 21:12:03 CST 2020 Snapshot read, resolving... Resolving 50639 objects... Chasing references, expect 10 dots.......... Eliminating duplicate references.......... Snapshot resolved. Started HTTP server on port 7001 Server is ready.
2.3.3 jhat -version
jhat -version:显示jhat版本信息
1 2
hnbiandeMacBook-Pro:MyJava hnbian$ jhat -version jhat version 2.0 (java version 1.8.0_191)
hnbiandeMacBook-Pro:MyJava hnbian$ jhat -stack false /Users/hnbian/Desktop/jamp_live_dump.hprof Reading from /Users/hnbian/Desktop/jamp_live_dump.hprof... Dump file created Thu Jan 30 21:12:03 CST 2020 Snapshot read, resolving... Resolving 50639 objects... Chasing references, expect 10 dots.......... Eliminating duplicate references.......... Snapshot resolved. Started HTTP server on port 7000 Server is ready. ^ChnbiandeMacBook-Pro:MyJava hnbian$ hnbiandeMacBook-Pro:MyJava hnbian$ jhat -stack true /Users/hnbian/Desktop/jamp_live_dump.hprof Reading from /Users/hnbian/Desktop/jamp_live_dump.hprof... Dump file created Thu Jan 30 21:12:03 CST 2020 Snapshot read, resolving... Resolving 50639 objects... Chasing references, expect 10 dots.......... Eliminating duplicate references.......... Snapshot resolved. Started HTTP server on port 7000 Server is ready.
2.3.2 jhat -refs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
hnbiandeMacBook-Pro:MyJava hnbian$ jhat -refs true /Users/hnbian/Desktop/jamp_live_dump.hprof Reading from /Users/hnbian/Desktop/jamp_live_dump.hprof... Dump file created Thu Jan 30 21:12:03 CST 2020 Snapshot read, resolving... Resolving 50639 objects... Chasing references, expect 10 dots.......... Eliminating duplicate references.......... Snapshot resolved. Started HTTP server on port 7000 Server is ready. ^ChnbiandeMacBook-Pro:MyJava hnbian$ hnbiandeMacBook-Pro:MyJava hnbian$ jhat -refs false /Users/hnbian/Desktop/jamp_live_dump.hprof Reading from /Users/hnbian/Desktop/jamp_live_dump.hprof... Dump file created Thu Jan 30 21:12:03 CST 2020 Snapshot read, resolving... Resolving 50639 objects... Snapshot resolved. Started HTTP server on port 7000 Server is ready.
2.3.6 jhat -debug
设置 debug 级别. 0 表示不输出调试信息。 值越大则表示输出更详细的 debug 信息.>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
jhat -J-Xmx256m -debug 1 /Users/hnbian/Desktop/jamp_live_dump.hprof Read heap sub-record type 5 at position 0x6aa352 Read heap sub-record type 5 at position 0x6aa35b ...... Read heap sub-record type 5 at position 0x6aa364 Finished heap sub-records. Finished processing instances in heap dump. Snapshot read, resolving... Resolving 50639 objects... Chasing references, expect 10 dots.......... Eliminating duplicate references.......... Snapshot resolved. Started HTTP server on port 7000 Server is ready.
2.4 页面信息说明
对于jhat启动后显示的html页面中功能: All classes including platform Show all members of the rootset Show instance counts for all classes (including platform) Show instance counts for all classes (excluding platform) Show heap histogram Show finalizer summary Execute Object Query Language (OQL) query
(1)显示出堆中所包含的所有的类
(2)从根集能引用到的对象
(3)显示所有类的实例数量(包括平台)
(4)显示所有类的实例数量(不包括平台)
(5)堆实例的分布表
(6)展示终结器汇总
(7)执行对象查询语句
3. jstack
jstack(Stack Trace for Java):用于生成虚拟机当前时刻的线程快照 (一般称为ThreadDump 或者Javacore文件)
[root@node1 ~]# jstack -F 3446 Attaching to process ID 3446, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.191-b12 Deadlock Detection:
"Connector-Scheduler-482f8f11"#28 prio=5 os_prio=0 tid=0x00007f905000b800 nid=0x43b7 waiting on condition [0x00007f9069491000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to waitfor <0x00000000d687c930> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1081) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
Locked ownable synchronizers: - None
"NIOWorkerThread-2"#27 daemon prio=5 os_prio=0 tid=0x00007f9048033800 nid=0x43b6 waiting on condition [0x00007f9069592000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to waitfor <0x00000000d687cb70> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
Locked ownable synchronizers: - None
...
"ContainerManagerTask"#25 daemon prio=5 os_prio=0 tid=0x00007f90804fb800 nid=0xd95 in Object.wait() [0x00007f9069794000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) at java.util.TimerThread.mainLoop(Timer.java:552) - locked <0x00000000d687cfc0> (a java.util.TaskQueue) at java.util.TimerThread.run(Timer.java:505)
Locked ownable synchronizers: - None
"ProcessThread(sid:0 cport:2181):"#24 prio=5 os_prio=0 tid=0x00007f90804f9800 nid=0xd94 waiting on condition [0x00007f9069895000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to waitfor <0x00000000d687d1a0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at org.apache.zookeeper.server.PrepRequestProcessor.run(PrepRequestProcessor.java:134)
Locked ownable synchronizers: - None
"SyncThread:0"#23 prio=5 os_prio=0 tid=0x00007f90804f7000 nid=0xd93 waiting on condition [0x00007f9069996000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to waitfor <0x00000000d687d3c8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at org.apache.zookeeper.server.SyncRequestProcessor.run(SyncRequestProcessor.java:109)
Locked ownable synchronizers: - None
"SessionTracker"#22 prio=5 os_prio=0 tid=0x00007f90804ef000 nid=0xd92 waiting on condition [0x00007f9069a97000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at org.apache.zookeeper.server.SessionTrackerImpl.run(SessionTrackerImpl.java:151)
Locked ownable synchronizers: - None
"ConnnectionExpirer"#19 prio=5 os_prio=0 tid=0x00007f90804e0800 nid=0xd91 waiting on condition [0x00007f9069b98000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at org.apache.zookeeper.server.NIOServerCnxnFactory$ConnectionExpirerThread.run(NIOServerCnxnFactory.java:574)
Locked ownable synchronizers: - None
"NIOServerCxnFactory.AcceptThread:0.0.0.0/0.0.0.0:2181"#21 daemon prio=5 os_prio=0 tid=0x00007f90804df000 nid=0xd90 runnable [0x00007f9069c99000] java.lang.Thread.State: RUNNABLE at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method) at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269) at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93) at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86) - locked <0x00000000d687d998> (a sun.nio.ch.Util$3) - locked <0x00000000d687d9a8> (a java.util.Collections$UnmodifiableSet) - locked <0x00000000d687d950> (a sun.nio.ch.EPollSelectorImpl) at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97) at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:101) at org.apache.zookeeper.server.NIOServerCnxnFactory$AcceptThread.select(NIOServerCnxnFactory.java:229) at org.apache.zookeeper.server.NIOServerCnxnFactory$AcceptThread.run(NIOServerCnxnFactory.java:205)
Locked ownable synchronizers: - None
"Session-HouseKeeper-1d29cf23"#18 prio=5 os_prio=0 tid=0x00007f9080478800 nid=0xd8e waiting on condition [0x00007f9069e9b000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to waitfor <0x00000000d687dd78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
Locked ownable synchronizers: - None
"qtp1798286609-17"#17 prio=5 os_prio=0 tid=0x00007f9080461000 nid=0xd8d waiting on condition [0x00007f9069f9c000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to waitfor <0x00000000d6790bb8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078) at org.eclipse.jetty.util.BlockingArrayQueue.poll(BlockingArrayQueue.java:392) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:727) at java.lang.Thread.run(Thread.java:748)
Locked ownable synchronizers: - None
......
"RMI TCP Accept-0"#9 daemon prio=5 os_prio=0 tid=0x00007f908027d000 nid=0xd81 runnable [0x00007f906aca5000] java.lang.Thread.State: RUNNABLE at java.net.PlainSocketImpl.socketAccept(Native Method) at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409) at java.net.ServerSocket.implAccept(ServerSocket.java:545) at java.net.ServerSocket.accept(ServerSocket.java:513) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:405) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:377) at java.lang.Thread.run(Thread.java:748)
"Finalizer"#3 daemon prio=8 os_prio=0 tid=0x00007f908007b800 nid=0xd7c in Object.wait() [0x00007f906befd000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144) - locked <0x00000000d66bc748> (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)
Locked ownable synchronizers: - None
"Reference Handler"#2 daemon prio=10 os_prio=0 tid=0x00007f9080079000 nid=0xd7b in Object.wait() [0x00007f906bffe000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:502) at java.lang.ref.Reference.tryHandlePending(Reference.java:191) - locked <0x00000000d66bc900> (a java.lang.ref.Reference$Lock) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
Locked ownable synchronizers: - None
"main"#1 prio=5 os_prio=0 tid=0x00007f908000a800 nid=0xd79 waiting on condition [0x00007f9086c6e000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to waitfor <0x00000000d6790ec8> (a java.util.concurrent.CountDownLatch$Sync) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836) at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304) at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231) at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:162) at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:106) at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:64) at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:128) at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
[root@node1 ~]# jstack -m 3446 Attaching to process ID 3446, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.191-b12 Deadlock Detection: