|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, Red Hat, Inc. 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 8245714 |
| 27 | + * @requires vm.compiler2.enabled |
| 28 | + * @summary "Bad graph detected in build_loop_late" when loads are pinned on loop limit check uncommon branch |
| 29 | + * |
| 30 | + * @run main/othervm -XX:-BackgroundCompilation -XX:ArrayCopyLoadStoreMaxElem=0 TestBadControlLoopLimitCheck |
| 31 | + */ |
| 32 | + |
| 33 | +public class TestBadControlLoopLimitCheck { |
| 34 | + public static void main(String[] args) { |
| 35 | + int[] int_array = {0, 0}; |
| 36 | + A[] obj_array = {new A(), new A()}; |
| 37 | + for (int i = 0; i < 20_000; i++) { |
| 38 | + test1(int_array, 0, 10, false); |
| 39 | + test_helper(42); |
| 40 | + test2(obj_array, 0, 10, false); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + private static int test1(int[] a, int start, int stop, boolean flag) { |
| 45 | + int[] b = new int[2]; // non escaping allocation |
| 46 | + System.arraycopy(a, 0, b, 0, 2); // optimized out |
| 47 | + int v = 1; |
| 48 | + int j = 0; |
| 49 | + for (; j < 10; j++); |
| 50 | + int inc = test_helper(j); // delay transformation to counted loop |
| 51 | + // loop limit check here has loads pinned on unc branch |
| 52 | + for (int i = start; i < stop; i += inc) { |
| 53 | + v *= 2; |
| 54 | + } |
| 55 | + if (flag) { |
| 56 | + v += b[0] + b[1]; |
| 57 | + } |
| 58 | + return v; |
| 59 | + } |
| 60 | + |
| 61 | + private static int test2(A[] a, int start, int stop, boolean flag) { |
| 62 | + A[] b = new A[2]; // non escaping allocation |
| 63 | + System.arraycopy(a, 0, b, 0, 2); // optimized out |
| 64 | + int v = 1; |
| 65 | + int j = 0; |
| 66 | + for (; j < 10; j++); |
| 67 | + int inc = test_helper(j); // delay transformation to counted loop |
| 68 | + // loop limit check here has loads pinned on unc branch |
| 69 | + for (int i = start; i < stop; i += inc) { |
| 70 | + v *= 2; |
| 71 | + } |
| 72 | + if (flag) { |
| 73 | + v += b[0].f + b[1].f; |
| 74 | + } |
| 75 | + return v; |
| 76 | + } |
| 77 | + |
| 78 | + static class A { |
| 79 | + int f; |
| 80 | + } |
| 81 | + |
| 82 | + static int test_helper(int j) { |
| 83 | + return j == 10 ? 10 : 1; |
| 84 | + } |
| 85 | +} |
0 commit comments