Path: blob/master/test/hotspot/jtreg/compiler/c1/TestRangeCheckEliminated.java
64474 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",52"-XX:CompileThreshold=500",53test_constant_array.class.getName()54};5556ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(procArgs);57String output = new OutputAnalyzer(pb.start()).getOutput();58// should have 2 "can be fully eliminated"59System.out.println(output);60if ((output.split(eliminated, -1).length - 1) == 2) {61System.out.println("test_constant_array pass");62} else {63System.out.println("test_constant_array fail");64error = true;65}6667procArgs = new String[] {68"-XX:CompileCommand=compileonly,*test_multi_constant_array::multi_constant_array_rc",69"-XX:TieredStopAtLevel=1",70"-XX:+TraceRangeCheckElimination",71"-XX:-BackgroundCompilation",72"-XX:CompileThreshold=500",73test_multi_constant_array.class.getName()74};7576pb = ProcessTools.createJavaProcessBuilder(procArgs);77output = new OutputAnalyzer(pb.start()).getOutput();78// should have 1 "can be fully eliminated"79System.out.println(output);80if ((output.split(eliminated, -1).length - 1) == 1) {81System.out.println("test_multi_constant_array pass");82} else {83System.out.println("test_multi_constant_array fail");84error = true;85}8687procArgs = new String[] {88"-XX:CompileCommand=compileonly,*test_multi_new_array::multi_new_array_rc",89"-XX:TieredStopAtLevel=1",90"-XX:+TraceRangeCheckElimination",91"-XX:-BackgroundCompilation",92"-XX:CompileThreshold=500",93test_multi_new_array.class.getName()94};9596pb = ProcessTools.createJavaProcessBuilder(procArgs);97output = new OutputAnalyzer(pb.start()).getOutput();98// should have 2 "can be fully eliminated"99System.out.println(output);100if ((output.split(eliminated, -1).length - 1) == 2) {101System.out.println("test_multi_new_array pass");102} else {103System.out.println("test_multi_new_array fail");104error = true;105}106107if (error) {108throw new InternalError();109}110}111112public static class test_constant_array {113static final int constant_array[] =114{50,60,55,67,70,62,65,70,70,81,72,66,77,80,69};115static void constant_array_rc() {116constant_array[1] += 5;117}118119public static void main(String[] args) {120for(int i = 0; i < 1_000; i++) {121constant_array_rc();122}123}124}125126public static class test_multi_constant_array {127static final int constant_multi_array[][] = {128{50,60,55,67,70}, {62,65,70,70,81}, {72,66,77,80,69}};129static void multi_constant_array_rc() {130constant_multi_array[2][3] += 5;131}132133public static void main(String[] args) {134for(int i = 0; i < 1_000; i++) {135multi_constant_array_rc();136}137}138}139140public static class test_multi_new_array {141static void foo(int i) {}142static void multi_new_array_rc(int index) {143int na[] = new int[800];144int nma[][] = new int[600][2];145nma[20][1] += 5; // optimize rc on NewMultiArray first dimension146nma[index][0] = 0; // index < 600 after this statement147foo(na[index]); // index must < 800, remove rc148}149150public static void main(String[] args) {151for(int i = 0; i < 600; i++) {152multi_new_array_rc(i);153}154}155}156}157158159