欢迎来到天天文库
浏览记录
ID:40749835
大小:321.45 KB
页数:13页
时间:2019-08-07
《JVM内存溢出与排错》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、JVM内存溢出与排错一、JVM堆内存溢出Java堆用于存储对象实例,我们只要不断创建对象,并且保证GCRoots到对象之间有可达路径来避免垃圾回收机制来清除这些对象,就会在对象数量达到最大队的容量限制后产生内存溢出异常。代码:[java]viewplaincopyprint?1./**2.*Java堆内存溢出3.*@authorjiangtong4.*5.*/6.publicclassHeapOOM{7.staticclassOOMObject{8.9.}10./**11.*-Xms20M-Xmx20M-Xmn10M-XX:SurvivorRatio=8-
2、XX:PermSize=32M-XX:MaxPermSize=64M-XX:+PrintGCDetails-XX:+HeapDumpOnOutOfMemoryError12.*/13.publicstaticvoidmain(String[]args){14.Listlist=newArrayList();15.intcount=0;16.while(true){17.try{18.count++;19.list.add(newOOMObject());20.System.out.println("共构造了"+c
3、ount+"个对象");21.Thread.sleep(100);22.}catch(Exceptione){23.e.printStackTrace();24.}25.}1.}2.}/***Java堆内存溢出*@authorjiangtong**/publicclassHeapOOM{staticclassOOMObject{}/***-Xms20M-Xmx20M-Xmn10M-XX:SurvivorRatio=8-XX:PermSize=32M-XX:MaxPermSize=64M-XX:+PrintGCDetails-XX:+HeapDumpOnOu
4、tOfMemoryError*/publicstaticvoidmain(String[]args){Listlist=newArrayList();intcount=0;while(true){try{count++;list.add(newOOMObject());System.out.println("共构造了"+count+"个对象");Thread.sleep(100);}catch(Exceptione){e.printStackTrace();}}}}虚拟机执行参数说明:Xms20M-Xmx20M:
5、最小堆内存和最大堆内存设置为一样是为了避免堆内存的自动扩展-Xmn10M:新生代内存分配10M,剩余的交给老年代-XX:SurvivorRatio=8:新生代中Eden区和Survivor区的内存比例为8:1-XX:PermSize=32M:永久代最小内存32M-XX:MaxPermSize=64M:永久代最大扩展内存64M-XX:+HeapDumpOnOutOfMemoryError:堆内存溢出时Dump出当前的内存堆转储快照以便事后分析1、控制台输出分析:[GC[DefNew:8192K->1024K(9216K),0.0426563secs]8192
6、K->4599K(19456K),0.0427200secs][GC[DefNew:6237K->1024K(9216K),0.0552875secs]9813K->9742K(19456K),0.0553528secs][GC[DefNew:7581K->7581K(9216K),0.0000467secs][Tenured:8718K->10240K(10240K),0.1228164secs]16299K->11923K(19456K),[Perm:2086K->2086K(32768K)],0.1229961secs][FullGC[Tenured
7、:10240K->7996K(10240K),0.1247832secs]19456K->15528K(19456K),[Perm:2086K->2086K(32768K)],0.1248966secs][FullGC[Tenured:8598K->8598K(10240K),0.1296810secs]17814K->17814K(19456K),[Perm:2086K->2086K(32768K)],0.1297631secs][FullGC[Tenured:8598K->8595K(10240K),0.1481811secs]17814K->1781
8、1K(19456K),[Perm:2086K->2084K(327
此文档下载收益归作者所有