本文翻译自:Java heap terminology: young, old and permanent generations?

I'm trying to understand What the concepts of young , old and permanent generations are in the Java heap terminology, and more specifically the interactions between the three generations. 我试图理解Java堆术语中的年轻老年永久一代的概念是什么,更具体地说是三代之间的交互。

My questions are: 我的问题是:

  • What is the young generation? 什么是年轻一代?
  • What is the old generation? 什么是老一代?
  • What is the permanent generation? 什么是永久一代?
  • How does the three generations interact/relate to each other? 这三代人之间是如何相互作用/相互联系的?

#1楼

参考:https://stackoom.com/question/8vrQ/Java堆术语-年轻一代-老一代和永久一代


#2楼

The Java virtual machine is organized into three generations: a young generation, an old generation, and a permanent generation. Java虚拟机分为三代:年轻一代,老一代和永久一代。 Most objects are initially allocated in the young generation. 大多数对象最初是在年轻一代中分配的。 The old generation contains objects that have survived some number of young generation collections, as well as some large objects that may be allocated directly in the old generation. 老一代包含的对象在许多年轻一代集合中幸存下来,还有一些大型对象可以直接在老一代中分配。 The permanent generation holds objects that the JVM finds convenient to have the garbage collector manage, such as objects describing classes and methods, as well as the classes and methods themselves. 永久生成包含JVM认为便于垃圾回收器管理的对象,例如描述类和方法的对象,以及类和方法本身。


#3楼

This seems like a common misunderstanding. 这似乎是一种常见的误解。 In Oracle's JVM, the permanent generation is not part of the heap. 在Oracle的JVM中,永久生成不是堆的一部分。 It's a separate space for class definitions and related data. 它是用于类定义和相关数据的单独空间。 In Java 6 and earlier, interned strings were also stored in the permanent generation. 在Java 6和更早版本中,实习生字符串也存储在永久代中。 In Java 7, interned strings are stored in the main object heap. 在Java 7中,插入的字符串存储在主对象堆中。

Here is a good post on permanent generation . 这是关于永久世代的好文章。

I like the descriptions given for each space in Oracle's guide on JConsole : 我喜欢Oracle 关于JConsole指南中对每个空间的描述:

For the HotSpot Java VM, the memory pools for serial garbage collection are the following. 对于HotSpot Java VM,用于串行垃圾回收的内存池如下。

  • Eden Space (heap): The pool from which memory is initially allocated for most objects. Eden Space(堆):最初从中为大多数对象分配内存的池。
  • Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space. 幸存者空间(堆):包含在Eden空间的垃圾回收中幸存的对象的池。
  • Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space. 永久生成(堆):包含幸存者空间中已存在一段时间的对象的池。
  • Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. 永久生成(非堆):包含虚拟机本身所有反射数据的池,例如类和方法对象。 With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas. 对于使用类数据共享的Java VM,这一代被分为只读和读写区域。
  • Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code. 代码缓存(非堆):HotSpot Java VM还包括代码缓存,其中包含用于编译和存储本机代码的内存。

Java uses generational garbage collection. Java使用分代垃圾回收。 This means that if you have an object foo (which is an instance of some class), the more garbage collection events it survives (if there are still references to it), the further it gets promoted. 这意味着,如果您有一个对象foo(它是某个类的实例),则该对象幸存的垃圾回收事件越多(如果仍然有对其的引用),则它得到的推广就越多。 It starts in the young generation (which itself is divided into multiple spaces - Eden and Survivor) and would eventually end up in the tenured generation if it survived long enough. 它始于年轻一代(本身被划分为多个空间-伊甸园和幸存者),如果生存了足够长的时间,最终将进入终身一代。


#4楼

The Heap is divided into young and old generations as follows : 堆分为以下几代:

Young Generation : It is place where lived for short period and divided into two spaces: 青年一代 :是短暂居住的地方,分为两个空间:

  • Eden Space : When object created using new keyword memory allocated on this space. 伊甸园空间 :使用在此空间上分配的新关键字存储器创建对象时。
  • Survivor Space : This is the pool which contains objects which have survived after java garbage collection from Eden space. Survivor Space :这是一个池,其中包含在从Eden空间进行Java垃圾回收之后仍然存在的对象。

Old Generation : This pool basically contains tenured and virtual (reserved) space and will be holding those objects which survived after garbage collection from Young Generation. 老一代 :该池基本上包含使用权和虚拟(保留)空间,并将容纳从Young Generation回收垃圾后幸存的那些对象。

  • Tenured Space: This memory pool contains objects which survived after multiple garbage collection means object which survived after garbage collection from Survivor space. 永久性空间:此内存池包含在多次垃圾回收之后仍然存在的对象,这意味着从幸存者空间进行垃圾回收之后仍然存在的对象。

Permanent Generation : This memory pool as name also says contain permanent class metadata and descriptors information so PermGen space always reserved for classes and those that is tied to the classes for example static members. 永久生成:顾名思义,该内存池还包含永久类的元数据和描述符信息,因此PermGen空间始终为类以及与类相关的那些(例如静态成员)保留。

Java8 Update: PermGen is replaced with Metaspace which is very similar. Java8更新: PermGen被非常相似的Metaspace取代了。
Main difference is that Metaspace re-sizes dynamically ie, It can expand at runtime. 主要区别在于Metaspace可动态调整大小,即它可以在运行时扩展。
Java Metaspace space: unbounded (default) Java Metaspace空间:无界(默认)

Code Cache (Virtual or reserved) : If you are using HotSpot Java VM this includes code cache area that containing memory which will be used for compilation and storage of native code. 代码缓存 (虚拟或保留):如果使用的是HotSpot Java VM,则包括代码缓存区域,该区域包含用于编译和存储本机代码的内存。

Java堆术语:年轻一代,老一代和永久一代?

Courtesy 礼貌


#5楼

Memory in SunHotSpot JVM is organized into three generations: young generation, old generation and permanent generation. SunHotSpot JVM中的内存分为三代:年轻一代,老一代和永久一代。

  • Young Generation : the newly created objects are allocated to the young gen. 年轻一代:将新创建的对象分配给年轻一代。
  • Old Generation : If the new object requests for a larger heap space, it gets allocated directly into the old gen. 老一代:如果新对象要求更大的堆空间,它将直接分配给老一代。 Also objects which have survived a few GC cycles gets promoted to the old gen ie long lived objects house in old gen. 幸存了几个GC周期的对象也被提升为旧一代,即在旧一代中居住的寿命长的对象。
  • Permanent Generation : The permanent generation holds objects that the JVM finds convenient to have the garbage collector manage, such as objects describing classes and methods, as well as the classes and methods themselves. 永久代:永久代保存JVM发现便于垃圾回收器管理的对象,例如描述类和方法的对象以及类和方法本身。

FYI: The permanent gen is not considered a part of the Java heap. 仅供参考:永久gen不被视为Java堆的一部分。

How does the three generations interact/relate to each other? 这三代人之间是如何相互作用/相互联系的? Objects(except the large ones) are first allocated to the young generation. 对象(大对象除外)首先分配给年轻一代。 If an object remain alive after x no. 如果一个对象在x no之后仍然存在。 of garbage collection cycles it gets promoted to the old/tenured gen. 垃圾收集周期的提升,它被提升为旧的/终身使用的一代。 Hence we can say that the young gen contains the short lived objects while the old gen contains the objects having a long life. 因此,可以说年轻一代包含寿命短的对象,而老一代包含寿命长的对象。 The permanent gen does not interact with the other two generations. 永久一代不与其他两代交互。


#6楼

What is the young generation? 什么是年轻一代?

The Young Generation is where all new objects are allocated and aged. 年轻一代是所有新对象的分配和老化对象。 When the young generation fills up, this causes a minor garbage collection. 当年轻一代填满时,这将导致少量垃圾收集。 A young generation full of dead objects is collected very quickly. 充满死亡物体的年轻一代可以很快收集到。 Some survived objects are aged and eventually move to the old generation. 一些幸存的物体会老化,并最终移交给老一代。

What is the old generation? 什么是老一代?

The Old Generation is used to store long surviving objects. 老一代用于存储尚存的物体。 Typically, a threshold is set for young generation object and when that age is met, the object gets moved to the old generation. 通常,为年轻一代对象设置一个阈值,并且当达到该年龄时,该对象将移至老一代。 Eventually the old generation needs to be collected. 最终需要收集旧的一代。 This event is called a major garbage collection 此事件称为大型垃圾收集

What is the permanent generation? 什么是永久一代?

The Permanent generation contains metadata required by the JVM to describe the classes and methods used in the application. 永久生成包含JVM所需的元数据,用于描述应用程序中使用的类和方法。 The permanent generation is populated by the JVM at runtime based on classes in use by the application. 永久生成由JVM在运行时根据应用程序使用的类填充。

PermGen has been replaced with Metaspace since Java 8 release. 自Java 8发布以来,PermGen已被Metaspace取代。

PermSize & MaxPermSize parameters will be ignored now 现在将忽略PermSize和MaxPermSize参数

How does the three generations interact/relate to each other? 这三代人之间是如何相互作用/相互联系的?

Java堆术语:年轻一代,老一代和永久一代?

Image source & oracle technetwork tutorial article: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html 图像来源和Oracle TechNetwork教程文章: http : //www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html

" The General Garbage Collection Process " in above article explains the interactions between them with many diagrams. 上一篇文章中的“ 常规垃圾收集过程 ”通过许多图表说明了它们之间的交互。

Have a look at summary diagram: 看一下汇总图:

Java堆术语:年轻一代,老一代和永久一代?

相关文章: