diff options
Diffstat (limited to 'compiler/utils/assembler.cc')
| -rw-r--r-- | compiler/utils/assembler.cc | 89 |
1 files changed, 60 insertions, 29 deletions
diff --git a/compiler/utils/assembler.cc b/compiler/utils/assembler.cc index b016e74aba..e6c3a18d04 100644 --- a/compiler/utils/assembler.cc +++ b/compiler/utils/assembler.cc @@ -19,26 +19,35 @@ #include <algorithm> #include <vector> +#ifdef ART_ENABLE_CODEGEN_arm #include "arm/assembler_arm32.h" #include "arm/assembler_thumb2.h" +#endif +#ifdef ART_ENABLE_CODEGEN_arm64 #include "arm64/assembler_arm64.h" +#endif +#ifdef ART_ENABLE_CODEGEN_mips #include "mips/assembler_mips.h" +#endif +#ifdef ART_ENABLE_CODEGEN_mips64 #include "mips64/assembler_mips64.h" +#endif +#ifdef ART_ENABLE_CODEGEN_x86 #include "x86/assembler_x86.h" +#endif +#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; @@ -55,7 +64,9 @@ AssemblerBuffer::AssemblerBuffer() { AssemblerBuffer::~AssemblerBuffer() { - delete[] contents_; + if (arena_->IsRunningOnMemoryTool()) { + arena_->MakeInaccessible(contents_, Capacity()); + } } @@ -80,25 +91,20 @@ void AssemblerBuffer::FinalizeInstructions(const MemoryRegion& instructions) { } -void AssemblerBuffer::ExtendCapacity() { +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); @@ -106,25 +112,50 @@ void AssemblerBuffer::ExtendCapacity() { } void DebugFrameOpCodeWriterForAssembler::ImplicitlyAdvancePC() { - this->AdvancePC(assembler_->CodeSize()); + 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); + } } -Assembler* Assembler::Create(InstructionSet instruction_set) { +std::unique_ptr<Assembler> Assembler::Create( + ArenaAllocator* arena, + InstructionSet instruction_set, + const InstructionSetFeatures* instruction_set_features) { switch (instruction_set) { +#ifdef ART_ENABLE_CODEGEN_arm case kArm: - return new arm::Arm32Assembler(); + return std::unique_ptr<Assembler>(new (arena) arm::Arm32Assembler(arena)); case kThumb2: - return new arm::Thumb2Assembler(); + return std::unique_ptr<Assembler>(new (arena) arm::Thumb2Assembler(arena)); +#endif +#ifdef ART_ENABLE_CODEGEN_arm64 case kArm64: - return new arm64::Arm64Assembler(); + return std::unique_ptr<Assembler>(new (arena) arm64::Arm64Assembler(arena)); +#endif +#ifdef ART_ENABLE_CODEGEN_mips case kMips: - return new mips::MipsAssembler(); + return std::unique_ptr<Assembler>(new (arena) mips::MipsAssembler( + arena, + instruction_set_features != nullptr + ? instruction_set_features->AsMipsInstructionSetFeatures() + : nullptr)); +#endif +#ifdef ART_ENABLE_CODEGEN_mips64 case kMips64: - return new mips64::Mips64Assembler(); + return std::unique_ptr<Assembler>(new (arena) mips64::Mips64Assembler(arena)); +#endif +#ifdef ART_ENABLE_CODEGEN_x86 case kX86: - return new x86::X86Assembler(); + return std::unique_ptr<Assembler>(new (arena) x86::X86Assembler(arena)); +#endif +#ifdef ART_ENABLE_CODEGEN_x86_64 case kX86_64: - return new x86_64::X86_64Assembler(); + return std::unique_ptr<Assembler>(new (arena) x86_64::X86_64Assembler(arena)); +#endif default: LOG(FATAL) << "Unknown InstructionSet: " << instruction_set; return nullptr; |