summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2016-11-02 14:31:27 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2016-11-02 14:31:28 +0000
commit77a0e4541a29c26dba21ed8c1ed1c29ef8d0ce4c (patch)
treeb5d34c3e68a931ae3ee735718c3ba0296643f9a5
parentc65310326ea87008776bd64ed3bb530d8da644c3 (diff)
parent7d8d8ff0727a7aa9d11c738f13a7e06d3c4c3d68 (diff)
Merge "Revert "Revert "ART: Generalize FindClassInPathClassLoader"""
-rw-r--r--runtime/class_linker.cc34
-rw-r--r--runtime/class_linker.h16
-rw-r--r--runtime/native/java_lang_VMClassLoader.cc2
-rw-r--r--runtime/well_known_classes.cc2
-rw-r--r--runtime/well_known_classes.h1
5 files changed, 34 insertions, 21 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 73524af0be..d3d30d4cea 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2329,12 +2329,12 @@ ClassPathEntry FindInClassPath(const char* descriptor,
return ClassPathEntry(nullptr, nullptr);
}
-bool ClassLinker::FindClassInPathClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
- Thread* self,
- const char* descriptor,
- size_t hash,
- Handle<mirror::ClassLoader> class_loader,
- ObjPtr<mirror::Class>* result) {
+bool ClassLinker::FindClassInBaseDexClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
+ Thread* self,
+ const char* descriptor,
+ size_t hash,
+ Handle<mirror::ClassLoader> class_loader,
+ ObjPtr<mirror::Class>* result) {
// Termination case: boot class-loader.
if (IsBootClassLoader(soa, class_loader.Get())) {
// The boot class loader, search the boot class path.
@@ -2364,14 +2364,24 @@ bool ClassLinker::FindClassInPathClassLoader(ScopedObjectAccessAlreadyRunnable&
// Unsupported class-loader?
if (soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_PathClassLoader) !=
class_loader->GetClass()) {
- *result = nullptr;
- return false;
+ // PathClassLoader is the most common case, so it's the one we check first. For secondary dex
+ // files, we also check DexClassLoader here.
+ if (soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_DexClassLoader) !=
+ class_loader->GetClass()) {
+ *result = nullptr;
+ return false;
+ }
}
// Handles as RegisterDexFile may allocate dex caches (and cause thread suspension).
StackHandleScope<4> hs(self);
Handle<mirror::ClassLoader> h_parent(hs.NewHandle(class_loader->GetParent()));
- bool recursive_result = FindClassInPathClassLoader(soa, self, descriptor, hash, h_parent, result);
+ bool recursive_result = FindClassInBaseDexClassLoader(soa,
+ self,
+ descriptor,
+ hash,
+ h_parent,
+ result);
if (!recursive_result) {
// Something wrong up the chain.
@@ -2493,14 +2503,14 @@ mirror::Class* ClassLinker::FindClass(Thread* self,
} else {
ScopedObjectAccessUnchecked soa(self);
ObjPtr<mirror::Class> cp_klass;
- if (FindClassInPathClassLoader(soa, self, descriptor, hash, class_loader, &cp_klass)) {
+ if (FindClassInBaseDexClassLoader(soa, self, descriptor, hash, class_loader, &cp_klass)) {
// The chain was understood. So the value in cp_klass is either the class we were looking
// for, or not found.
if (cp_klass != nullptr) {
return cp_klass.Ptr();
}
- // TODO: We handle the boot classpath loader in FindClassInPathClassLoader. Try to unify this
- // and the branch above. TODO: throw the right exception here.
+ // TODO: We handle the boot classpath loader in FindClassInBaseDexClassLoader. Try to unify
+ // this and the branch above. TODO: throw the right exception here.
// We'll let the Java-side rediscover all this and throw the exception with the right stack
// trace.
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 3248d0e3d9..4426056078 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -794,17 +794,17 @@ class ClassLinker {
void FixupStaticTrampolines(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
- // Finds a class in the path class loader, loading it if necessary without using JNI. Hash
+ // Finds a class in a Path- or DexClassLoader, loading it if necessary without using JNI. Hash
// function is supposed to be ComputeModifiedUtf8Hash(descriptor). Returns true if the
// class-loader chain could be handled, false otherwise, i.e., a non-supported class-loader
// was encountered while walking the parent chain (currently only BootClassLoader and
// PathClassLoader are supported).
- bool FindClassInPathClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
- Thread* self,
- const char* descriptor,
- size_t hash,
- Handle<mirror::ClassLoader> class_loader,
- ObjPtr<mirror::Class>* result)
+ bool FindClassInBaseDexClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
+ Thread* self,
+ const char* descriptor,
+ size_t hash,
+ Handle<mirror::ClassLoader> class_loader,
+ ObjPtr<mirror::Class>* result)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!dex_lock_);
@@ -1200,7 +1200,7 @@ class ClassLinker {
friend struct CompilationHelper; // For Compile in ImageTest.
friend class ImageDumper; // for DexLock
friend class ImageWriter; // for GetClassRoots
- friend class VMClassLoader; // for LookupClass and FindClassInPathClassLoader.
+ friend class VMClassLoader; // for LookupClass and FindClassInBaseDexClassLoader.
friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub
friend class JniInternalTest; // for GetRuntimeQuickGenericJniStub
ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for DexLock, and RegisterDexFileLocked
diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc
index e5bab36870..284d2d10c5 100644
--- a/runtime/native/java_lang_VMClassLoader.cc
+++ b/runtime/native/java_lang_VMClassLoader.cc
@@ -48,7 +48,7 @@ class VMClassLoader {
Handle<mirror::ClassLoader> class_loader)
REQUIRES_SHARED(Locks::mutator_lock_) {
ObjPtr<mirror::Class> result;
- if (cl->FindClassInPathClassLoader(soa, self, descriptor, hash, class_loader, &result)) {
+ if (cl->FindClassInBaseDexClassLoader(soa, self, descriptor, hash, class_loader, &result)) {
return result;
}
return nullptr;
diff --git a/runtime/well_known_classes.cc b/runtime/well_known_classes.cc
index 0f4ae521ec..2797d8570c 100644
--- a/runtime/well_known_classes.cc
+++ b/runtime/well_known_classes.cc
@@ -35,6 +35,7 @@ jclass WellKnownClasses::com_android_dex_Dex;
jclass WellKnownClasses::dalvik_annotation_optimization_CriticalNative;
jclass WellKnownClasses::dalvik_annotation_optimization_FastNative;
jclass WellKnownClasses::dalvik_system_BaseDexClassLoader;
+jclass WellKnownClasses::dalvik_system_DexClassLoader;
jclass WellKnownClasses::dalvik_system_DexFile;
jclass WellKnownClasses::dalvik_system_DexPathList;
jclass WellKnownClasses::dalvik_system_DexPathList__Element;
@@ -266,6 +267,7 @@ void WellKnownClasses::Init(JNIEnv* env) {
CacheClass(env, "dalvik/annotation/optimization/CriticalNative");
dalvik_annotation_optimization_FastNative = CacheClass(env, "dalvik/annotation/optimization/FastNative");
dalvik_system_BaseDexClassLoader = CacheClass(env, "dalvik/system/BaseDexClassLoader");
+ dalvik_system_DexClassLoader = CacheClass(env, "dalvik/system/DexClassLoader");
dalvik_system_DexFile = CacheClass(env, "dalvik/system/DexFile");
dalvik_system_DexPathList = CacheClass(env, "dalvik/system/DexPathList");
dalvik_system_DexPathList__Element = CacheClass(env, "dalvik/system/DexPathList$Element");
diff --git a/runtime/well_known_classes.h b/runtime/well_known_classes.h
index d07977a493..227996ad99 100644
--- a/runtime/well_known_classes.h
+++ b/runtime/well_known_classes.h
@@ -48,6 +48,7 @@ struct WellKnownClasses {
static jclass dalvik_annotation_optimization_CriticalNative;
static jclass dalvik_annotation_optimization_FastNative;
static jclass dalvik_system_BaseDexClassLoader;
+ static jclass dalvik_system_DexClassLoader;
static jclass dalvik_system_DexFile;
static jclass dalvik_system_DexPathList;
static jclass dalvik_system_DexPathList__Element;