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 HIDDEN {
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->SetReadBarrierMarkReg00(is_active ? art_quick_read_barrier_mark_reg00 : nullptr);
60   qpoints->SetReadBarrierMarkReg01(is_active ? art_quick_read_barrier_mark_reg01 : nullptr);
61   qpoints->SetReadBarrierMarkReg02(is_active ? art_quick_read_barrier_mark_reg02 : nullptr);
62   qpoints->SetReadBarrierMarkReg03(is_active ? art_quick_read_barrier_mark_reg03 : nullptr);
63   qpoints->SetReadBarrierMarkReg05(is_active ? art_quick_read_barrier_mark_reg05 : nullptr);
64   qpoints->SetReadBarrierMarkReg06(is_active ? art_quick_read_barrier_mark_reg06 : nullptr);
65   qpoints->SetReadBarrierMarkReg07(is_active ? art_quick_read_barrier_mark_reg07 : nullptr);
66   qpoints->SetReadBarrierMarkReg08(is_active ? art_quick_read_barrier_mark_reg08 : nullptr);
67   qpoints->SetReadBarrierMarkReg09(is_active ? art_quick_read_barrier_mark_reg09 : nullptr);
68   qpoints->SetReadBarrierMarkReg10(is_active ? art_quick_read_barrier_mark_reg10 : nullptr);
69   qpoints->SetReadBarrierMarkReg11(is_active ? art_quick_read_barrier_mark_reg11 : nullptr);
70   qpoints->SetReadBarrierMarkReg12(is_active ? art_quick_read_barrier_mark_reg12 : nullptr);
71   qpoints->SetReadBarrierMarkReg13(is_active ? art_quick_read_barrier_mark_reg13 : nullptr);
72   qpoints->SetReadBarrierMarkReg14(is_active ? art_quick_read_barrier_mark_reg14 : nullptr);
73   qpoints->SetReadBarrierMarkReg15(is_active ? art_quick_read_barrier_mark_reg15 : nullptr);
74 }
75 
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints,bool monitor_jni_entry_exit)76 void InitEntryPoints(JniEntryPoints* jpoints,
77                      QuickEntryPoints* qpoints,
78                      bool monitor_jni_entry_exit) {
79 #if defined(__APPLE__)
80   UNUSED(jpoints, qpoints);
81   UNIMPLEMENTED(FATAL);
82 #else
83   DefaultInitEntryPoints(jpoints, qpoints, monitor_jni_entry_exit);
84 
85   // Cast
86   qpoints->SetInstanceofNonTrivial(art_quick_instance_of);
87   qpoints->SetCheckInstanceOf(art_quick_check_instance_of);
88 
89   // More math.
90   qpoints->SetCos(cos);
91   qpoints->SetSin(sin);
92   qpoints->SetAcos(acos);
93   qpoints->SetAsin(asin);
94   qpoints->SetAtan(atan);
95   qpoints->SetAtan2(atan2);
96   qpoints->SetPow(pow);
97   qpoints->SetCbrt(cbrt);
98   qpoints->SetCosh(cosh);
99   qpoints->SetExp(exp);
100   qpoints->SetExpm1(expm1);
101   qpoints->SetHypot(hypot);
102   qpoints->SetLog(log);
103   qpoints->SetLog10(log10);
104   qpoints->SetNextAfter(nextafter);
105   qpoints->SetSinh(sinh);
106   qpoints->SetTan(tan);
107   qpoints->SetTanh(tanh);
108 
109   // Math
110   qpoints->SetD2l(art_d2l);
111   qpoints->SetF2l(art_f2l);
112   qpoints->SetLdiv(art_quick_ldiv);
113   qpoints->SetLmod(art_quick_lmod);
114   qpoints->SetLmul(art_quick_lmul);
115   qpoints->SetShlLong(art_quick_lshl);
116   qpoints->SetShrLong(art_quick_lshr);
117   qpoints->SetUshrLong(art_quick_lushr);
118 
119   // Intrinsics
120   qpoints->SetStringCompareTo(art_quick_string_compareto);
121   qpoints->SetMemcpy(art_quick_memcpy);
122 
123   // Read barrier.
124   UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false);
125   qpoints->SetReadBarrierMarkReg04(nullptr);  // Cannot use register 4 (RSP) to pass arguments.
126   // x86-64 has only 16 core registers.
127   qpoints->SetReadBarrierMarkReg16(nullptr);
128   qpoints->SetReadBarrierMarkReg17(nullptr);
129   qpoints->SetReadBarrierMarkReg18(nullptr);
130   qpoints->SetReadBarrierMarkReg19(nullptr);
131   qpoints->SetReadBarrierMarkReg20(nullptr);
132   qpoints->SetReadBarrierMarkReg21(nullptr);
133   qpoints->SetReadBarrierMarkReg22(nullptr);
134   qpoints->SetReadBarrierMarkReg23(nullptr);
135   qpoints->SetReadBarrierMarkReg24(nullptr);
136   qpoints->SetReadBarrierMarkReg25(nullptr);
137   qpoints->SetReadBarrierMarkReg26(nullptr);
138   qpoints->SetReadBarrierMarkReg27(nullptr);
139   qpoints->SetReadBarrierMarkReg28(nullptr);
140   qpoints->SetReadBarrierMarkReg29(nullptr);
141   qpoints->SetReadBarrierSlow(art_quick_read_barrier_slow);
142   qpoints->SetReadBarrierForRootSlow(art_quick_read_barrier_for_root_slow);
143 #endif  // __APPLE__
144 }
145 
146 }  // namespace art
147