blob: 331a46135493b12d8640c0d8efc0e08819f91d1a [file] [log] [blame]
Ian Rogers7655f292013-07-29 11:07:13 -07001/*
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/portable/portable_entrypoints.h"
18#include "entrypoints/quick/quick_entrypoints.h"
19#include "entrypoints/entrypoint_utils.h"
20#include "entrypoints/math_entrypoints.h"
21
22namespace art {
23
Ian Rogers848871b2013-08-05 10:56:33 -070024// Interpreter entrypoints.
25extern "C" void artInterpreterToInterpreterBridge(Thread* self, MethodHelper& mh,
26 const DexFile::CodeItem* code_item,
27 ShadowFrame* shadow_frame, JValue* result);
Dragos Sbirlea08bf1962013-08-12 08:53:04 -070028extern "C" void artInterpreterToCompiledCodeBridge(Thread* self, MethodHelper& mh,
Ian Rogers848871b2013-08-05 10:56:33 -070029 const DexFile::CodeItem* code_item,
30 ShadowFrame* shadow_frame, JValue* result);
31
32// Portable entrypoints.
Brian Carlstromea46f952013-07-30 01:26:50 -070033extern "C" void art_portable_resolution_trampoline(mirror::ArtMethod*);
34extern "C" void art_portable_to_interpreter_bridge(mirror::ArtMethod*);
Ian Rogers848871b2013-08-05 10:56:33 -070035
Ian Rogers7655f292013-07-29 11:07:13 -070036// Alloc entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -070037extern "C" void* art_quick_alloc_array(uint32_t, void*, int32_t);
38extern "C" void* art_quick_alloc_array_with_access_check(uint32_t, void*, int32_t);
39extern "C" void* art_quick_alloc_object(uint32_t type_idx, void* method);
40extern "C" void* art_quick_alloc_object_with_access_check(uint32_t type_idx, void* method);
41extern "C" void* art_quick_check_and_alloc_array(uint32_t, void*, int32_t);
42extern "C" void* art_quick_check_and_alloc_array_with_access_check(uint32_t, void*, int32_t);
Ian Rogers7655f292013-07-29 11:07:13 -070043
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070044extern "C" void* art_quick_alloc_array_instrumented(uint32_t, void*, int32_t);
45extern "C" void* art_quick_alloc_array_with_access_check_instrumented(uint32_t, void*, int32_t);
46extern "C" void* art_quick_alloc_object_instrumented(uint32_t type_idx, void* method);
47extern "C" void* art_quick_alloc_object_with_access_check_instrumented(uint32_t type_idx, void* method);
48extern "C" void* art_quick_check_and_alloc_array_instrumented(uint32_t, void*, int32_t);
49extern "C" void* art_quick_check_and_alloc_array_with_access_check_instrumented(uint32_t, void*, int32_t);
50
Ian Rogers7655f292013-07-29 11:07:13 -070051// Cast entrypoints.
52extern "C" uint32_t artIsAssignableFromCode(const mirror::Class* klass,
53 const mirror::Class* ref_class);
Ian Rogers848871b2013-08-05 10:56:33 -070054extern "C" void art_quick_check_cast(void*, void*);
Ian Rogers7655f292013-07-29 11:07:13 -070055
56// DexCache entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -070057extern "C" void* art_quick_initialize_static_storage(uint32_t, void*);
58extern "C" void* art_quick_initialize_type(uint32_t, void*);
59extern "C" void* art_quick_initialize_type_and_verify_access(uint32_t, void*);
60extern "C" void* art_quick_resolve_string(void*, uint32_t);
Ian Rogers7655f292013-07-29 11:07:13 -070061
62// Exception entrypoints.
63extern "C" void* GetAndClearException(Thread*);
64
65// Field entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -070066extern "C" int art_quick_set32_instance(uint32_t, void*, int32_t);
67extern "C" int art_quick_set32_static(uint32_t, int32_t);
68extern "C" int art_quick_set64_instance(uint32_t, void*, int64_t);
69extern "C" int art_quick_set64_static(uint32_t, int64_t);
70extern "C" int art_quick_set_obj_instance(uint32_t, void*, void*);
71extern "C" int art_quick_set_obj_static(uint32_t, void*);
72extern "C" int32_t art_quick_get32_instance(uint32_t, void*);
73extern "C" int32_t art_quick_get32_static(uint32_t);
74extern "C" int64_t art_quick_get64_instance(uint32_t, void*);
75extern "C" int64_t art_quick_get64_static(uint32_t);
76extern "C" void* art_quick_get_obj_instance(uint32_t, void*);
77extern "C" void* art_quick_get_obj_static(uint32_t);
Ian Rogers7655f292013-07-29 11:07:13 -070078
Ian Rogersa9a82542013-10-04 11:17:26 -070079// Array entrypoints.
80extern "C" void art_quick_aput_obj_with_null_and_bound_check(void*, uint32_t, void*);
81extern "C" void art_quick_aput_obj_with_bound_check(void*, uint32_t, void*);
82extern "C" void art_quick_aput_obj(void*, uint32_t, void*);
Ian Rogers848871b2013-08-05 10:56:33 -070083extern "C" void art_quick_handle_fill_data(void*, void*);
Ian Rogers7655f292013-07-29 11:07:13 -070084
85// Lock entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -070086extern "C" void art_quick_lock_object(void*);
87extern "C" void art_quick_unlock_object(void*);
Ian Rogers7655f292013-07-29 11:07:13 -070088
89// Math entrypoints.
90extern int32_t CmpgDouble(double a, double b);
91extern int32_t CmplDouble(double a, double b);
92extern int32_t CmpgFloat(float a, float b);
93extern int32_t CmplFloat(float a, float b);
Ian Rogersa9a82542013-10-04 11:17:26 -070094extern "C" int64_t artLmul(int64_t a, int64_t b);
95extern "C" int64_t artLdiv(int64_t a, int64_t b);
96extern "C" int64_t artLmod(int64_t a, int64_t b);
Ian Rogers7655f292013-07-29 11:07:13 -070097
98// Math conversions.
99extern "C" int32_t __fixsfsi(float op1); // FLOAT_TO_INT
100extern "C" int32_t __fixdfsi(double op1); // DOUBLE_TO_INT
101extern "C" float __floatdisf(int64_t op1); // LONG_TO_FLOAT
102extern "C" double __floatdidf(int64_t op1); // LONG_TO_DOUBLE
103extern "C" int64_t __fixsfdi(float op1); // FLOAT_TO_LONG
104extern "C" int64_t __fixdfdi(double op1); // DOUBLE_TO_LONG
105
106// Single-precision FP arithmetics.
107extern "C" float fmodf(float a, float b); // REM_FLOAT[_2ADDR]
108
109// Double-precision FP arithmetics.
110extern "C" double fmod(double a, double b); // REM_DOUBLE[_2ADDR]
111
112// Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR]
113extern "C" int64_t __divdi3(int64_t, int64_t);
114extern "C" int64_t __moddi3(int64_t, int64_t);
115extern "C" uint64_t art_quick_shl_long(uint64_t, uint32_t);
116extern "C" uint64_t art_quick_shr_long(uint64_t, uint32_t);
117extern "C" uint64_t art_quick_ushr_long(uint64_t, uint32_t);
118
Ian Rogers7655f292013-07-29 11:07:13 -0700119// Intrinsic entrypoints.
120extern "C" int32_t __memcmp16(void*, void*, int32_t);
121extern "C" int32_t art_quick_indexof(void*, uint32_t, uint32_t, uint32_t);
122extern "C" int32_t art_quick_string_compareto(void*, void*);
123
124// Invoke entrypoints.
Jeff Hao88474b42013-10-23 16:24:40 -0700125extern "C" void art_quick_imt_conflict_trampoline(mirror::ArtMethod*);
Brian Carlstromea46f952013-07-30 01:26:50 -0700126extern "C" void art_quick_resolution_trampoline(mirror::ArtMethod*);
127extern "C" void art_quick_to_interpreter_bridge(mirror::ArtMethod*);
Ian Rogers7655f292013-07-29 11:07:13 -0700128extern "C" void art_quick_invoke_direct_trampoline_with_access_check(uint32_t, void*);
Ian Rogers7655f292013-07-29 11:07:13 -0700129extern "C" void art_quick_invoke_interface_trampoline_with_access_check(uint32_t, void*);
130extern "C" void art_quick_invoke_static_trampoline_with_access_check(uint32_t, void*);
131extern "C" void art_quick_invoke_super_trampoline_with_access_check(uint32_t, void*);
132extern "C" void art_quick_invoke_virtual_trampoline_with_access_check(uint32_t, void*);
133
134// Thread entrypoints.
135extern void CheckSuspendFromCode(Thread* thread);
136extern "C" void art_quick_test_suspend();
137
138// Throw entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -0700139extern "C" void art_quick_deliver_exception(void*);
140extern "C" void art_quick_throw_array_bounds(int32_t index, int32_t limit);
141extern "C" void art_quick_throw_div_zero();
142extern "C" void art_quick_throw_no_such_method(int32_t method_idx);
143extern "C" void art_quick_throw_null_pointer_exception();
144extern "C" void art_quick_throw_stack_overflow(void*);
Ian Rogers7655f292013-07-29 11:07:13 -0700145
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700146static bool quick_alloc_entry_points_instrumented = false;
147
148void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
149 quick_alloc_entry_points_instrumented = instrumented;
150}
151
152void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
153 if (quick_alloc_entry_points_instrumented) {
154 qpoints->pAllocArray = art_quick_alloc_array_instrumented;
155 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check_instrumented;
156 qpoints->pAllocObject = art_quick_alloc_object_instrumented;
157 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check_instrumented;
158 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array_instrumented;
159 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check_instrumented;
160 } else {
161 qpoints->pAllocArray = art_quick_alloc_array;
162 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check;
163 qpoints->pAllocObject = art_quick_alloc_object;
164 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check;
165 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array;
166 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check;
167 }
168}
169
Ian Rogers848871b2013-08-05 10:56:33 -0700170void InitEntryPoints(InterpreterEntryPoints* ipoints, JniEntryPoints* jpoints,
171 PortableEntryPoints* ppoints, QuickEntryPoints* qpoints) {
172 // Interpreter
173 ipoints->pInterpreterToInterpreterBridge = artInterpreterToInterpreterBridge;
Dragos Sbirlea08bf1962013-08-12 08:53:04 -0700174 ipoints->pInterpreterToCompiledCodeBridge = artInterpreterToCompiledCodeBridge;
Ian Rogers848871b2013-08-05 10:56:33 -0700175
176 // JNI
177 jpoints->pDlsymLookup = art_jni_dlsym_lookup_stub;
178
179 // Portable
180 ppoints->pPortableResolutionTrampoline = art_portable_resolution_trampoline;
181 ppoints->pPortableToInterpreterBridge = art_portable_to_interpreter_bridge;
182
Ian Rogers7655f292013-07-29 11:07:13 -0700183 // Alloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700184 ResetQuickAllocEntryPoints(qpoints);
Ian Rogers7655f292013-07-29 11:07:13 -0700185
186 // Cast
Ian Rogers848871b2013-08-05 10:56:33 -0700187 qpoints->pInstanceofNonTrivial = artIsAssignableFromCode;
Ian Rogers848871b2013-08-05 10:56:33 -0700188 qpoints->pCheckCast = art_quick_check_cast;
Ian Rogers7655f292013-07-29 11:07:13 -0700189
190 // DexCache
Ian Rogers848871b2013-08-05 10:56:33 -0700191 qpoints->pInitializeStaticStorage = art_quick_initialize_static_storage;
192 qpoints->pInitializeTypeAndVerifyAccess = art_quick_initialize_type_and_verify_access;
193 qpoints->pInitializeType = art_quick_initialize_type;
194 qpoints->pResolveString = art_quick_resolve_string;
Ian Rogers7655f292013-07-29 11:07:13 -0700195
196 // Field
Ian Rogers848871b2013-08-05 10:56:33 -0700197 qpoints->pSet32Instance = art_quick_set32_instance;
198 qpoints->pSet32Static = art_quick_set32_static;
199 qpoints->pSet64Instance = art_quick_set64_instance;
200 qpoints->pSet64Static = art_quick_set64_static;
201 qpoints->pSetObjInstance = art_quick_set_obj_instance;
202 qpoints->pSetObjStatic = art_quick_set_obj_static;
203 qpoints->pGet32Instance = art_quick_get32_instance;
204 qpoints->pGet64Instance = art_quick_get64_instance;
205 qpoints->pGetObjInstance = art_quick_get_obj_instance;
206 qpoints->pGet32Static = art_quick_get32_static;
207 qpoints->pGet64Static = art_quick_get64_static;
208 qpoints->pGetObjStatic = art_quick_get_obj_static;
Ian Rogers7655f292013-07-29 11:07:13 -0700209
Ian Rogersa9a82542013-10-04 11:17:26 -0700210 // Array
211 qpoints->pAputObjectWithNullAndBoundCheck = art_quick_aput_obj_with_null_and_bound_check;
212 qpoints->pAputObjectWithBoundCheck = art_quick_aput_obj_with_bound_check;
213 qpoints->pAputObject = art_quick_aput_obj;
Ian Rogers848871b2013-08-05 10:56:33 -0700214 qpoints->pHandleFillArrayData = art_quick_handle_fill_data;
Ian Rogers7655f292013-07-29 11:07:13 -0700215
216 // JNI
217 qpoints->pJniMethodStart = JniMethodStart;
218 qpoints->pJniMethodStartSynchronized = JniMethodStartSynchronized;
219 qpoints->pJniMethodEnd = JniMethodEnd;
220 qpoints->pJniMethodEndSynchronized = JniMethodEndSynchronized;
221 qpoints->pJniMethodEndWithReference = JniMethodEndWithReference;
222 qpoints->pJniMethodEndWithReferenceSynchronized = JniMethodEndWithReferenceSynchronized;
223
224 // Locks
Ian Rogers848871b2013-08-05 10:56:33 -0700225 qpoints->pLockObject = art_quick_lock_object;
226 qpoints->pUnlockObject = art_quick_unlock_object;
Ian Rogers7655f292013-07-29 11:07:13 -0700227
228 // Math
229 qpoints->pCmpgDouble = CmpgDouble;
230 qpoints->pCmpgFloat = CmpgFloat;
231 qpoints->pCmplDouble = CmplDouble;
232 qpoints->pCmplFloat = CmplFloat;
233 qpoints->pFmod = fmod;
234 qpoints->pL2d = __floatdidf;
235 qpoints->pFmodf = fmodf;
236 qpoints->pL2f = __floatdisf;
237 qpoints->pD2iz = __fixdfsi;
238 qpoints->pF2iz = __fixsfsi;
239 qpoints->pIdivmod = NULL;
240 qpoints->pD2l = art_d2l;
241 qpoints->pF2l = art_f2l;
Ian Rogersa9a82542013-10-04 11:17:26 -0700242 qpoints->pLdiv = artLdiv;
243 qpoints->pLmod = artLmod;
244 qpoints->pLmul = artLmul;
Ian Rogers7655f292013-07-29 11:07:13 -0700245 qpoints->pShlLong = art_quick_shl_long;
246 qpoints->pShrLong = art_quick_shr_long;
247 qpoints->pUshrLong = art_quick_ushr_long;
248
Ian Rogers7655f292013-07-29 11:07:13 -0700249 // Intrinsics
250 qpoints->pIndexOf = art_quick_indexof;
251 qpoints->pMemcmp16 = __memcmp16;
252 qpoints->pStringCompareTo = art_quick_string_compareto;
253 qpoints->pMemcpy = memcpy;
254
255 // Invocation
Jeff Hao88474b42013-10-23 16:24:40 -0700256 qpoints->pQuickImtConflictTrampoline = art_quick_imt_conflict_trampoline;
Ian Rogers848871b2013-08-05 10:56:33 -0700257 qpoints->pQuickResolutionTrampoline = art_quick_resolution_trampoline;
258 qpoints->pQuickToInterpreterBridge = art_quick_to_interpreter_bridge;
Ian Rogers7655f292013-07-29 11:07:13 -0700259 qpoints->pInvokeDirectTrampolineWithAccessCheck = art_quick_invoke_direct_trampoline_with_access_check;
Ian Rogers7655f292013-07-29 11:07:13 -0700260 qpoints->pInvokeInterfaceTrampolineWithAccessCheck = art_quick_invoke_interface_trampoline_with_access_check;
261 qpoints->pInvokeStaticTrampolineWithAccessCheck = art_quick_invoke_static_trampoline_with_access_check;
262 qpoints->pInvokeSuperTrampolineWithAccessCheck = art_quick_invoke_super_trampoline_with_access_check;
263 qpoints->pInvokeVirtualTrampolineWithAccessCheck = art_quick_invoke_virtual_trampoline_with_access_check;
264
265 // Thread
Ian Rogers848871b2013-08-05 10:56:33 -0700266 qpoints->pCheckSuspend = CheckSuspendFromCode;
267 qpoints->pTestSuspend = art_quick_test_suspend;
Ian Rogers7655f292013-07-29 11:07:13 -0700268
269 // Throws
Ian Rogers848871b2013-08-05 10:56:33 -0700270 qpoints->pDeliverException = art_quick_deliver_exception;
271 qpoints->pThrowArrayBounds = art_quick_throw_array_bounds;
272 qpoints->pThrowDivZero = art_quick_throw_div_zero;
273 qpoints->pThrowNoSuchMethod = art_quick_throw_no_such_method;
274 qpoints->pThrowNullPointer = art_quick_throw_null_pointer_exception;
275 qpoints->pThrowStackOverflow = art_quick_throw_stack_overflow;
Ian Rogers7655f292013-07-29 11:07:13 -0700276};
277
278} // namespace art