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
![]() | 1 qinglangee 2016-01-28 17:47:33 +08:00 -Xms20M 值太大,还没触发 GC , 改成 -Xms8M 试试 |
2 binbing 2016-01-28 17:53:04 +08:00 System.gc() |
![]() | 3 eightqueen OP @qinglangee @binbing bytes4 直接被分配到了老年代 |
![]() | 4 qinglangee 216-02-03 12:07:09 +08:00 ![]() 我是说把 -Xms 值设小才会触发 GC |