Java GC 策略

Sun Hotspot JVM的GC策略是分代:

1. Yong Generation: Eden, Survior1, Survivor2

    Scavenge GC, Copy算法,GC频繁

 

2. Old(Tenured) Generation

     会引起Full GC, 尽可能减少Full GC次数.一般采用CMS(Concurrency-Mark-Sweep, C is not referening to Compact)算法

 

3. Permanent Generation

    会引起Full GC, 尽可能减少Full GC次数

    通过 -XX:PermSize= -XX:MaxPermSize=  设置

   permanent Generation Space 保存Class,Method等MetaData信息,与Heap不同,Sun JVM默认64M。

 

注:

1. GC调优中平衡throughput和pause time两个指标, Server 和 Client JVM会有不同的考量(HotSpot中)

2. new,old space 调优

new space一般占25~40%,如果Stateless对象比较多的话可以考虑多分配一点;相反如果stateful对象比较多,可以多分配一点old space

 

 

4. java 启动命令行中加入 -verbose:gc 来measure 当前GC 性能

 

 

[GC 325407K->83000K(776768K), 0.2300771 secs]
[GC 325816K->83372K(776768K), 0.2454258 secs]
[Full GC 267628K->83769K(776768K), 1.8479984 secs]

 

  325407K和83000K是Minor GC前后Yong GenerationHeap大小

  776768K  is the committed size of the heap: the amount of space usable for java objects without requesting more memory from the operating system. Note that this number does not include one of the survivor spaces, since only one can be used at any given time, and also does not include the permanent generation, which holds metadata used by the virtual machine.

我的理解是young 和old generation当前之和除去一个survivor区和permanent区的大小。当前young Generation的大小是逐步增大的,介于xms和xmx之间。

 

5. -XX:+PrintGCDetails 参数输出的GC log格式会有不同

 

 

[GC [DefNew: 64575K->959K(64576K), 0.0457646 secs] 196016K->133633K(261184K), 0.0459067 secs]

 

indicates that the minor collection recovered about 98% of the young generation, DefNew: 64575K->959K(64576K) and took 0.0457646 secs (about 45 milliseconds).

 

The usage of the entire heap was reduced to about 51% 196016K->133633K(261184K) and that there was some slight additional overhead for the collection (over and above the collection of the young generation) as indicated by the final time of 0.0459067 secs.

 

 

6.  -XX:NewRatio=3

means that the ratio between the young and tenured generation is 1:3. In other words, the combined size of the eden and survivor spaces will be one fourth of the total heap size.

 

7.  -XX:SurvivorRatio=6 

 sets the ratio between a survivor space and eden  to 1:6. In other words, each survivor space will be one sixth the size of eden, and thus one eighth the size of the young generation (not one seventh, because there are two survivor spaces).

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值