Java 什么是烫发空间?

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

What is perm space?

javaprofiling

提问by skiphoppy

While learning about java memory profiling, I keep seeing the term "perm space" in addition to "heap." I know what the heap is - what's perm space?

在学习 Java 内存分析时,除了“堆”之外,我还经常看到“永久空间”一词。我知道堆是什么 - 什么是永久空间?

采纳答案by Andrew Hare

It stands for permanent generation:

它代表永久代

The permanent generation is special because it holds meta-data describing user classes (classes that are not part of the Java language). Examples of such meta-data are objects describing classes and methods and they are stored in the Permanent Generation. Applications with large code-base can quickly fill up this segment of the heap which will cause java.lang.OutOfMemoryError: PermGen no matter how high your -Xmx and how much memory you have on the machine.

永久代是特殊的,因为它保存描述用户类(不属于 Java 语言的类)的元数据。这种元数据的例子是描述类和方法的对象,它们存储在永久代中。具有大型代码库的应用程序可以快速填满堆的这一部分,这将导致 java.lang.OutOfMemoryError: PermGen 无论您的 -Xmx 有多高以及您在机器上有多少内存。

回答by Jesse

The permgen space is the area of heap that holds all the reflective data of the virtual machine itself, such as class and method objects.

permgen 空间是堆的区域,其中包含虚拟机本身的所有反射数据,例如类和方法对象。

回答by Nick

It holds stuff like class definitions, string pool, etc. I guess you could call it meta-data.

它包含类定义、字符串池等内容。我想您可以将其称为元数据。

回答by Matt

Simple (and oversimplified) answer: it's where the jvm stores its own bookkeeping data, as opposed to your data.

简单(且过于简单)的答案:这是 jvm 存储自己的簿记数据的地方,而不是您的数据。

回答by DKSRathore

Perm spaceis used to keep informations for loaded classes and few other advanced features like String Pool(for highly optimized string equality testing), which usually get created by String.intern()methods. As your application(number of classes) will grow this space shall get filled quickly, since the garbage collection on this Space is not much effective to clean up as required, you quickly get Out of Memory : perm gen space error. After then, no application shall run on that machine effectively even after having a huge empty JVM.

Perm space用于保存加载类和一些其他高级功能的信息,例如String Pool(用于高度优化的字符串相等性测试),这些功能通常由String.intern()方法创建。由于您的应用程序(类的数量)会增长,这个空间将很快被填满,因为这个空间上的垃圾收集不能有效地根据需要清理,您很快就会得到内存不足:永久空间错误。之后,即使有一个巨大的空 JVM,也不会在该机器上有效地运行任何应用程序。

Before starting your application you should java -XX:MaxPermSizeto get rid of this error.

在开始你的应用程序之前,你应该java -XX:MaxPermSize摆脱这个错误。

回答by Spark-Beginner

PermGen Space stands for memory allocation for Permanent generation All Java immutable objects come under this category, like Stringwhich is created with literals or with String.intern()methods and for loading the classes into memory. PermGen Space speeds up our String equality searching.

PermGen Space 代表永久代的内存分配所有 Java 不可变对象都属于这一类别,例如String使用文字或String.intern()方法创建并将类加载到内存中。PermGen Space 加速了我们的字符串相等搜索。

回答by Praveen Kumar K S

Perm Gen stands for permanent generation which holds the meta-data information about the classes.

Perm Gen 代表永久代,它保存有关类的元数据信息。

  1. Suppose if you create a class name A, it's instance variable will be stored in heap memory and class A along with static classloaders will be stored in permanent generation.
  2. Garbage collectors will find it difficult to clear or free the memory space stored in permanent generation memory. Hence it is always recommended to keep the permgen memory settings to the advisable limit.
  3. JAVA8 has introduced the concept called meta-space generation, hence permgen is no longer needed when you use jdk 1.8 versions.
  1. 假设如果您创建一个类名 A,它的实例变量将存储在堆内存中,而类 A 与静态类加载器将存储在永久代中。
  2. 垃圾收集器会发现很难清除或释放存储在永久代内存中的内存空间。因此,始终建议将 permgen 内存设置保持在可取的​​限度内。
  3. JAVA8 引入了称为元空间生成的概念,因此当您使用 jdk 1.8 版本时不再需要 permgen。

回答by hi.nitish

What exists under PremGen : Class Area comes under PremGen area. Static fields are also developed at class loading time, so they also exist in PremGen. Constant Pool area having all immutable fields that are pooled like String are kept here. In addition to that, class data loaded by class loaders, Object arrays, internal objects used by jvm are also located.

PremGen 下存在什么: Class Area 位于 PremGen 区域下。静态字段也在类加载时开发,因此它们也存在于 PremGen 中。具有所有不可变字段的常量池区域,这些字段像 String 一样被汇集在这里。除此之外,类加载器加载的类数据、Object数组、jvm使用的内部对象也都在。

回答by Amruta

Permgen space is always known as method area.When the classloader subsystem will load the the class file(byte code) to the method area(permGen). It contains all the class metadata eg: Fully qualified name of your class, Fully qualified name of the immediate parent class, variable info, constructor info, constant pool infor etc.

Permgen 空间总是被称为方法区。当类加载器子系统将类文件(字节码)加载到方法区(permGen)时。它包含所有类元数据,例如:类的完全限定名称、直接父类的完全限定名称、变量信息、构造函数信息、常量池信息等。

回答by user2815984

  • JVM has an internal representation of Java objects and those internal representations are stored in the heap (in the young generation or the tenured generation).
  • JVM also has an internal representation of the Java classes and those are stored in the permanent generation
  • JVM 具有 Java 对象的内部表示,这些内部表示存储在堆中(年轻代或年老代)。
  • JVM 还具有 Java 类的内部表示,这些类存储在永久代中

enter image description here

在此处输入图片说明