背景
最近在给我们的一个使用了Java 11
的项目添加 GC 日志参数的时候,
添加了 -Xloggc:/ms/jvmlogs/gc.log -XX:+PrintHeapAtGC -XX:+PrintReferenceGC
之后,却发现启动失败了,直接启动失败
Picked up JAVA_TOOL_OPTIONS: -XX:-OmitStackTraceInFastThrow -XX:+PrintCommandLineFlags -XX:MetaspaceSize=100m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/ms/jvmlogs/ -Xloggc:/ms/jvmlogs/gc.log -XX:+PrintHeapAtGC -XX:+PrintReferenceGC
Unrecognized VM option 'PrintHeapAtGC'
[0.001s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/ms/jvmlogs/gc.log instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
error
解决
经过一番搜索,发现是因为从 Java 9
开始,一部分jvm 参数被废弃了
根据 openjdk 说法,以下参数被移除
CMSDumpAtPromotionFailure
CMSPrintEdenSurvivorChunks
G1LogLevel
G1PrintHeapRegions
G1PrintRegionLivenessInfo
G1SummarizeConcMark
G1SummarizeRSetStats
G1TraceConcRefinement
G1TraceEagerReclaimHumongousObjects
G1TraceStringSymbolTableScrubbing
GCLogFileSize
NumberOfGCLogFiles
PrintAdaptiveSizePolicy
PrintClassHistogramAfterFullGC
PrintClassHistogramBeforeFullGC
PrintCMSInitiationStatistics
PrintCMSStatistics
PrintFLSCensus
PrintFLSStatistics
PrintGC
PrintGCApplicationConcurrentTime
PrintGCApplicationStoppedTime
PrintGCCause
PrintGCDateStamps
PrintGCDetails
PrintGCID
PrintGCTaskTimeStamps
PrintGCTimeStamps
PrintHeapAtGC
PrintHeapAtGCExtended
PrintJNIGCStalls
PrintOldPLAB
PrintParallelOldGCPhaseTimes
PrintPLAB
PrintPromotionFailure
PrintReferenceGC
PrintStringDeduplicationStatistics
PrintTaskqueue
PrintTenuringDistribution
PrintTerminationStats
PrintTLAB
TraceDynamicGCThreads
TraceMetadataHumongousAllocation
UseGCLogFileRotation
VerifySilently
-Xloggc
这里有个博客,列了一下参数对比 博客
可以看到
-Xloggc:gc.log
变成了-Xlog:gc:gc.log
-XX:+PrintHeapAtGC
变成了-Xlog:gc+heap=trace
-XX:+PrintReferenceGC
变成了 -Xlog:ref*=debug
最后 jvm
参数变为
-XX:-OmitStackTraceInFastThrow -XX:+PrintCommandLineFlags -XX:MetaspaceSize=100m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/ms/jvmlogs/ -Xlog:gc*,gc+ref=debug,gc+heap=debug,gc+age=trace:file=gc-%p-%t.log:tags,uptime,time,level:filecount=10,filesize=50m
输出样式
demo
网友评论