8239593: Bogus warning "Re-registering of platform native method" for a JVMTI agent

Reviewed-by: dcubed, alanb, hseigel
This commit is contained in:
David Holmes 2020-03-17 19:57:58 -04:00
parent c003fffd84
commit f959b01203

View File

@ -2811,17 +2811,26 @@ JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz,
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
// There are no restrictions on native code registering native methods, which
// allows agents to redefine the bindings to native methods. But we issue a
// warning if any code running outside of the boot/platform loader is rebinding
// any native methods in classes loaded by the boot/platform loader.
Klass* caller = thread->security_get_caller_class(1);
// There are no restrictions on native code registering native methods,
// which allows agents to redefine the bindings to native methods, however
// we issue a warning if any code running outside of the boot/platform
// loader is rebinding any native methods in classes loaded by the
// boot/platform loader that are in named modules. That will catch changes
// to platform classes while excluding classes added to the bootclasspath.
bool do_warning = false;
oop cl = k->class_loader();
if (cl == NULL || SystemDictionary::is_platform_class_loader(cl)) {
// If no caller class, or caller class has a different loader, then
// issue a warning below.
do_warning = (caller == NULL) || caller->class_loader() != cl;
// Only instanceKlasses can have native methods
if (k->is_instance_klass()) {
oop cl = k->class_loader();
InstanceKlass* ik = InstanceKlass::cast(k);
// Check for a platform class
if ((cl == NULL || SystemDictionary::is_platform_class_loader(cl)) &&
ik->module()->is_named()) {
Klass* caller = thread->security_get_caller_class(1);
// If no caller class, or caller class has a different loader, then
// issue a warning below.
do_warning = (caller == NULL) || caller->class_loader() != cl;
}
}