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 "atomic.h"
18 #include "entrypoints/interpreter/interpreter_entrypoints.h"
19 #include "entrypoints/jni/jni_entrypoints.h"
20 #include "entrypoints/quick/quick_alloc_entrypoints.h"
21 #include "entrypoints/quick/quick_default_externs.h"
22 #include "entrypoints/quick/quick_entrypoints.h"
23 #include "entrypoints/entrypoint_utils.h"
24 #include "entrypoints/math_entrypoints.h"
25 #include "entrypoints/runtime_asm_entrypoints.h"
26 #include "entrypoints_direct_mips.h"
27 #include "interpreter/interpreter.h"
28
29 namespace art {
30
31 // Cast entrypoints.
32 extern "C" uint32_t artIsAssignableFromCode(const mirror::Class* klass,
33 const mirror::Class* ref_class);
34
35 // Math entrypoints.
36 extern int32_t CmpgDouble(double a, double b);
37 extern int32_t CmplDouble(double a, double b);
38 extern int32_t CmpgFloat(float a, float b);
39 extern int32_t CmplFloat(float a, float b);
40 extern "C" int64_t artLmul(int64_t a, int64_t b);
41 extern "C" int64_t artLdiv(int64_t a, int64_t b);
42 extern "C" int64_t artLmod(int64_t a, int64_t b);
43
44 // Math conversions.
45 extern "C" int32_t __fixsfsi(float op1); // FLOAT_TO_INT
46 extern "C" int32_t __fixdfsi(double op1); // DOUBLE_TO_INT
47 extern "C" float __floatdisf(int64_t op1); // LONG_TO_FLOAT
48 extern "C" double __floatdidf(int64_t op1); // LONG_TO_DOUBLE
49 extern "C" int64_t __fixsfdi(float op1); // FLOAT_TO_LONG
50 extern "C" int64_t __fixdfdi(double op1); // DOUBLE_TO_LONG
51
52 // Single-precision FP arithmetics.
53 extern "C" float fmodf(float a, float b); // REM_FLOAT[_2ADDR]
54
55 // Double-precision FP arithmetics.
56 extern "C" double fmod(double a, double b); // REM_DOUBLE[_2ADDR]
57
58 // Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR]
59 extern "C" int64_t __divdi3(int64_t, int64_t);
60 extern "C" int64_t __moddi3(int64_t, int64_t);
61
InitEntryPoints(InterpreterEntryPoints * ipoints,JniEntryPoints * jpoints,QuickEntryPoints * qpoints)62 void InitEntryPoints(InterpreterEntryPoints* ipoints, JniEntryPoints* jpoints,
63 QuickEntryPoints* qpoints) {
64 // Interpreter
65 ipoints->pInterpreterToInterpreterBridge = artInterpreterToInterpreterBridge;
66 ipoints->pInterpreterToCompiledCodeBridge = artInterpreterToCompiledCodeBridge;
67
68 // JNI
69 jpoints->pDlsymLookup = art_jni_dlsym_lookup_stub;
70
71 // Alloc
72 ResetQuickAllocEntryPoints(qpoints);
73
74 // Cast
75 qpoints->pInstanceofNonTrivial = artIsAssignableFromCode;
76 static_assert(IsDirectEntrypoint(kQuickInstanceofNonTrivial), "Direct C stub not marked direct.");
77 qpoints->pCheckCast = art_quick_check_cast;
78 static_assert(!IsDirectEntrypoint(kQuickCheckCast), "Non-direct C stub marked direct.");
79
80 // DexCache
81 qpoints->pInitializeStaticStorage = art_quick_initialize_static_storage;
82 static_assert(!IsDirectEntrypoint(kQuickInitializeStaticStorage),
83 "Non-direct C stub marked direct.");
84 qpoints->pInitializeTypeAndVerifyAccess = art_quick_initialize_type_and_verify_access;
85 static_assert(!IsDirectEntrypoint(kQuickInitializeTypeAndVerifyAccess),
86 "Non-direct C stub marked direct.");
87 qpoints->pInitializeType = art_quick_initialize_type;
88 static_assert(!IsDirectEntrypoint(kQuickInitializeType), "Non-direct C stub marked direct.");
89 qpoints->pResolveString = art_quick_resolve_string;
90 static_assert(!IsDirectEntrypoint(kQuickResolveString), "Non-direct C stub marked direct.");
91
92 // Field
93 qpoints->pSet8Instance = art_quick_set8_instance;
94 static_assert(!IsDirectEntrypoint(kQuickSet8Instance), "Non-direct C stub marked direct.");
95 qpoints->pSet8Static = art_quick_set8_static;
96 static_assert(!IsDirectEntrypoint(kQuickSet8Static), "Non-direct C stub marked direct.");
97 qpoints->pSet16Instance = art_quick_set16_instance;
98 static_assert(!IsDirectEntrypoint(kQuickSet16Instance), "Non-direct C stub marked direct.");
99 qpoints->pSet16Static = art_quick_set16_static;
100 static_assert(!IsDirectEntrypoint(kQuickSet16Static), "Non-direct C stub marked direct.");
101 qpoints->pSet32Instance = art_quick_set32_instance;
102 static_assert(!IsDirectEntrypoint(kQuickSet32Instance), "Non-direct C stub marked direct.");
103 qpoints->pSet32Static = art_quick_set32_static;
104 static_assert(!IsDirectEntrypoint(kQuickSet32Static), "Non-direct C stub marked direct.");
105 qpoints->pSet64Instance = art_quick_set64_instance;
106 static_assert(!IsDirectEntrypoint(kQuickSet64Instance), "Non-direct C stub marked direct.");
107 qpoints->pSet64Static = art_quick_set64_static;
108 static_assert(!IsDirectEntrypoint(kQuickSet64Static), "Non-direct C stub marked direct.");
109 qpoints->pSetObjInstance = art_quick_set_obj_instance;
110 static_assert(!IsDirectEntrypoint(kQuickSetObjInstance), "Non-direct C stub marked direct.");
111 qpoints->pSetObjStatic = art_quick_set_obj_static;
112 static_assert(!IsDirectEntrypoint(kQuickSetObjStatic), "Non-direct C stub marked direct.");
113 qpoints->pGetBooleanInstance = art_quick_get_boolean_instance;
114 static_assert(!IsDirectEntrypoint(kQuickGetBooleanInstance), "Non-direct C stub marked direct.");
115 qpoints->pGetByteInstance = art_quick_get_byte_instance;
116 static_assert(!IsDirectEntrypoint(kQuickGetByteInstance), "Non-direct C stub marked direct.");
117 qpoints->pGetCharInstance = art_quick_get_char_instance;
118 static_assert(!IsDirectEntrypoint(kQuickGetCharInstance), "Non-direct C stub marked direct.");
119 qpoints->pGetShortInstance = art_quick_get_short_instance;
120 static_assert(!IsDirectEntrypoint(kQuickGetShortInstance), "Non-direct C stub marked direct.");
121 qpoints->pGet32Instance = art_quick_get32_instance;
122 static_assert(!IsDirectEntrypoint(kQuickGet32Instance), "Non-direct C stub marked direct.");
123 qpoints->pGet64Instance = art_quick_get64_instance;
124 static_assert(!IsDirectEntrypoint(kQuickGet64Instance), "Non-direct C stub marked direct.");
125 qpoints->pGetObjInstance = art_quick_get_obj_instance;
126 static_assert(!IsDirectEntrypoint(kQuickGetObjInstance), "Non-direct C stub marked direct.");
127 qpoints->pGetBooleanStatic = art_quick_get_boolean_static;
128 static_assert(!IsDirectEntrypoint(kQuickGetBooleanStatic), "Non-direct C stub marked direct.");
129 qpoints->pGetByteStatic = art_quick_get_byte_static;
130 static_assert(!IsDirectEntrypoint(kQuickGetByteStatic), "Non-direct C stub marked direct.");
131 qpoints->pGetCharStatic = art_quick_get_char_static;
132 static_assert(!IsDirectEntrypoint(kQuickGetCharStatic), "Non-direct C stub marked direct.");
133 qpoints->pGetShortStatic = art_quick_get_short_static;
134 static_assert(!IsDirectEntrypoint(kQuickGetShortStatic), "Non-direct C stub marked direct.");
135 qpoints->pGet32Static = art_quick_get32_static;
136 static_assert(!IsDirectEntrypoint(kQuickGet32Static), "Non-direct C stub marked direct.");
137 qpoints->pGet64Static = art_quick_get64_static;
138 static_assert(!IsDirectEntrypoint(kQuickGet64Static), "Non-direct C stub marked direct.");
139 qpoints->pGetObjStatic = art_quick_get_obj_static;
140 static_assert(!IsDirectEntrypoint(kQuickGetObjStatic), "Non-direct C stub marked direct.");
141
142 // Array
143 qpoints->pAputObjectWithNullAndBoundCheck = art_quick_aput_obj_with_null_and_bound_check;
144 static_assert(!IsDirectEntrypoint(kQuickAputObjectWithNullAndBoundCheck),
145 "Non-direct C stub marked direct.");
146 qpoints->pAputObjectWithBoundCheck = art_quick_aput_obj_with_bound_check;
147 static_assert(!IsDirectEntrypoint(kQuickAputObjectWithBoundCheck),
148 "Non-direct C stub marked direct.");
149 qpoints->pAputObject = art_quick_aput_obj;
150 static_assert(!IsDirectEntrypoint(kQuickAputObject), "Non-direct C stub marked direct.");
151 qpoints->pHandleFillArrayData = art_quick_handle_fill_data;
152 static_assert(!IsDirectEntrypoint(kQuickHandleFillArrayData), "Non-direct C stub marked direct.");
153
154 // JNI
155 qpoints->pJniMethodStart = JniMethodStart;
156 static_assert(!IsDirectEntrypoint(kQuickJniMethodStart), "Non-direct C stub marked direct.");
157 qpoints->pJniMethodStartSynchronized = JniMethodStartSynchronized;
158 static_assert(!IsDirectEntrypoint(kQuickJniMethodStartSynchronized),
159 "Non-direct C stub marked direct.");
160 qpoints->pJniMethodEnd = JniMethodEnd;
161 static_assert(!IsDirectEntrypoint(kQuickJniMethodEnd), "Non-direct C stub marked direct.");
162 qpoints->pJniMethodEndSynchronized = JniMethodEndSynchronized;
163 static_assert(!IsDirectEntrypoint(kQuickJniMethodEndSynchronized),
164 "Non-direct C stub marked direct.");
165 qpoints->pJniMethodEndWithReference = JniMethodEndWithReference;
166 static_assert(!IsDirectEntrypoint(kQuickJniMethodEndWithReference),
167 "Non-direct C stub marked direct.");
168 qpoints->pJniMethodEndWithReferenceSynchronized = JniMethodEndWithReferenceSynchronized;
169 static_assert(!IsDirectEntrypoint(kQuickJniMethodEndWithReferenceSynchronized),
170 "Non-direct C stub marked direct.");
171 qpoints->pQuickGenericJniTrampoline = art_quick_generic_jni_trampoline;
172 static_assert(!IsDirectEntrypoint(kQuickQuickGenericJniTrampoline),
173 "Non-direct C stub marked direct.");
174
175 // Locks
176 qpoints->pLockObject = art_quick_lock_object;
177 static_assert(!IsDirectEntrypoint(kQuickLockObject), "Non-direct C stub marked direct.");
178 qpoints->pUnlockObject = art_quick_unlock_object;
179 static_assert(!IsDirectEntrypoint(kQuickUnlockObject), "Non-direct C stub marked direct.");
180
181 // Math
182 qpoints->pCmpgDouble = CmpgDouble;
183 static_assert(IsDirectEntrypoint(kQuickCmpgDouble), "Direct C stub not marked direct.");
184 qpoints->pCmpgFloat = CmpgFloat;
185 static_assert(IsDirectEntrypoint(kQuickCmpgFloat), "Direct C stub not marked direct.");
186 qpoints->pCmplDouble = CmplDouble;
187 static_assert(IsDirectEntrypoint(kQuickCmplDouble), "Direct C stub not marked direct.");
188 qpoints->pCmplFloat = CmplFloat;
189 static_assert(IsDirectEntrypoint(kQuickCmplFloat), "Direct C stub not marked direct.");
190 qpoints->pFmod = fmod;
191 static_assert(IsDirectEntrypoint(kQuickFmod), "Direct C stub not marked direct.");
192 qpoints->pL2d = art_l2d;
193 static_assert(IsDirectEntrypoint(kQuickL2d), "Direct C stub not marked direct.");
194 qpoints->pFmodf = fmodf;
195 static_assert(IsDirectEntrypoint(kQuickFmodf), "Direct C stub not marked direct.");
196 qpoints->pL2f = art_l2f;
197 static_assert(IsDirectEntrypoint(kQuickL2f), "Direct C stub not marked direct.");
198 qpoints->pD2iz = art_d2i;
199 static_assert(IsDirectEntrypoint(kQuickD2iz), "Direct C stub not marked direct.");
200 qpoints->pF2iz = art_f2i;
201 static_assert(IsDirectEntrypoint(kQuickF2iz), "Direct C stub not marked direct.");
202 qpoints->pIdivmod = nullptr;
203 qpoints->pD2l = art_d2l;
204 static_assert(IsDirectEntrypoint(kQuickD2l), "Direct C stub not marked direct.");
205 qpoints->pF2l = art_f2l;
206 static_assert(IsDirectEntrypoint(kQuickF2l), "Direct C stub not marked direct.");
207 qpoints->pLdiv = artLdiv;
208 static_assert(IsDirectEntrypoint(kQuickLdiv), "Direct C stub not marked direct.");
209 qpoints->pLmod = artLmod;
210 static_assert(IsDirectEntrypoint(kQuickLmod), "Direct C stub not marked direct.");
211 qpoints->pLmul = artLmul;
212 static_assert(IsDirectEntrypoint(kQuickLmul), "Direct C stub not marked direct.");
213 qpoints->pShlLong = art_quick_shl_long;
214 static_assert(!IsDirectEntrypoint(kQuickShlLong), "Non-direct C stub marked direct.");
215 qpoints->pShrLong = art_quick_shr_long;
216 static_assert(!IsDirectEntrypoint(kQuickShrLong), "Non-direct C stub marked direct.");
217 qpoints->pUshrLong = art_quick_ushr_long;
218 static_assert(!IsDirectEntrypoint(kQuickUshrLong), "Non-direct C stub marked direct.");
219
220 // Intrinsics
221 qpoints->pIndexOf = art_quick_indexof;
222 static_assert(!IsDirectEntrypoint(kQuickIndexOf), "Non-direct C stub marked direct.");
223 qpoints->pStringCompareTo = art_quick_string_compareto;
224 static_assert(!IsDirectEntrypoint(kQuickStringCompareTo), "Non-direct C stub marked direct.");
225 qpoints->pMemcpy = memcpy;
226
227 // Invocation
228 qpoints->pQuickImtConflictTrampoline = art_quick_imt_conflict_trampoline;
229 qpoints->pQuickResolutionTrampoline = art_quick_resolution_trampoline;
230 qpoints->pQuickToInterpreterBridge = art_quick_to_interpreter_bridge;
231 qpoints->pInvokeDirectTrampolineWithAccessCheck =
232 art_quick_invoke_direct_trampoline_with_access_check;
233 static_assert(!IsDirectEntrypoint(kQuickInvokeDirectTrampolineWithAccessCheck),
234 "Non-direct C stub marked direct.");
235 qpoints->pInvokeInterfaceTrampolineWithAccessCheck =
236 art_quick_invoke_interface_trampoline_with_access_check;
237 static_assert(!IsDirectEntrypoint(kQuickInvokeInterfaceTrampolineWithAccessCheck),
238 "Non-direct C stub marked direct.");
239 qpoints->pInvokeStaticTrampolineWithAccessCheck =
240 art_quick_invoke_static_trampoline_with_access_check;
241 static_assert(!IsDirectEntrypoint(kQuickInvokeStaticTrampolineWithAccessCheck),
242 "Non-direct C stub marked direct.");
243 qpoints->pInvokeSuperTrampolineWithAccessCheck =
244 art_quick_invoke_super_trampoline_with_access_check;
245 static_assert(!IsDirectEntrypoint(kQuickInvokeSuperTrampolineWithAccessCheck),
246 "Non-direct C stub marked direct.");
247 qpoints->pInvokeVirtualTrampolineWithAccessCheck =
248 art_quick_invoke_virtual_trampoline_with_access_check;
249 static_assert(!IsDirectEntrypoint(kQuickInvokeVirtualTrampolineWithAccessCheck),
250 "Non-direct C stub marked direct.");
251
252 // Thread
253 qpoints->pTestSuspend = art_quick_test_suspend;
254 static_assert(!IsDirectEntrypoint(kQuickTestSuspend), "Non-direct C stub marked direct.");
255
256 // Throws
257 qpoints->pDeliverException = art_quick_deliver_exception;
258 static_assert(!IsDirectEntrypoint(kQuickDeliverException), "Non-direct C stub marked direct.");
259 qpoints->pThrowArrayBounds = art_quick_throw_array_bounds;
260 static_assert(!IsDirectEntrypoint(kQuickThrowArrayBounds), "Non-direct C stub marked direct.");
261 qpoints->pThrowDivZero = art_quick_throw_div_zero;
262 static_assert(!IsDirectEntrypoint(kQuickThrowDivZero), "Non-direct C stub marked direct.");
263 qpoints->pThrowNoSuchMethod = art_quick_throw_no_such_method;
264 static_assert(!IsDirectEntrypoint(kQuickThrowNoSuchMethod), "Non-direct C stub marked direct.");
265 qpoints->pThrowNullPointer = art_quick_throw_null_pointer_exception;
266 static_assert(!IsDirectEntrypoint(kQuickThrowNullPointer), "Non-direct C stub marked direct.");
267 qpoints->pThrowStackOverflow = art_quick_throw_stack_overflow;
268 static_assert(!IsDirectEntrypoint(kQuickThrowStackOverflow), "Non-direct C stub marked direct.");
269
270 // Deoptimize
271 qpoints->pDeoptimize = art_quick_deoptimize;
272 static_assert(!IsDirectEntrypoint(kQuickDeoptimize), "Non-direct C stub marked direct.");
273
274 // Atomic 64-bit load/store
275 qpoints->pA64Load = QuasiAtomic::Read64;
276 static_assert(IsDirectEntrypoint(kQuickA64Load), "Non-direct C stub marked direct.");
277 qpoints->pA64Store = QuasiAtomic::Write64;
278 static_assert(IsDirectEntrypoint(kQuickA64Store), "Non-direct C stub marked direct.");
279
280 qpoints->pReadBarrierJni = ReadBarrierJni;
281 static_assert(!IsDirectEntrypoint(kQuickReadBarrierJni), "Non-direct C stub marked direct.");
282 };
283
284 } // namespace art
285