Understand the GC log

It is used java version "1.8.0_161"for testing.
Set the JVM startup parameters as:

-Xms10m -Xmx10m -XX:+PrintGCDetails -Xloggc:/data/log/gc.log 
-XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError 
-XX:HeapDumpPath=/data/log

Execute code snippet:

public class RuntimeConstantPoolOOM {
    
    
    public static void main(String[] args) {
    
    
        List<String> list = new ArrayList<>();
        int i = 0;
        while (true) {
    
    
            list.add(String.valueOf(i++).intern());
        }
    }
}

Then throw an exception

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded

Let's look at the generated gc.log.

CommandLine flags:
 -XX:+HeapDumpOnOutOfMemoryError
 -XX:HeapDumpPath=/data/log
 -XX:InitialHeapSize=10485760 
 -XX:MaxHeapSize=10485760
 -XX:+PrintGC 
 -XX:+PrintGCDateStamps 
 -XX:+PrintGCDetails 
 -XX:+PrintGCTimeStamps 
 -XX:+UseCompressedClassPointers
 -XX:+UseCompressedOops 
 -XX:+UseParallelGC 

This is the parameter of the virtual machine running in gc.log, we know that our garbage collector is ParallelGC.

Minor GC

Minor GC: Cenozoic GC refers to GC events that occur in the Cenozoic. Most Java objects in the Cenozoic are born and die. Minor GCs are frequent and the collection speed is very fast.

2018-11-18T19:31:12.804-0800: 0.207: 
[ GC (Allocation Failure) [PSYoungGen: 2048K->496K(2560K)] 
 2048K->588K(9728K), 0.0011270 secs ]
[Times: user=0.00 sys=0.01, real=0.00 secs] 
  1. 2018-11-18T19:31:12.804-0800: The start time point of the GC event
  2. 0.207: The start time of the GC event, relative to the start time of the JVM, in seconds
  3. GC: A sign used to distinguish whether it is Minor GC or Full GC, where it indicates the occurrence of Minor GC
  4. Allocation Failure: The cause of garbage collection, this GC is because the newly allocated data structure cannot be stored in the young generation
  5. PSYoungGen: Represents the new generation, this name is determined by the GC collector, the collector here is Parallel Scavenge, the new generation collector uses a replication algorithm for collection
  6. 2048K->496K(2560K): Indicates the memory usage of the young generation before and after this GC. 2560k in parentheses represents the total size of the young generation. The young generation is subdivided into Eden, From Survivor, and To Survivor spaces.
  7. 2048K->588K(9728K): Indicates the usage of heap memory before and after this GC, the memory size in parentheses indicates the available heap memory
  8. 0.0011270 secs:The duration of the GC event, in seconds
  9. Times: user=0.00 sys=0.01, real=0.00 secs: The duration of the GC event is measured by a variety of categories:
    user-This garbage collection, all the CPU time consumed by the garbage collection thread, that is, the CPU time consumed by the user mode-the CPU time
    sysconsumed by the kernel mode
    real-the application pause time (Clock time), including various non-operational waiting time, such as waiting for disk I/O, thread blocking, CPU time does not include these

Heap size =
young generation (eden + from + to) + old generation, the young generation recovered 1552 k from 2048K->496K, and the
heap memory recovered 1460 k from 2048K->588K. It
can be seen that there are 1552-1460 = 92k objects from The young generation upgraded to the old generation

Full GC

The GC (or Major GC) that occurred in the old age is often accompanied by at least one Minor GC. The speed of Full GC is generally more than 10 times slower than that of Minor GC.

2018-11-18T19:31:12.857-0800: 0.259:
 [Full GC (Ergonomics) [PSYoungGen: 480K->0K(2560K)] 
 [ParOldGen: 5706K->5764K(7168K)] 6186K->5764K(9728K),
 [Metaspace: 3317K->3317K(1056768K)], 0.0556835 secs] 
 [Times: user=0.09 sys=0.00, real=0.06 secs] 
  1. [Full GC (Ergonomics) [PSYoungGen: 480K->0K(2560K)]: Old generation GC, also known as Major GC, will be accompanied by a young generation GC (Minor GC), which is slower
  2. [ParOldGen: 5706K->5764K(7168K)] 6186K->5764K(9728K): Old generation GC, the old generation version of Parallel Scavenge, 5706K->5764K(7168K)]this is similar to the young generation GC, indicating the space occupied before and after GC. 6186K->5764K(9728K)Indicates the heap memory usage before and after GC, the size of the heap memory in parentheses
  3. [Metaspace: 3317K->3317K(1056768K)]: Represents the memory usage of the metaspace before and after GC. The parentheses indicate the total size of the JVM metaspace.
    Reference: Understanding Garbage Collection Logs
    JVM (13) Understanding GC logs
    "In-depth understanding of the Java Virtual Machine" (6) Heap memory usage analysis , Garbage collector GC log interpretation

Guess you like

Origin blog.csdn.net/jiaobuchong/article/details/84203749