79-新生代与老年代垃圾收集器实现详解

新生代与老年代垃圾收集器实现详解

默认情况下:

​ 虚拟机中新生代和老年代所采用的垃圾收集器为:【在jdk1.8中,并不能保证其他的】

​ PSyoungGen:Parallel Scavenge(新生代垃圾收集器);

​ ParOldGen:Parallel Old(老年代垃圾收集器)

★★★

当新生代无法容纳下将要创建的对象的话,那么这个对象将在老年代产生分配。

实例:
public class MyTest1 {
    public static void main(String[] args) {
        int size = 1024 * 1024;
        byte[] myAlloc1 = new byte[2 * size];
        byte[] myAlloc2 = new byte[2 * size];
        byte[] myAlloc3 = new byte[3 * size];
        byte[] myAlloc4 = new byte[3 * size];

        System.out.println("hello world");
    }
}
[GC (Allocation Failure) [PSYoungGen: 7133K->992K(9216K)] 7133K->3419K(19456K), 0.0050842 secs] [Times: user=0.03 sys=0.00, real=0.01 secs] 
[GC (Allocation Failure) [PSYoungGen: 6434K->960K(9216K)] 8861K->8507K(19456K), 0.0127432 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

//对Full GC进行分析:
//在实际的业务开发中,应尽量避免Full GC
//ParOldGen: 7546K->8112K(10240K) ,可以看到,老年代的数量变多了,这种属于正常现象。
[Full GC (Ergonomics) [PSYoungGen: 960K->0K(9216K)] [ParOldGen: 7546K->8112K(10240K)] 8507K->8112K(19456K), [Metaspace: 3311K->3311K(1056768K)], 0.0150647 secs] [Times: user=0.03 sys=0.00, real=0.02 secs] 
hello world
Heap
 PSYoungGen      total 9216K, used 3361K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 41% used [0x00000000ff600000,0x00000000ff9487c0,0x00000000ffe00000)
  from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
  to   space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
 ParOldGen       total 10240K, used 8112K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 79% used [0x00000000fec00000,0x00000000ff3ec048,0x00000000ff600000)
 Metaspace       used 3320K, capacity 4568K, committed 4864K, reserved 1056768K
  class space    used 361K, capacity 392K, committed 512K, reserved 1048576K
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值