JVM参数配置测试
2017-11-22 00:00
169 查看
摘要: JVM
参考:http://blog.csdn.net/witsmakemen/article/details/28600127
如果使用Eclipse开发工具,可以使用Debug configurations--->Arguments--->VM arguments 配置
参数说明见另一篇博文:java虚拟机的原理
测试类:
输出
测试代码
测试代码:
参考:http://blog.csdn.net/witsmakemen/article/details/28600127
如果使用Eclipse开发工具,可以使用Debug configurations--->Arguments--->VM arguments 配置
参数说明见另一篇博文:java虚拟机的原理
测试堆内存初始化
VM arguments配置 -Xms5m -Xmx20m -XX:+PrintGCDetails -XX:+UseSerialGC -XX:+PrintCommandLineFlags
测试类:
public static void main(String[] args) { //-Xms5m -Xmx20m -XX:+PrintGCDetails -XX:+UseSerialGC -XX:+PrintCommandLineFlags //查看GC信息 System.out.println("max memory:" + Runtime.getRuntime().maxMemory()); System.out.println("free memory:" + Runtime.getRuntime().freeMemory()); System.out.println("total memory:" + Runtime.getRuntime().totalMemory()); byte[] b1 = new byte[1 * 1024 * 1024]; System.out.println("分配了1M"); System.out.println("max memory:" + Runtime.getRuntime().maxMemory()); System.out.println("free memory:" + Runtime.getRuntime().freeMemory()); System.out.println("total memory:" + Runtime.getRuntime().totalMemory()); byte[] b2 = new byte[4 * 1024 * 1024]; System.out.println("分配了4M"); System.out.println("max memory:" + Runtime.getRuntime().maxMemory()); System.out.println("free memory:" + Runtime.getRuntime().freeMemory()); System.out.println("total memory:" + Runtime.getRuntime().totalMemory()); }
输出
-XX:InitialHeapSize=5242880 -XX:MaxHeapSize=20971520 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:-UseLargePagesIndividualAllocation -XX:+UseSerialGC ---XX:+PrintCommandLineFlags参数作用 max memory:20316160 free memory:4433040 --初始化5M total memory:5111808 --heap总大小 [GC [DefNew: 662K->128K(1536K), 0.0040522 secs] 662K->452K(4992K), 0.0041507 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 分配了1M max memory:20316160 free memory:3571336 --消耗掉1M后 total memory:5111808----heap总大小不变 [GC [DefNew: 1180K->0K(1536K), 0.0034828 secs][Tenured: 1476K->1476K(3456K), 0.0055071 secs] 1504K->1476K(4992K), [Perm : 1620K->1620K(12288K)], 0.0091993 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 分配了4M --此时free memory 不足 max memory:20316160 free memory:3656000 --不变 total memory:9441280 --增加4M Heap--堆详细信息 def new generation total 1664K, used 108K [0x04750000, 0x04910000, 0x04df0000)--新生代 eden space 1536K, 7% used [0x04750000, 0x0476b108, 0x048d0000)--eden区 from space 128K, 0% used [0x048d0000, 0x048d0000, 0x048f0000) --from区 to space 128K, 0% used [0x048f0000, 0x048f0000, 0x04910000)--to区 tenured generation total 7556K, used 5572K [0x04df0000, 0x05551000, 0x05b50000)--老年代 the space 7556K, 73% used [0x04df0000, 0x05361100, 0x05361200, 0x05551000) compacting perm gen total 12288K, used 1627K [0x05b50000, 0x06750000, 0x09b50000) --方法区 the space 12288K, 13% used [0x05b50000, 0x05ce6f58, 0x05ce7000, 0x06750000) No shared spaces configured.
测试配置新生代大小对GC影响
//1、新生代分配1M 如果分配的初始化堆太小,会频繁的引起GC,导致性能下降 -Xms20m -Xmx20m -Xmn1m -XX:SurvivorRatio= 7fe0 2 -XX:+PrintGCDetails -XX:+UseSerialGC //2、新生代分配7M -Xms20m -Xmx20m -Xmn7m -XX:SurvivorRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC //3、配置新生代和老生代的比例 //-XX:NewRatio=老年代/新生代 -Xms20m -Xmx20m -XX:NewRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC
测试代码
/**如果分配的初始化堆太小,会频繁的引起GC,导致性能下降 **/ public static void main(String[] args) { byte[] b = null; for(int i = 0 ; i <10; i ++){ b = new byte[1*1024*1024];//连续向系统申请10MB空间 } }
内存溢出测试
-Xms2m -Xmx2m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/Test03.dump
测试代码:
public static void main(String[] args) { //堆内存溢出 Vector v = new Vector(); for(int i=0; i < 5; i ++){ v.add(new Byte[1*1024*1024]); } }
相关文章推荐
- JVM参数调优(虚拟机参数配置)
- [转载]eclipse.ini中配置参数 -Xms,-Xmx,-PerSize(JVM内存参数说明)
- JVM的配置参数
- Java虚拟机(JVM)参数配置说明
- JVM参数配置大全
- 一个resin 4.0.29的样例配置文件,包含jvm的参数
- [转载]SOAPUI压力测试的参数配置
- 深入理解JVM(三)——配置参数
- 常用JVM配置参数
- 常用jvm参数配置以及提供系统堆益处日志监控方法
- JVM参数配置
- JVM内存配置参数说明
- jvm垃圾回收参数配置
- tomcat 压力测试调优+参数配置
- Java虚拟机(JVM)参数配置说明(转)
- Java虚拟机(JVM)参数配置说明
- Java虚拟机详解----常用JVM配置参数
- 如何配置JVM的GC参数
- TestNG的参数化测试、共享线程池配置、参数默认值配置
- Java虚拟机详解----常用JVM配置参数