Garbage-first collector

The Garbage-First Collector is a garbage collection algorithm introduced in the Oracle HotSpot Java virtual machine 6 and supported from 7 Update 4. It was planned to replace Concurrent mark sweep collector in JVM 7 and was made default in Java 9.

Garbage collector

Garbage-first collector is a server-style garbage collector, targeted for multiprocessors with large memories, that meets a soft real-time goal with high probability, while achieving high throughput. G1 preferentially collects regions with the least amount of live data, or "garbage first". G1 is the long term replacement of CMS. Whole-heap operations, such as global marking, are performed concurrently with the application threads, to prevent interruptions proportional to heap or live-data size. Concurrent marking provides both collection completeness and identifies regions ripe for reclamation via compacting evacuation. This evacuation is performed in parallel on multiprocessors, to decrease pause times and increase throughput.
G1 was first introduced as an experimental option in Java SE 6 Update 14, where it can be enabled with the following two command-line parameters:
-XX:+UnlockExperimentalVMOptions and -XX:+UseG1GC
With JDK 7, G1 was planned to replace CMS in the Hotspot JVM. There are two major differences between CMS and G1. The first is that 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. As well as compacting, G1 offers more predictable garbage collection pauses than the CMS collector and allows users to set their desired pause targets.
Proposals for Java 9 included making G1 the standard garbage collector, with Google counter proposing the well-known CMS as the standard, claiming the modified CMS it uses performs better than G1.
In Java 9 the G1 was made the default garbage collector.

Related products

Guaranteed real-time behavior even with garbage collection requires a real-time garbage collector such as those that come with Sun's Java RTS or IBM’s WebSphere RT.