Skip to content
Permalink
Browse files

8229900: RedefineDeleteJmethod.java fails with -Xcheck:jni

Remove RedefineClasses adjustment and test, but improve checking for method/class matching.

Reviewed-by: dholmes, sspitsyn
  • Loading branch information
Coleen Phillimore
Coleen Phillimore committed Oct 7, 2019
1 parent bb09c0c commit 638910826adfc886b30f917f57289121f91e1e7f
@@ -448,16 +448,16 @@ oop jniCheck::validate_handle(JavaThread* thr, jobject obj) {
Method* jniCheck::validate_jmethod_id(JavaThread* thr, jmethodID method_id) {
ASSERT_OOPS_ALLOWED;
// do the fast jmethodID check first
Method* moop = Method::checked_resolve_jmethod_id(method_id);
if (moop == NULL) {
Method* m = Method::checked_resolve_jmethod_id(method_id);
if (m == NULL) {
ReportJNIFatalError(thr, fatal_wrong_class_or_method);
}
// jmethodIDs are supposed to be weak handles in the class loader data,
// jmethodIDs are handles in the class loader data,
// but that can be expensive so check it last
else if (!Method::is_method_id(method_id)) {
ReportJNIFatalError(thr, fatal_non_weak_method);
}
return moop;
return m;
}


@@ -518,18 +518,29 @@ void jniCheck::validate_throwable_klass(JavaThread* thr, Klass* klass) {
}
}

void jniCheck::validate_call_object(JavaThread* thr, jobject obj, jmethodID method_id) {
/* validate the object being passed */
void jniCheck::validate_call(JavaThread* thr, jclass clazz, jmethodID method_id, jobject obj) {
ASSERT_OOPS_ALLOWED;
jniCheck::validate_jmethod_id(thr, method_id);
jniCheck::validate_object(thr, obj);
}
Method* m = jniCheck::validate_jmethod_id(thr, method_id);
InstanceKlass* holder = m->method_holder();

if (clazz != NULL) {
Klass* k = jniCheck::validate_class(thr, clazz, false);
// Check that method is in the class, must be InstanceKlass
if (!InstanceKlass::cast(k)->is_subtype_of(holder)) {
ReportJNIFatalError(thr, fatal_wrong_class_or_method);
}
}

void jniCheck::validate_call_class(JavaThread* thr, jclass clazz, jmethodID method_id) {
/* validate the class being passed */
ASSERT_OOPS_ALLOWED;
jniCheck::validate_jmethod_id(thr, method_id);
jniCheck::validate_class(thr, clazz, false);
if (obj != NULL) {
oop recv = jniCheck::validate_object(thr, obj);
assert(recv != NULL, "validate_object checks that");
Klass* ik = recv->klass();

// Check that the object is a subtype of method holder too.
if (!InstanceKlass::cast(ik)->is_subtype_of(holder)) {
ReportJNIFatalError(thr, fatal_wrong_class_or_method);
}
}
}


@@ -595,8 +606,7 @@ JNI_ENTRY_CHECKED(jobject,
jboolean isStatic))
functionEnter(thr);
IN_VM(
jniCheck::validate_class(thr, cls, false);
jniCheck::validate_jmethod_id(thr, methodID);
jniCheck::validate_call(thr, cls, methodID);
)
jobject result = UNCHECKED()->ToReflectedMethod(env, cls, methodID,
isStatic);
@@ -852,8 +862,7 @@ JNI_ENTRY_CHECKED(jobject,
functionEnter(thr);
va_list args;
IN_VM(
jniCheck::validate_class(thr, clazz, false);
jniCheck::validate_jmethod_id(thr, methodID);
jniCheck::validate_call(thr, clazz, methodID);
)
va_start(args, methodID);
jobject result = UNCHECKED()->NewObjectV(env,clazz,methodID,args);
@@ -869,8 +878,7 @@ JNI_ENTRY_CHECKED(jobject,
va_list args))
functionEnter(thr);
IN_VM(
jniCheck::validate_class(thr, clazz, false);
jniCheck::validate_jmethod_id(thr, methodID);
jniCheck::validate_call(thr, clazz, methodID);
)
jobject result = UNCHECKED()->NewObjectV(env,clazz,methodID,args);
functionExit(thr);
@@ -884,8 +892,7 @@ JNI_ENTRY_CHECKED(jobject,
const jvalue *args))
functionEnter(thr);
IN_VM(
jniCheck::validate_class(thr, clazz, false);
jniCheck::validate_jmethod_id(thr, methodID);
jniCheck::validate_call(thr, clazz, methodID);
)
jobject result = UNCHECKED()->NewObjectA(env,clazz,methodID,args);
functionExit(thr);
@@ -941,7 +948,7 @@ JNI_ENTRY_CHECKED(ResultType, \
functionEnter(thr); \
va_list args; \
IN_VM( \
jniCheck::validate_call_object(thr, obj, methodID); \
jniCheck::validate_call(thr, NULL, methodID, obj); \
) \
va_start(args,methodID); \
ResultType result =UNCHECKED()->Call##Result##MethodV(env, obj, methodID, \
@@ -959,7 +966,7 @@ JNI_ENTRY_CHECKED(ResultType, \
va_list args)) \
functionEnter(thr); \
IN_VM(\
jniCheck::validate_call_object(thr, obj, methodID); \
jniCheck::validate_call(thr, NULL, methodID, obj); \
) \
ResultType result = UNCHECKED()->Call##Result##MethodV(env, obj, methodID,\
args); \
@@ -975,7 +982,7 @@ JNI_ENTRY_CHECKED(ResultType, \
const jvalue * args)) \
functionEnter(thr); \
IN_VM( \
jniCheck::validate_call_object(thr, obj, methodID); \
jniCheck::validate_call(thr, NULL, methodID, obj); \
) \
ResultType result = UNCHECKED()->Call##Result##MethodA(env, obj, methodID,\
args); \
@@ -1002,7 +1009,7 @@ JNI_ENTRY_CHECKED(void,
functionEnter(thr);
va_list args;
IN_VM(
jniCheck::validate_call_object(thr, obj, methodID);
jniCheck::validate_call(thr, NULL, methodID, obj);
)
va_start(args,methodID);
UNCHECKED()->CallVoidMethodV(env,obj,methodID,args);
@@ -1018,7 +1025,7 @@ JNI_ENTRY_CHECKED(void,
va_list args))
functionEnter(thr);
IN_VM(
jniCheck::validate_call_object(thr, obj, methodID);
jniCheck::validate_call(thr, NULL, methodID, obj);
)
UNCHECKED()->CallVoidMethodV(env,obj,methodID,args);
thr->set_pending_jni_exception_check("CallVoidMethodV");
@@ -1032,7 +1039,7 @@ JNI_ENTRY_CHECKED(void,
const jvalue * args))
functionEnter(thr);
IN_VM(
jniCheck::validate_call_object(thr, obj, methodID);
jniCheck::validate_call(thr, NULL, methodID, obj);
)
UNCHECKED()->CallVoidMethodA(env,obj,methodID,args);
thr->set_pending_jni_exception_check("CallVoidMethodA");
@@ -1049,8 +1056,7 @@ JNI_ENTRY_CHECKED(ResultType, \
functionEnter(thr); \
va_list args; \
IN_VM( \
jniCheck::validate_call_object(thr, obj, methodID); \
jniCheck::validate_call_class(thr, clazz, methodID); \
jniCheck::validate_call(thr, clazz, methodID, obj); \
) \
va_start(args,methodID); \
ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodV(env, \
@@ -1072,8 +1078,7 @@ JNI_ENTRY_CHECKED(ResultType, \
va_list args)) \
functionEnter(thr); \
IN_VM( \
jniCheck::validate_call_object(thr, obj, methodID); \
jniCheck::validate_call_class(thr, clazz, methodID); \
jniCheck::validate_call(thr, clazz, methodID, obj); \
) \
ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodV(env, \
obj, \
@@ -1093,8 +1098,7 @@ JNI_ENTRY_CHECKED(ResultType, \
const jvalue * args)) \
functionEnter(thr); \
IN_VM( \
jniCheck::validate_call_object(thr, obj, methodID); \
jniCheck::validate_call_class(thr, clazz, methodID); \
jniCheck::validate_call(thr, clazz, methodID, obj); \
) \
ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodA(env, \
obj, \
@@ -1125,8 +1129,7 @@ JNI_ENTRY_CHECKED(void,
functionEnter(thr);
va_list args;
IN_VM(
jniCheck::validate_call_object(thr, obj, methodID);
jniCheck::validate_call_class(thr, clazz, methodID);
jniCheck::validate_call(thr, clazz, methodID, obj);
)
va_start(args,methodID);
UNCHECKED()->CallNonvirtualVoidMethodV(env,obj,clazz,methodID,args);
@@ -1143,8 +1146,7 @@ JNI_ENTRY_CHECKED(void,
va_list args))
functionEnter(thr);
IN_VM(
jniCheck::validate_call_object(thr, obj, methodID);
jniCheck::validate_call_class(thr, clazz, methodID);
jniCheck::validate_call(thr, clazz, methodID, obj);
)
UNCHECKED()->CallNonvirtualVoidMethodV(env,obj,clazz,methodID,args);
thr->set_pending_jni_exception_check("CallNonvirtualVoidMethodV");
@@ -1159,8 +1161,7 @@ JNI_ENTRY_CHECKED(void,
const jvalue * args))
functionEnter(thr);
IN_VM(
jniCheck::validate_call_object(thr, obj, methodID);
jniCheck::validate_call_class(thr, clazz, methodID);
jniCheck::validate_call(thr, clazz, methodID, obj);
)
UNCHECKED()->CallNonvirtualVoidMethodA(env,obj,clazz,methodID,args);
thr->set_pending_jni_exception_check("CallNonvirtualVoidMethodA");
@@ -1253,8 +1254,7 @@ JNI_ENTRY_CHECKED(ReturnType, \
functionEnter(thr); \
va_list args; \
IN_VM( \
jniCheck::validate_jmethod_id(thr, methodID); \
jniCheck::validate_class(thr, clazz, false); \
jniCheck::validate_call(thr, clazz, methodID); \
) \
va_start(args,methodID); \
ReturnType result = UNCHECKED()->CallStatic##Result##MethodV(env, \
@@ -1274,8 +1274,7 @@ JNI_ENTRY_CHECKED(ReturnType, \
va_list args)) \
functionEnter(thr); \
IN_VM( \
jniCheck::validate_jmethod_id(thr, methodID); \
jniCheck::validate_class(thr, clazz, false); \
jniCheck::validate_call(thr, clazz, methodID); \
) \
ReturnType result = UNCHECKED()->CallStatic##Result##MethodV(env, \
clazz, \
@@ -1293,8 +1292,7 @@ JNI_ENTRY_CHECKED(ReturnType, \
const jvalue *args)) \
functionEnter(thr); \
IN_VM( \
jniCheck::validate_jmethod_id(thr, methodID); \
jniCheck::validate_class(thr, clazz, false); \
jniCheck::validate_call(thr, clazz, methodID); \
) \
ReturnType result = UNCHECKED()->CallStatic##Result##MethodA(env, \
clazz, \
@@ -1323,8 +1321,7 @@ JNI_ENTRY_CHECKED(void,
functionEnter(thr);
va_list args;
IN_VM(
jniCheck::validate_jmethod_id(thr, methodID);
jniCheck::validate_class(thr, cls, false);
jniCheck::validate_call(thr, cls, methodID);
)
va_start(args,methodID);
UNCHECKED()->CallStaticVoidMethodV(env,cls,methodID,args);
@@ -1340,8 +1337,7 @@ JNI_ENTRY_CHECKED(void,
va_list args))
functionEnter(thr);
IN_VM(
jniCheck::validate_jmethod_id(thr, methodID);
jniCheck::validate_class(thr, cls, false);
jniCheck::validate_call(thr, cls, methodID);
)
UNCHECKED()->CallStaticVoidMethodV(env,cls,methodID,args);
thr->set_pending_jni_exception_check("CallStaticVoidMethodV");
@@ -1355,8 +1351,7 @@ JNI_ENTRY_CHECKED(void,
const jvalue * args))
functionEnter(thr);
IN_VM(
jniCheck::validate_jmethod_id(thr, methodID);
jniCheck::validate_class(thr, cls, false);
jniCheck::validate_call(thr, cls, methodID);
)
UNCHECKED()->CallStaticVoidMethodA(env,cls,methodID,args);
thr->set_pending_jni_exception_check("CallStaticVoidMethodA");
@@ -51,8 +51,7 @@ class jniCheck : public AllStatic {
static Klass* validate_class(JavaThread* thr, jclass clazz, bool allow_primitive = false);
static void validate_class_descriptor(JavaThread* thr, const char* name);
static void validate_throwable_klass(JavaThread* thr, Klass* klass);
static void validate_call_object(JavaThread* thr, jobject obj, jmethodID method_id);
static void validate_call_class(JavaThread* thr, jclass clazz, jmethodID method_id);
static void validate_call(JavaThread* thr, jclass clazz, jmethodID method_id, jobject obj = NULL);
static Method* validate_jmethod_id(JavaThread* thr, jmethodID method_id);
};

@@ -3528,15 +3528,6 @@ void VM_RedefineClasses::update_jmethod_ids() {
"should be replaced");
}
}
// Update deleted jmethodID
for (int j = 0; j < _deleted_methods_length; ++j) {
Method* old_method = _deleted_methods[j];
jmethodID jmid = old_method->find_jmethod_id_or_null();
if (jmid != NULL) {
// Change the jmethodID to point to NSME.
Method::change_method_associated_with_jmethod_id(jmid, Universe::throw_no_such_method_error());
}
}
}

int VM_RedefineClasses::check_methods_and_mark_as_obsolete() {

This file was deleted.

0 comments on commit 6389108

Please sign in to comment.
You can’t perform that action at this time.