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_64_JNI_MACRO_ASSEMBLER_X86_64_H_ 18 #define ART_COMPILER_UTILS_X86_64_JNI_MACRO_ASSEMBLER_X86_64_H_ 19 20 #include <vector> 21 22 #include "assembler_x86_64.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/assembler.h" 29 #include "utils/jni_macro_assembler.h" 30 31 namespace art { 32 namespace x86_64 { 33 34 class X86_64JNIMacroAssembler final : public JNIMacroAssemblerFwd<X86_64Assembler, 35 PointerSize::k64> { 36 public: X86_64JNIMacroAssembler(ArenaAllocator * allocator)37 explicit X86_64JNIMacroAssembler(ArenaAllocator* allocator) 38 : JNIMacroAssemblerFwd<X86_64Assembler, PointerSize::k64>(allocator) {} ~X86_64JNIMacroAssembler()39 virtual ~X86_64JNIMacroAssembler() {} 40 41 // 42 // Overridden common assembler high-level functionality 43 // 44 45 // Emit code that will create an activation on the stack 46 void BuildFrame(size_t frame_size, 47 ManagedRegister method_reg, 48 ArrayRef<const ManagedRegister> callee_save_regs) 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) override; 64 65 void StoreStackOffsetToThread(ThreadOffset64 thr_offs, FrameOffset fr_offs) override; 66 67 void StoreStackPointerToThread(ThreadOffset64 thr_offs) override; 68 69 void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off) override; 70 71 // Load routines 72 void Load(ManagedRegister dest, FrameOffset src, size_t size) override; 73 74 void LoadFromThread(ManagedRegister dest, ThreadOffset64 src, size_t size) override; 75 76 void LoadRef(ManagedRegister dest, FrameOffset src) override; 77 78 void LoadRef(ManagedRegister dest, 79 ManagedRegister base, 80 MemberOffset offs, 81 bool unpoison_reference) override; 82 83 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) override; 84 85 void LoadRawPtrFromThread(ManagedRegister dest, ThreadOffset64 offs) override; 86 87 // Copying routines 88 void MoveArguments(ArrayRef<ArgumentLocation> dests, ArrayRef<ArgumentLocation> srcs) override; 89 90 void Move(ManagedRegister dest, ManagedRegister src, size_t size) override; 91 92 void CopyRawPtrFromThread(FrameOffset fr_offs, ThreadOffset64 thr_offs) override; 93 94 void CopyRawPtrToThread(ThreadOffset64 thr_offs, FrameOffset fr_offs, ManagedRegister scratch) 95 override; 96 97 void CopyRef(FrameOffset dest, FrameOffset src) override; 98 void CopyRef(FrameOffset dest, 99 ManagedRegister base, 100 MemberOffset offs, 101 bool unpoison_reference) override; 102 103 void Copy(FrameOffset dest, FrameOffset src, size_t size) override; 104 105 void Copy(FrameOffset dest, 106 ManagedRegister src_base, 107 Offset src_offset, 108 ManagedRegister scratch, 109 size_t size) override; 110 111 void Copy(ManagedRegister dest_base, 112 Offset dest_offset, 113 FrameOffset src, 114 ManagedRegister scratch, 115 size_t size) override; 116 117 void Copy(FrameOffset dest, 118 FrameOffset src_base, 119 Offset src_offset, 120 ManagedRegister scratch, 121 size_t size) override; 122 123 void Copy(ManagedRegister dest, 124 Offset dest_offset, 125 ManagedRegister src, 126 Offset src_offset, 127 ManagedRegister scratch, 128 size_t size) override; 129 130 void Copy(FrameOffset dest, 131 Offset dest_offset, 132 FrameOffset src, 133 Offset src_offset, 134 ManagedRegister scratch, 135 size_t size) override; 136 137 void MemoryBarrier(ManagedRegister) override; 138 139 // Sign extension 140 void SignExtend(ManagedRegister mreg, size_t size) override; 141 142 // Zero extension 143 void ZeroExtend(ManagedRegister mreg, size_t size) override; 144 145 // Exploit fast access in managed code to Thread::Current() 146 void GetCurrentThread(ManagedRegister dest) override; 147 void GetCurrentThread(FrameOffset dest_offset) override; 148 149 // Set up `out_reg` to hold a `jobject` (`StackReference<Object>*` to a spilled value), 150 // or to be null if the value is null and `null_allowed`. `in_reg` holds a possibly 151 // stale reference that can be used to avoid loading the spilled value to 152 // see if the value is null. 153 void CreateJObject(ManagedRegister out_reg, 154 FrameOffset spilled_reference_offset, 155 ManagedRegister in_reg, 156 bool null_allowed) override; 157 158 // Set up `out_off` to hold a `jobject` (`StackReference<Object>*` to a spilled value), 159 // or to be null if the value is null and `null_allowed`. 160 void CreateJObject(FrameOffset out_off, 161 FrameOffset spilled_reference_offset, 162 bool null_allowed) override; 163 164 // Heap::VerifyObject on src. In some cases (such as a reference to this) we 165 // know that src may not be null. 166 void VerifyObject(ManagedRegister src, bool could_be_null) override; 167 void VerifyObject(FrameOffset src, bool could_be_null) override; 168 169 // Jump to address held at [base+offset] (used for tail calls). 170 void Jump(ManagedRegister base, Offset offset) override; 171 172 // Call to address held at [base+offset] 173 void Call(ManagedRegister base, Offset offset) override; 174 void Call(FrameOffset base, Offset offset) override; 175 void CallFromThread(ThreadOffset64 offset) override; 176 177 // Generate code to check if Thread::Current()->exception_ is non-null 178 // and branch to a ExceptionSlowPath if it is. 179 void ExceptionPoll(size_t stack_adjust) override; 180 181 // Create a new label that can be used with Jump/Bind calls. 182 std::unique_ptr<JNIMacroLabel> CreateLabel() override; 183 // Emit an unconditional jump to the label. 184 void Jump(JNIMacroLabel* label) override; 185 // Emit a conditional jump to the label by applying a unary condition test to the GC marking flag. 186 void TestGcMarking(JNIMacroLabel* label, JNIMacroUnaryCondition cond) override; 187 // Code at this offset will serve as the target for the Jump call. 188 void Bind(JNIMacroLabel* label) override; 189 190 private: 191 DISALLOW_COPY_AND_ASSIGN(X86_64JNIMacroAssembler); 192 }; 193 194 class X86_64JNIMacroLabel final 195 : public JNIMacroLabelCommon<X86_64JNIMacroLabel, 196 art::Label, 197 InstructionSet::kX86_64> { 198 public: AsX86_64()199 art::Label* AsX86_64() { 200 return AsPlatformLabel(); 201 } 202 }; 203 204 } // namespace x86_64 205 } // namespace art 206 207 #endif // ART_COMPILER_UTILS_X86_64_JNI_MACRO_ASSEMBLER_X86_64_H_ 208