JVM-Java8 GC日誌分析

package com.java.test.jvm;

import org.junit.Test;

public class TestAllocation {
	
	private static final int _1MB = 1024* 1024;

	/**
	 * VM 參數:
	 * 		verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+PrintHeapAtGC
	 */
	@Test
    public void testAllocation(){
        byte[] allocation,allocation2,allocation3,allocation4;
        allocation = new byte[2*_1MB];
        allocation2 = new byte[2*_1MB];
        allocation3 = new byte[2*_1MB];
        allocation4 = new byte[4*_1MB];
    }

}

代碼運行結果:

{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 9216K, used 6392K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 78% used [0x00000000ff600000,0x00000000ffc3e368,0x00000000ffe00000)
  from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
  to   space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
 ParOldGen       total 10240K, used 0K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 0% used [0x00000000fec00000,0x00000000fec00000,0x00000000ff600000)
 Metaspace       used 4887K, capacity 5188K, committed 5248K, reserved 1056768K
  class space    used 571K, capacity 627K, committed 640K, reserved 1048576K
2020-04-02T15:22:06.321+0800: [GC (Allocation Failure) [PSYoungGen: 6392K->1008K(9216K)] 6392K->3309K(19456K), 0.0018253 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 9216K, used 1008K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffe00000)
  from space 1024K, 98% used [0x00000000ffe00000,0x00000000ffefc030,0x00000000fff00000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 10240K, used 2301K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 22% used [0x00000000fec00000,0x00000000fee3f658,0x00000000ff600000)
 Metaspace       used 4887K, capacity 5188K, committed 5248K, reserved 1056768K
  class space    used 571K, capacity 627K, committed 640K, reserved 1048576K
}
Heap
 PSYoungGen      total 9216K, used 5343K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 52% used [0x00000000ff600000,0x00000000ffa3bdc0,0x00000000ffe00000)
  from space 1024K, 98% used [0x00000000ffe00000,0x00000000ffefc030,0x00000000fff00000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 10240K, used 6397K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 62% used [0x00000000fec00000,0x00000000ff23f668,0x00000000ff600000)
 Metaspace       used 4904K, capacity 5188K, committed 5248K, reserved 1056768K
  class space    used 573K, capacity 627K, committed 640K, reserved 1048576K

日誌分析

 PSYoungGen      total 9216K, used 6392K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  1. PSYoungGen——表示使用 Parallel Scavenge 收集器回收新生代(Young Generation)
    ParOldGen——表示使用 Parallel Old 收集器回收老年代(Old Generation)

  2. PSYoungGen total 9216K, used 5343K——表示新生代總可用內存 9216 K,已使用 5343 K
    ParOldGen total 10240K, used 6397K——表示老年代總可用內存 10240 K,已使用 6397 K

 eden space 8192K, 78% used [0x00000000ff600000,0x00000000ffc3e368,0x00000000ffe00000)
 from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 to   space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
  1. eden space 8192K, 78% used——eden區可用內存 8192K,78% 已使用
2020-04-02T15:22:06.321+0800: [GC (Allocation Failure) [PSYoungGen: 6392K->1008K(9216K)] 6392K->3309K(19456K), 0.0018253 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 

參考文檔

java8 GC日誌分析
JDK1.8 GC日誌查看(參考深入理解JAVA虛擬機)
第22課:通過案例瞬間理解JVM中PSYoungGen、ParOldGen、MetaSpace
JVM垃圾回收機制入門
JVM GC 日誌詳解
GC日誌分析
GC之詳解CMS收集過程和日誌分析

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章