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 "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 "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 // Math entrypoints.
34 extern int32_t CmpgDouble(double a, double b);
35 extern int32_t CmplDouble(double a, double b);
36 extern int32_t CmpgFloat(float a, float b);
37 extern int32_t CmplFloat(float a, float b);
38 extern "C" int64_t artLmul(int64_t a, int64_t b);
39 extern "C" int64_t artLdiv(int64_t a, int64_t b);
40 extern "C" int64_t artLmod(int64_t a, int64_t b);
41 
42 // Math conversions.
43 extern "C" int32_t __fixsfsi(float op1);      // FLOAT_TO_INT
44 extern "C" int32_t __fixdfsi(double op1);     // DOUBLE_TO_INT
45 extern "C" float __floatdisf(int64_t op1);    // LONG_TO_FLOAT
46 extern "C" double __floatdidf(int64_t op1);   // LONG_TO_DOUBLE
47 extern "C" int64_t __fixsfdi(float op1);      // FLOAT_TO_LONG
48 extern "C" int64_t __fixdfdi(double op1);     // DOUBLE_TO_LONG
49 
50 // Single-precision FP arithmetics.
51 extern "C" float fmodf(float a, float b);      // REM_FLOAT[_2ADDR]
52 
53 // Double-precision FP arithmetics.
54 extern "C" double fmod(double a, double b);     // REM_DOUBLE[_2ADDR]
55 
56 // Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR]
57 extern "C" int64_t __divdi3(int64_t, int64_t);
58 extern "C" int64_t __moddi3(int64_t, int64_t);
59 
InitEntryPoints(InterpreterEntryPoints * ipoints,JniEntryPoints * jpoints,QuickEntryPoints * qpoints)60 void InitEntryPoints(InterpreterEntryPoints* ipoints, JniEntryPoints* jpoints,
61                      QuickEntryPoints* qpoints) {
62   // Interpreter
63   ipoints->pInterpreterToInterpreterBridge = artInterpreterToInterpreterBridge;
64   ipoints->pInterpreterToCompiledCodeBridge = artInterpreterToCompiledCodeBridge;
65 
66   // JNI
67   jpoints->pDlsymLookup = art_jni_dlsym_lookup_stub;
68 
69   // Alloc
70   ResetQuickAllocEntryPoints(qpoints);
71 
72   // Cast
73   qpoints->pInstanceofNonTrivial = artIsAssignableFromCode;
74   qpoints->pCheckCast = art_quick_check_cast;
75 
76   // DexCache
77   qpoints->pInitializeStaticStorage = art_quick_initialize_static_storage;
78   qpoints->pInitializeTypeAndVerifyAccess = art_quick_initialize_type_and_verify_access;
79   qpoints->pInitializeType = art_quick_initialize_type;
80   qpoints->pResolveString = art_quick_resolve_string;
81 
82   // Field
83   qpoints->pSet8Instance = art_quick_set8_instance;
84   qpoints->pSet8Static = art_quick_set8_static;
85   qpoints->pSet16Instance = art_quick_set16_instance;
86   qpoints->pSet16Static = art_quick_set16_static;
87   qpoints->pSet32Instance = art_quick_set32_instance;
88   qpoints->pSet32Static = art_quick_set32_static;
89   qpoints->pSet64Instance = art_quick_set64_instance;
90   qpoints->pSet64Static = art_quick_set64_static;
91   qpoints->pSetObjInstance = art_quick_set_obj_instance;
92   qpoints->pSetObjStatic = art_quick_set_obj_static;
93   qpoints->pGetBooleanInstance = art_quick_get_boolean_instance;
94   qpoints->pGetByteInstance = art_quick_get_byte_instance;
95   qpoints->pGetCharInstance = art_quick_get_char_instance;
96   qpoints->pGetShortInstance = art_quick_get_short_instance;
97   qpoints->pGet32Instance = art_quick_get32_instance;
98   qpoints->pGet64Instance = art_quick_get64_instance;
99   qpoints->pGetObjInstance = art_quick_get_obj_instance;
100   qpoints->pGetBooleanStatic = art_quick_get_boolean_static;
101   qpoints->pGetByteStatic = art_quick_get_byte_static;
102   qpoints->pGetCharStatic = art_quick_get_char_static;
103   qpoints->pGetShortStatic = art_quick_get_short_static;
104   qpoints->pGet32Static = art_quick_get32_static;
105   qpoints->pGet64Static = art_quick_get64_static;
106   qpoints->pGetObjStatic = art_quick_get_obj_static;
107 
108   // Array
109   qpoints->pAputObjectWithNullAndBoundCheck = art_quick_aput_obj_with_null_and_bound_check;
110   qpoints->pAputObjectWithBoundCheck = art_quick_aput_obj_with_bound_check;
111   qpoints->pAputObject = art_quick_aput_obj;
112   qpoints->pHandleFillArrayData = art_quick_handle_fill_data;
113 
114   // JNI
115   qpoints->pJniMethodStart = JniMethodStart;
116   qpoints->pJniMethodStartSynchronized = JniMethodStartSynchronized;
117   qpoints->pJniMethodEnd = JniMethodEnd;
118   qpoints->pJniMethodEndSynchronized = JniMethodEndSynchronized;
119   qpoints->pJniMethodEndWithReference = JniMethodEndWithReference;
120   qpoints->pJniMethodEndWithReferenceSynchronized = JniMethodEndWithReferenceSynchronized;
121   qpoints->pQuickGenericJniTrampoline = art_quick_generic_jni_trampoline;
122 
123   // Locks
124   qpoints->pLockObject = art_quick_lock_object;
125   qpoints->pUnlockObject = art_quick_unlock_object;
126 
127   // Math
128   qpoints->pCmpgDouble = CmpgDouble;
129   qpoints->pCmpgFloat = CmpgFloat;
130   qpoints->pCmplDouble = CmplDouble;
131   qpoints->pCmplFloat = CmplFloat;
132   qpoints->pFmod = fmod;
133   qpoints->pL2d = art_l2d;
134   qpoints->pFmodf = fmodf;
135   qpoints->pL2f = art_l2f;
136   qpoints->pD2iz = art_d2i;
137   qpoints->pF2iz = art_f2i;
138   qpoints->pIdivmod = nullptr;
139   qpoints->pD2l = art_d2l;
140   qpoints->pF2l = art_f2l;
141   qpoints->pLdiv = artLdiv;
142   qpoints->pLmod = artLmod;
143   qpoints->pLmul = artLmul;
144   qpoints->pShlLong = nullptr;
145   qpoints->pShrLong = nullptr;
146   qpoints->pUshrLong = nullptr;
147 
148   // Intrinsics
149   qpoints->pIndexOf = art_quick_indexof;
150   qpoints->pStringCompareTo = art_quick_string_compareto;
151   qpoints->pMemcpy = memcpy;
152 
153   // Invocation
154   qpoints->pQuickImtConflictTrampoline = art_quick_imt_conflict_trampoline;
155   qpoints->pQuickResolutionTrampoline = art_quick_resolution_trampoline;
156   qpoints->pQuickToInterpreterBridge = art_quick_to_interpreter_bridge;
157   qpoints->pInvokeDirectTrampolineWithAccessCheck =
158       art_quick_invoke_direct_trampoline_with_access_check;
159   qpoints->pInvokeInterfaceTrampolineWithAccessCheck =
160       art_quick_invoke_interface_trampoline_with_access_check;
161   qpoints->pInvokeStaticTrampolineWithAccessCheck =
162       art_quick_invoke_static_trampoline_with_access_check;
163   qpoints->pInvokeSuperTrampolineWithAccessCheck =
164       art_quick_invoke_super_trampoline_with_access_check;
165   qpoints->pInvokeVirtualTrampolineWithAccessCheck =
166       art_quick_invoke_virtual_trampoline_with_access_check;
167 
168   // Thread
169   qpoints->pTestSuspend = art_quick_test_suspend;
170 
171   // Throws
172   qpoints->pDeliverException = art_quick_deliver_exception;
173   qpoints->pThrowArrayBounds = art_quick_throw_array_bounds;
174   qpoints->pThrowDivZero = art_quick_throw_div_zero;
175   qpoints->pThrowNoSuchMethod = art_quick_throw_no_such_method;
176   qpoints->pThrowNullPointer = art_quick_throw_null_pointer_exception;
177   qpoints->pThrowStackOverflow = art_quick_throw_stack_overflow;
178 
179   // Deoptimize
180   qpoints->pDeoptimize = art_quick_deoptimize;
181 
182   // TODO - use lld/scd instructions for Mips64
183   // Atomic 64-bit load/store
184   qpoints->pA64Load = QuasiAtomic::Read64;
185   qpoints->pA64Store = QuasiAtomic::Write64;
186 
187   // Read barrier
188   qpoints->pReadBarrierJni = ReadBarrierJni;
189 };
190 
191 }  // namespace art
192