测试堆内存溢出

jvm参数设置:

-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails

-XX:SurvivorRatio=4


测试堆溢内存出代码:
package com.sxt.jvm; import java.util.ArrayList; public class JVM { public static void main(String[] args) { ArrayList<StringBuffer> arrayList = new ArrayList<StringBuffer>(); while(true){ arrayList.add(new StringBuffer()); } } } 

控制台输出:

[GC [PSYoungGen: 6912K->1640K(8576K)] 6912K->5992K(18816K), 0.0133114 secs] [Times: user=0.00 sys=0.00, real=0.06 secs]
[GC-- [PSYoungGen: 8552K->8552K(8576K)] 12904K->18792K(18816K), 0.0356064 secs] [Times: user=0.05 sys=0.00, real=0.04 secs]
[Full GC [PSYoungGen: 8552K->1660K(8576K)] [ParOldGen: 10240K->10236K(10240K)] 18792K->11896K(18816K) [PSPermGen: 2521K->2520K(21248K)], 0.2316587 secs] [Times: user=0.56 sys=0.00, real=0.23 secs]
[Full GC [PSYoungGen: 8515K->8050K(8576K)] [ParOldGen: 10236K->10236K(10240K)] 18751K->18287K(18816K) [PSPermGen: 2520K->2520K(21248K)], 0.1373233 secs] [Times: user=0.45 sys=0.00, real=0.14 secs]
[Full GC [PSYoungGen: 8050K->8036K(8576K)] [ParOldGen: 10236K->10236K(10240K)] 18287K->18272K(18816K) [PSPermGen: 2520K->2520K(21248K)], 0.1145759 secs] [Times: user=0.39 sys=0.00, real=0.12 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2245)
[Full GC [PSYoungGen: 8037K->0K(8576K)] [ParOldGen: 10239K->455K(10240K)] 18276K->455K(18816K) [PSPermGen: 2545K->2545K(21248K)], 0.0064279 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
at java.util.Arrays.copyOf(Arrays.java:2219)
at java.util.ArrayList.grow(ArrayList.java:213)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:187)
at java.util.ArrayList.add(ArrayList.java:411)
at com.sxt.jvm.JVM.main(JVM.java:9)
Heap
PSYoungGen total 8576K, used 219K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 6912K, 3% used [0x00000000ff600000,0x00000000ff636e50,0x00000000ffcc0000)
from space 1664K, 0% used [0x00000000ffcc0000,0x00000000ffcc0000,0x00000000ffe60000)
to space 1664K, 0% used [0x00000000ffe60000,0x00000000ffe60000,0x0000000100000000)
ParOldGen total 10240K, used 455K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 4% used [0x00000000fec00000,0x00000000fec71c60,0x00000000ff600000)
PSPermGen total 21248K, used 2552K [0x00000000f9a00000, 0x00000000faec0000, 0x00000000fec00000)
object space 21248K, 12% used [0x00000000f9a00000,0x00000000f9c7e3b0,0x00000000faec0000)

 

猜你喜欢

转载自www.cnblogs.com/huiandong/p/9476575.html