Java 8中MetaSpace有什么用? [英] What is the use of MetaSpace in Java 8?

查看:18
本文介绍了Java 8中MetaSpace有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道他们在 Java 8 中用 MetaSpace 替换了 PermGen.但我有几个问题:

I know they have replaced PermGen with MetaSpace in Java 8. But I have few questions:

  1. MetaSpace 是否默认是 GC 收集的?
  2. 即使是 PermGen 也是通过添加像 -XX:+CMSClassUnloadingEnabled 这样的参数来 GC 收集的,那么是什么让 MetaSpace 比 PermGen 更好?
  3. MetaSpace 基于本机内存,因此它将 Java 对象保存在磁盘上而不是 VM 上?
  4. 即使是 MetaSpace 也会耗尽内存?如果再次这样,我将收到 OutOfMemoryException.
  5. 默认情况下,MetaSpace 可以随着内存的增加而增长吗?
  1. Is MetaSpace by default is GC collected?
  2. Even the PermGen is GC collected by adding the args like -XX:+CMSClassUnloadingEnabled, then what makes MetaSpace better than PermGen?
  3. MetaSpace is based on native memory, so it keeps the java objects on the disks rather than on VM?
  4. Even MetaSpace can run out of memory? If so again I will get OutOfMemoryException.
  5. 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 这样的参数来收集的,那么是什么让 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 对象保存在磁盘上而不是虚拟机上?

MetaSpace is based on native memory, so it keeps the java objects on the disks rather than on VM?

根据metaspace的描述,它只使用本机内存(无分页).

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有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆