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

Thomas Schatzl tschatzl at openjdk.org
Mon Aug 25 10:34:11 UTC 2025


On Fri, 22 Aug 2025 12:22:24 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

>> 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.

I do not feel strongly about this, and I can see both sides. Changed it to do the check in the logging directly.

For simplicity I want to avoid a "n/a" or something, and in fact we recently changed it to just return 0.

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

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


More information about the hotspot-gc-dev mailing list