• 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_vixl.h"
27 #include "utils/arm/managed_register_arm.h"
28 #include "utils/assembler.h"
29 #include "utils/jni_macro_assembler.h"
30 
31 namespace art HIDDEN {
32 namespace arm {
33 
34 class ArmVIXLJNIMacroAssembler final
35     : public JNIMacroAssemblerFwd<ArmVIXLAssembler, PointerSize::k32> {
36  public:
ArmVIXLJNIMacroAssembler(ArenaAllocator * allocator)37   explicit ArmVIXLJNIMacroAssembler(ArenaAllocator* allocator)
38       : JNIMacroAssemblerFwd(allocator) {}
39 
~ArmVIXLJNIMacroAssembler()40   virtual ~ArmVIXLJNIMacroAssembler() {}
41   void FinalizeCode() override;
42 
43   //
44   // Overridden common assembler high-level functionality
45   //
46 
47   // Emit code that will create an activation on the stack.
48   void BuildFrame(size_t frame_size,
49                   ManagedRegister method_reg,
50                   ArrayRef<const ManagedRegister> callee_save_regs) override;
51 
52   // Emit code that will remove an activation from the stack.
53   void RemoveFrame(size_t frame_size,
54                    ArrayRef<const ManagedRegister> callee_save_regs,
55                    bool may_suspend) override;
56 
57   void IncreaseFrameSize(size_t adjust) override;
58   void DecreaseFrameSize(size_t adjust) override;
59 
60   ManagedRegister CoreRegisterWithSize(ManagedRegister src, size_t size) override;
61 
62   // Store routines.
63   void Store(FrameOffset offs, ManagedRegister src, size_t size) override;
64   void Store(ManagedRegister base, MemberOffset offs, ManagedRegister src, size_t size) override;
65   void StoreRawPtr(FrameOffset dest, ManagedRegister src) override;
66 
67   void StoreStackPointerToThread(ThreadOffset32 thr_offs, bool tag_sp) override;
68 
69   // Load routines.
70   void Load(ManagedRegister dest, FrameOffset src, size_t size) override;
71   void Load(ManagedRegister dest, ManagedRegister base, MemberOffset offs, size_t size) override;
72 
73   void LoadRawPtrFromThread(ManagedRegister dest, ThreadOffset32 offs) override;
74 
75   // Copying routines.
76   void MoveArguments(ArrayRef<ArgumentLocation> dests,
77                      ArrayRef<ArgumentLocation> srcs,
78                      ArrayRef<FrameOffset> refs) override;
79 
80   void Move(ManagedRegister dest, ManagedRegister src, size_t size) override;
81 
82   void Move(ManagedRegister dest, size_t value) override;
83 
84   // Sign extension.
85   void SignExtend(ManagedRegister mreg, size_t size) override;
86 
87   // Zero extension.
88   void ZeroExtend(ManagedRegister mreg, size_t size) override;
89 
90   // Exploit fast access in managed code to Thread::Current().
91   void GetCurrentThread(ManagedRegister dest) override;
92   void GetCurrentThread(FrameOffset dest_offset) override;
93 
94   // Decode JNI transition or local `jobject`. For (weak) global `jobject`, jump to slow path.
95   void DecodeJNITransitionOrLocalJObject(ManagedRegister reg,
96                                          JNIMacroLabel* slow_path,
97                                          JNIMacroLabel* resume) override;
98 
99   // Heap::VerifyObject on src. In some cases (such as a reference to this) we
100   // know that src may not be null.
101   void VerifyObject(ManagedRegister src, bool could_be_null) override;
102   void VerifyObject(FrameOffset src, bool could_be_null) override;
103 
104   // Jump to address held at [base+offset] (used for tail calls).
105   void Jump(ManagedRegister base, Offset offset) override;
106 
107   // Call to address held at [base+offset].
108   void Call(ManagedRegister base, Offset offset) override;
109   void CallFromThread(ThreadOffset32 offset) override;
110 
111   // Generate fast-path for transition to Native. Go to `label` if any thread flag is set.
112   // The implementation can use `scratch_regs` which should be callee save core registers
113   // (already saved before this call) and must preserve all argument registers.
114   void TryToTransitionFromRunnableToNative(
115       JNIMacroLabel* label, ArrayRef<const ManagedRegister> scratch_regs) override;
116 
117   // Generate fast-path for transition to Runnable. Go to `label` if any thread flag is set.
118   // The implementation can use `scratch_regs` which should be core argument registers
119   // not used as return registers and it must preserve the `return_reg` if any.
120   void TryToTransitionFromNativeToRunnable(JNIMacroLabel* label,
121                                            ArrayRef<const ManagedRegister> scratch_regs,
122                                            ManagedRegister return_reg) override;
123 
124   // Generate suspend check and branch to `label` if there is a pending suspend request.
125   void SuspendCheck(JNIMacroLabel* label) override;
126 
127   // Generate code to check if Thread::Current()->exception_ is non-null
128   // and branch to the `label` if it is.
129   void ExceptionPoll(JNIMacroLabel* label) override;
130   // Deliver pending exception.
131   void DeliverPendingException() override;
132 
133   // Create a new label that can be used with Jump/Bind calls.
134   std::unique_ptr<JNIMacroLabel> CreateLabel() override;
135   // Emit an unconditional jump to the label.
136   void Jump(JNIMacroLabel* label) override;
137   // Emit a conditional jump to the label by applying a unary condition test to the GC marking flag.
138   void TestGcMarking(JNIMacroLabel* label, JNIMacroUnaryCondition cond) override;
139   // Emit a conditional jump to the label by applying a unary condition test to object's mark bit.
140   void TestMarkBit(ManagedRegister ref, JNIMacroLabel* label, JNIMacroUnaryCondition cond) override;
141   // Emit a conditional jump to label if the loaded value from specified locations is not zero.
142   void TestByteAndJumpIfNotZero(uintptr_t address, JNIMacroLabel* label) override;
143   // Code at this offset will serve as the target for the Jump call.
144   void Bind(JNIMacroLabel* label) override;
145 
146  private:
147   void Copy(FrameOffset dest, FrameOffset src, size_t size);
148   void Load(ArmManagedRegister dest, vixl32::Register base, int32_t offset, size_t size);
149 
150   // Set up `out_reg` to hold a `jobject` (`StackReference<Object>*` to a spilled value),
151   // or to be null if the value is null and `null_allowed`. `in_reg` holds a possibly
152   // stale reference that can be used to avoid loading the spilled value to
153   // see if the value is null.
154   void CreateJObject(ManagedRegister out_reg,
155                      FrameOffset spilled_reference_offset,
156                      ManagedRegister in_reg,
157                      bool null_allowed);
158 
159   // Used for testing.
160   ART_FRIEND_TEST(ArmVIXLAssemblerTest, VixlJniHelpers);
161   ART_FRIEND_TEST(ArmVIXLAssemblerTest, VixlLoadFromOffset);
162   ART_FRIEND_TEST(ArmVIXLAssemblerTest, VixlStoreToOffset);
163 };
164 
165 class ArmVIXLJNIMacroLabel final
166     : public JNIMacroLabelCommon<ArmVIXLJNIMacroLabel,
167                                  vixl32::Label,
168                                  InstructionSet::kArm> {
169  public:
AsArm()170   vixl32::Label* AsArm() {
171     return AsPlatformLabel();
172   }
173 };
174 
175 }  // namespace arm
176 }  // namespace art
177 
178 #endif  // ART_COMPILER_UTILS_ARM_JNI_MACRO_ASSEMBLER_ARM_VIXL_H_
179