常用JVM配置参数
常用JVM配置参数
- Trace跟踪参数
- 堆的分配参数
- 栈的分配参数
Trace跟踪参数
1.打开GC的日志,如果在程序的运行过程中,系统发生了GC,就会打印相关的信息。
- -verbose:gc
- -XX:+printGC
- 可以打印GC的简要信息//0.0001606 secs垃圾收集消耗的时间//回收前占据的堆的空间是4790k,回收后占据374k,相减,回收了多少垃圾//整个堆的大小是15872k
- [GC 4790K->374K(15872K), 0.0001606 secs]
- [GC 4790K->374K(15872K), 0.0001474 secs]
- [GC 4790K->374K(15872K), 0.0001563 secs]
- [GC 4790K->374K(15872K), 0.0001682 secs]
2.上述打印的内容比较简单,如果要打印出GC的详细信息,
- -XX:+PrintGCDetails
- 打印GC详细信息
- -XX:+PrintGCTimeStamps
- 打印CG发生的时间戳
- 例//新生代的GC,回收前占4416k,回收之后清空,新生代总大小4928k。
- [GC[DefNew: 4416K->0K(4928K), 0.0001897 secs] 4790K->374K(15872K), 0.0002232 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- -XX:+PrintGCDetails的输出
- Heap
- def new generation total 13824K, used 11223K [0x27e80000, 0x28d80000, 0x28d80000)
- eden space 12288K, 91% used [0x27e80000, 0x28975f20, 0x28a80000)
- from space 1536K, 0% used [0x28a80000, 0x28a80000, 0x28c00000)
- to space 1536K, 0% used [0x28c00000, 0x28c00000, 0x28d80000)
- tenured generation total 5120K, used 0K [0x28d80000, 0x29280000, 0x34680000)
- the space 5120K, 0% used [0x28d80000, 0x28d80000, 0x28d80200, 0x29280000)
- compacting perm gen total 12288K, used 142K [0x34680000, 0x35280000, 0x38680000)
- the space 12288K, 1% used [0x34680000, 0x346a3a90, 0x346a3c00, 0x35280000)
- ro space 10240K, 44% used [0x38680000, 0x38af73f0, 0x38af7400, 0x39080000)
- rw space 12288K, 52% used [0x39080000, 0x396cdd28, 0x396cde00, 0x39c80000)
GC日志重定向
- -Xloggc:log/gc.log
- 指定GC log的位置,以文件输出
- 帮助开发人员分析问题
-----
- -XX:+PrintHeapAtGC
- 每次一次GC后,都打印堆信息
- {
- Heap before GC invocations=0 (full 0):
- def new generation total 3072K, used 2752K [0x33c80000, 0x33fd0000, 0x33fd0000)
- eden space 2752K, 100% used [0x33c80000, 0x33f30000, 0x33f30000)
- from space 320K, 0% used [0x33f30000, 0x33f30000, 0x33f80000)
- to space 320K, 0% used [0x33f80000, 0x33f80000, 0x33fd0000)
- tenured generation total 6848K, used 0K [0x33fd0000, 0x34680000, 0x34680000)
- the space 6848K, 0% used [0x33fd0000, 0x33fd0000, 0x33fd0200, 0x34680000)
- compacting perm gen total 12288K, used 143K [0x34680000, 0x35280000, 0x38680000)
- the space 12288K, 1% used [0x34680000, 0x346a3c58, 0x346a3e00, 0x35280000)
- ro space 10240K, 44% used [0x38680000, 0x38af73f0, 0x38af7400, 0x39080000)
- rw space 12288K, 52% used [0x39080000, 0x396cdd28, 0x396cde00, 0x39c80000)
- [GC[DefNew: 2752K->320K(3072K), 0.0014296 secs] 2752K->377K(9920K), 0.0014604 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- Heap after GC invocations=1 (full 0):
- def new generation total 3072K, used 320K [0x33c80000, 0x33fd0000, 0x33fd0000)
- eden space 2752K, 0% used [0x33c80000, 0x33c80000, 0x33f30000)
- from space 320K, 100% used [0x33f80000, 0x33fd0000, 0x33fd0000)
- to space 320K, 0% used [0x33f30000, 0x33f30000, 0x33f80000)
- tenured generation total 6848K, used 57K [0x33fd0000, 0x34680000, 0x34680000)
- the space 6848K, 0% used [0x33fd0000, 0x33fde458, 0x33fde600, 0x34680000)
- compacting perm gen total 12288K, used 143K [0x34680000, 0x35280000, 0x38680000)
- the space 12288K, 1% used [0x34680000, 0x346a3c58, 0x346a3e00, 0x35280000)
- ro space 10240K, 44% used [0x38680000, 0x38af73f0, 0x38af7400, 0x39080000)
- rw space 12288K, 52% used [0x39080000, 0x396cdd28, 0x396cde00, 0x39c80000)
- }
3.跟踪类的被加载的过程
- -XX:+TraceClassLoading
- 监控类的加载
- [Loaded java.lang.Object from shared objects file]
- [Loaded java.io.Serializable from shared objects file]
- [Loaded java.lang.Comparable from shared objects file]
- [Loaded java.lang.CharSequence from shared objects file]
- [Loaded java.lang.String from shared objects file]
- [Loaded java.lang.reflect.GenericDeclaration from shared objects file]
- [Loaded java.lang.reflect.Type from shared objects file]
4.打印类的使用情况
- XX:+PrintClassHistogram
- 在控制台按下Ctrl+Break后,打印类的信息:
- num #instances #bytes class name
- ----------------------------------------------
- 1: 890617 470266000 [B
- 2: 890643 21375432 java.util.HashMap$Node
- 3: 890608 14249728 java.lang.Long
- 4: 13 8389712 [Ljava.util.HashMap$Node;
- 5: 2062 371680 [C
- 6: 463 41904 java.lang.Class
- 分别显示:序号、实例数量、总大小、类
所有的类的使用情况。
1:890617:470266000:[B
-->Byte数组,有890617个Byte数组对象,它们总共占了470266000字节的空间。
堆的分配参数
- -Xmx –Xms
- 指定最大堆和最小堆
- //JVM最多使用20M空间,系统一启动就占用5M空间
- -Xmx20m -Xms5m 运行代码:
- public class Test {
- public static void main(String[] args) {
- System.out.print("Xmx=");
- System.out.println(Runtime.getRuntime().maxMemory()/1024.0/1024+"M");
- System.out.print("free mem=");
- System.out.println(Runtime.getRuntime().freeMemory()/1024.0/1024+"M");
- System.out.print("total mem=");
- System.out.println(Runtime.getRuntime().totalMemory()/1024.0/1024+"M");
- }
- }
- public class Test {
- public static void main(String[] args) {
- byte[] b=new byte[1*1024*1024];
- System.out.println("分配了1M空间给数组");
- System.out.print("Xmx=");
- System.out.println(Runtime.getRuntime().maxMemory()/1024.0/1024+"M");
- System.out.print("free mem=");
- System.out.println(Runtime.getRuntime().freeMemory()/1024.0/1024+"M");
- System.out.print("total mem=");
- System.out.println(Runtime.getRuntime().totalMemory()/1024.0/1024+"M");
- }
- }
我们看到,总内存没变,这里涉及一个原则:Java会尽可能维持在最小堆(Xms5m)
但是当内存中对象比较大,最小堆无法满足要求时,总内存就会变大。
- public class Test {
- public static void main(String[] args) {
- byte[] b=new byte[4*1024*1024];
- System.out.println("分配了4M空间给数组");
- System.out.print("Xmx=");
- System.out.println(Runtime.getRuntime().maxMemory()/1024.0/1024+"M");
- System.out.print("free mem=");
- System.out.println(Runtime.getRuntime().freeMemory()/1024.0/1024+"M");
- System.out.print("total mem=");
- System.out.println(Runtime.getRuntime().totalMemory()/1024.0/1024+"M");
- }
- }
可以看到,总内存变大了。
在前面两个字节数组的基础上,手动进行垃圾回收,
- public class Test {
- public static void main(String[] args) {
- System.gc();
- System.out.print("Xmx=");
- System.out.println(Runtime.getRuntime().maxMemory()/1024.0/1024+"M");
- System.out.print("free mem=");
- System.out.println(Runtime.getRuntime().freeMemory()/1024.0/1024+"M");
- System.out.print("total mem=");
- System.out.println(Runtime.getRuntime().totalMemory()/1024.0/1024+"M");
- }
- }
维持在最小堆(Xms5m)
------
- -Xmn
- 设置新生代大小
- -XX:NewRatio
- 新生代(eden+2*s)和老年代(不包含永久区)的比值
- 4 表示 新生代:老年代=1:4,即年轻代占堆的1/5
- -XX:SurvivorRatio
- 设置两个Survivor区和eden的比
- 8表示 两个Survivor :eden=2:8,即一个Survivor占年轻代的1/10
- public class Test {
- public static void main(String[] args) {
- byte[] b=null;
- for(int i=0;i<10;i++)
- b=new byte[1*1024*1024];
- }
- }
- Heap
- def new generation total 960K, used 551K [0x327a0000, 0x328a0000, 0x328a0000)
- eden space 896K, 61% used [0x327a0000, 0x32829e68, 0x32880000)
- from space 64K, 0% used [0x32880000, 0x32880000, 0x32890000)
- to space 64K, 0% used [0x32890000, 0x32890000, 0x328a0000)
- tenured generation total 19456K, used 10240K [0x328a0000, 0x33ba0000, 0x33ba0000)
- the space 19456K, 52% used [0x328a0000, 0x332a00a0, 0x332a0200, 0x33ba0000)
- compacting perm gen total 12288K, used 145K [0x33ba0000, 0x347a0000, 0x37ba0000)
- the space 12288K, 1% used [0x33ba0000, 0x33bc44f0, 0x33bc4600, 0x347a0000)
- ro space 10240K, 41% used [0x37ba0000, 0x37fd2050, 0x37fd2200, 0x385a0000)
- rw space 12288K, 52% used [0x385a0000, 0x38be6800, 0x38be6800, 0x391a0000)
- Heap
- def new generation total 13824K, used 11223K [0x327a0000, 0x336a0000, 0x336a0000)
- eden space 12288K, 91% used [0x327a0000, 0x33295f00, 0x333a0000)
- from space 1536K, 0% used [0x333a0000, 0x333a0000, 0x33520000)
- to space 1536K, 0% used [0x33520000, 0x33520000, 0x336a0000)
- tenured generation total 5120K, used 0K [0x336a0000, 0x33ba0000, 0x33ba0000)
- the space 5120K, 0% used [0x336a0000, 0x336a0000, 0x336a0200, 0x33ba0000)
- compacting perm gen total 12288K, used 145K [0x33ba0000, 0x347a0000, 0x37ba0000)
- the space 12288K, 1% used [0x33ba0000, 0x33bc44f0, 0x33bc4600, 0x347a0000)
- ro space 10240K, 41% used [0x37ba0000, 0x37fd2050, 0x37fd2200, 0x385a0000)
- rw space 12288K, 52% used [0x385a0000, 0x38be6800, 0x38be6800, 0x391a0000)
- [GC[DefNew: 5737K->372K(6464K), 0.0022402 secs] 5737K->1396K(19776K), 0.0022938 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- Heap
- def new generation total 6464K, used 5786K [0x327a0000, 0x32ea0000, 0x32ea0000)
- eden space 5760K, 93% used [0x327a0000, 0x32ce9848, 0x32d40000)
- from space 704K, 52% used [0x32df0000, 0x32e4d068, 0x32ea0000)
- to space 704K, 0% used [0x32d40000, 0x32d40000, 0x32df0000)
- tenured generation total 13312K, used 1024K [0x32ea0000, 0x33ba0000, 0x33ba0000)
- the space 13312K, 7% used [0x32ea0000, 0x32fa0010, 0x32fa0200, 0x33ba0000)
- compacting perm gen total 12288K, used 145K [0x33ba0000, 0x347a0000, 0x37ba0000)
- the space 12288K, 1% used [0x33ba0000, 0x33bc44f0, 0x33bc4600, 0x347a0000)
- ro space 10240K, 41% used [0x37ba0000, 0x37fd2050, 0x37fd2200, 0x385a0000)
- rw space 12288K, 52% used [0x385a0000, 0x38be6800, 0x38be6800, 0x391a0000)
1.进行了1次新生代GC
2.s0 s1 太小需要老年代担保
- [GC[DefNew: 2583K->1396K(5376K), 0.0023742 secs] 2583K->1396K(18688K), 0.0024289 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- [GC[DefNew: 4582K->1024K(5376K), 0.0017806 secs] 4582K->1395K(18688K), 0.0018160 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- [GC[DefNew: 4124K->1024K(5376K), 0.0007338 secs] 4495K->1395K(18688K), 0.0007731 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- Heap
- def new generation total 5376K, used 3162K [0x327a0000, 0x32ea0000, 0x32ea0000)
- eden space 3584K, 59% used [0x327a0000, 0x329b6960, 0x32b20000)
- from space 1792K, 57% used [0x32ce0000, 0x32de0010, 0x32ea0000)
- to space 1792K, 0% used [0x32b20000, 0x32b20000, 0x32ce0000)
- tenured generation total 13312K, used 371K [0x32ea0000, 0x33ba0000, 0x33ba0000)
- the space 13312K, 2% used [0x32ea0000, 0x32efcf00, 0x32efd000, 0x33ba0000)
- compacting perm gen total 12288K, used 145K [0x33ba0000, 0x347a0000, 0x37ba0000)
- the space 12288K, 1% used [0x33ba0000, 0x33bc44f0, 0x33bc4600, 0x347a0000)
1.进行了3次新生代GC
2.s0 s1 增大
- [GC[DefNew: 4625K->1396K(7680K), 0.0030680 secs] 4625K->1396K(17920K), 0.0031348 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- [GC[DefNew: 5651K->1024K(7680K), 0.0022846 secs] 5651K->1395K(17920K), 0.0023257 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- Heap
- def new generation total 7680K, used 3212K [0x327a0000, 0x331a0000, 0x331a0000)
- eden space 5120K, 42% used [0x327a0000, 0x329c2fe8, 0x32ca0000)
- from space 2560K, 40% used [0x32ca0000, 0x32da0098, 0x32f20000)
- to space 2560K, 0% used [0x32f20000, 0x32f20000, 0x331a0000)
- tenured generation total 10240K, used 371K [0x331a0000, 0x33ba0000, 0x33ba0000)
- the space 10240K, 3% used [0x331a0000, 0x331fce78, 0x331fd000, 0x33ba0000)
- compacting perm gen total 12288K, used 145K [0x33ba0000, 0x347a0000, 0x37ba0000)
- the space 12288K, 1% used [0x33ba0000, 0x33bc44f0, 0x33bc4600, 0x347a0000)
- ro space 10240K, 41% used [0x37ba0000, 0x37fd2050, 0x37fd2200, 0x385a0000)
比例分配,新生代 老年代对半开
对象全部留在新生代
- [GC[DefNew: 5751K->1396K(8192K), 0.0022373 secs] 5751K->1396K(18432K), 0.0022949 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
- Heap
- def new generation total 8192K, used 6830K [0x327a0000, 0x331a0000, 0x331a0000)
- eden space 6144K, 88% used [0x327a0000, 0x32cee838, 0x32da0000)
- from space 2048K, 68% used [0x32fa0000, 0x330fd078, 0x331a0000)
- to space 2048K, 0% used [0x32da0000, 0x32da0000, 0x32fa0000)
- tenured generation total 10240K, used 0K [0x331a0000, 0x33ba0000, 0x33ba0000)
- the space 10240K, 0% used [0x331a0000, 0x331a0000, 0x331a0200, 0x33ba0000)
- compacting perm gen total 12288K, used 145K [0x33ba0000, 0x347a0000, 0x37ba0000)
- the space 12288K, 1% used [0x33ba0000, 0x33bc44f0, 0x33bc4600, 0x347a0000)
- ro space 10240K, 41% used [0x37ba0000, 0x37fd2050, 0x37fd2200, 0x385a0000)
- rw space 12288K, 52% used [0x385a0000, 0x38be6800, 0x38be6800, 0x391a0000)
减少了s0 s1 GC数量变少,老年代未使用 空间使用率更高
- -XX:+HeapDumpOnOutOfMemoryError
- OOM时导出堆到文件
- -XX:+HeapDumpPath
- 导出OOM的路径
- -Xmx20m -Xms5m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/a.dump
- public class Test {
- public static void main(String[] args) {
- Vector v=new Vector();
- for(int i=0;i<25;i++)
- v.add(new byte[1*1024*1024]);
- }
- }
堆的分配参数 – 总结
永久区分配参数
- -XX:PermSize -XX:MaxPermSize
- 设置永久区的初始空间和最大空间
- 他们表示,一个系统可以容纳多少个类型
- for(int i=0;i<100000;i++){
- CglibBean bean = new CglibBean("geym.jvm.ch3.perm.bean"+i,new HashMap());
- }
栈大小分配
- -Xss
- 通常只有几百K
- 决定了函数调用的深度
- 每个线程都有独立的栈空间
- 局部变量、参数 分配在栈上
- public class TestStackDeep {
- private static int count=0;
- public static void recursion(long a,long b,long c){
- long e=1,f=2,g=3,h=4,i=5,k=6,q=7,x=8,y=9,z=10;
- count++;
- recursion(a,b,c);
- }
- public static void main(String args[]){
- try{
- recursion(0L,0L,0L);
- }catch(Throwable e){
- System.out.println("deep of calling = "+count);
- e.printStackTrace();
- }
- }
- }
- 递归调用
- -Xss128K
- deep of calling = 701
- java.lang.StackOverflowError
- -Xss256K
- deep of calling = 1817
- java.lang.StackOverflowError
去掉局部变量 调用层次可以更深
常用JVM配置参数的更多相关文章
- JVM虚拟机(1)---常用JVM配置参数
常用JVM配置参数 常用JVM配置参数主要有:Trace跟踪参数.堆的分配参数.栈的分配参数. 一.Trace跟踪参数 跟踪参数用于跟踪监控JVM,对于开发人员来讲用于JVM调优以及故障排查的. 1. ...
- JVM学习八:常用JVM配置参数
前面学习的都是和类加载相关的知识,接下来学习的则和GC相关的知识,都是JVM的几个重点块. 零.在IDE的后台打印GC日志: 既然学习JVM,阅读GC日志是处理Java虚拟机内存问题的基础技能,它只是 ...
- Java虚拟机详解----常用JVM配置参数
本文主要内容: Trace跟踪参数 堆的分配参数 栈的分配参数 零.在IDE的后台打印GC日志: 既然学习JVM,阅读GC日志是处理Java虚拟机内存问题的基础技能,它只是一些人为确定的规则,没有太多 ...
- 【转】Java虚拟机详解----常用JVM配置参数
原文地址:http://www.cnblogs.com/smyhvae/p/4736162.html 本文主要内容: Trace跟踪参数 堆的分配参数 栈的分配参数 零.在IDE的后台打印GC日志: ...
- JVM学习一:常用JVM配置参数
原文链接:https://www.cnblogs.com/pony1223/p/8661219.html 在IDE的后台打印GC日志: 既然学习JVM,阅读GC日志是处理Java虚拟机内存问题的基础技 ...
- JVM内核-原理、诊断与优化学习笔记(三):常用JVM配置参数
文章目录 Trace跟踪参数 -verbose:gc (打开gc的跟踪情况) -XX:+printGC(打开gc的log开关,如果在运行的过程中出现了gc,就会打印出相关的信息.) -XX:+Prin ...
- Java虚拟机(四):常用JVM配置参数
一.VM选项 - : 标准VM选项,VM规范的选项 -X: 非标准VM选项,不保证所有VM支持 -XX: 高级选项,高级特性,但属于不稳定的选项 参见Java HotSpot VM Options 二 ...
- 深入JVM内核--常用JVM配置参数
Trace跟踪参数 -verbose:gc -XX:+printGC 可以打印GC的简要信息 [GC 4790K->374K(15872K), 0.0001606 secs] [GC 4790K ...
- 一文学会JVM配置参数与工具使用
经过前面的各种分析,我们知道了关于JVM很多的知识,比如版本信息,类加载,堆,方法区,垃圾回收等,但是总觉得心里不踏实,原因是没看到实际的一些东西. 所以这在本文,咱们就好好来聊一聊关于怎么将这些内容 ...
随机推荐
- From MSI to WiX, Part 8 - Major Upgrade, by Alex Shevchuk
Following content is reprinted from here, please go to the original website for more information. Au ...
- 学习笔记--Quartz定时器
文章同步发表在博主网站朗度云,传输门:http://www.wolfbe.com/detail/201608/338.html 1.Quartz定时器执行流程 Quartz需要定义执行任务.触发器,在 ...
- slider jq小插件
html代码 <div class="r_list r_1" style="display:block;"> <div class=" ...
- 多线程的单元测试工具 - GroboUtils
写过Junit单元测试的同学应该会有感觉,Junit本身是不支持普通的多线程测试的,这是因为Junit的底层实现上,是用System.exit退出用例执行的.JVM都终止了,在测试线程启动的其他线程自 ...
- 《C和指针》 读书笔记 -- 第8章 数组
1.在C中,数组名的值是一个指针常量而不是指针变量,也就是数组第一个元素的地址. 2.数组和指针的区别: 声明一个数组时,编译器将根据声明所指定的元素数量为数组保留内存空间,然后再创建数组名,它的值是 ...
- Device eth0 does not seem to be present
解决办法: 首先,打开/etc/udev/rules.d/70-persistent-net.rules内容如下面例子所示: # vi /etc/udev/rules.d/70-persistent- ...
- Webx框架自带的petstore
Webx框架:http://openwebx.org/ petstore:webx3/webx-sample/petstore/tags/3.0/petstore 编译之后:mvn jetty:run ...
- Android导入Cocos2D的Sample项目
导入Cocos2D项目到Android的Eclipse时注意以下几点 1. Set up Variables: Eclipse->Windows->Preferences->Gene ...
- git/ TortoiseGit 在bitbucket.org 使用证书登陆
背景:使用https协议在bitbucket中进行pull,push 时每次都要输入密码,比较麻烦还耽误时间,在网上找了下保存密码的方式 使用在用户环境变量中配置_netrc 文件的方式(http:/ ...
- poj 2728 Desert King (最小比例生成树)
http://poj.org/problem?id=2728 Desert King Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...