MetaSpace 在 Java 8 中有什么用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24074164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the use of MetaSpace in Java 8?
提问by batman
I know they have replaced PermGen with MetaSpace in Java 8. But I have few questions:
我知道他们在 Java 8 中用 MetaSpace 替换了 PermGen。但我有几个问题:
- 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 收集的?
- 甚至 PermGen 也是通过添加 args 来 GC 收集的
-XX:+CMSClassUnloadingEnabled
,那么是什么让 MetaSpace 比 PermGen 更好? - MetaSpace 基于本机内存,因此它将 Java 对象保存在磁盘上而不是 VM 上?
- 甚至 MetaSpace 也会耗尽内存?如果是这样,我会得到
OutOfMemoryException
。 - 默认情况下,MetaSpace 可以随着内存的增加而增长吗?
Thanks in advance
提前致谢
采纳答案by Anantha Sharma
Is MetaSpace by default is GC collected?
MetaSpace 是否默认是 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.
是的,GC 将在元空间变满时在元空间上运行,它还会动态增加(在允许的情况下)为元数据分配的内存。
Even the PermGen is GC collected by adding the args like -XX:+CMSClassUnloadingEnabled, then what makes MetaSpace better than PermGen?
甚至 PermGen 也是通过添加像 -XX:+CMSClassUnloadingEnabled 这样的 args 来收集的,那么是什么让 MetaSpace 比 PermGen 更好?
The improvement is with the dynamic expansion of the metaspace which is something permgen wasn't able to do.
改进在于元空间的动态扩展,这是 permgen 无法做到的。
MetaSpace is based on native memory, so it keeps the java objects on the disks rather than on VM?
MetaSpace 基于本机内存,因此它将 Java 对象保存在磁盘上而不是 VM 上?
Based on the description of metaspace, it only uses the native memory (no paging).
根据元空间的描述,它只使用本机内存(无分页)。
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).
根据 Pierre-Hugues Charbonneau 的研究(链接在这里),很明显元空间的引入不一定解决 OOM 问题,它充其量只是解决问题的创可贴,它尝试动态调整元空间内存的大小以适应越来越多的类被加载,可能会产生无法控制的增长(只要本机内存允许)。
We can achieve the famed OOM error by setting the MaxMetaspaceSize
argument to JVM and running the sample program provided.
我们可以通过将MaxMetaspaceSize
参数设置为 JVM 并运行提供的示例程序来实现著名的 OOM 错误。
many thanks to Pierre - Hugues Charbonneau.
非常感谢 Pierre - Hugues Charbonneau。
回答by Fernando Rincon
In response:
回应:
By default the Metaspace memory is collected if it reaches the MaxMetaspaceSize. This parameter is initially unlimited. The limit is the memory in your machine. But the memory is automatically freeded when a class and class loader is no longer needed. You only need to tune this parameter if you suspect that the ClassLoader has a memory leak.
The MetaSpece use native memory and the organization in memory with pointers makes that the GC are faster than older PermGen memory.
No, it means that the JVM use the memory like common C program and don't use the virtual memory space for java objects. That seems that the memory is only limited by the machine. Take care that the memory of the machine can be swapped to disk if needed.
If you set the parameter MaxMetaspaceSize you can get OutOfMemory and, if you don't set this parameter you can get if the process allocate all the machine memory (including swap space).
默认情况下,如果达到 MaxMetaspaceSize,则收集元空间内存。此参数最初是无限制的。限制是您机器中的内存。但是当不再需要类和类加载器时,内存会自动释放。如果您怀疑 ClassLoader 存在内存泄漏,则只需调整此参数。
MetaSpece 使用本机内存,内存中的指针组织使得 GC 比旧的 PermGen 内存更快。
不,这意味着JVM像普通C程序一样使用内存,不使用java对象的虚拟内存空间。那似乎内存只受机器限制。请注意,如果需要,可以将机器的内存交换到磁盘。
如果你设置参数 MaxMetaspaceSize 你可以得到 OutOfMemory ,如果你不设置这个参数你可以得到如果进程分配了所有的机器内存(包括交换空间)。
回答by Raj
Is MetaSpace by default is GC collected?
Garbage collection of the dead classes and classloaders is triggered once the class metadata usage reaches the “MaxMetaspaceSize” which by default is
"unlimited"
so a proper monitoring is required to limit the delay or frequency of such GC.Even the PermGen is GC collected by adding the args like -XX:+CMSClassUnloadingEnabled, then what makes MetaSpace better than PermGen?
The main goal is removing permgen was so that users do not have to think about correctly sizing it.
MetaSpace is based on native memory, so it keeps the java objects on the disks rather than on VM?
Disk is not native memory but storage device. Native memory, in this context is the area, is the memory for the process left over from the Java heap
Even MetaSpace can run out of memory?
Yes, it is limited by the amount of memory in your machine.
MetaSpace 是否默认是 GC 收集的?
一旦类元数据使用达到“MaxMetaspaceSize”,默认情况下,就会触发死类和类加载器的垃圾收集,
"unlimited"
因此需要适当的监控来限制此类 GC 的延迟或频率。甚至 PermGen 也是通过添加像 -XX:+CMSClassUnloadingEnabled 这样的 args 来收集的,那么是什么让 MetaSpace 比 PermGen 更好?
主要目标是删除 permgen 以便用户不必考虑正确调整它的大小。
MetaSpace 基于本机内存,因此它将 Java 对象保存在磁盘上而不是 VM 上?
磁盘不是本机内存而是存储设备。本机内存,在这个上下文中是区域,是进程从 Java 堆中遗留下来的内存
甚至 MetaSpace 也会耗尽内存?
是的,它受机器内存量的限制。