Java Reference
In-Depth Information
There are multiple ways to enable the GC log: specifying either of the flags -verbose:gc or
-XX:+PrintGC will create a simple GC log (the flags are aliases for each other, and by de-
fault the log is disabled). The -XX:+PrintGCDetails flag will create a log with much more
information. This flag is recommended (it is also false by default); it is often too difficult to
diagnose what is happening with GC using only the simple log. In conjunction with the de-
tailed log, it is recommended to include -XX:+PrintGCTimeStamps or -
XX:+PrintGCDateStamps , so that the time between GC operations can be determined. The
difference in those two arguments is that the timestamps are relative to 0 (based on when the
JVM starts), while the date stamps are an actual date string. That makes the date stamps
ever-so-slightly less efficient as the dates are formatted, though it is an infrequent enough op-
eration that its effect is unlikely to be noticed.
The GC log is written to standard output, though that location can be changed with the -
Xloggc: filename flag. Using -Xloggc automatically enables the simple GC log unless
PrintGCDetails has also been enabled. The amount of data that is kept in the GC log can be
limited using log rotation; this is quite useful for a long-running server that might otherwise
fill up its disk with logs over several months. Logfile rotation is controlled with these flags: -
XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles= N -XX:GCLogFileSize= N . By de-
fault, UseGCLogFileRotation is disabled. When that flag is enabled, the default number of
files is 0 (meaning unlimited), and the default logfile size is 0 (meaning unlimited). Hence,
values must be specified for all these options in order for log rotation to work as expected.
Note that a logfile size will be rounded up to 8 KB for values less than that.
You can parse and peruse the GC logfiles on your own, although there are several tools that
do that. One of these is GC Histogram . GC Histogram reads in a GC log and provides sever-
al charts and tables about the data in that log. A summary of the overhead of GC produced by
GC Histogram is shown in Figure 5-4 .
Search WWH ::

Custom Search