How to print, interpret and tune g1gc

g1gc logs - Ergonomics -how to print and how to understand

Introduction

Ever wondered how g1 decide which regions should be included in the collection set, when to trigger the concurrent marking cycle, or why stops mixed gc? You can get that information from -XX:+PrintAdaptiveSizePolicy

The 3rd line shows g1 can not add more old regions to CSet since the predicted time is already over the target pause time. However, g1 is requested to add minimum old regions (63) to CSet.

The 4th line shows that g1 added 63 old regions to meet the minimum requirement.

The last line indicates the next gc is mixed gc as well, since the reclaimable heap after this gc is 11.47%, higher then the threshold 10%.

Thresholds and Parameters:

We mentioned a lot of thresholds. Here we will explain what those thresholds are and how to control them. The numbers in <> is the default value.

-XX:MaxGCPauseMillis=<200>

In the gc log, we saw some entries like: "target pause time: 100.00 ms". This is controlled by MaxGCPauseMillis. This is a very important parameter as g1 adjusts heap generations sizes to meet this goal.

-XX:G1NewSizePercent=<5> -XX:G1MaxNewSizePercent=<60>

Sometimes we see that g1 does not push Eden size low enough to meet the gc pause goal, or does not have big Eden though still below the pause time goal. Please check if these 2 parameters are limiting the range of Eden that g1 can control ergonomically. G1NewSizePercent defines minimum percentage young gen over the heap size. G1MaxNewSizePercent defines maximum percentage young gen over the heap size.

We do not see this reflected in the gc log, but some times this could be important, when the heap is tight. This means if a region's live data is above this percentage, g1 will not consider it as a candidate for mixed gc. If the heap is tight, you can try to increase it. However, since there are more live data, collecting this region can be more expensive.