/* * Copyright (c) 2026 IBM Corporation. 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 8380166 * @summary C2: crash in compiled code due to zero division because of widened CastII * * @run main/othervm -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:-BackgroundCompilation * ${test.main.class} * @run main ${test.main.class} * */ package compiler.integerArithmetic; public class TestZeroDivModWidenedCastII { private static int intField; private static long longField; private static volatile int volatileField; public static void main(String[] args) { for (int i = 0; i < 20_000; i++) { test1(0, 9, 1, true, false); test1(0, 9, 1, false, false); inlined1_2(9, 1, 1, true, 0); inlined1_3(0, 0); test2(0, 9, 1, true, false); test2(0, 9, 1, false, false); inlined2_2(9, 1, 1, true, 0); inlined2_3(0, 0); test3(0, 9, 1, true, false); test3(0, 9, 1, false, false); inlined3_2(9, 1, 1, true, 0); inlined3_3(0, 0); test4(0, 9, 1, true, false); test4(0, 9, 1, false, false); inlined4_2(9, 1, 1, true, 0); inlined4_3(0, 0); test5(0, 9, 1, true, false); test5(0, 9, 1, false, false); inlined5_2(9, 1, 1, true, 0); inlined5_3(0, 0); test6(0, 9, 1, true, false); test6(0, 9, 1, false, false); inlined6_2(9, 1, 1, true, 0); inlined6_3(0, 0); test7(0, 9, 1, true, false); test7(0, 9, 1, false, false); inlined7_2(9, 1, 1, true, 0); inlined7_3(0, 0); test8(0, 9, 1, true, false); test8(0, 9, 1, false, false); inlined8_2(9, 1, 1, true, 0); inlined8_3(0, 0); test9(0, 9, 1, true, false); test9(0, 9, 1, false, false); inlined9_2(9, 1, 1, true, 0); inlined9_3(0, 0); test10(0, 9, 1, false); inlined10_2(9, 1, 1, true, 0); inlined10_3(0, 0); test11(0, 9, 1, false); inlined11_2(9, 1, 1, true, 0); inlined11_3(0, 0); test12(0, 9, 1, false); inlined12_2(9, 1, 1, true, 0); inlined12_3(0, 0); test13(0, 9, 1, false); inlined13_2(9, 1, 1, true, 0); inlined13_3(0, 0); test14(0, 9, 1, false); inlined14_2(9, 1, 1, true, 0); inlined14_3(0, 0); test15(0, 9, 1, false); inlined15_2(9, 1, 1, true, 0); inlined15_3(0, 0); test16(0, 9, 1, false); inlined16_2(9, 1, 1, true, 0); inlined16_3(0, 0); test17(0, 9, 1, false); inlined17_2(9, 1, 1, true, 0); inlined17_3(0, 0); } } private static void test1(int k, int j, int flag, boolean flag2, boolean flag3) { int l = 0; for (; l < 10; l++); int m = inlined1_3(j, l); int i = inlined1(k, flag2); j = Integer.min(j, 9); int[] array = new int[10]; if (flag == 0) { throw new RuntimeException("never taken"); } if (flag2) { inlined1_2(j, flag, i, flag3, m); } else { inlined1_2(j, flag, i, flag3, m); } } private static int inlined1_3(int j, int l) { if (l == 10) { j = 1; } return j; } private static void inlined1_2(int j, int flag, int i, boolean flag3, int m) { if (flag3) { float[] newArray = new float[j + 1]; // j + 1 in [0..10] // RC i