- Young Generation
- Eden Space
- Survivor space
- Virtual space
- Tenured (Old) generation:
- Virtual Space
- Other Areas: Not a part of heap:
- PermGen Area
- Native Area
JVM Heap details (Image from Oracle(SUN) itself):
Young Space: Young space holds the newly created objects and can be tuned with the parameter -XX:NewRatio=<value>, for example, you set -XX:NewRatio=3 [ which means ratio of young:old generation=1:3 and since total heap=young+old=4. So you have set the young space as one fourth of the total Heap] . You can even decide the initial and max sizes of the young space with parameters NewSize and MaxNewSize
Eden Space: All the objects either created inside the methods or as class member variables are created in the Eden space. Space allocated to objects created inside the methods is reclaimed after the method execution is over. Some objects might live longer as reference pointing to them are class member variables. If the Eden space starts filling up then minor garbage collector runs and shifts the old objects to the Tenured Generation space so that space is available for creation of new objects in Eden space. Objects that might never move to tenured generation are
- Objects created inside the loops
- Objects created inside the methods
Survivor Ratio: it is the ratio of the Eden space to Survivor space in the Young space. This parameter can be controlled by property -XX:SurvivorRatio Suppose if the -XXSurvivorRatio=6, it means each survivor space is one eigth of the total Young space[total young space=2*1 (as there are 2 survivor spacee)+6]. If survivor space is too small to copy collections then survivor space will extend in the tenured area also.
Virtual Space-1: It is the difference between the parameters of young space i.e, MaxNewSize-NewSize (Young Space Max Size - Young space initially size)
Tenured Generation: It contains the objects which have survived minor collections and are aged enough to be in tenured area. Major GC runs in the tenured area [See Collection algos of GC for collection algorithms of GC].
Virtual Space-2: It is the difference between MaxHeapSize and IntialHeapSize(Virtual Space-2 = MaxHeapSize-IntialHeapSize)
PermGen(Permanent Generation) Area: It is the area where class loading and unloading happens. it stores metadata about classes , methods,etc. Please find the metadata term elaborated below:
- Constant pool information
- Array having references to methods
- Internal Objects (for exceptions, etc.)
- Information for compilers for optimization
- Methods of class
Native area is for the internal operations of the JVM. JVM uses this area to load libraries and for intermediate code generation. We cannot size the native area but other areas can be sized to control it. We can calculate the native area as below:
ProcessSize(Total memory allocated to Heap and other areas)-HeapSize-MaxPermSize
Collection Algorithms of GC (as per JVM 1.3, there are new additions as well):
- Copying or Scavange : It is very efficient and used only for minor collections in Eden space as it requires significant footprint.
- Mark-compact : it is slower than above technique. It does not require extra memory. It is used in major collections.
- Incremental or train : this collector is used only if -Xincgc is passed on the command line. This is significantly slower than Mark-Compact
Other Related articles on this blog:
JVM Memory Structure
References (Only which are worth reading :) ):