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  * Inlined native functions.
     18  */
     19 #ifndef _DALVIK_INLINENATIVE
     20 #define _DALVIK_INLINENATIVE
     21 
     22 /* startup/shutdown */
     23 bool dvmInlineNativeStartup(void);
     24 void dvmInlineNativeShutdown(void);
     25 
     26 /*
     27  * Basic 4-argument inline operation handler.
     28  */
     29 typedef bool (*InlineOp4Func)(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
     30     JValue* pResult);
     31 
     32 /*
     33  * Table of inline operations.
     34  *
     35  * Try to keep this at a power-of-two size, so we don't have to multiply.
     36  *
     37  * TODO: might be to our advantage to generate a compact jump table on
     38  * the heap at runtime (or just declare two static tables, one with full
     39  * info and one with just function pointers).  Especially useful if we decide
     40  * to support other method call forms, e.g. /range.  We can also just
     41  * generate assembly code that knows how many args it needs and has the
     42  * target address embedded.
     43  */
     44 typedef struct InlineOperation {
     45     InlineOp4Func   func;               /* MUST be first entry */
     46     const char*     classDescriptor;
     47     const char*     methodName;
     48     const char*     methodSignature;
     49 } InlineOperation;
     50 
     51 /* Must be kept in sync w/ gDvmInlineOpsTable in InlineNative.c */
     52 typedef enum NativeInlineOps {
     53     INLINE_EMPTYINLINEMETHOD = 0,
     54     INLINE_STRING_CHARAT = 1,
     55     INLINE_STRING_COMPARETO = 2,
     56     INLINE_STRING_EQUALS = 3,
     57     INLINE_STRING_INDEXOF_I = 4,
     58     INLINE_STRING_INDEXOF_II = 5,
     59     INLINE_STRING_LENGTH = 6,
     60     INLINE_MATH_ABS_INT = 7,
     61     INLINE_MATH_ABS_LONG = 8,
     62     INLINE_MATH_ABS_FLOAT = 9,
     63     INLINE_MATH_ABS_DOUBLE = 10,
     64     INLINE_MATH_MIN_INT = 11,
     65     INLINE_MATH_MAX_INT = 12,
     66     INLINE_MATH_SQRT = 13,
     67     INLINE_MATH_COS = 14,
     68     INLINE_MATH_SIN = 15,
     69 } NativeInlineOps;
     70 
     71 /*
     72  * Get the inlineops table.
     73  */
     74 const InlineOperation* dvmGetInlineOpsTable(void);
     75 int dvmGetInlineOpsTableLength(void);
     76 
     77 /*
     78  * The table, exposed so we can access it with C inlines.  Prefer access
     79  * through dvmGetInlineOpsTable().
     80  */
     81 extern const InlineOperation gDvmInlineOpsTable[];
     82 
     83 /*
     84  * Perform the operation specified by "opIndex".
     85  *
     86  * We want the arguments to appear in the first 4 registers so they can
     87  * be passed straight through to the handler function.  Ideally on ARM
     88  * they'll go into r0-r3 and stay there.
     89  *
     90  * Returns "true" if everything went normally, "false" if an exception
     91  * was thrown.
     92  */
     93 INLINE bool dvmPerformInlineOp4Std(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
     94     JValue* pResult, int opIndex)
     95 {
     96     return (*gDvmInlineOpsTable[opIndex].func)(arg0, arg1, arg2, arg3, pResult);
     97 }
     98 
     99 /*
    100  * Like the "std" version, but will emit profiling info.
    101  */
    102 bool dvmPerformInlineOp4Dbg(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
    103     JValue* pResult, int opIndex);
    104 
    105 #endif /*_DALVIK_INLINENATIVE*/
    106