关于JVM GC回收的疑问
最近在读关于GC问题看到个例子,这么做都没办法做出应有的效果:
private static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
testAllocation();
// testPretenureSizeThreshold();
}
/**
* -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
*/
public static void testAllocation() {
byte[] allocation1, allocation2, allocation3, allocation4;
allocation1 = new byte[2 * _1MB];
allocation2 = new byte[2 * _1MB];
allocation3 = new byte[2 * _1MB];
allocation4 = new byte[5 * _1MB];
}
/**
* -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=3145728
*/
public static void testPretenureSizeThreshold() {
byte[] allocation;
allocation = new byte[4 * _1MB];
}
1)在文章上是这样说的,testAllocation()在执行到allocation4 = new byte[5 * _1MB];的时候会超出新生代,导致产生一次minor GC,可是我在打印GC信息的过程中并没有发生GC,下面是我打印的结果:
Heap
PSYoungGen total 9216K, used 6979K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 8192K, 85% used [0x00000000ff600000,0x00000000ffcd0fa0,0x00000000ffe00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
ParOldGen total 10240K, used 5120K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 50% used [0x00000000fec00000,0x00000000ff100010,0x00000000ff600000)
PSPermGen total 21504K, used 2483K [0x00000000f9a00000, 0x00000000faf00000, 0x00000000fec00000)
object space 21504K, 11% used [0x00000000f9a00000,0x00000000f9c6cd80,0x00000000faf00000)
感觉allocation4 = new byte[5 * _1MB];直接进入了年老代,有点迷茫
2)执行testPretenureSizeThreshold方法的时候,我已经指定了XX:PretenureSizeThreshold=3145728,也就是说当我开创allocation = new byte[4 * _1MB]; 一个大于3MB的空间时候,应该直接进入年老代,但是打印结果却是:
Heap
PSYoungGen total 9216K, used 4931K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 8192K, 60% used [0x00000000ff600000,0x00000000ffad0f80,0x00000000ffe00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
ParOldGen total 10240K, used 0K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 0% used [0x00000000fec00000,0x00000000fec00000,0x00000000ff600000)
PSPermGen total 21504K, used 2483K [0x00000000f9a00000, 0x00000000faf00000, 0x00000000fec00000)
object space 21504K, 11% used [0x00000000f9a00000,0x00000000f9c6cd80,0x00000000faf00000)
从打印上看,并没有进入到年老代。
请大神指导,我用的JDK是1.7.0.51,eclipse下编译。