刚开始学习jvm,看《深入java虚拟机这本书》其中一个例子有点儿问题
不太理解虚拟机是怎么分配内存的
代码如下
public class EdenFirstAllocTest {
public static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
byte[] date1 = new byte[2 * _1MB];
byte[] date2 = new byte[2 * _1MB];
byte[] date3 = new byte[2 * _1MB];
byte[] date4 = new byte[4 * _1MB];
}
}
虚拟机参数
-Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -verbose:gc -XX:SurvivorRatio=8
JDK版本是1.8,在mac上运行,
GC日志如下
Heap
PSYoungGen total 9216K, used 8192K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000)
eden space 8192K, 100% used [0x00000007bf600000,0x00000007bfe00000,0x00000007bfe00000)
from space 1024K, 0% used [0x00000007bff00000,0x00000007bff00000,0x00000007c0000000)
to space 1024K, 0% used [0x00000007bfe00000,0x00000007bfe00000,0x00000007bff00000)
ParOldGen total 10240K, used 4096K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000)
object space 10240K, 40% used [0x00000007bec00000,0x00000007bf000010,0x00000007bf600000)
Metaspace used 3072K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 337K, capacity 388K, committed 512K, reserved 1048576K
正常不是把6兆内存移到老年代,然后4M放到年轻代的eden区么
而且大小也对不上,gc日志显示占用了8+4 = 12M内存,其实只有10M