"-XX:+PrintGCDetails" - Garbage Collection Logging

This section describes HotSpot JVM options to generate garbage collection logging messages. It also describes log message format to help us understand what the JVM is telling us.

Now we have a good idea of what is Serial Collector, and how it works. Let's see if we watch it doing the memory management job for my sample application, GarbageCollection.java.

To do this, we are going to use some HotSpot command line options related to garbage collection logging:

Now let's try it with HotSpot 1.8:

C:\herong>\progra~1\java\jdk1.8.0\bin\javac GarbageCollection.java

C:\>\progra~1\java\jdk1.8.0\bin\java -Xms2m -Xmx64m -XX:+UseSerialGC
   -XX:+PrintGCDetails GarbageCollection
Step/TotalMemory/FreeMemory/UsedMemory:
   [GC (Allocation Failure) 
      0.054: [DefNew: 649K->64K(960K), 0.0008674 secs] 
      649K->505K(1984K), 0.0009833 secs] 
   [Times: user=0.00 sys=0.00, real=0.00 secs] 
1   2031616   697016   1334600
...

Okay. We got our first log message, which indicates a Minor Collection, from the Serial Collector. We need to understand the format of the message first to be able to read the it:

Continue with additional output in the console:

...
   [GC (Allocation Failure) 
      1.055: [DefNew: 861K->64K(960K), 0.0008510 secs]
      1.056: [Tenured: 1226K->1279K(1280K), 0.0009817 secs]
      1303K->1290K(2240K), 
      [Metaspace: 44K->44K(4480K)], 
      0.0019995 secs] 
   [Times: user=0.00 sys=0.00, real=0.00 secs] 
...

This log message indicates a Full Collection in the Heap (both Young Generation and Tenured Generation). It also did a Method Area (Metaspace) garbage collection. The Full Collection log is larger than the Minor Collection log and contains additional information:

The table below summarizes different types of information included in a GC log message:

[GC (Allocation Failure) 
     ^- GC reason
     
           v- GC type - Young Generation
   1.055: [DefNew: 861K->64K(960K), 0.0008510 secs]
   ^               ^     ^   ^      ^- Time spent on GC
   ^               ^     ^   ^- Total area size
   ^               ^     ^- Object size aftter GC
   ^- Timestamp    ^- Object size before GC
   
           v- GC type - Tenured Generation
   1.056: [Tenured: 1226K->1279K(1280K), 0.0009817 secs]

    v- Heap Summary
   1303K->1290K(2240K), 
   ^      ^     ^- Total area size
   ^      ^- Object size aftter GC
   ^- Object size before GC

    v- GC type - Method Area (Metaspace)
   [Metaspace: 44K->44K(4480K)], 
   
    v- Total time spent on the entire GC operation
   0.0019995 secs] 
   
    v- CPU time report of the entire GC operation
[Times: user=0.00 sys=0.00, real=0.00 secs] 
        ^         ^         ^- Elapsed time
        ^         ^- CPU time spent on OS kernel
        ^- CPU time spent on JVM

When Java application is ended or terminated, the JVM also generate a memory usage summary in the GC log:

Heap
 def new generation   total 19648K, used 8770K [0x03c00000, 0x051...
  eden space 17472K,  50% used [0x03c00000, 0x04490bb0, 0x04d1000...
  from space 2176K,   0% used [0x04f30000, 0x04f30000, 0x05150000...
  to   space 2176K,   0% used [0x04d10000, 0x04d10000, 0x04f30000...
 tenured generation   total 43712K, used 32730K [0x05150000, 0x07...
   the space 43712K,  74% used [0x05150000, 0x07146ba8, 0x07146c0...
 Metaspace used 45K, capacity 2242K, committed 2368K, reserved 4480K

Now we now how big each data area is and how much space was actually used in each area.

Last update: 2014.

Table of Contents

 About This Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 Sun's JVM - Java HotSpot VM

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Runtime Data Areas

Memory Management and Garbage Collectors

 Memory Management General Rules

 Java Exception: "java.lang.OutOfMemoryError: Java heap space"

 OutOfMemoryError Comparison of HotSpot and JRockit

 Garbage Collection Demonstration

 JVM Memory Manager - Garbage Collector

 Generational Garbage Collection in HotSpot

 Young Generation Collection - Minor Collection

 Tenured Generation Collection - Full Collection

 HotSpot Default Garbage Collector - Serial Collector

"-XX:+PrintGCDetails" - Garbage Collection Logging

 GC Log Messages on GarbageCollection.java

 Serial, Parallel, Concurrent, and Regionalized Collectors

 Parallel Collector GC Log Message Format

 Parallel Compacting Collector GC Log Message Format

 Concurrent Mark-Sweep Collector GC Log Message Format

 Garbage First GC Log Message Format

 Garbage Collection Tests

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 Outdated Tutorials

 References

 PDF Printing Version