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

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

问题描述

在 Java 7 之前,JVM 内存中有一个名为 PermGen 的区域,JVM 用来保存其类.在 Java 8 中,它被删除并替换为称为元空间的区域.

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.

永久代和元空间之间最重要的区别是什么?

What are the most important differences between PermGen and Metaspace?

我知道的唯一区别是 java.lang.OutOfMemoryError: PermGen space 不能再被抛出并且 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 或动态类(卸载)加载,所以一旦一个类被加载,它就会被卡在内存中,直到 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 我想 OS 内存用完的影响可能比 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 还是 Metaspace 的 JVM,如果您正在进行动态类卸载,您应该采取措施防止类加载器泄漏,例如使用我的 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天全站免登陆