博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Survivor空间溢出实例
阅读量:6464 次
发布时间:2019-06-23

本文共 4850 字,大约阅读时间需要 16 分钟。

jvm系列

本文演示survivor空间溢出的场景。

实例代码

class MemoryObject{    private byte[] bytes;    public MemoryObject(int objectSize){        this.bytes = new byte[objectSize];    }}/**     * eden 13184K ,s0/s1 1600k 共16M     * old 24m-Xms40m -Xmx40m -Xmn16m -verbose:gc -XX:+PrintGCDetails -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution     * @throws InterruptedException     */    public static void survivorNotEnough2OldSpace() throws InterruptedException {//        Thread.sleep(50000);        MemoryObject object = new MemoryObject(1024*1024);        MemoryObject m2Object = new MemoryObject(1024*1024*2);        happenMinorGC(9);        Thread.sleep(2000);    }private static void happenMinorGC(int happenMinorGCIndex) throws InterruptedException {        for(int i=0;i

输出

allocate last:2014-11-04 15-43-18-829allocate last:2014-11-04 15-43-18-830allocate last:2014-11-04 15-43-18-830allocate last:2014-11-04 15-43-18-831allocate last:2014-11-04 15-43-18-831allocate last:2014-11-04 15-43-18-832allocate last:2014-11-04 15-43-18-833{Heap before GC invocations=0 (full 0): def new generation   total 14784K, used 13182K [0x00000007f8600000, 0x00000007f9600000, 0x00000007f9600000)  eden space 13184K,  99% used [0x00000007f8600000, 0x00000007f92df8b0, 0x00000007f92e0000)  from space 1600K,   0% used [0x00000007f92e0000, 0x00000007f92e0000, 0x00000007f9470000)  to   space 1600K,   0% used [0x00000007f9470000, 0x00000007f9470000, 0x00000007f9600000) tenured generation   total 24576K, used 0K [0x00000007f9600000, 0x00000007fae00000, 0x00000007fae00000)   the space 24576K,   0% used [0x00000007f9600000, 0x00000007f9600000, 0x00000007f9600200, 0x00000007fae00000) compacting perm gen  total 21248K, used 3994K [0x00000007fae00000, 0x00000007fc2c0000, 0x0000000800000000)   the space 21248K,  18% used [0x00000007fae00000, 0x00000007fb1e6950, 0x00000007fb1e6a00, 0x00000007fc2c0000)No shared spaces configured.[GC [DefNewDesired survivor size 819200 bytes, new threshold 1 (max 15)- age   1:    1638400 bytes(1600K),    1638400 total这个情况是survivor空间溢出,survivor空间被占满,然后溢出的部分,直接放到了年老代(2401K),溢出之后,计算survivor空间里头对象的年龄分布,发现年龄为1的对象大小总和超过了survivor的desired值,于是设置新的阈值为该age=1。(每次young gc之后打印survivor区域内对象的年龄分布)如果底下age的total大小大于Desired survivor size的大小,那么就代表了survivor空间溢出了,被填满,然后会重新计算threshold。: 13182K->1600K(14784K), 0.0057500 secs] 13182K->4001K(39360K), 0.0057720 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap after GC invocations=1 (full 0): def new generation   total 14784K, used 1600K [0x00000007f8600000, 0x00000007f9600000, 0x00000007f9600000)  eden space 13184K,   0% used [0x00000007f8600000, 0x00000007f8600000, 0x00000007f92e0000)  from space 1600K, 100% used [0x00000007f9470000, 0x00000007f9600000, 0x00000007f9600000)  to   space 1600K,   0% used [0x00000007f92e0000, 0x00000007f92e0000, 0x00000007f9470000) tenured generation   total 24576K, used 2401K [0x00000007f9600000, 0x00000007fae00000, 0x00000007fae00000)   the space 24576K,   9% used [0x00000007f9600000, 0x00000007f98586d8, 0x00000007f9858800, 0x00000007fae00000) compacting perm gen  total 21248K, used 3994K [0x00000007fae00000, 0x00000007fc2c0000, 0x0000000800000000)   the space 21248K,  18% used [0x00000007fae00000, 0x00000007fb1e6950, 0x00000007fb1e6a00, 0x00000007fc2c0000)No shared spaces configured.}allocate last:2014-11-04 15-43-18-839minor gc should happen:2014-11-04 15-43-18-839allocate last:2014-11-04 15-43-18-839Heap def new generation   total 14784K, used 4202K [0x00000007f8600000, 0x00000007f9600000, 0x00000007f9600000)  eden space 13184K,  19% used [0x00000007f8600000, 0x00000007f888a820, 0x00000007f92e0000)  from space 1600K, 100% used [0x00000007f9470000, 0x00000007f9600000, 0x00000007f9600000)  to   space 1600K,   0% used [0x00000007f92e0000, 0x00000007f92e0000, 0x00000007f9470000) tenured generation   total 24576K, used 2401K [0x00000007f9600000, 0x00000007fae00000, 0x00000007fae00000)   the space 24576K,   9% used [0x00000007f9600000, 0x00000007f98586d8, 0x00000007f9858800, 0x00000007fae00000) compacting perm gen  total 21248K, used 4001K [0x00000007fae00000, 0x00000007fc2c0000, 0x0000000800000000)   the space 21248K,  18% used [0x00000007fae00000, 0x00000007fb1e8710, 0x00000007fb1e8800, 0x00000007fc2c0000)No shared spaces configured.

小结

并不是都得等到对象年龄达到晋升阈值才提升到年老代

如果在Survivor空间中相同年龄所有对象大小的总和>Survivor空间的一半( -XX:TargetSurvivorRatio)时,年龄>=该年龄的对象就可以直接进入年老代

Desired survivor size = (survivor_capacity TargetSurvivorRatio) / 100 sizeof(a pointer):survivor_capacity(一个survivor space的大小)乘以TargetSurvivorRatio

-XX:TargetSurvivorRatio

目标存活率,默认为50%

表明所有age的survivor space对象的大小如果超过Desired survivor size,则重新计算threshold,以age和MaxTenuringThreshold的最小值为准,否则以MaxTenuringThreshold为准.

-XX:TargetSurvivorRatio

目标Survivor空间占用是HotSpot尝试在MinorGC之后仍然维持的Survivor空间占用,默认值为50

是因为HotSpot研发团队对不同类型的应用程序进行了大量的负荷测试,结果表明50%的目标Survivor空间占用能适应大多数应用程序,能应对MinorGC时存活对象的急速增加。

转载地址:http://wjezo.baihongyu.com/

你可能感兴趣的文章
[CareerCup] 17.3 Factorial Trailing Zeros 求阶乘末尾零的个数
查看>>
Security updates and resources
查看>>
深入理解JavaScript系列(25):设计模式之单例模式
查看>>
DNS为什么通常都会设置为14.114.114.114
查看>>
给定一个序列,判断该序列是否为二叉树查找树的后序遍历序列
查看>>
Sqoop架构(四)
查看>>
golang copy函数
查看>>
《你有多少问题要请示》精华集粹
查看>>
深度 | 机器学习敲门砖:任何人都能看懂的TensorFlow介绍【转】
查看>>
leveldb学习:DBimpl
查看>>
MySQL存储引擎--MYSIAM和INNODB引擎区别
查看>>
[Recompose] Stream Props to React Children with RxJS
查看>>
打印图片
查看>>
apache 配置
查看>>
SHOW CREATE DATABASE Syntax
查看>>
rsync常见问题及解决办法
查看>>
AKM项目轶事之GBS同事转入GDC
查看>>
MySQL日期 专题
查看>>
C#中禁止程序多开
查看>>
分布式缓存Redis使用以及原理
查看>>