jvmGC日志分析

TestGC.java

public class TestGc {
	
	private static final int _1MB = 1024*1024;
	
	public static void main(String[] args) {
		byte[] allocation1, allocation2, allocation3, allocation4,allocation5,allocation6;
		
		allocation1 = new byte[2 * _1MB];
		allocation2 = new byte[2 * _1MB];
		allocation3 = new byte[4 * _1MB];
		allocation4 = new byte[4 * _1MB];
//		allocation5 = new byte[2 * _1MB];
//		allocation6 = new byte[1 * _1MB];
	}
}

gc输出

0.083: [GC (Allocation Failure) --[PSYoungGen: 5141K->5141K(9216K)] 5141K->5181K(9728K), 0.0009566 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
0.084: [Full GC (Ergonomics) [PSYoungGen: 5141K->4571K(9216K)] [ParOldGen: 40K->51K(512K)] 5181K->4623K(9728K), [Metaspace: 2691K->2691K(1056768K)], 0.0054408 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
0.091: [GC (Allocation Failure) --[PSYoungGen: 8667K->8667K(9216K)] 8719K->8823K(9728K), 0.0009663 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
0.092: [Full GC (Ergonomics) [PSYoungGen: 8667K->8588K(9216K)] [ParOldGen: 155K->128K(512K)] 8823K->8717K(9728K), [Metaspace: 2691K->2691K(1056768K)], 0.0038156 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
0.096: [GC (Allocation Failure) --[PSYoungGen: 8588K->8588K(9216K)] 8717K->8733K(9728K), 0.0006163 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
0.097: [Full GC (Allocation Failure) [PSYoungGen: 8588K->8572K(9216K)] [ParOldGen: 144K->132K(512K)] 8733K->8705K(9728K), [Metaspace: 2691K->2691K(1056768K)], 0.0039691 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at demo.TestGc.main(TestGc.java:18)
Heap
 PSYoungGen      total 9216K, used 8704K [0x00000000ff680000, 0x0000000100000000, 0x0000000100000000)
  eden space 8704K, 100% used [0x00000000ff680000,0x00000000fff00000,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 512K, used 133K [0x00000000ff600000, 0x00000000ff680000, 0x00000000ff680000)
  object space 512K, 26% used [0x00000000ff600000,0x00000000ff621490,0x00000000ff680000)
 Metaspace       used 2722K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 300K, capacity 386K, committed 512K, reserved 1048576K
Java HotSpot(TM) 64-Bit Server VM warning: MaxNewSize (10240k) is equal to or greater than the entire heap (10240k).  A new max generation size of 9728k will be used.

gc日志分析:

  1. 0.083: 自从jvm启动以来,GC发生的时间

  2. [GC (Allocation Failure) –[PSYoungGen: 5141K->5141K(9216K)] GC前该内存区域已使用容量 -> GC后该内存区域已使用容量(该内存区域总容量)

  3. 5141K->5181K(9728K) GC前java堆已使用容量 -> GC后java堆已使用容量(Java堆总容量)

  4. [Times: user=0.00 sys=0.00, real=0.00 secs] 用户消耗的CPU时间,内存态消耗的CPU时间,和操作从开始到结束所经过的墙钟时间