RFR: 8365656: [ubsan] G1CSetCandidateGroup::liveness() reports division by 0 [v3]
Albert Mingkun Yang
ayang at openjdk.org
Fri Aug 22 12:24:50 UTC 2025
On Fri, 22 Aug 2025 11:15:16 GMT, Ivan Walulya <iwalulya at openjdk.org> wrote:
>> I actually think the zero-length checking should be done at the caller -- it's meaningless to ask `liveness_percent` on a zero-length group. Looking at neighboring code, does `gc_efficiency` have a sensible meaning for a zero-length group? Callees should have non-zero-length as precondition.
>>
>> Therefore, I suggest reorder the print a bit so that length-sensitive queries comes after `group->length()`, sth like:
>>
>>
>> type
>> group->card_set()->mem_size(),
>> group->length(),
>> group->length() > 0 ? group->gc_efficiency(), 0,
>> group->length() > 0 ? group->liveness_percent(), 0);
>
> I disagree, why should the caller know that the public method is subject to crashes if called with length() == 0? Eventually, one will use `liveness_percent()` without this guard.
Because this method doesn't have a sensible meaning for zero-length groups. Here we are printing `0` as a pragmatic solution, but maybe `N/A` can be more pedantic in this context.
In other contexts, I think it's beneficial to catch such misuse, hence the suggestion of precondition.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26888#discussion_r2293582612
More information about the hotspot-gc-dev
mailing list