1 /* 2 * Copyright (C) 2015 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 class Main { 18 19 // The code below is written in a way that would crash 20 // the generated code at the time of submission of this test. 21 // Therefore, changes to the register allocator may 22 // affect the reproducibility of the crash. $noinline$foo(int a, int b, int c)23 public static void $noinline$foo(int a, int b, int c) { 24 // The division on x86 will take EAX and EDX, leaving ECX 25 // to put the ART current method. 26 c = c / 42; 27 // We use the empty string for forcing the slow path. 28 // The slow path for charAt, when it is intrinsified, will 29 // move the parameter to ECX and therefore overwrite the ART 30 // current method. 31 "".charAt(c); 32 33 // Do more things in the method to prevent inlining. 34 c = c / 42; 35 "".charAt(c); 36 c = c / 42; 37 "".charAt(c); 38 c = c / 42; 39 "".charAt(c); 40 c = c / 42; 41 "".charAt(c); 42 c = c / 42; 43 "".charAt(c); 44 c = c / 42; 45 "".charAt(c); 46 c = c / 42; 47 "".charAt(c); 48 c = c / 42; 49 "".charAt(c); 50 c = c / 42; 51 "".charAt(c); 52 c = c / 42; 53 "".charAt(c); 54 c = c / 42; 55 "".charAt(c); 56 } 57 main(String[] args)58 public static void main(String[] args) { 59 boolean didThrow = false; 60 try { 61 $noinline$foo(1, 2, 3); 62 } catch (Throwable e) { 63 didThrow = true; 64 } 65 66 if (!didThrow) { 67 throw new Error("Expected an exception from charAt"); 68 } 69 } 70 } 71