diff options
author | 2022-03-29 11:23:39 +0000 | |
---|---|---|
committer | 2022-04-05 13:46:56 +0000 | |
commit | 099b75bdcf53aa40e7ac191fa7a28ec484e138fb (patch) | |
tree | 978e9cb6173191a51842bed675c443e4b1de7b5c | |
parent | 714328e2d2f64a5d3976f19e6ffa781c69e9f6de (diff) |
Use `HashMap<>` for code info deduplication.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 181943478
Change-Id: If99f5abfa67617d290a084d900e56355b6b10cdb
-rw-r--r-- | dex2oat/linker/oat_writer.cc | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc index df95f2a856..19e77de10b 100644 --- a/dex2oat/linker/oat_writer.cc +++ b/dex2oat/linker/oat_writer.cc @@ -1514,14 +1514,16 @@ class OatWriter::InitMapMethodVisitor : public OatDexMethodVisitor { : OatDexMethodVisitor(writer, offset), dedupe_bit_table_(&writer_->code_info_data_) { if (kDeduplicate) { - // Reserve a large buffer for `CodeInfo` bit table deduplication except for + // Reserve large buffers for `CodeInfo` and bit table deduplication except for // multi-image compilation as we do not want to reserve multiple large buffers. // User devices should not do any multi-image compilation. const CompilerOptions& compiler_options = writer->GetCompilerOptions(); DCHECK(compiler_options.IsAnyCompilationEnabled()); if (compiler_options.DeduplicateCode() && !compiler_options.IsMultiImage()) { - dedupe_bit_table_.ReserveDedupeBuffer( - writer->compiler_driver_->GetCompiledMethodStorage()->UniqueVMapTableEntries()); + size_t unique_code_infos = + writer->compiler_driver_->GetCompiledMethodStorage()->UniqueVMapTableEntries(); + dedupe_code_info_.reserve(unique_code_infos); + dedupe_bit_table_.ReserveDedupeBuffer(unique_code_infos); } } } @@ -1538,14 +1540,17 @@ class OatWriter::InitMapMethodVisitor : public OatDexMethodVisitor { ArrayRef<const uint8_t> map = compiled_method->GetVmapTable(); if (map.size() != 0u) { - size_t offset; + size_t offset = offset_ + writer_->code_info_data_.size(); if (kDeduplicate) { - offset = dedupe_code_info_.GetOrCreate(map.data(), [=]() { - // Deduplicate the inner BitTable<>s within the CodeInfo. - return offset_ + dedupe_bit_table_.Dedupe(map.data()); - }); + auto [it, inserted] = dedupe_code_info_.insert(std::make_pair(map.data(), offset)); + DCHECK_EQ(inserted, it->second == offset); + if (inserted) { + size_t dedupe_bit_table_offset = dedupe_bit_table_.Dedupe(map.data()); + DCHECK_EQ(offset, offset_ + dedupe_bit_table_offset); + } else { + offset = it->second; + } } else { - offset = offset_ + writer_->code_info_data_.size(); writer_->code_info_data_.insert(writer_->code_info_data_.end(), map.begin(), map.end()); } // Code offset is not initialized yet, so set file offset for now. @@ -1562,7 +1567,7 @@ class OatWriter::InitMapMethodVisitor : public OatDexMethodVisitor { // Deduplicate at CodeInfo level. The value is byte offset within code_info_data_. // This deduplicates the whole CodeInfo object without going into the inner tables. // The compiler already deduplicated the pointers but it did not dedupe the tables. - SafeMap<const uint8_t*, size_t> dedupe_code_info_; + HashMap<const uint8_t*, size_t> dedupe_code_info_; // Deduplicate at BitTable level. CodeInfoTableDeduper dedupe_bit_table_; |