Firstly,I think you may have misunderstood the effect of G1MixedGCLiveThresholdPercent
(the default value is 65% in Jdk7 and 85% in Jdk 11).
G1MixedGCLiveThresholdPercent
is not the space ratio of garbage objects, but the space ratio of live objects. If the space of live objects in a region exceeds 85% (in jdk11), then the region will not be selected into the
collection set
(region collection to be recycled)
Secondly,G1HeapWastePercent
(the default value is 10% in Jdk7 and 5% in Jdk11)
is a condition for triggering Mixed GC and exiting Mixed GC.
When the garbage objects in the collection set
account for more than 5% (in jdk11) of the total heap allocated space,
the Mixed GC will be triggered, and one of the sufficient conditions for exiting the Mixed GC That is
the garbage object rate in the collection set
is lower than 5%.
Therefore, if G1HeapWastePercent
is set to 0%, as long as there are garbage objects in the collection set, Mixed GC will be triggered.
Then the sufficient condition for exiting Mixed GC will become that the collection set
is empty,
Because every Mixed GC will remove the reclaimed region from the collection set
.
Finally, I want to explain to you the execution process of G1 GC, so that you can better understand the whole process.
G1 contains 3 phases, concurrent marking
, Only Young GC
, and Mixed GC
. The general process is as follows:
- At the end of
Only Young GC
, it will be judged whether it is necessary to start concurrent marking
- After the
concurrent marking
is finish, the space occupied by live objects and garbage objects in each region (old generation) will be calculated.
- Then the
collection set
(old region collection to be recycled) is generated, and only the old generation regions whose size of surviving objects account for the total size of the region exceeds G1MixedGCLiveThresholdPercent will enter the collection set
.
- After that, sort the
collection set
, with the highest _gc_efficiency
ranking first.
- If
reclaimable_percent
of collection set
exceeds G1HeapWastePercent
%, then Mixed GC
will be triggered later.
Mixed GC
will select all young regions and old_region_length
of old regions are reclaimed.
- At the end of Mixed GC execution, if
reclaimable_percent
still exceeds G1HeapWastePercent
%, then Mixed GC
will be executed again later.
Let me explain several parameters and concepts mentioned below:
G1MixedGCLiveThresholdPercent
- The default value in openjdk11 is 85, G1MixedGCLiveThresholdPercent
- The relevant use location is mixed_gc_live_threshold_bytes, which is used to calculate the threshold of the survival rate of objects in a single region. Regions that exceed this threshold will not enter the
collection set
.
_gc_efficiency
- The recycling value of a single region
- _gc_efficiency =
the size of garbage objects in a single region
/ the time it takes to transfer this region
- If there are more garbage objects in the region and the less time it takes to transfer, the _gc_efficiency will higher.
G1HeapWastePercent
- The default value in openjdk11 is 5, G1HeapWastePercent
- The related code next_gc_should_be_mixed is used to determine whether the next GC is
Mixed GC
.
reclaimable_percent
- reclaimable_percent =
garbage object size
/ total space size
- The garbage object here refers to the total size of garbage objects in the
collection set
G1MixedGCCountTarget
- The default value in openjdk11 is 8, G1MixedGCCountTarget
- Indicates that once Mixed GC is triggered, Expect to execute 8 Mixed GC.
G1OldCSetRegionThresholdPercent
- The default value in openjdk11 is 10, G1OldCSetRegionThresholdPercent
- Every time Mixed GC, the selected old_region_length has a maximum value
- The maximum value =
the number of allocated regions in heap
* 10 / 100
old_region_length
- This value means that this
Mixed GC
selects old_region_length
of Old Regions in collecion set
for recycling
- The lower limit of this value is
min_old_cset_length
, and the upper limit is max_old_cset_length
min_old_cset_length
= the size of collection set / G1MixedGCCountTarget
.
max_old_cset_length
= the number of allocated regions in heap * G1OldCSetRegionThresholdPercent / 100
- Because G1 will strictly control each
GC Pause Time
, so the final old_region_length is constrained by the gc pause time. But Mixed GC will put as many regions in collecion set
as possible into old_region_length
, until the total time it takes to reclaim these regions is close to the estimated GC Pause Time
.