Garbage Collection in Earlier versions
The major enhancements in Java 1.5 Garbage Collector (GC) has changed from the previous serial collector (-XX:+UseSerialGC) to a parallel collector (-XX:+UseParallelGC). You can override this default by using the -XX:+UseSerialGC command-line option to the java command. Enormous changes have made to the heap size.Before J2SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. Now it is increased and we can override this default maximum size of the heap using the -Xmx command-line option.
The implementation of certain policies for parallel collector has changed to consider three goals :-
- a desired maximum GC pause goal
- a desired application throughput goal
- minimum footprint
Garbage Collector in Java 1.5 was with some specific constraints to follow as strategies for an application to attain the above goals.
The Major Enhancements in Java 1.6 are
- Parallel Compaction Collector
- Concurrent Low Pause Collector: Concurrent Mark Sweep Collector Enhancements
- Ergonomics in the 6.0 Java Virtual Machine
It is a feature that enables the Garbage Collector to do collections in parallel leading to less garbage collection overhead and increase the performance for applications which require lager heaps. The platforms with more than two processors are best suited.
Previous to Java SE 6, while the young generation was collected in parallel, major collections were performed using a single thread. For applications with frequent major collections, this adversely affected scalability.
CMS collector improved to provide concurrent collection for System.gc() and Runtime.getRuntime().gc() method instructions.In Java SE 6, these instructions terminated all the threads to collect entire heap which lead to long pause times in applications with high heaps. This latest improved collector keeps the pause times shorter as how much as possible at the time of entire heap collection.
Concurrent marking job in CMS collector is done in parallel on platforms with more than two processors. This reduces the duration of concurrent marking cycle and makes the collector to support applications with huge number of threads and high object allocation rates.
In Java SE 5, platform-dependent default selections for the garbage collector, heap size, and runtime compiler were introduced to better match the needs of different types of applications while requiring less command-line tuning. New tuning flags were also introduced to allow users to specify a desired behavior which in turn enabled the garbage collector to dynamically tune the size of the heap to meet the specified behavior. In Java SE 6, the default selections have been further enhanced to improve application runtime performance and garbage collector efficiency.
Some other improvements include like increse in size of default younger generation size,Concurrent Mark Sweep Collector’s default Young Generation size,minimum young generation size ,proportion of the overall heap used for the young generation etc.
Java 1.6 Update 14
Major improvements on parallel compacting Garbage Collector are done to increase the performance of the Garbage Collection Process.
This version includes the initial preliminary version of the new Garbage First (G1) which served as a basis to the later versions of improved Garbage Collectors.
The Garbage-First Garbage Collector
The Garbage-First Garbage Collector (or G1 GC for short) is a new Garbage Collector that is being introduced in JDK 7. An begining version of G1 has also been released in Java SE 6 Update 14. G1 is mainly introduced to replce Concurrent Mark-Sweep GC.
Java 1.7 G1 Garbage Collector
In Java 1.7 might have a new garbage collection strategy by default. It is called G1, which is short for Garbage First. It has been experimentally launched in the Java 1.6 update 14 to replace the regular Concurrent Mark and Sweep Garbage Collectors with increased performance.
G1 is considered as “server centric” with following attributes.
- G1 uses parallelism which are mostly used in hardware today.The main advantage of G1 is designed in such a way to make use of all available CPU’s and utilize the processing power of all CPU’s and increase the performance and speed in Garbage Collection.
- Concurrency feature of G1 allows to run Java threads to minimize the heap operations at stop pauses.
- Next feature which plays a key role in increasing the Garbage Collection is treating the young objects(newly created) and the old objects(which lived for some time) differently.G1 mainly focuses on young objects as they can be reclaimable when traversing the old objects.
- Heap compaction is done to eliminate fragmentation problems.
- G1 can be more predictable when compared to CMS.
Features of G1 Garbage Collector
- A single contiguous heap which is split into same-sized regions. No separation between younger and older regions.
- G1 uses evacuation pauses.Evacuation pauses are done in parallel by using all the available processors.
- G1 uses a pause prediction model to meet user-defined pause time targets
- Like CMS,G1 also periodically performs a concurrent marking phase.
- Unlike CMS, G1 does not perform a concurrent sweeping phase.