Enabled verification in the compiler and some other verifier fixes.

The verifier still needs to be able to continue execution after it fails
to resolve a class or method. The structure for that doesn't exist yet.

Change-Id: Ie32f6f9971fed02b645ba715bc5164f86f70f1c6
diff --git a/src/compiler.cc b/src/compiler.cc
index 8a382f5..528a0b2 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -42,7 +42,7 @@
 
 void Compiler::CompileAll(const ClassLoader* class_loader) {
   Resolve(class_loader);
-  // TODO: add verification step
+  Verify(class_loader);
 
   // TODO: mark all verified classes initialized if they have no <clinit>
   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
@@ -58,7 +58,7 @@
 void Compiler::CompileOne(Method* method) {
   const ClassLoader* class_loader = method->GetDeclaringClass()->GetClassLoader();
   Resolve(class_loader);
-  // TODO: add verification step
+  Verify(class_loader);
   CompileMethod(method);
   SetCodeAndDirectMethods(class_loader);
 }
@@ -101,6 +101,26 @@
   }
 }
 
+void Compiler::Verify(const ClassLoader* class_loader) {
+  const std::vector<const DexFile*>& class_path = ClassLoader::GetClassPath(class_loader);
+  for (size_t i = 0; i != class_path.size(); ++i) {
+    const DexFile* dex_file = class_path[i];
+    CHECK(dex_file != NULL);
+    VerifyDexFile(class_loader, *dex_file);
+  }
+}
+
+void Compiler::VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file) {
+  ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+  for (size_t i = 0; i < dex_file.NumClassDefs(); i++) {
+    const DexFile::ClassDef& class_def = dex_file.GetClassDef(i);
+    const char* descriptor = dex_file.GetClassDescriptor(class_def);
+    Class* klass = class_linker->FindClass(descriptor, class_loader);
+    CHECK(klass != NULL);
+    class_linker->VerifyClass(klass);
+  }
+}
+
 void Compiler::Compile(const ClassLoader* class_loader) {
   const std::vector<const DexFile*>& class_path = ClassLoader::GetClassPath(class_loader);
   for (size_t i = 0; i != class_path.size(); ++i) {