Add image dependency to oat files

Change-Id: I945356f71357f1aa0092f4fe6c57eccfb029b4a6
diff --git a/src/dalvik_system_DexFile.cc b/src/dalvik_system_DexFile.cc
index 2b86b76..2539c92 100644
--- a/src/dalvik_system_DexFile.cc
+++ b/src/dalvik_system_DexFile.cc
@@ -19,9 +19,11 @@
 #include "class_loader.h"
 #include "class_linker.h"
 #include "dex_file.h"
+#include "image.h"
 #include "logging.h"
 #include "os.h"
 #include "runtime.h"
+#include "space.h"
 #include "zip_archive.h"
 #include "toStringArray.h"
 #include "ScopedLocalRef.h"
@@ -179,7 +181,8 @@
 
   // Always treat elements of the bootclasspath as up-to-date.  The
   // fact that code is running at all means that this should be true.
-  ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+  Runtime* runtime = Runtime::Current();
+  ClassLinker* class_linker = runtime->GetClassLinker();
   const std::vector<const DexFile*>& boot_class_path = class_linker->GetBootClassPath();
   for (size_t i = 0; i < boot_class_path.size(); i++) {
     if (boot_class_path[i]->GetLocation() == filename.c_str()) {
@@ -211,6 +214,14 @@
     return JNI_TRUE;
   }
 
+  const ImageHeader& image_header = runtime->GetHeap()->GetImageSpace()->GetImageHeader();
+  if (oat_file->GetOatHeader().GetImageFileLocationChecksum() != image_header.GetOatChecksum()) {
+    LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location
+              << " has out-of-date checksum compared to "
+              << image_header.GetImageRoot(ImageHeader::kOatLocation)->AsString()->ToModifiedUtf8();
+    return JNI_TRUE;
+  }
+
   const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(filename.c_str());
   if (oat_dex_file == NULL) {
     LOG(ERROR) << "DexFile_isDexOptNeeded cache file " << cache_location