Java heap terminology: young, old and permanent ge

2019-01-01 16:23发布

I'm trying to understand how the concepts of young, old and permanent generations in the Java heap terminology, and more specifically the interactions between the three generations.

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?

8条回答
不再属于我。
2楼-- · 2019-01-01 16:51

Although it is about tuning I can't resist recommend this document take a look at chapter 3 and go in depth if you like.

查看更多
姐姐魅力值爆表
3楼-- · 2019-01-01 16:54

Assuming you're talking about the Sun JDK/OpenJDK, see the page on the OpenJDK website on Storage Management. There are a couple of links to even more information at the bottom.

查看更多
皆成旧梦
4楼-- · 2019-01-01 16:55

Memory in SunHotSpot JVM is organized into three generations: young generation, old generation and permanent generation.

  • 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 i.e long lived objects house in old gen.
  • 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.

FYI: The permanent gen is not considered a part of the Java heap.

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. 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.

查看更多
素衣白纱
5楼-- · 2019-01-01 17:02

This article is a very good survey on garbage collectors. It defines the basic concepts and terminology of garbage collection and includes many explanatory drawings. It is a "must read" for anybody who is interested in how automatic memory allocation works; reading it will make it much easier for you to read and understand the various documents that others have pointed at.

(What that document lacks is any information about post-1993 research on garbage collectors, especially the whole business of multi-core systems. Still, you have to learn to walk before learning to run.)

查看更多
孤独寂梦人
6楼-- · 2019-01-01 17:05

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 surviving 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. The permanent generation is populated by the JVM at runtime based on classes in use by the application.

PermGen has been replaced with Metaspace since Java 8 release.

PermSize & MaxPermSize parameters will be ignored now

How does the three generations interact/relate to each other?

enter image description here

Image source & oracle technetwork tutorial article: 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:

enter image description here

查看更多
爱死公子算了
7楼-- · 2019-01-01 17:11

The Java virtual machine is organized into three generations: a young generation, an old generation, and a permanent generation. 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.

查看更多
登录 后发表回答