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