1 /*
2 * Copyright (C) 2014 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_entrypoints.h"
21 #include "entrypoints/entrypoint_utils.h"
22 #include "entrypoints/math_entrypoints.h"
23
24 namespace art {
25
26 // Interpreter entrypoints.
27 extern "C" void artInterpreterToInterpreterBridge(Thread* self, MethodHelper& mh,
28 const DexFile::CodeItem* code_item,
29 ShadowFrame* shadow_frame, JValue* result);
30 extern "C" void artInterpreterToCompiledCodeBridge(Thread* self, MethodHelper& mh,
31 const DexFile::CodeItem* code_item,
32 ShadowFrame* shadow_frame, JValue* result);
33
34 // Portable entrypoints.
35 extern "C" void art_portable_resolution_trampoline(mirror::ArtMethod*);
36 extern "C" void art_portable_to_interpreter_bridge(mirror::ArtMethod*);
37
38 // Cast entrypoints.
39 extern "C" uint32_t art_quick_assignable_from_code(const mirror::Class* klass,
40 const mirror::Class* ref_class);
41 extern "C" void art_quick_check_cast(void*, void*);
42
43 // DexCache entrypoints.
44 extern "C" void* art_quick_initialize_static_storage(uint32_t, void*);
45 extern "C" void* art_quick_initialize_type(uint32_t, void*);
46 extern "C" void* art_quick_initialize_type_and_verify_access(uint32_t, void*);
47 extern "C" void* art_quick_resolve_string(void*, uint32_t);
48
49 // Field entrypoints.
50 extern "C" int art_quick_set32_instance(uint32_t, void*, int32_t);
51 extern "C" int art_quick_set32_static(uint32_t, int32_t);
52 extern "C" int art_quick_set64_instance(uint32_t, void*, int64_t);
53 extern "C" int art_quick_set64_static(uint32_t, int64_t);
54 extern "C" int art_quick_set_obj_instance(uint32_t, void*, void*);
55 extern "C" int art_quick_set_obj_static(uint32_t, void*);
56 extern "C" int32_t art_quick_get32_instance(uint32_t, void*);
57 extern "C" int32_t art_quick_get32_static(uint32_t);
58 extern "C" int64_t art_quick_get64_instance(uint32_t, void*);
59 extern "C" int64_t art_quick_get64_static(uint32_t);
60 extern "C" void* art_quick_get_obj_instance(uint32_t, void*);
61 extern "C" void* art_quick_get_obj_static(uint32_t);
62
63 // Array entrypoints.
64 extern "C" void art_quick_aput_obj_with_null_and_bound_check(void*, uint32_t, void*);
65 extern "C" void art_quick_aput_obj_with_bound_check(void*, uint32_t, void*);
66 extern "C" void art_quick_aput_obj(void*, uint32_t, void*);
67 extern "C" void art_quick_handle_fill_data(void*, void*);
68
69 // Lock entrypoints.
70 extern "C" void art_quick_lock_object(void*);
71 extern "C" void art_quick_unlock_object(void*);
72
73 // Single-precision FP arithmetics.
74 extern "C" float art_quick_fmodf(float a, float b); // REM_FLOAT[_2ADDR]
75
76 // Double-precision FP arithmetics.
77 extern "C" double art_quick_fmod(double a, double b); // REM_DOUBLE[_2ADDR]
78
79 // Memcpy
80 extern "C" void* art_quick_memcpy(void* __restrict, const void* __restrict, size_t);
81
82 // Intrinsic entrypoints.
83 extern "C" int32_t art_quick_indexof(void*, uint32_t, uint32_t, uint32_t);
84 extern "C" int32_t art_quick_string_compareto(void*, void*);
85
86 // Invoke entrypoints.
87 extern "C" void art_quick_imt_conflict_trampoline(mirror::ArtMethod*);
88 extern "C" void art_quick_resolution_trampoline(mirror::ArtMethod*);
89 extern "C" void art_quick_to_interpreter_bridge(mirror::ArtMethod*);
90 extern "C" void art_quick_invoke_direct_trampoline_with_access_check(uint32_t, void*);
91 extern "C" void art_quick_invoke_interface_trampoline_with_access_check(uint32_t, void*);
92 extern "C" void art_quick_invoke_static_trampoline_with_access_check(uint32_t, void*);
93 extern "C" void art_quick_invoke_super_trampoline_with_access_check(uint32_t, void*);
94 extern "C" void art_quick_invoke_virtual_trampoline_with_access_check(uint32_t, void*);
95
96 // Thread entrypoints.
97 extern "C" void art_quick_test_suspend();
98
99 // Throw entrypoints.
100 extern "C" void art_quick_deliver_exception(void*);
101 extern "C" void art_quick_throw_array_bounds(int32_t index, int32_t limit);
102 extern "C" void art_quick_throw_div_zero();
103 extern "C" void art_quick_throw_no_such_method(int32_t method_idx);
104 extern "C" void art_quick_throw_null_pointer_exception();
105 extern "C" void art_quick_throw_stack_overflow(void*);
106
107 extern void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints);
108
109 // Generic JNI downcall
110 extern "C" void art_quick_generic_jni_trampoline(mirror::ArtMethod*);
111
InitEntryPoints(InterpreterEntryPoints * ipoints,JniEntryPoints * jpoints,PortableEntryPoints * ppoints,QuickEntryPoints * qpoints)112 void InitEntryPoints(InterpreterEntryPoints* ipoints, JniEntryPoints* jpoints,
113 PortableEntryPoints* ppoints, QuickEntryPoints* qpoints) {
114 // Interpreter
115 ipoints->pInterpreterToInterpreterBridge = artInterpreterToInterpreterBridge;
116 ipoints->pInterpreterToCompiledCodeBridge = artInterpreterToCompiledCodeBridge;
117
118 // JNI
119 jpoints->pDlsymLookup = art_jni_dlsym_lookup_stub;
120
121 // Portable
122 ppoints->pPortableResolutionTrampoline = art_portable_resolution_trampoline;
123 ppoints->pPortableToInterpreterBridge = art_portable_to_interpreter_bridge;
124
125 // Alloc
126 ResetQuickAllocEntryPoints(qpoints);
127
128 // Cast
129 qpoints->pInstanceofNonTrivial = art_quick_assignable_from_code;
130 qpoints->pCheckCast = art_quick_check_cast;
131
132 // DexCache
133 qpoints->pInitializeStaticStorage = art_quick_initialize_static_storage;
134 qpoints->pInitializeTypeAndVerifyAccess = art_quick_initialize_type_and_verify_access;
135 qpoints->pInitializeType = art_quick_initialize_type;
136 qpoints->pResolveString = art_quick_resolve_string;
137
138 // Field
139 qpoints->pSet32Instance = art_quick_set32_instance;
140 qpoints->pSet32Static = art_quick_set32_static;
141 qpoints->pSet64Instance = art_quick_set64_instance;
142 qpoints->pSet64Static = art_quick_set64_static;
143 qpoints->pSetObjInstance = art_quick_set_obj_instance;
144 qpoints->pSetObjStatic = art_quick_set_obj_static;
145 qpoints->pGet32Instance = art_quick_get32_instance;
146 qpoints->pGet64Instance = art_quick_get64_instance;
147 qpoints->pGetObjInstance = art_quick_get_obj_instance;
148 qpoints->pGet32Static = art_quick_get32_static;
149 qpoints->pGet64Static = art_quick_get64_static;
150 qpoints->pGetObjStatic = art_quick_get_obj_static;
151
152 // Array
153 qpoints->pAputObjectWithNullAndBoundCheck = art_quick_aput_obj_with_null_and_bound_check;
154 qpoints->pAputObjectWithBoundCheck = art_quick_aput_obj_with_bound_check;
155 qpoints->pAputObject = art_quick_aput_obj;
156 qpoints->pHandleFillArrayData = art_quick_handle_fill_data;
157
158 // JNI
159 qpoints->pJniMethodStart = JniMethodStart;
160 qpoints->pJniMethodStartSynchronized = JniMethodStartSynchronized;
161 qpoints->pJniMethodEnd = JniMethodEnd;
162 qpoints->pJniMethodEndSynchronized = JniMethodEndSynchronized;
163 qpoints->pJniMethodEndWithReference = JniMethodEndWithReference;
164 qpoints->pJniMethodEndWithReferenceSynchronized = JniMethodEndWithReferenceSynchronized;
165 qpoints->pQuickGenericJniTrampoline = art_quick_generic_jni_trampoline;
166
167 // Locks
168 qpoints->pLockObject = art_quick_lock_object;
169 qpoints->pUnlockObject = art_quick_unlock_object;
170
171 // Math
172 // TODO nullptr entrypoints not needed for ARM64 - generate inline.
173 qpoints->pCmpgDouble = nullptr;
174 qpoints->pCmpgFloat = nullptr;
175 qpoints->pCmplDouble = nullptr;
176 qpoints->pCmplFloat = nullptr;
177 qpoints->pFmod = art_quick_fmod;
178 qpoints->pL2d = nullptr;
179 qpoints->pFmodf = art_quick_fmodf;
180 qpoints->pL2f = nullptr;
181 qpoints->pD2iz = nullptr;
182 qpoints->pF2iz = nullptr;
183 qpoints->pIdivmod = nullptr;
184 qpoints->pD2l = nullptr;
185 qpoints->pF2l = nullptr;
186 qpoints->pLdiv = nullptr;
187 qpoints->pLmod = nullptr;
188 qpoints->pLmul = nullptr;
189 qpoints->pShlLong = nullptr;
190 qpoints->pShrLong = nullptr;
191 qpoints->pUshrLong = nullptr;
192
193 // Intrinsics
194 qpoints->pIndexOf = art_quick_indexof;
195 qpoints->pStringCompareTo = art_quick_string_compareto;
196 qpoints->pMemcpy = art_quick_memcpy;
197
198 // Invocation
199 qpoints->pQuickImtConflictTrampoline = art_quick_imt_conflict_trampoline;
200 qpoints->pQuickResolutionTrampoline = art_quick_resolution_trampoline;
201 qpoints->pQuickToInterpreterBridge = art_quick_to_interpreter_bridge;
202 qpoints->pInvokeDirectTrampolineWithAccessCheck = art_quick_invoke_direct_trampoline_with_access_check;
203 qpoints->pInvokeInterfaceTrampolineWithAccessCheck = art_quick_invoke_interface_trampoline_with_access_check;
204 qpoints->pInvokeStaticTrampolineWithAccessCheck = art_quick_invoke_static_trampoline_with_access_check;
205 qpoints->pInvokeSuperTrampolineWithAccessCheck = art_quick_invoke_super_trampoline_with_access_check;
206 qpoints->pInvokeVirtualTrampolineWithAccessCheck = art_quick_invoke_virtual_trampoline_with_access_check;
207
208 // Thread
209 qpoints->pTestSuspend = art_quick_test_suspend;
210
211 // Throws
212 qpoints->pDeliverException = art_quick_deliver_exception;
213 qpoints->pThrowArrayBounds = art_quick_throw_array_bounds;
214 qpoints->pThrowDivZero = art_quick_throw_div_zero;
215 qpoints->pThrowNoSuchMethod = art_quick_throw_no_such_method;
216 qpoints->pThrowNullPointer = art_quick_throw_null_pointer_exception;
217 qpoints->pThrowStackOverflow = art_quick_throw_stack_overflow;
218 };
219
220 } // namespace art
221