RFR: 8356865: C2: Unreasonable values for debug flag FastAllocateSizeLimit can lead to left-shift-overflow, which is UB [v3]
Benoît Maillard
bmaillard at openjdk.org
Fri Jun 20 16:43:27 UTC 2025
On Wed, 18 Jun 2025 19:42:07 GMT, Evgeny Astigeevich <eastigeevich at openjdk.org> wrote:
>> Thanks for the comments!
>>
>> I added the assert because the issue in the JBS mentioned a specific case where we ended up with negative values.
>>
>> Should I leave it like this, or rather convert it to a more specific check (ie. making sure that the `LogBytesPerLong - log2_esize` most significant bits are not used **before** shifting)?
>
> IMO your assert is obfuscating the overflow problem.
> I think the assert should be before doing the shift.
> It can be like:
>
> assert((fast_size_limit == 0) || (count_leading_zeros(fast_size_limit) > (LogBytesPerLong - log2_esize), "fast_size_limit (%d) overflow when shifted left by %d", fast_size_limit, (LogBytesPerLong - log2_esize));
Thanks for the tip, I made the requested changes!
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25834#discussion_r2159359020
More information about the hotspot-dev
mailing list