1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2019 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 package art; 18*795d594fSAndroid Build Coastguard Worker 19*795d594fSAndroid Build Coastguard Worker public class NonStandardExit { popFrame(Thread thr)20*795d594fSAndroid Build Coastguard Worker public static native void popFrame(Thread thr); forceEarlyReturnVoid(Thread thr)21*795d594fSAndroid Build Coastguard Worker public static native void forceEarlyReturnVoid(Thread thr); forceEarlyReturnFloat(Thread thr, float f)22*795d594fSAndroid Build Coastguard Worker public static native void forceEarlyReturnFloat(Thread thr, float f); forceEarlyReturnDouble(Thread thr, double f)23*795d594fSAndroid Build Coastguard Worker public static native void forceEarlyReturnDouble(Thread thr, double f); forceEarlyReturnInt(Thread thr, int f)24*795d594fSAndroid Build Coastguard Worker public static native void forceEarlyReturnInt(Thread thr, int f); forceEarlyReturnLong(Thread thr, long f)25*795d594fSAndroid Build Coastguard Worker public static native void forceEarlyReturnLong(Thread thr, long f); forceEarlyReturnObject(Thread thr, Object f)26*795d594fSAndroid Build Coastguard Worker public static native void forceEarlyReturnObject(Thread thr, Object f); 27*795d594fSAndroid Build Coastguard Worker forceEarlyReturn(Thread thr, Object o)28*795d594fSAndroid Build Coastguard Worker public static void forceEarlyReturn(Thread thr, Object o) { 29*795d594fSAndroid Build Coastguard Worker if (o instanceof Number && o.getClass().getPackage().equals(Object.class.getPackage())) { 30*795d594fSAndroid Build Coastguard Worker Number n = (Number)o; 31*795d594fSAndroid Build Coastguard Worker if (n instanceof Integer || n instanceof Short || n instanceof Byte) { 32*795d594fSAndroid Build Coastguard Worker forceEarlyReturnInt(thr, n.intValue()); 33*795d594fSAndroid Build Coastguard Worker } else if (n instanceof Long) { 34*795d594fSAndroid Build Coastguard Worker forceEarlyReturnLong(thr, n.longValue()); 35*795d594fSAndroid Build Coastguard Worker } else if (n instanceof Float) { 36*795d594fSAndroid Build Coastguard Worker forceEarlyReturnFloat(thr, n.floatValue()); 37*795d594fSAndroid Build Coastguard Worker } else if (n instanceof Double) { 38*795d594fSAndroid Build Coastguard Worker forceEarlyReturnDouble(thr, n.doubleValue()); 39*795d594fSAndroid Build Coastguard Worker } else { 40*795d594fSAndroid Build Coastguard Worker throw new IllegalArgumentException("Unknown number subtype: " + n.getClass() + " - " + n); 41*795d594fSAndroid Build Coastguard Worker } 42*795d594fSAndroid Build Coastguard Worker } else if (o instanceof Character) { 43*795d594fSAndroid Build Coastguard Worker forceEarlyReturnInt(thr, ((Character)o).charValue()); 44*795d594fSAndroid Build Coastguard Worker } else if (o instanceof Boolean) { 45*795d594fSAndroid Build Coastguard Worker forceEarlyReturnInt(thr, ((Boolean)o).booleanValue() ? 1 : 0); 46*795d594fSAndroid Build Coastguard Worker } else { 47*795d594fSAndroid Build Coastguard Worker forceEarlyReturnObject(thr, o); 48*795d594fSAndroid Build Coastguard Worker } 49*795d594fSAndroid Build Coastguard Worker } 50*795d594fSAndroid Build Coastguard Worker } 51