The code that sets / calculates G1's young list target length has many
inconsistencies and mistakes. The include:
a) There are two entry points:
* calculate_young_list_target_length(), for use when ergonomics are or
are not enabled.
* calculate_young_list_target_length(size_t rs_lengths), for use when
ergonomics are enabled and the calculation needs to be revised due
to RS lengts being measured to be longer than the last prediction.
Unfortunately, the latter does not seem to recalculate several values
including the max GC locker expansion and the max survivor region
number, both of which are based on the calculated target length.
b) There is no obvious place to bound the final young target length
with a desired min and/or max length, given that it's done differently
(and in a way: redundantly) for the two entry points described in a).
c) The max survivor region number calculation is done with an integer
division and it is not taking into account the fact that the resulting
value could be between 0.0 and 1.0. This meant that, in some cases,
the max survivor number is set to 0.
d) The code the calculates the optimal young list length target using
a binary search is incorrect and exits earlier than it should without
finding an optimal result. The reason for this is that it is written
in a way that it keeps halving the distance between min and max length
by decreasing max length, until it finds a length that fits into the
pause time target. But it then stops, instead of attempting to
increase max length (while still halving the distance between min and
max length). This means that, even though the result fits into the
pause time target, it is not optimal and there are longer lengths that
will also fit into the pause time target.