diff options
author | 2018-06-29 09:31:30 -0700 | |
---|---|---|
committer | 2018-06-29 09:50:55 -0700 | |
commit | 689caf046cb99efda4462183eeaacb11a6119adb (patch) | |
tree | d318dd6e64269150bd3844b94ebb75dc8abf8ea2 | |
parent | 04a4f20f26b0935a43f74269f68ddfd67335afb8 (diff) |
Cache DexFile begin and size
Avoid virtual function invocations in DexFile Begin() and Size() methods
by caching duplicate copies of the beginning address and size at construction.
Bug: 110980617
Test: make -j 50 test-art-host
Change-Id: I70867bcd69e30a93b91873171d365a916b76bc96
-rw-r--r-- | libdexfile/dex/dex_file.cc | 16 | ||||
-rw-r--r-- | libdexfile/dex/dex_file.h | 20 |
2 files changed, 23 insertions, 13 deletions
diff --git a/libdexfile/dex/dex_file.cc b/libdexfile/dex/dex_file.cc index c2b478aded..47a6c1b6b7 100644 --- a/libdexfile/dex/dex_file.cc +++ b/libdexfile/dex/dex_file.cc @@ -99,6 +99,11 @@ DexFile::DexFile(std::unique_ptr<DexFileContainer> main_section, const OatDexFile* oat_dex_file, bool is_compact_dex) : main_section_(std::move(main_section)), + main_begin_(main_section_->Begin()), + main_size_(main_section_->Size()), + data_section_(std::move(data_section)), + data_begin_(data_section_->Begin()), + data_size_(data_section_->Size()), location_(location), location_checksum_(location_checksum), header_(reinterpret_cast<const Header*>(main_section_->Begin())), @@ -127,8 +132,6 @@ DexFile::DexFile(std::unique_ptr<DexFileContainer> main_section, // any of the sections via a pointer. CHECK_ALIGNED(main_section_->Begin(), alignof(Header)); - data_section_ = std::move(data_section); - InitializeSectionsFromMapList(); } @@ -138,6 +141,12 @@ DexFile::DexFile(std::unique_ptr<DexFileContainer> main_section, const OatDexFile* oat_dex_file, bool is_compact_dex) : main_section_(std::move(main_section)), + main_begin_(main_section_->Begin()), + main_size_(main_section_->Size()), + data_section_(std::make_unique<NonOwningDexFileContainer>(main_section_->Begin(), + main_section_->Size())), + data_begin_(data_section_->Begin()), + data_size_(data_section_->Size()), location_(location), location_checksum_(location_checksum), header_(reinterpret_cast<const Header*>(main_section_->Begin())), @@ -166,9 +175,6 @@ DexFile::DexFile(std::unique_ptr<DexFileContainer> main_section, // any of the sections via a pointer. CHECK_ALIGNED(main_section_->Begin(), alignof(Header)); - data_section_ = std::make_unique<NonOwningDexFileContainer>(main_section_->Begin(), - main_section_->Size()); - InitializeSectionsFromMapList(); } diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h index c94c786699..714e42cb3c 100644 --- a/libdexfile/dex/dex_file.h +++ b/libdexfile/dex/dex_file.h @@ -966,19 +966,19 @@ class DexFile { bool DisableWrite() const; const uint8_t* Begin() const { - return main_section_->Begin(); + return main_begin_; } size_t Size() const { - return main_section_->Size(); + return main_size_; } const uint8_t* DataBegin() const { - return data_section_->Begin(); + return data_begin_; } size_t DataSize() const { - return data_section_->Size(); + return data_size_; } template <typename T> @@ -1089,10 +1089,14 @@ class DexFile { void InitializeSectionsFromMapList(); // The container for the header and fixed portions. - std::unique_ptr<DexFileContainer> main_section_; - - // The container for the data section - std::unique_ptr<DexFileContainer> data_section_; + const std::unique_ptr<DexFileContainer> main_section_; + const uint8_t* const main_begin_; + const size_t main_size_; + + // The container for the data section. + const std::unique_ptr<DexFileContainer> data_section_; + const uint8_t* const data_begin_; + const size_t data_size_; // Typically the dex file name when available, alternatively some identifying string. // |