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