RFR: 8377990: Zero: Replace Java math ops with UB-safe implementations
Aleksey Shipilev
shade at openjdk.org
Mon Feb 16 17:14:15 UTC 2026
For Valhalla enablement reasons, I have been hunting Zero bugs. Noticed that Zero fails with UBSan enabled, mostly when doing Java math and running in 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) did 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` (passes with UBSan enabled)
-------------
Commit messages:
- Still check for toolchains
- Fix
Changes: https://git.openjdk.org/jdk/pull/29743/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29743&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8377990
Stats: 23 lines in 2 files changed: 4 ins; 4 del; 15 mod
Patch: https://git.openjdk.org/jdk/pull/29743.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/29743/head:pull/29743
PR: https://git.openjdk.org/jdk/pull/29743
More information about the hotspot-dev
mailing list