Path: blob/master/test/hotspot/jtreg/compiler/loopopts/TestBadControlLoopLimitCheck.java
41149 views
/*1* Copyright (c) 2020, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 824571426* @requires vm.compiler2.enabled27* @summary "Bad graph detected in build_loop_late" when loads are pinned on loop limit check uncommon branch28*29* @run main/othervm -XX:-BackgroundCompilation -XX:ArrayCopyLoadStoreMaxElem=0 TestBadControlLoopLimitCheck30*/3132public class TestBadControlLoopLimitCheck {33public static void main(String[] args) {34int[] int_array = {0, 0};35A[] obj_array = {new A(), new A()};36for (int i = 0; i < 20_000; i++) {37test1(int_array, 0, 10, false);38test_helper(42);39test2(obj_array, 0, 10, false);40}41}4243private static int test1(int[] a, int start, int stop, boolean flag) {44int[] b = new int[2]; // non escaping allocation45System.arraycopy(a, 0, b, 0, 2); // optimized out46int v = 1;47int j = 0;48for (; j < 10; j++);49int inc = test_helper(j); // delay transformation to counted loop50// loop limit check here has loads pinned on unc branch51for (int i = start; i < stop; i += inc) {52v *= 2;53}54if (flag) {55v += b[0] + b[1];56}57return v;58}5960private static int test2(A[] a, int start, int stop, boolean flag) {61A[] b = new A[2]; // non escaping allocation62System.arraycopy(a, 0, b, 0, 2); // optimized out63int v = 1;64int j = 0;65for (; j < 10; j++);66int inc = test_helper(j); // delay transformation to counted loop67// loop limit check here has loads pinned on unc branch68for (int i = start; i < stop; i += inc) {69v *= 2;70}71if (flag) {72v += b[0].f + b[1].f;73}74return v;75}7677static class A {78int f;79}8081static int test_helper(int j) {82return j == 10 ? 10 : 1;83}84}858687