OSDN Git Service

am 565c5663: am 44dcf29d: Add include guards to avoid multiple definitions.
[android-x86/dalvik.git] / vm / InlineNative.h
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 bool dvmInlineNativeCheck(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 typedef struct InlineOperation {
49     InlineOp4Func   func;               /* MUST be first entry */
50     const char*     classDescriptor;
51     const char*     methodName;
52     const char*     methodSignature;
53 } InlineOperation;
54
55 /* Must be kept in sync w/ gDvmInlineOpsTable in InlineNative.c */
56 typedef enum NativeInlineOps {
57     INLINE_EMPTYINLINEMETHOD = 0,
58     INLINE_STRING_CHARAT = 1,
59     INLINE_STRING_COMPARETO = 2,
60     INLINE_STRING_EQUALS = 3,
61     INLINE_STRING_FASTINDEXOF_II = 4,
62     INLINE_STRING_IS_EMPTY = 5,
63     INLINE_STRING_LENGTH = 6,
64     INLINE_MATH_ABS_INT = 7,
65     INLINE_MATH_ABS_LONG = 8,
66     INLINE_MATH_ABS_FLOAT = 9,
67     INLINE_MATH_ABS_DOUBLE = 10,
68     INLINE_MATH_MIN_INT = 11,
69     INLINE_MATH_MAX_INT = 12,
70     INLINE_MATH_SQRT = 13,
71     INLINE_MATH_COS = 14,
72     INLINE_MATH_SIN = 15,
73     INLINE_FLOAT_TO_INT_BITS = 16,
74     INLINE_FLOAT_TO_RAW_INT_BITS = 17,
75     INLINE_INT_BITS_TO_FLOAT = 18,
76     INLINE_DOUBLE_TO_LONG_BITS = 19,
77     INLINE_DOUBLE_TO_RAW_LONG_BITS = 20,
78     INLINE_LONG_BITS_TO_DOUBLE = 21,
79 } NativeInlineOps;
80
81 /*
82  * Get the inlineops table.
83  */
84 const InlineOperation* dvmGetInlineOpsTable(void);
85 int dvmGetInlineOpsTableLength(void);
86
87 /*
88  * The table, exposed so we can access it with C inlines.  Prefer access
89  * through dvmGetInlineOpsTable().
90  */
91 extern const InlineOperation gDvmInlineOpsTable[];
92
93 /*
94  * Perform the operation specified by "opIndex".
95  *
96  * We want the arguments to appear in the first 4 registers so they can
97  * be passed straight through to the handler function.  Ideally on ARM
98  * they'll go into r0-r3 and stay there.
99  *
100  * Returns "true" if everything went normally, "false" if an exception
101  * was thrown.
102  */
103 INLINE bool dvmPerformInlineOp4Std(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
104     JValue* pResult, int opIndex)
105 {
106     return (*gDvmInlineOpsTable[opIndex].func)(arg0, arg1, arg2, arg3, pResult);
107 }
108
109 /*
110  * Like the "std" version, but will emit profiling info.
111  */
112 bool dvmPerformInlineOp4Dbg(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
113     JValue* pResult, int opIndex);
114
115 #endif /*_DALVIK_INLINENATIVE*/