Disable LZ4HC compressed images

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

Change-Id: I652eee7498dc84994993be3a5b0447ec5b246304
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index 0b69810..07bd0e3 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -229,6 +229,7 @@
 
     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 @@
 
         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 @@
             image_data_size);
         break;
       }
+      */
       case ImageHeader::kStorageModeUncompressed: {
         data_size = image_data_size;
         image_data_to_write = image_data;
@@ -264,6 +268,16 @@
       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 @@
   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_);
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index d8e309d..271b7c9 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -760,7 +760,8 @@
                                  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) {