PermGen和Metaspace有什么区别? [英] What is the difference between PermGen and Metaspace?

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

问题描述

在Java 7之前,JVM内存中有一个名为 PermGen 的区域,其中JVM用于保留其类。在 Java 8 中,它被删除并替换为区域称为 Metaspace

Until Java 7 there was an area in JVM memory called PermGen, where JVM used to keep its classes. In Java 8 it was removed and replaced by area called Metaspace.

PermGen和Metaspace之间最重要的区别是什么?

What are the most important differences between PermGen and Metaspace?

我知道的唯一区别是 java.lang.OutOfMemoryError:无法再抛出PermGen空间,并忽略VM参数 MaxPermSize

The only difference I know is that java.lang.OutOfMemoryError: PermGen space can no longer be thrown and the VM parameter MaxPermSize is ignored.

推荐答案

从用户的角度来看 - 我认为之前的答案不够强调 - 的主要区别在于 Metaspace默认情况下,自动增加其大小(直到底层操作系统提供的内容),而PermGen始终具有固定的最大大小。您可以使用JVM参数为Metaspace设置固定的最大值,但不能使PermGen自动增加。

The main difference from a user perspective - which I think the previous answer does not stress enough - is that Metaspace by default auto increases its size (up to what the underlying OS provides), while PermGen always has a fixed maximum size. You can set a fixed maximum for Metaspace with JVM parameters, but you cannot make PermGen auto increase.

在很大程度上,它只是名称的更改。回到引入PermGen时,没有Java EE或动态类(un)加载,所以一旦加载了类,它就会停留在内存中,直到JVM关闭 - 因此永久生成。现在可以在JVM的生命周期内加载和卸载类,因此Metaspace对保存元数据的区域更有意义。

To a large degree it is just a change of name. Back when PermGen was introduced, there was no Java EE or dynamic class(un)loading, so once a class was loaded it was stuck in memory until the JVM shut down - thus Permanent Generation. Nowadays classes may be loaded and unloaded during the lifespan of the JVM, so Metaspace makes more sense for the area where the metadata is kept.

它们都包含 java.lang.Class 实例,它们都遭受 ClassLoader泄漏。唯一不同的是,使用Metaspace默认设置,它需要更长的时间,直到您注意到症状(因为它会尽可能多地自动增加),即您只是将问题推得更远而不解决它。 OTOH我想象用完内存操作系统内存的效果可能比用完JVM PermGen更严重,所以我不确定它有多大的改进。

Both of them contain the java.lang.Class instances and both of them suffer from ClassLoader leaks. Only difference is that with Metaspace default settings, it takes longer until you notice the symptoms (since it auto increases as much as it can), i.e. you just push the problem further away without solving it. OTOH I imagine the effect of running out of OS memory can be more severe than just running out of JVM PermGen, so I'm not sure it is much of an improvement.

无论您是使用带有PermGen的JVM还是使用Metaspace,如果您正在进行动态类卸载,您应该对类加载器泄漏采取措施,例如使用我的 ClassLoader防漏库

Whether you're using a JVM with PermGen or with Metaspace, if you are doing dynamic class unloading, you should to take measures against classloader leaks, for example by using my ClassLoader Leak Prevention library.

这篇关于PermGen和Metaspace有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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