JVM 学习笔记记录
Sun JDK 监控和故障处理工具
名称 | 主要作用 |
---|---|
jps | JVM Process Status Tool, 显示指定系统内所有的HotSpot虚拟机进程 |
jstat | JVM Statistics Moitoring Tool,用于收集HotSpot虚拟机各方面的运行数据 |
jinfo | Configuration info for java,显示虚拟机配置信息 |
jmap | Memory Map for java,生成虚拟机的内存转储快照(heapdump文件) |
jhat | JVM Heap Dump Browser,用于分析heapdump文件,它会建立一个HTTP/HTML服务器,让用户可以在浏览器上查看分析结果 |
jstack | Stack Trace for java,显示虚拟机的线程快照 |
常用命令:
1. jps -l 查询LVMID,及主类的名称
C:\Users\Harry>jps -l
11856 com.ssm.common.jvm.JvmTest
14368 com.ddc.template.TemplateApplication
16848
19664
6640 org.jetbrains.jps.cmdline.Launcher
7732 sun.tools.jps.Jps
2168 org.apache.zookeeper.server.quorum.QuorumPeerMain
2. jps -v 输出虚拟机进程参数
C:\Users\Harry>jps -v
11856 JvmTest -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:49232 -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -Dfile.encoding=utf8
3. jstat -gc 11856 250 5 每250毫秒查询一次进程11856垃圾收集情况状况,一共查询5次
C:\Users\Harry>jstat -gc 11856 250 20
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
1024.0 1024.0 0.0 0.0 8192.0 7619.8 10240.0 0.0 4480.0 780.5 384.0 75.8 0 0.000 0 0.000 0.000
1024.0 1024.0 0.0 0.0 8192.0 7619.8 10240.0 0.0 4480.0 780.5 384.0 75.8 0 0.000 0 0.000 0.000
1024.0 1024.0 0.0 0.0 8192.0 7619.8 10240.0 0.0 4480.0 780.5 384.0 75.8 0 0.000 0 0.000 0.000
1024.0 1024.0 0.0 0.0 8192.0 7619.8 10240.0 0.0 4480.0 780.5 384.0 75.8 0 0.000 0 0.000 0.000
1024.0 1024.0 0.0 0.0 8192.0 7619.8 10240.0 0.0 4480.0 780.5 384.0 75.8 0 0.000 0 0.000 0.000
4. jstat -gc 11856 只查询一次
C:\Users\Harry>jstat -gc 11856
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
1024.0 1024.0 0.0 0.0 8192.0 7619.8 10240.0 0.0 4480.0 780.5 384.0 75.8 0 0.000 0 0.000 0.000
5. jstat -gcutil 11856 查询各JVM内存使用百分比
C:\Users\Harry>jstat -gcutil 11856
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 93.01 0.00 17.42 19.75 0 0.000 0 0.000 0.000
6. jstat -gcnew 11856 查询新生代GC状况
C:\Users\Harry>jstat -gcnew 11856
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
1024.0 1024.0 0.0 0.0 15 15 0.0 8192.0 7619.8 0 0.000
7. jstat -gcold 11856 查询老年代GC状况
C:\Users\Harry>jstat -gcold 11856
MC MU CCSC CCSU OC OU YGC FGC FGCT GCT
4480.0 780.5 384.0 75.8 10240.0 0.0 0 0 0.000 0.000
8. jinfo -flag CMSInitiatingOccupancyFraction 11856 查询JVM参数的值
C:\Users\Harry>jinfo -flag CMSInitiatingOccupancyFraction 11856
-XX:CMSInitiatingOccupancyFraction=-1
9. jinfo -sysprops 11856
可以把System.getProperties()信息打印出来
C:\Users\Harry>jinfo -sysprops 11856
Attaching to process ID 11856, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.92-b14
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.92-b14
......
10. jmap -dump:format=b,file=eclipse.bin 11856 生成java堆转储快照
C:\Users\Harry>jmap -dump:format=b,file=eclipse.bin 11856
Dumping heap to C:\Users\Harry\eclipse.bin ...
Heap dump file created
11. jhat eclipse.bin 分析dump文件,浏览器中访问http://localhost:7000
C:\Users\Harry>jhat eclipse.bin
Reading from eclipse.bin...
Dump file created Sun Jul 22 11:55:08 CST 2018
Snapshot read, resolving...
Resolving 11914 objects...
Chasing references, expect 2 dots..
Eliminating duplicate references..
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
11. jmap -heap 11856 查看堆中jvm参数情况
Attaching to process ID 11856, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.131-b11
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 1073741824 (1024.0MB)
NewSize = 357564416 (341.0MB)
MaxNewSize = 357564416 (341.0MB)
OldSize = 716177408 (683.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 = 310902784 (296.5MB)
used = 90540600 (86.34624481201172MB)
free = 220362184 (210.15375518798828MB)
29.121836361555385% used
From Space:
capacity = 23068672 (22.0MB)
used = 11927744 (11.37518310546875MB)
free = 11140928 (10.62481689453125MB)
51.70537775213068% used
To Space:
capacity = 22544384 (21.5MB)
used = 0 (0.0MB)
free = 22544384 (21.5MB)
0.0% used
PS Old Generation
capacity = 716177408 (683.0MB)
used = 82475416 (78.6546859741211MB)
free = 633701992 (604.3453140258789MB)
11.516059439842035% used
13. jmap -dump:live,format=b,file=heap.hprof 11856
将heap.hprof传输出来到window电脑上使用mat工具分析。
14. jhat -heap 11856 显示java堆详细信息,如使用哪种回收器、参数配置、分代状况等,只在linux平台才可以测试
15. jstack -l 11856 除堆栈外,显示锁的附加信息
"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x00000000152da800 nid=0x18b4 in Object.wait() [0x000000001664e000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000ff608ee0> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x00000000ff608ee0> (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=0x00000000152b9000 nid=0x444c in Object.wait() [0x000000001654f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000ff606b50> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
- locked <0x00000000ff606b50> (a java.lang.ref.Reference$Lock)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
Locked ownable synchronizers:
- None
本文由博客群发一文多发等运营工具平台 OpenWrite 发布