java 堆溢出例子

阅读更多
引用
本次测试为idea 工具
 
引用
idea 内存分配,参考附件



import com.googl :wink: e.common.collect.Lists;

import java.util.List;

/**
 * @Author admin Date: 2017/6/19 10:40
 * @description:
 */
public class HeapOOM {

    static class  OOMObject{

    }
    public static void main(String[] args){
        List list = Lists.newArrayList();
        while (true){
            list.add(new OOMObject());
        }
    }
}

 


引用
结果输出:

"C:\Program Files\Java\jdk1.8.0_101\bin\java" -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.1\lib\idea_rt.jar=50551:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_101\jre\lib\charsets.jar;C:\Program ...
 HeapOOM
[GC (Allocation Failure) [PSYoungGen: 7709K->1022K(9216K)] 7709K->3562K(19456K), 0.0048906 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
[GC (Allocation Failure) [PSYoungGen: 8067K->1022K(9216K)] 10607K->10342K(19456K), 0.0080288 secs] [Times: user=0.06 sys=0.00, real=0.01 secs] 
[Full GC (Ergonomics) [PSYoungGen: 1022K->0K(9216K)] [ParOldGen: 9320K->8114K(10240K)] 10342K->8114K(19456K), [Metaspace: 3440K->3440K(1056768K)], 0.0939976 secs] [Times: user=0.14 sys=0.02, real=0.09 secs] 
[Full GC (Ergonomics) [PSYoungGen: 5123K->1503K(9216K)] [ParOldGen: 8114K->10126K(10240K)] 13237K->11630K(19456K), [Metaspace: 3441K->3441K(1056768K)], 0.0882936 secs] [Times: user=0.16 sys=0.00, real=0.09 secs] 
[Full GC (Ergonomics) [PSYoungGen: 8192K->7167K(9216K)] [ParOldGen: 10126K->9040K(10240K)] 18318K->16207K(19456K), [Metaspace: 3441K->3441K(1056768K)], 0.1115602 secs] [Times: user=0.17 sys=0.00, real=0.11 secs] 
[Full GC (Ergonomics) [PSYoungGen: 7915K->7865K(9216K)] [ParOldGen: 9040K->9040K(10240K)] 16955K->16905K(19456K), [Metaspace: 3441K->3441K(1056768K)], 0.0706948 secs] [Times: user=0.13 sys=0.00, real=0.07 secs] 
[Full GC (Allocation Failure) 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 HeapOOM.main(HeapOOM.java:17)
[PSYoungGen: 7865K->7865K(9216K)] [ParOldGen: 9040K->9014K(10240K)] 16905K->16880K(19456K), [Metaspace: 3441K->3441K(1056768K)], 0.1130058 secs] [Times: user=0.14 sys=0.00, real=0.11 secs] 
Heap
 PSYoungGen      total 9216K, used 8131K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 99% used [0x00000000ff600000,0x00000000ffdf0d60,0x00000000ffe00000)
  from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
  to   space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
 ParOldGen       total 10240K, used 9014K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 88% used [0x00000000fec00000,0x00000000ff4cda80,0x00000000ff600000)
 Metaspace       used 3472K, capacity 4600K, committed 4864K, reserved 1056768K
  class space    used 378K, capacity 424K, committed 512K, reserved 1048576K

Process finished with exit code 1
  • java 堆溢出例子_第1张图片
  • 大小: 48.9 KB
  • 查看图片附件

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