Garbage First Overview
Performance consultants and engineers introduce the Garbage First (or G1) garbage collector (GC) along with a historical perspective on the garbage collectors in the Java HotSpot Virtual Machine (VM) and the reasoning behind G1’s inclusion in HotSpot.
This chapter is an introduction to the Garbage First (or G1) garbage collector (GC) along with a historical perspective on the garbage collectors in the Java HotSpot Virtual Machine (VM), hereafter called just HotSpot, and the reasoning behind G1’s inclusion in HotSpot. The reader is assumed to be familiar with basic garbage collection concepts such as young generation, old generation, and compaction. Chapter 3, “JVM Overview,” of the book Java™ Performance [1] is a good source for learning more about these concepts.
Serial GC was the first garbage collector introduced in HotSpot in 1999 as part of Java Development Kit (JDK) 1.3.1. The Parallel and Concurrent Mark Sweep collectors were introduced in 2002 as part of JDK 1.4.2. These three collectors roughly correspond to the three most important GC use cases: “minimize memory footprint and concurrent overhead,” “maximize application throughput,” and “minimize GC-related pause times.” One might ask, “Why do we need a new collector such as G1?” Before answering, let’s clarify some terminology that is often used when comparing and contrasting garbage collectors. We’ll then move on to a brief overview of the four HotSpot garbage collectors, including G1, and identify how G1 differs from the others.
Terminology
In this section, we define the terms parallel, stop-the-world, and concurrent. The term parallel means a multithreaded garbage collection operation. When a GC event activity is described as parallel, multiple threads are used to perform it. When a garbage collector is described as parallel, it uses multiple threads to perform garbage collection. In the case of the HotSpot garbage collectors, almost all multithreaded GC operations are handled by internal Java VM (JVM) threads. One major exception to this is the G1 garbage collector, in which some background GC work can be taken on by the application threads. For more detail see Chapter 2, “Garbage First Garbage Collector in Depth,” and Chapter 3, “Garbage First Garbage Collector Performance Tuning.”
The term stop-the-world means that all Java application threads are stopped during a GC event. A stop-the-world garbage collector is one that stops all Java application threads when it performs a garbage collection. A GC phase or event may be described as stop-the-world, which means that during that particular GC phase or event all Java application threads are stopped.
The term concurrent means that garbage collection activity is occurring at the same time as the Java application is executing. A concurrent GC phase or event means that the GC phase or event executes at the same time as the application.
A garbage collector may be described by any one or a combination of these three terms. For example, a parallel concurrent collector is multithreaded (the parallel part) and also executes at the same time as the application (the concurrent part).