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的默认参数是什么,这只是冰山一角