53

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.

3 Answers 3

73

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.

3
  • 3
    Filesize is in bytes, unless you append a K, so you should probably use filesize=1024K instead. This is wrong even on 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 Dec 15, 2020 at 7:45
  • 1
    @GuntramBlohm thanks for the insight there, I think its really worth a mention and that's where this another answer from ocarlsen makes sense too.
    – Naman
    Dec 15, 2020 at 8:45
  • If you use -Xlog:safepoint, will you see literally ALL of the JVM pauses? Or would there be missing ones?
    – MarkoPaulo
    Mar 20, 2021 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 ...
3
  • Doesn't work for me, at least -Xlog:gc*,filecount=10,filesize=25M gives me a JVM that crashes instantly.
    – Aarkon
    Jun 16, 2021 at 10:47
  • @Aarkon you need more params than that and probably more colons to supply defaults in the format they want. See docs.oracle.com/javase/9/tools/… Xlog:gc:::filecount=10,filesize=25M should probably do it
    – jbu
    Mar 3, 2022 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 4, 2022 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

2

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.