From: Neil Fuller Date: Wed, 3 Jun 2015 15:46:29 +0000 (+0000) Subject: Revert "Modification to the way boot classpath resources are loaded" X-Git-Tag: android-x86-7.1-r1~889^2~1085^2~1 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1e27c5bd372fbe55c46127c8f233a13d9994334c;p=android-x86%2Fart.git Revert "Modification to the way boot classpath resources are loaded" This reverts commit 0e08b767f1bd0b892e3ac5724d517caae70f5c04. Change-Id: Ie3d3caec98f5a65759bb6d44c1f8c76dc6aa2afa --- diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc index 15156301c..0c39f2b53 100644 --- a/runtime/native/java_lang_VMClassLoader.cc +++ b/runtime/native/java_lang_VMClassLoader.cc @@ -55,29 +55,60 @@ static jclass VMClassLoader_findLoadedClass(JNIEnv* env, jclass, jobject javaLoa return nullptr; } +static jint VMClassLoader_getBootClassPathSize(JNIEnv*, jclass) { + return Runtime::Current()->GetClassLinker()->GetBootClassPath().size(); +} + /* - * Returns an array of entries from the boot classpath that could contain resources. + * Returns a string URL for a resource with the specified 'javaName' in + * entry 'index' of the boot class path. + * + * We return a newly-allocated String in the following form: + * + * jar:file://path!/name + * + * Where "path" is the bootstrap class path entry and "name" is the string + * passed into this method. "path" needs to be an absolute path (starting + * with '/'); if it's not we'd need to make it absolute as part of forming + * the URL string. */ -static jobjectArray VMClassLoader_getBootClassPathEntries(JNIEnv* env, jclass) { +static jstring VMClassLoader_getBootClassPathResource(JNIEnv* env, jclass, jstring javaName, + jint index) { + ScopedUtfChars name(env, javaName); + if (name.c_str() == nullptr) { + return nullptr; + } + const std::vector& path = Runtime::Current()->GetClassLinker()->GetBootClassPath(); - jclass stringClass = env->FindClass("java/lang/String"); - jobjectArray array = env->NewObjectArray(path.size(), stringClass, nullptr); - for (size_t i = 0; i < path.size(); ++i) { - const DexFile* dex_file = path[i]; + if (index < 0 || size_t(index) >= path.size()) { + return nullptr; + } + const DexFile* dex_file = path[index]; - // For multidex locations, e.g., x.jar:classes2.dex, we want to look into x.jar. - const std::string& location(dex_file->GetBaseLocation()); + // For multidex locations, e.g., x.jar:classes2.dex, we want to look into x.jar. + const std::string& location(dex_file->GetBaseLocation()); - jstring javaPath = env->NewStringUTF(location.c_str()); - env->SetObjectArrayElement(array, i, javaPath); + std::string error_msg; + std::unique_ptr zip_archive(ZipArchive::Open(location.c_str(), &error_msg)); + if (zip_archive.get() == nullptr) { + LOG(WARNING) << "Failed to open zip archive '" << location << "': " << error_msg; + return nullptr; + } + std::unique_ptr zip_entry(zip_archive->Find(name.c_str(), &error_msg)); + if (zip_entry.get() == nullptr) { + return nullptr; } - return array; + + std::string url; + StringAppendF(&url, "jar:file://%s!/%s", location.c_str(), name.c_str()); + return env->NewStringUTF(url.c_str()); } static JNINativeMethod gMethods[] = { NATIVE_METHOD(VMClassLoader, findLoadedClass, "!(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;"), - NATIVE_METHOD(VMClassLoader, getBootClassPathEntries, "()[Ljava/lang/String;"), + NATIVE_METHOD(VMClassLoader, getBootClassPathResource, "(Ljava/lang/String;I)Ljava/lang/String;"), + NATIVE_METHOD(VMClassLoader, getBootClassPathSize, "!()I"), }; void register_java_lang_VMClassLoader(JNIEnv* env) {