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