简体   繁体   English

PermGen空间的意义

[英]Significance of PermGen Space

PermGen空间在java中有什么意义?

PermGen space is reserved for long-term objects - mostly Class objects loaded by the ClassLoader . PermGen空间保留给长期对象 - 主要是由ClassLoader加载的Class对象。 PermGen will not be garbage collected except under very special circumstances (specifically, when the ClassLoader that loaded those classes goes out of scope). 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. 这是一个垃圾收集优化 - 如果我们不希望被垃圾收集的对象被单独存储,它会压缩存储其余对象的空间,这导致垃圾收集器的工作量减少。

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,那么“PermGen的意义”就不存在了,因为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). 几年前,当奇怪的“出于PermGen空间”错误开始出现并且没有人知道它的错误(Tomcat + Hibernate + Sun VM用来触发它)来替换其中一个组件时,它常见(现在问题已被理解,但几年前当他们开始裁剪时,很难找到任何有关此问题的信息)。 You could replace Tomcat with Resin or the Sun VM with JRockIt etc. 你可以用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的实现细节。

The only thing you really need to know is that PermGen space is separate from the general heap and not affected by the -Xmx VM parameter. 您真正需要知道的唯一事情是PermGen空间与常规堆分开,并且不受-Xmx VM参数的影响。 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:MaxPermSize VM option. 如果您的应用程序加载了许多类定义(如应用程序服务器或IDE),则可以使用-XX:MaxPermSize VM选项设置PermGen空间大小。

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 . 具有大型代码库的应用程序可以填满堆的这一部分,这将导致java.lang.OutOfMemoryError: PermGen This is not affected by the -Xmx setting or how much memory you have on the machine. 这不受-Xmx设置或机器上有多少内存的影响。 To set a new initial size, use -XX:PermSize=64m . 要设置新的初始大小,请使用-XX:PermSize=64m To set a maximum size, use -XX:MaxPermSize=128m 要设置最大大小,请使用-XX:MaxPermSize=128m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM