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