OSDN Git Service

Disable LZ4HC compressed images
authorMathieu Chartier <mathieuc@google.com>
Fri, 18 Mar 2016 02:19:15 +0000 (19:19 -0700)
committerMathieu Chartier <mathieuc@google.com>
Mon, 21 Mar 2016 19:38:05 +0000 (12:38 -0700)
Seem to get randomly compressed incorrectly on volantis. Added
verifiation in the image writer.

Using LZ4HC now silently uses LZ4. This is still safe since both use
the same decompression code.

Bug: 27560444

(cherry picked from commit 9894fc8079a5c6eb72e04099bdbd3239b75cf491)

Change-Id: Ic0d78f419884d7ef2e29948835c942fbb68e66da

compiler/image_writer.cc
runtime/class_linker.cc

index 0b69810..07bd0e3 100644 (file)
@@ -229,6 +229,7 @@ bool ImageWriter::Write(int image_fd,
 
     CHECK_EQ(image_header->storage_mode_, image_storage_mode_);
     switch (image_storage_mode_) {
+      case ImageHeader::kStorageModeLZ4HC:  // Fall-through.
       case ImageHeader::kStorageModeLZ4: {
         const size_t compressed_max_size = LZ4_compressBound(image_data_size);
         compressed_data.reset(new char[compressed_max_size]);
@@ -239,6 +240,8 @@ bool ImageWriter::Write(int image_fd,
 
         break;
       }
+      /*
+       * Disabled due to image_test64 flakyness. Both use same decompression. b/27560444
       case ImageHeader::kStorageModeLZ4HC: {
         // Bound is same as non HC.
         const size_t compressed_max_size = LZ4_compressBound(image_data_size);
@@ -249,6 +252,7 @@ bool ImageWriter::Write(int image_fd,
             image_data_size);
         break;
       }
+      */
       case ImageHeader::kStorageModeUncompressed: {
         data_size = image_data_size;
         image_data_to_write = image_data;
@@ -264,6 +268,16 @@ bool ImageWriter::Write(int image_fd,
       image_data_to_write = &compressed_data[0];
       VLOG(compiler) << "Compressed from " << image_data_size << " to " << data_size << " in "
                      << PrettyDuration(NanoTime() - compress_start_time);
+      if (kIsDebugBuild) {
+        std::unique_ptr<uint8_t[]> temp(new uint8_t[image_data_size]);
+        const size_t decompressed_size = LZ4_decompress_safe(
+            reinterpret_cast<char*>(&compressed_data[0]),
+            reinterpret_cast<char*>(&temp[0]),
+            data_size,
+            image_data_size);
+        CHECK_EQ(decompressed_size, image_data_size);
+        CHECK_EQ(memcmp(image_data, &temp[0], image_data_size), 0) << image_storage_mode_;
+      }
     }
 
     // Write out the image + fields + methods.
@@ -2024,7 +2038,6 @@ void ImageWriter::CopyAndFixupMethod(ArtMethod* orig,
   memcpy(copy, orig, ArtMethod::Size(target_ptr_size_));
 
   copy->SetDeclaringClass(GetImageAddress(orig->GetDeclaringClassUnchecked()));
-
   ArtMethod** orig_resolved_methods = orig->GetDexCacheResolvedMethods(target_ptr_size_);
   copy->SetDexCacheResolvedMethods(NativeLocationInImage(orig_resolved_methods), target_ptr_size_);
   GcRoot<mirror::Class>* orig_resolved_types = orig->GetDexCacheResolvedTypes(target_ptr_size_);
index ada6e5c..f5482c5 100644 (file)
@@ -761,7 +761,8 @@ static void SanityCheckArtMethod(ArtMethod* m,
                                  const std::vector<gc::space::ImageSpace*>& spaces)
     SHARED_REQUIRES(Locks::mutator_lock_) {
   if (m->IsRuntimeMethod()) {
-    CHECK(m->GetDeclaringClass() == nullptr) << PrettyMethod(m);
+    mirror::Class* declaring_class = m->GetDeclaringClassUnchecked();
+    CHECK(declaring_class == nullptr) << declaring_class << " " << PrettyMethod(m);
   } else if (m->IsCopied()) {
     CHECK(m->GetDeclaringClass() != nullptr) << PrettyMethod(m);
   } else if (expected_class != nullptr) {