blob: 3d08298151d99e35fbafc3d3dfd97b34693a40b4 [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_can_put_array_element(void*, void*);
55extern "C" void art_quick_check_cast(void*, void*);
Ian Rogers7655f292013-07-29 11:07:13 -070056
57// DexCache entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -070058extern "C" void* art_quick_initialize_static_storage(uint32_t, void*);
59extern "C" void* art_quick_initialize_type(uint32_t, void*);
60extern "C" void* art_quick_initialize_type_and_verify_access(uint32_t, void*);
61extern "C" void* art_quick_resolve_string(void*, uint32_t);
Ian Rogers7655f292013-07-29 11:07:13 -070062
63// Exception entrypoints.
64extern "C" void* GetAndClearException(Thread*);
65
66// Field entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -070067extern "C" int art_quick_set32_instance(uint32_t, void*, int32_t);
68extern "C" int art_quick_set32_static(uint32_t, int32_t);
69extern "C" int art_quick_set64_instance(uint32_t, void*, int64_t);
70extern "C" int art_quick_set64_static(uint32_t, int64_t);
71extern "C" int art_quick_set_obj_instance(uint32_t, void*, void*);
72extern "C" int art_quick_set_obj_static(uint32_t, void*);
73extern "C" int32_t art_quick_get32_instance(uint32_t, void*);
74extern "C" int32_t art_quick_get32_static(uint32_t);
75extern "C" int64_t art_quick_get64_instance(uint32_t, void*);
76extern "C" int64_t art_quick_get64_static(uint32_t);
77extern "C" void* art_quick_get_obj_instance(uint32_t, void*);
78extern "C" void* art_quick_get_obj_static(uint32_t);
Ian Rogers7655f292013-07-29 11:07:13 -070079
80// FillArray entrypoint.
Ian Rogers848871b2013-08-05 10:56:33 -070081extern "C" void art_quick_handle_fill_data(void*, void*);
Ian Rogers7655f292013-07-29 11:07:13 -070082
83// Lock entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -070084extern "C" void art_quick_lock_object(void*);
85extern "C" void art_quick_unlock_object(void*);
Ian Rogers7655f292013-07-29 11:07:13 -070086
87// Math entrypoints.
88extern int32_t CmpgDouble(double a, double b);
89extern int32_t CmplDouble(double a, double b);
90extern int32_t CmpgFloat(float a, float b);
91extern int32_t CmplFloat(float a, float b);
92extern "C" int64_t artLmulFromCode(int64_t a, int64_t b);
93extern "C" int64_t artLdivFromCode(int64_t a, int64_t b);
94extern "C" int64_t artLdivmodFromCode(int64_t a, int64_t b);
95
96// Math conversions.
97extern "C" int32_t __fixsfsi(float op1); // FLOAT_TO_INT
98extern "C" int32_t __fixdfsi(double op1); // DOUBLE_TO_INT
99extern "C" float __floatdisf(int64_t op1); // LONG_TO_FLOAT
100extern "C" double __floatdidf(int64_t op1); // LONG_TO_DOUBLE
101extern "C" int64_t __fixsfdi(float op1); // FLOAT_TO_LONG
102extern "C" int64_t __fixdfdi(double op1); // DOUBLE_TO_LONG
103
104// Single-precision FP arithmetics.
105extern "C" float fmodf(float a, float b); // REM_FLOAT[_2ADDR]
106
107// Double-precision FP arithmetics.
108extern "C" double fmod(double a, double b); // REM_DOUBLE[_2ADDR]
109
110// Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR]
111extern "C" int64_t __divdi3(int64_t, int64_t);
112extern "C" int64_t __moddi3(int64_t, int64_t);
113extern "C" uint64_t art_quick_shl_long(uint64_t, uint32_t);
114extern "C" uint64_t art_quick_shr_long(uint64_t, uint32_t);
115extern "C" uint64_t art_quick_ushr_long(uint64_t, uint32_t);
116
Ian Rogers7655f292013-07-29 11:07:13 -0700117// Intrinsic entrypoints.
118extern "C" int32_t __memcmp16(void*, void*, int32_t);
119extern "C" int32_t art_quick_indexof(void*, uint32_t, uint32_t, uint32_t);
120extern "C" int32_t art_quick_string_compareto(void*, void*);
121
122// Invoke entrypoints.
Brian Carlstromea46f952013-07-30 01:26:50 -0700123extern "C" void art_quick_resolution_trampoline(mirror::ArtMethod*);
124extern "C" void art_quick_to_interpreter_bridge(mirror::ArtMethod*);
Ian Rogers7655f292013-07-29 11:07:13 -0700125extern "C" void art_quick_invoke_direct_trampoline_with_access_check(uint32_t, void*);
126extern "C" void art_quick_invoke_interface_trampoline(uint32_t, void*);
127extern "C" void art_quick_invoke_interface_trampoline_with_access_check(uint32_t, void*);
128extern "C" void art_quick_invoke_static_trampoline_with_access_check(uint32_t, void*);
129extern "C" void art_quick_invoke_super_trampoline_with_access_check(uint32_t, void*);
130extern "C" void art_quick_invoke_virtual_trampoline_with_access_check(uint32_t, void*);
131
132// Thread entrypoints.
133extern void CheckSuspendFromCode(Thread* thread);
134extern "C" void art_quick_test_suspend();
135
136// Throw entrypoints.
Ian Rogers848871b2013-08-05 10:56:33 -0700137extern "C" void art_quick_deliver_exception(void*);
138extern "C" void art_quick_throw_array_bounds(int32_t index, int32_t limit);
139extern "C" void art_quick_throw_div_zero();
140extern "C" void art_quick_throw_no_such_method(int32_t method_idx);
141extern "C" void art_quick_throw_null_pointer_exception();
142extern "C" void art_quick_throw_stack_overflow(void*);
Ian Rogers7655f292013-07-29 11:07:13 -0700143
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700144static bool quick_alloc_entry_points_instrumented = false;
145
146void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
147 quick_alloc_entry_points_instrumented = instrumented;
148}
149
150void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
151 if (quick_alloc_entry_points_instrumented) {
152 qpoints->pAllocArray = art_quick_alloc_array_instrumented;
153 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check_instrumented;
154 qpoints->pAllocObject = art_quick_alloc_object_instrumented;
155 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check_instrumented;
156 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array_instrumented;
157 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check_instrumented;
158 } else {
159 qpoints->pAllocArray = art_quick_alloc_array;
160 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check;
161 qpoints->pAllocObject = art_quick_alloc_object;
162 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check;
163 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array;
164 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check;
165 }
166}
167
Ian Rogers848871b2013-08-05 10:56:33 -0700168void InitEntryPoints(InterpreterEntryPoints* ipoints, JniEntryPoints* jpoints,
169 PortableEntryPoints* ppoints, QuickEntryPoints* qpoints) {
170 // Interpreter
171 ipoints->pInterpreterToInterpreterBridge = artInterpreterToInterpreterBridge;
Dragos Sbirlea08bf1962013-08-12 08:53:04 -0700172 ipoints->pInterpreterToCompiledCodeBridge = artInterpreterToCompiledCodeBridge;
Ian Rogers848871b2013-08-05 10:56:33 -0700173
174 // JNI
175 jpoints->pDlsymLookup = art_jni_dlsym_lookup_stub;
176
177 // Portable
178 ppoints->pPortableResolutionTrampoline = art_portable_resolution_trampoline;
179 ppoints->pPortableToInterpreterBridge = art_portable_to_interpreter_bridge;
180
Ian Rogers7655f292013-07-29 11:07:13 -0700181 // Alloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700182 ResetQuickAllocEntryPoints(qpoints);
Ian Rogers7655f292013-07-29 11:07:13 -0700183
184 // Cast
Ian Rogers848871b2013-08-05 10:56:33 -0700185 qpoints->pInstanceofNonTrivial = artIsAssignableFromCode;
186 qpoints->pCanPutArrayElement = art_quick_can_put_array_element;
187 qpoints->pCheckCast = art_quick_check_cast;
Ian Rogers7655f292013-07-29 11:07:13 -0700188
189 // DexCache
Ian Rogers848871b2013-08-05 10:56:33 -0700190 qpoints->pInitializeStaticStorage = art_quick_initialize_static_storage;
191 qpoints->pInitializeTypeAndVerifyAccess = art_quick_initialize_type_and_verify_access;
192 qpoints->pInitializeType = art_quick_initialize_type;
193 qpoints->pResolveString = art_quick_resolve_string;
Ian Rogers7655f292013-07-29 11:07:13 -0700194
195 // Field
Ian Rogers848871b2013-08-05 10:56:33 -0700196 qpoints->pSet32Instance = art_quick_set32_instance;
197 qpoints->pSet32Static = art_quick_set32_static;
198 qpoints->pSet64Instance = art_quick_set64_instance;
199 qpoints->pSet64Static = art_quick_set64_static;
200 qpoints->pSetObjInstance = art_quick_set_obj_instance;
201 qpoints->pSetObjStatic = art_quick_set_obj_static;
202 qpoints->pGet32Instance = art_quick_get32_instance;
203 qpoints->pGet64Instance = art_quick_get64_instance;
204 qpoints->pGetObjInstance = art_quick_get_obj_instance;
205 qpoints->pGet32Static = art_quick_get32_static;
206 qpoints->pGet64Static = art_quick_get64_static;
207 qpoints->pGetObjStatic = art_quick_get_obj_static;
Ian Rogers7655f292013-07-29 11:07:13 -0700208
209 // FillArray
Ian Rogers848871b2013-08-05 10:56:33 -0700210 qpoints->pHandleFillArrayData = art_quick_handle_fill_data;
Ian Rogers7655f292013-07-29 11:07:13 -0700211
212 // JNI
213 qpoints->pJniMethodStart = JniMethodStart;
214 qpoints->pJniMethodStartSynchronized = JniMethodStartSynchronized;
215 qpoints->pJniMethodEnd = JniMethodEnd;
216 qpoints->pJniMethodEndSynchronized = JniMethodEndSynchronized;
217 qpoints->pJniMethodEndWithReference = JniMethodEndWithReference;
218 qpoints->pJniMethodEndWithReferenceSynchronized = JniMethodEndWithReferenceSynchronized;
219
220 // Locks
Ian Rogers848871b2013-08-05 10:56:33 -0700221 qpoints->pLockObject = art_quick_lock_object;
222 qpoints->pUnlockObject = art_quick_unlock_object;
Ian Rogers7655f292013-07-29 11:07:13 -0700223
224 // Math
225 qpoints->pCmpgDouble = CmpgDouble;
226 qpoints->pCmpgFloat = CmpgFloat;
227 qpoints->pCmplDouble = CmplDouble;
228 qpoints->pCmplFloat = CmplFloat;
229 qpoints->pFmod = fmod;
230 qpoints->pL2d = __floatdidf;
231 qpoints->pFmodf = fmodf;
232 qpoints->pL2f = __floatdisf;
233 qpoints->pD2iz = __fixdfsi;
234 qpoints->pF2iz = __fixsfsi;
235 qpoints->pIdivmod = NULL;
236 qpoints->pD2l = art_d2l;
237 qpoints->pF2l = art_f2l;
238 qpoints->pLdiv = artLdivFromCode;
239 qpoints->pLdivmod = artLdivmodFromCode;
240 qpoints->pLmul = artLmulFromCode;
241 qpoints->pShlLong = art_quick_shl_long;
242 qpoints->pShrLong = art_quick_shr_long;
243 qpoints->pUshrLong = art_quick_ushr_long;
244
Ian Rogers7655f292013-07-29 11:07:13 -0700245 // Intrinsics
246 qpoints->pIndexOf = art_quick_indexof;
247 qpoints->pMemcmp16 = __memcmp16;
248 qpoints->pStringCompareTo = art_quick_string_compareto;
249 qpoints->pMemcpy = memcpy;
250
251 // Invocation
Ian Rogers848871b2013-08-05 10:56:33 -0700252 qpoints->pQuickResolutionTrampoline = art_quick_resolution_trampoline;
253 qpoints->pQuickToInterpreterBridge = art_quick_to_interpreter_bridge;
Ian Rogers7655f292013-07-29 11:07:13 -0700254 qpoints->pInvokeDirectTrampolineWithAccessCheck = art_quick_invoke_direct_trampoline_with_access_check;
255 qpoints->pInvokeInterfaceTrampoline = art_quick_invoke_interface_trampoline;
256 qpoints->pInvokeInterfaceTrampolineWithAccessCheck = art_quick_invoke_interface_trampoline_with_access_check;
257 qpoints->pInvokeStaticTrampolineWithAccessCheck = art_quick_invoke_static_trampoline_with_access_check;
258 qpoints->pInvokeSuperTrampolineWithAccessCheck = art_quick_invoke_super_trampoline_with_access_check;
259 qpoints->pInvokeVirtualTrampolineWithAccessCheck = art_quick_invoke_virtual_trampoline_with_access_check;
260
261 // Thread
Ian Rogers848871b2013-08-05 10:56:33 -0700262 qpoints->pCheckSuspend = CheckSuspendFromCode;
263 qpoints->pTestSuspend = art_quick_test_suspend;
Ian Rogers7655f292013-07-29 11:07:13 -0700264
265 // Throws
Ian Rogers848871b2013-08-05 10:56:33 -0700266 qpoints->pDeliverException = art_quick_deliver_exception;
267 qpoints->pThrowArrayBounds = art_quick_throw_array_bounds;
268 qpoints->pThrowDivZero = art_quick_throw_div_zero;
269 qpoints->pThrowNoSuchMethod = art_quick_throw_no_such_method;
270 qpoints->pThrowNullPointer = art_quick_throw_null_pointer_exception;
271 qpoints->pThrowStackOverflow = art_quick_throw_stack_overflow;
Ian Rogers7655f292013-07-29 11:07:13 -0700272};
273
274} // namespace art