1 /* 2 * Copyright (C) 2014 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 { main(String[] args)18 public static void main(String[] args) { 19 Exception exception = null; 20 try { 21 $opt$Throw(new int[1]); 22 } catch (ArrayIndexOutOfBoundsException e) { 23 exception = e; 24 } 25 26 String exceptionMessage = exception.getMessage(); 27 28 // Note that it's ART specific to emit the length. 29 if (exceptionMessage.contains("length")) { 30 if (!exceptionMessage.contains("length=1")) { 31 throw new Error("Wrong length in exception message"); 32 } 33 } 34 35 // Note that it's ART specific to emit the index. 36 if (exceptionMessage.contains("index")) { 37 if (!exceptionMessage.contains("index=2")) { 38 throw new Error("Wrong index in exception message"); 39 } 40 } 41 } 42 $opt$Throw(int[] array)43 static void $opt$Throw(int[] array) { 44 // We fetch the length first, to ensure it is in EAX (on x86). 45 // The pThrowArrayBounds entrypoint expects the index in EAX and the 46 // length in ECX, and the optimizing compiler used to write to EAX 47 // before putting the length in ECX. 48 int length = array.length; 49 array[2] = 42; 50 } 51 } 52