From ab0ed82ff64ba5a751dcc0a38d0e0c41c53dc923 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 11 Sep 2014 14:21:41 -0700 Subject: Add fast path to VMClassLoader.findLoadedClass VMClassLoader.findLoadedClass now calls FindClassInPathClassLoader as a fast path. Exclusive time results (trace view maps launch): Before: nativeFillInStackTrace 1.4% defineClassNative 1.2% findLoadedClass 0.2% After: nativeFillInStackTrace 0.5% defineClassNative 0.0% findLoadedClass 0.9% (cherry picked from commit 194116c836080de14245a3a7c4617d07b8abf8cf) Change-Id: I63fd7b4bccb71789e92bd39d1d3f9d0de22535de --- runtime/native/java_lang_VMClassLoader.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'runtime/native/java_lang_VMClassLoader.cc') diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc index fefddae761..761e8009e3 100644 --- a/runtime/native/java_lang_VMClassLoader.cc +++ b/runtime/native/java_lang_VMClassLoader.cc @@ -31,16 +31,23 @@ static jclass VMClassLoader_findLoadedClass(JNIEnv* env, jclass, jobject javaLoa if (name.c_str() == NULL) { return NULL; } - + ClassLinker* cl = Runtime::Current()->GetClassLinker(); std::string descriptor(DotToDescriptor(name.c_str())); - mirror::Class* c = Runtime::Current()->GetClassLinker()->LookupClass(descriptor.c_str(), loader); + mirror::Class* c = cl->LookupClass(descriptor.c_str(), loader); if (c != NULL && c->IsResolved()) { return soa.AddLocalReference(c); - } else { - // Class wasn't resolved so it may be erroneous or not yet ready, force the caller to go into - // the regular loadClass code. - return NULL; } + if (loader != nullptr) { + // Try the common case. + StackHandleScope<1> hs(soa.Self()); + c = cl->FindClassInPathClassLoader(soa, soa.Self(), descriptor.c_str(), hs.NewHandle(loader)); + if (c != nullptr) { + return soa.AddLocalReference(c); + } + } + // Class wasn't resolved so it may be erroneous or not yet ready, force the caller to go into + // the regular loadClass code. + return NULL; } static jint VMClassLoader_getBootClassPathSize(JNIEnv*, jclass) { -- cgit v1.2.3-59-g8ed1b