全面了解JVM执行过程的细节-最全GC日志参数

全面了解JVM执行过程的细节-最全GC日志参数

最近老有朋友问我,GC日志的信息不全面,不够充分了解JVM执行过程,特别是GC时候的详细信息。

JDK1.8下GC最全日志配置方式

这个问题好办,直接把有用的JVM和GC信息都打印了就得了,参数见下:

java -Xmx4g -Xms4g -XX:+UseG1GC 
-XX:ConcGCThreads=2 -XX:ParallelGCThreads=8 
-XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled 
-XX:InitiatingHeapOccupancyPercent=45 
-XX:MaxGCPauseMillis=200 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=8 
-XX:+UnlockExperimentalVMOptions -XX:G1MixedGCLiveThresholdPercent=85 
-XX:G1ReservePercent=10 -XX:G1HeapRegionSize=2m -XX:G1NewSizePercent=5 
-XX:G1MaxNewSizePercent=60 -XX:G1OldCSetRegionThresholdPercent=10 
-XX:+PrintCommandLineFlags -XX:+PrintAdaptiveSizePolicy
-XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails 
-XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintGCCause 
-XX:+PrintPromotionFailure -XX:+PrintReferenceGC -XX:+PrintTenuringDistribution 
-XX:+UnlockDiagnosticVMOptions -XX:+G1PrintHeapRegions 
-XX:+PrintVMOptions -XX:+PrintTLAB -Xloggc:gc.log -jar gateway-server-0.0.1-SNAPSHOT.jar 

jdk8下执行,然后使用某种工具压测,比如wrk:wrk -d 120s localhost:8088/api/hell

最后看一下gc.log,你会发现跟你常见的gc日志,完全不一样,详细的一塌糊涂。

[G1Ergonomics (Mixed GCs) do not start mixed GCs, reason: candidate old regions not available]
 G1HR #EndGC 

能看到判断是否执行mixed gc

[SoftReference, 0 refs, 0.0005449 secs]2021-11-22T23:19:40.381-0800: 10.248: 
[WeakReference, 1009 refs, 0.0002207 secs]2021-11-22T23:19:40.382-0800: 10.248: 
[FinalReference, 63 refs, 0.0002413 secs]2021-11-22T23:19:40.382-0800: 10.249: 
[PhantomReference, 0 refs, 11 refs, 0.0004593 secs]2021-11-22T23:19:40.382-0800: 10.2

ref引用的数量

Desired survivor size 161480704 bytes, new threshold 15 (max 15)
- age   1:      69112 bytes,      69112 total
- age   2:     244616 bytes,     313728 total
- age   3:    3825312 bytes,    4139040 total
- age   4:    8959368 bytes,   13098408 total
- age   5:     327952 bytes,   13426360 total
- age   6:    3634808 bytes,   17061168 total

各代的对象占用内存

 14.208: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 0, 
          predicted base time: 14.03 ms, remaining time: 185.97 ms, target pause time: 200.00 ms]
 14.208: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 1217 regions, 
          survivors: 11 regions, predicted young region time: 101.24 ms]
 14.208: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 1217 regions, 
          survivors: 11 regions, old: 0 regions, predicted pause time: 115.27 ms, 
          target pause time: 200.00 ms]

选择的CSet收集集数量,预测的处理时间等。

2022-09-26 update:

是不是还能加的更全?当然可以,还少了不少参数,比如safepoint相关的:

-XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime 
-XX:+PrintSafepointStatistics -XX:PrintSafepointStatisticsCount=1 
-XX:PrintSafepointStatisticsTimeout=100 -XX:+SafepointTimeout -XX:SafepointTimeoutDelay=100 


JDK11+下最全GC日志配置方式

待续...

编辑于 2022-09-26 20:20