From fb407aa2dbcdb39a5c4e23054c1ac295ae6e2391 Mon Sep 17 00:00:00 2001 From: Saranya Natarajan Date: Wed, 2 Apr 2025 13:44:13 +0000 Subject: [PATCH 1/5] JDK-8351660: C2: SIGFPE in unsigned_mod_value --- src/hotspot/share/opto/divnode.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hotspot/share/opto/divnode.cpp b/src/hotspot/share/opto/divnode.cpp index 90b5d7f9e27b0..5ff9a58d4862d 100644 --- a/src/hotspot/share/opto/divnode.cpp +++ b/src/hotspot/share/opto/divnode.cpp @@ -1319,6 +1319,11 @@ static const Type* unsigned_mod_value(PhaseGVN* phase, const Node* mod) { return TypeClass::ZERO; } + // Mod by zero? Throw exception at runtime! + if (type_divisor->is_con() && type_divisor->get_con() == 0) { + return TypeClass::POS; + } + const TypeClass* type_dividend = t1->cast(); if (type_dividend->is_con() && type_divisor->is_con()) { Unsigned dividend = static_cast(type_dividend->get_con()); From 3bce2b2eaa21e07c090e55a4271a5bc35d4964e4 Mon Sep 17 00:00:00 2001 From: Saranya Natarajan Date: Mon, 7 Apr 2025 12:24:58 +0000 Subject: [PATCH 2/5] added jtreg test --- .../TestUnsignedModByZero.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java diff --git a/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java b/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java new file mode 100644 index 0000000000000..1cda0280bb330 --- /dev/null +++ b/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8351660 + * @summary Test that modulo by zero throws exception at runtime in case of unsigned values. + * @library /test/lib + * @run main/othervm -Xbatch + * -XX:CompileCommand=compileonly,compiler.integerArithmetic.TestUnsignedModByZero::testInt + * -XX:CompileCommand=compileonly,compiler.integerArithmetic.TestUnsignedModByZero::testLong + * compiler.integerArithmetic.TestUnsignedModByZero + */ + + package compiler.integerArithmetic; + + import jdk.test.lib.Asserts; + + + public class TestUnsignedModByZero { + + public static Object testInt() { + double x = 1.0; + return Long.remainderUnsigned(1, (long)(x % x)); + } + + public static Object testLong() { + double x = 1.0; + return Long.remainderUnsigned(1, (long)(x % x)); + } + + public static void main(String[] args) { + for (int i =0; i < 10_000; i++) { + Asserts.assertThrows(ArithmeticException.class, TestUnsignedModByZero::testInt); + Asserts.assertThrows(ArithmeticException.class, TestUnsignedModByZero::testLong); + } + } + } \ No newline at end of file From 15bd99d9dbf7a18cb6a5ec54ee3b5de93adf41e7 Mon Sep 17 00:00:00 2001 From: Saranya Natarajan Date: Tue, 8 Apr 2025 22:31:09 +0000 Subject: [PATCH 3/5] correcting test --- .../jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java b/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java index 1cda0280bb330..cc2755b07e74b 100644 --- a/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java +++ b/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java @@ -41,7 +41,7 @@ public class TestUnsignedModByZero { public static Object testInt() { double x = 1.0; - return Long.remainderUnsigned(1, (long)(x % x)); + return Integer.remainderUnsigned(1, (int)(x % x)); } public static Object testLong() { From 667c7e7aa26ee42a5f019fd13ff024e9fd731b55 Mon Sep 17 00:00:00 2001 From: Saranya Natarajan Date: Wed, 9 Apr 2025 08:10:09 +0000 Subject: [PATCH 4/5] implementing reviewer comment --- src/hotspot/share/opto/divnode.cpp | 2 +- .../jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/opto/divnode.cpp b/src/hotspot/share/opto/divnode.cpp index 5ff9a58d4862d..1966cdf9462c6 100644 --- a/src/hotspot/share/opto/divnode.cpp +++ b/src/hotspot/share/opto/divnode.cpp @@ -1319,7 +1319,7 @@ static const Type* unsigned_mod_value(PhaseGVN* phase, const Node* mod) { return TypeClass::ZERO; } - // Mod by zero? Throw exception at runtime! + // Mod by zero? Throw an exception at runtime! if (type_divisor->is_con() && type_divisor->get_con() == 0) { return TypeClass::POS; } diff --git a/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java b/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java index cc2755b07e74b..639da55f2960d 100644 --- a/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java +++ b/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java @@ -50,7 +50,7 @@ public static Object testLong() { } public static void main(String[] args) { - for (int i =0; i < 10_000; i++) { + for (int i = 0; i < 10_000; i++) { Asserts.assertThrows(ArithmeticException.class, TestUnsignedModByZero::testInt); Asserts.assertThrows(ArithmeticException.class, TestUnsignedModByZero::testLong); } From 21623249d7e09116c54d9f6b81f3a819cab22a18 Mon Sep 17 00:00:00 2001 From: Saranya Natarajan Date: Wed, 9 Apr 2025 08:45:28 +0000 Subject: [PATCH 5/5] correcting comments in included test --- .../jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java b/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java index 639da55f2960d..27252cd53c733 100644 --- a/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java +++ b/test/hotspot/jtreg/compiler/integerArithmetic/TestUnsignedModByZero.java @@ -24,7 +24,7 @@ /* * @test * @bug 8351660 - * @summary Test that modulo by zero throws exception at runtime in case of unsigned values. + * @summary Test that modulo by zero throws an exception at runtime in case of unsigned values. * @library /test/lib * @run main/othervm -Xbatch * -XX:CompileCommand=compileonly,compiler.integerArithmetic.TestUnsignedModByZero::testInt