From d37d364c27e74a7b49970a8c970482e273aa7b1a Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 19 Nov 2015 16:05:58 -0800 Subject: Create parent class loader for dex2oat This means we also put the class loader in the app image so that it can be used for verifying the dex file order. Bug: 22858531 Change-Id: I30761b59421c8a24cffd62b469134b25d2929e2e --- runtime/class_linker.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'runtime/class_linker.cc') diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index d5a5ea6797..2dd2a83888 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -6629,7 +6629,9 @@ bool ClassLinker::MayBeCalledWithDirectCodePointer(ArtMethod* m) { } } -jobject ClassLinker::CreatePathClassLoader(Thread* self, std::vector& dex_files) { +jobject ClassLinker::CreatePathClassLoader(Thread* self, + std::vector& dex_files, + jobject parent_loader) { // SOAAlreadyRunnable is protected, and we need something to add a global reference. // We could move the jobject to the callers, but all call-sites do this... ScopedObjectAccessUnchecked soa(self); @@ -6660,8 +6662,8 @@ jobject ClassLinker::CreatePathClassLoader(Thread* self, std::vector hs2(self); - // CreatePathClassLoader is only used by gtests. Index 0 of h_long_array is supposed to be the - // oat file but we can leave it null. + // CreatePathClassLoader is only used by gtests and dex2oat. Index 0 of h_long_array is + // supposed to be the oat file but we can leave it null. Handle h_long_array = hs2.NewHandle(mirror::LongArray::Alloc( self, kDexFileIndexStart + 1)); @@ -6707,9 +6709,10 @@ jobject ClassLinker::CreatePathClassLoader(Thread* self, std::vectorGetClass()), "parent", "Ljava/lang/ClassLoader;"); DCHECK(parent_field != nullptr); - mirror::Object* boot_cl = - soa.Decode(WellKnownClasses::java_lang_BootClassLoader)->AllocObject(self); - parent_field->SetObject(h_path_class_loader.Get(), boot_cl); + mirror::Object* parent = (parent_loader != nullptr) + ? soa.Decode(parent_loader) + : soa.Decode(WellKnownClasses::java_lang_BootClassLoader)->AllocObject(self); + parent_field->SetObject(h_path_class_loader.Get(), parent); // Make it a global ref and return. ScopedLocalRef local_ref( -- cgit v1.2.3-59-g8ed1b