Java 中的“PermSize”是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1634216/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:01:45  来源:igfitidea点击:

What is 'PermSize' in Java?

javamemory

提问by Anand

I was going through the document in Java Memory Managementand in that I came across PermSize which I couldn't understand. The document says that it stores, "JVM stores its metadata", but I couldn't exactly get what is meant by metadata. I was googling and somewhere I read it stores a value object (user defined object).

我正在浏览Java 内存管理中的文档,并在其中遇到了我无法理解的 PermSize。该文档说它存储“JVM 存储其元数据”,但我无法完全理解元数据的含义。我在谷歌上搜索,在我读到的某个地方存储了一个值对象(用户定义的对象)。

What kind of objects are stored there? An example with an explanation would be great.

什么样的对象存储在那里?一个有解释的例子会很棒。

采纳答案by Pascal Thivent

A quick definition of the "permanent generation":

“永久一代”的快速定义:

"The permanent generation is used to hold reflective data of the VM itself such as class objects and method objects. These reflective objects are allocated directly into the permanent generation, and it is sized independently from the other generations." [ref]

“永久代用于保存 VM 本身的反射数据,例如类对象和方法对象。这些反射对象直接分配到永久代中,并且其大小独立于其他代。” [参考]

In other words, this is where class definitions go (and this explains why you may get the message OutOfMemoryError: PermGen spaceif an application loads a large number of classes and/or on redeployment).

换句话说,这就是类定义的所在(这解释了为什么OutOfMemoryError: PermGen space如果应用程序加载大量类和/或重新部署时您可能会收到消息)。

Note that PermSizeis additional to the -Xmxvalue set by the user on the JVM options. But MaxPermSizeallows for the JVM to be able to grow the PermSizeto the amount specified. Initially when the VM is loaded, the MaxPermSizewill still be the default value (32mb for -clientand 64mb for -server) but will not actually take up that amount until it is needed. On the other hand, if you were to set BOTH PermSizeand MaxPermSizeto 256mb, you would notice that the overall heap has increased by 256mb additional to the -Xmxsetting.

请注意,这PermSize-Xmx用户在 JVM 选项上设置的值的附加值。但MaxPermSize允许 JVM 能够增长PermSize到指定的数量。最初当 VM 被加载时,MaxPermSize仍然是默认值(32mb for-client和 64mb for -server),但在需要之前不会实际占用该数量。另一方面,如果您将 BOTHPermSizeMaxPermSize256mb都设置为 256mb,您会注意到整体堆增加了 256mb -Xmx

回答by ankon

The permament pool contains everything that is not your application data, but rather things required for the VM: typically it contains interned strings, the byte code of defined classes, but also other "not yours" pieces of data.

永久池包含不是您的应用程序数据的所有内容,而是 VM 所需的内容:通常它包含内部字符串、已定义类的字节码,以及其他“不属于您的”数据。

回答by sleske

This blog postgives a nice explanation and some background. Basically, the "permanent generation" (whose size is given by PermSize) is used to store things that the JVM has to allocate space for, but which will not (normally) be garbage-collected (hence "permanent") (+). That means for example loaded classes and static fields.

这篇博文给出了一个很好的解释和一些背景。基本上,“永久代”(其大小由 PermSize 给出)用于存储 JVM 必须为其分配空间但不会(通常)被垃圾收集(因此是“永久”)(+)的东西。这意味着例如加载的类和静态字段。

There is also a FAQ on garbage collectiondirectly from Sun, which answers some questions about the permanent generation. Finally, here's a blog postwith a lot of technical detail.

还有一个直接来自Sun的关于垃圾收集FAQ,回答了一些关于永久代的问题。最后,这是一篇包含大量技术细节的博客文章

(+) Actually parts of the permanent generation willbe GCed, e.g. class objects will be removed when a class is unloaded. But that was uncommon when the permanent generation was introduced into the JVM, hence the name.

(+) 实际上永久代的一部分被GCed,例如当一个类被卸载时类对象将被删除。但是当永久代被引入 JVM 时,这种情况并不常见,因此得名。

回答by Appesh

lace to store your loaded class definition and metadata. If a large code-base project is loaded, the insufficient Perm Gen size will cause the popular Java.Lang.OutOfMemoryError: PermGen.

花边来存储您加载的类定义和元数据。如果加载大型代码库项目,Perm Gen 大小不足将导致流行的 Java.Lang.OutOfMemoryError: PermGen。