The check for the next cycle to be an initial mark should be after we decide if this is the last mixed GC cycle. E.g.
269.590: [G1Ergonomics (Concurrent Cycles) do not request concurrent cycle initiation, reason: still doing mixed collections, occupancy: 11257511936 bytes, allocation request: 0 bytes, threshold: 6442450900 bytes (50.00 %), source: end of GC]
269.590: [G1Ergonomics (Mixed GCs) do not continue mixed GCs, reason: reclaimable percentage not over threshold, candidate old regions: 384 regions, reclaimable: 643238328 bytes (4.99 %), threshold: 5.00 %]
, 0.1005750 secs]
The algo realized that the current cycle is a mixed GC, so it decided not to initiate a concurrent marking cycle for the next collection, but then algo after that realizes that this is going to be the last mixed GC, since we are below the threshold, so we loose the initiation of a concurrent cycle and then next cycle is a pure young. By then its too late e.g. at the end of this cycle we were at:
[Eden: 532.0M(532.0M)->0.0B(532.0M) Survivors: 80.0M->80.0M Heap: 10.9G(12.0G)->10.6G(12.0G)]
the next young brings us to -
[Eden: 532.0M(532.0M)->0.0B(532.0M) Survivors: 80.0M->80.0M Heap: 11.1G(12.0G)->11.1G(12.0G)]
and even though we start the concurrent cycle after this, we lose the race.
The question in this CR is whether it is useful to start initial mark during mixed GC or not to prevent going out of memory.