Path: blob/master/test/hotspot/jtreg/compiler/c1/TestRangeCheckEliminated.java
41149 views
/*1* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* @test26* @bug 826370727* @summary Test range check for constant array and NewMultiArray is removed properly28* @author Hui Shi29*30* @requires vm.flagless31* @requires vm.debug == true & vm.compiler1.enabled32*33* @library /test/lib34*35* @run driver compiler.c1.TestRangeCheckEliminated36*/3738package compiler.c1;3940import jdk.test.lib.process.OutputAnalyzer;41import jdk.test.lib.process.ProcessTools;4243public class TestRangeCheckEliminated {44static final String eliminated = "can be fully eliminated";45public static void main(String[] args) throws Throwable {46boolean error = false;47String[] procArgs = new String[] {48"-XX:CompileCommand=compileonly,*test_constant_array::constant_array_rc",49"-XX:TieredStopAtLevel=1",50"-XX:+TraceRangeCheckElimination",51"-XX:-BackgroundCompilation",52test_constant_array.class.getName()53};5455ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(procArgs);56String output = new OutputAnalyzer(pb.start()).getOutput();57// should have 2 "can be fully eliminated"58System.out.println(output);59if ((output.split(eliminated, -1).length - 1) == 2) {60System.out.println("test_constant_array pass");61} else {62System.out.println("test_constant_array fail");63error = true;64}6566procArgs = new String[] {67"-XX:CompileCommand=compileonly,*test_multi_constant_array::multi_constant_array_rc",68"-XX:TieredStopAtLevel=1",69"-XX:+TraceRangeCheckElimination",70"-XX:-BackgroundCompilation",71test_multi_constant_array.class.getName()72};7374pb = ProcessTools.createJavaProcessBuilder(procArgs);75output = new OutputAnalyzer(pb.start()).getOutput();76// should have 1 "can be fully eliminated"77System.out.println(output);78if ((output.split(eliminated, -1).length - 1) == 1) {79System.out.println("test_multi_constant_array pass");80} else {81System.out.println("test_multi_constant_array fail");82error = true;83}8485procArgs = new String[] {86"-XX:CompileCommand=compileonly,*test_multi_new_array::multi_new_array_rc",87"-XX:TieredStopAtLevel=1",88"-XX:+TraceRangeCheckElimination",89"-XX:-BackgroundCompilation",90test_multi_new_array.class.getName()91};9293pb = ProcessTools.createJavaProcessBuilder(procArgs);94output = new OutputAnalyzer(pb.start()).getOutput();95// should have 2 "can be fully eliminated"96System.out.println(output);97if ((output.split(eliminated, -1).length - 1) == 2) {98System.out.println("test_multi_new_array pass");99} else {100System.out.println("test_multi_new_array fail");101error = true;102}103104if (error) {105throw new InternalError();106}107}108109public static class test_constant_array {110static final int constant_array[] =111{50,60,55,67,70,62,65,70,70,81,72,66,77,80,69};112static void constant_array_rc() {113constant_array[1] += 5;114}115116public static void main(String[] args) {117for(int i = 0; i < 1_000; i++) {118constant_array_rc();119}120}121}122123public static class test_multi_constant_array {124static final int constant_multi_array[][] = {125{50,60,55,67,70}, {62,65,70,70,81}, {72,66,77,80,69}};126static void multi_constant_array_rc() {127constant_multi_array[2][3] += 5;128}129130public static void main(String[] args) {131for(int i = 0; i < 1_000; i++) {132multi_constant_array_rc();133}134}135}136137public static class test_multi_new_array {138static void foo(int i) {}139static void multi_new_array_rc(int index) {140int na[] = new int[800];141int nma[][] = new int[600][2];142nma[20][1] += 5; // optimize rc on NewMultiArray first dimension143nma[index][0] = 0; // index < 600 after this statement144foo(na[index]); // index must < 800, remove rc145}146147public static void main(String[] args) {148for(int i = 0; i < 600; i++) {149multi_new_array_rc(i);150}151}152}153}154155156