SoFunction
Updated on 2025-03-08

A brief discussion on the features of JDK9, the xlog of JVM

Introduction

JVM is the basis for running Java programs. Various events in JVM such as GC, class loading, JPMS, heap, thread, etc. can actually be recorded with logs. Through these logs, we can monitor events in the JVM and tune the Java applications in turn.

The Xlog log service introduced in JDK9 was created for this purpose.

Through xlog, JDK unifies various events in the JVM and outputs them to the outside in a unified form. The molecular system is distinguished by tag parameters, the urgency of events is distinguished by log level, and the output address is configured by logging output.

Use of xlog

Let’s first look at the simplest example of using xlog:

java -Xlog -version

Output result:

[0.016s][info][os] Use of CLOCK_MONOTONIC is supported

[0.016s][info][os] Use of pthread_condattr_setclock is not supported

[0.016s][info][os] Relative timed-wait using pthread_cond_timedwait is associated with the default clock

[0.017s][info][os] SafePoint Polling address, bad (protected) page:0x0000000108901000, good (unprotected) page:0x0000000108902000

[0.022s][info][biasedlocking] Aligned thread 0x00007f983e008200 to 0x00007f983e008800

[0.023s][info][os,thread    ] Thread attached (tid: 10499, pthread id: 123145571979264).

The logs are very, very long, so I won't list them all here. From the output log we can see that the JVM performs many operations in the java -verson command.

We can see that each operation lists the time spent on the operation, the log level and the classification to which the operation belongs.

Through these logs, we can have a deeper understanding of the operation of the JVM.

Using the java -Xlog:help command, let's take a look at the basic format of xlog:

-Xlog Usage: -Xlog[:[selections][:[output][:[decorators][:output-options]]]]

where 'selections' are combinations of tags and levels of the form tag1[+tag2...][*][=level][,...]

NOTE: Unless wildcard (*) is specified, only log messages tagged with exactly the tags specified will be matched.

selections

selections indicates what information needs to be output. It is expressed by tag=level.

Tags represent events or subsystems in JVM:

Available log tags:

 add, age, alloc, annotation, aot, arguments, attach, barrier, biasedlocking, blocks, bot, breakpoint, bytecode, cds, census, class, classhisto, cleanup, codecache, compaction, compilation, constantpool, constraints, container, coops, cpu, cset, data, datacreation, dcmd, decoder, defaultmethods, director, dump, dynamic, ergo, event, exceptions, exit, fingerprint, free, freelist, gc, handshake, hashtables, heap, humongous, ihop, iklass, init, inlining, install, interpreter, itables, jfr, jit, jni, jvmti, liveness, load, loader, logging, malloc, mark, marking, membername, memops, metadata, metaspace, methodcomparator, mirror, mmu, module, monitorinflation, monitormismatch, nestmates, nmethod, normalize, numa, objecttagging, obsolete, oldobject, oom, oopmap, oops, oopstorage, os, pagesize, parser, patch, path, perf, periodic, phases, plab, preorder, preview, promotion, protectiondomain, ptrqueue, purge, record, redefine, ref, refine, region, reloc, remset, resolve, safepoint, sampling, scavenge, setting, smr, stackmap, stacktrace, stackwalk, start, startuptime, state, stats, streaming, stringdedup, stringtable, subclass, survivor, sweep, symboltable, system, table, task, thread, time, timer, tlab, tracking, unload, unshareable, update, verification, verify, vmmutex, vmoperation, vmthread, vtables, vtablestubs, workgang

 Specifying 'all' instead of a tag combination matches all tag combinations

levels represent the level of the log:

Available log levels: off, trace, debug, info, warning, error

Here is an example:

java -Xlog:os,class=info -version

Output result:

[0.002s][info][os] Use of CLOCK_MONOTONIC is supported

[0.002s][info][os] Use of pthread_condattr_setclock is not supported

[0.002s][info][os] Relative timed-wait using pthread_cond_timedwait is associated with the default clock

[0.003s][info][os] SafePoint Polling address, bad (protected) page:0x0000000109543000, good (unprotected) page:0x0000000109544000

[0.006s][info][os] attempting shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0./Contents/Home/lib/

[0.007s][info][os] shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0./Contents/Home/lib/ was successful

[0.007s][info][os] attempting shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0./Contents/Home/lib/

[0.010s][info][os] shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0./Contents/Home/lib/ was successful

output

output means where the log is output.

Optional for output:

stdout/stderr file=<filename>

stdout means standard output, stderr means standard error. File means output to the file.

For example:

java -Xlog:all=debug:file= -version

decorators

decorators means what is output to the log.

time (t), utctime (utc), uptime (u), timemillis (tm), uptimemillis (um), timenanos (tn), uptimenanos (un), hostname (hn), pid (p), tid (ti), level (l), tags (tg)

 Decorators can also be specified as 'none' for no decoration

Take a look at this example:

 java -Xlog:gc*=debug:stdout:time,uptimemillis,tid -version

Output result:

[2020-05-05T16:12:06.871-0800][32ms][9475] Heap region size: 1M

[2020-05-05T16:12:06.871-0800][32ms][9475] Minimum heap 8388608  Initial heap 134217728  Maximum heap 2147483648

[2020-05-05T16:12:06.872-0800][33ms][9475] Heap address: 0x0000000780000000, size: 2048 MB, Compressed Oops mode: Zero based, Oop shift amount: 3

[2020-05-05T16:12:06.872-0800][33ms][9475] ConcGCThreads: 1 offset 8

[2020-05-05T16:12:06.872-0800][33ms][9475] ParallelGCThreads: 4

The above is a detailed content about the JVM xlog of JDK9's features. For more information about JDK9's features, please pay attention to my other related articles!