Home | History | Annotate | Download | only in vm
      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  */
     16 
     17 /*
     18  * Inlined native functions.
     19  */
     20 #ifndef DALVIK_INLINENATIVE_H_
     21 #define DALVIK_INLINENATIVE_H_
     22 
     23 /* startup/shutdown */
     24 bool dvmInlineNativeStartup(void);
     25 void dvmInlineNativeShutdown(void);
     26 
     27 Method* dvmFindInlinableMethod(const char* classDescriptor,
     28     const char* methodName, const char* methodSignature);
     29 
     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  */
     48 struct InlineOperation {
     49     InlineOp4Func   func;               /* MUST be first entry */
     50     const char*     classDescriptor;
     51     const char*     methodName;
     52     const char*     methodSignature;
     53 };
     54 
     55 /*
     56  * Must be kept in sync w/ gDvmInlineOpsTable in InlineNative.cpp
     57  *
     58  * You should also add a test to libcore's IntrinsicTest.
     59  */
     60 enum NativeInlineOps {
     61     INLINE_EMPTYINLINEMETHOD = 0,
     62     INLINE_STRING_CHARAT = 1,
     63     INLINE_STRING_COMPARETO = 2,
     64     INLINE_STRING_EQUALS = 3,
     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,
     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,
     83     INLINE_STRICT_MATH_ABS_INT = 22,
     84     INLINE_STRICT_MATH_ABS_LONG = 23,
     85     INLINE_STRICT_MATH_ABS_FLOAT = 24,
     86     INLINE_STRICT_MATH_ABS_DOUBLE = 25,
     87     INLINE_STRICT_MATH_MIN_INT = 26,
     88     INLINE_STRICT_MATH_MAX_INT = 27,
     89     INLINE_STRICT_MATH_SQRT = 28,
     90 };
     91 
     92 /*
     93  * Get the inlineops table.
     94  */
     95 const InlineOperation* dvmGetInlineOpsTable(void);
     96 int dvmGetInlineOpsTableLength(void);
     97 
     98 /*
     99  * The table, exposed so we can access it with C inlines.  Prefer access
    100  * through dvmGetInlineOpsTable().
    101  */
    102 extern const InlineOperation gDvmInlineOpsTable[];
    103 
    104 /*
    105  * Perform the operation specified by "opIndex".
    106  *
    107  * We want the arguments to appear in the first 4 registers so they can
    108  * be passed straight through to the handler function.  Ideally on ARM
    109  * they'll go into r0-r3 and stay there.
    110  *
    111  * Returns "true" if everything went normally, "false" if an exception
    112  * was thrown.
    113  */
    114 INLINE bool dvmPerformInlineOp4Std(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    115     JValue* pResult, int opIndex)
    116 {
    117     return (*gDvmInlineOpsTable[opIndex].func)(arg0, arg1, arg2, arg3, pResult);
    118 }
    119 
    120 /*
    121  * Like the "std" version, but will emit profiling info.
    122  */
    123 bool dvmPerformInlineOp4Dbg(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    124     JValue* pResult, int opIndex);
    125 
    126 /*
    127  * Return method & populate the table on first use.
    128  */
    129 extern "C" Method* dvmResolveInlineNative(int opIndex);
    130 
    131 /*
    132  * The actual inline native definitions.
    133  */
    134 bool javaLangString_charAt(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    135                            JValue* pResult);
    136 
    137 bool javaLangString_compareTo(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    138                               JValue* pResult);
    139 
    140 bool javaLangString_equals(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    141                            JValue* pResult);
    142 
    143 bool javaLangString_length(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    144                            JValue* pResult);
    145 
    146 bool javaLangString_isEmpty(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    147                             JValue* pResult);
    148 
    149 bool javaLangString_fastIndexOf_II(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    150                                    JValue* pResult);
    151 
    152 bool javaLangMath_abs_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    153                           JValue* pResult);
    154 
    155 bool javaLangMath_abs_long(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    156                            JValue* pResult);
    157 
    158 bool javaLangMath_abs_float(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    159                             JValue* pResult);
    160 
    161 bool javaLangMath_abs_double(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    162                              JValue* pResult);
    163 
    164 bool javaLangMath_min_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    165                           JValue* pResult);
    166 
    167 bool javaLangMath_max_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    168                           JValue* pResult);
    169 
    170 bool javaLangMath_sqrt(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    171                        JValue* pResult);
    172 
    173 bool javaLangMath_cos(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    174                       JValue* pResult);
    175 
    176 bool javaLangMath_sin(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    177                       JValue* pResult);
    178 
    179 bool javaLangFloat_floatToIntBits(u4 arg0, u4 arg1, u4 arg2, u4 arg,
    180                                   JValue* pResult);
    181 
    182 bool javaLangFloat_floatToRawIntBits(u4 arg0, u4 arg1, u4 arg2, u4 arg,
    183                                      JValue* pResult);
    184 
    185 bool javaLangFloat_intBitsToFloat(u4 arg0, u4 arg1, u4 arg2, u4 arg,
    186                                   JValue* pResult);
    187 
    188 bool javaLangDouble_doubleToLongBits(u4 arg0, u4 arg1, u4 arg2, u4 arg,
    189                                      JValue* pResult);
    190 
    191 bool javaLangDouble_longBitsToDouble(u4 arg0, u4 arg1, u4 arg2, u4 arg,
    192                                      JValue* pResult);
    193 
    194 bool javaLangDouble_doubleToRawLongBits(u4 arg0, u4 arg1, u4 arg2,
    195                                         u4 arg, JValue* pResult);
    196 
    197 bool javaLangDouble_longBitsToDouble(u4 arg0, u4 arg1, u4 arg2, u4 arg,
    198                                      JValue* pResult);
    199 
    200 #endif  // DALVIK_INLINENATIVE_H_
    201