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 19 public static void main(String args[]) { 20 int[] array = new int[51]; 21 testArrayLengthBoundsCheckX86(array, 10); 22 23 System.out.println("passed"); 24 } 25 26 /// CHECK-START-X86: void Main.testArrayLengthBoundsCheckX86(int[], int) x86_memory_operand_generation (before) 27 /// CHECK-DAG: <<Array:l\d+>> ParameterValue 28 /// CHECK-DAG: <<Index:i\d+>> ParameterValue 29 /// CHECK-DAG: <<Value:i\d+>> IntConstant 9 30 /// CHECK-DAG: <<CheckedArray:l\d+>> NullCheck [<<Array>>] 31 /// CHECK-DAG: <<Length:i\d+>> ArrayLength [<<CheckedArray>>] is_string_length:false loop:none 32 /// CHECK-DAG: <<CheckedIndex:i\d+>> BoundsCheck [<<Index>>,<<Length>>] 33 /// CHECK-DAG: <<ArraySet:v\d+>> ArraySet [<<CheckedArray>>,<<CheckedIndex>>,<<Value>>] 34 35 /// CHECK-START-X86: void Main.testArrayLengthBoundsCheckX86(int[], int) x86_memory_operand_generation (after) 36 /// CHECK-DAG: <<Array:l\d+>> ParameterValue 37 /// CHECK-DAG: <<Index:i\d+>> ParameterValue 38 /// CHECK-DAG: <<Value:i\d+>> IntConstant 9 39 /// CHECK-DAG: <<CheckedArray:l\d+>> NullCheck [<<Array>>] 40 /// CHECK-DAG: <<Length:i\d+>> ArrayLength [<<CheckedArray>>] is_string_length:false emitted_at_use:true loop:none 41 /// CHECK-DAG: <<CheckedIndex:i\d+>> BoundsCheck [<<Index>>,<<Length>>] 42 /// CHECK-DAG: <<ArraySet:v\d+>> ArraySet [<<CheckedArray>>,<<CheckedIndex>>,<<Value>>] 43 44 /// CHECK-START-X86: void Main.testArrayLengthBoundsCheckX86(int[], int) disassembly (after) 45 /// CHECK-DAG: <<Array:l\d+>> ParameterValue 46 /// CHECK-DAG: <<Index:i\d+>> ParameterValue 47 /// CHECK-DAG: <<Value:i\d+>> IntConstant 9 48 /// CHECK: <<CheckedArray:l\d+>> NullCheck [<<Array>>] 49 /// CHECK-NEXT: <<Length:i\d+>> ArrayLength [<<Array>>] is_string_length:false emitted_at_use:true loop:none 50 /// CHECK-NEXT: <<CheckedIndex:i\d+>> BoundsCheck [<<Index>>,<<Length>>] 51 /// CHECK-NEXT: cmp [<<BaseReg:\w+>> + 8], <<IndexReg:\w+>> 52 /// CHECK: <<ArraySet:v\d+>> ArraySet [<<Array>>,<<Index>>,<<Value>>] 53 /// CHECK-NEXT: mov [<<BaseReg>> + <<IndexReg>> * 4 + 12], 9 54 55 /// CHECK-START-X86_64: void Main.testArrayLengthBoundsCheckX86(int[], int) x86_memory_operand_generation (before) 56 /// CHECK-DAG: <<Array:l\d+>> ParameterValue 57 /// CHECK-DAG: <<Index:i\d+>> ParameterValue 58 /// CHECK-DAG: <<Value:i\d+>> IntConstant 9 59 /// CHECK-DAG: <<CheckedArray:l\d+>> NullCheck [<<Array>>] 60 /// CHECK-DAG: <<Length:i\d+>> ArrayLength [<<CheckedArray>>] is_string_length:false loop:none 61 /// CHECK-DAG: <<CheckedIndex:i\d+>> BoundsCheck [<<Index>>,<<Length>>] 62 /// CHECK-DAG: <<ArraySet:v\d+>> ArraySet [<<CheckedArray>>,<<CheckedIndex>>,<<Value>>] 63 64 /// CHECK-START-X86_64: void Main.testArrayLengthBoundsCheckX86(int[], int) x86_memory_operand_generation (after) 65 /// CHECK-DAG: <<Array:l\d+>> ParameterValue 66 /// CHECK-DAG: <<Index:i\d+>> ParameterValue 67 /// CHECK-DAG: <<Value:i\d+>> IntConstant 9 68 /// CHECK-DAG: <<CheckedArray:l\d+>> NullCheck [<<Array>>] 69 /// CHECK-DAG: <<Length:i\d+>> ArrayLength [<<CheckedArray>>] is_string_length:false emitted_at_use:true loop:none 70 /// CHECK-DAG: <<CheckedIndex:i\d+>> BoundsCheck [<<Index>>,<<Length>>] 71 /// CHECK-DAG: <<ArraySet:v\d+>> ArraySet [<<CheckedArray>>,<<CheckedIndex>>,<<Value>>] 72 73 // Test assumes parameter value is in lower 8 registers (it is passed in edx). 74 /// CHECK-START-X86_64: void Main.testArrayLengthBoundsCheckX86(int[], int) disassembly (after) 75 /// CHECK-DAG: <<Array:l\d+>> ParameterValue 76 /// CHECK-DAG: <<Index:i\d+>> ParameterValue 77 /// CHECK-DAG: <<Value:i\d+>> IntConstant 9 78 /// CHECK: <<CheckedArray:l\d+>> NullCheck [<<Array>>] 79 /// CHECK-NEXT: <<Length:i\d+>> ArrayLength [<<Array>>] is_string_length:false emitted_at_use:true loop:none 80 /// CHECK-NEXT: <<CheckedIndex:i\d+>> BoundsCheck [<<Index>>,<<Length>>] 81 /// CHECK-NEXT: cmp [<<BaseReg:\w+>> + 8], e<<IndexReg:\w+>> 82 /// CHECK: <<ArraySet:v\d+>> ArraySet [<<Array>>,<<Index>>,<<Value>>] 83 /// CHECK-NEXT: mov [<<BaseReg>> + r<<IndexReg>> * 4 + 12], 9 84 85 static void testArrayLengthBoundsCheckX86(int[] array, int index) { 86 array[index] = 9; 87 } 88 } 89