1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker public class Main { main(String[] args)18*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) {} 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker /// CHECK-START: java.lang.Object[] Main.testNoRTILoopNoIterations() builder (after) 21*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<Null:l\d+>> NullConstant 22*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<Phi:l\d+>> Phi [<<Null>>,<<PhiBoundType:l\d+>>] klass:invalid 23*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<Check:l\d+>> NullCheck [<<Phi>>] klass:invalid 24*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<ArrayGet:l\d+>> ArrayGet [<<Check>>,<<BoundsCheck:i\d+>>] klass:invalid 25*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<BoundType:l\d+>> BoundType [<<ArrayGet>>] klass:invalid 26*795d594fSAndroid Build Coastguard Worker // Due to the circular uses, this is how we check that the BoundType is a use of the Phi. 27*795d594fSAndroid Build Coastguard Worker /// CHECK-EVAL: "<<PhiBoundType>>" == "<<BoundType>>" testNoRTILoopNoIterations()28*795d594fSAndroid Build Coastguard Worker private static Object[] testNoRTILoopNoIterations() { 29*795d594fSAndroid Build Coastguard Worker Object[] h = null; 30*795d594fSAndroid Build Coastguard Worker for (int j = 0; j < 0; j++) { 31*795d594fSAndroid Build Coastguard Worker h = (Object[]) h[0]; 32*795d594fSAndroid Build Coastguard Worker } 33*795d594fSAndroid Build Coastguard Worker return h; 34*795d594fSAndroid Build Coastguard Worker } 35*795d594fSAndroid Build Coastguard Worker $inline$doNothing(Object[] obj)36*795d594fSAndroid Build Coastguard Worker private static void $inline$doNothing(Object[] obj) {} 37*795d594fSAndroid Build Coastguard Worker 38*795d594fSAndroid Build Coastguard Worker // This test also has no iterations, but we won't know until LSE. We inline the doNothing 39*795d594fSAndroid Build Coastguard Worker // method, try to apply the invalid RTI and crash. 40*795d594fSAndroid Build Coastguard Worker 41*795d594fSAndroid Build Coastguard Worker /// CHECK-START: java.lang.Object[] Main.testNoRTILoopNoIterationsWithInlining() builder (after) 42*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<Null:l\d+>> NullConstant 43*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<Phi:l\d+>> Phi [<<Null>>,<<PhiBoundType:l\d+>>] klass:invalid 44*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: InvokeStaticOrDirect [<<Phi>>] method_name:Main.$inline$doNothing 45*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<Check:l\d+>> NullCheck [<<Phi>>] klass:invalid 46*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<ArrayGet:l\d+>> ArrayGet [<<Check>>,<<BoundsCheck:i\d+>>] klass:invalid 47*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: <<BoundType:l\d+>> BoundType [<<ArrayGet>>] klass:invalid 48*795d594fSAndroid Build Coastguard Worker // Due to the circular uses, this is how we check that the BoundType is a use of the Phi. 49*795d594fSAndroid Build Coastguard Worker /// CHECK-EVAL: "<<PhiBoundType>>" == "<<BoundType>>" testNoRTILoopNoIterationsWithInlining()50*795d594fSAndroid Build Coastguard Worker public static Object[] testNoRTILoopNoIterationsWithInlining() { 51*795d594fSAndroid Build Coastguard Worker Object[] h = null; 52*795d594fSAndroid Build Coastguard Worker int iterations = 0; 53*795d594fSAndroid Build Coastguard Worker int other_iterations = iterations; 54*795d594fSAndroid Build Coastguard Worker for (int j = 0; j < other_iterations; j++) { 55*795d594fSAndroid Build Coastguard Worker $inline$doNothing(h); 56*795d594fSAndroid Build Coastguard Worker h = (Object[]) h[0]; 57*795d594fSAndroid Build Coastguard Worker } 58*795d594fSAndroid Build Coastguard Worker return h; 59*795d594fSAndroid Build Coastguard Worker } 60*795d594fSAndroid Build Coastguard Worker 61*795d594fSAndroid Build Coastguard Worker } 62