gpt4 book ai didi

java - PSYoungGen 不是 "eden"、 "from"和 "to"的总和?

转载 作者:行者123 更新时间:2023-11-30 05:43:52 27 4
gpt4 key购买 nike

我有一个简单的演示来检查 JVM 内存分配和释放的详细信息。

Java 版本

$ java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

演示

/**
* VM Options: -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
*/
public class DefaultCollector {
private static final int _1MB = 1024 * 1024;
public static void main(String... args) {
byte[] arr1 = new byte[2 * _1MB];
byte[] arr2 = new byte[2 * _1MB];
byte[] arr3 = new byte[2 * _1MB];
byte[] arr4 = new byte[4 * _1MB];
}
}

手动使用 CLI 编译并运行该程序

$ javac DefaultCollector.java 
$ java -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 DefaultCollector

GC日志

Heap
PSYoungGen total 9216K, used 6979K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 8192K, 85% used [0x00000000ff600000,0x00000000ffcd0f68,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)
Metaspace used 2468K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 265K, capacity 386K, committed 512K, reserved 1048576K

我的问题

  1. -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8已经设置并且 eden: 8M, from: 1M, and to: 1M表述清楚,为什么PSYoungGen total 9216K而不是10240K
  2. 为什么 Metaspace 占用这么多内存Metaspace used 2468K ?里面到底是什么?是否有仅有类型信息

最佳答案

对于第一个问题,@Holger 提供了相当直接的实验来证明 fact

The total size reported for the Young Generation always includes the eden and from space only, ignoring the always-empty to space, which is inconsistent to the addresses reported behind the sizes, which include the complete span, covering all three spaces.

那么到了第二个

why Metaspace taking so much memory Metaspace used 2468K? what's in there exactly? Are there only type information?

我在 Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide 中找到了它的规范作为

In the line beginning with Metaspace, the used value is the amount of space used for loaded classes...The line beginning with class space line contains the corresponding values for the metadata for compressed class pointers.

关于java - PSYoungGen 不是 "eden"、 "from"和 "to"的总和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55175723/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com