diff options
Diffstat (limited to 'compiler/utils/assembler.cc')
| -rw-r--r-- | compiler/utils/assembler.cc | 162 |
1 files changed, 18 insertions, 144 deletions
diff --git a/compiler/utils/assembler.cc b/compiler/utils/assembler.cc index b01b0fe4e0..81159e69a0 100644 --- a/compiler/utils/assembler.cc +++ b/compiler/utils/assembler.cc @@ -38,19 +38,16 @@ #ifdef ART_ENABLE_CODEGEN_x86_64 #include "x86_64/assembler_x86_64.h" #endif +#include "base/casts.h" #include "globals.h" #include "memory_region.h" namespace art { -static uint8_t* NewContents(size_t capacity) { - return new uint8_t[capacity]; -} - - -AssemblerBuffer::AssemblerBuffer() { +AssemblerBuffer::AssemblerBuffer(ArenaAllocator* arena) + : arena_(arena) { static const size_t kInitialBufferCapacity = 4 * KB; - contents_ = NewContents(kInitialBufferCapacity); + contents_ = arena_->AllocArray<uint8_t>(kInitialBufferCapacity, kArenaAllocAssembler); cursor_ = contents_; limit_ = ComputeLimit(contents_, kInitialBufferCapacity); fixup_ = nullptr; @@ -67,7 +64,9 @@ AssemblerBuffer::AssemblerBuffer() { AssemblerBuffer::~AssemblerBuffer() { - delete[] contents_; + if (arena_->IsRunningOnMemoryTool()) { + arena_->MakeInaccessible(contents_, Capacity()); + } } @@ -95,23 +94,17 @@ void AssemblerBuffer::FinalizeInstructions(const MemoryRegion& instructions) { void AssemblerBuffer::ExtendCapacity(size_t min_capacity) { size_t old_size = Size(); size_t old_capacity = Capacity(); + DCHECK_GT(min_capacity, old_capacity); size_t new_capacity = std::min(old_capacity * 2, old_capacity + 1 * MB); new_capacity = std::max(new_capacity, min_capacity); // Allocate the new data area and copy contents of the old one to it. - uint8_t* new_contents = NewContents(new_capacity); - memmove(reinterpret_cast<void*>(new_contents), - reinterpret_cast<void*>(contents_), - old_size); - - // Compute the relocation delta and switch to the new contents area. - ptrdiff_t delta = new_contents - contents_; - delete[] contents_; - contents_ = new_contents; + contents_ = reinterpret_cast<uint8_t*>( + arena_->Realloc(contents_, old_capacity, new_capacity, kArenaAllocAssembler)); // Update the cursor and recompute the limit. - cursor_ += delta; - limit_ = ComputeLimit(new_contents, new_capacity); + cursor_ = contents_ + old_size; + limit_ = ComputeLimit(contents_, new_capacity); // Verify internal state. CHECK_EQ(Capacity(), new_capacity); @@ -119,132 +112,13 @@ void AssemblerBuffer::ExtendCapacity(size_t min_capacity) { } void DebugFrameOpCodeWriterForAssembler::ImplicitlyAdvancePC() { - this->AdvancePC(assembler_->CodeSize()); -} - -Assembler* Assembler::Create(InstructionSet instruction_set, - const InstructionSetFeatures* instruction_set_features) { - switch (instruction_set) { -#ifdef ART_ENABLE_CODEGEN_arm - case kArm: - return new arm::Arm32Assembler(); - case kThumb2: - return new arm::Thumb2Assembler(); -#endif -#ifdef ART_ENABLE_CODEGEN_arm64 - case kArm64: - return new arm64::Arm64Assembler(); -#endif -#ifdef ART_ENABLE_CODEGEN_mips - case kMips: - return new mips::MipsAssembler(instruction_set_features != nullptr - ? instruction_set_features->AsMipsInstructionSetFeatures() - : nullptr); -#endif -#ifdef ART_ENABLE_CODEGEN_mips64 - case kMips64: - return new mips64::Mips64Assembler(); -#endif -#ifdef ART_ENABLE_CODEGEN_x86 - case kX86: - return new x86::X86Assembler(); -#endif -#ifdef ART_ENABLE_CODEGEN_x86_64 - case kX86_64: - return new x86_64::X86_64Assembler(); -#endif - default: - LOG(FATAL) << "Unknown InstructionSet: " << instruction_set; - return nullptr; + uint32_t pc = dchecked_integral_cast<uint32_t>(assembler_->CodeSize()); + if (delay_emitting_advance_pc_) { + uint32_t stream_pos = dchecked_integral_cast<uint32_t>(opcodes_.size()); + delayed_advance_pcs_.push_back(DelayedAdvancePC {stream_pos, pc}); + } else { + AdvancePC(pc); } } -void Assembler::StoreImmediateToThread32(ThreadOffset<4> dest ATTRIBUTE_UNUSED, - uint32_t imm ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::StoreImmediateToThread64(ThreadOffset<8> dest ATTRIBUTE_UNUSED, - uint32_t imm ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::StoreStackOffsetToThread32(ThreadOffset<4> thr_offs ATTRIBUTE_UNUSED, - FrameOffset fr_offs ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::StoreStackOffsetToThread64(ThreadOffset<8> thr_offs ATTRIBUTE_UNUSED, - FrameOffset fr_offs ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::StoreStackPointerToThread32(ThreadOffset<4> thr_offs ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::StoreStackPointerToThread64(ThreadOffset<8> thr_offs ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::LoadFromThread32(ManagedRegister dest ATTRIBUTE_UNUSED, - ThreadOffset<4> src ATTRIBUTE_UNUSED, - size_t size ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::LoadFromThread64(ManagedRegister dest ATTRIBUTE_UNUSED, - ThreadOffset<8> src ATTRIBUTE_UNUSED, - size_t size ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::LoadRawPtrFromThread32(ManagedRegister dest ATTRIBUTE_UNUSED, - ThreadOffset<4> offs ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::LoadRawPtrFromThread64(ManagedRegister dest ATTRIBUTE_UNUSED, - ThreadOffset<8> offs ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::CopyRawPtrFromThread32(FrameOffset fr_offs ATTRIBUTE_UNUSED, - ThreadOffset<4> thr_offs ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::CopyRawPtrFromThread64(FrameOffset fr_offs ATTRIBUTE_UNUSED, - ThreadOffset<8> thr_offs ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::CopyRawPtrToThread32(ThreadOffset<4> thr_offs ATTRIBUTE_UNUSED, - FrameOffset fr_offs ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::CopyRawPtrToThread64(ThreadOffset<8> thr_offs ATTRIBUTE_UNUSED, - FrameOffset fr_offs ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::CallFromThread32(ThreadOffset<4> offset ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - -void Assembler::CallFromThread64(ThreadOffset<8> offset ATTRIBUTE_UNUSED, - ManagedRegister scratch ATTRIBUTE_UNUSED) { - UNIMPLEMENTED(FATAL); -} - } // namespace art |