OpenJDK 11 JVM logs associated with the use of analytical parameters

 

Personal blog navigation page (click on the right link to open a personal blog): Daniel take you on technology stack 

OpenJDK 11 is the first long-term support version after 8 OpenJDK, this version of the JVM log configuration has changed substantially, mainly standardization and unification of. In OpenJDK 8, there is a lot of logging configuration status bit confusing and more difficult to maintain and further iterations. Finally JVM logs related configuration specifications up in OpenJDK 11, unified configuration. This article will do a basic description and parsing for these configurations.

A, JVM log tag

JVM logs and logs of our java code, in fact, is similar. In Java code, we generally use slf4j logging, for example:

Logger logger = LogFactory.getLooger("core-logger");
logger.info("this is core logger log");

Then log output will look like this:

2020-02-05 10:50:52.670  INFO [core-logger] [22] [pool-13-thread-1]: this is core logger log

Include a timestamp, the log level and log tab (core-logger), the contents of the log information. JVM logs also include these elements. for example:

[0.182s][debug][jit,compilation]    1       3       java.lang.StringLatin1::hashCode (42 bytes)
[0.183s][debug][jit,compilation]    2       3       java.lang.Object::<init> (1 bytes)
[0.183s][debug][jit,compilation]    3       3       java.lang.String::hashCode (49 bytes)

As can be seen, the default JVM logs include:

[启动经过时间][日志级别][日志标签,可能包含多个] 日志内容

Where a row of logs may contain multiple tabs, after the relevant configuration on JVM logs also be configured around these labels. Most of the labels are to the JVM developers to use, some of us who use the label for the JVM JVM parameters were tuning and code tuning. So we need to care about what label it? I personally follow the function, we need to care about the labels are divided into the following broad categories

1. gc related

gc log There are many combinations of labels and, most gc label to start, mixed with a number of other labels. Generally, there are several labels we often use:

labelgc

gc general description of the log, the general level set info time gc to see happen, and time-consuming as well as memory size. For example: Pause Young (Normal) (g1 Evacuation Pause) 3480M->1565M(5120M) 15.968ms it contains the type gc, gc reasons, to collect memory size, duration and other information

labelgc,age

gc in age-related information, age relatively high objects into the old era. If trace level, the output of all the objects will each occupy a total age of the size and age of all sizes lower than the age of, debug output level can only expect the highest levels of age and size, not the current total size, for example:

[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

Label gc,alloc,gc,alloc,region

These two parameters only g1 gc effective  gc,alloc in gc when completed, print trace-level logging thread which is triggered gc and gc result of the return address; this is usually when the gc debugging only need to look at the log. gc,alloc,region Statistical information every time gc of Regions, print debug level log.

[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%)

Labelgc,cpu  this is the most gc log to locate the problem you want to view, info-level print each gc real time:

[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

Note that this JFR and statistics may vary, JFR gc statistics from the beginning of time is considered to begin on schedule gc gc, and the time is here to mark the start from the beginning.

Label gc,ergo, gc,ergo,cset, gc,ergo,ihop,gc,ergo,refine

This is the Adaptive Size Policy related logs, if you want detailed learning algorithm can be used to trace levels, the general level of debug information is enough

[2020-02-28T01:59:46.367+0000][trace][gc,ergo,cset                ] gc(7841) Start choosing CSet. pending cards: 26996 predicted base time: 13.34ms remaining time: 186.66ms target pause time: 200.00ms
[2020-02-28T01:59:46.367+0000][trace][gc,ergo,cset                ] gc(7841) Add young regions to CSet. eden: 676 regions, survivors: 6 regions, predicted young region time: 19.02ms, target pause time: 200.00ms
[2020-02-28T01:59:46.367+0000][debug][gc,ergo,cset                ] gc(7841) Finish choosing CSet. old: 0 regions, predicted old region time: 0.00ms, time remaining: 167.64
[2020-02-28T01:59:46.389+0000][debug][gc,ergo                     ] gc(7841) Running g1 Clear Card Table Task using 4 workers for 7 units of work for 895 regions.
[2020-02-28T01:59:46.391+0000][debug][gc,ergo                     ] gc(7841) Running g1 Free Collection Set using 4 workers for collection set length 682
[2020-02-28T01:59:46.391+0000][trace][gc,ergo,refine              ] gc(7841) Updating Refinement Zones: update_rs time: 6.800ms, update_rs buffers: 397, update_rs goal time: 19.998ms
[2020-02-28T01:59:46.391+0000][debug][gc,ergo,refine              ] gc(7841) Updated Refinement Zones: green: 572, yellow: 1716, red: 2860
[2020-02-28T02:01:20.108+0000][trace][gc,ergo,cset                ] gc(7842) Start choosing CSet. pending cards: 25786 predicted base time: 12.87ms remaining time: 187.13ms target pause time: 200.00ms
[2020-02-28T02:01:20.108+0000][trace][gc,ergo,cset                ] gc(7842) Add young regions to CSet. eden: 677 regions, survivors: 5 regions, predicted young region time: 14.43ms, target pause time: 200.00ms
[2020-02-28T02:01:20.108+0000][debug][gc,ergo,cset                ] gc(7842) Finish choosing CSet. old: 0 regions, predicted old region time: 0.00ms, time remaining: 172.70
[2020-02-28T02:01:20.132+0000][debug][gc,ergo                     ] gc(7842) Running g1 Clear Card Table Task using 4 workers for 8 units of work for 903 regions.
[2020-02-28T02:01:20.133+0000][debug][gc,ergo                     ] gc(7842) Running g1 Free Collection Set using 4 workers for collection set length 682
[2020-02-28T02:01:20.133+0000][trace][gc,ergo,refine              ] gc(7842) Updating Refinement Zones: update_rs time: 6.303ms, update_rs buffers: 305, update_rs goal time: 19.997ms
[2020-02-28T02:01:20.133+0000][debug][gc,ergo,refine              ] gc(7842) Updated Refinement Zones: green: 572, yellow: 1716, red: 2860
[2020-02-28T02:04:36.095+0000][trace][gc,ergo,cset                ] gc(7843) Start choosing CSet. pending cards: 26115 predicted base time: 12.85ms remaining time: 187.15ms target pause time: 200.00ms
[2020-02-28T02:04:36.095+0000][trace][gc,ergo,cset                ] gc(7843) Add young regions to CSet. eden: 676 regions, survivors: 6 regions, predicted young region time: 69.11ms, target pause time: 200.00ms
[2020-02-28T02:04:36.095+0000][debug][gc,ergo,cset                ] gc(7843) Finish choosing CSet. old: 0 regions, predicted old region time: 0.00ms, time remaining: 118.04
[2020-02-28T02:04:36.118+0000][debug][gc,ergo                     ] gc(7843) Running g1 Clear Card Table Task using 4 workers for 7 units of work for 894 regions.
[2020-02-28T02:04:36.120+0000][debug][gc,ergo                     ] gc(7843) Running g1 Free Collection Set using 4 workers for collection set length 682
[2020-02-28T02:04:36.121+0000][trace][gc,ergo,refine              ] gc(7843) Updating Refinement Zones: update_rs time: 6.929ms, update_rs buffers: 364, update_rs goal time: 19.997ms
[2020-02-28T02:04:36.121+0000][debug][gc,ergo,refine              ] gc(7843) Updated Refinement Zones: green: 572, yellow: 1716, red: 2860

Label gc,heap,gc,heap,region

gc,heapThe debug level will show an overview of gc heap when gc for g1  gc,heap,regionthe trace level, each region will print the details, this gc debugging for general use.

We generally only need to care about gc,heapthe log on the line

These labels are in

[2020-02-28T06:01:20.787+0000][debug][gc,heap                     ] gc(7922) Heap before gc invocations=7922 (full 0): garbage-first heap   total 8388608K, used 4076387K [0x0000000600000000, 0x0000000800000000)
[2020-02-28T06:01:20.787+0000][debug][gc,heap                     ] gc(7922)   region size 4096K, 682 young (2793472K), 5 survivors (20480K)
[2020-02-28T06:01:20.787+0000][debug][gc,heap                     ] gc(7922)  Metaspace       used 163068K, capacity 166731K, committed 169728K, reserved 1198080K[2020-02-28T06:01:20.787+0000][debug][gc,heap                     ] gc(7922)   class space    used 18180K, capacity 19580K, committed 20480K, reserved 1048576K
[2020-02-28T06:01:20.787+0000][trace][gc,heap,region              ] gc(7922) Heap Regions: E=young(eden), S=young(survivor), O=old, HS=humongous(starts), HC=humongous(continues), CS=collection set, F=free, A=archive, TAMS=top-at-mark-start (previous, next)[2020-02-28T06:01:20.787+0000][trace][gc,heap,region              ] gc(7922) |   0|0x0000000600000000, 0x0000000600400000, 0x0000000600400000|100%| O|  |TAMS 0x0000000600400000, 0x0000000600000000| Untracked
[2020-02-28T06:01:20.787+0000][trace][gc,heap,region              ] gc(7922) |   1|0x0000000600400000, 0x0000000600800000, 0x0000000600800000|100%| O|  |TAMS 0x0000000600800000, 0x0000000600400000| Untracked
[2020-02-28T06:01:20.787+0000][trace][gc,heap,region              ] gc(7922) |   2|0x0000000600800000, 0x0000000600c00000, 0x0000000600c00000|100%| O|  |TAMS 0x0000000600c00000, 0x0000000600800000| Untracked
[2020-02-28T06:01:20.787+0000][trace][gc,heap,region              ] gc(7922) |   3|0x0000000600c00000, 0x0000000601000000, 0x0000000601000000|100%| O|  |TAMS 0x0000000601000000, 0x0000000600c00000| Untracked
[2020-02-28T06:01:20.787+0000][trace][gc,heap,region              ] gc(7922) |   4|0x0000000601000000, 0x0000000601400000, 0x0000000601400000|100%| O|  |TAMS 0x0000000601400000, 0x0000000601000000| Untracked
[2020-02-28T06:01:20.787+0000][trace][gc,heap,region              ] gc(7922) |   5|0x0000000601400000, 0x0000000601800000, 0x0000000601800000|100%| O|  |TAMS 0x0000000601800000, 0x0000000601400000| Untracked
[2020-02-28T06:01:20.787+0000][trace][gc,heap,region              ] gc(7922) |   6|0x0000000601800000, 0x0000000601c00000, 0x0000000601c00000|100%| O|  |TAMS 0x0000000601c00000, 0x0000000601800000| Untracked

Labelgc,humongous  If you are using g1 gc, and often Evacuation Failure or Humongous Allocation, and do not know what the reason, you can consider a look at this tag related logs:

[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 219 object size 2160888 start 0x0000000636c00000  with remset 1 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 412 object size 2160888 start 0x0000000667000000  with remset 1 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 443 object size 3241320 start 0x000000066ec00000  with remset 1 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 489 object size 2160888 start 0x000000067a400000  with remset 2 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 490 object size 2160888 start 0x000000067a800000  with remset 1 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 499 object size 7292936 start 0x000000067cc00000  with remset 2 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 536 object size 2160888 start 0x0000000686000000  with remset 2 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 656 object size 2160888 start 0x00000006a4000000  with remset 1 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 768 object size 2160888 start 0x00000006c0000000  with remset 1 code roots 0 is marked 0 reclaim candidate 0 type array 0
[2020-02-28T06:01:20.831+0000][debug][gc,humongous                ] gc(7922) Live humongous region 786 object size 2160888 start 0x00000006c4800000  with remset 1 code roots 0 is marked 0 reclaim candidate 0 type array 0

Label gc,metaspace, gc,metaspace,freelist,gc,metaspace,freelist,blocks  gc log viewer metaspace related, gc,metaspacethe info output level will change every time gc metaspace involved in memory, if there is a change, the change will be detailed by gc,metaspace,freelist, gc,metaspace,freelist,blocksthe trace level of output.

[2020-02-28T04:32:13.123+0000][info ][gc,metaspace                ] gc(7896) Metaspace: 163062K->163062K(1198080K)
[2020-02-28T04:35:44.956+0000][trace][gc,metaspace,freelist       ] SpaceManager::grow_and_allocate for 49 words 109 words used 19 words left
[2020-02-28T04:35:44.956+0000][trace][gc,metaspace,freelist       ] ChunkManager::free_chunks_get: free_list: 0x00007fddccb89770 chunks left: 433.
[2020-02-28T04:35:44.956+0000][trace][gc,metaspace,freelist       ] ChunkManager::chunk_freelist_allocate: 0x00007fddccb89770 chunk 0x00007fdc74221000  size 128 count 433 Free chunk total 255616  count 824
[2020-02-28T04:35:44.956+0000][trace][gc,metaspace,freelist,blocks] returning block at 0x00007fdd95575b68 size = 19
[2020-02-28T04:35:44.956+0000][trace][gc,metaspace,freelist       ] SpaceManager::added chunk: 
[2020-02-28T04:35:44.956+0000][trace][gc,metaspace,freelist       ] Metachunk: bottom 0x00007fdc74221000 top 0x00007fdc74221040 end 0x00007fdc74221400 size 128 (specialized)
[2020-02-28T04:35:44.956+0000][trace][gc,metaspace,freelist       ] Free chunk total 255616  count 824
[2020-02-28T04:36:35.367+0000][info ][gc,metaspace                ] gc(7897) Metaspace: 163065K->163065K(1198080K)

Label gc,phases, gc,phases,ref, gc,phases,task, gc,ref, gc,start,gc,ref,start  these labels associated with gc step, if you want to learn gc algorithm, you can view a log of these labels, to understand the principles and steps gc

labelsafepoint

We know that only reach safepoint, we can be gc, if we can see the debug level of interest in the label of these logs safepoint

2. runtime class loading and compiling relevant

Label class,preorder, class,init, class,loadclass,unload  as the name suggests, this is the class initialization, class loading and unloading of the class log, info-level information on to enough. If you want to learn JVM class loading process, you can view the trace log level class label.

[8.931s][debug][class,preorder  ] com.fasterxml.jackson.core.PrettyPrinter source: file:/D:/Repositories/maven/com/fasterxml/jackson/core/jackson-core/2.10.0/jackson-core-2.10.0.jar
[8.931s][info][class,init              ] 2740 Initializing 'com/fasterxml/jackson/core/PrettyPrinter' (0x0000000801399220)
[8.934s][info][class,load              ] com.fasterxml.jackson.core.PrettyPrinter source: file:/D:/Repositories/maven/com/fasterxml/jackson/core/jackson-core/2.10.0/jackson-core-2.10.0.jar

Tagsjit,compilation  are generally for our time compiler optimization, only to see jit compiler log, the corresponding label is jit,compilation, the log level is debug

[2020-02-28T03:01:51.619+0000][debug][jit,compilation] 153756   !   4       jdk.internal.reflect.GeneratedConstructorAccessor161::newInstance (49 bytes)   made zombie
[2020-02-28T03:01:51.620+0000][debug][jit,compilation] 153219       4       io.lettuce.core.protocol.CommandArgs$IntegerArgument::encode (12 bytes)   made zombie
[2020-02-28T03:01:51.623+0000][debug][jit,compilation] 153192       4       io.lettuce.core.protocol.CommandArgs$StringArgument::writeString (60 bytes)   made zombie
[2020-02-28T03:01:54.911+0000][debug][jit,compilation] 157252   !   4       jdk.internal.reflect.GeneratedConstructorAccessor161::newInstance (49 bytes)

3. Other relevant runtime

Labelmonitorinflation  synchronization lock-related logs, general view debug level can be used to locate deadlock

[5.033s][debug][monitorinflation] Deflating object 0x0000000708310378 , mark 0x0000021cef446002 , type java.lang.ref.ReferenceQueue$Lock
[5.033s][debug][monitorinflation] Inflating object 0x0000000708310378 , mark 0x0000021cf085c002 , type java.lang.ref.ReferenceQueue$Lock
[5.035s][debug][monitorinflation] Deflating object 0x0000000708310378 , mark 0x0000021cf085c002 , type java.lang.ref.ReferenceQueue$Lock
[5.035s][debug][monitorinflation] Inflating object 0x0000000708310378 , mark 0x0000021cef445e02 , type java.lang.ref.ReferenceQueue$Lock

Labelbiasedlocking  biased locking related logs, you can usually see the info level, trace-level display more detailed biased locking contention details, can be used to implement the principles of learning biased locking

[7.273s][info ][biasedlocking] Revoking bias by walking my own stack:
[7.273s][info ][biasedlocking] Revoking bias of object 0x0000000711b1ca40, mark 0x000001c6d0acc905, type sun.net.www.protocol.jar.URLJarFile, prototype header 0x0000000000000105, allow rebias 0, requesting thread 0x000001c6d0acc800
[7.273s][info ][biasedlocking]   Revoked bias of object biased toward live thread (0x000001c6d0acc800)
[7.273s][trace][biasedlocking]    mon_info->owner (0x00000007022634d8) != obj (0x0000000711b1ca40)
[7.273s][trace][biasedlocking]    mon_info->owner (0x0000000711b200d8) != obj (0x0000000711b1ca40)
[7.273s][trace][biasedlocking]    mon_info->owner (0x0000000711b200d8) != obj (0x0000000711b1ca40)
[7.273s][trace][biasedlocking]    mon_info->owner (0x0000000702970260) != obj (0x0000000711b1ca40)
[7.273s][info ][biasedlocking]   Revoked bias of currently-unlocked object

Two, JVM log configuration

Configuration format:

-Xlog[:[what][:[output][:[decorators][:output-options[,...]]]]]

If not specified, the default is:

-Xlog:all=warning:stdout:uptime,level,tags

This is a colon-separated configuration, after the colon is the first what, a second output, a third decorators, a fourth comma separated output-options. Portion corresponding portion is not disposed above the default value , for example, the following several group configuration is equivalent to:

  • -Xlog:all=warningAnd -Xlog::stdoutand -Xlog::::uptime,level,tagsand -Xlog:all=warning:stdoutand -Xlog::stdout:uptime,level,tagsand-Xlog:all=warning:stdout:uptime,level,tags
  • -Xlog:gc*=infoversus-Xlog:gc*=info:stdout:uptime,level,tags
  • -Xlog::file=/project/log/app.log::filecount=50,filesize=100Mversus-Xlog:all=warning:file=/project/log/app.log:uptime,level,tags:filecount=50,filesize=100M

1. what

what label also includes the log level, for example, you can configure:

  • -Xlog:gc=info, Saying only that all log gc contains a label, info level will be output.
  • -Xlog:gc*=infoIndicating label containing all log gc, info output level will be, which is above gc related to all the labels .
  • -Xlog:gc+age=debugIndicating at the same time includes only the  gc and age of these two labels, debug level will be output.
  • -Xlog:gc*=info,gc+heap=debug,gc+heap+region=debugWhile setting includes only the  gc heap and those two labels to debug, includes only the  set gc heap and region and three labels to debug, the rest of the log level contains gc label for info and because we just know that age labels and tags with gc, so you can also write:
  • -Xlog:gc*=info,age*=debug And  -Xlog:gc*=info,gc+age=debugare equivalent to such a label may be incorporated, to modify the parameters to see how the log is merged JVM JVM log level section can be modified dynamically by reference to the following be.

Log levels include:

  • off: Close
  • trace: contains trace, debug, info, warning, error logs all
  • debug:包含debug,info,warning,error
  • info: contains info, warning, error
  • warning:包含warning,error
  • error: it contains only error

** If the level is not given, then the default is to configure the info level. ** for example, -Xlog:gc*and -Xlog:gc*=infois equivalent to

If the wrong label, it will exit with an error:

[0.005s][error][logging] Invalid tag 'phase' in log selection. Did you mean 'phases'?
Invalid -Xlog option '-Xlog:gc+phase=debug', see error log for details.

If there is no combination of such a label (or label alone can not appear), the alarm will be, but continues to run:

[0.006s][warning][logging] No tag set matches selection: gc+add. Did you mean any of the following? gc* gc+metaspace* gc+ref* gc+stringtable gc+compaction
[0.007s][warning][logging] No tag set matches selection: phases. Did you mean any of the following? phases* gc+phases* gc+phases+start* gc+phases+task gc+phases+ref

2. output

It contains three outputs:

  • stdout:  Standard output

  • stderr:  Standard error output

  • file = filename  output to a file

For the configuration file can be output to Output-Options : filecount=50,filesize=100MThis represents a 50 to retain files, each 100M

3. decorators

You can use the tag:

mark meaning
time or t Current time, ISO-8601 format
utctime or utc UTC time
uptime or u Elapsed time to start now, with millisecond precision
timemillis or tm Milliseconds timestamp, equivalentSystem.currentTimeMillis().
uptimemillis or um Start to the millisecond time now
timenanos or tn Nanosecond timestamps, equivalent toSystem.nanoTime()
uptimenanos or un Nanosecond time to start now
hostname or hn Host Name
pid or p Process ID
tid or ti Thread number
l level or Log Level
tags or tg Log tag, label section reference log previously mentioned

Suppose we configure uptime,level,tags, the log will be like this:

[2020-02-26T08:34:12.823+0000][debug][gc,age         ] gc(1661) Desired survivor size 167772160 bytes, new threshold 6 (max threshold 6)

4. The conversion of the old version to the new version of the log configuration log configuration

gc Related:

Original parameters New equivalent parameters and description
g1PrintHeapRegions -Xlog:gc+region=trace
gcLogFileSize and NumberOfgcLogFiles there UsegcLogFileRotation And output achieved by the above-mentioned output-option
PrintTenuringDistribution -Xlog: gc + age * = level, referring to the above gc, age label to determine the level you want to view
PrintAdaptiveSizePolicy -Xlog: gc + ergo * = level, referring to the above gc, ergo Tags section to determine the log level you want to see
Printgc -Xlog: gc = info or -Xlog: gc, gc print all log contains only tag
PrintgcDetails -Xlog:gc*=infoor-Xlog:gc*
PrintgcApplicationConcurrentTime和PrintgcApplicationStoppedTime -Xlog: safepoint = log or -Xlog: safepoint, the original is separated, in the new log parameters, tags are safepoint
PrintgcTaskTimeStamps -Xlog:gc+task*=debug
PrintHeapAtgc -Xlog:gc+heap=trace
PrintReferencegc -Xlog:gc+ref*=debug
PrintStringDeduplicationStatistics -Xlog:gc+stringdedup*=debug
PrintgcDateStamps The present configuration by decorators section above, or corresponds to the time t
PrintgcCause和PrintgcID There are currently ID gc gc reason of default would play out, you do not configure this anymore

Other parameters:

Original parameters New equivalent parameters and description
TraceExceptions -Xlog: exceptions = info print any error exception log JVM encountered, the default print only error level
TraceClassLoadingPreorder -Xlog:class+preorder=debug
TraceClassLoading -Xlog: class + load = info loading type printing log, info level it is sufficient
TraceClassUnloading -Xlog:class+unload=info 打印类卸载日志,info 级别就很足够
TraceClassLoadingPreorder -Xlog:class+preorder=debug
TraceClassInitialization -Xlog:class+init=info
TraceClassResolution -Xlog:class+resolve=debug
TraceClassPaths -Xlog:class+path=info
TraceLoaderConstraints -Xlog:class+loader+constraints=info
VerboseVerification -Xlog:verification=info
TraceSafepoint -Xlog:safepoint=debug
TraceSafepointCleanupTime -Xlog:safepoint+cleanup=info
TraceMonitorInflation -Xlog:monitorinflation=debug
TraceBiasedLocking -Xlog:biasedlocking=level 可以参考上面提到的 biasedlocking 标签,根据你想看的信息来配置级别
TraceRedefineClasses -Xlog:redefine+class*=level

三、动态修改JVM日志级别

可以通过 jcmd 动态修改 JVM 日志配置, 主要命令是VM.log, 假设我们的 JVM 进程是22,则可以通过这个命令查看格式:

jcmd 22  VM.log

结果:

22
Syntax : VM.log [options]

Options: (options must be specified using the <key> or <key>=<value> syntax)
        output : [optional] The name or index (#<index>) of output to configure. (STRING, no default value)
        output_options : [optional] Options for the output. (STRING, no default value)
        what : [optional] Configures what tags to log. (STRING, no default value)
        decorators : [optional] Configures which decorators to use. Use 'none' or an empty value to remove all. (STRING, no default value)
        disable : [optional] Turns off all logging and clears the log configuration. (BOOLEAN, no default value)
        list : [optional] Lists current log configuration. (BOOLEAN, no default value)
        rotate : [optional] Rotates all logs. (BOOLEAN, no default value)

查看当前日志参数配置

假设我们22的进程,启动参数中日志相关的参数是这么配置的:

-Xlog:gc*=debug:file=/project/log/gc.log:utctime,level,tags:filecount=50,filesize=100M 
-Xlog:jit+compilation=debug:file=/project/log/jit_compile.log:utctime,level,tags:filecount=10,filesize=100M

执行list命令:

jcmd 22 VM.log list

结果:

22:

Log output configuration:
 #0: stdout all=warning uptime,level,tags
 #1: stderr all=off uptime,level,tags
 #2: file=/project/log/gc.log all=off,gc*=debug utctime,level,tags filecount=50,filesize=100M
 #3: file=/project/log/jit_compile.log all=off,jit+compilation=debug utctime,level,tags filecount=10,filesize=100M

里面的#0还有#1是我们之前说的默认JVM日志配置:

 #0: stdout all=warning uptime,level,tags //代表标准输出中输出所有标签的warn级别日志,格式为[uptime][level][tags]日志内容
 #1: stderr all=off uptime,level,tags //代表标准错误输出中,不输出任何日志

我们在启动参数中配置的日志参数对应的是#2#3

让日志另起一个文件输出

jcmd 22 VM.log rotate
22:
Command executed successfully

可以看到#2#3对应的日志都另起一个文件继续输出

关闭所有日志,并清理日志相关参数

jcmd 22 VM.log disable
22:
Command executed successfully
jcmd 22 VM.log list
22:

Log output configuration:
 #0: stdout all=off uptime,level,tags
 #1: stderr all=off uptime,level,tags

可以看出,执行这个命令后,所有的日志都被关闭,并且参数被清理掉了(连启动参数配置的日志参数都不例外)

新增日志配置输出

以下参数和我们启动参数的-Xlog:gc*=debug:file=/project/log/gc.log:utctime,level,tags:filecount=50,filesize=100M保持一致。

jcmd 22 VM.log output=/project/core/log/gc.log output_options="filecount=50,filesize=100M" decorators="utctime,level,tags" what="gc*=debug"

结果:

22:
Command executed successfully

jcmd 22 VM.log list

22:

Log output configuration:
 #0: stdout all=off uptime,level,tags
 #1: stderr all=off uptime,level,tags
 #2: file=/project/core/log/gc.log all=off,gc*=debug utctime,level,tags filecount=50,filesize=100M (reconfigured)

由于之前配置过一次所以这里有(reconfigured)

修改日志配置输出

怎么区分日志呢?是通过 output 来唯一区分的(不指定就是stdout)。保持与现有的某个output一致,就是修改配置,但是 output_options 只要设定了,就不能改,只能通过 disable 关闭所有日志之后重新设置。

例如我们来修改刚刚的配置级别为info:

jcmd 22 VM.log output=/project/core/log/gc.log what="gc*=info"

结果:

22:
Command executed successfully

jcmd 22 VM.log list
22:

Log output configuration:
 #0: stdout all=off uptime,level,tags
 #1: stderr all=off uptime,level,tags
 #2: file=/project/core/log/gc.log all=off,gc*=info uptime,level,tags filecount=50,filesize=100M (reconfigured)

其中,标签为包含关系的会自动合并,每次设置是增量设置,而不是全量设置也就是每次配置的what会附加到现有的输出当中,从下面几个例子就能看出来

jcmd 22 VM.log output=/project/core/log/gc.log what="gc+age=info"

22:
Command executed successfully

jcmd 22 VM.log list

22:

Log output configuration:
 #0: stdout all=off uptime,level,tags
 #1: stderr all=off uptime,level,tags
 #2: file=/project/core/log/gc.log all=off,gc*=info uptime,level,tags filecount=50,filesize=100M (reconfigured)

由于gc+age其实属于gc*,所以被合并到了gc*

jcmd 22 VM.log output=/project/core/log/gc.log what="gc+age=debug"

22:
Command executed successfully

jcmd 22 VM.log list

22:

Log output configuration:
 #0: stdout all=off uptime,level,tags
 #1: stderr all=off uptime,level,tags
 #2: file=/project/core/log/gc.log all=off,gc*=info,age*=debug uptime,level,tags filecount=50,filesize=100M (reconfigured)
 

gc+age设置为 debug 级别,合并变成了gc*=info,age*=debug,可以推测出,age 只能和 gc 搭配使用

jcmd 22 VM.log output=/project/core/log/gc.log what="gc+alloc+region=debug"

22:
Command executed successfully

jcmd 22 VM.log list

22:

Log output configuration:
 #0: stdout all=off uptime,level,tags
 #1: stderr all=off uptime,level,tags
 #2: file=/project/core/log/gc.log all=off,gc*=info,age*=debug,alloc+region*=debug uptime,level,tags filecount=50,filesize=100M (reconfigured)
 
jcmd 22 VM.log output=/project/core/log/gc.log what="gc+heap=debug,gc+heap+region=debug"

22:

Command executed successfully

jcmd 22 VM.log list

22:

Log output configuration:
 #0: stdout all=off uptime,level,tags
 #1: stderr all=off uptime,level,tags
 #2: file=/project/core/log/gc.log all=off,gc*=info,age*=debug,region*=debug,gc+heap=debug,gc+region=info uptime,level,tags filecount=50,filesize=100M (reconfigured)

gc+alloc+region设置为 debug ,合并变成了gc*=info,age*=debug;再加上gc+heap=debug,gc+heap+region=debug,合并变成了gc*=info,age*=debug,region*=debug,gc+heap=debug,gc+region=info,可以看出,region 只有两种搭配gc+alloc+regiongc+heap+region

附Java/C/C++/机器学习/算法与数据结构/前端/安卓/Python/程序员必读/书籍书单大全:

(点击右侧 即可打开个人博客内有干货):技术干货小栈
=====>>①【Java大牛带你入门到进阶之路】<<====
=====>>②【算法数据结构+acm大牛带你入门到进阶之路】<<===
=====>>③【数据库大牛带你入门到进阶之路】<<=====
=====>>④【Web前端大牛带你入门到进阶之路】<<====
=====>>⑤【机器学习和python大牛带你入门到进阶之路】<<====
=====>>⑥【架构师大牛带你入门到进阶之路】<<=====
=====>>⑦【C++大牛带你入门到进阶之路】<<====
=====>>⑧【ios大牛带你入门到进阶之路】<<====
=====>>⑨【Web安全大牛带你入门到进阶之路】<<=====
=====>>⑩【Linux和操作系统大牛带你入门到进阶之路】<<=====

天下没有不劳而获的果实,望各位年轻的朋友,想学技术的朋友,在决心扎入技术道路的路上披荆斩棘,把书弄懂了,再去敲代码,把原理弄懂了,再去实践,将会带给你的人生,你的工作,你的未来一个美梦。

发布了141 篇原创文章 · 获赞 17 · 访问量 8159

Guess you like

Origin blog.csdn.net/JKX_geek/article/details/104891119