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