The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | */ |
Andy McFadden | 65a54dc | 2011-01-27 17:01:54 -0800 | [diff] [blame] | 16 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 17 | /* |
| 18 | * Inlined native functions. |
| 19 | */ |
Carl Shapiro | 375fb11 | 2011-06-14 20:31:24 -0700 | [diff] [blame] | 20 | #ifndef DALVIK_INLINENATIVE_H_ |
| 21 | #define DALVIK_INLINENATIVE_H_ |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 22 | |
| 23 | /* startup/shutdown */ |
| 24 | bool dvmInlineNativeStartup(void); |
| 25 | void dvmInlineNativeShutdown(void); |
| 26 | |
Elliott Hughes | fe70026 | 2010-09-14 17:42:07 -0700 | [diff] [blame] | 27 | Method* dvmFindInlinableMethod(const char* classDescriptor, |
| 28 | const char* methodName, const char* methodSignature); |
| 29 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 30 | /* |
| 31 | * Basic 4-argument inline operation handler. |
| 32 | */ |
| 33 | typedef bool (*InlineOp4Func)(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 34 | JValue* pResult); |
| 35 | |
| 36 | /* |
| 37 | * Table of inline operations. |
| 38 | * |
| 39 | * Try to keep this at a power-of-two size, so we don't have to multiply. |
| 40 | * |
| 41 | * TODO: might be to our advantage to generate a compact jump table on |
| 42 | * the heap at runtime (or just declare two static tables, one with full |
| 43 | * info and one with just function pointers). Especially useful if we decide |
| 44 | * to support other method call forms, e.g. /range. We can also just |
| 45 | * generate assembly code that knows how many args it needs and has the |
| 46 | * target address embedded. |
| 47 | */ |
Carl Shapiro | d862faa | 2011-04-27 23:00:01 -0700 | [diff] [blame] | 48 | struct InlineOperation { |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 49 | InlineOp4Func func; /* MUST be first entry */ |
| 50 | const char* classDescriptor; |
| 51 | const char* methodName; |
| 52 | const char* methodSignature; |
Carl Shapiro | d862faa | 2011-04-27 23:00:01 -0700 | [diff] [blame] | 53 | }; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 54 | |
Elliott Hughes | 69ee8f6 | 2011-02-16 14:30:45 -0800 | [diff] [blame] | 55 | /* |
| 56 | * Must be kept in sync w/ gDvmInlineOpsTable in InlineNative.c |
| 57 | * |
| 58 | * You should also add a test to libcore's IntrinsicTest. |
| 59 | */ |
Carl Shapiro | d862faa | 2011-04-27 23:00:01 -0700 | [diff] [blame] | 60 | enum NativeInlineOps { |
Bill Buzbee | 50a6bf2 | 2009-07-08 13:08:04 -0700 | [diff] [blame] | 61 | INLINE_EMPTYINLINEMETHOD = 0, |
| 62 | INLINE_STRING_CHARAT = 1, |
| 63 | INLINE_STRING_COMPARETO = 2, |
| 64 | INLINE_STRING_EQUALS = 3, |
Elliott Hughes | 2bdbcb6 | 2010-04-12 14:29:37 -0700 | [diff] [blame] | 65 | INLINE_STRING_FASTINDEXOF_II = 4, |
| 66 | INLINE_STRING_IS_EMPTY = 5, |
| 67 | INLINE_STRING_LENGTH = 6, |
| 68 | INLINE_MATH_ABS_INT = 7, |
| 69 | INLINE_MATH_ABS_LONG = 8, |
| 70 | INLINE_MATH_ABS_FLOAT = 9, |
| 71 | INLINE_MATH_ABS_DOUBLE = 10, |
| 72 | INLINE_MATH_MIN_INT = 11, |
| 73 | INLINE_MATH_MAX_INT = 12, |
| 74 | INLINE_MATH_SQRT = 13, |
| 75 | INLINE_MATH_COS = 14, |
| 76 | INLINE_MATH_SIN = 15, |
Elliott Hughes | e22bd84 | 2010-08-20 18:47:36 -0700 | [diff] [blame] | 77 | INLINE_FLOAT_TO_INT_BITS = 16, |
| 78 | INLINE_FLOAT_TO_RAW_INT_BITS = 17, |
| 79 | INLINE_INT_BITS_TO_FLOAT = 18, |
| 80 | INLINE_DOUBLE_TO_LONG_BITS = 19, |
| 81 | INLINE_DOUBLE_TO_RAW_LONG_BITS = 20, |
| 82 | INLINE_LONG_BITS_TO_DOUBLE = 21, |
Carl Shapiro | d862faa | 2011-04-27 23:00:01 -0700 | [diff] [blame] | 83 | }; |
Bill Buzbee | 50a6bf2 | 2009-07-08 13:08:04 -0700 | [diff] [blame] | 84 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 85 | /* |
| 86 | * Get the inlineops table. |
| 87 | */ |
| 88 | const InlineOperation* dvmGetInlineOpsTable(void); |
| 89 | int dvmGetInlineOpsTableLength(void); |
| 90 | |
| 91 | /* |
| 92 | * The table, exposed so we can access it with C inlines. Prefer access |
| 93 | * through dvmGetInlineOpsTable(). |
| 94 | */ |
| 95 | extern const InlineOperation gDvmInlineOpsTable[]; |
| 96 | |
| 97 | /* |
| 98 | * Perform the operation specified by "opIndex". |
| 99 | * |
| 100 | * We want the arguments to appear in the first 4 registers so they can |
| 101 | * be passed straight through to the handler function. Ideally on ARM |
| 102 | * they'll go into r0-r3 and stay there. |
| 103 | * |
| 104 | * Returns "true" if everything went normally, "false" if an exception |
| 105 | * was thrown. |
| 106 | */ |
| 107 | INLINE bool dvmPerformInlineOp4Std(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 108 | JValue* pResult, int opIndex) |
| 109 | { |
| 110 | return (*gDvmInlineOpsTable[opIndex].func)(arg0, arg1, arg2, arg3, pResult); |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * Like the "std" version, but will emit profiling info. |
| 115 | */ |
| 116 | bool dvmPerformInlineOp4Dbg(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 117 | JValue* pResult, int opIndex); |
| 118 | |
buzbee | 9a3147c | 2011-03-02 15:43:48 -0800 | [diff] [blame] | 119 | /* |
| 120 | * Return method & populate the table on first use. |
| 121 | */ |
Carl Shapiro | d862faa | 2011-04-27 23:00:01 -0700 | [diff] [blame] | 122 | extern "C" Method* dvmResolveInlineNative(int opIndex); |
buzbee | 9a3147c | 2011-03-02 15:43:48 -0800 | [diff] [blame] | 123 | |
Carl Shapiro | db0c954 | 2011-04-12 19:14:06 -0700 | [diff] [blame] | 124 | /* |
| 125 | * The actual inline native definitions. |
| 126 | */ |
| 127 | bool javaLangString_charAt(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 128 | JValue* pResult); |
| 129 | |
| 130 | bool javaLangString_compareTo(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 131 | JValue* pResult); |
| 132 | |
| 133 | bool javaLangString_equals(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 134 | JValue* pResult); |
| 135 | |
| 136 | bool javaLangString_length(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 137 | JValue* pResult); |
| 138 | |
| 139 | bool javaLangString_isEmpty(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 140 | JValue* pResult); |
| 141 | |
| 142 | bool javaLangString_fastIndexOf_II(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 143 | JValue* pResult); |
| 144 | |
| 145 | bool javaLangMath_abs_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 146 | JValue* pResult); |
| 147 | |
| 148 | bool javaLangMath_abs_long(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 149 | JValue* pResult); |
| 150 | |
| 151 | bool javaLangMath_abs_float(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 152 | JValue* pResult); |
| 153 | |
| 154 | bool javaLangMath_abs_double(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 155 | JValue* pResult); |
| 156 | |
| 157 | bool javaLangMath_min_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 158 | JValue* pResult); |
| 159 | |
| 160 | bool javaLangMath_max_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 161 | JValue* pResult); |
| 162 | |
| 163 | bool javaLangMath_sqrt(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 164 | JValue* pResult); |
| 165 | |
| 166 | bool javaLangMath_cos(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 167 | JValue* pResult); |
| 168 | |
| 169 | bool javaLangMath_sin(u4 arg0, u4 arg1, u4 arg2, u4 arg3, |
| 170 | JValue* pResult); |
| 171 | |
| 172 | bool javaLangFloat_floatToIntBits(u4 arg0, u4 arg1, u4 arg2, u4 arg, |
| 173 | JValue* pResult); |
| 174 | |
| 175 | bool javaLangFloat_floatToRawIntBits(u4 arg0, u4 arg1, u4 arg2, u4 arg, |
| 176 | JValue* pResult); |
| 177 | |
| 178 | bool javaLangFloat_intBitsToFloat(u4 arg0, u4 arg1, u4 arg2, u4 arg, |
| 179 | JValue* pResult); |
| 180 | |
| 181 | bool javaLangDouble_doubleToLongBits(u4 arg0, u4 arg1, u4 arg2, u4 arg, |
| 182 | JValue* pResult); |
| 183 | |
| 184 | bool javaLangDouble_longBitsToDouble(u4 arg0, u4 arg1, u4 arg2, u4 arg, |
| 185 | JValue* pResult); |
| 186 | |
| 187 | bool javaLangDouble_doubleToRawLongBits(u4 arg0, u4 arg1, u4 arg2, |
| 188 | u4 arg, JValue* pResult); |
| 189 | |
| 190 | bool javaLangDouble_longBitsToDouble(u4 arg0, u4 arg1, u4 arg2, u4 arg, |
| 191 | JValue* pResult); |
| 192 | |
Carl Shapiro | 375fb11 | 2011-06-14 20:31:24 -0700 | [diff] [blame] | 193 | #endif // DALVIK_INLINENATIVE_H_ |