The java heap is divided into three main categories.
- Young generation
- Old generation
- Permanent generation
Young generation
The young generation comprises of eden space , survivor 1 and survivor 2. The Eden space of the young generation holds only the newly created objects. when this memory gets filled the garbage collectors clears all the unreferenced objects from the memory. The Objects which survived are moved to "From" survivor space (survivor 1). The survivor space is collection of young inter lived objects. The space has a "to" and "From". This is used by algorithms for clean up and faster switching. Once the Scavenge GC is complete the spaces are reversed, "to" becomes "from" and "from" becomes "to". The sizing of the young generation can be achieved by -Xmn option on the java command line.
Old generation
Old generation are for the objects which have survived the the number of scavenge GC cycles. The objects are promoted from the young generation to old generation. Object in this space are never garbage collected except in two cases either full garbage collection or in concurrent mark and sweep garbage collection. If the old generation is filled blocking the extension of the heap , an OutOfMemory occurs and the JVM will crash. The Old generation is sized with with -Xmn and -Xmx where -Xmn is the minimum amount of memory allocated at the startup and -Xmx is the maximum amount of memory that can be allocated.
Permanent generation
The permanent generation is the place where all the class files are kept. These are the compiled classes and JSP pages. When this space is full it triggers a full GC collection. OutOf Memory is thrown when this space cannot be extended. The permanent generation can be sized with -XX:PermSize and -XX:MaxPermSize parameters.
Note : The permanent generation is actually pinned on to the end of the Old Generation. It also has a small code cache of 50 MB for internal JVM memory management. This means that the total initial heap =-Xmx+-XX:PermSize+50 MB and the maximum total heap size = -Xmx+-XX:MaxPermSize+50 MB.
Garbage Collection Algorithms
There are various garbage collection algorithms such as Scavenge Garbage Collection, Full Garbage Collection, Parallel GC and Concurrent Mark and Sweep. Lets move on to more details how each one of the GC algorithms work.
coming soon...
No comments:
Post a Comment