From: Vladimir Marko Date: Thu, 19 Feb 2015 15:50:28 +0000 (+0000) Subject: Replace a few std::vector with ArenaVector in Mir2Lir. X-Git-Tag: android-x86-7.1-r1~889^2~1999^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=80b96d1a76790527f72a660ac03d9c215eed17ce;p=android-x86%2Fart.git Replace a few std::vector with ArenaVector in Mir2Lir. Change-Id: I7867d60afc60f57cdbbfd312f02883854d65c805 --- diff --git a/compiler/dex/quick/codegen_util.cc b/compiler/dex/quick/codegen_util.cc index 055c39f70..0be9fd478 100644 --- a/compiler/dex/quick/codegen_util.cc +++ b/compiler/dex/quick/codegen_util.cc @@ -456,37 +456,29 @@ LIR* Mir2Lir::AddWideData(LIR* *constant_list_p, int val_lo, int val_hi) { return AddWordData(constant_list_p, val_lo); } -static void Push32(std::vector&buf, int data) { - buf.push_back(data & 0xff); - buf.push_back((data >> 8) & 0xff); - buf.push_back((data >> 16) & 0xff); - buf.push_back((data >> 24) & 0xff); -} - /** * @brief Push a compressed reference which needs patching at link/patchoat-time. * @details This needs to be kept consistent with the code which actually does the patching in * oat_writer.cc and in the patchoat tool. */ -static void PushUnpatchedReference(std::vector&buf) { +static void PushUnpatchedReference(CodeBuffer* buf) { // Note that we can safely initialize the patches to zero. The code deduplication mechanism takes // the patches into account when determining whether two pieces of codes are functionally // equivalent. Push32(buf, UINT32_C(0)); } -static void AlignBuffer(std::vector&buf, size_t offset) { - while (buf.size() < offset) { - buf.push_back(0); - } +static void AlignBuffer(CodeBuffer* buf, size_t offset) { + DCHECK_LE(buf->size(), offset); + buf->insert(buf->end(), offset - buf->size(), 0u); } /* Write the literal pool to the output stream */ void Mir2Lir::InstallLiteralPools() { - AlignBuffer(code_buffer_, data_offset_); + AlignBuffer(&code_buffer_, data_offset_); LIR* data_lir = literal_list_; while (data_lir != nullptr) { - Push32(code_buffer_, data_lir->operands[0]); + Push32(&code_buffer_, data_lir->operands[0]); data_lir = NEXT_LIR(data_lir); } // TODO: patches_.reserve() as needed. @@ -498,7 +490,7 @@ void Mir2Lir::InstallLiteralPools() { reinterpret_cast(UnwrapPointer(data_lir->operands[1])); patches_.push_back(LinkerPatch::CodePatch(code_buffer_.size(), target_dex_file, target_method_idx)); - PushUnpatchedReference(code_buffer_); + PushUnpatchedReference(&code_buffer_); data_lir = NEXT_LIR(data_lir); } data_lir = method_literal_list_; @@ -508,7 +500,7 @@ void Mir2Lir::InstallLiteralPools() { reinterpret_cast(UnwrapPointer(data_lir->operands[1])); patches_.push_back(LinkerPatch::MethodPatch(code_buffer_.size(), target_dex_file, target_method_idx)); - PushUnpatchedReference(code_buffer_); + PushUnpatchedReference(&code_buffer_); data_lir = NEXT_LIR(data_lir); } // Push class literals. @@ -519,7 +511,7 @@ void Mir2Lir::InstallLiteralPools() { reinterpret_cast(UnwrapPointer(data_lir->operands[1])); patches_.push_back(LinkerPatch::TypePatch(code_buffer_.size(), class_dex_file, target_type_idx)); - PushUnpatchedReference(code_buffer_); + PushUnpatchedReference(&code_buffer_); data_lir = NEXT_LIR(data_lir); } } @@ -527,7 +519,7 @@ void Mir2Lir::InstallLiteralPools() { /* Write the switch tables to the output stream */ void Mir2Lir::InstallSwitchTables() { for (Mir2Lir::SwitchTable* tab_rec : switch_tables_) { - AlignBuffer(code_buffer_, tab_rec->offset); + AlignBuffer(&code_buffer_, tab_rec->offset); /* * For Arm, our reference point is the address of the bx * instruction that does the launch, so we have to subtract @@ -567,8 +559,8 @@ void Mir2Lir::InstallSwitchTables() { LIR* boundary_lir = InsertCaseLabel(target, key); DCHECK(boundary_lir != nullptr); int disp = boundary_lir->offset - bx_offset; - Push32(code_buffer_, key); - Push32(code_buffer_, disp); + Push32(&code_buffer_, key); + Push32(&code_buffer_, disp); if (cu_->verbose) { LOG(INFO) << " Case[" << elems << "] key: 0x" << std::hex << key << ", disp: 0x" @@ -592,7 +584,7 @@ void Mir2Lir::InstallSwitchTables() { LIR* boundary_lir = InsertCaseLabel(target, key); DCHECK(boundary_lir != nullptr); int disp = boundary_lir->offset - bx_offset; - Push32(code_buffer_, disp); + Push32(&code_buffer_, disp); if (cu_->verbose) { LOG(INFO) << " Case[" << elems << "] disp: 0x" << std::hex << disp; @@ -607,7 +599,7 @@ void Mir2Lir::InstallSwitchTables() { /* Write the fill array dta to the output stream */ void Mir2Lir::InstallFillArrayData() { for (Mir2Lir::FillArrayData* tab_rec : fill_array_data_) { - AlignBuffer(code_buffer_, tab_rec->offset); + AlignBuffer(&code_buffer_, tab_rec->offset); for (int i = 0; i < (tab_rec->size + 1) / 2; i++) { code_buffer_.push_back(tab_rec->table[i] & 0xFF); code_buffer_.push_back((tab_rec->table[i] >> 8) & 0xFF); @@ -975,8 +967,11 @@ Mir2Lir::Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena estimated_native_code_size_(0), reg_pool_(nullptr), live_sreg_(0), + code_buffer_(mir_graph->GetArena()->Adapter()), + encoded_mapping_table_(mir_graph->GetArena()->Adapter()), core_vmap_table_(mir_graph->GetArena()->Adapter()), fp_vmap_table_(mir_graph->GetArena()->Adapter()), + native_gc_map_(mir_graph->GetArena()->Adapter()), patches_(mir_graph->GetArena()->Adapter()), num_core_spills_(0), num_fp_spills_(0), diff --git a/compiler/dex/quick/mir_to_lir.h b/compiler/dex/quick/mir_to_lir.h index 88ca91173..6fdd76482 100644 --- a/compiler/dex/quick/mir_to_lir.h +++ b/compiler/dex/quick/mir_to_lir.h @@ -146,7 +146,7 @@ typedef int (*NextCallInsn)(CompilationUnit*, CallInfo*, int, uint32_t method_idx, uintptr_t direct_code, uintptr_t direct_method, InvokeType type); -typedef std::vector CodeBuffer; +typedef ArenaVector CodeBuffer; typedef uint32_t CodeOffset; // Native code offset in bytes. struct UseDefMasks { @@ -1742,10 +1742,10 @@ class Mir2Lir { // The source mapping table data (pc -> dex). More entries than in encoded_mapping_table_ DefaultSrcMap src_mapping_table_; // The encoding mapping table data (dex -> pc offset and pc offset -> dex) with a size prefix. - std::vector encoded_mapping_table_; + ArenaVector encoded_mapping_table_; ArenaVector core_vmap_table_; ArenaVector fp_vmap_table_; - std::vector native_gc_map_; + ArenaVector native_gc_map_; ArenaVector patches_; int num_core_spills_; int num_fp_spills_; diff --git a/compiler/dex/quick/x86/target_x86.cc b/compiler/dex/quick/x86/target_x86.cc index c4adb0924..8f97d1e7c 100755 --- a/compiler/dex/quick/x86/target_x86.cc +++ b/compiler/dex/quick/x86/target_x86.cc @@ -1051,10 +1051,10 @@ void X86Mir2Lir::InstallLiteralPools() { } for (LIR *p = const_vectors_; p != nullptr; p = p->next) { - PushWord(&code_buffer_, p->operands[0]); - PushWord(&code_buffer_, p->operands[1]); - PushWord(&code_buffer_, p->operands[2]); - PushWord(&code_buffer_, p->operands[3]); + Push32(&code_buffer_, p->operands[0]); + Push32(&code_buffer_, p->operands[1]); + Push32(&code_buffer_, p->operands[2]); + Push32(&code_buffer_, p->operands[3]); } } diff --git a/compiler/elf_writer_quick.cc b/compiler/elf_writer_quick.cc index 9ec4f281c..401d5a951 100644 --- a/compiler/elf_writer_quick.cc +++ b/compiler/elf_writer_quick.cc @@ -90,19 +90,19 @@ std::vector* ConstructCIEFrameX86(bool is_x86_64) { // Length (will be filled in later in this routine). if (is_x86_64) { - PushWord(cfi_info, 0xffffffff); // Indicates 64bit - PushWord(cfi_info, 0); - PushWord(cfi_info, 0); + Push32(cfi_info, 0xffffffff); // Indicates 64bit + Push32(cfi_info, 0); + Push32(cfi_info, 0); } else { - PushWord(cfi_info, 0); + Push32(cfi_info, 0); } // CIE id: always 0. if (is_x86_64) { - PushWord(cfi_info, 0); - PushWord(cfi_info, 0); + Push32(cfi_info, 0); + Push32(cfi_info, 0); } else { - PushWord(cfi_info, 0); + Push32(cfi_info, 0); } // Version: always 1. @@ -318,7 +318,7 @@ class LineTableGenerator FINAL : public Leb128Encoder { PushByte(data_, 0); // extended opcode: PushByte(data_, 1 + 4); // length: opcode_size + address_size PushByte(data_, DW_LNE_set_address); - PushWord(data_, addr); + Push32(data_, addr); } void SetLine(unsigned line) { @@ -507,13 +507,13 @@ static void FillInCFIInformation(OatWriter* oat_writer, // Start the debug_info section with the header information // 'unit_length' will be filled in later. int cunit_length = dbg_info->size(); - PushWord(dbg_info, 0); + Push32(dbg_info, 0); // 'version' - 3. PushHalf(dbg_info, 3); // Offset into .debug_abbrev section (always 0). - PushWord(dbg_info, 0); + Push32(dbg_info, 0); // Address size: 4. PushByte(dbg_info, 4); @@ -523,7 +523,7 @@ static void FillInCFIInformation(OatWriter* oat_writer, PushByte(dbg_info, 1); // The producer is Android dex2oat. - PushWord(dbg_info, producer_str_offset); + Push32(dbg_info, producer_str_offset); // The language is Java. PushByte(dbg_info, DW_LANG_Java); @@ -532,8 +532,8 @@ static void FillInCFIInformation(OatWriter* oat_writer, uint32_t cunit_low_pc = 0 - 1; uint32_t cunit_high_pc = 0; int cunit_low_pc_pos = dbg_info->size(); - PushWord(dbg_info, 0); - PushWord(dbg_info, 0); + Push32(dbg_info, 0); + Push32(dbg_info, 0); if (dbg_line == nullptr) { for (size_t i = 0; i < method_info.size(); ++i) { @@ -546,9 +546,9 @@ static void FillInCFIInformation(OatWriter* oat_writer, PushByte(dbg_info, 2); // Enter name, low_pc, high_pc. - PushWord(dbg_info, PushStr(dbg_str, dbg.method_name_)); - PushWord(dbg_info, dbg.low_pc_ + text_section_offset); - PushWord(dbg_info, dbg.high_pc_ + text_section_offset); + Push32(dbg_info, PushStr(dbg_str, dbg.method_name_)); + Push32(dbg_info, dbg.low_pc_ + text_section_offset); + Push32(dbg_info, dbg.high_pc_ + text_section_offset); } } else { // TODO: in gdb info functions - reports Java functions, but @@ -559,15 +559,15 @@ static void FillInCFIInformation(OatWriter* oat_writer, // method ranges. // Line number table offset - PushWord(dbg_info, dbg_line->size()); + Push32(dbg_info, dbg_line->size()); size_t lnt_length = dbg_line->size(); - PushWord(dbg_line, 0); + Push32(dbg_line, 0); PushHalf(dbg_line, 4); // LNT Version DWARF v4 => 4 size_t lnt_hdr_length = dbg_line->size(); - PushWord(dbg_line, 0); // TODO: 64-bit uses 8-byte here + Push32(dbg_line, 0); // TODO: 64-bit uses 8-byte here PushByte(dbg_line, 1); // minimum_instruction_length (ubyte) PushByte(dbg_line, 1); // maximum_operations_per_instruction (ubyte) = always 1 @@ -629,9 +629,9 @@ static void FillInCFIInformation(OatWriter* oat_writer, PushByte(dbg_info, 2); // Enter name, low_pc, high_pc. - PushWord(dbg_info, PushStr(dbg_str, dbg.method_name_)); - PushWord(dbg_info, dbg.low_pc_ + text_section_offset); - PushWord(dbg_info, dbg.high_pc_ + text_section_offset); + Push32(dbg_info, PushStr(dbg_str, dbg.method_name_)); + Push32(dbg_info, dbg.low_pc_ + text_section_offset); + Push32(dbg_info, dbg.high_pc_ + text_section_offset); GetLineInfoForJava(dbg.dbgstream_, dbg.compiled_method_->GetSrcMappingTable(), &pc2java_map, dbg.low_pc_); diff --git a/compiler/gc_map_builder.h b/compiler/gc_map_builder.h index bc8ad4160..4c36ef733 100644 --- a/compiler/gc_map_builder.h +++ b/compiler/gc_map_builder.h @@ -26,15 +26,17 @@ namespace art { class GcMapBuilder { public: - GcMapBuilder(std::vector* table, size_t entries, uint32_t max_native_offset, + template + GcMapBuilder(std::vector* table, size_t entries, uint32_t max_native_offset, size_t references_width) : entries_(entries), references_width_(entries != 0u ? references_width : 0u), native_offset_width_(entries != 0 && max_native_offset != 0 ? sizeof(max_native_offset) - CLZ(max_native_offset) / 8u : 0u), - in_use_(entries), table_(table) { + in_use_(entries) { // Resize table and set up header. table->resize((EntryWidth() * entries) + sizeof(uint32_t)); + table_ = table->data(); CHECK_LT(native_offset_width_, 1U << 3); (*table)[0] = native_offset_width_ & 7; CHECK_LT(references_width_, 1U << 13); @@ -65,7 +67,7 @@ class GcMapBuilder { uint32_t native_offset = 0; size_t table_offset = (table_index * EntryWidth()) + sizeof(uint32_t); for (size_t i = 0; i < native_offset_width_; i++) { - native_offset |= (*table_)[table_offset + i] << (i * 8); + native_offset |= table_[table_offset + i] << (i * 8); } return native_offset; } @@ -73,13 +75,13 @@ class GcMapBuilder { void SetCodeOffset(size_t table_index, uint32_t native_offset) { size_t table_offset = (table_index * EntryWidth()) + sizeof(uint32_t); for (size_t i = 0; i < native_offset_width_; i++) { - (*table_)[table_offset + i] = (native_offset >> (i * 8)) & 0xFF; + table_[table_offset + i] = (native_offset >> (i * 8)) & 0xFF; } } void SetReferences(size_t table_index, const uint8_t* references) { size_t table_offset = (table_index * EntryWidth()) + sizeof(uint32_t); - memcpy(&(*table_)[table_offset + native_offset_width_], references, references_width_); + memcpy(&table_[table_offset + native_offset_width_], references, references_width_); } size_t EntryWidth() const { @@ -95,7 +97,7 @@ class GcMapBuilder { // Entries that are in use. std::vector in_use_; // The table we're building. - std::vector* const table_; + uint8_t* table_; }; } // namespace art diff --git a/compiler/utils/dwarf_cfi.cc b/compiler/utils/dwarf_cfi.cc index 83e5f5ad3..a7e09c651 100644 --- a/compiler/utils/dwarf_cfi.cc +++ b/compiler/utils/dwarf_cfi.cc @@ -37,7 +37,7 @@ void DW_CFA_advance_loc(std::vector* buf, uint32_t increment) { } else { // Four byte delta. buf->push_back(0x04); - PushWord(buf, increment); + Push32(buf, increment); } } @@ -68,35 +68,35 @@ void DW_CFA_restore_state(std::vector* buf) { void WriteFDEHeader(std::vector* buf, bool is_64bit) { // 'length' (filled in by other functions). if (is_64bit) { - PushWord(buf, 0xffffffff); // Indicates 64bit - PushWord(buf, 0); - PushWord(buf, 0); + Push32(buf, 0xffffffff); // Indicates 64bit + Push32(buf, 0); + Push32(buf, 0); } else { - PushWord(buf, 0); + Push32(buf, 0); } // 'CIE_pointer' (filled in by linker). if (is_64bit) { - PushWord(buf, 0); - PushWord(buf, 0); + Push32(buf, 0); + Push32(buf, 0); } else { - PushWord(buf, 0); + Push32(buf, 0); } // 'initial_location' (filled in by linker). if (is_64bit) { - PushWord(buf, 0); - PushWord(buf, 0); + Push32(buf, 0); + Push32(buf, 0); } else { - PushWord(buf, 0); + Push32(buf, 0); } // 'address_range' (filled in by other functions). if (is_64bit) { - PushWord(buf, 0); - PushWord(buf, 0); + Push32(buf, 0); + Push32(buf, 0); } else { - PushWord(buf, 0); + Push32(buf, 0); } // Augmentation length: 0 diff --git a/runtime/utils.cc b/runtime/utils.cc index 3ec9561f4..85c9340d0 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -1554,13 +1554,6 @@ void EncodeSignedLeb128(int32_t data, std::vector* dst) { Leb128Encoder(dst).PushBackSigned(data); } -void PushWord(std::vector* buf, int data) { - buf->push_back(data & 0xff); - buf->push_back((data >> 8) & 0xff); - buf->push_back((data >> 16) & 0xff); - buf->push_back((data >> 24) & 0xff); -} - std::string PrettyDescriptor(Primitive::Type type) { return PrettyDescriptor(Primitive::Descriptor(type)); } diff --git a/runtime/utils.h b/runtime/utils.h index 0fbc9df5a..3191e7d30 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -546,7 +546,13 @@ class VoidFunctor { } }; -void PushWord(std::vector* buf, int32_t data); +template +void Push32(std::vector* buf, int32_t data) { + buf->push_back(data & 0xff); + buf->push_back((data >> 8) & 0xff); + buf->push_back((data >> 16) & 0xff); + buf->push_back((data >> 24) & 0xff); +} void EncodeUnsignedLeb128(uint32_t data, std::vector* buf); void EncodeSignedLeb128(int32_t data, std::vector* buf);