打印GC日志
1.在Arguments 設置 VM Arguments:-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
2.測試代碼及日志打印public class MinorGCExample {private static final int _1MB=1024*1024;public static void testAllocation() {byte[] allocation1,allocation2,allocation3,allocation4;allocation1=new byte[2*_1MB];allocation2=new byte[2*_1MB];allocation3=new byte[2*_1MB];allocation4=new byte[4*_1MB];}public static void main(String[] args) {MinorGCExample.testAllocation();}
}日志打印:
HeapPSYoungGen total 9216K, used 7128K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)eden space 8192K, 87% used [0x00000000ff600000,0x00000000ffcf6038,0x00000000ffe00000)from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)ParOldGen total 10240K, used 4096K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)object space 10240K, 40% used [0x00000000fec00000,0x00000000ff000010,0x00000000ff600000)Metaspace used 2647K, capacity 4486K, committed 4864K, reserved 1056768Kclass space used 285K, capacity 386K, committed 512K, reserved 1048576K
?
?
?3.日志分析:對象優先在Eden分配
? ? I.當新生對象在Eden區中分配。當Eden區沒有足夠空間進行分配時,虛擬機會進行一次Minor GC(新生代)?
? ? ||.Arguments VM參數介紹:-XX:PrintGCDetails收集器日志參數,告訴虛擬機進行垃圾回收打印回收日志,程序退出時輸出當? ? ? ? ? ?前內存區域分配情況。
? ? |||.testAllocation()方法中,嘗試分配3個2MB大小和一個4MB大小,-Xms20M、-Xmx20M、-Xmn10M這三個參數限制了堆的? ? ? ? ? ?大小不可擴展,新生代分配10M,剩余的10M分配給老年代。-XX:SurvivorRatio=8e決定了新生代中的Eden與Survivor區的空? ? ? ? ?間比例為8:1
?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: The MySQL server is
- 下一篇: microsoft store打不开,提