Java 8 Garbage Collection Logging

From NovaOrdis Knowledge Base
Revision as of 19:30, 28 December 2020 by Ovidiu (talk | contribs) (→‎Internal)
Jump to navigation Jump to search

External

Internal

Overview

Overview

In Java 8, GC logging is enabled with the -Xloggc:<file> (see below). The actual -XX values the JVM operates with are displayed at the top of the log file:

...
CommandLine flags: -XX:InitialHeapSize=268435456 -XX:MaxHeapSize=4294967296 -XX:+PrintGC -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
...


The recommended GC logging configuration is:

-Xloggc:<absolute-path> -XX:+PrintGCDateStamps -XX:+PrintGCDetails

In case the space of the filesystem logs are written onto is limited, log rotation can be enabled.

Options

-Xloggc:

Turns on GC logging and directs the output into the specified file. When used, -verbose:gc becomes irrelevant.

-Xloggc:<file>

where <file> can be absolute or relative. In case of a relative path, it is relative to the current directory.

If used, the option automatically turns on the following: -XX:+PrintGC, -XX:+PrintGCTimeStamps.

-XX:+PrintGC

-XX:+PrintGC

Enables printing of messages at every GC. By default, this option is disabled, but -Xloggc:<file> turns it on implicitly.

-XX:+PrintGCTimeStamps

-XX:+PrintGCTimeStamps

Enables printing of time stamps (time in seconds since the JVM started) at every GC. By default, this option is disabled. It is implicit turned on if -Xloggc:<file> is used. Time stamps recorded this way provide a chronology relative to the time the JVM started, but additional calculation is needed to translate the timestamps to normal timestamps, and it is only possible if the JVM start time is also recorded. A better way to record timestamps is to use -XX:+PrintGCDateStamps.

-XX:+PrintGCDateStamps

-XX:+PrintGCDateStamps

Records the GC event timestamps in the following format:

2017-02-12T19:26:03.328+0800:

-XX:+PrintGCDetails

Enables printing of detailed messages at every GC:

-XX:+PrintGCDetails

When used, each GC event contains information of how the event affected various heap areas such as the young generation, old generation and the metaspace. The default behavior is to report how the entire heap was modified as the result of the GC event. The difference in output is the following:

2017-02-12T19:26:03.378+0800: 0.144: [Full GC (Ergonomics)  126674K->126513K(413696K), 0.0181008 secs]
2017-02-12T19:42:35.003+0800: 0.156: [Full GC (Ergonomics) [PSYoungGen: 10721K->0K(141824K)] [ParOldGen: 115952K->126513K(270848K)] 126674K->126513K(412672K), [Metaspace: 3447K->3447K(1056768K)], 0.0182535 secs] [Times: user=0.10 sys=0.03, real=0.02 secs]

-verbose:gc

Displays GC log information at stdout. This option is rendered irrelevant by -Xloggc:<file>. When -Xloggc:<file> is used, the GC log information is redirected into the specified file.

-verbose:gc

GC Log File Rotation

-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=5
-XX:GCLogFileSize=3M

-XX:+PrintGCApplicationConcurrentTime

Enables printing of how much time elapsed since the last GC pause.

-XX:+PrintGCApplicationConcurrentTime

Output Example:

2017-02-12T19:54:39.920+0800: 0.484: Application time: 0.0261502 seconds

-XX:+PrintGCApplicationStoppedTime

Enables printing of how much time the GC pause lasted.

-XX:+PrintGCApplicationStoppedTime

Output Example:

2017-02-12T19:57:57.170+0800: 0.116: Total time for which application threads were stopped: 0.0218238 seconds