diff options
| -rw-r--r-- | dex2oat/dex2oat.cc | 42 | ||||
| -rw-r--r-- | dex2oat/linker/image_test.h | 26 | ||||
| -rw-r--r-- | dex2oat/linker/image_writer.cc | 12 | ||||
| -rw-r--r-- | dex2oat/linker/image_writer.h | 8 | ||||
| -rw-r--r-- | runtime/gc/space/image_space.cc | 6 | ||||
| -rw-r--r-- | runtime/gc/space/image_space.h | 6 |
6 files changed, 45 insertions, 55 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 3a24542221..84a3ff6950 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -683,7 +683,7 @@ class Dex2Oat final { } struct ParserOptions { - std::vector<const char*> oat_symbols; + std::vector<std::string> oat_symbols; std::string boot_image_filename; int64_t watch_dog_timeout_in_ms = -1; bool watch_dog_enabled = true; @@ -833,9 +833,7 @@ class Dex2Oat final { } if (dex_locations_.empty()) { - for (const char* dex_file_name : dex_filenames_) { - dex_locations_.push_back(dex_file_name); - } + dex_locations_ = dex_filenames_; } else if (dex_locations_.size() != dex_filenames_.size()) { Usage("--dex-location arguments do not match --dex-file arguments"); } @@ -1254,8 +1252,8 @@ class Dex2Oat final { // OAT and VDEX file handling if (oat_fd_ == -1) { DCHECK(!oat_filenames_.empty()); - for (const char* oat_filename : oat_filenames_) { - std::unique_ptr<File> oat_file(OS::CreateEmptyFile(oat_filename)); + for (const std::string& oat_filename : oat_filenames_) { + std::unique_ptr<File> oat_file(OS::CreateEmptyFile(oat_filename.c_str())); if (oat_file == nullptr) { PLOG(ERROR) << "Failed to create oat file: " << oat_filename; return false; @@ -1353,7 +1351,7 @@ class Dex2Oat final { } vdex_files_.push_back(std::move(vdex_file)); - oat_filenames_.push_back(oat_location_.c_str()); + oat_filenames_.push_back(oat_location_); } // If we're updating in place a vdex file, be defensive and put an invalid vdex magic in case @@ -2127,12 +2125,12 @@ class Dex2Oat final { for (size_t i = 0; i < oat_unstripped_.size(); ++i) { // If we don't want to strip in place, copy from stripped location to unstripped location. // We need to strip after image creation because FixupElf needs to use .strtab. - if (strcmp(oat_unstripped_[i], oat_filenames_[i]) != 0) { + if (oat_unstripped_[i] != oat_filenames_[i]) { DCHECK(oat_files_[i].get() != nullptr && oat_files_[i]->IsOpened()); TimingLogger::ScopedTiming t("dex2oat OatFile copy", timings_); std::unique_ptr<File>& in = oat_files_[i]; - std::unique_ptr<File> out(OS::CreateEmptyFile(oat_unstripped_[i])); + std::unique_ptr<File> out(OS::CreateEmptyFile(oat_unstripped_[i].c_str())); int64_t in_length = in->GetLength(); if (in_length < 0) { PLOG(ERROR) << "Failed to get the length of oat file: " << in->GetPath(); @@ -2361,11 +2359,13 @@ class Dex2Oat final { DCHECK_EQ(dex_filenames_.size(), dex_locations_.size()); size_t kept = 0u; for (size_t i = 0, size = dex_filenames_.size(); i != size; ++i) { - if (!OS::FileExists(dex_filenames_[i])) { + if (!OS::FileExists(dex_filenames_[i].c_str())) { LOG(WARNING) << "Skipping non-existent dex file '" << dex_filenames_[i] << "'"; } else { - dex_filenames_[kept] = dex_filenames_[i]; - dex_locations_[kept] = dex_locations_[i]; + if (kept != i) { + dex_filenames_[kept] = dex_filenames_[i]; + dex_locations_[kept] = dex_locations_[i]; + } ++kept; } } @@ -2393,7 +2393,8 @@ class Dex2Oat final { DCHECK_EQ(oat_writers_.size(), dex_filenames_.size()); DCHECK_EQ(oat_writers_.size(), dex_locations_.size()); for (size_t i = 0, size = oat_writers_.size(); i != size; ++i) { - if (!oat_writers_[i]->AddDexFileSource(dex_filenames_[i], dex_locations_[i])) { + if (!oat_writers_[i]->AddDexFileSource(dex_filenames_[i].c_str(), + dex_locations_[i].c_str())) { return false; } } @@ -2402,7 +2403,8 @@ class Dex2Oat final { DCHECK_EQ(dex_filenames_.size(), dex_locations_.size()); DCHECK_NE(dex_filenames_.size(), 0u); for (size_t i = 0; i != dex_filenames_.size(); ++i) { - if (!oat_writers_[0]->AddDexFileSource(dex_filenames_[i], dex_locations_[i])) { + if (!oat_writers_[0]->AddDexFileSource(dex_filenames_[i].c_str(), + dex_locations_[i].c_str())) { return false; } } @@ -2562,7 +2564,7 @@ class Dex2Oat final { CHECK(image_writer_ != nullptr); if (!IsBootImage()) { CHECK(image_filenames_.empty()); - image_filenames_.push_back(app_image_file_name_.c_str()); + image_filenames_.push_back(app_image_file_name_); } if (!image_writer_->Write(app_image_fd_, image_filenames_, @@ -2725,8 +2727,8 @@ class Dex2Oat final { std::vector<std::unique_ptr<File>> oat_files_; std::vector<std::unique_ptr<File>> vdex_files_; std::string oat_location_; - std::vector<const char*> oat_filenames_; - std::vector<const char*> oat_unstripped_; + std::vector<std::string> oat_filenames_; + std::vector<std::string> oat_unstripped_; bool strip_; int oat_fd_; int input_vdex_fd_; @@ -2737,13 +2739,13 @@ class Dex2Oat final { int dm_fd_; std::string dm_file_location_; std::unique_ptr<ZipArchive> dm_file_; - std::vector<const char*> dex_filenames_; - std::vector<const char*> dex_locations_; + std::vector<std::string> dex_filenames_; + std::vector<std::string> dex_locations_; int zip_fd_; std::string zip_location_; std::string boot_image_filename_; std::vector<const char*> runtime_args_; - std::vector<const char*> image_filenames_; + std::vector<std::string> image_filenames_; uintptr_t image_base_; const char* image_classes_zip_filename_; const char* image_classes_filename_; diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h index c90eaddb4c..cde657380a 100644 --- a/dex2oat/linker/image_test.h +++ b/dex2oat/linker/image_test.h @@ -200,14 +200,6 @@ inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode, } std::unordered_map<const DexFile*, size_t> dex_file_to_oat_index_map; - std::vector<const char*> oat_filename_vector; - for (const std::string& file : oat_filenames) { - oat_filename_vector.push_back(file.c_str()); - } - std::vector<const char*> image_filename_vector; - for (const std::string& file : image_filenames) { - image_filename_vector.push_back(file.c_str()); - } size_t image_idx = 0; for (const DexFile* dex_file : class_path) { dex_file_to_oat_index_map.emplace(dex_file, image_idx); @@ -217,7 +209,7 @@ inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode, std::unique_ptr<ImageWriter> writer(new ImageWriter(*compiler_options_, kRequestedImageBase, storage_mode, - oat_filename_vector, + oat_filenames, dex_file_to_oat_index_map, /*class_loader=*/ nullptr, /*dirty_image_objects=*/ nullptr)); @@ -231,15 +223,11 @@ inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode, t.NewTiming("WriteElf"); SafeMap<std::string, std::string> key_value_store; - std::vector<const char*> dex_filename_vector; - for (size_t i = 0; i < class_path.size(); ++i) { - dex_filename_vector.push_back(""); - } key_value_store.Put(OatHeader::kBootClassPathKey, gc::space::ImageSpace::GetMultiImageBootClassPath( - dex_filename_vector, - oat_filename_vector, - image_filename_vector)); + out_helper.dex_file_locations, + oat_filenames, + image_filenames)); std::vector<std::unique_ptr<ElfWriter>> elf_writers; std::vector<std::unique_ptr<OatWriter>> oat_writers; @@ -271,7 +259,7 @@ inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode, bool dex_files_ok = oat_writers[i]->WriteAndOpenDexFiles( out_helper.vdex_files[i].GetFile(), rodata.back(), - &key_value_store, + (i == 0u) ? &key_value_store : nullptr, /* verify */ false, // Dex files may be dex-to-dex-ed, don't verify. /* update_input_vdex */ false, /* copy_dex_files */ CopyOption::kOnlyIfCompressed, @@ -356,8 +344,8 @@ inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode, } bool success_image = writer->Write(kInvalidFd, - image_filename_vector, - oat_filename_vector); + image_filenames, + oat_filenames); ASSERT_TRUE(success_image); for (size_t i = 0, size = oat_filenames.size(); i != size; ++i) { diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc index 75b35556f1..6f91d03e10 100644 --- a/dex2oat/linker/image_writer.cc +++ b/dex2oat/linker/image_writer.cc @@ -662,8 +662,8 @@ class ImageWriter::ImageFileGuard { }; bool ImageWriter::Write(int image_fd, - const std::vector<const char*>& image_filenames, - const std::vector<const char*>& oat_filenames) { + const std::vector<std::string>& image_filenames, + const std::vector<std::string>& oat_filenames) { // If image_fd or oat_fd are not kInvalidFd then we may have empty strings in image_filenames or // oat_filenames. CHECK(!image_filenames.empty()); @@ -715,11 +715,11 @@ bool ImageWriter::Write(int image_fd, ImageHeader* primary_header = reinterpret_cast<ImageHeader*>(image_infos_[0].image_.Begin()); ImageFileGuard primary_image_file; for (size_t i = 0; i < image_filenames.size(); ++i) { - const char* image_filename = image_filenames[i]; + const std::string& image_filename = image_filenames[i]; ImageInfo& image_info = GetImageInfo(i); ImageFileGuard image_file; if (image_fd != kInvalidFd) { - if (strlen(image_filename) == 0u) { + if (image_filename.empty()) { image_file.reset(new File(image_fd, unix_file::kCheckSafeUsage)); // Empty the file in case it already exists. if (image_file != nullptr) { @@ -730,7 +730,7 @@ bool ImageWriter::Write(int image_fd, LOG(ERROR) << "image fd " << image_fd << " name " << image_filename; } } else { - image_file.reset(OS::CreateEmptyFile(image_filename)); + image_file.reset(OS::CreateEmptyFile(image_filename.c_str())); } if (image_file == nullptr) { @@ -3454,7 +3454,7 @@ ImageWriter::ImageWriter( const CompilerOptions& compiler_options, uintptr_t image_begin, ImageHeader::StorageMode image_storage_mode, - const std::vector<const char*>& oat_filenames, + const std::vector<std::string>& oat_filenames, const std::unordered_map<const DexFile*, size_t>& dex_file_oat_index_map, jobject class_loader, const HashSet<std::string>* dirty_image_objects) diff --git a/dex2oat/linker/image_writer.h b/dex2oat/linker/image_writer.h index 782bbd2fc2..33bacf8c1b 100644 --- a/dex2oat/linker/image_writer.h +++ b/dex2oat/linker/image_writer.h @@ -79,7 +79,7 @@ class ImageWriter final { ImageWriter(const CompilerOptions& compiler_options, uintptr_t image_begin, ImageHeader::StorageMode image_storage_mode, - const std::vector<const char*>& oat_filenames, + const std::vector<std::string>& oat_filenames, const std::unordered_map<const DexFile*, size_t>& dex_file_oat_index_map, jobject class_loader, const HashSet<std::string>* dirty_image_objects); @@ -142,8 +142,8 @@ class ImageWriter final { // If oat_fd is not kInvalidFd, then we use that for the oat file. Otherwise we open // the names in oat_filenames. bool Write(int image_fd, - const std::vector<const char*>& image_filenames, - const std::vector<const char*>& oat_filenames) + const std::vector<std::string>& image_filenames, + const std::vector<std::string>& oat_filenames) REQUIRES(!Locks::mutator_lock_); uintptr_t GetOatDataBegin(size_t oat_index) { @@ -785,7 +785,7 @@ class ImageWriter final { const ImageHeader::StorageMode image_storage_mode_; // The file names of oat files. - const std::vector<const char*>& oat_filenames_; + const std::vector<std::string>& oat_filenames_; // Map of dex files to the indexes of oat files that they were compiled into. const std::unordered_map<const DexFile*, size_t>& dex_file_oat_index_map_; diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index bfb37463e5..085799c492 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -2337,9 +2337,9 @@ void ImageSpace::Dump(std::ostream& os) const { } std::string ImageSpace::GetMultiImageBootClassPath( - const std::vector<const char*>& dex_locations, - const std::vector<const char*>& oat_filenames, - const std::vector<const char*>& image_filenames) { + const std::vector<std::string>& dex_locations, + const std::vector<std::string>& oat_filenames, + const std::vector<std::string>& image_filenames) { DCHECK_GT(oat_filenames.size(), 1u); // If the image filename was adapted (e.g., for our tests), we need to change this here, // too, but need to strip all path components (they will be re-established when loading). diff --git a/runtime/gc/space/image_space.h b/runtime/gc/space/image_space.h index b940d88de8..aa45ed3952 100644 --- a/runtime/gc/space/image_space.h +++ b/runtime/gc/space/image_space.h @@ -128,9 +128,9 @@ class ImageSpace : public MemMapSpace { const std::string& boot_classpath, std::vector<std::string>* image_filenames); - static std::string GetMultiImageBootClassPath(const std::vector<const char*>& dex_locations, - const std::vector<const char*>& oat_filenames, - const std::vector<const char*>& image_filenames); + static std::string GetMultiImageBootClassPath(const std::vector<std::string>& dex_locations, + const std::vector<std::string>& oat_filenames, + const std::vector<std::string>& image_filenames); // Returns true if the dex checksums in the given oat file match the // checksums of the original dex files on disk. This is intended to be used |