Java virtual machine GC log analysis

  • 2021-01-18 06:24:37
  • OfStack

This paper mainly studies the understanding of gc logs in Java virtual machine, as follows.

1. Log analysis

Understanding GC logging is an essential skill for dealing with Java virtual machine memory problems.

By adding parameters to the java command type to specify the corresponding gc type, printing gc log information and output to a file and other policies.

1. Write java code


public class ReferenceCountingGC {
	public Object instance = null;
	private static final int ONE_MB = 1024 * 1024;
	private byte[] bigSize = new byte[2 * ONE_MB];
	public static void main(String[] args) {
		testGC();
	}
	public static void testGC() {
		ReferenceCountingGC objA = new ReferenceCountingGC();
		ReferenceCountingGC objB = new ReferenceCountingGC();
		objA.instance = objB;
		objB.instance = objA;
		objA = null;
		objB = null;
		System.gc();
	}
}

2. Compile java file


javac ReferenceCountingGC.java 

3. Execute class file


java -XX:+PrintGCDateStamps -XX:+PrintGCDetails ReferenceCountingGC

The corresponding parameter list

[

-XX:+PrintGC output GC log
-XX:+PrintGCDetails outputs detailed logs for GC
-XX:+PrintGCTimeStamps Output GC timestamp (in the form of base time)
-XX:+PrintGCDateStamps outputs GC timestamp (in date form, e.g. 2013-05-04T21:53:59.234+0800)
-XX:+PrintHeapAtGC prints out heap information before and after GC
-Xloggc:.. /logs/ gc.log log file output path

]

Result output:

[

2016-03-20T14:34:55.118-0800: [GC [PSYoungGen: 6123K- > 400K(38912K)] 6123K- > 400K(125952K), 0.0012070 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2016-03-20T14:34:55.119-0800: [Full GC [PSYoungGen: 400K- > 0K(38912K)] [ParOldGen: 0K- > 282K(87040K)] 400K- > 282K(125952K) [PSPermGen: 2622K- > 2621K(21504K)], 0.0084640 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
Heap
PSYoungGen total 38912K, used 1013K [0x00000007d5500000, 0x00000007d8000000, 0x0000000800000000)
eden space 33792K, 3% used [0x00000007d5500000,0x00000007d55fd7d0,0x00000007d7600000)
from space 5120K, 0% used [0x00000007d7600000,0x00000007d7600000,0x00000007d7b00000)
to space 5120K, 0% used [0x00000007d7b00000,0x00000007d7b00000,0x00000007d8000000)
ParOldGen total 87040K, used 282K [0x0000000780000000, 0x0000000785500000, 0x00000007d5500000)
object space 87040K, 0% used [0x0000000780000000,0x0000000780046bf8,0x0000000785500000)
PSPermGen total 21504K, used 2628K [0x000000077ae00000, 0x000000077c300000, 0x0000000780000000)
object space 21504K, 12% used [0x000000077ae00000,0x000000077b091380,0x000000077c300000)

]

PSYoungGen stands for the new generation, and the name is determined by the collector, which in this case is Parallel Scavenge. ParOldGen for the elderly, PSPermGen for the permanent

If the collector is ParNew collector, the new generation is ParNew, Parallel New Generation If the collector is an Serial collector, the new generation is DefNew, Default New Generation

There are two types of GC: GC and Full and GC. Full indicates that Stop-The-World occurred this time.

Cenozoic GC (Minor GC) : Refers to the garbage collection in the Cenozoic, because Java objects are mostly with the characteristics of life and death, so Minor GC is very frequent, and the recycling speed is very fast.

Old GC (Major GC/Full GC) : refers to the old GC, the occurrence of Major GC, often accompanied by at least one Minor GC, Major GC is usually 10 times slower than Minor GC.

[

[GC [PSYoungGen: 6123K- > 400K(38912K)] 6123K- > 400K(125952K), 0.0012070 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

]

6123K- inside the square brackets above > 400K(38912K), which means the memory area used before GC - > GC = 38912K = 38912K = 38912K = 38912K = 38912K;

Square brackets outside 6123K- > 400K(125952K), indicating the capacity of the Java heap used before GC - > The Java heap has been used, and 125952K in parentheses is the total Java heap capacity.

[Times: user=0.00 sys=0.00, real=0.00 secs] respectively represent the CPU consumed by the user, the CPU consumed by the kernel mode and the wall clock time passed from the beginning to the end of the operation (Wall Clock Time). The difference between CPU and wall clock time is that the wall clock time includes various non-operational waiting time, such as waiting for the disk I/O, waiting for thread blocking, etc. The CPU time does not include these times.

2. Offline analysis of GC logs

Can use 1 some off-line tool to analyze GC log, such as sun gchisto (https: / / java net/projects/gchisto), gcviewer (https: / / github com/chewiebug/GCViewer), these are open source tools, users can directly download the source code through the version control tool, offline analysis.

conclusion

That is all about the Java virtual machine GC log analysis, I hope to help you. Interested friends can continue to refer to the site of other related topics, if there are shortcomings, welcome to leave a message to point out. Thank you for your support!


Related articles: