1 /*
2 * Copyright (C) 2012 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 #include "entrypoints/interpreter/interpreter_entrypoints.h"
18 #include "entrypoints/jni/jni_entrypoints.h"
19 #include "entrypoints/portable/portable_entrypoints.h"
20 #include "entrypoints/quick/quick_alloc_entrypoints.h"
21 #include "entrypoints/quick/quick_entrypoints.h"
22 #include "entrypoints/entrypoint_utils.h"
23 #include "entrypoints/math_entrypoints.h"
24 #include "atomic.h"
25
26 namespace art {
27
28 // Interpreter entrypoints.
29 extern "C" void artInterpreterToInterpreterBridge(Thread* self, MethodHelper& mh,
30 const DexFile::CodeItem* code_item,
31 ShadowFrame* shadow_frame, JValue* result);
32 extern "C" void artInterpreterToCompiledCodeBridge(Thread* self, MethodHelper& mh,
33 const DexFile::CodeItem* code_item,
34 ShadowFrame* shadow_frame, JValue* result);
35
36 // Portable entrypoints.
37 extern "C" void art_portable_resolution_trampoline(mirror::ArtMethod*);
38 extern "C" void art_portable_to_interpreter_bridge(mirror::ArtMethod*);
39
40 // Cast entrypoints.
41 extern "C" uint32_t artIsAssignableFromCode(const mirror::Class* klass,
42 const mirror::Class* ref_class);
43 extern "C" void art_quick_check_cast(void*, void*);
44
45 // DexCache entrypoints.
46 extern "C" void* art_quick_initialize_static_storage(uint32_t, void*);
47 extern "C" void* art_quick_initialize_type(uint32_t, void*);
48 extern "C" void* art_quick_initialize_type_and_verify_access(uint32_t, void*);
49 extern "C" void* art_quick_resolve_string(void*, uint32_t);
50
51 // Field entrypoints.
52 extern "C" int art_quick_set32_instance(uint32_t, void*, int32_t);
53 extern "C" int art_quick_set32_static(uint32_t, int32_t);
54 extern "C" int art_quick_set64_instance(uint32_t, void*, int64_t);
55 extern "C" int art_quick_set64_static(uint32_t, int64_t);
56 extern "C" int art_quick_set_obj_instance(uint32_t, void*, void*);
57 extern "C" int art_quick_set_obj_static(uint32_t, void*);
58 extern "C" int32_t art_quick_get32_instance(uint32_t, void*);
59 extern "C" int32_t art_quick_get32_static(uint32_t);
60 extern "C" int64_t art_quick_get64_instance(uint32_t, void*);
61 extern "C" int64_t art_quick_get64_static(uint32_t);
62 extern "C" void* art_quick_get_obj_instance(uint32_t, void*);
63 extern "C" void* art_quick_get_obj_static(uint32_t);
64
65 // Array entrypoints.
66 extern "C" void art_quick_aput_obj_with_null_and_bound_check(void*, uint32_t, void*);
67 extern "C" void art_quick_aput_obj_with_bound_check(void*, uint32_t, void*);
68 extern "C" void art_quick_aput_obj(void*, uint32_t, void*);
69 extern "C" void art_quick_handle_fill_data(void*, void*);
70
71 // Lock entrypoints.
72 extern "C" void art_quick_lock_object(void*);
73 extern "C" void art_quick_unlock_object(void*);
74
75 // Math entrypoints.
76 extern int32_t CmpgDouble(double a, double b);
77 extern int32_t CmplDouble(double a, double b);
78 extern int32_t CmpgFloat(float a, float b);
79 extern int32_t CmplFloat(float a, float b);
80 extern "C" int64_t artLmul(int64_t a, int64_t b);
81 extern "C" int64_t artLdiv(int64_t a, int64_t b);
82 extern "C" int64_t artLmod(int64_t a, int64_t b);
83
84 // Math conversions.
85 extern "C" int32_t __fixsfsi(float op1); // FLOAT_TO_INT
86 extern "C" int32_t __fixdfsi(double op1); // DOUBLE_TO_INT
87 extern "C" float __floatdisf(int64_t op1); // LONG_TO_FLOAT
88 extern "C" double __floatdidf(int64_t op1); // LONG_TO_DOUBLE
89 extern "C" int64_t __fixsfdi(float op1); // FLOAT_TO_LONG
90 extern "C" int64_t __fixdfdi(double op1); // DOUBLE_TO_LONG
91
92 // Single-precision FP arithmetics.
93 extern "C" float fmodf(float a, float b); // REM_FLOAT[_2ADDR]
94
95 // Double-precision FP arithmetics.
96 extern "C" double fmod(double a, double b); // REM_DOUBLE[_2ADDR]
97
98 // Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR]
99 extern "C" int64_t __divdi3(int64_t, int64_t);
100 extern "C" int64_t __moddi3(int64_t, int64_t);
101 extern "C" uint64_t art_quick_shl_long(uint64_t, uint32_t);
102 extern "C" uint64_t art_quick_shr_long(uint64_t, uint32_t);
103 extern "C" uint64_t art_quick_ushr_long(uint64_t, uint32_t);
104
105 // Intrinsic entrypoints.
106 extern "C" int32_t art_quick_indexof(void*, uint32_t, uint32_t, uint32_t);
107 extern "C" int32_t art_quick_string_compareto(void*, void*);
108
109 // Invoke entrypoints.
110 extern "C" void art_quick_imt_conflict_trampoline(mirror::ArtMethod*);
111 extern "C" void art_quick_resolution_trampoline(mirror::ArtMethod*);
112 extern "C" void art_quick_to_interpreter_bridge(mirror::ArtMethod*);
113 extern "C" void art_quick_invoke_direct_trampoline_with_access_check(uint32_t, void*);
114 extern "C" void art_quick_invoke_interface_trampoline_with_access_check(uint32_t, void*);
115 extern "C" void art_quick_invoke_static_trampoline_with_access_check(uint32_t, void*);
116 extern "C" void art_quick_invoke_super_trampoline_with_access_check(uint32_t, void*);
117 extern "C" void art_quick_invoke_virtual_trampoline_with_access_check(uint32_t, void*);
118
119 // Thread entrypoints.
120 extern "C" void art_quick_test_suspend();
121
122 // Throw entrypoints.
123 extern "C" void art_quick_deliver_exception(void*);
124 extern "C" void art_quick_throw_array_bounds(int32_t index, int32_t limit);
125 extern "C" void art_quick_throw_div_zero();
126 extern "C" void art_quick_throw_no_such_method(int32_t method_idx);
127 extern "C" void art_quick_throw_null_pointer_exception();
128 extern "C" void art_quick_throw_stack_overflow(void*);
129
130 // Generic JNI downcall
131 extern "C" void art_quick_generic_jni_trampoline(mirror::ArtMethod*);
132
133 extern void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints);
134
InitEntryPoints(InterpreterEntryPoints * ipoints,JniEntryPoints * jpoints,PortableEntryPoints * ppoints,QuickEntryPoints * qpoints)135 void InitEntryPoints(InterpreterEntryPoints* ipoints, JniEntryPoints* jpoints,
136 PortableEntryPoints* ppoints, QuickEntryPoints* qpoints) {
137 // Interpreter
138 ipoints->pInterpreterToInterpreterBridge = artInterpreterToInterpreterBridge;
139 ipoints->pInterpreterToCompiledCodeBridge = artInterpreterToCompiledCodeBridge;
140
141 // JNI
142 jpoints->pDlsymLookup = art_jni_dlsym_lookup_stub;
143
144 // Portable
145 ppoints->pPortableResolutionTrampoline = art_portable_resolution_trampoline;
146 ppoints->pPortableToInterpreterBridge = art_portable_to_interpreter_bridge;
147
148 // Alloc
149 ResetQuickAllocEntryPoints(qpoints);
150
151 // Cast
152 qpoints->pInstanceofNonTrivial = artIsAssignableFromCode;
153 qpoints->pCheckCast = art_quick_check_cast;
154
155 // DexCache
156 qpoints->pInitializeStaticStorage = art_quick_initialize_static_storage;
157 qpoints->pInitializeTypeAndVerifyAccess = art_quick_initialize_type_and_verify_access;
158 qpoints->pInitializeType = art_quick_initialize_type;
159 qpoints->pResolveString = art_quick_resolve_string;
160
161 // Field
162 qpoints->pSet32Instance = art_quick_set32_instance;
163 qpoints->pSet32Static = art_quick_set32_static;
164 qpoints->pSet64Instance = art_quick_set64_instance;
165 qpoints->pSet64Static = art_quick_set64_static;
166 qpoints->pSetObjInstance = art_quick_set_obj_instance;
167 qpoints->pSetObjStatic = art_quick_set_obj_static;
168 qpoints->pGet32Instance = art_quick_get32_instance;
169 qpoints->pGet64Instance = art_quick_get64_instance;
170 qpoints->pGetObjInstance = art_quick_get_obj_instance;
171 qpoints->pGet32Static = art_quick_get32_static;
172 qpoints->pGet64Static = art_quick_get64_static;
173 qpoints->pGetObjStatic = art_quick_get_obj_static;
174
175 // Array
176 qpoints->pAputObjectWithNullAndBoundCheck = art_quick_aput_obj_with_null_and_bound_check;
177 qpoints->pAputObjectWithBoundCheck = art_quick_aput_obj_with_bound_check;
178 qpoints->pAputObject = art_quick_aput_obj;
179 qpoints->pHandleFillArrayData = art_quick_handle_fill_data;
180
181 // JNI
182 qpoints->pJniMethodStart = JniMethodStart;
183 qpoints->pJniMethodStartSynchronized = JniMethodStartSynchronized;
184 qpoints->pJniMethodEnd = JniMethodEnd;
185 qpoints->pJniMethodEndSynchronized = JniMethodEndSynchronized;
186 qpoints->pJniMethodEndWithReference = JniMethodEndWithReference;
187 qpoints->pJniMethodEndWithReferenceSynchronized = JniMethodEndWithReferenceSynchronized;
188 qpoints->pQuickGenericJniTrampoline = art_quick_generic_jni_trampoline;
189
190 // Locks
191 qpoints->pLockObject = art_quick_lock_object;
192 qpoints->pUnlockObject = art_quick_unlock_object;
193
194 // Math
195 qpoints->pCmpgDouble = CmpgDouble;
196 qpoints->pCmpgFloat = CmpgFloat;
197 qpoints->pCmplDouble = CmplDouble;
198 qpoints->pCmplFloat = CmplFloat;
199 qpoints->pFmod = fmod;
200 qpoints->pL2d = art_l2d;
201 qpoints->pFmodf = fmodf;
202 qpoints->pL2f = art_l2f;
203 qpoints->pD2iz = art_d2i;
204 qpoints->pF2iz = art_f2i;
205 qpoints->pIdivmod = NULL;
206 qpoints->pD2l = art_d2l;
207 qpoints->pF2l = art_f2l;
208 qpoints->pLdiv = artLdiv;
209 qpoints->pLmod = artLmod;
210 qpoints->pLmul = artLmul;
211 qpoints->pShlLong = art_quick_shl_long;
212 qpoints->pShrLong = art_quick_shr_long;
213 qpoints->pUshrLong = art_quick_ushr_long;
214
215 // Intrinsics
216 qpoints->pIndexOf = art_quick_indexof;
217 qpoints->pStringCompareTo = art_quick_string_compareto;
218 qpoints->pMemcpy = memcpy;
219
220 // Invocation
221 qpoints->pQuickImtConflictTrampoline = art_quick_imt_conflict_trampoline;
222 qpoints->pQuickResolutionTrampoline = art_quick_resolution_trampoline;
223 qpoints->pQuickToInterpreterBridge = art_quick_to_interpreter_bridge;
224 qpoints->pInvokeDirectTrampolineWithAccessCheck = art_quick_invoke_direct_trampoline_with_access_check;
225 qpoints->pInvokeInterfaceTrampolineWithAccessCheck = art_quick_invoke_interface_trampoline_with_access_check;
226 qpoints->pInvokeStaticTrampolineWithAccessCheck = art_quick_invoke_static_trampoline_with_access_check;
227 qpoints->pInvokeSuperTrampolineWithAccessCheck = art_quick_invoke_super_trampoline_with_access_check;
228 qpoints->pInvokeVirtualTrampolineWithAccessCheck = art_quick_invoke_virtual_trampoline_with_access_check;
229
230 // Thread
231 qpoints->pTestSuspend = art_quick_test_suspend;
232
233 // Throws
234 qpoints->pDeliverException = art_quick_deliver_exception;
235 qpoints->pThrowArrayBounds = art_quick_throw_array_bounds;
236 qpoints->pThrowDivZero = art_quick_throw_div_zero;
237 qpoints->pThrowNoSuchMethod = art_quick_throw_no_such_method;
238 qpoints->pThrowNullPointer = art_quick_throw_null_pointer_exception;
239 qpoints->pThrowStackOverflow = art_quick_throw_stack_overflow;
240
241 // Atomic 64-bit load/store
242 qpoints->pA64Load = QuasiAtomic::Read64;
243 qpoints->pA64Store = QuasiAtomic::Write64;
244 };
245
246 } // namespace art
247