java9中gc log参数迁移

作者:codecraft 时间:2022-06-28 03:21:01 


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

统一JVM及GC的Logging

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

相关JEP(JDK Enhancement Proposal)

  • JEP 158: Unified JVM Logging

  • JEP 264: Platform Logging API and Service

  • JEP 271: Unified GC Logging

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) FlagXlog ConfigurationComment
G1PrintHeapRegions-Xlog:gc+region=traceNot Applicable
GCLogFileSizeNo configuration availableLog rotation is handled by the framework.
NumberOfGCLogFilesNot ApplicableLog rotation is handled by the framework.
PrintAdaptiveSizePolicy-Xlog:ergo*=levelUse a level of debug for most of the information, or a level of trace for all of what was logged for PrintAdaptiveSizePolicy.
PrintGC-Xlog:gcNot Applicable
PrintGCApplicationConcurrentTime-Xlog:safepointNote that PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime are logged on the same tag and aren't separated in the new logging.
PrintGCApplicationStoppedTime-Xlog:safepointNote that PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime are logged on the same tag and not separated in the new logging.
PrintGCCauseNot ApplicableGC cause is now always logged.
PrintGCDateStampsNot ApplicableDate stamps are logged by the framework.
PrintGCDetails-Xlog:gc*Not Applicable
PrintGCIDNot ApplicableGC ID is now always logged.
PrintGCTaskTimeStamps-Xlog:task*=debugNot Applicable
PrintGCTimeStampsNot ApplicableTime stamps are logged by the framework.
PrintHeapAtGC-Xlog:gc+heap=traceNot Applicable
PrintReferenceGC-Xlog:ref*=debugNote that in the old logging, PrintReferenceGC had an effect only if PrintGCDetails was also enabled.
PrintStringDeduplicationStatistics-Xlog:stringdedup*=debugNot Applicable
PrintTenuringDistribution-Xlog:age*=levelUse a level of debug for the most relevant information, or a level of trace for all of what was logged for PrintTenuringDistribution.
UseGCLogFileRotationNot ApplicableWhat was logged for PrintTenuringDistribution.

旧版运行时参数迁移

Legacy Runtime FlagXlog ConfigurationComment
TraceExceptions-Xlog:exceptions=infoNot Applicable
TraceClassLoading-Xlog:class+load=levelUse 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=debugNot Applicable
TraceClassUnloading-Xlog:class+unload=levelUse 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=infoNot Applicable
TraceClassPaths-Xlog:class+path=infoNot Applicable
TraceClassResolution-Xlog:class+resolve=debugNot Applicable
TraceClassInitialization-Xlog:class+init=infoNot Applicable
TraceLoaderConstraints-Xlog:class+loader+constraints=infoNot Applicable
TraceClassLoaderData-Xlog:class+loader+data=levelUse level=debug for regular information or level=trace for additional information.
TraceSafepointCleanupTime-Xlog:safepoint+cleanup=infoNot Applicable
TraceSafepoint-Xlog:safepoint=debugNot Applicable
TraceMonitorInflation-Xlog:monitorinflation=debugNot Applicable
TraceBiasedLocking-Xlog:biasedlocking=levelUse level=info for regular information, or level=trace for additional information.
TraceRedefineClasses-Xlog:redefine+class*=levellevel=info, =debug, and =trace provide increasing amounts of information.

小结

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

来源:https://segmentfault.com/a/1190000013475524

标签:java9,gc,log
0
投稿

猜你喜欢

  • SpringCloud Feign多参数传递及需要注意的问题

    2022-05-25 11:11:58
  • springMvc注解之@ResponseBody和@RequestBody详解

    2022-10-09 17:57:19
  • Java编程中的一些常见问题汇总

    2022-01-08 18:05:46
  • 详解Java并发包中线程池ThreadPoolExecutor

    2022-03-23 19:57:20
  • Java使用RedisTemplate模糊删除key操作

    2023-06-24 06:45:25
  • java web监听器统计在线用户及人数

    2023-12-14 14:42:52
  • 通过Java连接SQL Server数据库的超详细操作流程

    2022-08-01 12:46:01
  • Spring Boot实现文件上传下载

    2021-11-22 21:19:36
  • c#创建Graphics对象的三种方法

    2022-11-24 10:20:53
  • Java中LinkedList和ArrayList的效率分析

    2023-02-12 06:21:55
  • java用applet画图用到的方法(涉及双缓冲)

    2021-07-09 17:27:32
  • 基于java构造方法Vector创建对象源码分析

    2023-11-25 11:27:54
  • SpringBoot如何根据用户系统时区动态展示时间

    2021-09-23 23:37:10
  • CentOS 7下JDK8的详细安装步骤

    2022-02-18 12:06:28
  • Java特性队列和栈的堵塞原理解析

    2023-10-13 14:15:55
  • C#中is,as,using关键字的使用说明

    2023-07-01 22:54:42
  • Android中通过样式来去除app的头及界面全屏(备忘)的实现方法

    2023-07-30 00:03:23
  • 一文详解Object类和抽象类

    2023-06-09 16:27:14
  • Nacos 动态服务发现、配置和服务管理平台初体验

    2022-09-10 23:56:53
  • 浅谈java 面对对象(抽象 继承 接口 多态)

    2022-04-01 07:23:50
  • asp之家 软件编程 m.aspxhome.com