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?
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.
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.
Memory in SunHotSpot JVM is organized into three generations: young generation, old generation and permanent generation.
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.
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.)
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.
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
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
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:
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.