What are Java heap Young, Old and Permanent Generations?

The Java heap is dived into two parts i.e. Young generation and old generation.

Young generation

Young generation  memory is 40% of Maximum Java Heap. It consists of two parts, Eden space and Survivor Space.

Eden Space

Initially objects are created in this  Part of Java Heap , here most objects die and quickly are cleaned up by the minor Garbage Collectors (It only runs in young generation and its frequency is high in compared to major garbage collector). Usually any new objects created inside a Java Method go into Eden space and the objects space is reclaimed once the method execution completes. Whereas the Instance Variables of a Class usually lives longer until the Object based on that class gets destroyed. When Eden fills up it causes a minor collection, in which some surviving objects are moved to Survivor Space or an older generation. 

Survivor Space 

 The pool containing objects that have survived the garbage collection of the Eden space
The parameter Survivor Ratio can be used to tune the size of the survivor spaces.
-XX:Survivor Ratio=6 sets the ratio between each survivor space and Eden to be 1:6
If survivor spaces are too small copying collection overflows directly into the tenured generation.

Java heap Young, Old and Permanent Generations

Old Generation – Tenured

This pool contains objects that have existed for some time in the survivor space. And they may be long survived object and may be used overall during application runs

PermGen Space

PermGen is a non-heap memory area here the Class Loading happens and the JVM allocates spaces for classes, class meta data, , stores class level details, loading and unloading classes (e.g. JSPs), methods, String pool. java methods and the reference Objects here. The PermGen is independent from the Heap Area. you  can resiz it according to the requirement using -XX:MaxPermSize and -XX:PermSize  JVM Options. The Garbage collection happens in this area of JVM Memory as well. The Garbage collection in this area is called as “Class GC”. We can disable the Class Garbage Collection using the JVM Option -noclassgc. if  ”-noclassgc” Java Option is added while starting the Server.it also holds all the reflective data of the virtual machine itself, stores class level details, loading and unloading classes (e.g. JSPs), methods, String pool.


Post a Comment