提交 759956ab 编写于 作者: M mchung

6864003: Modify JVM_FindClassFromBootLoader to return null if class not found

Summary: JVM_FindClassFromBootLoader returns null if class not found
Reviewed-by: acorn, alanb, dholmes
上级 b355f668
...@@ -638,32 +638,10 @@ JVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls)) ...@@ -638,32 +638,10 @@ JVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls))
if (PrintJVMWarnings) warning("JVM_ResolveClass not implemented"); if (PrintJVMWarnings) warning("JVM_ResolveClass not implemented");
JVM_END JVM_END
// Common implementation for JVM_FindClassFromBootLoader and
// JVM_FindClassFromLoader
static jclass jvm_find_class_from_class_loader(JNIEnv* env, const char* name,
jboolean init, jobject loader,
jboolean throwError, TRAPS) {
// Java libraries should ensure that name is never null...
if (name == NULL || (int)strlen(name) > symbolOopDesc::max_length()) {
// It's impossible to create this class; the name cannot fit
// into the constant pool.
if (throwError) {
THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
} else {
THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name);
}
}
symbolHandle h_name = oopFactory::new_symbol_handle(name, CHECK_NULL);
Handle h_loader(THREAD, JNIHandles::resolve(loader));
jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
Handle(), throwError, THREAD);
if (TraceClassResolution && result != NULL) {
trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result)));
}
return result;
}
// Returns a class loaded by the bootstrap class loader; or null
// if not found. ClassNotFoundException is not thrown.
//
// Rationale behind JVM_FindClassFromBootLoader // Rationale behind JVM_FindClassFromBootLoader
// a> JVM_FindClassFromClassLoader was never exported in the export tables. // a> JVM_FindClassFromClassLoader was never exported in the export tables.
// b> because of (a) java.dll has a direct dependecy on the unexported // b> because of (a) java.dll has a direct dependecy on the unexported
...@@ -681,12 +659,26 @@ static jclass jvm_find_class_from_class_loader(JNIEnv* env, const char* name, ...@@ -681,12 +659,26 @@ static jclass jvm_find_class_from_class_loader(JNIEnv* env, const char* name,
// to the JDK, and is not intended to be a public API. // to the JDK, and is not intended to be a public API.
JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env, JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env,
const char* name, const char* name))
jboolean throwError)) JVMWrapper2("JVM_FindClassFromBootLoader %s", name);
JVMWrapper3("JVM_FindClassFromBootLoader %s throw %s", name,
throwError ? "error" : "exception"); // Java libraries should ensure that name is never null...
return jvm_find_class_from_class_loader(env, name, JNI_FALSE, if (name == NULL || (int)strlen(name) > symbolOopDesc::max_length()) {
(jobject)NULL, throwError, THREAD); // It's impossible to create this class; the name cannot fit
// into the constant pool.
return NULL;
}
symbolHandle h_name = oopFactory::new_symbol_handle(name, CHECK_NULL);
klassOop k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL);
if (k == NULL) {
return NULL;
}
if (TraceClassResolution) {
trace_class_resolution(k);
}
return (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
JVM_END JVM_END
JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name,
...@@ -694,8 +686,25 @@ JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, ...@@ -694,8 +686,25 @@ JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name,
jboolean throwError)) jboolean throwError))
JVMWrapper3("JVM_FindClassFromClassLoader %s throw %s", name, JVMWrapper3("JVM_FindClassFromClassLoader %s throw %s", name,
throwError ? "error" : "exception"); throwError ? "error" : "exception");
return jvm_find_class_from_class_loader(env, name, init, loader, // Java libraries should ensure that name is never null...
throwError, THREAD); if (name == NULL || (int)strlen(name) > symbolOopDesc::max_length()) {
// It's impossible to create this class; the name cannot fit
// into the constant pool.
if (throwError) {
THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
} else {
THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name);
}
}
symbolHandle h_name = oopFactory::new_symbol_handle(name, CHECK_NULL);
Handle h_loader(THREAD, JNIHandles::resolve(loader));
jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
Handle(), throwError, THREAD);
if (TraceClassResolution && result != NULL) {
trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result)));
}
return result;
JVM_END JVM_END
...@@ -3919,6 +3928,7 @@ jclass find_class_from_class_loader(JNIEnv* env, symbolHandle name, jboolean ini ...@@ -3919,6 +3928,7 @@ jclass find_class_from_class_loader(JNIEnv* env, symbolHandle name, jboolean ini
// The Java level wrapper will perform the necessary security check allowing // The Java level wrapper will perform the necessary security check allowing
// us to pass the NULL as the initiating class loader. // us to pass the NULL as the initiating class loader.
klassOop klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL); klassOop klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
KlassHandle klass_handle(THREAD, klass); KlassHandle klass_handle(THREAD, klass);
// Check if we should initialize the class // Check if we should initialize the class
if (init && klass_handle->oop_is_instance()) { if (init && klass_handle->oop_is_instance()) {
......
...@@ -390,15 +390,10 @@ JVM_FindClassFromClassLoader(JNIEnv *env, const char *name, jboolean init, ...@@ -390,15 +390,10 @@ JVM_FindClassFromClassLoader(JNIEnv *env, const char *name, jboolean init,
jobject loader, jboolean throwError); jobject loader, jboolean throwError);
/* /*
* Find a class from a boot class loader. Throw ClassNotFoundException * Find a class from a boot class loader. Returns NULL if class not found.
* or NoClassDefFoundError depending on the value of the last
* argument. This is the same as FindClassFromClassLoader but provided
* as a convenience method exported correctly on all platforms for
* JSR 277 launcher class loading.
*/ */
JNIEXPORT jclass JNICALL JNIEXPORT jclass JNICALL
JVM_FindClassFromBootLoader(JNIEnv *env, const char *name, JVM_FindClassFromBootLoader(JNIEnv *env, const char *name);
jboolean throwError);
/* /*
* Find a class from a given class. * Find a class from a given class.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册