JVM调优Demo(四)合适的年轻对象存活年龄
来源:互联网 发布:雅马哈机器人编程软件 编辑:程序博客网 时间:2024/05/06 14:25
先上代码:
生成单位大小对象的类:
public class GCDataObject {byte[] bytes = null;public GCDataObject(int i){bytes = new byte[i *1024 * 1024];}}测试逻辑:
public class Test_MaxTenuringThreshold {public static void main(String[] args){//1-------------------------------------GCDataObject old = new GCDataObject(9);//清理掉新生代的16%内存到旧生代,不知道是什么。。。System.gc();<pre name="code" class="java">//2-------------------------------------GCDataObject newObject1 = new GCDataObject(1);
//为了填满旧生代,触发MinorGC使上面不可回收的对象进入Survivorfor(int ii = 0 ; ii < 5 ; ii++){new GCDataObject(1);}}}注释掉2以下的代码并使用如下的参数运行一个虚拟机 ;
-Xmn10M -Xmx20M -Xms20M -verbose:gc -XX:+PrintGCDetails -XX:+UseSerialGC -XX:SurvivorRatio=3 -XX:MaxTenuringThreshold=1
[Full GC (System.gc()) [Tenured: 9216K->9738K(10240K), 0.0020278 secs] 10180K->9738K(18432K), [Metaspace: 2573K->2573K(1056768K)], 0.0020877 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 8192K, used 61K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 6144K, 1% used [0x00000000fec00000, 0x00000000fec0f738, 0x00000000ff200000)
from space 2048K, 0% used [0x00000000ff200000, 0x00000000ff200000, 0x00000000ff400000)
to space 2048K, 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff600000)
tenured generation total 10240K, used 9738K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
the space 10240K, 95% used [0x00000000ff600000, 0x00000000fff82b30, 0x00000000fff82c00, 0x0000000100000000)
Metaspace used 2580K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 286K, capacity 386K, committed 512K, reserved 1048576K
Heap
def new generation total 8192K, used 61K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 6144K, 1% used [0x00000000fec00000, 0x00000000fec0f738, 0x00000000ff200000)
from space 2048K, 0% used [0x00000000ff200000, 0x00000000ff200000, 0x00000000ff400000)
to space 2048K, 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff600000)
tenured generation total 10240K, used 9738K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
the space 10240K, 95% used [0x00000000ff600000, 0x00000000fff82b30, 0x00000000fff82c00, 0x0000000100000000)
Metaspace used 2580K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 286K, capacity 386K, committed 512K, reserved 1048576K
只触发了一次FullGC,是代码显式使用的System.gc触发,目的是为了让对象全部进入旧生代,如果有一个1M对象进入旧生代的话,就会触发FullGC,以此来判断设置新生代存活年龄的重要性。
取消注释,用和上面相同的参数运行一个jvm得到下面的日志:
[Full GC (System.gc()) [Tenured: 9216K->9738K(10240K), 0.0019239 secs] 10180K->9738K(18432K), [Metaspace: 2574K->2574K(1056768K)], 0.0019757 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 5242K->1024K(8192K), 0.0004939 secs] 14981K->10762K(18432K), 0.0005162 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 8192K, used 2109K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 6144K, 17% used [0x00000000fec00000, 0x00000000fed0f748, 0x00000000ff200000)
from space 2048K, 50% used [0x00000000ff400000, 0x00000000ff500030, 0x00000000ff600000)
to space 2048K, 0% used [0x00000000ff200000, 0x00000000ff200000, 0x00000000ff400000)
tenured generation total 10240K, used 9738K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
the space 10240K, 95% used [0x00000000ff600000, 0x00000000fff82b30, 0x00000000fff82c00, 0x0000000100000000)
Metaspace used 2581K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 286K, capacity 386K, committed 512K, reserved 1048576K
[GC (Allocation Failure) [DefNew: 5242K->1024K(8192K), 0.0004939 secs] 14981K->10762K(18432K), 0.0005162 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 8192K, used 2109K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 6144K, 17% used [0x00000000fec00000, 0x00000000fed0f748, 0x00000000ff200000)
from space 2048K, 50% used [0x00000000ff400000, 0x00000000ff500030, 0x00000000ff600000)
to space 2048K, 0% used [0x00000000ff200000, 0x00000000ff200000, 0x00000000ff400000)
tenured generation total 10240K, used 9738K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
the space 10240K, 95% used [0x00000000ff600000, 0x00000000fff82b30, 0x00000000fff82c00, 0x0000000100000000)
Metaspace used 2581K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 286K, capacity 386K, committed 512K, reserved 1048576K
可以看到from有一一半的空间(1M)被占用了,因为新对象存活年龄为1,所以发生了一次MinorGC后的那个1M的对象不仅进入旧生代。
再使用类似上面的参数,但是把-XX:MaxTenuringThreshold=0运行得到下面的日志:
[Full GC (System.gc()) [Tenured: 9216K->9738K(10240K), 0.0022147 secs] 10180K->9738K(18432K), [Metaspace: 2574K->2574K(1056768K)], 0.0022690 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew (promotion failed) : 5242K->5242K(8192K), 0.0002177 secs][Tenured: 9738K->9738K(10240K), 0.0016011 secs] 14981K->10762K(18432K), [Metaspace: 2574K->2574K(1056768K)], 0.0018564 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 8192K, used 2109K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 6144K, 34% used [0x00000000fec00000, 0x00000000fee0f758, 0x00000000ff200000)
from space 2048K, 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff600000)
to space 2048K, 0% used [0x00000000ff200000, 0x00000000ff200000, 0x00000000ff400000)
tenured generation total 10240K, used 9738K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
the space 10240K, 95% used [0x00000000ff600000, 0x00000000fff82b50, 0x00000000fff82c00, 0x0000000100000000)
Metaspace used 2580K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 286K, capacity 386K, committed 512K, reserved 1048576K
[GC (Allocation Failure) [DefNew (promotion failed) : 5242K->5242K(8192K), 0.0002177 secs][Tenured: 9738K->9738K(10240K), 0.0016011 secs] 14981K->10762K(18432K), [Metaspace: 2574K->2574K(1056768K)], 0.0018564 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 8192K, used 2109K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 6144K, 34% used [0x00000000fec00000, 0x00000000fee0f758, 0x00000000ff200000)
from space 2048K, 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff600000)
to space 2048K, 0% used [0x00000000ff200000, 0x00000000ff200000, 0x00000000ff400000)
tenured generation total 10240K, used 9738K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
the space 10240K, 95% used [0x00000000ff600000, 0x00000000fff82b50, 0x00000000fff82c00, 0x0000000100000000)
Metaspace used 2580K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 286K, capacity 386K, committed 512K, reserved 1048576K
可见那个1M的不可回收的对象立马进入旧生代,导致旧生代触发FullGC。旧生代放不下,放在了Eden下。Eden为2M。
注意这个值只有在串行gc和并行gc的时候才可以用
0 0
- JVM调优Demo(四)合适的年轻对象存活年龄
- JVM调优Demo(三)合适的Survivor
- JVM之对象存活的算法
- JVM判断对象是否存活的方法
- jvm-判断对象是否存活的算法
- JVM学习笔记(二)JVM判断对象是否”存活”
- jvm判断对象是否存活
- jvm对象存活判定算法
- JVM 运行时数据区及GC机制(补)—— 对象存活的判定
- JVM中判断对象是否存活的方法
- JVM调优Demo(二)避免新生代过大(调整合适新生代大小)
- JVM调优:选择合适的GC collector (一)
- JVM调优:选择合适的GC collector (二)
- JVM调优:选择合适的GC collector (三)
- JVM调优:选择合适的GC collector (三)
- JVM调优:选择合适的GC collector (一)
- JVM调优:选择合适的GC collector (二)
- JVM调优:选择合适的GC collector (三)
- 如何将SAE上的数据库同步到本地
- 缓存淘汰算法--LRU算法
- iOS开发企业版ipa分发
- 了解女生一生的朋友____生理周期
- Android设计中的.9.png
- JVM调优Demo(四)合适的年轻对象存活年龄
- Entity Framework连接MySQL,出现报错:由于出现以下异常,无法生成模型:“表“TableDetails”中列“IsPrimaryKey”的值为DBNull.
- 如何正确计算文本所占字节数
- Android创建本地数据可简单操作
- 深入学习集合之HashMap实现原理
- 记录使用intellig idea遇到的问题
- Unity3d Andriod版本发布后lightmap失效
- hdu1890 Robotic Sort (splay+区间翻转单点更新)
- Xcode如何打包ipa安装包