RFR: 8356865: C2: Unreasonable values for debug flag FastAllocateSizeLimit can lead to left-shift-overflow, which is UB [v2]
Benoît Maillard
bmaillard at openjdk.org
Wed Jun 18 07:38:33 UTC 2025
On Tue, 17 Jun 2025 17:04:25 GMT, Dean Long <dlong at openjdk.org> wrote:
>> src/hotspot/share/opto/graphKit.cpp line 3807:
>>
>>> 3805: int log2_esize = Klass::layout_helper_log2_element_size(layout_con);
>>> 3806: fast_size_limit <<= (LogBytesPerLong - log2_esize);
>>> 3807: assert (fast_size_limit > 0, "increasing the size limit should not produce negative values");
>>
>> Prior C++14 left shit producing a negative value is undefined behavior: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2161.pdf
>>
>> Do we compile c++ source specifying the C++ standard?
>
> Yes we use -std=c++14, but creating a negative value in this way still feels like a kind of overflow to me.
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)?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25834#discussion_r2153869915
More information about the hotspot-dev
mailing list