Heap def new generation total 9216K, used 2047K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000) eden space 8192K, 24% used [0x00000007bec00000, 0x00000007bedffce8, 0x00000007bf400000) from space 1024K, 0% used [0x00000007bf400000, 0x00000007bf400000, 0x00000007bf500000) to space 1024K, 0% used [0x00000007bf500000, 0x00000007bf500000, 0x00000007bf600000) tenured generation total 10240K, used 0K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000) the space 10240K, 0% used [0x00000007bf600000, 0x00000007bf600000, 0x00000007bf600200, 0x00000007c0000000) Metaspace used 3143K, capacity 4496K, committed 4864K, reserved 1056768K class space used 346K, capacity 388K, committed 512K, reserved 1048576K
byte[] a,b,c,d; a = new byte[2 * _1M]; System.out.println("create a"); b = new byte[2 * _1M]; System.out.println("create b"); c = new byte[2 * _1M]; System.out.println("create c"); d = new byte[5 * _1M]; System.out.println("create d");
}
运行结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
create a create b create c [GC (Allocation Failure) [DefNew: 8027K->479K(9216K), 0.0090355 secs] 8027K->6623K(19456K), 0.0090701 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] create d Heap def new generation total 9216K, used 5923K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000) eden space 8192K, 66% used [0x00000007bec00000, 0x00000007bf1512e0, 0x00000007bf400000) from space 1024K, 46% used [0x00000007bf500000, 0x00000007bf577d10, 0x00000007bf600000) to space 1024K, 0% used [0x00000007bf400000, 0x00000007bf400000, 0x00000007bf500000) tenured generation total 10240K, used 6144K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000) the space 10240K, 60% used [0x00000007bf600000, 0x00000007bfc00030, 0x00000007bfc00200, 0x00000007c0000000) Metaspace used 3191K, capacity 4496K, committed 4864K, reserved 1056768K class space used 354K, capacity 388K, committed 512K, reserved 1048576K
Heap PSYoungGen total 9216K, used 2047K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000) eden space 8192K, 24% used [0x00000007bf600000,0x00000007bf7ffce8,0x00000007bfe00000) from space 1024K, 0% used [0x00000007bff00000,0x00000007bff00000,0x00000007c0000000) to space 1024K, 0% used [0x00000007bfe00000,0x00000007bfe00000,0x00000007bff00000) ParOldGen total 10240K, used 0K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000) object space 10240K, 0% used [0x00000007bec00000,0x00000007bec00000,0x00000007bf600000) Metaspace used 3143K, capacity 4496K, committed 4864K, reserved 1056768K class space used 346K, capacity 388K, committed 512K, reserved 1048576K
Process finished with exit code 0
下面我们同样创建和上文一样的4个大对象,看看结果会怎么样?
同样的代码(换了收集器),运行结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
create a create b create c create d [GC (Allocation Failure) [PSYoungGen: 8192K->688K(9216K)] 13312K->5816K(19456K), 0.0009297 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap PSYoungGen total 9216K, used 852K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000) eden space 8192K, 2% used [0x00000007bf600000,0x00000007bf6290e8,0x00000007bfe00000) from space 1024K, 67% used [0x00000007bfe00000,0x00000007bfeac010,0x00000007bff00000) to space 1024K, 0% used [0x00000007bff00000,0x00000007bff00000,0x00000007c0000000) ParOldGen total 10240K, used 5128K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000) object space 10240K, 50% used [0x00000007bec00000,0x00000007bf102010,0x00000007bf600000) Metaspace used 3285K, capacity 4496K, committed 4864K, reserved 1056768K class space used 361K, capacity 388K, committed 512K, reserved 1048576K