简体   繁体   English

java中的PermGen空间

[英]PermGen space in java

What is PermGen-space in Java ? 什么是Java中的 PermGen-space Our team has issues with PermGen-space getting increased. 我们的团队在PermGen空间方面遇到了问题。 This increase affects performance in the end. 这种增加最终会影响性能。

I wanted to know about what PermGen-space is and how can we optimize its space usage? 我想知道PermGen-space是什么,我们如何优化其空间使用?

From http://java.sun.com/docs/hotspot/gc1.4.2/faq.html (Questions 7--10) 来自http://java.sun.com/docs/hotspot/gc1.4.2/faq.html (问题7--10)

  1. How should the permanent generation be sized? 永久世代应该如何规模?

    The permanent generation is used to hold reflective of the VM itself such as class objects and method objects. 永久生成用于保持VM本身的反射,例如类对象和方法对象。 These reflective objects are allocated directly into the permanent generation, and it is sized independently from the other generations. 这些反射物体直接分配到永久世代中,并且其尺寸独立于其他世代。 Generally, sizing of this generation can be ignored because the default size is adequate. 通常,可以忽略此代的大小,因为默认大小足够。 However, programs that load many classes may need a larger permanent generation. 但是,加载许多类的程序可能需要更大的永久代。

  2. How can I tell if the permanent generation is filling up? 如何判断永久性一代是否填满?

    Starting in 1.4.2 -XX:+PrintGCDetails will print information about all parts of the heap collected at each garbage collection. 从1.4.2 -XX开始:+ PrintGCDetails将打印有关在每个垃圾收集中收集的堆的所有部分的信息。 For a full collection 完整系列

    [Full GC [Tenured: 30437K->33739K(280576K), 0.7050569 secs] 106231K->33739K(362112K), [Perm : 2919K->2919K(16384K)], 0.7052334 secs] [Full GC [Tenured:30437K-> 33739K(280576K),0.7050569 secs] 106231K-> 33739K(362112K),[Perm:2919K-> 2919K(16384K)],0.7052334 secs]

    this example shows that little was collected in the permanent generation (it went from 2919K used before the collection to 2919K used after the collection) and the current size of the permanent generation is 16384K. 这个例子显示在永久世代中收集的很少(它从收集前使用的2919K到收集后使用的2919K),并且永久世代的当前大小是16384K。

  3. How can I increase the permanent generation size? 如何增加永久发电量?

    Use the command line option -XX:MaxPermSize= 使用命令行选项-XX:MaxPermSize =

  4. How do I know what classes are being loaded or unloaded? 我如何知道正在加载或卸载的类?

    Use the command line options -XX:+TraceClassloading and -XX:+TraceClassUnloading 使用命令行选项-XX:+ TraceClassloading和-XX:+ TraceClassUnloading

In the JVM, PermGen holds the classes that have been loaded/created. 在JVM中,PermGen包含已加载/创建的类。 This information is garbage collected like the other parts of the heap, however there are rough edges that can prevent this from happening. 这些信息像堆的其他部分一样被垃圾收集,但是有粗糙的边缘可以防止这种情况发生。 Just increase PermGen space 只需增加PermGen空间

Start your JVM with
-XX:MaxPermSize=Xm
where X is a number like 128, 256.

A good link about this error 关于此错误的良好链接

Basically, Perm generation refers to the space on the heap where all the loaded classes are stored. 基本上,Perm生成指的是堆上存储所有已加载类的空间。 It's exclusively used to store the class definitions. 它专门用于存储类定义。

Besides the basic fields of a Java class there are 除了Java类的基本字段外

* Methods of a class (including the bytecodes)
* Names of the classes (in the form of an object that points to a string also in the permanent generation)
* Constant pool information (data read from the class file, see chapter 4 of the JVM specification for all the details).
* Object arrays and type arrays associated with a class (e.g., an object array containing references to methods).
* Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance)
* Information used for optimization by the compilers (JITs) 

See here. 看到这里。

I know this is an old thread but I think it is worthy to mention that there is no PermGen space after the introduction of Java 8. The JDK 8 HotSpot JVM uses native memory for the representation of class metadata, similar to the Oracle JRockit and IBM JVM's. 我知道这是一个旧线程,但我认为值得一提的是,在引入Java 8之后没有PermGen空间.JDK 8 HotSpot JVM使用本机内存来表示类元数据,类似于Oracle JRockit和IBM JVM的。 The metadata information is not gone, just that the space where it was held is no longer contiguous to the Java heap. 元数据信息没有消失,只是它所保存的空间不再与Java堆相邻。 The metadata has now moved to native memory to an area known as the “Metaspace”. 元数据现在已经移动到本机内存到称为“Metaspace”的区域。 Since the class metadata is allocated out of native memory, the max available space is the total available system memory. 由于类元数据是从本机内存分配的,因此最大可用空间是可用的总系统内存。

There is a very nice article about this subject here: https://www.infoq.com/articles/Java-PERMGEN-Removed 这里有一篇关于这个主题的非常好的文章: https//www.infoq.com/articles/Java-PERMGEN-Removed

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

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