Fix to prevent a dex file from being verified multiple times.

Instead of verifying a dex file whenever one is initialized, they're now
verified when not opened from memory. Also, the way dalvik_system_DexFile
opens dex files has been changed to check for an existing oat file and
get the corresponding dex file from there instead.

Change-Id: I75fc26247150107d628e2c4e364ef8a53fbf9481
diff --git a/src/dalvik_system_DexFile.cc b/src/dalvik_system_DexFile.cc
index dd91eac..67cb49b 100644
--- a/src/dalvik_system_DexFile.cc
+++ b/src/dalvik_system_DexFile.cc
@@ -90,7 +90,10 @@
   }
   const DexFile* dex_file;
   if (outputName.c_str() == NULL) {
-    dex_file = DexFile::Open(sourceName.c_str(), "");
+    dex_file = Runtime::Current()->GetClassLinker()->FindDexFileFromDexLocation(sourceName.c_str());
+    if (dex_file == NULL) {
+      dex_file = DexFile::Open(sourceName.c_str(), "");
+    }
   } else {
     // Sanity check the arguments.
     if (!IsValidZipFilename(sourceName.c_str()) || !IsValidDexFilename(outputName.c_str())) {
@@ -233,20 +236,8 @@
     }
   }
 
-  UniquePtr<const DexFile> dex_file(DexFile::Open(filename.c_str(), ""));
-  if (dex_file.get() == NULL) {
-    return JNI_TRUE;
-  }
-
-  const OatFile* oat_file = class_linker->FindOatFileForDexFile(*dex_file.get());
-  if (oat_file == NULL) {
-    return JNI_TRUE;
-  }
-  const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_file->GetLocation());
-  if (oat_dex_file == NULL) {
-    return JNI_TRUE;
-  }
-  if (oat_dex_file->GetDexFileChecksum() != dex_file->GetHeader().checksum_) {
+  const DexFile* dex_file = class_linker->FindDexFileFromDexLocation(filename.c_str());
+  if (dex_file == NULL) {
     return JNI_TRUE;
   }
   return JNI_FALSE;