PSYoungGen 有错space

PSYoungGen has wrong space

我测试了一些 jvm 参数来显示 GC 日志,发现一些细节不是我想要的,也许我错了?

public class EdenDemo {

private static final int _1MB = 1024 * 1024;

/**
 * vm arguments:-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[4 * _1MB];
}

public static void main(String[] args) {
    testAllocation();
}

}

jvm 参数

-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8

gc 日志

[GC (Allocation Failure) [PSYoungGen: 6794K->990K(9216K)] 6794K->5094K(19456K), 0.0041458 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap PSYoungGen total 9216K, used 7372K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 77% used [0x00000000ff600000,0x00000000ffc3b718,0x00000000ffe00000) from space 1024K, 96% used [0x00000000ffe00000,0x00000000ffef7910,0x00000000fff00000) to
space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) ParOldGen total 10240K, used 4104K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000) object space 10240K, 40% used [0x00000000fec00000,0x00000000ff002020,0x00000000ff600000) Metaspace used 3244K, capacity 4496K, committed 4864K, reserved 1056768K class space used 350K, capacity 388K, committed 512K, reserved 1048576K

为什么 PSYoungGen space 大小是 9216k(9M) 而不是 10M? 我已经设置了“-Xmn 10M”

引用您的日志

... eden space 8192K, 77% used ...
... from space 1024K, 96% used ...
... to space 1024K, 0% used ...

Young space -Xmn是eden、S0、S1的总和(fromto与S0、S1相同,虽然S0有from 一半集合的作用和 to 其他集合的作用,与 S1 相同)。

eden + from + to = 10MiB 符合预期。

不过,由于 logic of young collectionto space 的利用率应始终为零,因此年轻 space 的有效容量为 eden + from 因此 9 MiB。

不过,一般来说,一些 GC 变体可以动态调整 young space 大小(仅与 -Xmn 相比减少它)因此运行时有效的 young space 可能比配置的更小.