52

In Java 11 a number of JVM args relating to GC logging are not supported anymore. What, if anything, can they be replaced with, if we still want to use GC logging? In particular, this relates to the following JVM args:

-Xlog:gc:work/logs/gc.log
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-XX:+PrintGCApplicationStoppedTime
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles
-XX:GCLogFileSize

Thanks.

martin_wun
  • 1,599
  • 1
  • 15
  • 33

3 Answers3

71

List of your <arguments, current mapping, reasons> is as follows:

-XX:+PrintGCTimeStamps    
-XX:+PrintGCDateStamps    ==>  decoration options
                               -Xlog:::time,level,tags

-XX:+PrintGCDetails       ==>  -Xlog:gc*

-XX:+PrintGCApplicationStoppedTime ==> -Xlog:safepoint

Note: PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime are logged on the same tag and not separated in the new logging.


-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles    
-XX:GCLogFileSize          ==>  output options
                                -Xlog::::filecount=5,filesize=1024

The bits that are handled by the framework do require tweaking

Reference: The documentation I've referred to and request you to follow for such migration details.

Dan Berindei
  • 7,054
  • 3
  • 41
  • 48
Naman
  • 27,789
  • 26
  • 218
  • 353
  • 3
    Filesize is in bytes, unless you append a K, so you should probably use filesize=1024K instead. This is wrong even on https://docs.oracle.com/en/java/javase/14/docs/specs/man/java.html, where there's an example that says `filesize=1024`, but later `filesize=file size with optional K, M or G suffix` – Guntram Blohm Dec 15 '20 at 07:45
  • 1
    @GuntramBlohm thanks for the insight there, I think its really worth a mention and that's where [this another answer](https://stackoverflow.com/a/56179352/1746118) from ocarlsen makes sense too. – Naman Dec 15 '20 at 08:45
  • If you use -Xlog:safepoint, will you see literally ALL of the JVM pauses? Or would there be missing ones? – MarkoPaulo Mar 20 '21 at 22:13
20

BTW, although the NumberOfGCLogFiles and GCLogFileSize options are gone in Java 11, it is still possible to set rolling file size and count. For example:

java -Xlog:gc*,safepoint:gc.log:time,uptime:filecount=100,filesize=128K ...
ocarlsen
  • 1,312
  • 2
  • 16
  • 20
  • Doesn't work for me, at least `-Xlog:gc*,filecount=10,filesize=25M` gives me a JVM that crashes instantly. – Aarkon Jun 16 '21 at 10:47
  • @Aarkon you need more params than that and probably more colons to supply defaults in the format they want. See https://docs.oracle.com/javase/9/tools/java.htm#JSWOR-GUID-BE93ABDC-999C-4CB5-A88B-1994AAAC74D5- Xlog:gc:::filecount=10,filesize=25M should probably do it – jbu Mar 03 '22 at 18:44
  • Re: previous comment, seems like I can't edit it anymore but that link doesn't jump to the right anchor. Just search for the section "Enable Logging with the JVM Unified Logging Framework" and you will see that the format is not as simple as in the example you've provided. – jbu Mar 04 '22 at 12:45
8

It does print date with time

-Xlog:gc*:verbose_gc.log:time

[2019-05-13T14:01:03.356+0530] Heap region size: 1M
[2019-05-13T14:01:03.357+0530] Using G1

NOTE :- JDK 11 been used

Swarit Agarwal
  • 2,520
  • 1
  • 26
  • 33
  • It is not working with JDK 11, it should be -Xlog:gc:file=verbose_gc.log:time – Diego Jan 06 '20 at 11:19
  • As per https://docs.oracle.com/javase/9/tools/java.htm#JSWOR-GUID-4856361B-8BFD-4964-AE84-121F5F6CF111 **PrintGCDetails** has been replaced with **-Xlog:gc*** – Swarit Agarwal Jan 07 '20 at 04:43