java9中gc log参数迁移

 更新时间:2018年03月02日 08:44:20   作者:codecraft  
本篇文章给大家详细讲述了java9中gc log参数迁移的相关知识点,对此有需要的朋友可以参考学习下。


本文主要研究一下java9 gc log参数的迁移。

统一JVM及GC的Logging

java9引进了一个统一的日志框架,把gc相关的log输出及配置也给纳入进来了。

相关JEP(JDK Enhancement Proposal)

Xlog语法

-Xlog[:option]
  option     := [<what>][:[<output>][:[<decorators>][:<output-options>]]]
            'help'
            'disable'
  what      := <selector>[,...]
  selector    := <tag-set>[*][=<level>]
  tag-set    := <tag>[+...]
            'all'
  tag      := name of tag
  level     := trace
            debug
            info
            warning
            error
  output     := 'stderr'
            'stdout'
            [file=]<filename>
  decorators   := <decorator>[,...]
            'none'
  decorator   := time
            uptime
            timemillis
            uptimemillis
            timenanos
            uptimenanos
            pid
            tid
            level
            tags
  output-options := <output_option>[,...]
  output-option := filecount=<file count>
            filesize=<file size in kb>
            parameter=value

what

主要是配置tag及level

tag

其中all代表所有的tag,其他的如下:

add,age,alloc,annotation,aot,arguments,attach,barrier,biasedlocking,blocks,bot,breakpoint,bytecode,census,class,classhisto,cleanup,compaction,comparator,constraints,constantpool,coops,cpu,cset,data,defaultmethods,dump,ergo,event,exceptions,exit,fingerprint,freelist,gc,hashtables,heap,humongous,ihop,iklass,init,itables,jfr,jni,jvmti,liveness,load,loader,logging,mark,marking,metadata,metaspace,method,mmu,modules,monitorinflation,monitormismatch,nmethod,normalize,objecttagging,obsolete,oopmap,os,pagesize,parser,patch,path,phases,plab,preorder,promotion,protectiondomain,purge,redefine,ref,refine,region,remset,resolve,safepoint,scavenge,scrub,setting,stackmap,stacktrace,stackwalk,start,startuptime,state,stats,stringdedup,stringtable,subclass,survivor,sweep,system,task,thread,time,timer,tlab,unload,update,verification,verify,vmoperation,vtables,workgang

level

主要分off,trace,debug,info,warning,error

output

- stdout(`Sends output to stdout`)
- stderr(`Sends output to stderr`)
- file=filename(`Sends output to text file(s)`)

有如上三种,其中指定file的话,可以使用%p变量表示当前jvm的pid,用%t表示jvm的启动时间戳。比如

-Xlog:gc:demoapp-gc-%p-%t.log

输出的文件名如下:

demoapp-gc-1678-2018-03-01_21-44-18.log

decorators

  • time -- Current time and date in ISO-8601 format
  • uptime -- Time since the start of the JVM in seconds and milliseconds (e.g., 6.567s)
  • timemillis -- The same value as generated by System.currentTimeMillis()
  • uptimemillis -- Milliseconds since the JVM started
  • timenanos -- The same value as generated by System.nanoTime()
  • uptimenanos -- Nanoseconds since the JVM started
  • pid -- The process identifier
  • tid -- The thread identifier
  • level -- The level associated with the log message
  • tags -- The tag-set associated with the log message

不指定的话,默认是uptime, level, and tags这三个。比如

[3.080s][info][gc,cpu ] GC(5) User=0.03s Sys=0.00s Real=0.01s

实例

-Xlog:gc=trace:file=gctrace.txt:uptimemillis,pid:filecount=5,filesize=1024

tag为gc,levle为trace,rotate文件数为5,每个文件1M,文件名为gctrace.txt,decrotators为uptimemillis和pid

输出实例

[1110ms][1867] GC(2) Pause Remark 17M->17M(256M) 2.024ms
[1110ms][1867] GC(2) Finalize Live Data 0.000ms
[1110ms][1867] GC(2) Pause Cleanup 17M->17M(256M) 0.177ms
[1112ms][1867] GC(2) Concurrent Cycle 7.470ms
[2951ms][1867] GC(3) Pause Initial Mark (Metadata GC Threshold) 149M->30M(256M) 27.175ms
[2951ms][1867] GC(4) Concurrent Cycle
[2972ms][1867] GC(4) Pause Remark 32M->32M(256M) 5.132ms
[2974ms][1867] GC(4) Finalize Live Data 0.000ms
[2974ms][1867] GC(4) Pause Cleanup 32M->32M(256M) 0.214ms
[2976ms][1867] GC(4) Concurrent Cycle 25.422ms

迁移

旧版GC相关参数迁移

Legacy Garbage Collection (GC) Flag Xlog Configuration Comment
G1PrintHeapRegions -Xlog:gc+region=trace Not Applicable
GCLogFileSize No configuration available Log rotation is handled by the framework.
NumberOfGCLogFiles Not Applicable Log rotation is handled by the framework.
PrintAdaptiveSizePolicy -Xlog:ergo*=level Use a level of debug for most of the information, or a level of trace for all of what was logged for PrintAdaptiveSizePolicy.
PrintGC -Xlog:gc Not Applicable
PrintGCApplicationConcurrentTime -Xlog:safepoint Note that PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime are logged on the same tag and aren't separated in the new logging.
PrintGCApplicationStoppedTime -Xlog:safepoint Note that PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime are logged on the same tag and not separated in the new logging.
PrintGCCause Not Applicable GC cause is now always logged.
PrintGCDateStamps Not Applicable Date stamps are logged by the framework.
PrintGCDetails -Xlog:gc* Not Applicable
PrintGCID Not Applicable GC ID is now always logged.
PrintGCTaskTimeStamps -Xlog:task*=debug Not Applicable
PrintGCTimeStamps Not Applicable Time stamps are logged by the framework.
PrintHeapAtGC -Xlog:gc+heap=trace Not Applicable
PrintReferenceGC -Xlog:ref*=debug Note that in the old logging, PrintReferenceGC had an effect only if PrintGCDetails was also enabled.
PrintStringDeduplicationStatistics -Xlog:stringdedup*=debug Not Applicable
PrintTenuringDistribution -Xlog:age*=level Use a level of debug for the most relevant information, or a level of trace for all of what was logged for PrintTenuringDistribution.
UseGCLogFileRotation Not Applicable What was logged for PrintTenuringDistribution.

旧版运行时参数迁移

Legacy Runtime Flag Xlog Configuration Comment
TraceExceptions -Xlog:exceptions=info Not Applicable
TraceClassLoading -Xlog:class+load=level Use level=info for regular information, or level=debug for additional information. In Unified Logging syntax, -verbose:class equals -Xlog:class+load=info,class+unload=info.
TraceClassLoadingPreorder -Xlog:class+preorder=debug Not Applicable
TraceClassUnloading -Xlog:class+unload=level Use level=info for regular information, or level=trace for additional information. In Unified Logging syntax, -verbose:class equals -Xlog:class+load=info,class+unload=info.
VerboseVerification -Xlog:verification=info Not Applicable
TraceClassPaths -Xlog:class+path=info Not Applicable
TraceClassResolution -Xlog:class+resolve=debug Not Applicable
TraceClassInitialization -Xlog:class+init=info Not Applicable
TraceLoaderConstraints -Xlog:class+loader+constraints=info Not Applicable
TraceClassLoaderData -Xlog:class+loader+data=level Use level=debug for regular information or level=trace for additional information.
TraceSafepointCleanupTime -Xlog:safepoint+cleanup=info Not Applicable
TraceSafepoint -Xlog:safepoint=debug Not Applicable
TraceMonitorInflation -Xlog:monitorinflation=debug Not Applicable
TraceBiasedLocking -Xlog:biasedlocking=level Use level=info for regular information, or level=trace for additional information.
TraceRedefineClasses -Xlog:redefine+class*=level level=info, =debug, and =trace provide increasing amounts of information.

小结

java9把gc log的选型及输出也给统一到了Xlog中,可以按照官方给出的迁移表进行迁移。

相关文章

  • Java设计模式之代理模式解析

    Java设计模式之代理模式解析

    这篇文章主要介绍了Java设计模式之代理模式解析,代理模式为一个对象提供一个替身,以控制对这个对象的访问,即通过代理对象访问目标对象,需要的朋友可以参考下
    2023-12-12
  • java中实现兼容ie6 7 8 9的spring4+websocket

    java中实现兼容ie6 7 8 9的spring4+websocket

    这篇文章主要介绍了java中实现兼容ie6 7 8 9的spring4+websocket程序代码,十分的简单实用,有需要的小伙伴可以参考下。
    2015-06-06
  • 基于JAVA中使用Axis发布/调用Webservice的方法详解

    基于JAVA中使用Axis发布/调用Webservice的方法详解

    如果初识axis发布/调用WS,建议先读上面的参考文件,本文对于发布/调用WS的主要步骤只是简单文字描述,没有它写的详尽
    2013-05-05
  • Java多线程 中断机制及实例详解

    Java多线程 中断机制及实例详解

    这篇文章主要介绍了Java多线程 中断机制及实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-09-09
  • Java手动配置线程池过程详解

    Java手动配置线程池过程详解

    这篇文章主要介绍了Java手动配置线程池过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-05-05
  • Java程序初始化启动自动执行的三种方式

    Java程序初始化启动自动执行的三种方式

    这篇文章主要介绍了Java程序初始化启动自动执行的三种方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-01-01
  • java.net.MalformedURLException异常的解决方法

    java.net.MalformedURLException异常的解决方法

    下面小编就为大家带来一篇java.net.MalformedURLException异常的解决方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • JAVA spark创建DataFrame的方法

    JAVA spark创建DataFrame的方法

    这篇文章主要介绍了JAVA spark创建DataFrame的方法,帮助大家更好的理解和学习spark,感兴趣的朋友可以了解下
    2020-08-08
  • java byte数组与int,long,short,byte的转换实现方法

    java byte数组与int,long,short,byte的转换实现方法

    下面小编就为大家带来一篇java byte数组与int,long,short,byte的转换实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-10-10
  • java判断字符串是否有逗号的方法

    java判断字符串是否有逗号的方法

    下面小编就为大家带来一篇java判断字符串是否有逗号的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-11-11

最新评论