1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 public class Main { 18 main(String[] args)19 public static void main(String[] args) { 20 Object[] array = { new Integer(1), new Integer(2), new Integer(3) }; 21 int result = test(array, 0, 2); 22 System.out.println(result); 23 } 24 25 // This test method uses two integers (`index1` and `index2`) to 26 // force the register allocator to use some high registers (R8-R15) 27 // on x86-64 in the code generated for the first CheckCast (which 28 // converts `new_array` to an `Object[]`), so as to produce code 29 // containing a conditional jump whose offset does not fit in a 30 // NearLabel when using Baker's read barrier fast path (because 31 // x86-64 instructions using these high registers have a larger 32 // encoding). 33 // 34 // The intent of this artifical constraint is to ensure the initial 35 // failure is properly tested by this regression test. 36 37 /// CHECK-START: int Main.test(java.lang.Object, int, int) register (after) 38 /// CHECK-DAG: CheckCast check_kind:array_object_check 39 /// CHECK-DAG: CheckCast check_kind:exact_check 40 /// CHECK-DAG: CheckCast check_kind:exact_check 41 test(Object new_array, int index1, int index2)42 static public int test(Object new_array, int index1, int index2) { 43 Object[] objectArray = (Object[]) new_array; 44 Integer integer1 = (Integer) objectArray[index1]; 45 Integer integer2 = (Integer) objectArray[index2]; 46 return integer1.intValue() + integer2.intValue(); 47 } 48 49 } 50