读懂GC日志

先给出一个小demo,这里我偷个懒直接用的周志明《深入理解Java虚拟机》第三版P69的代码清单3-1:

public class ReferenceCountingGC{
    public Object instance = null;
    private static final int _1MB = 1024*1024;
    private byte[] bigSize = new byte[2 * _1MB];
    public static void main(String[] args) {
        ReferenceCountingGC obj1= new ReferenceCountingGC();
        ReferenceCountingGC obj2= new ReferenceCountingGC();
        obj1.instance = obj2;
        obj2.instance = obj1;

        System.gc();
    }
}

设置VM options如下: -Xms20M -Xmx20M -XX:+PrintGCDetails。

打印出来的GC日志为:

[GC (Allocation Failure) [PSYoungGen: 3807K->488K(6144K)] 3807K->2716K(19968K), 0.0020225 secs] [Times: user=0.06 sys=0.02, real=0.00 secs]
 
[GC (System.gc()) [PSYoungGen: 2536K->488K(6144K)] 4764K->4820K(19968K), 0.0013806 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 

[Full GC (System.gc()) [PSYoungGen: 488K->0K(6144K)] [ParOldGen: 4332K->4718K(13824K)] 4820K->4718K(19968K), [Metaspace: 3220K->3220K(1056768K)], 0.0065847 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

Heap
 PSYoungGen      total 6144K, used 169K [0x00000000ff980000, 0x0000000100000000, 0x0000000100000000)
  eden space 5632K, 3% used [0x00000000ff980000,0x00000000ff9aa558,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 13824K, used 4718K [0x00000000fec00000, 0x00000000ff980000, 0x00000000ff980000)
  object space 13824K, 34% used [0x00000000fec00000,0x00000000ff09b898,0x00000000ff980000)
 Metaspace       used 3227K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 350K, capacity 388K, committed 512K, reserved 1048576K

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值