Add DexCache table of <Method*, Method::GetCode()>

Change-Id: I69d46e61ff40456ff76888ad90b00e2036250d40
diff --git a/src/compiler.cc b/src/compiler.cc
index 57edf53..d1605a7 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -15,11 +15,9 @@
 const ClassLoader* Compiler::Compile(std::vector<const DexFile*> class_path) {
   const ClassLoader* class_loader = PathClassLoader::Alloc(class_path);
   Resolve(class_loader);
-  for (size_t i = 0; i != class_path.size(); ++i) {
-    const DexFile* dex_file = class_path[i];
-    CHECK(dex_file != NULL);
-    CompileDexFile(class_loader, *dex_file);
-  }
+  // TODO add verification step
+  Compile(class_loader);
+  SetCodeAndMethod(class_loader);
   return class_loader;
 }
 
@@ -61,6 +59,15 @@
   }
 }
 
+void Compiler::Compile(const ClassLoader* class_loader) {
+  const std::vector<const DexFile*>& class_path = class_loader->GetClassPath();
+  for (size_t i = 0; i != class_path.size(); ++i) {
+    const DexFile* dex_file = class_path[i];
+    CHECK(dex_file != NULL);
+    CompileDexFile(class_loader, *dex_file);
+  }
+}
+
 void Compiler::CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file) {
   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
   for (size_t i = 0; i < dex_file.NumClassDefs(); i++) {
@@ -97,4 +104,25 @@
   // CHECK(method->HasCode());  // TODO: enable this check ASAP
 }
 
+void Compiler::SetCodeAndMethod(const ClassLoader* class_loader) {
+  const std::vector<const DexFile*>& class_path = class_loader->GetClassPath();
+  for (size_t i = 0; i != class_path.size(); ++i) {
+    const DexFile* dex_file = class_path[i];
+    CHECK(dex_file != NULL);
+    SetCodeAndMethodDexFile(class_loader, *dex_file);
+  }
+}
+
+void Compiler::SetCodeAndMethodDexFile(const ClassLoader* class_loader, const DexFile& dex_file) {
+  ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+  DexCache* dex_cache = class_linker->FindDexCache(dex_file);
+  CodeAndMethods* code_and_methods = dex_cache->GetCodeAndMethods();
+  for (size_t i = 0; i < dex_cache->NumMethods(); i++) {
+    Method* method = dex_cache->GetResolvedMethod(i);
+    if (method != NULL) {
+      code_and_methods->SetResolvedMethod(i, method);
+    }
+  }
+}
+
 }  // namespace art