问题描述
我知道他们在 Java 8 中已将 PermGen 替换为 MetaSpace.但我有几个问题:
I know they have replaced PermGen with MetaSpace in Java 8. But I have few questions:
- MetaSpace默认是GC收集的吗?
- 连PermGen都是GC收集的,加了
-XX:+CMSClassUnloadingEnabled
之类的args,那MetaSpace有什么比PermGen更好的地方呢? - MetaSpace 是基于本地内存的,所以它会将 java 对象保存在磁盘上而不是 VM 上?
- 即使 MetaSpace 也会耗尽内存?如果再次这样,我会得到
OutOfMemoryException
. - 默认情况下,MetaSpace 可以随着内存的增加而增长?
- Is MetaSpace by default is GC collected?
- Even the PermGen is GC collected by adding the args like
-XX:+CMSClassUnloadingEnabled
, then what makes MetaSpace better than PermGen? - MetaSpace is based on native memory, so it keeps the java objects on the disks rather than on VM?
- Even MetaSpace can run out of memory? If so again I will get
OutOfMemoryException
. - By default the MetaSpace can grow on increase in memory?
提前致谢
推荐答案
MetaSpace默认是GC收集的吗?
Is MetaSpace by default is GC collected?
是的,当元空间满时,GC 会在元空间上运行,它也会动态增加(允许)分配给的内存元数据.
Yes, GC will run on metaspace when its getting full, it would also dynamically increase (given its allowed to) the memory allocated for metadata.
连PermGen都加了-XX:+CMSClassUnloadingEnabled这样的args被GC收集了,那MetaSpace有什么比PermGen更好的地方呢?
Even the PermGen is GC collected by adding the args like -XX:+CMSClassUnloadingEnabled, then what makes MetaSpace better than PermGen?
改进之处在于元空间的动态扩展是 permgen 无法做到的.
The improvement is with the dynamic expansion of the metaspace which is something permgen wasn't able to do.
MetaSpace 是基于本地内存的,所以它会将 java 对象保存在磁盘上而不是 VM 上?
MetaSpace is based on native memory, so it keeps the java objects on the disks rather than on VM?
根据元空间的描述,它只使用原生内存(没有分页).
Based on the description of metaspace, it only uses the native memory (no paging).
基于 Pierre - Hugues Charbonneau 的研究(链接在这里),很明显,元空间的引入并不一定能解决 OOM 问题,它充其量只是解决问题的方法,它试图动态调整元空间内存的大小以适应越来越多的类加载可能的副作用不受控制的增长(只要本机内存允许).
Based on the research by Pierre - Hugues Charbonneau (link here), it's clear that the introduction of metaspace doesn't necessarily solve the OOM issue, it's a bandaid to the problem at best, it attempts to dynamically resize the metaspace memory to accomodate the growing number of classes which get loaded with a possible side effect of growing uncontrollably (so long as the native memory permits it).
我们可以通过将 MaxMetaspaceSize
参数设置为 JVM 并运行提供的示例程序来实现著名的 OOM 错误.
We can achieve the famed OOM error by setting the MaxMetaspaceSize
argument to JVM and running the sample program provided.
非常感谢 Pierre - Hugues Charbonneau.
many thanks to Pierre - Hugues Charbonneau.
这篇关于Java 8 中的 MetaSpace 有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!