java PermGen 空间的意义

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

Significance of PermGen Space

javamemory-managementjvmpermgen

提问by java_geek

What is the significance of PermGen space in java?

Java中PermGen空间的意义是什么?

回答by danben

PermGen space is reserved for long-term objects - mostly Classobjects loaded by the ClassLoader. PermGen will not be garbage collected except under very special circumstances (specifically, when the ClassLoaderthat loaded those classes goes out of scope).

PermGen 空间是为长期对象保留的——主要是ClassClassLoader. PermGen 不会被垃圾回收,除非在非常特殊的情况下(特别是当ClassLoader加载这些类的 超出范围时)。

This is a garbage collection optimization - if objects that we don't expect to be garbage collected are stored separately, it compacts the space where the rest of the objects are stored, which leads to less work for the garbage collector.

这是一个垃圾收集优化——如果我们不希望被垃圾收集的对象被单独存储,它会压缩存储其余对象的空间,从而减少垃圾收集器的工作。

回答by SyntaxT3rr0r

The PermGen is specific to VMs having generational garbage collection.

PermGen 特定于具有分代垃圾收集功能的 VM。

If you use, say, JRockit, the "significance of PermGen" is non-existent because JRockit doesn't have that concept.

如果你使用,比如说,JRockit,“永久代的意义”是不存在的,因为 JRockit 没有这个概念。

It uses to be common, a few years ago, when the weird "out of PermGen space" errors started appearing and that nobody knew yet whose fault it was (Tomcat + Hibernate + Sun VM used to trigger this) to replace one of the component (nowadays the problems are understood, but years ago when they started cropping it was hardly possible to find any information on this). You could replace Tomcat with Resin or the Sun VM with JRockIt etc.

几年前,当奇怪的“永久代空间不足”错误开始出现并且没有人知道这是谁的错(Tomcat + Hibernate + Sun VM 用于触发此问题)时,它曾经很常见,以替换其中一个组件(现在问题已被理解,但几年前当他们开始裁剪时,几乎不可能找到任何关于此的信息)。你可以用 Resin 替换 Tomcat,或者用 JRockIt 等替换 Sun VM。

I think it's important to point out that PermGen are not part of the Java specs and only an implementation detail of (quite) some VMs.

我认为重要的是要指出 PermGen 不是 Java 规范的一部分,而只是(相当)一些 VM 的实现细节。

回答by Michael Borgwardt

The only thing you really need to know is that PermGen space is separate from the general heap and not affected by the -XmxVM parameter. If you have an application that loads lots of class definitions (like an application server or an IDE) then you can set the PermGen space size using the -XX:MaxPermSizeVM option.

您真正需要知道的唯一一件事是 PermGen 空间与一般堆是分开的,并且不受-XmxVM 参数的影响。如果您有一个加载大量类定义的应用程序(如应用程序服务器或 IDE),那么您可以使用-XX:MaxPermSizeVM 选项设置 PermGen 空间大小。

回答by lucrussell

The permanent generation holds meta-data describing user classes (classes that are not part of the Java language).

永久代保存描述用户类(不属于 Java 语言的类)的元数据。

Applications with large code-base can fill up this segment of the heap which will cause java.lang.OutOfMemoryError: PermGen. This is not affected by the -Xmx setting or how much memory you have on the machine. To set a new initial size, use -XX:PermSize=64m. To set a maximum size, use -XX:MaxPermSize=128m

具有大型代码库的应用程序可以填充这部分堆,这将导致java.lang.OutOfMemoryError: PermGen. 这不受 -Xmx 设置或机器上有多少内存的影响。要设置新的初始大小,请使用-XX:PermSize=64m. 要设置最大尺寸,请使用-XX:MaxPermSize=128m