JVM(G1)内存不足溢出测试

package org.ziegler.gc;

/**
 * VM参数:-Xms10M -Xmx10M -Xlog:gc*
 * */
public class GCOutOfMemoryTest {

    public static void main(String[] args) {
        byte[] a1, a2, a3, a4;
        a1 = new byte[2 * 1024 * 1024];
        a2 = new byte[2 * 1024 * 1024];
        a3 = new byte[2 * 1024 * 1024];
        a4 = new byte[4 * 1024 * 1024];
        final int i = a1[0] + a2[0] + a3[0] + a4[0];
        System.out.println(i);
    }
}
[0.021s][info][gc,heap] Heap region size: 1M
[0.022s][info][gc     ] Using G1
[0.022s][info][gc,heap,coops] Heap address: 0x00000000ff600000, size: 10 MB, Compressed Oops mode: 32-bit
[0.215s][info][gc,start     ] GC(0) Pause Young (Concurrent Start) (G1 Humongous Allocation)
[0.215s][info][gc,task      ] GC(0) Using 2 workers of 8 for evacuation
[0.218s][info][gc,phases    ] GC(0)   Pre Evacuate Collection Set: 0.0ms
[0.218s][info][gc,phases    ] GC(0)   Evacuate Collection Set: 2.8ms
[0.218s][info][gc,phases    ] GC(0)   Post Evacuate Collection Set: 0.1ms
[0.218s][info][gc,phases    ] GC(0)   Other: 0.4ms
[0.218s][info][gc,heap      ] GC(0) Eden regions: 3->0(1)
[0.218s][info][gc,heap      ] GC(0) Survivor regions: 0->1(1)
[0.218s][info][gc,heap      ] GC(0) Old regions: 0->1
[0.218s][info][gc,heap      ] GC(0) Humongous regions: 3->3
[0.218s][info][gc,metaspace ] GC(0) Metaspace: 6297K->6297K(1056768K)
[0.218s][info][gc           ] GC(0) Pause Young (Concurrent Start) (G1 Humongous Allocation) 5M->4M(10M) 3.397ms
[0.218s][info][gc,cpu       ] GC(0) User=0.02s Sys=0.00s Real=0.00s
[0.218s][info][gc           ] GC(1) Concurrent Cycle
[0.218s][info][gc,marking   ] GC(1) Concurrent Clear Claimed Marks
[0.218s][info][gc,marking   ] GC(1) Concurrent Clear Claimed Marks 0.009ms
[0.218s][info][gc,marking   ] GC(1) Concurrent Scan Root Regions
[0.219s][info][gc,marking   ] GC(1) Concurrent Scan Root Regions 0.679ms
[0.219s][info][gc,marking   ] GC(1) Concurrent Mark (0.219s)
[0.219s][info][gc,marking   ] GC(1) Concurrent Mark From Roots
[0.219s][info][gc,task      ] GC(1) Using 2 workers of 2 for marking
[0.221s][info][gc,start     ] GC(2) Pause Young (Normal) (G1 Humongous Allocation)
[0.221s][info][gc,task      ] GC(2) Using 2 workers of 8 for evacuation
[0.223s][info][gc           ] GC(2) To-space exhausted
[0.223s][info][gc,phases    ] GC(2)   Pre Evacuate Collection Set: 0.0ms
[0.223s][info][gc,phases    ] GC(2)   Evacuate Collection Set: 1.4ms
[0.223s][info][gc,phases    ] GC(2)   Post Evacuate Collection Set: 1.1ms
[0.223s][info][gc,phases    ] GC(2)   Other: 0.1ms
[0.223s][info][gc,heap      ] GC(2) Eden regions: 1->0(1)
[0.223s][info][gc,heap      ] GC(2) Survivor regions: 1->1(1)
[0.224s][info][gc,heap      ] GC(2) Old regions: 1->2
[0.224s][info][gc,heap      ] GC(2) Humongous regions: 6->6
[0.224s][info][gc,metaspace ] GC(2) Metaspace: 6322K->6322K(1056768K)
[0.224s][info][gc           ] GC(2) Pause Young (Normal) (G1 Humongous Allocation) 7M->8M(10M) 2.741ms
[0.224s][info][gc,cpu       ] GC(2) User=0.00s Sys=0.00s Real=0.00s
[0.224s][info][gc,task      ] GC(3) Using 1 workers of 8 for full compaction
[0.224s][info][gc,start     ] GC(3) Pause Full (G1 Humongous Allocation)
[0.224s][info][gc,phases,start] GC(3) Phase 1: Mark live objects
[0.228s][info][gc,stringtable ] GC(3) Cleaned string and symbol table, strings: 2839 processed, 7 removed, symbols: 26329 processed, 0 removed
[0.228s][info][gc,phases      ] GC(3) Phase 1: Mark live objects 4.295ms
[0.228s][info][gc,phases,start] GC(3) Phase 2: Prepare for compaction
[0.229s][info][gc,phases      ] GC(3) Phase 2: Prepare for compaction 0.895ms
[0.229s][info][gc,phases,start] GC(3) Phase 3: Adjust pointers
[0.230s][info][gc,phases      ] GC(3) Phase 3: Adjust pointers 1.200ms
[0.230s][info][gc,phases,start] GC(3) Phase 4: Compact heap
[0.231s][info][gc,phases      ] GC(3) Phase 4: Compact heap 0.475ms
[0.231s][info][gc,heap        ] GC(3) Eden regions: 0->0(1)
[0.231s][info][gc,heap        ] GC(3) Survivor regions: 1->0(1)
[0.231s][info][gc,heap        ] GC(3) Old regions: 2->2
[0.231s][info][gc,heap        ] GC(3) Humongous regions: 6->6
[0.231s][info][gc,metaspace   ] GC(3) Metaspace: 6322K->6322K(1056768K)
[0.231s][info][gc             ] GC(3) Pause Full (G1 Humongous Allocation) 8M->7M(10M) 7.377ms
[0.231s][info][gc,cpu         ] GC(3) User=0.00s Sys=0.00s Real=0.01s
[0.231s][info][gc,task        ] GC(4) Using 1 workers of 8 for full compaction
[0.231s][info][gc,start       ] GC(4) Pause Full (G1 Humongous Allocation)
[0.231s][info][gc,phases,start] GC(4) Phase 1: Mark live objects
[0.234s][info][gc,stringtable ] GC(4) Cleaned string and symbol table, strings: 2832 processed, 2 removed, symbols: 26329 processed, 0 removed
[0.234s][info][gc,phases      ] GC(4) Phase 1: Mark live objects 2.251ms
[0.234s][info][gc,phases,start] GC(4) Phase 2: Prepare for compaction
[0.234s][info][gc,phases      ] GC(4) Phase 2: Prepare for compaction 0.309ms
[0.234s][info][gc,phases,start] GC(4) Phase 3: Adjust pointers
[0.235s][info][gc,phases      ] GC(4) Phase 3: Adjust pointers 0.761ms
[0.235s][info][gc,phases,start] GC(4) Phase 4: Compact heap
[0.235s][info][gc,phases      ] GC(4) Phase 4: Compact heap 0.313ms
[0.235s][info][gc,heap        ] GC(4) Eden regions: 0->0(1)
[0.235s][info][gc,heap        ] GC(4) Survivor regions: 0->0(1)
[0.235s][info][gc,heap        ] GC(4) Old regions: 2->2
[0.235s][info][gc,heap        ] GC(4) Humongous regions: 6->6
[0.235s][info][gc,metaspace   ] GC(4) Metaspace: 6322K->6322K(1056768K)
[0.235s][info][gc             ] GC(4) Pause Full (G1 Humongous Allocation) 7M->7M(10M) 4.075ms
[0.236s][info][gc,cpu         ] GC(4) User=0.02s Sys=0.00s Real=0.00s
[0.236s][info][gc,marking     ] GC(1) Concurrent Mark From Roots 16.420ms
[0.236s][info][gc,marking     ] GC(1) Concurrent Mark Abort
[0.236s][info][gc             ] GC(1) Concurrent Cycle 17.212ms
[0.237s][info][gc,heap,exit   ] Heap
[0.237s][info][gc,heap,exit   ]  garbage-first heap   total 10240K, used 7228K [0x00000000ff600000, 0x0000000100000000)
[0.237s][info][gc,heap,exit   ]   region size 1024K, 1 young (1024K), 0 survivors (0K)
[0.237s][info][gc,heap,exit   ]  Metaspace       used 6386K, capacity 6443K, committed 6528K, reserved 1056768K
[0.237s][info][gc,heap,exit   ]   class space    used 555K, capacity 570K, committed 640K, reserved 1048576K
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at org.ziegler.gc.GCOutOfMemoryTest.main(GCOutOfMemoryTest.java:12)

 

你可能感兴趣的:(Java,JVM)