Updating the g1

Further, suppose that the fragmented old generation has insufficient space for the newly promoted objects.Such conditions would trigger a full garbage collection cycle, which will perform compaction of the heap.With CMS GC, the full collection is serial and STW, hence your application threads are stopped for the entire duration while the heap space is reclaimed and then compacted.

The basic idea with G1 GC is to set your heap ranges (using and then let the GC do its job.

With the introduction of G1 GC, Hot Spot moves away from its conventional GC layout where a contiguous Java heap splits into (contiguous) young and old generations.

In G1 GC, Hot Spot introduces the concept of “regions”.

Many articles describe how a poorly tuned garbage collector can bring an application's Service Level Agreement (SLA) commitments to its knees.

For example, an unpredictably protracted garbage collection pause can easily exceed the response-time requirements of an otherwise performant application.

Moreover, the irregularity increases when you have a non-compacting Garbage Collector (GC) such as Concurrent Mark and Sweep (CMS) that tries to reclaim its fragmented heap with a serial (single-threaded) full garbage collection that is stop-the-world (STW).

Let us now expand on the above paragraph: Suppose an allocation failure in the young generation triggers a young collection, leading to promotions to the old generation.

Alternatively, even if you do have parallel (multi-threaded) compaction to combat fragmentation, you still end up with a full garbage collection (that involves all the generations of the Java heap), when it might have been sufficient to just reclaim some of the free space from the old generation. With Parallel Old, the reclamation of old generation is with a parallel STW full garbage collection pause.

This full garbage collection is not incremental; it is one big STW pause and does not interleave with the application execution. With the above information, we would like to consider one solution in the form of the "Garbage First” (G1) collector, Hot Spot's latest GC (introduced in JDK7 update 4).

G1 GC is an incremental parallel compacting GC that provides more predictable pause times compared to CMS GC and Parallel Old GC.

By introducing a parallel, concurrent and multi-phased marking cycle, G1 GC can work with much larger heaps while providing reasonable worst-case pause times.