|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, 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 | + * @bug 8297951 |
| 27 | + * @summary Test that crashes because we do not emit skeleton predicates for normal If nodes for which a range check |
| 28 | + * predicate is created in loop predication. |
| 29 | + * @requires vm.debug == true & vm.compiler2.enabled |
| 30 | + * @run main/othervm -XX:-TieredCompilation -Xbatch -XX:-RangeCheckElimination -XX:+BailoutToInterpreterForThrows |
| 31 | + compiler.loopopts.TestMissingSkeletonPredicateForIfNode |
| 32 | + */ |
| 33 | +package compiler.loopopts; |
| 34 | + |
| 35 | +public class TestMissingSkeletonPredicateForIfNode { |
| 36 | + static int iFld = 2, x; |
| 37 | + static short limit = 10; |
| 38 | + |
| 39 | + public static void main(String[] args) throws Exception { |
| 40 | + for (int i = 0; i < 5000; i++) { |
| 41 | + try { |
| 42 | + test(i % 2 == 0, i % 3); |
| 43 | + } catch (Exception e) { |
| 44 | + // Expected |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + public static void test(boolean flag, int arg) throws Exception { |
| 50 | + int sum = 1; |
| 51 | + int[] iArr2 = new int[4]; |
| 52 | + RuntimeException r = new RuntimeException(); |
| 53 | + |
| 54 | + for (int i = 0; i < limit; i+=2) { // Pre/main/post + Unrolled once. This results in the following type for the iv phi i: [2..SHORT_MAX] |
| 55 | + x = 5 / sum; |
| 56 | + if (Integer.compareUnsigned(i, iArr2.length) < 0) { // (**) Loop predication creates a RC predicate for this check |
| 57 | + // After unrolling, we have: |
| 58 | + // |
| 59 | + // iArr2[i] |
| 60 | + // iArr2[i+2] |
| 61 | + // |
| 62 | + // The type of iArr2[i+2] is [4..SHORT_MAX+2] (we need limit to be short such that we do not have an integer overflow |
| 63 | + // which would set the type to int). However, the type of the CastII node for the index i+2 is [0..3] because its size |
| 64 | + // is only 4. Since the type of i+2 is outside the range of the CastII node, the CastII node is replaced by top and |
| 65 | + // some of the data nodes and memory nodes die. We are left with a broken graph and later assert because of that. |
| 66 | + iFld += iArr2[i]; // RangeCheck node is removed because it shares the same bool as the If (**). |
| 67 | + sum += iFld; |
| 68 | + } else { |
| 69 | + // Emits an UCT with -XX:+BailoutToInterpreterForThrows and therefore the If (**) satisfies the condition of being a |
| 70 | + // range check if with one of its blocks being an UCT. |
| 71 | + throw r; |
| 72 | + } |
| 73 | + if (i > 50) { |
| 74 | + break; |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments