简单来演示一下OOM的分析和实战。
直接上代码:
publicclassDemo4{publicstaticvoidmain(String[]args){ListDandanlist=newArrayList();while(true){list.add(newDandan());}}}classDandan{}
JVM参数:
-XX:+UseParNewGC-XX:+UseConcMarkSweepGC-Xms10m-Xmx10m-XX:+PrintGCDetails-Xloggc:gc_dandan.log-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=./
运行后的日志:
java.lang.OutOfMemoryError:JavaheapspaceDumpingheapto./java_pid.hprof...Heapdumpfilecreated[bytesin0.secs]Exceptioninthreadmainjava.lang.OutOfMemoryError:Javaheapspaceatjava.util.Arrays.copyOf(Arrays.java:)atjava.util.Arrays.copyOf(Arrays.java:)atjava.util.ArrayList.grow(ArrayList.java:)atjava.util.ArrayList.ensureExplicitCapacity(ArrayList.java:)atjava.util.ArrayList.ensureCapacityInternal(ArrayList.java:)atjava.util.ArrayList.add(ArrayList.java:)at