• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <math.h>
18 #include <string.h>
19 
20 #include "arch/arm64/asm_support_arm64.h"
21 #include "base/bit_utils.h"
22 #include "entrypoints/entrypoint_utils.h"
23 #include "entrypoints/jni/jni_entrypoints.h"
24 #include "entrypoints/math_entrypoints.h"
25 #include "entrypoints/quick/quick_alloc_entrypoints.h"
26 #include "entrypoints/quick/quick_default_externs.h"
27 #include "entrypoints/quick/quick_default_init_entrypoints.h"
28 #include "entrypoints/quick/quick_entrypoints.h"
29 #include "entrypoints/runtime_asm_entrypoints.h"
30 #include "interpreter/interpreter.h"
31 
32 namespace art HIDDEN {
33 
34 // Cast entrypoints.
35 extern "C" size_t artInstanceOfFromCode(mirror::Object* obj, mirror::Class* ref_class);
36 
37 // Read barrier entrypoints.
38 // art_quick_read_barrier_mark_regX uses an non-standard calling
39 // convention: it expects its input in register X and returns its
40 // result in that same register, and saves and restores all
41 // caller-save registers.
42 extern "C" mirror::Object* art_quick_read_barrier_mark_reg00(mirror::Object*);
43 extern "C" mirror::Object* art_quick_read_barrier_mark_reg01(mirror::Object*);
44 extern "C" mirror::Object* art_quick_read_barrier_mark_reg02(mirror::Object*);
45 extern "C" mirror::Object* art_quick_read_barrier_mark_reg03(mirror::Object*);
46 extern "C" mirror::Object* art_quick_read_barrier_mark_reg04(mirror::Object*);
47 extern "C" mirror::Object* art_quick_read_barrier_mark_reg05(mirror::Object*);
48 extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*);
49 extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*);
50 extern "C" mirror::Object* art_quick_read_barrier_mark_reg08(mirror::Object*);
51 extern "C" mirror::Object* art_quick_read_barrier_mark_reg09(mirror::Object*);
52 extern "C" mirror::Object* art_quick_read_barrier_mark_reg10(mirror::Object*);
53 extern "C" mirror::Object* art_quick_read_barrier_mark_reg11(mirror::Object*);
54 extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*);
55 extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*);
56 extern "C" mirror::Object* art_quick_read_barrier_mark_reg13(mirror::Object*);
57 extern "C" mirror::Object* art_quick_read_barrier_mark_reg14(mirror::Object*);
58 extern "C" mirror::Object* art_quick_read_barrier_mark_reg15(mirror::Object*);
59 extern "C" mirror::Object* art_quick_read_barrier_mark_reg16(mirror::Object*);
60 extern "C" mirror::Object* art_quick_read_barrier_mark_reg17(mirror::Object*);
61 extern "C" mirror::Object* art_quick_read_barrier_mark_reg18(mirror::Object*);
62 extern "C" mirror::Object* art_quick_read_barrier_mark_reg19(mirror::Object*);
63 extern "C" mirror::Object* art_quick_read_barrier_mark_reg20(mirror::Object*);
64 extern "C" mirror::Object* art_quick_read_barrier_mark_reg21(mirror::Object*);
65 extern "C" mirror::Object* art_quick_read_barrier_mark_reg22(mirror::Object*);
66 extern "C" mirror::Object* art_quick_read_barrier_mark_reg22(mirror::Object*);
67 extern "C" mirror::Object* art_quick_read_barrier_mark_reg23(mirror::Object*);
68 extern "C" mirror::Object* art_quick_read_barrier_mark_reg24(mirror::Object*);
69 extern "C" mirror::Object* art_quick_read_barrier_mark_reg25(mirror::Object*);
70 extern "C" mirror::Object* art_quick_read_barrier_mark_reg26(mirror::Object*);
71 extern "C" mirror::Object* art_quick_read_barrier_mark_reg27(mirror::Object*);
72 extern "C" mirror::Object* art_quick_read_barrier_mark_reg28(mirror::Object*);
73 extern "C" mirror::Object* art_quick_read_barrier_mark_reg29(mirror::Object*);
74 
75 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection(mirror::Object*);
76 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_arrays(mirror::Object*);
77 extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_gc_roots(mirror::Object*);
78 
UpdateReadBarrierEntrypoints(QuickEntryPoints * qpoints,bool is_active)79 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) {
80   // ARM64 is the architecture with the largest number of core
81   // registers (32) that supports the read barrier configuration.
82   // Because registers 30 (LR) and 31 (SP/XZR) cannot be used to pass
83   // arguments, only define ReadBarrierMarkRegX entrypoints for the
84   // first 30 registers.  This limitation is not a problem on other
85   // supported architectures (ARM, x86 and x86-64) either, as they
86   // have less core registers (resp. 16, 8 and 16).
87   // TODO: ARM/ARM64 now use introspection entrypoints. Consider
88   // reducing the number of entrypoints to those needed by x86-64.
89   qpoints->SetReadBarrierMarkReg00(is_active ? art_quick_read_barrier_mark_reg00 : nullptr);
90   qpoints->SetReadBarrierMarkReg01(is_active ? art_quick_read_barrier_mark_reg01 : nullptr);
91   qpoints->SetReadBarrierMarkReg02(is_active ? art_quick_read_barrier_mark_reg02 : nullptr);
92   qpoints->SetReadBarrierMarkReg03(is_active ? art_quick_read_barrier_mark_reg03 : nullptr);
93   qpoints->SetReadBarrierMarkReg04(is_active ? art_quick_read_barrier_mark_reg04 : nullptr);
94   qpoints->SetReadBarrierMarkReg05(is_active ? art_quick_read_barrier_mark_reg05 : nullptr);
95   qpoints->SetReadBarrierMarkReg06(is_active ? art_quick_read_barrier_mark_reg06 : nullptr);
96   qpoints->SetReadBarrierMarkReg07(is_active ? art_quick_read_barrier_mark_reg07 : nullptr);
97   qpoints->SetReadBarrierMarkReg08(is_active ? art_quick_read_barrier_mark_reg08 : nullptr);
98   qpoints->SetReadBarrierMarkReg09(is_active ? art_quick_read_barrier_mark_reg09 : nullptr);
99   qpoints->SetReadBarrierMarkReg10(is_active ? art_quick_read_barrier_mark_reg10 : nullptr);
100   qpoints->SetReadBarrierMarkReg11(is_active ? art_quick_read_barrier_mark_reg11 : nullptr);
101   qpoints->SetReadBarrierMarkReg12(is_active ? art_quick_read_barrier_mark_reg12 : nullptr);
102   qpoints->SetReadBarrierMarkReg13(is_active ? art_quick_read_barrier_mark_reg13 : nullptr);
103   qpoints->SetReadBarrierMarkReg14(is_active ? art_quick_read_barrier_mark_reg14 : nullptr);
104   qpoints->SetReadBarrierMarkReg15(is_active ? art_quick_read_barrier_mark_reg15 : nullptr);
105   qpoints->SetReadBarrierMarkReg17(is_active ? art_quick_read_barrier_mark_reg17 : nullptr);
106   qpoints->SetReadBarrierMarkReg19(is_active ? art_quick_read_barrier_mark_reg19 : nullptr);
107   qpoints->SetReadBarrierMarkReg20(is_active ? art_quick_read_barrier_mark_reg20 : nullptr);
108   qpoints->SetReadBarrierMarkReg21(is_active ? art_quick_read_barrier_mark_reg21 : nullptr);
109   qpoints->SetReadBarrierMarkReg22(is_active ? art_quick_read_barrier_mark_reg22 : nullptr);
110   qpoints->SetReadBarrierMarkReg23(is_active ? art_quick_read_barrier_mark_reg23 : nullptr);
111   qpoints->SetReadBarrierMarkReg24(is_active ? art_quick_read_barrier_mark_reg24 : nullptr);
112   qpoints->SetReadBarrierMarkReg25(is_active ? art_quick_read_barrier_mark_reg25 : nullptr);
113   qpoints->SetReadBarrierMarkReg26(is_active ? art_quick_read_barrier_mark_reg26 : nullptr);
114   qpoints->SetReadBarrierMarkReg27(is_active ? art_quick_read_barrier_mark_reg27 : nullptr);
115   qpoints->SetReadBarrierMarkReg28(is_active ? art_quick_read_barrier_mark_reg28 : nullptr);
116   qpoints->SetReadBarrierMarkReg29(is_active ? art_quick_read_barrier_mark_reg29 : nullptr);
117 
118   // Check that array switch cases are at appropriate offsets from the introspection entrypoint.
119   DCHECK_ALIGNED(art_quick_read_barrier_mark_introspection, 512u);
120   intptr_t array_diff =
121       reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_arrays) -
122       reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection);
123   DCHECK_EQ(BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET, array_diff);
124   // Check that the GC root entrypoint is at appropriate offset from the introspection entrypoint.
125   intptr_t gc_roots_diff =
126       reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection_gc_roots) -
127       reinterpret_cast<intptr_t>(art_quick_read_barrier_mark_introspection);
128   DCHECK_EQ(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET, gc_roots_diff);
129   // The register 16, i.e. IP0, is reserved, so there is no art_quick_read_barrier_mark_reg16.
130   // We're using the entry to hold a pointer to the introspection entrypoint instead.
131   qpoints->SetReadBarrierMarkReg16(is_active ? art_quick_read_barrier_mark_introspection : nullptr);
132 }
133 
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints,bool monitor_jni_entry_exit)134 void InitEntryPoints(JniEntryPoints* jpoints,
135                      QuickEntryPoints* qpoints,
136                      bool monitor_jni_entry_exit) {
137   DefaultInitEntryPoints(jpoints, qpoints, monitor_jni_entry_exit);
138 
139   // Cast
140   qpoints->SetInstanceofNonTrivial(artInstanceOfFromCode);
141   qpoints->SetCheckInstanceOf(art_quick_check_instance_of);
142 
143   // Math
144   // TODO null entrypoints not needed for ARM64 - generate inline.
145   qpoints->SetCmpgDouble(nullptr);
146   qpoints->SetCmpgFloat(nullptr);
147   qpoints->SetCmplDouble(nullptr);
148   qpoints->SetCmplFloat(nullptr);
149   qpoints->SetFmod(fmod);
150   qpoints->SetL2d(nullptr);
151   qpoints->SetFmodf(fmodf);
152   qpoints->SetL2f(nullptr);
153   qpoints->SetD2iz(nullptr);
154   qpoints->SetF2iz(nullptr);
155   qpoints->SetIdivmod(nullptr);
156   qpoints->SetD2l(nullptr);
157   qpoints->SetF2l(nullptr);
158   qpoints->SetLdiv(nullptr);
159   qpoints->SetLmod(nullptr);
160   qpoints->SetLmul(nullptr);
161   qpoints->SetShlLong(nullptr);
162   qpoints->SetShrLong(nullptr);
163   qpoints->SetUshrLong(nullptr);
164 
165   // More math.
166   qpoints->SetCos(cos);
167   qpoints->SetSin(sin);
168   qpoints->SetAcos(acos);
169   qpoints->SetAsin(asin);
170   qpoints->SetAtan(atan);
171   qpoints->SetAtan2(atan2);
172   qpoints->SetPow(pow);
173   qpoints->SetCbrt(cbrt);
174   qpoints->SetCosh(cosh);
175   qpoints->SetExp(exp);
176   qpoints->SetExpm1(expm1);
177   qpoints->SetHypot(hypot);
178   qpoints->SetLog(log);
179   qpoints->SetLog10(log10);
180   qpoints->SetNextAfter(nextafter);
181   qpoints->SetSinh(sinh);
182   qpoints->SetTan(tan);
183   qpoints->SetTanh(tanh);
184 
185   // Intrinsics
186   qpoints->SetIndexOf(art_quick_indexof);
187   // The ARM64 StringCompareTo intrinsic does not call the runtime.
188   qpoints->SetStringCompareTo(nullptr);
189   qpoints->SetMemcpy(memcpy);
190 
191   // Read barrier.
192   qpoints->SetReadBarrierMarkReg16(nullptr);  // IP0 is used as a temp by the asm stub.
193   UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false);
194   qpoints->SetReadBarrierSlow(artReadBarrierSlow);
195   qpoints->SetReadBarrierForRootSlow(artReadBarrierForRootSlow);
196 }
197 
198 }  // namespace art
199