Java Reference

In-Depth Information

G1 region sizes

G1 divides the heap into a number of regions, each of which has a fixed size. The region size

is not dynamic; it is determined at startup based on the minimum size of the heap (the value

of
Xms
). The minimum region size is 1 MB. If the minimum heap size is greater than 2 GB,

the size of the regions will be set according to this formula (using log base 2):

region_size = 1 << log(Initial Heap Size / 2048);

In short, the region size is the smallest power of 2 such that there are close to 2,048 regions

when the initial heap size is divided. There are some minimum and maximum constraints in

use here too; the region size is always at least 1 MB and never more than 32 MB.
Table 6-3

sorts out all the possibilities.

Table 6-3. Default G1 region sizes

Heap size

Default G1 region size

Less than 4 GB

1 MB

Between 4 GB and 8 GB

2 MB

Between 8 GB and 16 GB 4 MB

Between 16 GB and 32 GB 8 MB

Between 32 GB and 64 GB 16 MB

Larger than 64 GB

32 MB

The size of a G1 region can be set with the
-XX:G1HeapRegionSize=
N
flag (the default for

which is nominally 0, meaning to use the dynamic value just described). The value given

here should be a power of 2 (e.g., 1 MB or 2 MB); otherwise it is rounded down to the

nearest power of 2.