diff options
Diffstat (limited to 'dexlayout/dexlayout.cc')
| -rw-r--r-- | dexlayout/dexlayout.cc | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/dexlayout/dexlayout.cc b/dexlayout/dexlayout.cc index 47a3e943a5..3d3b121190 100644 --- a/dexlayout/dexlayout.cc +++ b/dexlayout/dexlayout.cc @@ -34,6 +34,7 @@ #include "android-base/stringprintf.h" #include "base/logging.h" // For VLOG_IS_ON. +#include "dex/art_dex_file_loader.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_layout.h" #include "dex/dex_file_loader.h" @@ -1819,8 +1820,13 @@ void DexLayout::OutputDexFile(const DexFile* dex_file, bool compute_offsets) { // Since we allow dex growth, we need to size the map larger than the original input to be safe. // Reserve an extra 10% to add some buffer room. Note that this is probably more than // necessary. - constexpr size_t kReserveFraction = 10; - const size_t max_size = header_->FileSize() + header_->FileSize() / kReserveFraction; + static constexpr size_t kReserveFraction = 10; + // Add an extra constant amount since the compact dex header and extra tables may cause more + // expansion than fits in the reserve fraction for small dex files. + // TODO: Move to using a resizable buffer like a vector. + static constexpr size_t kExtraReserve = 128 * KB; + const size_t max_size = header_->FileSize() + kExtraReserve + + header_->FileSize() / kReserveFraction; if (!options_.output_to_memmap_) { std::string output_location(options_.output_dex_directory_); size_t last_slash = dex_file_location.rfind('/'); @@ -1912,7 +1918,8 @@ void DexLayout::ProcessDexFile(const char* file_name, if (do_layout) { LayoutOutputFile(dex_file); } - OutputDexFile(dex_file, do_layout); + // If we didn't set the offsets eagerly, we definitely need to compute them here. + OutputDexFile(dex_file, do_layout || !eagerly_assign_offsets); // Clear header before verifying to reduce peak RAM usage. const size_t file_size = header_->FileSize(); @@ -1922,14 +1929,18 @@ void DexLayout::ProcessDexFile(const char* file_name, if (options_.verify_output_) { std::string error_msg; std::string location = "memory mapped file for " + std::string(file_name); - std::unique_ptr<const DexFile> output_dex_file(DexFileLoader::Open(mem_map_->Begin(), - file_size, - location, - /* checksum */ 0, - /*oat_dex_file*/ nullptr, - /*verify*/ true, - /*verify_checksum*/ false, - &error_msg)); + // Dex file verifier cannot handle compact dex. + bool verify = options_.compact_dex_level_ == CompactDexLevel::kCompactDexLevelNone; + const ArtDexFileLoader dex_file_loader; + std::unique_ptr<const DexFile> output_dex_file( + dex_file_loader.Open(mem_map_->Begin(), + file_size, + location, + /* checksum */ 0, + /*oat_dex_file*/ nullptr, + verify, + /*verify_checksum*/ false, + &error_msg)); CHECK(output_dex_file != nullptr) << "Failed to re-open output file:" << error_msg; // Do IR-level comparison between input and output. This check ignores potential differences @@ -1960,8 +1971,9 @@ int DexLayout::ProcessFile(const char* file_name) { // all of which are Zip archives with "classes.dex" inside. const bool verify_checksum = !options_.ignore_bad_checksum_; std::string error_msg; + const ArtDexFileLoader dex_file_loader; std::vector<std::unique_ptr<const DexFile>> dex_files; - if (!DexFileLoader::Open( + if (!dex_file_loader.Open( file_name, file_name, /* verify */ true, verify_checksum, &error_msg, &dex_files)) { // Display returned error message to user. Note that this error behavior // differs from the error messages shown by the original Dalvik dexdump. |