OpenJDK 11 是在 OpenJDK 8 之后的第一个长期支持版本,这一版本在JVM日志配置有了很大改动,主要是规范化,统一化了。在 OpenJDK 8 中,日志配置有很多状态位,让人摸不着头脑,并且比较难以维护与进一步迭代。在 OpenJDK 11终于将JVM日志相关的配置规范起来,统一配置。这篇文章会对于这些配置做一个基本的说明和解析。
一、JVM日志标签
JVM 日志和我们 java 代码中的日志,其实是类似。在 Java 代码中,我们一般使用 slf4j 记录日志,例如:
Logger logger = LogFactory.getLooger("core-logger");
logger.info("this is core logger log");
然后日志中就会输出类似于:
2020-02-05 10:50:52.670 INFO [core-logger] [22] [pool-13-thread-1]: this is core logger log
包括时间戳,日志级别,日志标签(core-logger),日志内容这些信息。JVM 日志也是包括这些元素。举个例子:
[0.182s][debug][jit,compilation] 1 3 java.lang.StringLatin1::hashCode (42 bytes)
[0.183s][debug][jit,compilation] 2 3 java.lang.Object::
[0.183s][debug][jit,compilation] 3 3 java.lang.String::hashCode (49 bytes)
可以看出,默认的 JVM 日志包括:
[启动经过时间][日志级别][日志标签,可能包含多个] 日志内容
其中一行日志,可能包含多个标签,之后关于JVM日志相关的配置,也是围绕着这些标签进行配置。大部分的标签是给JVM开发者用的,其中某些标签供我们使用 JVM 的人进行 JVM 参数调优以及代码调优。那么我们需要关心哪些标签呢?我个人按照功能,把我们需要关心的标签分为如下几大类
1. gc相关
gc日志有很多标签与组合,大部分以 gc 标签为开始,混合搭配其他一些标签。一般,有如下几个标签我们会经常用到:
标签gc
gc总体描述日志,一般设置info级别查看gc的发生时间,消耗时间还有内存大小。例如:Pause Young (Normal) (g1 Evacuation Pause) 3480M->1565M(5120M) 15.968ms 包含了gc类型,gc原因,收集内存大小,持续时间等信息
标签gc,age
gc 中 age 相关信息,age比较高的对象会进入老年代。如果是 trace 级别,会输出每一个 age 的所有对象占用总大小,以及比这个 age 低的所有 age 的大小,debug 级别只会输出最高级别的 age 以及期望大小,不是当前总大小,例如:
[2020-02-26T08:34:12.823+0000][debug][gc,age ] gc(1661) Desired survivor size 167772160 bytes, new threshold 6 (max threshold 6)
[2020-02-26T08:34:12.823+0000][trace][gc,age ] age 1: 16125960 bytes, 16125960 total
[2020-02-26T08:34:12.823+0000][trace][gc,age ] age 2: 16259512 bytes, 32385472 total
[2020-02-26T08:34:12.823+0000][trace][gc,age ] age 3: 2435240 bytes, 34820712 total
[2020-02-26T08:34:12.823+0000][trace][gc,age ] age 4: 17179320 bytes, 52000032 total
[2020-02-26T08:34:12.823+0000][trace][gc,age ] age 5: 43986952 bytes, 95986984 total
[2020-02-26T08:34:12.823+0000][trace][gc,age ] age 6: 20858328 bytes, 116845312 total
标签gc,alloc,gc,alloc,region
这两个参数仅对 g1 gc 有效 gc,alloc 在 gc 完成的时候,打印 trace 级别日志记录触发 gc 的线程是哪一个以及返回的 gc 结果地址;这个一般是在调试 gc 的时候才需要看这个日志。 gc,alloc,region 统计每次 gc 的 Regions 信息,打印 debug 级别日志。
[2020-02-28T02:14:02.694+0000][trace][gc,alloc ] sdk-27692-2-amqp-t-4: Successfully scheduled collection returning 0x00000007ffc00000
[2020-02-28T02:16:00.372+0000][debug][gc,alloc,region ] gc(7848) Mutator Allocation stats, regions: 677, wasted size: 63832B ( 0.0%)
标签gc,cpu 这个是大多数 gc 问题定位需要查看的日志, info 级别打印每次gc真正耗时:
[2020-02-28T01:59:46.406+0000][info ][gc,cpu ] gc(7841) User=0.10s Sys=0.00s Real=0.04s
[2020-02-28T02:01:20.148+0000][info ][gc,cpu ] gc(7842) User=0.04s Sys=0.06s Real=0.04s
注意这个和 JFR 的统计可能会有差异,JFR 统计的 gc 时间是从开始 schedule gc 就认为开始 gc ,而这里的时间是从开始标记开始。
标签gc,ergo,gc,ergo,cset,gc,ergo,ihop,gc,ergo,refine
这是 Adaptive Size Policy 相关的日志,如果想详细学习算法,可以用 trace 级别,一般的 debug 级别信息就够了
https://www.imdb.com/list/ls080108202/?publish=publish
https://www.imdb.com/list/ls080108234/?publish=publish
https://www.imdb.com/list/ls080108240/?publish=publish
https://www.imdb.com/list/ls080108407/?publish=publish
https://www.imdb.com/list/ls080108416/?publish=publish
https://www.imdb.com/list/ls080108420/?publish=publish
https://www.imdb.com/list/ls080108498/?publish=publish
https://www.imdb.com/list/ls080108959/?publish=publish
https://www.imdb.com/list/ls080108963/?publish=publish
https://www.imdb.com/list/ls080108995/?publish=publish
https://www.imdb.com/list/ls080108988/?publish=publish
https://www.imdb.com/list/ls080108870/?publish=publish
https://www.imdb.com/list/ls080108819/?publish=publish
https://www.imdb.com/list/ls080108826/?publish=publish
https://www.imdb.com/list/ls080108894/?publish=publish
https://www.imdb.com/list/ls080150054/?publish=publish
https://www.imdb.com/list/ls080150032/?publish=publish
https://www.imdb.com/list/ls080150049/?publish=publish
https://www.imdb.com/list/ls080150502/?publish=publish
https://www.imdb.com/list/ls080150510/?publish=publish
https://www.imdb.com/list/ls080150541/?publish=publish
https://www.imdb.com/list/ls080150588/?publish=publish
https://www.imdb.com/list/ls080150775/?publish=publish
https://www.imdb.com/list/ls080150719/?publish=publish
https://www.imdb.com/list/ls080150729/?publish=publish
https://www.imdb.com/list/ls080150787/?publish=publish
https://www.imdb.com/list/ls080150176/?publish=publish
https://www.imdb.com/list/ls080150131/?publish=publish
https://www.imdb.com/list/ls080150147/?publish=publish
https://www.imdb.com/list/ls080150186/?publish=publish
https://www.imdb.com/list/ls080150370/?publish=publish
https://www.imdb.com/list/ls080150332/?publish=publish
https://www.imdb.com/list/ls080150342/?publish=publish
https://www.imdb.com/list/ls080150606/?publish=publish
https://www.imdb.com/list/ls080150671/?publish=publish
https://www.imdb.com/list/ls080150632/?publish=publish
https://www.imdb.com/list/ls080150643/?publish=publish
https://www.imdb.com/list/ls080150686/?publish=publish
https://www.imdb.com/list/ls080150259/?publish=publish
https://www.imdb.com/list/ls080150216/?publish=publish
https://www.imdb.com/list/ls080150220/?publish=publish
https://www.imdb.com/list/ls080150248/?publish=publish
https://www.imdb.com/list/ls080150406/?publish=publish
https://www.imdb.com/list/ls080150415/?publish=publish
https://www.imdb.com/list/ls080150466/?publish=publish
https://www.imdb.com/list/ls080150491/?publish=publish
https://www.imdb.com/list/ls080150903/?publish=publish
https://www.imdb.com/list/ls080150973/?publish=publish
https://www.imdb.com/list/ls080150939/?publish=publish
https://www.imdb.com/list/ls080150949/?publish=publish
https://www.imdb.com/list/ls080150800/?publish=publish
https://www.imdb.com/list/ls080150875/?publish=publish
https://www.imdb.com/list/ls080150839/?publish=publish
https://www.imdb.com/list/ls080150829/?publish=publish
https://www.imdb.com/list/ls080150898/?publish=publish
https://www.imdb.com/list/ls080155057/?publish=publish
https://www.imdb.com/list/ls080155031/?publish=publish
https://www.imdb.com/list/ls080155021/?publish=publish
https://www.imdb.com/list/ls080155081/?publish=publish
https://www.imdb.com/list/ls080155512/?publish=publish
https://www.imdb.com/list/ls080155562/?publish=publish
https://www.imdb.com/list/ls080155548/?publish=publish
https://www.imdb.com/list/ls080155582/?publish=publish
https://www.imdb.com/list/ls080155753/?publish=publish
https://www.imdb.com/list/ls080155719/?publish=publish
https://www.imdb.com/list/ls080155746/?publish=publish
https://www.imdb.com/list/ls080155154/?publish=publish
https://www.imdb.com/list/ls080155120/?publish=publish
https://www.imdb.com/list/ls080155199/?publish=publish
https://www.imdb.com/list/ls080155350/?publish=publish
https://www.imdb.com/list/ls080155335/?publish=publish
https://www.imdb.com/list/ls080155322/?publish=publish
https://www.imdb.com/list/ls080155389/?publish=publish
https://www.imdb.com/list/ls080155675/?publish=publish
https://www.imdb.com/list/ls080155636/?publish=publish
https://www.imdb.com/list/ls080155626/?publish=publish
https://www.imdb.com/list/ls080155696/?publish=publish
https://www.imdb.com/list/ls080155208/?publish=publish
https://www.imdb.com/list/ls080155279/?publish=publish
https://www.imdb.com/list/ls080155263/?publish=publish
https://www.imdb.com/list/ls080155282/?publish=publish
https://www.imdb.com/list/ls080155410/?publish=publish
https://www.imdb.com/list/ls080155442/?publish=publish
https://www.imdb.com/list/ls080155908/?publish=publish
https://www.imdb.com/list/ls080155919/?publish=publish
https://www.imdb.com/list/ls080155924/?publish=publish
https://www.imdb.com/list/ls080155808/?publish=publish
https://www.imdb.com/list/ls080155834/?publish=publish
https://www.imdb.com/list/ls080155894/?publish=publish
https://www.imdb.com/list/ls080157059/?publish=publish