[root@wupx ~]# jmap -heap 8825Attaching to process ID 8825, please wait...Debugger attached successfully.Server compiler detected.JVM version is 25.201-b09using thread-local object allocation.Parallel GC with 10 thread(s)Heap Configuration:MinHeapFreeRatio= 0MaxHeapFreeRatio= 100MaxHeapSize= 8575254528 (8178.0MB)NewSize= 178782208 (170.5MB)MaxNewSize= 2858418176 (2726.0MB)OldSize= 358088704 (341.5MB)NewRatio= 2SurvivorRatio= 8MetaspaceSize= 21807104 (20.796875MB)CompressedClassSpaceSize = 1073741824 (1024.0MB)MaxMetaspaceSize= 17592186044415 MBG1HeapRegionSize= 0 (0.0MB)Heap Usage:PS Young GenerationEden Space:capacity = 624427008 (595.5MB)used= 32083672 (30.597373962402344MB)free= 592343336 (564.9026260375977MB)5.138098062536078% usedFrom Space:capacity = 19398656 (18.5MB)used= 15687272 (14.960548400878906MB)free= 3711384 (3.5394515991210938MB)80.86782919394004% usedTo Space:capacity = 20447232 (19.5MB)used= 0 (0.0MB)free= 20447232 (19.5MB)0.0% usedPS Old Generationcapacity = 256901120 (245.0MB)used= 22278496 (21.246429443359375MB)free= 234622624 (223.75357055664062MB)8.672012017697703% used24741 interned Strings occupying 2987512 bytes.首先会打印 堆的一些相关配置 ,比如最大新生代、元空间的大小等;下面为 堆的使用情况 ,包括新生代的 Eden 区、S0 区、S1 区以及老年代 。
jmap 还可以将堆的信息以文件的形式保存下来,相当于文件快照,执行 jmap -dump:live,format=b,file=heap.bin 8825 命令:
[root@wupx ~]# jmap -dump:live,format=b,file=heap.bin 8825Dumping heap to /root/heap.bin ...Heap dump file created这个 heap.bin 可以使用 jhat 命令打开,是以 html 的形式展示的 。
jhatjhat 分析 Java 堆的命令,可以将堆中对象以 html 的形式显示出来,支持对象查询语言 OQL,命令内容如下:

文章插图
现在执行 jhat -port 9999 heap.bin 来将刚刚保存的 heap.bin 以 html 展示出来:
【java程序员不可不知的 7 个 JDK 命令】
[root@wupx ~]# jhat -port 9999 heap.binReading from heap.bin...Dump file created Tue May 12 22:31:55 CST 2020Snapshot read, resolving...Resolving 570997 objects...Chasing references, expect 114 dots..................................................................................................................Eliminating duplicate references..................................................................................................................Snapshot resolved.Started HTTP server on port 9999Server is ready.执行完毕后,打开 http://localhost:9999/ 就可以看到类的实例的堆占用情况,它是按照包名来分组的:
文章插图
网页的底部还有许多 Query 方式:

文章插图
下面以 OQL 为例,打开后是一个类似 SQL 查询的窗口,比如输入 select s from java.lang.String s where s.value.length >= 100 就可以查询字符串长度大于 100 的实例:

文章插图
jstackjstack 是 堆栈跟踪工具 ,主要用于打印给定进程 pid 的堆栈信息,一般在发生死锁或者 CPU 100% 的时候排查问题使用,可以去查询当前运行的线程以及线程的堆栈信息是什么情况,命令内容如下:

文章插图
下面执行 jstack -F 8825 > jstack.log 命令,将线程的信息保存下来:
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.161-b12 mixed mode):"Attach Listener" #51805777 daemon prio=9 os_prio=0 tid=0x00007f971c001000 nid=0x9cd6 waiting on condition [0x0000000000000000]java.lang.Thread.State: RUNNABLE"DestroyJavaVM" #55 prio=5 os_prio=0 tid=0x00007f9fc8009800 nid=0x227a waiting on condition [0x0000000000000000]java.lang.Thread.State: RUNNABLE"http-nio-8111-Acceptor-0" #52 daemon prio=5 os_prio=0 tid=0x00007f96c40c5800 nid=0x2653 runnable [0x00007f97c0df9000]java.lang.Thread.State: RUNNABLE at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method) at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422) at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250) - locked <0x00007f982c6213c8> (a java.lang.Object) at org.Apache.Tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:455) at java.lang.Thread.run(Thread.java:748)"http-nio-8111-ClientPoller-0" #50 daemon prio=5 os_prio=0 tid=0x00007f9fc8e7e000 nid=0x2651 runnable [0x00007f97c21fb000]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 <0x00007f982c622460> (a sun.nio.ch.Util$3) - locked <0x00007f982c622450> (a java.util.Collections$UnmodifiableSet) - locked <0x00007f982c622408> (a sun.nio.ch.EPollSelectorImpl) at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97) at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:787) at java.lang.Thread.run(Thread.java:748)"Service Thread" #17 daemon prio=9 os_prio=0 tid=0x00007f9fc8379000 nid=0x229d runnable [0x0000000000000000]java.lang.Thread.State: RUNNABLE"C1 CompilerThread10" #15 daemon prio=9 os_prio=0 tid=0x00007f9fc8373800 nid=0x229b waiting on condition [0x0000000000000000]java.lang.Thread.State: RUNNABLE"VM Thread" os_prio=0 tid=0x00007f9fc831c000 nid=0x228d runnable "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f9fc801e800 nid=0x227b runnable "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f9fc8020800 nid=0x227c runnable "VM Periodic Task Thread" os_prio=0 tid=0x00007f9fc837e000 nid=0x229e waiting on condition JNI global references: 357
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 人的哪类细胞死亡脱落后不可再生?
- 菊花茶可不可以搭配茉莉起泡,枸杞菊花茶用量
- MySQL使用规范手册,程序员必知必会
- 糖尿病冬季如何饮食养生 4款膳食必不可少
- 冬季餐桌上这些滋补蔬菜必不可少
- 生薏米不可以直接泡水喝,玫瑰花茶泡水喝的功效
- 写给JavaScript开发人员的PHP快速入门指南
- 桃花不可以长期喝,喝茉莉花茶的好处和功效作用
- Java线程、多线程与线程池总结
- 有哪些新手程序员不知道的小技巧?
