// A class so we can be friends with ClassLinker and access internal methods. class VMClassLoader { public: static ObjPtr<mirror::Class> LookupClass(ClassLinker* cl,
Thread* self,
std::string_view descriptor,
size_t hash,
ObjPtr<mirror::ClassLoader> class_loader)
REQUIRES(!Locks::classlinker_classes_lock_)
REQUIRES_SHARED(Locks::mutator_lock_) { return cl->LookupClass(self, descriptor, hash, class_loader);
}
ObjPtr<mirror::Class> c = VMClassLoader::LookupClass(cl,
soa.Self(),
descriptor,
descriptor_hash,
loader); if (c != nullptr && c->IsResolved()) { return soa.AddLocalReference<jclass>(c);
} // If class is erroneous, throw the earlier failure, wrapped in certain cases. See b/28787733. if (c != nullptr && c->IsErroneous()) {
cl->ThrowEarlierClassFailure(c);
Thread* self = soa.Self();
ObjPtr<mirror::Class> exception_class = self->GetException()->GetClass(); if (exception_class == WellKnownClasses::java_lang_IllegalAccessError ||
exception_class == WellKnownClasses::java_lang_NoClassDefFoundError) {
self->ThrowNewWrappedException("Ljava/lang/ClassNotFoundException;",
c->PrettyDescriptor().c_str());
} return nullptr;
}
// Hard-coded performance optimization: We know that all failed libcore calls to findLoadedClass // are followed by a call to the the classloader to actually // load the class. if (loader != nullptr) { // Try the common case.
StackHandleScope<1> hs(soa.Self());
c = VMClassLoader::FindClassInPathClassLoader(cl,
soa.Self(),
descriptor.c_str(),
descriptor.length(),
descriptor_hash,
hs.NewHandle(loader)); if (c != nullptr) { return soa.AddLocalReference<jclass>(c);
}
}
// The class wasn't loaded, yet, and our fast-path did not apply (e.g., we didn't understand the // classloader chain). return nullptr;
}
const DexFile* last_dex_file = nullptr; auto dchecked_is_base_dex = [&](const DexFile* dex_file) { // For multidex locations, e.g., x.jar!classes2.dex, we want to look into x.jar. // But we do not need to look into the base dex file more than once so we filter // out multidex locations using the fact that they follow the base location. if (kIsDebugBuild) { if (is_base_dex(dex_file)) {
CHECK_EQ(DexFileLoader::GetBaseLocation(dex_file->GetLocation().c_str()),
dex_file->GetLocation());
} else {
CHECK(last_dex_file != nullptr);
CHECK_EQ(DexFileLoader::GetBaseLocation(dex_file->GetLocation().c_str()),
DexFileLoader::GetBaseLocation(last_dex_file->GetLocation().c_str()));
}
last_dex_file = dex_file;
} return is_base_dex(dex_file);
}; auto get_location = [](const DexFile* dex_file) { return dex_file->GetLocation(); };
ScopedObjectAccess soa(Thread::ForEnv(env)); return soa.AddLocalReference<jobjectArray>(CreateStringArray(
soa.Self(),
jar_count,
MakeTransformRange(Filter(path, dchecked_is_base_dex), get_location)));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.