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/quick/quick_alloc_entrypoints.h"
21 #include "entrypoints/quick/quick_default_externs.h"
22 #include "entrypoints/quick/quick_default_init_entrypoints.h"
23 #include "entrypoints/quick/quick_entrypoints.h"
24 #include "entrypoints/runtime_asm_entrypoints.h"
25 #include "interpreter/interpreter.h"
26 
27 namespace art HIDDEN {
28 
29 // Cast entrypoints.
30 extern "C" size_t art_quick_instance_of(mirror::Object* obj, mirror::Class* ref_class);
31 
32 // Read barrier entrypoints.
33 // art_quick_read_barrier_mark_regX uses an non-standard calling
34 // convention: it expects its input in register X and returns its
35 // result in that same register, and saves and restores all
36 // caller-save registers.
37 extern "C" mirror::Object* art_quick_read_barrier_mark_reg00(mirror::Object*);
38 extern "C" mirror::Object* art_quick_read_barrier_mark_reg01(mirror::Object*);
39 extern "C" mirror::Object* art_quick_read_barrier_mark_reg02(mirror::Object*);
40 extern "C" mirror::Object* art_quick_read_barrier_mark_reg03(mirror::Object*);
41 extern "C" mirror::Object* art_quick_read_barrier_mark_reg05(mirror::Object*);
42 extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*);
43 extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*);
44 extern "C" mirror::Object* art_quick_read_barrier_slow(mirror::Object*, mirror::Object*, uint32_t);
45 extern "C" mirror::Object* art_quick_read_barrier_for_root_slow(GcRoot<mirror::Object>*);
46 
UpdateReadBarrierEntrypoints(QuickEntryPoints * qpoints,bool is_active)47 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) {
48   qpoints->SetReadBarrierMarkReg00(is_active ? art_quick_read_barrier_mark_reg00 : nullptr);
49   qpoints->SetReadBarrierMarkReg01(is_active ? art_quick_read_barrier_mark_reg01 : nullptr);
50   qpoints->SetReadBarrierMarkReg02(is_active ? art_quick_read_barrier_mark_reg02 : nullptr);
51   qpoints->SetReadBarrierMarkReg03(is_active ? art_quick_read_barrier_mark_reg03 : nullptr);
52   qpoints->SetReadBarrierMarkReg05(is_active ? art_quick_read_barrier_mark_reg05 : nullptr);
53   qpoints->SetReadBarrierMarkReg06(is_active ? art_quick_read_barrier_mark_reg06 : nullptr);
54   qpoints->SetReadBarrierMarkReg07(is_active ? art_quick_read_barrier_mark_reg07 : nullptr);
55 }
56 
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints,bool monitor_jni_entry_exit)57 void InitEntryPoints(JniEntryPoints* jpoints,
58                      QuickEntryPoints* qpoints,
59                      bool monitor_jni_entry_exit) {
60   DefaultInitEntryPoints(jpoints, qpoints, monitor_jni_entry_exit);
61 
62   // Cast
63   qpoints->SetInstanceofNonTrivial(art_quick_instance_of);
64   qpoints->SetCheckInstanceOf(art_quick_check_instance_of);
65 
66   // More math.
67   qpoints->SetCos(cos);
68   qpoints->SetSin(sin);
69   qpoints->SetAcos(acos);
70   qpoints->SetAsin(asin);
71   qpoints->SetAtan(atan);
72   qpoints->SetAtan2(atan2);
73   qpoints->SetPow(pow);
74   qpoints->SetCbrt(cbrt);
75   qpoints->SetCosh(cosh);
76   qpoints->SetExp(exp);
77   qpoints->SetExpm1(expm1);
78   qpoints->SetHypot(hypot);
79   qpoints->SetLog(log);
80   qpoints->SetLog10(log10);
81   qpoints->SetNextAfter(nextafter);
82   qpoints->SetSinh(sinh);
83   qpoints->SetTan(tan);
84   qpoints->SetTanh(tanh);
85 
86   // Math
87   qpoints->SetD2l(art_quick_d2l);
88   qpoints->SetF2l(art_quick_f2l);
89   qpoints->SetLdiv(art_quick_ldiv);
90   qpoints->SetLmod(art_quick_lmod);
91   qpoints->SetLmul(art_quick_lmul);
92   qpoints->SetShlLong(art_quick_lshl);
93   qpoints->SetShrLong(art_quick_lshr);
94   qpoints->SetUshrLong(art_quick_lushr);
95 
96   // Intrinsics
97   // qpoints->pIndexOf = nullptr;  // Not needed on x86
98   qpoints->SetStringCompareTo(art_quick_string_compareto);
99   qpoints->SetMemcpy(art_quick_memcpy);
100 
101   // Read barrier.
102   UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false);
103   qpoints->SetReadBarrierMarkReg04(nullptr);  // Cannot use register 4 (ESP) to pass arguments.
104   // x86 has only 8 core registers.
105   qpoints->SetReadBarrierMarkReg08(nullptr);
106   qpoints->SetReadBarrierMarkReg09(nullptr);
107   qpoints->SetReadBarrierMarkReg10(nullptr);
108   qpoints->SetReadBarrierMarkReg11(nullptr);
109   qpoints->SetReadBarrierMarkReg12(nullptr);
110   qpoints->SetReadBarrierMarkReg13(nullptr);
111   qpoints->SetReadBarrierMarkReg14(nullptr);
112   qpoints->SetReadBarrierMarkReg15(nullptr);
113   qpoints->SetReadBarrierMarkReg16(nullptr);
114   qpoints->SetReadBarrierMarkReg17(nullptr);
115   qpoints->SetReadBarrierMarkReg18(nullptr);
116   qpoints->SetReadBarrierMarkReg19(nullptr);
117   qpoints->SetReadBarrierMarkReg20(nullptr);
118   qpoints->SetReadBarrierMarkReg21(nullptr);
119   qpoints->SetReadBarrierMarkReg22(nullptr);
120   qpoints->SetReadBarrierMarkReg23(nullptr);
121   qpoints->SetReadBarrierMarkReg24(nullptr);
122   qpoints->SetReadBarrierMarkReg25(nullptr);
123   qpoints->SetReadBarrierMarkReg26(nullptr);
124   qpoints->SetReadBarrierMarkReg27(nullptr);
125   qpoints->SetReadBarrierMarkReg28(nullptr);
126   qpoints->SetReadBarrierMarkReg29(nullptr);
127   qpoints->SetReadBarrierSlow(art_quick_read_barrier_slow);
128   qpoints->SetReadBarrierForRootSlow(art_quick_read_barrier_for_root_slow);
129 }
130 
131 }  // namespace art
132