• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #ifndef ART_COMPILER_UTILS_ARM_JNI_MACRO_ASSEMBLER_ARM_VIXL_H_
18 #define ART_COMPILER_UTILS_ARM_JNI_MACRO_ASSEMBLER_ARM_VIXL_H_
19 
20 #include <android-base/logging.h>
21 
22 #include "base/arena_containers.h"
23 #include "base/macros.h"
24 #include "constants_arm.h"
25 #include "offsets.h"
26 #include "utils/arm/assembler_arm_shared.h"
27 #include "utils/arm/assembler_arm_vixl.h"
28 #include "utils/arm/managed_register_arm.h"
29 #include "utils/assembler.h"
30 #include "utils/jni_macro_assembler.h"
31 
32 namespace art {
33 namespace arm {
34 
35 class ArmVIXLJNIMacroAssembler final
36     : public JNIMacroAssemblerFwd<ArmVIXLAssembler, PointerSize::k32> {
37  private:
38   class ArmException;
39  public:
ArmVIXLJNIMacroAssembler(ArenaAllocator * allocator)40   explicit ArmVIXLJNIMacroAssembler(ArenaAllocator* allocator)
41       : JNIMacroAssemblerFwd(allocator),
42         exception_blocks_(allocator->Adapter(kArenaAllocAssembler)) {}
43 
~ArmVIXLJNIMacroAssembler()44   virtual ~ArmVIXLJNIMacroAssembler() {}
45   void FinalizeCode() override;
46 
47   //
48   // Overridden common assembler high-level functionality
49   //
50 
51   // Emit code that will create an activation on the stack.
52   void BuildFrame(size_t frame_size,
53                   ManagedRegister method_reg,
54                   ArrayRef<const ManagedRegister> callee_save_regs) override;
55 
56   // Emit code that will remove an activation from the stack.
57   void RemoveFrame(size_t frame_size,
58                    ArrayRef<const ManagedRegister> callee_save_regs,
59                    bool may_suspend) override;
60 
61   void IncreaseFrameSize(size_t adjust) override;
62   void DecreaseFrameSize(size_t adjust) override;
63 
64   // Store routines.
65   void Store(FrameOffset offs, ManagedRegister src, size_t size) override;
66   void StoreRef(FrameOffset dest, ManagedRegister src) override;
67   void StoreRawPtr(FrameOffset dest, ManagedRegister src) override;
68 
69   void StoreImmediateToFrame(FrameOffset dest, uint32_t imm) override;
70 
71   void StoreStackOffsetToThread(ThreadOffset32 thr_offs, FrameOffset fr_offs) override;
72 
73   void StoreStackPointerToThread(ThreadOffset32 thr_offs) override;
74 
75   void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off) override;
76 
77   // Load routines.
78   void Load(ManagedRegister dest, FrameOffset src, size_t size) override;
79 
80   void LoadFromThread(ManagedRegister dest,
81                       ThreadOffset32 src,
82                       size_t size) override;
83 
84   void LoadRef(ManagedRegister dest, FrameOffset src) override;
85 
86   void LoadRef(ManagedRegister dest,
87                ManagedRegister base,
88                MemberOffset offs,
89                bool unpoison_reference) override;
90 
91   void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) override;
92 
93   void LoadRawPtrFromThread(ManagedRegister dest, ThreadOffset32 offs) override;
94 
95   // Copying routines.
96   void MoveArguments(ArrayRef<ArgumentLocation> dests, ArrayRef<ArgumentLocation> srcs) override;
97 
98   void Move(ManagedRegister dest, ManagedRegister src, size_t size) override;
99 
100   void CopyRawPtrFromThread(FrameOffset fr_offs, ThreadOffset32 thr_offs) override;
101 
102   void CopyRawPtrToThread(ThreadOffset32 thr_offs,
103                           FrameOffset fr_offs,
104                           ManagedRegister scratch) override;
105 
106   void CopyRef(FrameOffset dest, FrameOffset src) override;
107   void CopyRef(FrameOffset dest,
108                ManagedRegister base,
109                MemberOffset offs,
110                bool unpoison_reference) override;
111 
112   void Copy(FrameOffset dest, FrameOffset src, size_t size) override;
113 
114   void Copy(FrameOffset dest,
115             ManagedRegister src_base,
116             Offset src_offset,
117             ManagedRegister scratch,
118             size_t size) override;
119 
120   void Copy(ManagedRegister dest_base,
121             Offset dest_offset,
122             FrameOffset src,
123             ManagedRegister scratch,
124             size_t size) override;
125 
126   void Copy(FrameOffset dest,
127             FrameOffset src_base,
128             Offset src_offset,
129             ManagedRegister scratch,
130             size_t size) override;
131 
132   void Copy(ManagedRegister dest,
133             Offset dest_offset,
134             ManagedRegister src,
135             Offset src_offset,
136             ManagedRegister scratch,
137             size_t size) override;
138 
139   void Copy(FrameOffset dest,
140             Offset dest_offset,
141             FrameOffset src,
142             Offset src_offset,
143             ManagedRegister scratch,
144             size_t size) override;
145 
146   // Sign extension.
147   void SignExtend(ManagedRegister mreg, size_t size) override;
148 
149   // Zero extension.
150   void ZeroExtend(ManagedRegister mreg, size_t size) override;
151 
152   // Exploit fast access in managed code to Thread::Current().
153   void GetCurrentThread(ManagedRegister dest) override;
154   void GetCurrentThread(FrameOffset dest_offset) override;
155 
156   // Set up `out_reg` to hold a `jobject` (`StackReference<Object>*` to a spilled value),
157   // or to be null if the value is null and `null_allowed`. `in_reg` holds a possibly
158   // stale reference that can be used to avoid loading the spilled value to
159   // see if the value is null.
160   void CreateJObject(ManagedRegister out_reg,
161                      FrameOffset spilled_reference_offset,
162                      ManagedRegister in_reg,
163                      bool null_allowed) override;
164 
165   // Set up `out_off` to hold a `jobject` (`StackReference<Object>*` to a spilled value),
166   // or to be null if the value is null and `null_allowed`.
167   void CreateJObject(FrameOffset out_off,
168                      FrameOffset spilled_reference_offset,
169                      bool null_allowed) override;
170 
171   // Heap::VerifyObject on src. In some cases (such as a reference to this) we
172   // know that src may not be null.
173   void VerifyObject(ManagedRegister src, bool could_be_null) override;
174   void VerifyObject(FrameOffset src, bool could_be_null) override;
175 
176   // Jump to address held at [base+offset] (used for tail calls).
177   void Jump(ManagedRegister base, Offset offset) override;
178 
179   // Call to address held at [base+offset].
180   void Call(ManagedRegister base, Offset offset) override;
181   void Call(FrameOffset base, Offset offset) override;
182   void CallFromThread(ThreadOffset32 offset) override;
183 
184   // Generate code to check if Thread::Current()->exception_ is non-null
185   // and branch to a ExceptionSlowPath if it is.
186   void ExceptionPoll(size_t stack_adjust) override;
187 
188   // Create a new label that can be used with Jump/Bind calls.
189   std::unique_ptr<JNIMacroLabel> CreateLabel() override;
190   // Emit an unconditional jump to the label.
191   void Jump(JNIMacroLabel* label) override;
192   // Emit a conditional jump to the label by applying a unary condition test to the GC marking flag.
193   void TestGcMarking(JNIMacroLabel* label, JNIMacroUnaryCondition cond) override;
194   // Code at this offset will serve as the target for the Jump call.
195   void Bind(JNIMacroLabel* label) override;
196 
197   void MemoryBarrier(ManagedRegister scratch) override;
198 
199   void EmitExceptionPoll(ArmVIXLJNIMacroAssembler::ArmException *exception);
200   void Load(ArmManagedRegister dest, vixl32::Register base, int32_t offset, size_t size);
201 
202  private:
203   class ArmException {
204    private:
ArmException(vixl32::Register scratch,size_t stack_adjust)205     ArmException(vixl32::Register scratch, size_t stack_adjust)
206         : scratch_(scratch), stack_adjust_(stack_adjust) {}
207 
Entry()208     vixl32::Label* Entry() { return &exception_entry_; }
209 
210     // Register used for passing Thread::Current()->exception_ .
211     const vixl32::Register scratch_;
212 
213     // Stack adjust for ExceptionPool.
214     const size_t stack_adjust_;
215 
216     vixl32::Label exception_entry_;
217 
218     friend class ArmVIXLJNIMacroAssembler;
219     DISALLOW_COPY_AND_ASSIGN(ArmException);
220   };
221 
222   // List of exception blocks to generate at the end of the code cache.
223   ArenaVector<std::unique_ptr<ArmVIXLJNIMacroAssembler::ArmException>> exception_blocks_;
224   // Used for testing.
225   friend class ArmVIXLAssemblerTest_VixlLoadFromOffset_Test;
226   friend class ArmVIXLAssemblerTest_VixlStoreToOffset_Test;
227 };
228 
229 class ArmVIXLJNIMacroLabel final
230     : public JNIMacroLabelCommon<ArmVIXLJNIMacroLabel,
231                                  vixl32::Label,
232                                  InstructionSet::kArm> {
233  public:
AsArm()234   vixl32::Label* AsArm() {
235     return AsPlatformLabel();
236   }
237 };
238 
239 }  // namespace arm
240 }  // namespace art
241 
242 #endif  // ART_COMPILER_UTILS_ARM_JNI_MACRO_ASSEMBLER_ARM_VIXL_H_
243