• 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_X86_JNI_MACRO_ASSEMBLER_X86_H_
18 #define ART_COMPILER_UTILS_X86_JNI_MACRO_ASSEMBLER_X86_H_
19 
20 #include <vector>
21 
22 #include "assembler_x86.h"
23 #include "base/arena_containers.h"
24 #include "base/array_ref.h"
25 #include "base/enums.h"
26 #include "base/macros.h"
27 #include "offsets.h"
28 #include "utils/jni_macro_assembler.h"
29 
30 namespace art {
31 namespace x86 {
32 
33 class X86JNIMacroLabel;
34 
35 class X86JNIMacroAssembler final : public JNIMacroAssemblerFwd<X86Assembler, PointerSize::k32> {
36  public:
X86JNIMacroAssembler(ArenaAllocator * allocator)37   explicit X86JNIMacroAssembler(ArenaAllocator* allocator) : JNIMacroAssemblerFwd(allocator) {}
~X86JNIMacroAssembler()38   virtual ~X86JNIMacroAssembler() {}
39 
40   //
41   // Overridden common assembler high-level functionality
42   //
43 
44   // Emit code that will create an activation on the stack
45   void BuildFrame(size_t frame_size,
46                   ManagedRegister method_reg,
47                   ArrayRef<const ManagedRegister> callee_save_regs,
48                   const ManagedRegisterEntrySpills& entry_spills) override;
49 
50   // Emit code that will remove an activation from the stack
51   void RemoveFrame(size_t frame_size,
52                    ArrayRef<const ManagedRegister> callee_save_regs,
53                    bool may_suspend) override;
54 
55   void IncreaseFrameSize(size_t adjust) override;
56   void DecreaseFrameSize(size_t adjust) override;
57 
58   // Store routines
59   void Store(FrameOffset offs, ManagedRegister src, size_t size) override;
60   void StoreRef(FrameOffset dest, ManagedRegister src) override;
61   void StoreRawPtr(FrameOffset dest, ManagedRegister src) override;
62 
63   void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister scratch) override;
64 
65   void StoreStackOffsetToThread(ThreadOffset32 thr_offs,
66                                 FrameOffset fr_offs,
67                                 ManagedRegister scratch) override;
68 
69   void StoreStackPointerToThread(ThreadOffset32 thr_offs) override;
70 
71   void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off,
72                      ManagedRegister scratch) override;
73 
74   // Load routines
75   void Load(ManagedRegister dest, FrameOffset src, size_t size) override;
76 
77   void LoadFromThread(ManagedRegister dest, ThreadOffset32 src, size_t size) override;
78 
79   void LoadRef(ManagedRegister dest, FrameOffset src) override;
80 
81   void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs,
82                bool unpoison_reference) override;
83 
84   void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) override;
85 
86   void LoadRawPtrFromThread(ManagedRegister dest, ThreadOffset32 offs) override;
87 
88   // Copying routines
89   void Move(ManagedRegister dest, ManagedRegister src, size_t size) override;
90 
91   void CopyRawPtrFromThread(FrameOffset fr_offs,
92                             ThreadOffset32 thr_offs,
93                             ManagedRegister scratch) override;
94 
95   void CopyRawPtrToThread(ThreadOffset32 thr_offs, FrameOffset fr_offs, ManagedRegister scratch)
96       override;
97 
98   void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister scratch) override;
99 
100   void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) override;
101 
102   void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister scratch,
103             size_t size) override;
104 
105   void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, ManagedRegister scratch,
106             size_t size) override;
107 
108   void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister scratch,
109             size_t size) override;
110 
111   void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
112             ManagedRegister scratch, size_t size) override;
113 
114   void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
115             ManagedRegister scratch, size_t size) override;
116 
117   void MemoryBarrier(ManagedRegister) override;
118 
119   // Sign extension
120   void SignExtend(ManagedRegister mreg, size_t size) override;
121 
122   // Zero extension
123   void ZeroExtend(ManagedRegister mreg, size_t size) override;
124 
125   // Exploit fast access in managed code to Thread::Current()
126   void GetCurrentThread(ManagedRegister tr) override;
127   void GetCurrentThread(FrameOffset dest_offset, ManagedRegister scratch) override;
128 
129   // Set up out_reg to hold a Object** into the handle scope, or to be null if the
130   // value is null and null_allowed. in_reg holds a possibly stale reference
131   // that can be used to avoid loading the handle scope entry to see if the value is
132   // null.
133   void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
134                               ManagedRegister in_reg, bool null_allowed) override;
135 
136   // Set up out_off to hold a Object** into the handle scope, or to be null if the
137   // value is null and null_allowed.
138   void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
139                               ManagedRegister scratch, bool null_allowed) override;
140 
141   // src holds a handle scope entry (Object**) load this into dst
142   void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) override;
143 
144   // Heap::VerifyObject on src. In some cases (such as a reference to this) we
145   // know that src may not be null.
146   void VerifyObject(ManagedRegister src, bool could_be_null) override;
147   void VerifyObject(FrameOffset src, bool could_be_null) override;
148 
149   // Call to address held at [base+offset]
150   void Call(ManagedRegister base, Offset offset, ManagedRegister scratch) override;
151   void Call(FrameOffset base, Offset offset, ManagedRegister scratch) override;
152   void CallFromThread(ThreadOffset32 offset, ManagedRegister scratch) override;
153 
154   // Generate code to check if Thread::Current()->exception_ is non-null
155   // and branch to a ExceptionSlowPath if it is.
156   void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) override;
157 
158   // Create a new label that can be used with Jump/Bind calls.
159   std::unique_ptr<JNIMacroLabel> CreateLabel() override;
160   // Emit an unconditional jump to the label.
161   void Jump(JNIMacroLabel* label) override;
162   // Emit a conditional jump to the label by applying a unary condition test to the register.
163   void Jump(JNIMacroLabel* label, JNIMacroUnaryCondition cond, ManagedRegister test) override;
164   // Code at this offset will serve as the target for the Jump call.
165   void Bind(JNIMacroLabel* label) override;
166 
167  private:
168   DISALLOW_COPY_AND_ASSIGN(X86JNIMacroAssembler);
169 };
170 
171 class X86JNIMacroLabel final
172     : public JNIMacroLabelCommon<X86JNIMacroLabel,
173                                  art::Label,
174                                  InstructionSet::kX86> {
175  public:
AsX86()176   art::Label* AsX86() {
177     return AsPlatformLabel();
178   }
179 };
180 
181 }  // namespace x86
182 }  // namespace art
183 
184 #endif  // ART_COMPILER_UTILS_X86_JNI_MACRO_ASSEMBLER_X86_H_
185