Allow compilation of classes in different ClassLoaders

Change-Id: Ib0420471590a4c6d16bc25285ef3876098eacb36
diff --git a/build/Android.test.mk b/build/Android.test.mk
index d940a1d..3429041 100644
--- a/build/Android.test.mk
+++ b/build/Android.test.mk
@@ -63,8 +63,6 @@
   LOCAL_MODULE := art-test-dex-$(1)
   LOCAL_MODULE_TAGS := optional
   LOCAL_SRC_FILES := $(call all-java-files-under, test/$(1))
-  # TODO: remove --core-library when separate compilation works
-  LOCAL_DX_FLAGS := --core-library
   include $(BUILD_JAVA_LIBRARY)
   ART_TEST_DEX_FILES += $(TARGET_OUT_JAVA_LIBRARIES)/$$(LOCAL_MODULE).jar
 endef
diff --git a/src/class_linker.cc b/src/class_linker.cc
index a42ab72..e03eca6 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -489,7 +489,9 @@
     if (descriptor[0] == '[') {
       return CreateArrayClass(descriptor, class_loader);
     }
-    const DexFile::ClassPath& class_path = ((class_loader != NULL) ? class_loader->GetClassPath() : boot_class_path_);
+    const DexFile::ClassPath& class_path = ((class_loader != NULL)
+                                            ? ClassLoader::GetClassPath(class_loader)
+                                            : boot_class_path_);
     DexFile::ClassPathEntry pair = DexFile::FindInClassPath(descriptor, class_path);
     if (pair.second == NULL) {
       std::string name(PrintableString(descriptor));
diff --git a/src/class_linker.h b/src/class_linker.h
index b62433c..6e13aa7 100644
--- a/src/class_linker.h
+++ b/src/class_linker.h
@@ -117,6 +117,10 @@
   void RegisterDexFile(const DexFile& dex_file);
   void RegisterDexFile(const DexFile& dex_file, DexCache* dex_cache);
 
+  const std::vector<const DexFile*>& GetBootClassPath() {
+    return boot_class_path_;
+  }
+
   const InternTable& GetInternTable() {
     return intern_table_;
   }
diff --git a/src/class_linker_test.cc b/src/class_linker_test.cc
index 201db45..48408c8 100644
--- a/src/class_linker_test.cc
+++ b/src/class_linker_test.cc
@@ -58,7 +58,7 @@
   void AssertArrayClass(const StringPiece& array_descriptor,
                         int32_t array_rank,
                         const StringPiece& component_type,
-                        ClassLoader* class_loader) {
+                        const ClassLoader* class_loader) {
     Class* array = class_linker_->FindClass(array_descriptor, class_loader);
     EXPECT_EQ(array_rank, array->array_rank_);
     EXPECT_TRUE(array->GetComponentType()->GetDescriptor()->Equals(component_type));
@@ -274,7 +274,7 @@
 
 TEST_F(ClassLinkerTest, FindClassNested) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("Nested"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
 
   Class* outer = class_linker_->FindClass("LNested;", class_loader);
   ASSERT_TRUE(outer != NULL);
@@ -329,7 +329,7 @@
   EXPECT_EQ(0U, JavaLangObject->NumInterfaces());
 
   scoped_ptr<const DexFile> dex(OpenTestDexFile("MyClass"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   AssertNonExistentClass("LMyClass;");
   Class* MyClass = class_linker_->FindClass("LMyClass;", class_loader);
   ASSERT_TRUE(MyClass != NULL);
@@ -453,8 +453,8 @@
 TEST_F(ClassLinkerTest, TwoClassLoadersOneClass) {
   scoped_ptr<const DexFile> dex_1(OpenTestDexFile("MyClass"));
   scoped_ptr<const DexFile> dex_2(OpenTestDexFile("MyClass"));
-  PathClassLoader* class_loader_1 = AllocPathClassLoader(dex_1.get());
-  PathClassLoader* class_loader_2 = AllocPathClassLoader(dex_2.get());
+  const PathClassLoader* class_loader_1 = AllocPathClassLoader(dex_1.get());
+  const PathClassLoader* class_loader_2 = AllocPathClassLoader(dex_2.get());
   Class* MyClass_1 = class_linker_->FindClass("LMyClass;", class_loader_1);
   Class* MyClass_2 = class_linker_->FindClass("LMyClass;", class_loader_2);
   EXPECT_TRUE(MyClass_1 != NULL);
@@ -465,7 +465,7 @@
 TEST_F(ClassLinkerTest, StaticFields) {
   // TODO: uncomment expectations of initial values when InitializeClass works
   scoped_ptr<const DexFile> dex(OpenTestDexFile("Statics"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   Class* statics = class_linker_->FindClass("LStatics;", class_loader);
   class_linker_->EnsureInitialized(statics);
 
@@ -535,7 +535,7 @@
 
 TEST_F(ClassLinkerTest, Interfaces) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("Interfaces"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   Class* I = class_linker_->FindClass("LInterfaces$I;", class_loader);
   Class* J = class_linker_->FindClass("LInterfaces$J;", class_loader);
   Class* A = class_linker_->FindClass("LInterfaces$A;", class_loader);
diff --git a/src/common_test.h b/src/common_test.h
index aa9229e..afe0c0f 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -148,7 +148,7 @@
     return DexFile::OpenZip(libcore_dex_file_name);
   }
 
-  PathClassLoader* AllocPathClassLoader(const DexFile* dex_file) {
+  const PathClassLoader* AllocPathClassLoader(const DexFile* dex_file) {
     CHECK(dex_file != NULL);
     class_linker_->RegisterDexFile(*dex_file);
     std::vector<const DexFile*> dex_files;
diff --git a/src/compiler.cc b/src/compiler.cc
index 7644444..37f8298 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -12,17 +12,23 @@
 namespace art {
 
 // TODO need to specify target
-const ClassLoader* Compiler::Compile(std::vector<const DexFile*> class_path) {
-  const ClassLoader* class_loader = PathClassLoader::Alloc(class_path);
+void Compiler::CompileAll(const ClassLoader* class_loader) {
   Resolve(class_loader);
   // TODO add verification step
   Compile(class_loader);
   SetCodeAndDirectMethods(class_loader);
-  return class_loader;
+}
+
+void Compiler::CompileOne(Method* method) {
+  const ClassLoader* class_loader = method->GetDeclaringClass()->GetClassLoader();
+  Resolve(class_loader);
+  // TODO add verification step
+  CompileMethod(method);
+  SetCodeAndDirectMethods(class_loader);
 }
 
 void Compiler::Resolve(const ClassLoader* class_loader) {
-  const std::vector<const DexFile*>& class_path = class_loader->GetClassPath();
+  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);
@@ -60,7 +66,7 @@
 }
 
 void Compiler::Compile(const ClassLoader* class_loader) {
-  const std::vector<const DexFile*>& class_path = class_loader->GetClassPath();
+  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);
@@ -105,15 +111,15 @@
 }
 
 void Compiler::SetCodeAndDirectMethods(const ClassLoader* class_loader) {
-  const std::vector<const DexFile*>& class_path = class_loader->GetClassPath();
+  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);
-    SetCodeAndDirectMethodsDexFile(class_loader, *dex_file);
+    SetCodeAndDirectMethodsDexFile(*dex_file);
   }
 }
 
-void Compiler::SetCodeAndDirectMethodsDexFile(const ClassLoader* class_loader, const DexFile& dex_file) {
+void Compiler::SetCodeAndDirectMethodsDexFile(const DexFile& dex_file) {
   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
   DexCache* dex_cache = class_linker->FindDexCache(dex_file);
   CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods();
diff --git a/src/compiler.h b/src/compiler.h
index fde7a37..1214d3c 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -10,10 +10,11 @@
 
 class Compiler {
  public:
-  // Compile the DexFiles on a classpath. Returns a ClassLoader for
-  // the path used by the classes that were compiled. This ClassLoader
-  // can be used with FindClass to lookup a compiled class by name.
-  const ClassLoader* Compile(std::vector<const DexFile*> class_path);
+  // Compile all Methods of all the Classes of all the DexFiles that are part of a ClassLoader.
+  void CompileAll(const ClassLoader* class_loader);
+
+  // Compile a single Method
+  void CompileOne(Method* method);
 
  private:
   // Attempt to resolve all type, methods, fields, and strings
@@ -30,7 +31,7 @@
   // After compiling, walk all the DexCaches and set the code and
   // method pointers of CodeAndDirectMethods entries in the DexCaches.
   void SetCodeAndDirectMethods(const ClassLoader* class_loader);
-  void SetCodeAndDirectMethodsDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
+  void SetCodeAndDirectMethodsDexFile(const DexFile& dex_file);
 };
 
 }  // namespace art
diff --git a/src/compiler_test.cc b/src/compiler_test.cc
index 124668e..229235a 100644
--- a/src/compiler_test.cc
+++ b/src/compiler_test.cc
@@ -16,23 +16,76 @@
 
 class CompilerTest : public CommonTest {
  protected:
-  void CompileDex(const char* name) {
-    dex_file_.reset(OpenTestDexFile(name));
+
+  const ClassLoader* LoadDex(const char* dex_name) {
+    dex_file_.reset(OpenTestDexFile(dex_name));
     class_linker_->RegisterDexFile(*dex_file_.get());
     std::vector<const DexFile*> class_path;
     class_path.push_back(dex_file_.get());
-    Compiler compiler;
-    const ClassLoader* class_loader = compiler.Compile(class_path);
+    const ClassLoader* class_loader = PathClassLoader::Alloc(class_path);
     Thread::Current()->SetClassLoaderOverride(class_loader);
+    return class_loader;
   }
 
-  void AssertStaticIntMethod(const char* klass, const char* method, const char* signature,
+
+  void CompileDex(const char* dex_name) {
+    Compile(LoadDex(dex_name));
+  }
+
+  void CompileSystem() {
+    Compile(NULL);
+  }
+
+  void Compile(const ClassLoader* class_loader) {
+    Compiler compiler;
+    compiler.CompileAll(NULL);
+  }
+
+  std::string ConvertClassNameToClassDescriptor(const char* class_name) {
+    std::string desc;
+    desc += "L";
+    desc += class_name;
+    desc += ";";
+    std::replace(desc.begin(), desc.end(), '.', '/');
+    return desc;
+  }
+
+
+  void CompileDirectMethod(const ClassLoader* class_loader,
+                           const char* class_name,
+                           const char* method_name,
+                           const char* signature) {
+    std::string class_descriptor = ConvertClassNameToClassDescriptor(class_name);
+    Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
+    CHECK(klass != NULL) << "Class not found " << class_name;
+    Method* method = klass->FindDirectMethod(method_name, signature);
+    CHECK(method != NULL) << "Method not found " << method_name;
+    Compiler compiler;
+    compiler.CompileOne(method);
+  }
+
+  void CompileVirtualMethod(const ClassLoader* class_loader,
+                            const char* class_name,
+                            const char* method_name,
+                            const char* signature) {
+    std::string class_descriptor = ConvertClassNameToClassDescriptor(class_name);
+    Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
+    CHECK(klass != NULL) << "Class not found " << class_name;
+    Method* method = klass->FindVirtualMethod(method_name, signature);
+    CHECK(method != NULL) << "Method not found " << method_name;
+    Compiler compiler;
+    compiler.CompileOne(method);
+  }
+
+  void AssertStaticIntMethod(const ClassLoader* class_loader,
+                             const char* klass, const char* method, const char* signature,
                              jint expected, ...) {
+    CompileDirectMethod(class_loader, klass, method, signature);
     JNIEnv* env = Thread::Current()->GetJniEnv();
     jclass c = env->FindClass(klass);
-    CHECK(c != NULL);
+    CHECK(c != NULL) << "Class not found " << klass;
     jmethodID m = env->GetStaticMethodID(c, method, signature);
-    CHECK(m != NULL);
+    CHECK(m != NULL) << "Method not found " << method;
 #if defined(__arm__)
     va_list args;
     va_start(args, expected);
@@ -42,13 +95,15 @@
     EXPECT_EQ(expected, result);
 #endif // __arm__
   }
-  void AssertStaticLongMethod(const char* klass, const char* method,
-                              const char* signature, jlong expected, ...) {
+  void AssertStaticLongMethod(const ClassLoader* class_loader,
+                              const char* klass, const char* method, const char* signature,
+                              jlong expected, ...) {
+    CompileDirectMethod(class_loader, klass, method, signature);
     JNIEnv* env = Thread::Current()->GetJniEnv();
     jclass c = env->FindClass(klass);
-    CHECK(c != NULL);
+    CHECK(c != NULL) << "Class not found " << klass;
     jmethodID m = env->GetStaticMethodID(c, method, signature);
-    CHECK(m != NULL);
+    CHECK(m != NULL) << "Method not found " << method;
 #if defined(__arm__)
     va_list args;
     va_start(args, expected);
@@ -62,13 +117,10 @@
   scoped_ptr<const DexFile> dex_file_;
 };
 
-TEST_F(CompilerTest, CompileDexLibCore) {
-  // TODO renenable when compiler can handle libcore
-  if (true) {
-    return;
-  }
+// TODO renenable when compiler can handle libcore
+TEST_F(CompilerTest, DISABLED_CompileDexLibCore) {
   Compiler compiler;
-  compiler.Compile(boot_class_path_);
+  compiler.CompileAll(NULL);
 
   // All libcore references should resolve
   const DexFile* dex = java_lang_dex_file_.get();
@@ -108,132 +160,110 @@
 }
 
 TEST_F(CompilerTest, BasicCodegen) {
-  CompileDex("Fibonacci");
-  AssertStaticIntMethod("Fibonacci", "fibonacci", "(I)I", 55,
+  AssertStaticIntMethod(LoadDex("Fibonacci"), "Fibonacci", "fibonacci", "(I)I", 55,
                         10);
 }
 
 TEST_F(CompilerTest, StaticFieldTest) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "staticFieldTest", "(I)I", 1404,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "staticFieldTest", "(I)I", 1404,
                         404);
 }
 
 TEST_F(CompilerTest, UnopTest) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "unopTest", "(I)I", 37,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unopTest", "(I)I", 37,
                         38);
 }
 
 TEST_F(CompilerTest, ShiftTest1) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "shiftTest1", "()I", 0);
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest1", "()I", 0);
 }
 
 TEST_F(CompilerTest, ShiftTest2) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "shiftTest2", "()I", 0);
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest2", "()I", 0);
 }
 
 TEST_F(CompilerTest, UnsignedShiftTest) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "unsignedShiftTest", "()I", 0);
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unsignedShiftTest", "()I", 0);
 }
 
 TEST_F(CompilerTest, ConvTest) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "convTest", "()I", 0);
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "convTest", "()I", 0);
 }
 
 TEST_F(CompilerTest, CharSubTest) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "charSubTest", "()I", 0);
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "charSubTest", "()I", 0);
 }
 
 TEST_F(CompilerTest, IntOperTest) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "intOperTest", "(II)I", 0,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intOperTest", "(II)I", 0,
                         70000, -3);
 }
 
 TEST_F(CompilerTest, Lit16Test) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "lit16Test", "(I)I", 0,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit16Test", "(I)I", 0,
                         77777);
 }
 
 TEST_F(CompilerTest, Lit8Test) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "lit8Test", "(I)I", 0,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit8Test", "(I)I", 0,
                         -55555);
 }
 
 TEST_F(CompilerTest, IntShiftTest) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "intShiftTest", "(II)I", 0,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intShiftTest", "(II)I", 0,
                         0xff00aa01, 8);
 }
 
 TEST_F(CompilerTest, LongOperTest) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "longOperTest", "(JJ)I", 0,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "longOperTest", "(JJ)I", 0,
                         70000000000LL, -3LL);
 }
 
 TEST_F(CompilerTest, LongShiftTest) {
-  CompileDex("IntMath");
-  AssertStaticLongMethod("IntMath", "longShiftTest", "(JI)J",
+  AssertStaticLongMethod(LoadDex("IntMath"), "IntMath", "longShiftTest", "(JI)J",
                          0x96deff00aa010000LL, 0xd5aa96deff00aa01LL, 16);
 }
 
 TEST_F(CompilerTest, SwitchTest1) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "switchTest", "(I)I", 1234,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "switchTest", "(I)I", 1234,
                         1);
 }
 
 TEST_F(CompilerTest, IntCompare) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "testIntCompare", "(IIII)I", 1111,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testIntCompare", "(IIII)I", 1111,
                         -5, 4, 4, 0);
 }
 
 TEST_F(CompilerTest, LongCompare) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "testLongCompare", "(JJJJ)I", 2222,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testLongCompare", "(JJJJ)I", 2222,
                         -5LL, -4294967287LL, 4LL, 8LL);
 }
 
 TEST_F(CompilerTest, FloatCompare) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "testFloatCompare", "(FFFF)I", 3333,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testFloatCompare", "(FFFF)I", 3333,
                         -5.0f, 4.0f, 4.0f,
                         (1.0f/0.0f) / (1.0f/0.0f));
 }
 
 TEST_F(CompilerTest, DoubleCompare) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "testDoubleCompare", "(DDDD)I", 4444,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testDoubleCompare", "(DDDD)I", 4444,
                                     -5.0, 4.0, 4.0,
                                     (1.0/0.0) / (1.0/0.0));
 }
 
 TEST_F(CompilerTest, RecursiveFibonacci) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "fibonacci", "(I)I", 55,
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "fibonacci", "(I)I", 55,
                         10);
 }
 
 #if 0 // Need to complete try/catch block handling
 TEST_F(CompilerTest, ThrowAndCatch) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "throwAndCatch", "()I", 4);
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "throwAndCatch", "()I", 4);
 }
 #endif
 
 TEST_F(CompilerTest, ManyArgs) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "manyArgs",
+  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "manyArgs",
                         "(IJIJIJIIDFDSICIIBZIIJJIIIII)I", -1,
                         0, 1LL, 2, 3LL, 4, 5LL, 6, 7, 8.0, 9.0f, 10.0,
                         (short)11, 12, (char)13, 14, 15, (int8_t)-16, true, 18,
@@ -241,14 +271,22 @@
 }
 
 TEST_F(CompilerTest, VirtualCall) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "staticCall", "(I)I", 6,
+  CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
+  const ClassLoader* class_loader = LoadDex("IntMath");
+  CompileDirectMethod(class_loader, "IntMath", "<init>", "()V");
+  CompileVirtualMethod(class_loader, "IntMath", "virtualCall", "(I)I");
+  AssertStaticIntMethod(class_loader, "IntMath", "staticCall", "(I)I", 6,
                         3);
 }
 
 TEST_F(CompilerTest, TestIGetPut) {
-  CompileDex("IntMath");
-  AssertStaticIntMethod("IntMath", "testIGetPut", "(I)I", 333,
+  CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
+  const ClassLoader* class_loader = LoadDex("IntMath");
+  CompileDirectMethod(class_loader, "IntMath", "<init>", "(I)V");
+  CompileDirectMethod(class_loader, "IntMath", "<init>", "()V");
+  CompileVirtualMethod(class_loader, "IntMath", "getFoo", "()I");
+  CompileVirtualMethod(class_loader, "IntMath", "setFoo", "(I)V");
+  AssertStaticIntMethod(class_loader, "IntMath", "testIGetPut", "(I)I", 333,
                         111);
 }
 
diff --git a/src/dex_cache.h b/src/dex_cache.h
index 0d217bc..137f267 100644
--- a/src/dex_cache.h
+++ b/src/dex_cache.h
@@ -26,7 +26,7 @@
   }
 
   void SetResolvedDirectMethodTrampoline(uint32_t method_idx) {
-    UNIMPLEMENTED(FATAL) << "need to install a trampoline to resolve the method_idx at runtime";
+    UNIMPLEMENTED(WARNING) << "need to install a trampoline to resolve the method_idx at runtime";
     Set(method_idx * kMax + kCode,   0xffffffff);
     Set(method_idx * kMax + kMethod, method_idx);
   }
diff --git a/src/dex_verifier_test.cc b/src/dex_verifier_test.cc
index a9da38fe..20a3157 100644
--- a/src/dex_verifier_test.cc
+++ b/src/dex_verifier_test.cc
@@ -39,7 +39,7 @@
 
 TEST_F(DexVerifierTest, IntMath) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("IntMath"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   Class* klass = class_linker_->FindClass("LIntMath;", class_loader);
   ASSERT_TRUE(DexVerify::VerifyClass(klass));
 }
diff --git a/src/exception_test.cc b/src/exception_test.cc
index cc5e3e0..c384bc1 100644
--- a/src/exception_test.cc
+++ b/src/exception_test.cc
@@ -67,7 +67,7 @@
 
     dex_.reset(OpenDexFileBase64(kMyClassExceptionHandleDex, "kMyClassExceptionHandleDex"));
     ASSERT_TRUE(dex_ != NULL);
-    PathClassLoader* class_loader = AllocPathClassLoader(dex_.get());
+    const PathClassLoader* class_loader = AllocPathClassLoader(dex_.get());
     ASSERT_TRUE(class_loader != NULL);
     my_klass_ = class_linker_->FindClass("Ljava/lang/MyClass;", class_loader);
     ASSERT_TRUE(my_klass_ != NULL);
diff --git a/src/jni_compiler_test.cc b/src/jni_compiler_test.cc
index 4cd32e8..016a606 100644
--- a/src/jni_compiler_test.cc
+++ b/src/jni_compiler_test.cc
@@ -66,7 +66,7 @@
   static jobject jobj_;
  protected:
   scoped_ptr<const DexFile> dex_;
-  PathClassLoader* class_loader_;
+  const PathClassLoader* class_loader_;
   Assembler jni_asm;
   JniCompiler jni_compiler;
   JNIEnv* env_;
diff --git a/src/jni_internal_test.cc b/src/jni_internal_test.cc
index a71975b..fa98dd8 100644
--- a/src/jni_internal_test.cc
+++ b/src/jni_internal_test.cc
@@ -638,7 +638,7 @@
 
 TEST_F(JniInternalTest, GetPrimitiveField_SetPrimitiveField) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("AllFields"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   Thread::Current()->SetClassLoaderOverride(class_loader);
 
   jclass c = env_->FindClass("AllFields");
@@ -667,7 +667,7 @@
 
 TEST_F(JniInternalTest, GetObjectField_SetObjectField) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("AllFields"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   Thread::Current()->SetClassLoaderOverride(class_loader);
 
   jclass c = env_->FindClass("AllFields");
@@ -830,7 +830,7 @@
 TEST_F(JniInternalTest, StaticMainMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("Main"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LMain;", class_loader);
@@ -856,7 +856,7 @@
 TEST_F(JniInternalTest, StaticNopMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -881,7 +881,7 @@
 TEST_F(JniInternalTest, StaticIdentityByteMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -927,7 +927,7 @@
 TEST_F(JniInternalTest, StaticIdentityIntMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -973,7 +973,7 @@
 TEST_F(JniInternalTest, StaticIdentityDoubleMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -1020,7 +1020,7 @@
 TEST_F(JniInternalTest, StaticSumIntIntMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -1078,7 +1078,7 @@
 TEST_F(JniInternalTest, StaticSumIntIntIntMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -1143,7 +1143,7 @@
 TEST_F(JniInternalTest, StaticSumIntIntIntIntMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -1214,7 +1214,7 @@
 TEST_F(JniInternalTest, StaticSumIntIntIntIntIntMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -1292,7 +1292,7 @@
 TEST_F(JniInternalTest, StaticSumDoubleDoubleMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -1351,7 +1351,7 @@
 TEST_F(JniInternalTest, StaticSumDoubleDoubleDoubleMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -1403,7 +1403,7 @@
 TEST_F(JniInternalTest, StaticSumDoubleDoubleDoubleDoubleMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
@@ -1460,7 +1460,7 @@
 TEST_F(JniInternalTest, StaticSumDoubleDoubleDoubleDoubleDoubleMethod) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("StaticLeafMethods"));
 
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   ASSERT_TRUE(class_loader != NULL);
 
   Class* klass = class_linker_->FindClass("LStaticLeafMethods;", class_loader);
diff --git a/src/object.cc b/src/object.cc
index 9bb1cb7..66ea03f 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -14,6 +14,13 @@
 
 namespace art {
 
+const std::vector<const DexFile*>& ClassLoader::GetClassPath(const ClassLoader* class_loader) {
+  if (class_loader == NULL) {
+    return Runtime::Current()->GetClassLinker()->GetBootClassPath();
+  }
+  return class_loader->class_path_;
+}
+
 Array* Array::Alloc(Class* array_class, int32_t component_count, size_t component_size) {
   DCHECK_GE(component_count, 0);
   DCHECK(array_class->IsArrayClass());
@@ -671,7 +678,7 @@
 // TODO: get global references for these
 Class* PathClassLoader::dalvik_system_PathClassLoader_ = NULL;
 
-PathClassLoader* PathClassLoader::Alloc(std::vector<const DexFile*> dex_files) {
+const PathClassLoader* PathClassLoader::Alloc(std::vector<const DexFile*> dex_files) {
   PathClassLoader* p = down_cast<PathClassLoader*>(dalvik_system_PathClassLoader_->NewInstance());
   p->SetClassPath(dex_files);
   return p;
diff --git a/src/object.h b/src/object.h
index 1df10ad..2d07bd5 100644
--- a/src/object.h
+++ b/src/object.h
@@ -872,9 +872,8 @@
 // ClassLoader objects.
 class ClassLoader : public Object {
  public:
-  const std::vector<const DexFile*>& GetClassPath() const {
-    return class_path_;
-  }
+  static const std::vector<const DexFile*>& GetClassPath(const ClassLoader* class_loader);
+
   void SetClassPath(std::vector<const DexFile*>& class_path) {
     DCHECK_EQ(0U, class_path_.size());
     class_path_ = class_path;
@@ -901,7 +900,7 @@
 
 class PathClassLoader : public BaseDexClassLoader {
  public:
-  static PathClassLoader* Alloc(std::vector<const DexFile*> dex_files);
+  static const PathClassLoader* Alloc(std::vector<const DexFile*> dex_files);
   static void SetClass(Class* dalvik_system_PathClassLoader);
   static void ResetClass();
  private:
diff --git a/src/object_test.cc b/src/object_test.cc
index a862f71..1967ea7 100644
--- a/src/object_test.cc
+++ b/src/object_test.cc
@@ -275,9 +275,9 @@
   ClassLinker* linker = class_linker_;
 
   scoped_ptr<const DexFile> proto1_dex_file(OpenTestDexFile("ProtoCompare"));
-  PathClassLoader* class_loader_1 = AllocPathClassLoader(proto1_dex_file.get());
+  const PathClassLoader* class_loader_1 = AllocPathClassLoader(proto1_dex_file.get());
   scoped_ptr<const DexFile> proto2_dex_file(OpenTestDexFile("ProtoCompare2"));
-  PathClassLoader* class_loader_2 = AllocPathClassLoader(proto2_dex_file.get());
+  const PathClassLoader* class_loader_2 = AllocPathClassLoader(proto2_dex_file.get());
 
   Class* klass1 = linker->FindClass("LProtoCompare;", class_loader_1);
   ASSERT_TRUE(klass1 != NULL);
@@ -324,7 +324,7 @@
 
 TEST_F(ObjectTest, InstanceOf) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("XandY"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   Class* X = class_linker_->FindClass("LX;", class_loader);
   Class* Y = class_linker_->FindClass("LY;", class_loader);
   ASSERT_TRUE(X != NULL);
@@ -351,7 +351,7 @@
 
 TEST_F(ObjectTest, IsAssignableFrom) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("XandY"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   Class* X = class_linker_->FindClass("LX;", class_loader);
   Class* Y = class_linker_->FindClass("LY;", class_loader);
 
@@ -363,7 +363,7 @@
 
 TEST_F(ObjectTest, IsAssignableFromArray) {
   scoped_ptr<const DexFile> dex(OpenTestDexFile("XandY"));
-  PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
+  const PathClassLoader* class_loader = AllocPathClassLoader(dex.get());
   Class* X = class_linker_->FindClass("LX;", class_loader);
   Class* Y = class_linker_->FindClass("LY;", class_loader);
   ASSERT_TRUE(X != NULL);
diff --git a/test/IntMath/java/lang/Object.java b/test/IntMath/java/lang/Object.java
deleted file mode 100644
index 67e54e3..0000000
--- a/test/IntMath/java/lang/Object.java
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-
-// TODO: remove this when separate compilation works
-package java.lang;
-public class Object {}