目标:
模拟java堆溢出,并做简分析,熟悉环境搭建
环境: java version "1.8.0_131"
intelli IDEA
vm设置
参数分析:
-verbose:gc ==> 输出虚拟机GC详细情况
-Xms20M ===> 堆最小容量20M
-Xmx20M ===> 堆最大容量 20M
-Xmn10M ===> 年轻代容量 10M
-XX:+PrintGCDetails ==> 控制台打印GC具体细节
-XX:SurvivorRatio=8 ===> 设置2个survivor区,1 eden区大小比值为2:8 ,survivor区占整个
年轻代1/5,参数默认值为8
结果显示:
begin
[GC (Allocation Failure) [PSYoungGen: 8192K->1017K(9216K)] 8192K->4054K(19456K), 0.0073306 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [PSYoungGen: 9209K->1016K(9216K)] 12246K->9299K(19456K), 0.0138574 secs] [Times: user=0.06 sys=0.00, real=0.01 secs]
====> Young GC回收日志
9209K->1016K(9216K) 代表回收前、回收后以及总内存大小
Times: user=0.06 sys=0.00, real=0.01 secs ===>
user代表GC 需要的各个CPU总时间(各个CPU时间相加),sys代表回收器自身的行为所占用CPU时间,real则代表本次GC所耗费的真正耗时(在多核CPU中并行回收,它通常小于user)
[Full GC (Ergonomics) [PSYoungGen: 1016K->0K(9216K)] [ParOldGen: 8283K->9013K(10240K)] 9299K->9013K(19456K), [Metaspace: 3538K->3538K(1056768K)], 0.1593714 secs] [Times: user=0.20 sys=0.00, real=0.16 secs]
====> Full GC 回收
收集器为 parallel
[Full GC (Ergonomics) [PSYoungGen: 8192K->5631K(9216K)] [ParOldGen: 9013K->9449K(10240K)] 17205K->15080K(19456K), [Metaspace: 3538K->3538K(1056768K)], 0.3310052 secs] [Times: user=0.36 sys=0.02, real=0.33 secs]
[Full GC (Ergonomics) [PSYoungGen: 7588K->7307K(9216K)] [ParOldGen: 9449K->9445K(10240K)] 17037K->16753K(19456K), [Metaspace: 3538K->3538K(1056768K)], 0.1948600 secs] [Times: user=0.33 sys=0.00, real=0.19 secs]
[Full GC (Allocation Failure) [PSYoungGen: 7307K->7307K(9216K)] [ParOldGen: 9445K->9427K(10240K)] 16753K->16734K(19456K), [Metaspace: 3538K->3538K(1056768K)], 0.2022583 secs] [Times: user=0.23 sys=0.00, real=0.20 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3210)
at java.util.Arrays.copyOf(Arrays.java:3181)
at java.util.ArrayList.grow(ArrayList.java:261)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:235)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:227)
at java.util.ArrayList.add(ArrayList.java:458)
at memory.over.HeapOOM.main(HeapOOM.java:13)
Heap
PSYoungGen total 9216K, used 7507K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 8192K, 91% used [0x00000000ff600000,0x00000000ffd54ec0,0x00000000ffe00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
ParOldGen total 10240K, used 9427K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 92% used [0x00000000fec00000,0x00000000ff534d88,0x00000000ff600000)
Metaspace used 3570K, capacity 4506K, committed 4864K, reserved 1056768K
class space used 391K, capacity 394K, committed 512K, reserved 1048576K
Process finished with exit code 1
网友评论