Thursday, February 26, 2015

Garbage collections as per Admin point of view!!!!!

GC topic is more precise topic as administrators we need to know basic information on this topic. So i am trying to give simple way to know what is garbage collection and how many types and all info here.

Garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. An in use object, or a referenced object, means that some part of your program still maintains a pointer to that object. An unused object, or unreferenced object, is no longer referenced by any part of your program. So the memory used by an unreferenced object can be reclaimed.


 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.

If survivor spaces are too small copying collection overflows directly into the tenured generation.


  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



Different types of Garbage collectors is:

 

1. Serial GC:


a serial collector is a default copying collector which uses only one GC thread for the GC operation - See more at: http://www.tikalk.com/java/garbage-collection-serial-vs-parallel-vs-concurrent-mark-sweep/#sthash.aIh4SoS8.dpuf
 A serial collector is a default copying collector which uses only one GC thread for the GC operation.
That means , it’s mainly designed for single-threaded environments (e.g. 32 bit or Windows) and for small heaps. This collector freezes all application threads whenever it’s working, which disqualifies it for all intents and purposes from being used in a server environment.

you can use like this: -XX:+UseSerialGC

2. Parallel GC:


JVM’s default collector. Much like its name, its biggest advantage is that is uses multiple threads to scan through and compact the heap. The downside to the parallel collector is that it will stop application threads when performing either a minor or full GC collection. The parallel collector is best suited for apps that can tolerate application pauses and are trying to optimize for lower CPU overhead caused by the collector.
 -XX:+UseParallelGC
-XX:+UseParNewGC

 

3: CMS GC:


CMS collector (“concurrent-mark-sweep”). This algorithm uses multiple threads (“concurrent”) to scan through the heap (“mark”) for unused objects that can be recycled (“sweep”). This algorithm will enter “stop the world” (STW) mode in two cases: when initializing the initial marking of roots (objects in the old generation that are reachable from thread entry points or static variables) and when the application has changed the state of the heap while the algorithm was running concurrently, forcing it to go back and do some final touches to make sure it has the right objects marked.

-XX:+UseConcMarkSweepGC
-XX:+UseConcMarkSweepGC
-XX:+UseParallelGC
-XX:+UseParNewGC
-XX:+UseParallelGC
-XX:+UseParNewGC
 
a serial collector is a default copying collector which uses only one GC thread for the GC operation - See more at: http://www.tikalk.com/java/garbage-collection-serial-vs-parallel-vs-concurrent-mark-sweep/#sthash.aIh4SoS8.dpuf
a serial collector is a default copying collector which uses only one GC thread for the GC operation - See more at: http://www.tikalk.com/java/garbage-collection-serial-vs-parallel-vs-concurrent-mark-sweep/#sthash.aIh4SoS8.dpuf