Search code examples
javajvmg1gc

What is the default value of G1HeapRegionSize?


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.


Solution

  • 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