zoukankan      html  css  js  c++  java
  • Eclipse设置虚拟机参数 (转 构建内存溢出)

    Java -verbose:gc 中参数-verbose:gc 表示输出虚拟机中GC的详细情况.

    首先在Eclipse的Debug页签中设置虚拟机参数:

    步骤: 
    1、选中已经写好的项目 
    2、Run->Debug configurations->Java Application 双击 
    3、Arguments->VM arguments 
    4、在VM arguments 里面就可以对虚拟机的内存参数进行设置 
    5、设置完成后,Apply->Debug 
    6、过程结束

    采用《深入理解java虚拟机》的代码:

    package com.xc;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class HeapOOM {
        static class OOMObject{
    
        }
    
        public static void main(String[] args) {
            List<OOMObject> list = new ArrayList<OOMObject>();
            while(true){
                list.add(new OOMObject());
            }
    
        }
    
    }

    然后设置页面如下: 
    参数设置

    参数解释: 
    1,堆是存储对象实例的,创建的对象都是在堆中进行内存分配的;设置堆的大小:-Xmx20M(最大值) ,-Xms20M(最小值), 其中-Xmn设置年轻代大小。 
    2,栈是存储局部变量,操作栈,动态链接,方法出口(都在栈桢中) 的地方,调用方法时,会创建栈桢;设置栈的大小:-Xss128K。 
    3,方法区是存放Class的相关信息,如类名,访问修饰符,常量池,字段描述,方法描述等。此外运行时常量池是属于方法区的,即存放常量,静态常量等;设置方法区大小,-XX:PermSize=10M和-XX:MaxPermSize=10M。 
    4,本地直接内存;设置本地直接内存大小:-XX:MaxDirectMemorySize(默认与-Xmx的值一样)。 
    Debug结果:

    [GC (Allocation Failure)  8018K->4708K(19456K), 0.0115198 secs]
    [GC (Allocation Failure)  12900K->10789K(19456K), 0.0141827 secs]
    [Full GC (Allocation Failure)  18981K->14407K(19456K), 0.0437842 secs]
    [Full GC (Allocation Failure)  14730K->14730K(19456K), 0.0329332 secs]
    [Full GC (Allocation Failure)  14730K->14719K(19456K), 0.0356075 secs]
    java.lang.OutOfMemoryError: Java heap space
    Dumping heap to java_pid12508.hprof ...
    Heap dump file created [26562042 bytes in 0.149 secs]

    出现Java堆内存溢出时,异常堆栈信息 java.lang.OutOfMemoryError,会跟着进一步提示 : Java heap space。 
    接下来 就是 调试 分析的过程了 暂且不写了 要继续上班咯~

  • 相关阅读:
    centos 7 nginx 安装
    搭建Nuget.Server push时,"Failed to process request. 'Method Not Allowed'"
    Failed to create prime the NuGet cache
    Centos 7 安装 Visual stdio Code
    diskpart 格式化u盘 制作u盘启动盘方法
    sql server 2012 数据库日志文件过大,怎么缩小?
    浏览器同源政策及其规避方法
    redis底层数据结构--简单动态字符串 链表 字典 跳跃表 整数集合 压缩列表
    php的闭包
    hash一致性算法
  • 原文地址:https://www.cnblogs.com/snowwhite/p/9532443.html
Copyright © 2011-2022 走看看