Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JVM 参数 -XX:MetaspaceSize 解释错误 #1947

Open
qtoo opened this issue Mar 9, 2023 · 1 comment
Open

JVM 参数 -XX:MetaspaceSize 解释错误 #1947

qtoo opened this issue Mar 9, 2023 · 1 comment
Labels
bug Content error

Comments

@qtoo
Copy link

qtoo commented Mar 9, 2023

JVM 参数章节 jvm-parameters-intro.md: L98 中提到:

-XX:MetaspaceSize=N #设置 Metaspace 的初始(和最小大小)

此处解释错误,即 Metaspace 的初始大小非由 -XX:MetaspaceSize 设置。


参见 Oracle 官方文档 Other Considerations 中提到:

When the space committed for class metadata reaches a certain level (a high-water mark), a garbage collection is induced.

The high-water mark is initially set to the value of the command-line option MetaspaceSize.

可见 -XX:MetaspaceSize 是一个提前设定的阈值,会触发 GC,那一定不是初始大小。


通过实验证实 Metaspace 的初始大小非由 -XX:MetaspaceSize 设置,而是会引起 Full GC,过程详见:

JVM 参数 MetaspaceSize 的误解

@Snailclimb
Copy link
Owner

参见 Oracle 官方文档 Other Considerations 中提到:

When the space committed for class metadata reaches a certain level (a high-water mark), a garbage collection is induced.

The high-water mark is initially set to the value of the command-line option MetaspaceSize.

可见 -XX:MetaspaceSize 是一个提前设定的阈值,会触发 GC,那一定不是初始大小。

感谢指出,已经修正。

1、Metaspace 的初始容量并不是 -XX:MetaspaceSize 设置,无论 -XX:MetaspaceSize 配置什么值,对于 64 位 JVM 来说,Metaspace 的初始容量都是 21807104(约 20.8m)。

可以参考 Oracle 官方文档 Other Considerations中提到的:

Specify a higher value for the option MetaspaceSize to avoid early garbage collections induced for class metadata. The amount of class metadata allocated for an application is application-dependent and general guidelines do not exist for the selection of MetaspaceSize. The default size of MetaspaceSize is platform-dependent and ranges from 12 MB to about 20 MB.

MetaspaceSize 的默认大小取决于平台,范围从 12 MB 到大约 20 MB。

另外,还可以看一下这个试验:JVM 参数 MetaspaceSize 的误解

2、Metaspace 由于使用不断扩容到-XX:MetaspaceSize参数指定的量,就会发生 FGC,且之后每次 Metaspace 扩容都会发生 Full GC。

也就是说,MetaspaceSize 表示 Metaspace 使用过程中触发 Full GC 的阈值,只对触发起作用。

垃圾搜集器内部是根据变量 _capacity_until_GC来判断 Metaspace 区域是否达到阈值的,初始化代码如下所示:

void MetaspaceGC::initialize() {
  // Set the high-water mark to MaxMetapaceSize during VM initializaton since
  // we can't do a GC during initialization.
  _capacity_until_GC = MaxMetaspaceSize;
}

@Snailclimb Snailclimb added the bug Content error label Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Content error
Projects
None yet
Development

No branches or pull requests

2 participants