1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2016 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 { 18*795d594fSAndroid Build Coastguard Worker main(String[] args)19*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) { 20*795d594fSAndroid Build Coastguard Worker Object[] array = { new Integer(1), new Integer(2), new Integer(3) }; 21*795d594fSAndroid Build Coastguard Worker int result = test(array, 0, 2); 22*795d594fSAndroid Build Coastguard Worker System.out.println(result); 23*795d594fSAndroid Build Coastguard Worker } 24*795d594fSAndroid Build Coastguard Worker 25*795d594fSAndroid Build Coastguard Worker // This test method uses two integers (`index1` and `index2`) to 26*795d594fSAndroid Build Coastguard Worker // force the register allocator to use some high registers (R8-R15) 27*795d594fSAndroid Build Coastguard Worker // on x86-64 in the code generated for the first CheckCast (which 28*795d594fSAndroid Build Coastguard Worker // converts `new_array` to an `Object[]`), so as to produce code 29*795d594fSAndroid Build Coastguard Worker // containing a conditional jump whose offset does not fit in a 30*795d594fSAndroid Build Coastguard Worker // NearLabel when using Baker's read barrier fast path (because 31*795d594fSAndroid Build Coastguard Worker // x86-64 instructions using these high registers have a larger 32*795d594fSAndroid Build Coastguard Worker // encoding). 33*795d594fSAndroid Build Coastguard Worker // 34*795d594fSAndroid Build Coastguard Worker // The intent of this artifical constraint is to ensure the initial 35*795d594fSAndroid Build Coastguard Worker // failure is properly tested by this regression test. 36*795d594fSAndroid Build Coastguard Worker 37*795d594fSAndroid Build Coastguard Worker /// CHECK-START: int Main.test(java.lang.Object, int, int) register (after) 38*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: CheckCast check_kind:array_object_check 39*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: CheckCast check_kind:exact_check 40*795d594fSAndroid Build Coastguard Worker /// CHECK-DAG: CheckCast check_kind:exact_check 41*795d594fSAndroid Build Coastguard Worker test(Object new_array, int index1, int index2)42*795d594fSAndroid Build Coastguard Worker static public int test(Object new_array, int index1, int index2) { 43*795d594fSAndroid Build Coastguard Worker Object[] objectArray = (Object[]) new_array; 44*795d594fSAndroid Build Coastguard Worker Integer integer1 = (Integer) objectArray[index1]; 45*795d594fSAndroid Build Coastguard Worker Integer integer2 = (Integer) objectArray[index2]; 46*795d594fSAndroid Build Coastguard Worker return integer1.intValue() + integer2.intValue(); 47*795d594fSAndroid Build Coastguard Worker } 48*795d594fSAndroid Build Coastguard Worker 49*795d594fSAndroid Build Coastguard Worker } 50