RFR: 8358957: [ubsan]: The assert in layout_helper_boolean_diffbit() in klass.hpp needs UB to fail [v5]

Johan Sjölen jsjolen at openjdk.org
Fri Nov 7 10:17:30 UTC 2025


On Thu, 6 Nov 2025 13:06:41 GMT, Afshin Zafari <azafari at openjdk.org> wrote:

>> Avoid using loop and UB in left-shift operation as suggested by Kim's comment in the JBS-issue.
>> 
>> Tests:
>>  mach5 tiers 1-5 {macosx-aarch64, linux-x64, windows-x64} x {debug, product}
>
> Afshin Zafari has updated the pull request incrementally with one additional commit since the last revision:
> 
>   review comments applied

Seems fine, and I did learn a new bit hack.

src/hotspot/share/oops/klass.hpp line 524:

> 522:     // Use well known bit hack to isolate the low bit of candidates.
> 523:     // The usual form is (x & -x), but VS warns (C4146) about unary minus of unsigned.
> 524:     // So use alternate form of negation to avoid warning.

"So explicitly use two's complement to avoid warning"

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

Marked as reviewed by jsjolen (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27288#pullrequestreview-3432805526
PR Review Comment: https://git.openjdk.org/jdk/pull/27288#discussion_r2502572890


More information about the hotspot-dev mailing list