RFR: 8351660: C2: SIGFPE in unsigned_mod_value [v3]
Christian Hagedorn
chagedorn at openjdk.org
Wed Apr 9 05:49:32 UTC 2025
On Tue, 8 Apr 2025 22:37:34 GMT, Saranya Natarajan <duke at openjdk.org> wrote:
>> Description :: The test program performs a`Long.remainderUnsigned` which triggers the call to the function `unsigned_mod_value`. At the end of `unsigned_mod_value` the expression,` return TypeClass::make(static_cast<Signed>(dividend % divisor))`, is computed which leads to a SIGFPE as the divisor in the test program is zero. The same behaviour was observed when the ` Long.remainderUnsigned` was replaced with `Integer.remainderUnsigned` in the test program.
>>
>> Solution :: The fix for [JDK-8345766](https://bugs.openjdk.org/browse/JDK-8345766) emitted specific ModF/ModD nodes, which is optimized and converted to runtime calls after optimizations. This was done during parsing prior to [JDK-8345766](https://bugs.openjdk.org/browse/JDK-8345766). In the scenario where there was unsigned modulo operation as in this test, there was no check for modulo by zero that could trigger an exception during runtime. The below fix proposes a check for modulo by zero and throws exception at runtime.
>>
>> A Jtreg test has been added as part of this fix. This test case is based on the original test that resulted in the bug. @eme64 is the contributor of the original test. Thank you @eme64.
>
> Saranya Natarajan has updated the pull request incrementally with one additional commit since the last revision:
>
> correcting test
Looks good!
src/hotspot/share/opto/divnode.cpp line 1322:
> 1320: }
> 1321:
> 1322: // Mod by zero? Throw exception at runtime!
Suggestion:
// Mod by zero? Throw an exception at runtime!
test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java line 53:
> 51:
> 52: public static void main(String[] args) {
> 53: for (int i =0; i < 10_000; i++) {
Suggestion:
for (int i = 0; i < 10_000; i++) {
-------------
Marked as reviewed by chagedorn (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/24410#pullrequestreview-2752111076
PR Review Comment: https://git.openjdk.org/jdk/pull/24410#discussion_r2034489590
PR Review Comment: https://git.openjdk.org/jdk/pull/24410#discussion_r2034489938
More information about the hotspot-compiler-dev
mailing list