|
| 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 | + * @test |
| 26 | + * @key stress randomness |
| 27 | + * @bug 8274074 |
| 28 | + * @requires vm.compiler2.enabled |
| 29 | + * @summary Sinking a data node used as divisor of a DivI node into a zero check UCT loses its pin outside the loop due to |
| 30 | + * optimizing the CastII node away, resulting in a div by zero crash (SIGFPE) due to letting the DivI node floating |
| 31 | + * back inside the loop. |
| 32 | + * @run main/othervm -Xcomp -XX:CompileCommand=compileonly,compiler.loopopts.TestSinkingDivisorLostPin -XX:-TieredCompilation |
| 33 | + * -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:StressSeed=4177789702 compiler.loopopts.TestSinkingDivisorLostPin |
| 34 | + * @run main/othervm -Xcomp -XX:CompileCommand=compileonly,compiler.loopopts.TestSinkingDivisorLostPin -XX:-TieredCompilation |
| 35 | + * -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM compiler.loopopts.TestSinkingDivisorLostPin |
| 36 | + */ |
| 37 | + |
| 38 | +package compiler.loopopts; |
| 39 | + |
| 40 | +public class TestSinkingDivisorLostPin { |
| 41 | + static int iFld = 1; |
| 42 | + static int x = 1; |
| 43 | + static int q = 0; |
| 44 | + static int iArrFld[] = new int[100]; |
| 45 | + |
| 46 | + public static void main(String[] strArr) { |
| 47 | + test(); |
| 48 | + } |
| 49 | + |
| 50 | + static void test() { |
| 51 | + int y = 1; |
| 52 | + int i = 1; |
| 53 | + do { |
| 54 | + int j; |
| 55 | + for (j = 1; j < 88; j++) { |
| 56 | + iArrFld[1] = x; |
| 57 | + } |
| 58 | + try { |
| 59 | + y = iFld - q; // y = 1 - 0 |
| 60 | + y = (iArrFld[2] / y); // y = iArrFld[2] / 1 |
| 61 | + // Zero check Z1 with UCT |
| 62 | + // DivI node D on IfTrue path of zero check |
| 63 | + y = (5 / iFld); // y = 5 / 1 |
| 64 | + // Zero check Z2 with UCT |
| 65 | + // DivI node D is only used on IfFalse path of zero check Z2 into UCT (on IfTrue path, the result is not used anywhere |
| 66 | + // because we directly overwrite it again with "y = (5 / iFld)). The IfFalse path of the zero check, however, is never |
| 67 | + // taken because iFld = 1. But before applying the sinking algorithm, the DivI node D could be executed during the |
| 68 | + // loop, as the zero check Z1 succeeds. Only after sinking the SubI node for "iFld - q" into the IfFalse path of Z2 |
| 69 | + // and optimizing it accordingly (iFld is found to be zero because the zero check Z2 failed, i.e. iFld is zero which is |
| 70 | + // propagated into the CastII node whose type is improved to [0,0] and the node is replaced by constant zero), the |
| 71 | + // DivI node must NOT be executed inside the loop anymore. But the DivI node is executed in the loop because of losing |
| 72 | + // the CastII pin. The fix is to update the control input of the DivI node to the get_ctrl() input outside the loop |
| 73 | + // (IfFalse of zero check Z2). |
| 74 | + } catch (ArithmeticException a_e) { |
| 75 | + } |
| 76 | + |
| 77 | + iFld -= 8; |
| 78 | + if (y == 3) { |
| 79 | + } |
| 80 | + i++; |
| 81 | + } while (i < 10); |
| 82 | + } |
| 83 | + |
| 84 | +} |
| 85 | + |
0 commit comments