1 /*
2 * Copyright (C) 2023 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
19 #include "entrypoints/quick/quick_default_init_entrypoints.h"
20 #include "entrypoints/quick/quick_entrypoints.h"
21 #include "entrypoints/quick/runtime_entrypoints_list.h"
22
23 namespace art HIDDEN {
24
25 // Read barrier entrypoints.
26 // art_quick_read_barrier_mark_regX uses an non-standard calling convention: it
27 // expects its input in register X and returns its result in that same register,
28 // and saves and restores all other registers.
29 // No read barrier for X0 (Zero), X1 (RA), X2 (SP), X3 (GP) and X4 (TP).
30 extern "C" mirror::Object* art_quick_read_barrier_mark_reg05(mirror::Object*); // t0/x5
31 extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*); // t1/x6
32 extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*); // t2/x7
33 extern "C" mirror::Object* art_quick_read_barrier_mark_reg08(mirror::Object*); // t3/x8
34 // No read barrier for X9 (S1/xSELF).
35 extern "C" mirror::Object* art_quick_read_barrier_mark_reg10(mirror::Object*); // a0/x10
36 extern "C" mirror::Object* art_quick_read_barrier_mark_reg11(mirror::Object*); // a1/x11
37 extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*); // a2/x12
38 extern "C" mirror::Object* art_quick_read_barrier_mark_reg13(mirror::Object*); // a3/x13
39 extern "C" mirror::Object* art_quick_read_barrier_mark_reg14(mirror::Object*); // a4/x14
40 extern "C" mirror::Object* art_quick_read_barrier_mark_reg15(mirror::Object*); // a5/x15
41 extern "C" mirror::Object* art_quick_read_barrier_mark_reg16(mirror::Object*); // a6/x16
42 extern "C" mirror::Object* art_quick_read_barrier_mark_reg17(mirror::Object*); // a7/x17
43 extern "C" mirror::Object* art_quick_read_barrier_mark_reg18(mirror::Object*); // s2/x18
44 extern "C" mirror::Object* art_quick_read_barrier_mark_reg19(mirror::Object*); // s3/x19
45 extern "C" mirror::Object* art_quick_read_barrier_mark_reg20(mirror::Object*); // s4/x20
46 extern "C" mirror::Object* art_quick_read_barrier_mark_reg21(mirror::Object*); // s5/x21
47 extern "C" mirror::Object* art_quick_read_barrier_mark_reg22(mirror::Object*); // s6/x22
48 extern "C" mirror::Object* art_quick_read_barrier_mark_reg23(mirror::Object*); // s7/x23
49 extern "C" mirror::Object* art_quick_read_barrier_mark_reg24(mirror::Object*); // s8/x24
50 extern "C" mirror::Object* art_quick_read_barrier_mark_reg25(mirror::Object*); // s9/x25
51 extern "C" mirror::Object* art_quick_read_barrier_mark_reg26(mirror::Object*); // s10/x26
52 extern "C" mirror::Object* art_quick_read_barrier_mark_reg27(mirror::Object*); // s11/x27
53 extern "C" mirror::Object* art_quick_read_barrier_mark_reg28(mirror::Object*); // t3/x28
54 extern "C" mirror::Object* art_quick_read_barrier_mark_reg29(mirror::Object*); // t4/x29
55 extern "C" mirror::Object* art_quick_read_barrier_mark_reg30(mirror::Object*); // t5/x30
56 extern "C" mirror::Object* art_quick_read_barrier_mark_reg31(mirror::Object*); // t6/x31
57
UpdateReadBarrierEntrypoints(QuickEntryPoints * qpoints,bool is_active)58 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) {
59 // No read barrier for X0 (Zero), X1 (RA), X2 (SP), X3 (GP) and X4 (TP).
60 qpoints->SetReadBarrierMarkReg05(is_active ? art_quick_read_barrier_mark_reg05 : nullptr);
61 qpoints->SetReadBarrierMarkReg06(is_active ? art_quick_read_barrier_mark_reg06 : nullptr);
62 qpoints->SetReadBarrierMarkReg07(is_active ? art_quick_read_barrier_mark_reg07 : nullptr);
63 qpoints->SetReadBarrierMarkReg08(is_active ? art_quick_read_barrier_mark_reg08 : nullptr);
64 // No read barrier for X9 (S1/xSELF).
65 qpoints->SetReadBarrierMarkReg10(is_active ? art_quick_read_barrier_mark_reg10 : nullptr);
66 qpoints->SetReadBarrierMarkReg11(is_active ? art_quick_read_barrier_mark_reg11 : nullptr);
67 qpoints->SetReadBarrierMarkReg12(is_active ? art_quick_read_barrier_mark_reg12 : nullptr);
68 qpoints->SetReadBarrierMarkReg13(is_active ? art_quick_read_barrier_mark_reg13 : nullptr);
69 qpoints->SetReadBarrierMarkReg14(is_active ? art_quick_read_barrier_mark_reg14 : nullptr);
70 qpoints->SetReadBarrierMarkReg15(is_active ? art_quick_read_barrier_mark_reg15 : nullptr);
71 qpoints->SetReadBarrierMarkReg16(is_active ? art_quick_read_barrier_mark_reg16 : nullptr);
72 qpoints->SetReadBarrierMarkReg17(is_active ? art_quick_read_barrier_mark_reg17 : nullptr);
73 qpoints->SetReadBarrierMarkReg18(is_active ? art_quick_read_barrier_mark_reg18 : nullptr);
74 qpoints->SetReadBarrierMarkReg19(is_active ? art_quick_read_barrier_mark_reg19 : nullptr);
75 qpoints->SetReadBarrierMarkReg20(is_active ? art_quick_read_barrier_mark_reg20 : nullptr);
76 qpoints->SetReadBarrierMarkReg21(is_active ? art_quick_read_barrier_mark_reg21 : nullptr);
77 qpoints->SetReadBarrierMarkReg22(is_active ? art_quick_read_barrier_mark_reg22 : nullptr);
78 qpoints->SetReadBarrierMarkReg23(is_active ? art_quick_read_barrier_mark_reg23 : nullptr);
79 qpoints->SetReadBarrierMarkReg24(is_active ? art_quick_read_barrier_mark_reg24 : nullptr);
80 qpoints->SetReadBarrierMarkReg25(is_active ? art_quick_read_barrier_mark_reg25 : nullptr);
81 qpoints->SetReadBarrierMarkReg26(is_active ? art_quick_read_barrier_mark_reg26 : nullptr);
82 qpoints->SetReadBarrierMarkReg27(is_active ? art_quick_read_barrier_mark_reg27 : nullptr);
83 qpoints->SetReadBarrierMarkReg28(is_active ? art_quick_read_barrier_mark_reg28 : nullptr);
84 qpoints->SetReadBarrierMarkReg29(is_active ? art_quick_read_barrier_mark_reg29 : nullptr);
85 // Note: Entrypoints for registers X30 (T5) and T31 (T6) are stored in entries
86 // for X0 (Zero) and X1 (RA) because these are not valid registers for marking
87 // and we currently have slots only up to register 29.
88 qpoints->SetReadBarrierMarkReg00(is_active ? art_quick_read_barrier_mark_reg30 : nullptr);
89 qpoints->SetReadBarrierMarkReg01(is_active ? art_quick_read_barrier_mark_reg31 : nullptr);
90 }
91
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints,bool monitor_jni_entry_exit)92 void InitEntryPoints(JniEntryPoints* jpoints,
93 QuickEntryPoints* qpoints,
94 bool monitor_jni_entry_exit) {
95 DefaultInitEntryPoints(jpoints, qpoints, monitor_jni_entry_exit);
96
97 // Cast
98 qpoints->SetInstanceofNonTrivial(artInstanceOfFromCode);
99 qpoints->SetCheckInstanceOf(art_quick_check_instance_of);
100
101 // Math
102 // TODO(riscv64): null entrypoints not needed for riscv64 - using generated code.
103 qpoints->SetCmpgDouble(nullptr);
104 qpoints->SetCmpgFloat(nullptr);
105 qpoints->SetCmplDouble(nullptr);
106 qpoints->SetCmplFloat(nullptr);
107 qpoints->SetFmod(fmod);
108 qpoints->SetL2d(nullptr);
109 qpoints->SetFmodf(fmodf);
110 qpoints->SetL2f(nullptr);
111 qpoints->SetD2iz(nullptr);
112 qpoints->SetF2iz(nullptr);
113 qpoints->SetIdivmod(nullptr);
114 qpoints->SetD2l(nullptr);
115 qpoints->SetF2l(nullptr);
116 qpoints->SetLdiv(nullptr);
117 qpoints->SetLmod(nullptr);
118 qpoints->SetLmul(nullptr);
119 qpoints->SetShlLong(nullptr);
120 qpoints->SetShrLong(nullptr);
121 qpoints->SetUshrLong(nullptr);
122
123 // More math.
124 qpoints->SetCos(cos);
125 qpoints->SetSin(sin);
126 qpoints->SetAcos(acos);
127 qpoints->SetAsin(asin);
128 qpoints->SetAtan(atan);
129 qpoints->SetAtan2(atan2);
130 qpoints->SetPow(pow);
131 qpoints->SetCbrt(cbrt);
132 qpoints->SetCosh(cosh);
133 qpoints->SetExp(exp);
134 qpoints->SetExpm1(expm1);
135 qpoints->SetHypot(hypot);
136 qpoints->SetLog(log);
137 qpoints->SetLog10(log10);
138 qpoints->SetNextAfter(nextafter);
139 qpoints->SetSinh(sinh);
140 qpoints->SetTan(tan);
141 qpoints->SetTanh(tanh);
142
143 // Intrinsics
144 qpoints->SetIndexOf(art_quick_indexof);
145 // TODO(riscv64): More intrinsics.
146
147 // Read barrier.
148 UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false);
149 qpoints->SetReadBarrierSlow(artReadBarrierSlow);
150 qpoints->SetReadBarrierForRootSlow(artReadBarrierForRootSlow);
151 }
152
UpdateLowOverheadTraceEntrypoints(QuickEntryPoints * qpoints,bool enable)153 void UpdateLowOverheadTraceEntrypoints([[maybe_unused]] QuickEntryPoints* qpoints,
154 [[maybe_unused]] bool enable) {
155 // This is a nop on this architecture. Low overhead tracing is only implemented for ARM64.
156 }
157
158 } // namespace art
159