0

For the G1GC, I am trying to understand what the default value of G1HeapRegionSize argument is.

I see here that:

-XX:G1HeapRegionSize=n : Sets the size of a G1 region. The value will be a power of two and can range from 1 MB to 32 MB. The goal is to have around 2048 regions based on the minimum Java heap size.

But what is the value of n here?

Similar explanation is given here too.

Mooncrater
  • 4,146
  • 4
  • 33
  • 62
  • 2
    From the cited text “*The goal is to have around 2048 regions based on the minimum Java heap size.*” So, the default is not constant but depends on your actual minimum heap size. Consider the other cited statements “*The value will be a power of two*” and “*can range from 1 MB to 32 MB*” and you have everything you need to predict the value. – Holger May 25 '22 at 11:14
  • @Holger Gotchya - So basically it will try (heap size / 2048) and if it's less than 1 MB, then it will make the value of G1HeapRegionSize to 1 MB and so on – Mooncrater May 25 '22 at 11:38
  • 1
    …and rounded to a power of two. – Holger May 25 '22 at 12:01

1 Answers1

1

You can see default G1HeapRegionSize value using -XX:+PrintFlagsFinal

java -XX:+PrintFlagsFinal --version | grep -i G1HeapRegionSize

size_t G1HeapRegionSize = 1048576 {product} {ergonomic}

You can also specify unit using k,m,g... suffix. Otherwise bits is used. For example (Temurin 18 is being used)

java -XX:+PrintFlagsFinal -XX:G1HeapRegionSize=2m --version | grep -i G1HeapRegionSize

size_t G1HeapRegionSize = 2097152 {product} {command line}

G1 garbage collector partitions the heap into a set of equally sized heap regions. This parameter indicates the JVM the size of these regions. If you do not indicate this parameter to the JVM, it will use ergonomics and its magic.

More about G1 can be read here

Mooncrater
  • 4,146
  • 4
  • 33
  • 62
usuario
  • 2,132
  • 1
  • 10
  • 26