blob: 4ea85a2c183635ff07f13b5e364612aa4ae772cf [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 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 */
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070016
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_COMPILER_UTILS_ASSEMBLER_H_
18#define ART_COMPILER_UTILS_ASSEMBLER_H_
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070019
Ian Rogers2c8f6532011-09-02 17:16:34 -070020#include <vector>
21
Ian Rogersd582fa42014-11-05 23:46:43 -080022#include "arch/instruction_set.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020023#include "arch/instruction_set_features.h"
David Srbecky4fda4eb2016-02-05 13:34:46 +000024#include "arm/constants_arm.h"
Vladimir Marko93205e32016-04-13 11:59:46 +010025#include "base/arena_allocator.h"
26#include "base/arena_object.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080027#include "base/logging.h"
Elliott Hughes76160052012-12-12 16:31:20 -080028#include "base/macros.h"
David Srbecky4fda4eb2016-02-05 13:34:46 +000029#include "debug/dwarf/debug_frame_opcode_writer.h"
Andreas Gampe85b62f22015-09-09 13:15:38 -070030#include "label.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070031#include "managed_register.h"
32#include "memory_region.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080033#include "mips/constants_mips.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070034#include "offsets.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080035#include "x86/constants_x86.h"
36#include "x86_64/constants_x86_64.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070037
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070038namespace art {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070039
40class Assembler;
41class AssemblerBuffer;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070042
43// Assembler fixups are positions in generated code that require processing
44// after the code has been copied to executable memory. This includes building
45// relocation information.
46class AssemblerFixup {
47 public:
48 virtual void Process(const MemoryRegion& region, int position) = 0;
49 virtual ~AssemblerFixup() {}
50
51 private:
52 AssemblerFixup* previous_;
53 int position_;
54
55 AssemblerFixup* previous() const { return previous_; }
Andreas Gampe277ccbd2014-11-03 21:36:10 -080056 void set_previous(AssemblerFixup* previous_in) { previous_ = previous_in; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070057
58 int position() const { return position_; }
Andreas Gampe277ccbd2014-11-03 21:36:10 -080059 void set_position(int position_in) { position_ = position_in; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070060
61 friend class AssemblerBuffer;
62};
63
Ian Rogers45a76cb2011-07-21 22:00:15 -070064// Parent of all queued slow paths, emitted during finalization
Vladimir Marko93205e32016-04-13 11:59:46 +010065class SlowPath : public DeletableArenaObject<kArenaAllocAssembler> {
Ian Rogers45a76cb2011-07-21 22:00:15 -070066 public:
Mathieu Chartier2cebb242015-04-21 16:50:40 -070067 SlowPath() : next_(nullptr) {}
Ian Rogers45a76cb2011-07-21 22:00:15 -070068 virtual ~SlowPath() {}
69
70 Label* Continuation() { return &continuation_; }
71 Label* Entry() { return &entry_; }
72 // Generate code for slow path
73 virtual void Emit(Assembler *sp_asm) = 0;
74
75 protected:
76 // Entry branched to by fast path
77 Label entry_;
78 // Optional continuation that is branched to at the end of the slow path
79 Label continuation_;
80 // Next in linked list of slow paths
81 SlowPath *next_;
82
Mathieu Chartier02e25112013-08-14 16:14:24 -070083 private:
Ian Rogers45a76cb2011-07-21 22:00:15 -070084 friend class AssemblerBuffer;
85 DISALLOW_COPY_AND_ASSIGN(SlowPath);
86};
87
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070088class AssemblerBuffer {
89 public:
Vladimir Marko93205e32016-04-13 11:59:46 +010090 explicit AssemblerBuffer(ArenaAllocator* arena);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070091 ~AssemblerBuffer();
92
Vladimir Marko93205e32016-04-13 11:59:46 +010093 ArenaAllocator* GetArena() {
94 return arena_;
95 }
96
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070097 // Basic support for emitting, loading, and storing.
98 template<typename T> void Emit(T value) {
99 CHECK(HasEnsuredCapacity());
100 *reinterpret_cast<T*>(cursor_) = value;
101 cursor_ += sizeof(T);
102 }
103
104 template<typename T> T Load(size_t position) {
105 CHECK_LE(position, Size() - static_cast<int>(sizeof(T)));
106 return *reinterpret_cast<T*>(contents_ + position);
107 }
108
109 template<typename T> void Store(size_t position, T value) {
110 CHECK_LE(position, Size() - static_cast<int>(sizeof(T)));
111 *reinterpret_cast<T*>(contents_ + position) = value;
112 }
113
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000114 void Resize(size_t new_size) {
115 if (new_size > Capacity()) {
116 ExtendCapacity(new_size);
117 }
118 cursor_ = contents_ + new_size;
119 }
120
121 void Move(size_t newposition, size_t oldposition, size_t size) {
122 // Move a chunk of the buffer from oldposition to newposition.
123 DCHECK_LE(oldposition + size, Size());
124 DCHECK_LE(newposition + size, Size());
125 memmove(contents_ + newposition, contents_ + oldposition, size);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700126 }
127
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700128 // Emit a fixup at the current location.
129 void EmitFixup(AssemblerFixup* fixup) {
130 fixup->set_previous(fixup_);
131 fixup->set_position(Size());
132 fixup_ = fixup;
133 }
134
Ian Rogers45a76cb2011-07-21 22:00:15 -0700135 void EnqueueSlowPath(SlowPath* slowpath) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700136 if (slow_path_ == nullptr) {
Ian Rogers45a76cb2011-07-21 22:00:15 -0700137 slow_path_ = slowpath;
138 } else {
139 SlowPath* cur = slow_path_;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700140 for ( ; cur->next_ != nullptr ; cur = cur->next_) {}
Ian Rogers45a76cb2011-07-21 22:00:15 -0700141 cur->next_ = slowpath;
142 }
143 }
144
145 void EmitSlowPaths(Assembler* sp_asm) {
146 SlowPath* cur = slow_path_;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700147 SlowPath* next = nullptr;
148 slow_path_ = nullptr;
149 for ( ; cur != nullptr ; cur = next) {
Ian Rogers45a76cb2011-07-21 22:00:15 -0700150 cur->Emit(sp_asm);
151 next = cur->next_;
152 delete cur;
153 }
154 }
155
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700156 // Get the size of the emitted code.
157 size_t Size() const {
158 CHECK_GE(cursor_, contents_);
159 return cursor_ - contents_;
160 }
161
Ian Rogers13735952014-10-08 12:43:28 -0700162 uint8_t* contents() const { return contents_; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700163
164 // Copy the assembled instructions into the specified memory block
165 // and apply all fixups.
166 void FinalizeInstructions(const MemoryRegion& region);
167
168 // To emit an instruction to the assembler buffer, the EnsureCapacity helper
169 // must be used to guarantee that the underlying data area is big enough to
170 // hold the emitted instruction. Usage:
171 //
172 // AssemblerBuffer buffer;
173 // AssemblerBuffer::EnsureCapacity ensured(&buffer);
174 // ... emit bytes for single instruction ...
175
Elliott Hughes31f1f4f2012-03-12 13:57:36 -0700176#ifndef NDEBUG
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700177
178 class EnsureCapacity {
179 public:
180 explicit EnsureCapacity(AssemblerBuffer* buffer) {
Elliott Hughes31f1f4f2012-03-12 13:57:36 -0700181 if (buffer->cursor() >= buffer->limit()) {
182 buffer->ExtendCapacity();
183 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700184 // In debug mode, we save the assembler buffer along with the gap
185 // size before we start emitting to the buffer. This allows us to
186 // check that any single generated instruction doesn't overflow the
187 // limit implied by the minimum gap size.
188 buffer_ = buffer;
189 gap_ = ComputeGap();
190 // Make sure that extending the capacity leaves a big enough gap
191 // for any kind of instruction.
192 CHECK_GE(gap_, kMinimumGap);
193 // Mark the buffer as having ensured the capacity.
194 CHECK(!buffer->HasEnsuredCapacity()); // Cannot nest.
195 buffer->has_ensured_capacity_ = true;
196 }
197
198 ~EnsureCapacity() {
199 // Unmark the buffer, so we cannot emit after this.
200 buffer_->has_ensured_capacity_ = false;
201 // Make sure the generated instruction doesn't take up more
202 // space than the minimum gap.
203 int delta = gap_ - ComputeGap();
Ian Rogersb033c752011-07-20 12:22:35 -0700204 CHECK_LE(delta, kMinimumGap);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700205 }
206
207 private:
208 AssemblerBuffer* buffer_;
209 int gap_;
210
211 int ComputeGap() { return buffer_->Capacity() - buffer_->Size(); }
212 };
213
214 bool has_ensured_capacity_;
215 bool HasEnsuredCapacity() const { return has_ensured_capacity_; }
216
217#else
218
219 class EnsureCapacity {
220 public:
221 explicit EnsureCapacity(AssemblerBuffer* buffer) {
222 if (buffer->cursor() >= buffer->limit()) buffer->ExtendCapacity();
223 }
224 };
225
226 // When building the C++ tests, assertion code is enabled. To allow
227 // asserting that the user of the assembler buffer has ensured the
228 // capacity needed for emitting, we add a dummy method in non-debug mode.
229 bool HasEnsuredCapacity() const { return true; }
230
231#endif
232
233 // Returns the position in the instruction stream.
234 int GetPosition() { return cursor_ - contents_; }
235
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700236 void ExtendCapacity(size_t min_capacity = 0u);
237
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700238 private:
239 // The limit is set to kMinimumGap bytes before the end of the data area.
240 // This leaves enough space for the longest possible instruction and allows
241 // for a single, fast space check per instruction.
242 static const int kMinimumGap = 32;
243
Vladimir Marko93205e32016-04-13 11:59:46 +0100244 ArenaAllocator* arena_;
Ian Rogers13735952014-10-08 12:43:28 -0700245 uint8_t* contents_;
246 uint8_t* cursor_;
247 uint8_t* limit_;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700248 AssemblerFixup* fixup_;
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800249#ifndef NDEBUG
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700250 bool fixups_processed_;
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800251#endif
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700252
Ian Rogers45a76cb2011-07-21 22:00:15 -0700253 // Head of linked list of slow paths
254 SlowPath* slow_path_;
255
Ian Rogers13735952014-10-08 12:43:28 -0700256 uint8_t* cursor() const { return cursor_; }
257 uint8_t* limit() const { return limit_; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700258 size_t Capacity() const {
259 CHECK_GE(limit_, contents_);
260 return (limit_ - contents_) + kMinimumGap;
261 }
262
263 // Process the fixup chain starting at the given fixup. The offset is
264 // non-zero for fixups in the body if the preamble is non-empty.
265 void ProcessFixups(const MemoryRegion& region);
266
267 // Compute the limit based on the data area and the capacity. See
268 // description of kMinimumGap for the reasoning behind the value.
Ian Rogers13735952014-10-08 12:43:28 -0700269 static uint8_t* ComputeLimit(uint8_t* data, size_t capacity) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700270 return data + capacity - kMinimumGap;
271 }
272
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700273 friend class AssemblerFixup;
274};
275
David Srbeckydd973932015-04-07 20:29:48 +0100276// The purpose of this class is to ensure that we do not have to explicitly
277// call the AdvancePC method (which is good for convenience and correctness).
278class DebugFrameOpCodeWriterForAssembler FINAL
279 : public dwarf::DebugFrameOpCodeWriter<> {
280 public:
Vladimir Marko10ef6942015-10-22 15:25:54 +0100281 struct DelayedAdvancePC {
282 uint32_t stream_pos;
283 uint32_t pc;
284 };
285
David Srbeckydd973932015-04-07 20:29:48 +0100286 // This method is called the by the opcode writers.
287 virtual void ImplicitlyAdvancePC() FINAL;
288
289 explicit DebugFrameOpCodeWriterForAssembler(Assembler* buffer)
Vladimir Marko10ef6942015-10-22 15:25:54 +0100290 : dwarf::DebugFrameOpCodeWriter<>(false /* enabled */),
291 assembler_(buffer),
292 delay_emitting_advance_pc_(false),
293 delayed_advance_pcs_() {
294 }
295
296 ~DebugFrameOpCodeWriterForAssembler() {
297 DCHECK(delayed_advance_pcs_.empty());
298 }
299
300 // Tell the writer to delay emitting advance PC info.
301 // The assembler must explicitly process all the delayed advances.
302 void DelayEmittingAdvancePCs() {
303 delay_emitting_advance_pc_ = true;
304 }
305
306 // Override the last delayed PC. The new PC can be out of order.
307 void OverrideDelayedPC(size_t pc) {
308 DCHECK(delay_emitting_advance_pc_);
309 DCHECK(!delayed_advance_pcs_.empty());
310 delayed_advance_pcs_.back().pc = pc;
311 }
312
313 // Return the number of delayed advance PC entries.
314 size_t NumberOfDelayedAdvancePCs() const {
315 return delayed_advance_pcs_.size();
316 }
317
318 // Release the CFI stream and advance PC infos so that the assembler can patch it.
319 std::pair<std::vector<uint8_t>, std::vector<DelayedAdvancePC>>
320 ReleaseStreamAndPrepareForDelayedAdvancePC() {
321 DCHECK(delay_emitting_advance_pc_);
322 delay_emitting_advance_pc_ = false;
323 std::pair<std::vector<uint8_t>, std::vector<DelayedAdvancePC>> result;
324 result.first.swap(opcodes_);
325 result.second.swap(delayed_advance_pcs_);
326 return result;
327 }
328
329 // Reserve space for the CFI stream.
330 void ReserveCFIStream(size_t capacity) {
331 opcodes_.reserve(capacity);
332 }
333
334 // Append raw data to the CFI stream.
335 void AppendRawData(const std::vector<uint8_t>& raw_data, size_t first, size_t last) {
336 DCHECK_LE(0u, first);
337 DCHECK_LE(first, last);
338 DCHECK_LE(last, raw_data.size());
339 opcodes_.insert(opcodes_.end(), raw_data.begin() + first, raw_data.begin() + last);
David Srbeckydd973932015-04-07 20:29:48 +0100340 }
341
342 private:
343 Assembler* assembler_;
Vladimir Marko10ef6942015-10-22 15:25:54 +0100344 bool delay_emitting_advance_pc_;
345 std::vector<DelayedAdvancePC> delayed_advance_pcs_;
David Srbeckydd973932015-04-07 20:29:48 +0100346};
347
Vladimir Marko93205e32016-04-13 11:59:46 +0100348class Assembler : public DeletableArenaObject<kArenaAllocAssembler> {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700349 public:
Vladimir Marko93205e32016-04-13 11:59:46 +0100350 static std::unique_ptr<Assembler> Create(
351 ArenaAllocator* arena,
352 InstructionSet instruction_set,
353 const InstructionSetFeatures* instruction_set_features = nullptr);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700354
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000355 // Finalize the code; emit slow paths, fixup branches, add literal pool, etc.
356 virtual void FinalizeCode() { buffer_.EmitSlowPaths(this); }
Ian Rogers2c8f6532011-09-02 17:16:34 -0700357
358 // Size of generated code
Serban Constantinescued8dd492014-02-11 14:15:10 +0000359 virtual size_t CodeSize() const { return buffer_.Size(); }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100360 virtual const uint8_t* CodeBufferBaseAddress() const { return buffer_.contents(); }
Ian Rogers2c8f6532011-09-02 17:16:34 -0700361
362 // Copy instructions out of assembly buffer into the given region of memory
Serban Constantinescued8dd492014-02-11 14:15:10 +0000363 virtual void FinalizeInstructions(const MemoryRegion& region) {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700364 buffer_.FinalizeInstructions(region);
365 }
366
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000367 // TODO: Implement with disassembler.
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100368 virtual void Comment(const char* format ATTRIBUTE_UNUSED, ...) {}
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000369
Ian Rogers2c8f6532011-09-02 17:16:34 -0700370 // Emit code that will create an activation on the stack
371 virtual void BuildFrame(size_t frame_size, ManagedRegister method_reg,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800372 const std::vector<ManagedRegister>& callee_save_regs,
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700373 const ManagedRegisterEntrySpills& entry_spills) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700374
375 // Emit code that will remove an activation from the stack
376 virtual void RemoveFrame(size_t frame_size,
Ian Rogersbdb03912011-09-14 00:55:44 -0700377 const std::vector<ManagedRegister>& callee_save_regs) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700378
379 virtual void IncreaseFrameSize(size_t adjust) = 0;
380 virtual void DecreaseFrameSize(size_t adjust) = 0;
381
382 // Store routines
383 virtual void Store(FrameOffset offs, ManagedRegister src, size_t size) = 0;
384 virtual void StoreRef(FrameOffset dest, ManagedRegister src) = 0;
385 virtual void StoreRawPtr(FrameOffset dest, ManagedRegister src) = 0;
386
387 virtual void StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
388 ManagedRegister scratch) = 0;
389
Ian Rogersdd7624d2014-03-14 17:43:00 -0700390 virtual void StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm,
391 ManagedRegister scratch);
392 virtual void StoreImmediateToThread64(ThreadOffset<8> dest, uint32_t imm,
393 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700394
Ian Rogersdd7624d2014-03-14 17:43:00 -0700395 virtual void StoreStackOffsetToThread32(ThreadOffset<4> thr_offs,
396 FrameOffset fr_offs,
397 ManagedRegister scratch);
398 virtual void StoreStackOffsetToThread64(ThreadOffset<8> thr_offs,
399 FrameOffset fr_offs,
400 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700401
Ian Rogersdd7624d2014-03-14 17:43:00 -0700402 virtual void StoreStackPointerToThread32(ThreadOffset<4> thr_offs);
403 virtual void StoreStackPointerToThread64(ThreadOffset<8> thr_offs);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700404
405 virtual void StoreSpanning(FrameOffset dest, ManagedRegister src,
406 FrameOffset in_off, ManagedRegister scratch) = 0;
407
408 // Load routines
409 virtual void Load(ManagedRegister dest, FrameOffset src, size_t size) = 0;
410
Ian Rogersdd7624d2014-03-14 17:43:00 -0700411 virtual void LoadFromThread32(ManagedRegister dest, ThreadOffset<4> src, size_t size);
412 virtual void LoadFromThread64(ManagedRegister dest, ThreadOffset<8> src, size_t size);
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700413
Mathieu Chartiere401d142015-04-22 13:56:20 -0700414 virtual void LoadRef(ManagedRegister dest, FrameOffset src) = 0;
Roland Levillain4d027112015-07-01 15:41:14 +0100415 // If unpoison_reference is true and kPoisonReference is true, then we negate the read reference.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700416 virtual void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +0100417 bool unpoison_reference) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700418
Ian Rogersdd7624d2014-03-14 17:43:00 -0700419 virtual void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700420
Ian Rogersdd7624d2014-03-14 17:43:00 -0700421 virtual void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset<4> offs);
422 virtual void LoadRawPtrFromThread64(ManagedRegister dest, ThreadOffset<8> offs);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700423
424 // Copying routines
Ian Rogersb5d09b22012-03-06 22:14:17 -0800425 virtual void Move(ManagedRegister dest, ManagedRegister src, size_t size) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700426
Ian Rogersdd7624d2014-03-14 17:43:00 -0700427 virtual void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset<4> thr_offs,
428 ManagedRegister scratch);
429 virtual void CopyRawPtrFromThread64(FrameOffset fr_offs, ThreadOffset<8> thr_offs,
430 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700431
Ian Rogersdd7624d2014-03-14 17:43:00 -0700432 virtual void CopyRawPtrToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs,
433 ManagedRegister scratch);
434 virtual void CopyRawPtrToThread64(ThreadOffset<8> thr_offs, FrameOffset fr_offs,
435 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700436
437 virtual void CopyRef(FrameOffset dest, FrameOffset src,
438 ManagedRegister scratch) = 0;
439
Elliott Hughesa09aea22012-01-06 18:58:27 -0800440 virtual void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700441
Ian Rogersdc51b792011-09-22 20:41:37 -0700442 virtual void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
443 ManagedRegister scratch, size_t size) = 0;
444
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700445 virtual void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
446 ManagedRegister scratch, size_t size) = 0;
447
Ian Rogersdc51b792011-09-22 20:41:37 -0700448 virtual void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset,
449 ManagedRegister scratch, size_t size) = 0;
450
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700451 virtual void Copy(ManagedRegister dest, Offset dest_offset,
452 ManagedRegister src, Offset src_offset,
453 ManagedRegister scratch, size_t size) = 0;
454
455 virtual void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
456 ManagedRegister scratch, size_t size) = 0;
Ian Rogersdc51b792011-09-22 20:41:37 -0700457
Ian Rogerse5de95b2011-09-18 20:31:38 -0700458 virtual void MemoryBarrier(ManagedRegister scratch) = 0;
459
jeffhao58136ca2012-05-24 13:40:11 -0700460 // Sign extension
461 virtual void SignExtend(ManagedRegister mreg, size_t size) = 0;
462
jeffhaocee4d0c2012-06-15 14:42:01 -0700463 // Zero extension
464 virtual void ZeroExtend(ManagedRegister mreg, size_t size) = 0;
465
Ian Rogers2c8f6532011-09-02 17:16:34 -0700466 // Exploit fast access in managed code to Thread::Current()
467 virtual void GetCurrentThread(ManagedRegister tr) = 0;
468 virtual void GetCurrentThread(FrameOffset dest_offset,
469 ManagedRegister scratch) = 0;
470
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700471 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700472 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700473 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700474 // null.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700475 virtual void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700476 ManagedRegister in_reg, bool null_allowed) = 0;
477
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700478 // Set up out_off to hold a Object** into the handle scope, or to be null if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700479 // value is null and null_allowed.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700480 virtual void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700481 ManagedRegister scratch, bool null_allowed) = 0;
482
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700483 // src holds a handle scope entry (Object**) load this into dst
484 virtual void LoadReferenceFromHandleScope(ManagedRegister dst,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700485 ManagedRegister src) = 0;
486
487 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
488 // know that src may not be null.
489 virtual void VerifyObject(ManagedRegister src, bool could_be_null) = 0;
490 virtual void VerifyObject(FrameOffset src, bool could_be_null) = 0;
491
492 // Call to address held at [base+offset]
493 virtual void Call(ManagedRegister base, Offset offset,
494 ManagedRegister scratch) = 0;
495 virtual void Call(FrameOffset base, Offset offset,
496 ManagedRegister scratch) = 0;
Ian Rogersdd7624d2014-03-14 17:43:00 -0700497 virtual void CallFromThread32(ThreadOffset<4> offset, ManagedRegister scratch);
498 virtual void CallFromThread64(ThreadOffset<8> offset, ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700499
Ian Rogers2c8f6532011-09-02 17:16:34 -0700500 // Generate code to check if Thread::Current()->exception_ is non-null
501 // and branch to a ExceptionSlowPath if it is.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700502 virtual void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700503
Andreas Gampe85b62f22015-09-09 13:15:38 -0700504 virtual void Bind(Label* label) = 0;
505 virtual void Jump(Label* label) = 0;
506
Ian Rogers2c8f6532011-09-02 17:16:34 -0700507 virtual ~Assembler() {}
508
David Srbeckydd973932015-04-07 20:29:48 +0100509 /**
510 * @brief Buffer of DWARF's Call Frame Information opcodes.
511 * @details It is used by debuggers and other tools to unwind the call stack.
512 */
513 DebugFrameOpCodeWriterForAssembler& cfi() { return cfi_; }
514
Ian Rogers2c8f6532011-09-02 17:16:34 -0700515 protected:
Vladimir Marko93205e32016-04-13 11:59:46 +0100516 explicit Assembler(ArenaAllocator* arena) : buffer_(arena), cfi_(this) {}
517
518 ArenaAllocator* GetArena() {
519 return buffer_.GetArena();
520 }
Ian Rogers2c8f6532011-09-02 17:16:34 -0700521
522 AssemblerBuffer buffer_;
David Srbeckydd973932015-04-07 20:29:48 +0100523
524 DebugFrameOpCodeWriterForAssembler cfi_;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700525};
526
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700527} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700528
Ian Rogers166db042013-07-26 12:05:57 -0700529#endif // ART_COMPILER_UTILS_ASSEMBLER_H_