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
19 #include "entrypoints/jni/jni_entrypoints.h"
20 #include "entrypoints/math_entrypoints.h"
21 #include "entrypoints/quick/quick_alloc_entrypoints.h"
22 #include "entrypoints/quick/quick_default_externs.h"
23 #if !defined(__APPLE__)
24 #include "entrypoints/quick/quick_default_init_entrypoints.h"
25 #endif
26 #include "entrypoints/quick/quick_entrypoints.h"
27 #include "entrypoints/runtime_asm_entrypoints.h"
28 #include "interpreter/interpreter.h"
29
30 namespace art {
31
32 // Cast entrypoints.
33 extern "C" size_t art_quick_instance_of(mirror::Object* obj, mirror::Class* ref_class);
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_reg05(mirror::Object*);
45 extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*);
46 extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*);
47 extern "C" mirror::Object* art_quick_read_barrier_mark_reg08(mirror::Object*);
48 extern "C" mirror::Object* art_quick_read_barrier_mark_reg09(mirror::Object*);
49 extern "C" mirror::Object* art_quick_read_barrier_mark_reg10(mirror::Object*);
50 extern "C" mirror::Object* art_quick_read_barrier_mark_reg11(mirror::Object*);
51 extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*);
52 extern "C" mirror::Object* art_quick_read_barrier_mark_reg13(mirror::Object*);
53 extern "C" mirror::Object* art_quick_read_barrier_mark_reg14(mirror::Object*);
54 extern "C" mirror::Object* art_quick_read_barrier_mark_reg15(mirror::Object*);
55 extern "C" mirror::Object* art_quick_read_barrier_slow(mirror::Object*, mirror::Object*, uint32_t);
56 extern "C" mirror::Object* art_quick_read_barrier_for_root_slow(GcRoot<mirror::Object>*);
57
UpdateReadBarrierEntrypoints(QuickEntryPoints * qpoints,bool is_active)58 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) {
59 qpoints->pReadBarrierMarkReg00 = is_active ? art_quick_read_barrier_mark_reg00 : nullptr;
60 qpoints->pReadBarrierMarkReg01 = is_active ? art_quick_read_barrier_mark_reg01 : nullptr;
61 qpoints->pReadBarrierMarkReg02 = is_active ? art_quick_read_barrier_mark_reg02 : nullptr;
62 qpoints->pReadBarrierMarkReg03 = is_active ? art_quick_read_barrier_mark_reg03 : nullptr;
63 qpoints->pReadBarrierMarkReg05 = is_active ? art_quick_read_barrier_mark_reg05 : nullptr;
64 qpoints->pReadBarrierMarkReg06 = is_active ? art_quick_read_barrier_mark_reg06 : nullptr;
65 qpoints->pReadBarrierMarkReg07 = is_active ? art_quick_read_barrier_mark_reg07 : nullptr;
66 qpoints->pReadBarrierMarkReg08 = is_active ? art_quick_read_barrier_mark_reg08 : nullptr;
67 qpoints->pReadBarrierMarkReg09 = is_active ? art_quick_read_barrier_mark_reg09 : nullptr;
68 qpoints->pReadBarrierMarkReg10 = is_active ? art_quick_read_barrier_mark_reg10 : nullptr;
69 qpoints->pReadBarrierMarkReg11 = is_active ? art_quick_read_barrier_mark_reg11 : nullptr;
70 qpoints->pReadBarrierMarkReg12 = is_active ? art_quick_read_barrier_mark_reg12 : nullptr;
71 qpoints->pReadBarrierMarkReg13 = is_active ? art_quick_read_barrier_mark_reg13 : nullptr;
72 qpoints->pReadBarrierMarkReg14 = is_active ? art_quick_read_barrier_mark_reg14 : nullptr;
73 qpoints->pReadBarrierMarkReg15 = is_active ? art_quick_read_barrier_mark_reg15 : nullptr;
74 }
75
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints)76 void InitEntryPoints(JniEntryPoints* jpoints, QuickEntryPoints* qpoints) {
77 #if defined(__APPLE__)
78 UNUSED(jpoints, qpoints);
79 UNIMPLEMENTED(FATAL);
80 #else
81 DefaultInitEntryPoints(jpoints, qpoints);
82
83 // Cast
84 qpoints->pInstanceofNonTrivial = art_quick_instance_of;
85 qpoints->pCheckInstanceOf = art_quick_check_instance_of;
86
87 // More math.
88 qpoints->pCos = cos;
89 qpoints->pSin = sin;
90 qpoints->pAcos = acos;
91 qpoints->pAsin = asin;
92 qpoints->pAtan = atan;
93 qpoints->pAtan2 = atan2;
94 qpoints->pPow = pow;
95 qpoints->pCbrt = cbrt;
96 qpoints->pCosh = cosh;
97 qpoints->pExp = exp;
98 qpoints->pExpm1 = expm1;
99 qpoints->pHypot = hypot;
100 qpoints->pLog = log;
101 qpoints->pLog10 = log10;
102 qpoints->pNextAfter = nextafter;
103 qpoints->pSinh = sinh;
104 qpoints->pTan = tan;
105 qpoints->pTanh = tanh;
106
107 // Math
108 qpoints->pD2l = art_d2l;
109 qpoints->pF2l = art_f2l;
110 qpoints->pLdiv = art_quick_ldiv;
111 qpoints->pLmod = art_quick_lmod;
112 qpoints->pLmul = art_quick_lmul;
113 qpoints->pShlLong = art_quick_lshl;
114 qpoints->pShrLong = art_quick_lshr;
115 qpoints->pUshrLong = art_quick_lushr;
116
117 // Intrinsics
118 qpoints->pStringCompareTo = art_quick_string_compareto;
119 qpoints->pMemcpy = art_quick_memcpy;
120
121 // Read barrier.
122 qpoints->pReadBarrierJni = ReadBarrierJni;
123 UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false);
124 qpoints->pReadBarrierMarkReg04 = nullptr; // Cannot use register 4 (RSP) to pass arguments.
125 // x86-64 has only 16 core registers.
126 qpoints->pReadBarrierMarkReg16 = nullptr;
127 qpoints->pReadBarrierMarkReg17 = nullptr;
128 qpoints->pReadBarrierMarkReg18 = nullptr;
129 qpoints->pReadBarrierMarkReg19 = nullptr;
130 qpoints->pReadBarrierMarkReg20 = nullptr;
131 qpoints->pReadBarrierMarkReg21 = nullptr;
132 qpoints->pReadBarrierMarkReg22 = nullptr;
133 qpoints->pReadBarrierMarkReg23 = nullptr;
134 qpoints->pReadBarrierMarkReg24 = nullptr;
135 qpoints->pReadBarrierMarkReg25 = nullptr;
136 qpoints->pReadBarrierMarkReg26 = nullptr;
137 qpoints->pReadBarrierMarkReg27 = nullptr;
138 qpoints->pReadBarrierMarkReg28 = nullptr;
139 qpoints->pReadBarrierMarkReg29 = nullptr;
140 qpoints->pReadBarrierSlow = art_quick_read_barrier_slow;
141 qpoints->pReadBarrierForRootSlow = art_quick_read_barrier_for_root_slow;
142 #endif // __APPLE__
143 }
144
145 } // namespace art
146