|
| 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 8296389 |
| 27 | + * @summary Peeling of Irreducible loop can lead to NeverBranch being visited from either side |
| 28 | + * @run main/othervm -Xcomp -XX:-TieredCompilation -XX:PerMethodTrapLimit=0 |
| 29 | + * -XX:CompileCommand=compileonly,TestPhaseCFGNeverBranchToGotoMain::test |
| 30 | + * TestPhaseCFGNeverBranchToGotoMain |
| 31 | + */ |
| 32 | + |
| 33 | +/* |
| 34 | + * @test |
| 35 | + * @bug 8296389 |
| 36 | + * @compile TestPhaseCFGNeverBranchToGoto.jasm |
| 37 | + * @summary Peeling of Irreducible loop can lead to NeverBranch being visited from either side |
| 38 | + * @run main/othervm -Xcomp -XX:-TieredCompilation -XX:PerMethodTrapLimit=0 |
| 39 | + * -XX:CompileCommand=compileonly,TestPhaseCFGNeverBranchToGoto::test |
| 40 | + * TestPhaseCFGNeverBranchToGoto |
| 41 | + */ |
| 42 | + |
| 43 | + |
| 44 | +public class TestPhaseCFGNeverBranchToGotoMain { |
| 45 | + public static void main (String[] args) { |
| 46 | + test(false, false); |
| 47 | + } |
| 48 | + |
| 49 | + public static void test(boolean flag1, boolean flag2) { |
| 50 | + if (flag1) { // runtime check, avoid infinite loop |
| 51 | + int a = 77; |
| 52 | + int b = 0; |
| 53 | + do { // empty loop |
| 54 | + a--; |
| 55 | + b++; |
| 56 | + } while (a > 0); |
| 57 | + // a == 0, b == 77 - after first loop-opts phase |
| 58 | + int p = 0; |
| 59 | + for (int i = 0; i < 4; i++) { |
| 60 | + if ((i % 2) == 0) { |
| 61 | + p = 1; |
| 62 | + } |
| 63 | + } |
| 64 | + // p == 1 - after second loop-opts phase (via unrolling) |
| 65 | + // in first loop-opts phase we have 2x unrolling, 4x after second |
| 66 | + int x = 1; |
| 67 | + if (flag2) { |
| 68 | + x = 3; |
| 69 | + } // have region here, so that NeverBranch does not get removed |
| 70 | + do { // infinite loop |
| 71 | + do { |
| 72 | + // NeverBranch inserted here, during loop-opts 1 |
| 73 | + x *= 2; |
| 74 | + if (p == 0) { // reason for peeling in loop-opts 1 |
| 75 | + // after we know that p == 1, we lose this exit |
| 76 | + break; |
| 77 | + } |
| 78 | + // once we know that b == 77, we lose exit |
| 79 | + } while (b == 77); |
| 80 | + // after we lost both exits above, this loop gets cut off |
| 81 | + int y = 5; |
| 82 | + do { |
| 83 | + y *= 3; |
| 84 | + } while (b == 77); |
| 85 | + } while (true); |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments