RFR: 8365656: [ubsan] G1CSetCandidateGroup::liveness() reports division by 0 [v3]

Ivan Walulya iwalulya at openjdk.org
Fri Aug 22 11:17:51 UTC 2025


On Fri, 22 Aug 2025 11:05:58 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

>> src/hotspot/share/gc/g1/g1ConcurrentMark.cpp line 3125:
>> 
>>> 3123:                           group->length(),
>>> 3124:                           group->gc_efficiency(),
>>> 3125:                           group->length() > 0 ? group->liveness_percent() : 0.0f,
>> 
>> Why not move this logic into `liveness_percent()` (i.e returns 0.0f if length() == 0)?
>
> 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.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26888#discussion_r2293445720


More information about the hotspot-gc-dev mailing list