mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
8233091: Backout JDK-8212117: Class.forName loads a class but not linked if class is not initialized
Reviewed-by: alanb, dholmes, mchung
This commit is contained in:
parent
691e75e223
commit
3561b4ed50
13 changed files with 14 additions and 340 deletions
|
@ -742,17 +742,6 @@ JVM_END
|
|||
// Misc. class handling ///////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
JVM_ENTRY(void, JVM_LinkClass(JNIEnv* env, jclass classClass, jclass arg))
|
||||
JVMWrapper("JVM_LinkClass");
|
||||
|
||||
oop r = JNIHandles::resolve(arg);
|
||||
Klass* klass = java_lang_Class::as_Klass(r);
|
||||
|
||||
if (!ClassForNameDeferLinking && klass->is_instance_klass()) {
|
||||
InstanceKlass::cast(klass)->link_class(CHECK);
|
||||
}
|
||||
JVM_END
|
||||
|
||||
JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
|
||||
JVMWrapper("JVM_GetCallerClass");
|
||||
|
||||
|
@ -863,10 +852,9 @@ JVM_ENTRY(jclass, JVM_FindClassFromCaller(JNIEnv* env, const char* name,
|
|||
|
||||
Handle h_loader(THREAD, loader_oop);
|
||||
Handle h_prot(THREAD, protection_domain);
|
||||
|
||||
jboolean link = !ClassForNameDeferLinking;
|
||||
jclass result = find_class_from_class_loader(env, h_name, init, link, h_loader,
|
||||
jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
|
||||
h_prot, false, THREAD);
|
||||
|
||||
if (log_is_enabled(Debug, class, resolve) && result != NULL) {
|
||||
trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
|
||||
}
|
||||
|
@ -903,7 +891,7 @@ JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name,
|
|||
}
|
||||
Handle h_loader(THREAD, class_loader);
|
||||
Handle h_prot (THREAD, protection_domain);
|
||||
jclass result = find_class_from_class_loader(env, h_name, init, false, h_loader,
|
||||
jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
|
||||
h_prot, true, thread);
|
||||
|
||||
if (log_is_enabled(Debug, class, resolve) && result != NULL) {
|
||||
|
@ -3410,12 +3398,9 @@ JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
|
|||
|
||||
// Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
|
||||
|
||||
jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, jboolean link,
|
||||
jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
|
||||
Handle loader, Handle protection_domain,
|
||||
jboolean throwError, TRAPS) {
|
||||
// Initialization also implies linking - check for coherent args
|
||||
assert((init && link) || !init, "incorrect use of init/link arguments");
|
||||
|
||||
// Security Note:
|
||||
// The Java level wrapper will perform the necessary security check allowing
|
||||
// us to pass the NULL as the initiating class loader. The VM is responsible for
|
||||
|
@ -3424,11 +3409,9 @@ jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, jb
|
|||
// if there is no security manager in 3-arg Class.forName().
|
||||
Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
|
||||
|
||||
// Check if we should initialize the class (which implies linking), or just link it
|
||||
// Check if we should initialize the class
|
||||
if (init && klass->is_instance_klass()) {
|
||||
klass->initialize(CHECK_NULL);
|
||||
} else if (link && klass->is_instance_klass()) {
|
||||
InstanceKlass::cast(klass)->link_class(CHECK_NULL);
|
||||
}
|
||||
return (jclass) JNIHandles::make_local(env, klass->java_mirror());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue