OSDN Git Service

Use null error_msg for pic images
authorMathieu Chartier <mathieuc@google.com>
Sat, 11 Feb 2017 02:41:39 +0000 (18:41 -0800)
committerMathieu Chartier <mathieuc@google.com>
Sat, 11 Feb 2017 02:42:21 +0000 (18:42 -0800)
Reduces 20ms of overhead for reading proc maps when the map can't be
placed at the optimal address.

Bug: 34927277

Test: test-art-host && device boot

Change-Id: Ib91fff2b832f61c49e67edcd2b7a222ab4409984

runtime/gc/space/image_space.cc
runtime/mem_map.cc

index ffbca52..fe1c8e8 100644 (file)
@@ -587,15 +587,18 @@ class ImageSpaceLoader {
     }
 
     std::unique_ptr<MemMap> map;
+
     // GetImageBegin is the preferred address to map the image. If we manage to map the
     // image at the image begin, the amount of fixup work required is minimized.
+    // If it is pic we will retry with error_msg for the failure case. Pass a null error_msg to
+    // avoid reading proc maps for a mapping failure and slowing everything down.
     map.reset(LoadImageFile(image_filename,
                             image_location,
                             *image_header,
                             image_header->GetImageBegin(),
                             file->Fd(),
                             logger,
-                            error_msg));
+                            image_header->IsPic() ? nullptr : error_msg));
     // If the header specifies PIC mode, we can also map at a random low_4gb address since we can
     // relocate in-place.
     if (map == nullptr && image_header->IsPic()) {
@@ -765,8 +768,10 @@ class ImageSpaceLoader {
 
     if (storage_mode != ImageHeader::kStorageModeLZ4 &&
         storage_mode != ImageHeader::kStorageModeLZ4HC) {
-      *error_msg = StringPrintf("Invalid storage mode in image header %d",
-                                static_cast<int>(storage_mode));
+      if (error_msg != nullptr) {
+        *error_msg = StringPrintf("Invalid storage mode in image header %d",
+                                  static_cast<int>(storage_mode));
+      }
       return nullptr;
     }
 
@@ -790,7 +795,7 @@ class ImageSpaceLoader {
                                                        image_filename,
                                                        error_msg));
       if (temp_map == nullptr) {
-        DCHECK(!error_msg->empty());
+        DCHECK(error_msg == nullptr || !error_msg->empty());
         return nullptr;
       }
       memcpy(map->Begin(), &image_header, sizeof(ImageHeader));
@@ -804,10 +809,12 @@ class ImageSpaceLoader {
           map->Size() - decompress_offset);
       VLOG(image) << "Decompressing image took " << PrettyDuration(NanoTime() - start);
       if (decompressed_size + sizeof(ImageHeader) != image_header.GetImageSize()) {
-        *error_msg = StringPrintf(
-            "Decompressed size does not match expected image size %zu vs %zu",
-            decompressed_size + sizeof(ImageHeader),
-            image_header.GetImageSize());
+        if (error_msg != nullptr) {
+          *error_msg = StringPrintf(
+              "Decompressed size does not match expected image size %zu vs %zu",
+              decompressed_size + sizeof(ImageHeader),
+              image_header.GetImageSize());
+        }
         return nullptr;
       }
     }
index dce56b3..93c212b 100644 (file)
@@ -400,7 +400,7 @@ MemMap* MemMap::MapFileAtAddress(uint8_t* expected_ptr,
     // reuse means it is okay that it overlaps an existing page mapping.
     // Only use this if you actually made the page reservation yourself.
     CHECK(expected_ptr != nullptr);
-
+    DCHECK(error_msg != nullptr);
     DCHECK(ContainedWithinExistingMap(expected_ptr, byte_count, error_msg))
         << ((error_msg != nullptr) ? *error_msg : std::string());
     flags |= MAP_FIXED;