java 如何打印垃圾回收花费的时间?

2016-01-28 16:37:16 +08:00
 eightqueen
package com.v2ex;

public class Test {

    private static final int MB = 1024 * 1024;

    public static void main(String[] args) {
        byte[] bytes1, bytes2, bytes3, bytes4;
        bytes1 = new byte[2 * MB];
        bytes2 = new byte[2 * MB];
        bytes3 = new byte[2 * MB];
        bytes4 = new byte[4 * MB];
    }
}

我的执行命令是 java -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 com/v2ex/Test
打印的数据是:

Heap
 PSYoungGen      total 9216K, used 6799K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 83% used [0x00000000ff600000,0x00000000ffca3f28,0x00000000ffe00000)
  from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
  to   space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
 ParOldGen       total 10240K, used 4096K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 40% used [0x00000000fec00000,0x00000000ff000010,0x00000000ff600000)
 PSPermGen       total 21504K, used 2751K [0x00000000f4600000, 0x00000000f5b00000, 0x00000000fec00000)
  object space 21504K, 12% used [0x00000000f4600000,0x00000000f48afc08,0x00000000f5b00000)

可是时间去哪了?我在网上查了很多资料,都会打印时间的。
我用的系统是 mint , jdk 是 openjdk 1.7.0_79

2292 次点击
所在节点    问与答
4 条回复
qinglangee
2016-01-28 17:47:33 +08:00
-Xms20M 值太大,还没触发 GC , 改成 -Xms8M 试试
binbing
2016-01-28 17:53:04 +08:00
System.gc()
eightqueen
2016-02-03 10:51:48 +08:00
@qinglangee @binbing bytes4 直接被分配到了老年代
qinglangee
2016-02-03 12:07:09 +08:00
我是说把 -Xms 值设小才会触发 GC

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/254032

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX