简体   繁体   English

PermGen和Heap,差异及其意义

[英]PermGen and Heap, Difference and their significance

Friends, 朋友们,

Can you please give me significance, difference and uses for Heap and PermGen. 你能否告诉我Heap和PermGen的意义,差异和用途。 Also it would be good to know what class are loaded in them respectively. 同样知道分别在其中加载了哪个类也是一件好事。

Explanation related to Java VM specification would be really helpful 与Java VM规范相关的解释非常有用

Thanks Punith 谢谢Punith

Memory(Heap) is managed in generations, or memory pools holding objects of different ages. 内存(堆)是代代管理的,或者是存放不同年龄对象的内存池。 Garbage collection occurs in each generation when the generation fills up. 当生成填满时,每一代都会发生垃圾收集。 Objects are allocated in a generation for younger objects or the young generation , and because of infant mortality most objects die there. 物体被分配在一代中用于较年轻的物体或young generation ,并且由于婴儿死亡,大多数物体死在那里。

When any new object is constructed it goes to Eden space which is a part of Young Generation . 当构建任何新对象时,它将进入Eden空间,这是Young Generation的一部分。

If object is still alive after some time it goes to tenured generation where long lived objects lie. 如果物体在一段时间后仍处于活着状态,那么它将进入tenured generation物体,长寿物体就会存在。

If object is supposed to live until over process exist then object is moved to Perm Generation . 如果对象应该存在,直到存在过程,则将对象移动到Perm Generation Java classes are stored in the permanent generation. Java classes存储在永久代中。

Good links are there in What does PermGen actually stand for? PermGen实际上代表的是什么? . Especially liked this blog 特别喜欢这个博客

I was having the same doubt about the PermGen and other Heap memory parts. 我对PermGen和其他堆内存部分有同样的疑问。 After doing some search, here what I finally concluded. 在做了一些搜索之后,这里我最终得出结论。

Java HotSpot VM needs memory which it gets from the operating system, this memory is termed as Heap memory. Java HotSpot VM需要从操作系统获取的内存,此内存称为堆内存。 Now heap memory as famously known to store the objects and holds other important things as well. 现在堆内存是众所周知的存储对象并保存其他重要的东西。

Short live span Java objects are stored in the young generation and if those objects are still needed for further execution then, it is shifted to the tenure/old generation. 短期Java对象存储在年轻代中,如果仍需要这些对象进行进一步执行,则将其转移到终身/旧代。 And depending upon the type of Generation Garbage Collector, memory is cleaned. 并且根据Generation Garbage Collector的类型,清理内存。

What about the Permanent Generation (PermGen)? 永久世代(PermGen)怎么样? Java HotSpot VM loads the classes/class structure in the PermGen which is used by JVM to store loaded classes and other meta-data. Java HotSpot VM加载PermGen中的类/类结构,JVM使用它来存储加载的类和其他元数据。 PermGen is not used to store objects. PermGen不用于存储对象。

Apart from objects and class structure, JVM code itself loads profiler agent code and data etc. 除了对象和类结构之外,JVM代码本身还加载了探查器代理代码和数据等。

So basically, heap = object + class structure + JVM architecture. 所以基本上,heap = object + class structure + JVM体系结构。

References: Java Docs , Java GC Guide 参考文献: Java DocsJava GC Guide

Well i'm no expert, but the PermGem memory resides within the Heap, since its like a special place where all the classes are loaded at runtime. 嗯,我不是专家,但PermGem内存驻留在Heap中,因为它就像一个特殊的地方,所有类都在运行时加载。 So if you have too many classes, the PermGem throws an OutOfMemoryException. 因此,如果你有太多的类,PermGem会抛出一个OutOfMemoryException。 And well the heap stores the objects you instanciate within your java code, where the GC collects the objects that are not referenced by any variable in a running thread in the stack. 而且,堆存储您在java代码中实例化的对象,其中GC收集堆栈中正在运行的线程中的任何变量未引用的对象。

I believe Permgen is memory area inside Heap memory only. 我相信Permgen只是堆内存中的内存区域。 It is created for special purpose like holding String. 它是为特殊目的而创建的,比如持有String。

All the object created does not get Permgen Memory It is only for special clasess like String in JDK 6 or below. 创建的所有对象都没有得到Permgen Memory它只适用于JDK 6或更低版本中的String之类的特殊clasess。

In modern JDK versions like 8 and above, Pergen is not found however new memory like Non Heap and other various cache memories are introduced. 在现代JDK版本(如8及更高版本)中,未找到Pergen,但是引入了像Non Heap和其他各种缓存的新内存。

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

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