1 /*
2  * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 /*
26  * @test
27  * @key stress
28  * @bug 8259227
29  * @summary Verify that zero check is executed before division/modulo operation.
30  * @requires vm.compiler2.enabled
31  * @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileOnly=compiler/loopopts/TestDivZeroDominatedBy::test
32  *                   -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM compiler.loopopts.TestDivZeroDominatedBy
33  * @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileOnly=compiler/loopopts/TestDivZeroDominatedBy::test
34  *                   -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM compiler.loopopts.TestDivZeroDominatedBy
35  */
36 
37 package compiler.loopopts;
38 
39 public class TestDivZeroDominatedBy {
40 
41     public static int iFld = 1;
42     public static int iFld1 = 2;
43     public static int iFld2 = 3;
44     public static int iArrFld[] = new int[10];
45     public static double dFld = 1.0;
46 
test()47     public static void test() {
48         int x = 1;
49         int y = 2;
50         int z = 3;
51 
52         iFld = y;
53         iArrFld[5] += iFld1;
54         int i = 1;
55         do {
56             for (int j = 0; j < 10; j++) {
57                 iFld2 += iFld2;
58                 iFld1 = iFld2;
59                 int k = 1;
60                 do {
61                     iArrFld[k] = y;
62                     z = iFld2;
63                     dFld = x;
64                     try {
65                         y = iArrFld[k];
66                         iArrFld[8] = 5;
67                         iFld = (100 / z);
68                     } catch (ArithmeticException a_e) {}
69                 } while (++k < 2);
70             }
71         } while (++i < 10);
72     }
73 
main(String[] strArr)74     public static void main(String[] strArr) {
75         test();
76     }
77 }
78 
79