RFR: 8358957: [ubsan]: The assert in layout_helper_boolean_diffbit() in klass.hpp needs UB to fail [v4]
Kim Barrett
kbarrett at openjdk.org
Tue Nov 4 04:29:12 UTC 2025
On Mon, 3 Nov 2025 09:29:28 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:
>
> comments and post-cond
src/hotspot/share/oops/klass.hpp line 514:
> 512: }
> 513:
> 514: // Find the right-most non-zero (e.g., ...1000) bit of the diff of array-of-boolean and array-of-byte layout helpers.
Callers don't care whether it's the rightmost bit, only that it's a single
bit. (Some callers use log2_exact to get the bit position.) So a more
pedantically correct description might be something like "Return a value
containing a single set bit that is in the bitset difference between the
layout helpers for array-of-boolean and array-of-byte."
src/hotspot/share/oops/klass.hpp line 525:
> 523: // So use alternate form of negation to avoid warning.
> 524: uint result = candidates & (~candidates + 1);
> 525: assert(((result - 1) & result) == 0, "post-condition");
Use `power_of_2(result)`. For completeness, also consider checking other post-conditions - result is set
in zlh and clear in blh.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27288#discussion_r2488596063
PR Review Comment: https://git.openjdk.org/jdk/pull/27288#discussion_r2488602736
More information about the hotspot-dev
mailing list