一段jvm虚拟机学习代码

public class Test1 {
    private static final int _1MB = 1024*1024;

    public Test1() {
    }
    public static void main(String[] args)throws Throwable{
           byte[] allocation1,allocation2,allocation3,allocation4;
        allocation1 = new byte[2 * _1MB];
        allocation2 = new byte[3 * _1MB];
        allocation3 = new byte[3 * _1MB];
        allocation4 = new byte[4 * _1MB];
    }
}

虚拟机配置:

-verbose:gc
-Xms20M
-Xmx20M
-Xmn10M
-XX:+PrintGCDetails
-XX:SurvivorRatio=8
-XX:+UseSerialGC

运行结果

[GC[DefNew: 6292K->534K(9216K), 0.0041814 secs] 6292K->5654K(19456K), 0.0042722 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 def new generation   total 9216K, used 8209K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
  eden space 8192K,  93% used [0x00000000f9a00000, 0x00000000fa17eb90, 0x00000000fa200000)
  from space 1024K,  52% used [0x00000000fa300000, 0x00000000fa3859d8, 0x00000000fa400000)
  to   space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
 tenured generation   total 10240K, used 5120K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
   the space 10240K,  50% used [0x00000000fa400000, 0x00000000fa900020, 0x00000000fa900200, 0x00000000fae00000)
 compacting perm gen  total 21248K, used 2985K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
   the space 21248K,  14% used [0x00000000fae00000, 0x00000000fb0eb8b0, 0x00000000fb0eba00, 0x00000000fc2c0000)
No shared spaces configured.

如果去掉-XX:+UseSerialGC参数 运行结果如下:

[GC [PSYoungGen: 6292K->632K(9216K)] 6292K->5752K(19456K), 0.0036761 secs] [Times: user=0.02 sys=0.03, real=0.00 secs] 
[Full GC [PSYoungGen: 632K->0K(9216K)] [ParOldGen: 5120K->5653K(10240K)] 5752K->5653K(19456K) [PSPermGen: 2891K->2890K(21504K)], 0.0116868 secs] [Times: user=0.02 sys=0.00, real=0.01 secs] 
Heap
 PSYoungGen      total 9216K, used 7674K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 93% used [0x00000000ff600000,0x00000000ffd7eb88,0x00000000ffe00000)
  from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 10240K, used 5653K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 55% used [0x00000000fec00000,0x00000000ff1855b0,0x00000000ff600000)
 PSPermGen       total 21504K, used 2907K [0x00000000f9a00000, 0x00000000faf00000, 0x00000000fec00000)
  object space 21504K, 13% used [0x00000000f9a00000,0x00000000f9cd6f80,0x00000000faf00000)

通过以上运行示例可以看出,我的jvm默认的收集器不是Serial + Serial Old 而是 Parallel Scavenge + Parallel Old,所以当我们学习JVM的时候一定要弄清自己的JVM的默认参数是什么,这只是冰山一角

转载于:https://my.oschina.net/wfire/blog/532583

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值