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 <math.h>
18 #include <string.h>
19
20 #include "arch/arm/asm_support_arm.h"
21 #include "base/bit_utils.h"
22 #include "entrypoints/entrypoint_utils.h"
23 #include "entrypoints/jni/jni_entrypoints.h"
24 #include "entrypoints/quick/quick_alloc_entrypoints.h"
25 #include "entrypoints/quick/quick_default_externs.h"
26 #include "entrypoints/quick/quick_default_init_entrypoints.h"
27 #include "entrypoints/quick/quick_entrypoints.h"
28 #include "entrypoints/quick/runtime_entrypoints_list.h"
29 #include "entrypoints/runtime_asm_entrypoints.h"
30 #include "interpreter/interpreter.h"
31 #include "trace_profile.h"
32
33 namespace art HIDDEN {
34
35 // Read barrier entrypoints.
36 // art_quick_read_barrier_mark_regX uses an non-standard calling
37 // convention: it expects its input in register X and returns its
38 // result in that same register, and saves and restores all
39 // caller-save registers.
40 extern "C" mirror::Object* art_quick_read_barrier_mark_reg00(mirror::Object*);
41 extern "C" mirror::Object* art_quick_read_barrier_mark_reg01(mirror::Object*);
42 extern "C" mirror::Object* art_quick_read_barrier_mark_reg02(mirror::Object*);
43 extern "C" mirror::Object* art_quick_read_barrier_mark_reg03(mirror::Object*);
44 extern "C" mirror::Object* art_quick_read_barrier_mark_reg04(mirror::Object*);
45 extern "C" mirror::Object* art_quick_read_barrier_mark_reg05(mirror::Object*);
46 extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*);
47 extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*);
48 extern "C" mirror::Object* art_quick_read_barrier_mark_reg08(mirror::Object*);
49 extern "C" mirror::Object* art_quick_read_barrier_mark_reg09(mirror::Object*);
50 extern "C" mirror::Object* art_quick_read_barrier_mark_reg10(mirror::Object*);
51 extern "C" mirror::Object* art_quick_read_barrier_mark_reg11(mirror::Object*);
52 extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*);
53
54 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection(mirror::Object*);
55 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_narrow(mirror::Object*);
56 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_arrays(mirror::Object*);
57 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_gc_roots_wide(mirror::Object*);
58 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_gc_roots_narrow(
59 mirror::Object*);
60 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_intrinsic_cas(mirror::Object*);
61
62 // Used by soft float.
63 // Single-precision FP arithmetics.
64 extern "C" float fmodf(float a, float b); // REM_FLOAT[_2ADDR]
65 // Double-precision FP arithmetics.
66 extern "C" double fmod(double a, double b); // REM_DOUBLE[_2ADDR]
67
68 // Used by hard float.
69 extern "C" float art_quick_fmodf(float a, float b); // REM_FLOAT[_2ADDR]
70 extern "C" double art_quick_fmod(double a, double b); // REM_DOUBLE[_2ADDR]
71
72 // Integer arithmetics.
73 extern "C" int __aeabi_idivmod(int32_t, int32_t); // [DIV|REM]_INT[_2ADDR|_LIT8|_LIT16]
74
75 // Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR]
76 extern "C" int64_t __aeabi_ldivmod(int64_t, int64_t);
77
UpdateReadBarrierEntrypoints(QuickEntryPoints * qpoints,bool is_active)78 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) {
79 qpoints->SetReadBarrierMarkReg00(is_active ? art_quick_read_barrier_mark_reg00 : nullptr);
80 qpoints->SetReadBarrierMarkReg01(is_active ? art_quick_read_barrier_mark_reg01 : nullptr);
81 qpoints->SetReadBarrierMarkReg02(is_active ? art_quick_read_barrier_mark_reg02 : nullptr);
82 qpoints->SetReadBarrierMarkReg03(is_active ? art_quick_read_barrier_mark_reg03 : nullptr);
83 qpoints->SetReadBarrierMarkReg04(is_active ? art_quick_read_barrier_mark_reg04 : nullptr);
84 qpoints->SetReadBarrierMarkReg05(is_active ? art_quick_read_barrier_mark_reg05 : nullptr);
85 qpoints->SetReadBarrierMarkReg06(is_active ? art_quick_read_barrier_mark_reg06 : nullptr);
86 qpoints->SetReadBarrierMarkReg07(is_active ? art_quick_read_barrier_mark_reg07 : nullptr);
87 qpoints->SetReadBarrierMarkReg08(is_active ? art_quick_read_barrier_mark_reg08 : nullptr);
88 qpoints->SetReadBarrierMarkReg09(is_active ? art_quick_read_barrier_mark_reg09 : nullptr);
89 qpoints->SetReadBarrierMarkReg10(is_active ? art_quick_read_barrier_mark_reg10 : nullptr);
90 qpoints->SetReadBarrierMarkReg11(is_active ? art_quick_read_barrier_mark_reg11 : nullptr);
91
92 if (gUseReadBarrier && kUseBakerReadBarrier) {
93 // For the alignment check, strip the Thumb mode bit.
94 DCHECK_ALIGNED(reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection) - 1u,
95 256u);
96 // Check the field narrow entrypoint offset from the introspection entrypoint.
97 intptr_t narrow_diff =
98 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_narrow) -
99 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection);
100 DCHECK_EQ(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET, narrow_diff);
101 // Check array switch cases offsets from the introspection entrypoint.
102 intptr_t array_diff =
103 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_arrays) -
104 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection);
105 DCHECK_EQ(BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET, array_diff);
106 // Check the GC root entrypoint offsets from the introspection entrypoint.
107 intptr_t gc_roots_wide_diff =
108 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_gc_roots_wide) -
109 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection);
110 DCHECK_EQ(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET, gc_roots_wide_diff);
111 intptr_t gc_roots_narrow_diff =
112 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_gc_roots_narrow) -
113 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection);
114 DCHECK_EQ(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET, gc_roots_narrow_diff);
115 intptr_t intrinsic_cas_diff =
116 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_intrinsic_cas) -
117 reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection);
118 DCHECK_EQ(BAKER_MARK_INTROSPECTION_INTRINSIC_CAS_ENTRYPOINT_OFFSET, intrinsic_cas_diff);
119 // The register 12, i.e. IP, is reserved, so there is no art_quick_read_barrier_mark_reg12.
120 // We're using the entry to hold a pointer to the introspection entrypoint instead.
121 qpoints->SetReadBarrierMarkReg12(
122 is_active ? art_quick_read_barrier_mark_introspection : nullptr);
123 }
124 }
125
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints,bool monitor_jni_entry_exit)126 void InitEntryPoints(JniEntryPoints* jpoints,
127 QuickEntryPoints* qpoints,
128 bool monitor_jni_entry_exit) {
129 DefaultInitEntryPoints(jpoints, qpoints, monitor_jni_entry_exit);
130
131 // Cast
132 qpoints->SetInstanceofNonTrivial(artInstanceOfFromCode);
133 qpoints->SetCheckInstanceOf(art_quick_check_instance_of);
134
135 // Math
136 qpoints->SetIdivmod(__aeabi_idivmod);
137 qpoints->SetLdiv(__aeabi_ldivmod);
138 qpoints->SetLmod(__aeabi_ldivmod); // result returned in r2:r3
139 qpoints->SetLmul(art_quick_mul_long);
140 qpoints->SetShlLong(art_quick_shl_long);
141 qpoints->SetShrLong(art_quick_shr_long);
142 qpoints->SetUshrLong(art_quick_ushr_long);
143 qpoints->SetFmod(art_quick_fmod);
144 qpoints->SetFmodf(art_quick_fmodf);
145 qpoints->SetD2l(art_quick_d2l);
146 qpoints->SetF2l(art_quick_f2l);
147 qpoints->SetL2f(art_quick_l2f);
148
149 // More math.
150 qpoints->SetCos(cos);
151 qpoints->SetSin(sin);
152 qpoints->SetAcos(acos);
153 qpoints->SetAsin(asin);
154 qpoints->SetAtan(atan);
155 qpoints->SetAtan2(atan2);
156 qpoints->SetPow(pow);
157 qpoints->SetCbrt(cbrt);
158 qpoints->SetCosh(cosh);
159 qpoints->SetExp(exp);
160 qpoints->SetExpm1(expm1);
161 qpoints->SetHypot(hypot);
162 qpoints->SetLog(log);
163 qpoints->SetLog10(log10);
164 qpoints->SetNextAfter(nextafter);
165 qpoints->SetSinh(sinh);
166 qpoints->SetTan(tan);
167 qpoints->SetTanh(tanh);
168
169 // Intrinsics
170 qpoints->SetIndexOf(art_quick_indexof);
171 // The ARM StringCompareTo intrinsic does not call the runtime.
172 qpoints->SetStringCompareTo(nullptr);
173 qpoints->SetMemcpy(memcpy);
174
175 // Read barrier.
176 UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false);
177 qpoints->SetReadBarrierMarkReg12(nullptr); // Cannot use register 12 (IP) to pass arguments.
178 qpoints->SetReadBarrierMarkReg13(nullptr); // Cannot use register 13 (SP) to pass arguments.
179 qpoints->SetReadBarrierMarkReg14(nullptr); // Cannot use register 14 (LR) to pass arguments.
180 qpoints->SetReadBarrierMarkReg15(nullptr); // Cannot use register 15 (PC) to pass arguments.
181 // ARM has only 16 core registers.
182 qpoints->SetReadBarrierMarkReg16(nullptr);
183 qpoints->SetReadBarrierMarkReg17(nullptr);
184 qpoints->SetReadBarrierMarkReg18(nullptr);
185 qpoints->SetReadBarrierMarkReg19(nullptr);
186 qpoints->SetReadBarrierMarkReg20(nullptr);
187 qpoints->SetReadBarrierMarkReg21(nullptr);
188 qpoints->SetReadBarrierMarkReg22(nullptr);
189 qpoints->SetReadBarrierMarkReg23(nullptr);
190 qpoints->SetReadBarrierMarkReg24(nullptr);
191 qpoints->SetReadBarrierMarkReg25(nullptr);
192 qpoints->SetReadBarrierMarkReg26(nullptr);
193 qpoints->SetReadBarrierMarkReg27(nullptr);
194 qpoints->SetReadBarrierMarkReg28(nullptr);
195 qpoints->SetReadBarrierMarkReg29(nullptr);
196 qpoints->SetReadBarrierSlow(artReadBarrierSlow);
197 qpoints->SetReadBarrierForRootSlow(artReadBarrierForRootSlow);
198 }
199
UpdateLowOverheadTraceEntrypoints(QuickEntryPoints * qpoints,LowOverheadTraceType trace_type)200 void UpdateLowOverheadTraceEntrypoints([[maybe_unused]] QuickEntryPoints* qpoints,
201 [[maybe_unused]] LowOverheadTraceType trace_type) {
202 // This is a nop on this architecture. Low overhead tracing is only implemented for ARM64.
203 }
204
205 } // namespace art
206