Minor GC 中 MaxTenuringThreshold 和 TargetSurvivorRatio 参数说明

Minor GC 中 MaxTenuringThreshold 和 TargetSurvivorRatio 参数说明

-XX:MaxTenuringThreshold
在新生代中对象存活次数(经过Minor GC的次数)后仍然存活,就会晋升到旧生代。

-XX:TargetSurvivorRatio 
一个计算期望存活大小Desired survivor size的参数.
计算公式: (survivor_capacity * TargetSurvivorRatio) / 100 * sizeof(a pointer):survivor_capacity(一个survivor space的大小)乘以TargetSurvivorRatio,
                         表明所有age的survivor space对象的大小如果超过Desired survivor size,则重新计算threshold,以age和MaxTenuringThreshold的最小值为准,否则以MaxTenuringThreshold为准.

 

 

 

 

以-Xms20M –Xmx20M –Xmn10M –XX:+UseSerialGC参数执行以上代码,
输出如下:
[GC [DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 15)
- age   1:     677968 bytes,     677968 total
: 6999K->662K(9216K), 0.0028753 secs] 6999K->2710K(19456K), 0.0029048 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC [DefNew
Desired survivor size 524288 bytes, new threshold 15 (max 15)
- age   1:         16 bytes,         16 total
: 6891K->0K(9216K), 0.0025312 secs] 8939K->2709K(19456K), 0.0026029 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC [DefNew
Desired survivor size 524288 bytes, new threshold 15 (max 15)
- age   1:         48 bytes,         48 total
- age   2:         16 bytes,         64 total
: 6200K->0K(9216K), 0.0095025 secs] 8910K->8853K(19456K), 0.0095770 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
ok
Heap
 def new generation   total 9216K, used 4297K [0x32310000, 0x32d10000, 0x32d10000)
  eden space 8192K,  52% used [0x32310000, 0x32742508, 0x32b10000)
  from space 1024K,   0% used [0x32c10000, 0x32c10040, 0x32d10000)
  to   space 1024K,   0% used [0x32b10000, 0x32b10000, 0x32c10000)
 tenured generation   total 10240K, used 8853K [0x32d10000, 0x33710000, 0x33710000)
   the space 10240K,  86% used [0x32d10000, 0x335b57a8, 0x335b5800, 0x33710000)
 compacting perm gen  total 12288K, used 369K [0x33710000, 0x34310000, 0x37710000)
   the space 12288K,   3% used [0x33710000, 0x3376c438, 0x3376c600, 0x34310000)
    ro space 10240K,  51% used [0x37710000, 0x37c3b700, 0x37c3b800, 0x38110000)
    rw space 12288K,  54% used [0x38110000, 0x387a76c0, 0x387a7800, 0x38d10000)

可以看出,每次都重新计算threshhold,或者说从survivor space晋升到旧生代后,重新计算threshold。
SurvivorRatio过大,都应该是age为准,因为触发gc的条件没有达到,但survivor space/2的条件优先达到。
所以调小SurvivorRatio,可以达到MaxTenuringThreshold次数还存活的对象。代码如下:

 

 

 

以-Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=1 -XX:+UseSerialGC -XX:MaxTenuringThreshold=3 -XX:+PrintTenuringDistribution -XX:+PrintGCDetails
运行上述代码。
[GC [DefNew
Desired survivor size 1736704 bytes, new threshold 3 (max 3)
- age   1:     363408 bytes,     363408 total
: 2529K->354K(6848K), 0.0017645 secs] 2529K->354K(17088K), 0.0018275 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC [DefNew
Desired survivor size 1736704 bytes, new threshold 3 (max 3)
- age   1:     314616 bytes,     314616 total
- age   2:     363176 bytes,     677792 total
: 2748K->661K(6848K), 0.0009114 secs] 2748K->661K(17088K), 0.0009399 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC [DefNew
Desired survivor size 1736704 bytes, new threshold 3 (max 3)
- age   1:     314616 bytes,     314616 total
- age   2:     314600 bytes,     629216 total
- age   3:     363176 bytes,     992392 total
: 3042K->969K(6848K), 0.0010587 secs] 3042K->969K(17088K), 0.0010872 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC [DefNew
Desired survivor size 1736704 bytes, new threshold 3 (max 3)
- age   1:     314616 bytes,     314616 total
- age   2:     314600 bytes,     629216 total
- age   3:     314600 bytes,     943816 total
: 3341K->921K(6848K), 0.0012151 secs] 3341K->1276K(17088K), 0.0012443 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
ok
Heap
 def new generation   total 6848K, used 3049K [0x32310000, 0x32d10000, 0x32d10000)
  eden space 3456K,  61% used [0x32310000, 0x32524128, 0x32670000)
  from space 3392K,  27% used [0x32670000, 0x327566c8, 0x329c0000)
  to   space 3392K,   0% used [0x329c0000, 0x329c0000, 0x32d10000)
 tenured generation   total 10240K, used 354K [0x32d10000, 0x33710000, 0x33710000)
   the space 10240K,   3% used [0x32d10000, 0x32d68aa8, 0x32d68c00, 0x33710000)
 compacting perm gen  total 12288K, used 369K [0x33710000, 0x34310000, 0x37710000)
   the space 12288K,   3% used [0x33710000, 0x3376c430, 0x3376c600, 0x34310000)
    ro space 10240K,  51% used [0x37710000, 0x37c3b700, 0x37c3b800, 0x38110000)
    rw space 12288K,  54% used [0x38110000, 0x387a76c0, 0x387a7800, 0x38d10000)



参考:
      http://cr.openjdk.java.net/~andrew/jdk6-hs14-merge/webrev.01/hotspot/src/share  /vm/gc_implementation/shared/ageTable.cpp.frames.html
      http://blog.bluedavy.com/?p=70
      http://java.sun.com/performance/reference/whitepapers/tuning.html
      http://java.sun.com/docs/hotspot/gc1.4.2/faq.html
      http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值