Java小工具查看JVM信息
程序员文章站
2022-07-08 15:54:46
...
jps
$ jps
8864 KotlinCompileDaemon
9536 AssertTestClientStartMain
10692 Jps
6564
9588 Launcher
2988 Launcher
8556 Launcher
jmap
打印每个class的实例数目,内存占用,类全名信息 head -20 打印排行前20的
jmap -histo 9536 | head -20
$ jmap -histo 9536 | head -20
num #instances #bytes class name
----------------------------------------------
1: 207317 48257936 [C
2: 7234 10878128 [I
3: 5524 3678872 [B
4: 146649 3519576 java.lang.String
5: 22973 2021624 java.lang.reflect.Method
6: 41314 1652560 java.util.LinkedHashMap$Entry
7: 9240 1031640 java.lang.Class
8: 9964 986464 [Ljava.util.HashMap$Node;
9: 26837 858784 java.util.concurrent.ConcurrentHashMap$Node
10: 19753 790120 org.springframework.boot.devtools.filewatch.FileSnapshot
11: 22771 728672 java.io.File
12: 12453 648040 [Ljava.lang.Object;
13: 11147 624232 java.util.LinkedHashMap
14: 7006 504432 java.lang.reflect.Field
15: 22713 501704 [Ljava.lang.Class;
16: 9797 497464 [Ljava.lang.String;
17: 15092 482944 java.util.HashMap$Node
只打印当前存活的
$ jmap -histo:live 9536 | head -20
num #instances #bytes class name
----------------------------------------------
1: 62785 7509392 [C
2: 21429 1885752 java.lang.reflect.Method
3: 62318 1495632 java.lang.String
4: 9235 1031120 java.lang.Class
5: 26043 833376 java.util.concurrent.ConcurrentHashMap$Node
6: 20827 833080 java.util.LinkedHashMap$Entry
7: 7657 626648 [Ljava.util.HashMap$Node;
8: 11398 607616 [Ljava.lang.Object;
9: 21737 482040 [Ljava.lang.Class;
10: 8440 472640 java.util.LinkedHashMap
11: 14295 457440 java.util.HashMap$Node
12: 5100 418384 [I
13: 3094 361936 [B
14: 4833 347976 java.lang.reflect.Field
15: 119 223728 [Ljava.util.concurrent.ConcurrentHashMap$Node;
16: 9237 221688 org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource$DefaultCacheKey
17: 4378 210144 java.util.concurrent.ConcurrentHashMap$TreeNode
jmap -heap 9536
B940+Administrator@B940 MINGW64 ~/Desktop
$ jmap -heap 9536
Attaching to process ID 9536, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
using thread-local object allocation.
Parallel GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 4219469824 (4024.0MB)
NewSize = 88080384 (84.0MB)
MaxNewSize = 1406140416 (1341.0MB)
OldSize = 176160768 (168.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 = 525860864 (501.5MB)
used = 203110568 (193.70133209228516MB)
free = 322750296 (307.79866790771484MB)
38.62439323874081% used
From Space:
capacity = 7864320 (7.5MB)
used = 7669288 (7.314002990722656MB)
free = 195032 (0.18599700927734375MB)
97.52003987630208% used
To Space:
capacity = 14680064 (14.0MB)
used = 0 (0.0MB)
free = 14680064 (14.0MB)
0.0% used
PS Old Generation
capacity = 155713536 (148.5MB)
used = 22183840 (21.156158447265625MB)
free = 133529696 (127.34384155273438MB)
14.246571344960017% used
22781 interned Strings occupying 2226256 bytes.
进行dump操作
jmap -dump:live,format=b,file=heap.bin 9536
$ jmap -dump:live,format=b,file=heap.bin 9536
Dumping heap to C:\Users\Administrator\Desktop\heap.bin ...
Heap dump file created
$ jhat C:\Users\Administrator\Desktop\heap.bin
Reading from C:UsersAdministratorDesktopheap.bin...
java.io.FileNotFoundException: C:UsersAdministratorDesktopheap.bin (ϵͳ▒Ҳ▒▒▒ָ▒▒▒▒▒ļ▒▒▒)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at com.sun.tools.hat.internal.parser.Reader.readFile(Reader.java:84)
at com.sun.tools.hat.Main.main(Main.java:159)
然后使用jhat查看(需要注意文件分割符)
jhat C:/Users/Administrator/Desktop/heap.bin
$ jhat C:/Users/Administrator/Desktop/heap.bin
Reading from C:/Users/Administrator/Desktop/heap.bin...
Dump file created Tue Sep 08 11:24:12 CST 2020
Snapshot read, resolving...
Resolving 462912 objects...
Chasing references, expect 92 dots............................................................................................
Eliminating duplicate references............................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
通过浏览器查看:http://localhost:7000/
jstat
jstat -gc 9536
jstat -class 9536
jstat -gccapacity 9536
$ jstat -gc 9536
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
13824.0 9216.0 0.0 8736.0 557568.0 113420.2 152064.0 21647.9 45696.0 42837.6 6272.0 5732.7 13 0.209 2 0.149 0.358
$ jstat -class 9536
Loaded Bytes Unloaded Bytes Time
8625 15808.3 1 0.9 9.65
$ jstat -gccapacity 9536
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
86016.0 1373184.0 734720.0 13824.0 9216.0 557568.0 172032.0 2747392.0 152064.0 152064.0 0.0 1089536.0 45696.0 0.0 1048576.0 6272.0 13 2
$ jstat -gccause 9536
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC
0.00 94.79 95.03 14.24 93.74 91.40 13 0.209 2 0.149 0.358 Allocation Failure No GC
jstack
查看进程信息
$ jstack 9536
2020-09-08 11:29:41
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode):
"OracleTimeoutPollingThread" #87 daemon prio=10 os_prio=2 tid=0x0000000021c87000 nid=0x2600 waiting on condition [0x0000000025aaf000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at oracle.jdbc.driver.OracleTimeoutPollingThread.run(OracleTimeoutPollingThread.java:150)
"Druid-ConnectionPool-Destroy-1008780851" #86 daemon prio=5 os_prio=0 tid=0x0000000021c89000 nid=0x2648 waiting on condition [0x000000002631f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:2850)
"Druid-ConnectionPool-Create-1008780851" #85 daemon prio=5 os_prio=0 tid=0x0000000021c88800 nid=0x26d4 waiting on condition [0x000000002621f000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006c52d7208> (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 com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2754)
"Abandoned connection cleanup thread" #84 daemon prio=5 os_prio=0 tid=0x0000000021c87800 nid=0x1d24 in Object.wait() [0x0000000025dff000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x00000006c5a2f770> (a java.lang.ref.ReferenceQueue$Lock)
at com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
上一篇: JAVA mail邮箱发送信息