Tuesday, February 7, 2012

Java 7: Garbage First(G1) Collector

The Garbage-First Garbage Collector (or G1 GC for short) is a new GC that is being introduced in the Java HotSpot VM in JDK 7. In Java 7, Concurrent Mark-Sweep Collector (CMS) is replaced by G1 and enabled by default. It is a server-style collector, targeted at multi-processor machines with large amounts of memory that meets a soft real-time goal with high probability, while achieving high throughput.

This allow users to specify a soft real-time goal, stating their desire that collection consume no more than x ms of any y ms time slice. By making this goal explicit, the collector can try to keep collection pauses as small and infrequent as necessary for the application, but not so low as to decrease throughput or increase footprint unnecessarily.

There are two major differences between CMS and G1.

  • G1 is a compacting collector. G1 compacts sufficiently to completely avoid the use of fine-grain free lists for allocation, which considerably simplifies parts of the collector and mostly eliminates potential fragmentation issues.
  • G1 offers more predictable garbage collection pauses than the CMS collector and allows users to set their desired pause targets.

How Does G1 Work?

Please read Dr. Dobbs article which explains in detail the working of G1.

Further Reading about G1:

No comments: