OSDN Git Service

Clean up UpdateOatFile for app images
authorMathieu Chartier <mathieuc@google.com>
Fri, 29 Jan 2016 04:33:36 +0000 (20:33 -0800)
committerMathieu Chartier <mathieuc@google.com>
Sat, 30 Jan 2016 00:09:23 +0000 (16:09 -0800)
Check that for the there is only one oat file name for the app image
case.

Avoid calling GetOatElfInformation unless necessary.

Bug: 22858531
Change-Id: I88d258a1cc2823956ecc4fca9a6f7b2d3c4b986e

compiler/image_writer.cc

index 8b7fbf6..60dfcfb 100644 (file)
@@ -2276,10 +2276,10 @@ const ImageWriter::ImageInfo& ImageWriter::GetImageInfo(size_t index) const {
 
 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, &oat_loaded_size, &oat_data_offset);
-
+  if (compile_app_image_) {
+    CHECK_EQ(oat_filenames_.size(), 1u) << "App image should have no next image.";
+    return;
+  }
   ImageInfo& cur_image_info = GetImageInfo(oat_filename);
 
   // Update the oat_offset of the next image info.
@@ -2288,6 +2288,9 @@ void ImageWriter::UpdateOatFile(File* oat_file, const char* oat_filename) {
 
   it++;
   if (it != oat_filenames_.end()) {
+    size_t oat_loaded_size = 0;
+    size_t oat_data_offset = 0;
+    ElfWriter::GetOatElfInformation(oat_file, &oat_loaded_size, &oat_data_offset);
     // There is a following one.
     ImageInfo& next_image_info = GetImageInfo(*it);
     next_image_info.oat_offset_ = cur_image_info.oat_offset_ + oat_loaded_size;