ART: Do not reopen oat file in ImageWriter::UpdateOatFile().
Instead, pass the already opened file from Dex2Oat.
Bug: 26831001
Change-Id: I2341259499067f43ce620b590c5482d28f140e9f
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index 6abc6fa..8b7fbf6 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -2274,12 +2274,11 @@
return GetConstImageInfo(oat_filenames_[index]);
}
-void ImageWriter::UpdateOatFile(const char* oat_filename) {
- std::unique_ptr<File> oat_file(OS::OpenFileForReading(oat_filename));
+void ImageWriter::UpdateOatFile(File* oat_file, const char* oat_filename) {
DCHECK(oat_file != nullptr);
size_t oat_loaded_size = 0;
size_t oat_data_offset = 0;
- ElfWriter::GetOatElfInformation(oat_file.get(), &oat_loaded_size, &oat_data_offset);
+ ElfWriter::GetOatElfInformation(oat_file, &oat_loaded_size, &oat_data_offset);
ImageInfo& cur_image_info = GetImageInfo(oat_filename);
diff --git a/compiler/image_writer.h b/compiler/image_writer.h
index 622eb19..9371d9f 100644
--- a/compiler/image_writer.h
+++ b/compiler/image_writer.h
@@ -123,7 +123,7 @@
// Update the oat size for the given oat file. This will make the oat_offset for the next oat
// file valid.
- void UpdateOatFile(const char* oat_filename);
+ void UpdateOatFile(File* oat_file, const char* oat_filename);
private:
bool AllocMemory();
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index f56fc38..4871648 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1709,7 +1709,10 @@
if (IsImage()) {
// Update oat estimates.
- UpdateImageWriter(i);
+ DCHECK(image_writer_ != nullptr);
+ DCHECK_LT(i, oat_filenames_.size());
+
+ image_writer_->UpdateOatFile(oat_file.get(), oat_filenames_[i]);
}
VLOG(compiler) << "Oat file written successfully: " << oat_filenames_[i];
@@ -2351,14 +2354,6 @@
return res.substr(0, penultimate_slash) + res.substr(last_slash);
}
- // Update the estimate for the oat file with the given index.
- void UpdateImageWriter(size_t index) {
- DCHECK(image_writer_ != nullptr);
- DCHECK_LT(index, oat_filenames_.size());
-
- image_writer_->UpdateOatFile(oat_filenames_[index]);
- }
-
std::unique_ptr<CompilerOptions> compiler_options_;
Compiler::Kind compiler_kind_;