7.15.5 Relationship between memory space and region
G1 GC divides the Java heap area into a New area which stores objects with a short lifespan, and a Tenured area which stores objects with a long lifespan. The New area is further divided into an Eden area for objects that were just created by the new operator, and a Survivor area for objects that have survived GC at least once. Objects that have undergone GC in the New area a certain number of times are determined to have a long lifespan and transferred to the Tenured area.
The following figure shows an overview of the memory spaces managed by G1 GC while an application is running. The Eden area, Survivor area, Tenured area, and Free area are collectively called the Java heap area.
|
|
G1 GC does not allocate a Tenured area from the start. When the time comes to move an object to the Tenured area, G1 GC moves the object after allocating a region of the Free area to the Tenured area. G1 GC also expands or shrinks the New area after GC (hereinafter called resizing). When resizing entails expanding the New area, G1 GC allocates a region of the Free area to the New area. When resizing entails shrinking the New area, G1 GC recovers a region of the New area and allocates it to the Free area. When an object is created that is large in size, that object is stored in the Humongous area.
The following explains how each area is used:
-
New area
An area that stores objects with a short lifespan. The New area consists of the Eden are and the Survivor area. The New area is resized after GC to prepare for the next time GC occurs. For details, see 7.15.8 Young GC.
-
Eden area
An area in which objects are stored first when created.
-
Survivor area
An area that stores the objects in the New area that were not collected when GC was executed. The Survivor area consists of a From space and a To space. The From space and the To space are the same size.
-
Tenured area
An area that stores objects with a long lifespan. Objects that have survived GC in the Survivor area a certain number of times are transferred to the Tenured area.
-
Humongous area
A part of the Tenured area that stores large objects. Objects in the Humongous are collected by Full GC or Concurrent Cleanup. For details about Concurrent Cleanup, see 7.15.9 Concurrent Marking (CM).
-
Free area
An area that is not allocated to the New area or the Tenured area. The Free area is allocated to the New area or the Tenured area when the region of the Tenured area is too small and when resizing the New area after GC.
-
Metaspace area
An area that stores the loaded class information. Note that the Metaspace area is not managed at the region level. Objects in the Metaspace area are collected by Full GC only.
Figure 7-22 shows the areas of the Java heap area to be contiguous, but the areas are not necessarily contiguous in practice. G1 GC manages the Java heap area as blocks called regions, which are allocated in a distributed way as shown in the following figure.
|
|
Each region is represented by the name of the area followed by the word region. For example, a region of the Eden area is called an Eden region, and a region of the New area is called a New region.