Path: blob/master/test/hotspot/jtreg/compiler/c1/RangeCheckVerificationOfIR.java
41149 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. 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 823817826* @summary Checks the C1 RangeCheckEliminator::Verification code for nested exceptions in loops that are always executed once on the non-exceptional path.27*28* @run main/othervm -Xbatch -XX:TieredStopAtLevel=1 -XX:CompileCommand=dontinline,compiler.c1.RangeCheckVerificationOfIR::throwException*29* -XX:CompileCommand=dontinline,compiler.c1.RangeCheckVerificationOfIR::test* compiler.c1.RangeCheckVerificationOfIR30*/3132package compiler.c1;3334public class RangeCheckVerificationOfIR {3536int a;37int i1;38int i2;39int i3;4041public static void main(String[] args) {42RangeCheckVerificationOfIR instance = new RangeCheckVerificationOfIR();43instance.resetValues();44for (int i = 0; i < 1000; i++) {45instance.testSimple();46instance.resetValues();47instance.testDominatedByXhandler();48instance.resetValues();49instance.testThrowOneException();50instance.resetValues();51instance.testNestedExceptions();52instance.resetValues();53instance.testTriplyNestedExceptions();54instance.resetValues();55instance.testTriplyNestedExceptions2();56instance.resetValues();57instance.testTriplyNestedMultipleHandlers();58instance.resetValues();59instance.testTriplyNestedNoExceptionThrown();60instance.resetValues();61}62}6364private void resetValues() {65i1 = 0;66i2 = 0;67i3 = 0;68}6970// Is handled by current code (xhandler equals a pred of loop header block)71public void testSimple() {72int[] iArr = new int[8];73for (int i = 0; i < 8; i++) {74iArr[0] = 4;75}7677while (true) {78try {79throwException();80break;81} catch(Exception ex1) {82i1++;83}84}8586for (int i = 0; i < 10; i++) {87a = 5;88}89}9091// Is handled by current code (xhandler dominates a pred of loop header block)92public void testDominatedByXhandler() {93int[] iArr = new int[8];94for (int i = 0; i < 8; i++) {95iArr[0] = 4;96}9798while (true) {99try {100throwException();101break;102} catch (Exception ex1) {103if (i1 < i2) {104a = 3;105} else {106a = 4;107}108i1++;109}110}111112for (int i = 0; i < 10; i++) {113a = 5;114}115}116117// Not a problem, since no backbranch and therefore no loop118public void testThrowOneException() {119int[] iArr = new int[8];120for (int i = 0; i < 8; i++) {121iArr[0] = 4;122}123124try {125for (int i = 0; i < iArr[4]; i++) {126throwException();127}128} catch (Exception ex) {129a = 345;130}131132try {133while (true) {134throwException();135break;136}137} catch (Exception e) {138a = 45;139}140141for (int i = 0; i < 10; i++) {142a = 5;143}144}145146// All following cases are not handled yet. Need to walk backbranch of loop header block147// to find one of the exception handlers of loop header block somewhere. Must exist.148public void testNestedExceptions() {149int[] iArr = new int[8];150for (int i = 0; i < 8; i++) {151iArr[0] = 4;152}153154// The block from the backbranch, lets say B, is no xhandler block and not dominated by either of the two xhandler blocks, lets say155// E1 for the outer and E2 for the inner try/catch block: If no exception occurs in E1, then E1 is completely executed without156// executing E2. But if an exception occurs, then only parts of E1 is executed and E2 is executed completely.157// Therefore, neither of them dominates B.158while (true) {159try {160throwException();161break;162} catch (Exception ex1) {163i1++;164try {165throwException2();166} catch (Exception ex2) {167if (i1 < i2) {168a = 3;169} else {170a = 4;171}172i2++;173}174if (i1 < i2) {175a = 3;176} else {177a = 4;178}179i1++;180}181}182183for (int i = 0; i < 10; i++) {184a = 5;185}186}187188public void testTriplyNestedExceptions() {189int[] iArr = new int[8];190for (int i = 0; i < 8; i++) {191iArr[0] = 4;192}193194while (true) {195try {196throwException();197break;198} catch (Exception ex1) {199i1++;200try {201throwException2();202} catch (Exception ex2) {203if (i1 < i2) {204a = 3;205} else {206a = 4;207}208try {209throwException3();210} catch (Exception ex3) {211i3++;212}213try {214throwException3();215} catch (Exception ex3) {216i3++;217}218i2++;219}220if (i1 < i2) {221a = 3;222} else {223a = 4;224}225i1++;226}227}228229for (int i = 0; i < 10; i++) {230a = 5;231}232}233234public void testTriplyNestedExceptions2() {235int[] iArr = new int[8];236for (int i = 0; i < 8; i++) {237iArr[0] = 4;238}239240try {241for (int i = 0; i < iArr[4]; i++) {242throwException();243}244} catch (Exception ex) {245a = 345;246}247248while (true) {249try {250throwException();251break;252} catch (Exception ex1) {253i1++;254try {255throwException2();256} catch (Exception ex2) {257if (i1 < i2) {258a = 3;259} else {260a = 4;261}262try {263throwException3();264} catch (Exception ex3) {265i3++;266}267try {268throwException3();269} catch (Exception ex3) {270i3++;271}272i2++;273}274if (i1 < i2) {275a = 3;276} else {277a = 4;278}279i1++;280}281}282283for (int i = 0; i < 10; i++) {284a = 5;285}286}287288public void testTriplyNestedMultipleHandlers() {289int[] iArr = new int[8];290for (int i = 0; i < 8; i++) {291iArr[0] = 4;292}293294try {295for (int i = 0; i < iArr[4]; i++) {296throwException();297}298} catch (Exception ex) {299a = 345;300}301302try {303while (true) {304try {305throwException();306break;307} catch (MyInnerException ie) {308i1++;309try {310throwException2();311} catch (Exception ex2) {312if (i1 < i2) {313a = 3;314} else {315a = 4;316}317try {318throwException3();319} catch (Exception ex3) {320i3++;321}322try {323throwException3();324} catch (Exception ex3) {325i3++;326}327i2++;328}329if (i1 < i2) {330a = 3;331} else {332a = 4;333}334i1++;335}336}337} catch (MyOuterException oe) {338a = 45;339}340341for (int i = 0; i < 10; i++) {342a = 5;343}344}345346public void testTriplyNestedNoExceptionThrown() {347int[] iArr = new int[8];348for (int i = 0; i < 8; i++) {349iArr[0] = 4;350}351352try {353for (int i = 0; i < iArr[4]; i++) {354throwException();355}356} catch (Exception ex) {357a = 345;358}359360try {361while (true) {362try {363a = 4;364break;365} catch (RuntimeException ie) {366i1++;367try {368throwException2();369} catch (Exception ex2) {370if (i1 < i2) {371a = 3;372} else {373a = 4;374}375try {376throwException3();377} catch (Exception ex3) {378i3++;379}380try {381throwException3();382} catch (Exception ex3) {383i3++;384}385i2++;386}387if (i1 < i2) {388a = 3;389} else {390a = 4;391}392i1++;393}394}395} catch (Exception e) {396a = 45;397}398399for (int i = 0; i < 10; i++) {400a = 5;401}402}403404void throwException() throws MyInnerException, MyOuterException {405if (i1 < 3) {406throw new MyInnerException();407}408if (i1 < 5) {409throw new MyOuterException();410}411}412413public void throwException2() throws Exception {414if (i2 < 3) {415throw new RuntimeException();416}417}418419public void throwException3() throws Exception {420if (i3 < 2) {421throw new RuntimeException();422}423}424425class MyInnerException extends Exception { }426427class MyOuterException extends Exception { }428}429430431