Enable kSupportBootImageFixup

Change-Id: I57b338b3d985e2de96a6fb99327fc274406e3844
diff --git a/src/common_test.h b/src/common_test.h
index d8832f6..a3e530b 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -350,7 +350,7 @@
       }
     }
     class_linker_->FixupDexCaches(runtime_->GetResolutionMethod());
-    compiler_.reset(new Compiler(instruction_set, false, 2, false, NULL));
+    compiler_.reset(new Compiler(instruction_set, true, 2, false, new std::set<std::string>));
 #if defined(ART_USE_LLVM_COMPILER)
     compiler_->SetElfFileName("gtest");
 #endif
diff --git a/src/compiler.cc b/src/compiler.cc
index f066b0a..ce34f0f 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -716,13 +716,15 @@
   stats_->DirectMethodsToBoot(type);
   bool compiling_boot = Runtime::Current()->GetHeap()->GetSpaces().size() == 1;
   if (compiling_boot) {
-    const bool kSupportBootImageFixup = false;
+    const bool kSupportBootImageFixup = true;
     if (kSupportBootImageFixup) {
       MethodHelper mh(method);
       if (IsImageClass(mh.GetDeclaringClassDescriptor())) {
+        // We can only branch directly to Methods that are resolved in the DexCache.
+        // Otherwise we won't invoke the resolution trampoline.
         direct_method = -1;
+        direct_code = -1;
       }
-      direct_code = -1;
     }
   } else {
     if (Runtime::Current()->GetHeap()->GetImageSpace()->Contains(method)) {
diff --git a/src/image_writer.cc b/src/image_writer.cc
index fdee834..2d3ae44 100644
--- a/src/image_writer.cc
+++ b/src/image_writer.cc
@@ -542,6 +542,12 @@
                                                patch->GetReferrerIsDirect());
   CHECK(method != NULL)
     << patch->GetDexFile().GetLocation() << " " << patch->GetReferrerMethodIdx();
+  CHECK(!method->IsRuntimeMethod())
+    << patch->GetDexFile().GetLocation() << " " << patch->GetReferrerMethodIdx();
+  CHECK(patch->GetDexCache()->GetResolvedMethods()->Get(patch->GetReferrerMethodIdx()) == method)
+    << patch->GetDexFile().GetLocation() << " " << patch->GetReferrerMethodIdx() << " "
+    << PrettyMethod(patch->GetDexCache()->GetResolvedMethods()->Get(patch->GetReferrerMethodIdx())) << " "
+    << PrettyMethod(method);
   return method;
 }
 
@@ -554,6 +560,12 @@
                                                patch->GetTargetIsDirect());
   CHECK(method != NULL)
     << patch->GetDexFile().GetLocation() << " " << patch->GetTargetMethodIdx();
+  CHECK(!method->IsRuntimeMethod())
+    << patch->GetDexFile().GetLocation() << " " << patch->GetTargetMethodIdx();
+  CHECK(patch->GetDexCache()->GetResolvedMethods()->Get(patch->GetTargetMethodIdx()) == method)
+    << patch->GetDexFile().GetLocation() << " " << patch->GetReferrerMethodIdx() << " "
+    << PrettyMethod(patch->GetDexCache()->GetResolvedMethods()->Get(patch->GetTargetMethodIdx())) << " "
+    << PrettyMethod(method);
   return method;
 }