RFR: 8377990: Zero: Replace Java math ops with UB-safe implementations
Aleksey Shipilev
shade at openjdk.org
Wed Feb 18 13:33:04 UTC 2026
On Mon, 16 Feb 2026 12:37:16 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
> For Valhalla enablement reasons, I have been hunting Zero bugs. Noticed that Zero fails with UBSan enabled, mostly when doing Java math and running into C++ UBs around signed math overflows:
>
>
> $ CONF=linux-x86_64-zero-fastdebug make images
> Building target 'images' in configuration 'linux-x86_64-zero-fastdebug'
> ...
> /home/shade/trunks/jdk/src/hotspot/cpu/zero/bytecodeInterpreter_zero.inline.hpp:119:11: runtime error:
> negation of -9223372036854775808 cannot be represented in type 'long int';
> cast to an unsigned type to negate this value to itself
>
>
> Luckily, we already have the whole group of `java_*` methods that are there for the purpose we need in Zero: emulate Java math without running into C++ UB. Fixing these issues seems to resolve some of the hair-pulling bugs I have been chasing.
>
> I had to also cover the float-division-by-zero rule for FP divisions. For reasons, it is not under `undefined` umbrella that our current `ATTRIBUTE_NO_UBSAN` does: it is a runtime check that UBSan does in addition to other things. [JDK-8355979](https://bugs.openjdk.org/browse/JDK-8355979) extended it for Clang -- AFAICS, to fix only the paths folks seen failing -- but now we have the case for GCC as well.
>
> Additional testing:
> - [x] Linux x86_64 zero fastdebug, `make images` (invokes quite a bit of Zero code, now passes with UBSan enabled)
> - [x] Linux x86_64 zero fastdebug, `make bootcycle-images` (now passes with UBSan enabled)
Thanks! I think I need a second Reviewer before integrating. Who is interested in Zero these days, @adinn, maybe?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29743#issuecomment-3920848168
More information about the hotspot-dev
mailing list