RFR: 8284877: Check type compatibility before looking up method from receiver's vtable [v2]
David Holmes
dholmes at openjdk.org
Mon Jun 19 02:45:16 UTC 2023
On Mon, 19 Jun 2023 01:53:47 GMT, Yi Yang <yyang at openjdk.org> wrote:
>>> Is it possible to add this sanity check as part of `-Xcheck:jni`? I agree that this check should not be added by default.
>>
>> @dcubed-ojdk , @y1yang0 such a check is already part of `-Xcheck:jni`. See `src/hotspot/share/prims/jniCheck.cpp` and the `jniCheck::validate_call` method - it does a receiver typecheck:
>>
>> if (obj != nullptr) {
>> oop recv = jniCheck::validate_object(thr, obj);
>> assert(recv != nullptr, "validate_object checks that");
>> Klass* rk = recv->klass();
>>
>> // Check that the object is a subtype of method holder too.
>> if (!rk->is_subtype_of(holder)) {
>> ReportJNIFatalError(thr, fatal_wrong_class_or_method);
>> }
>> }
>
>> validate_call
>
> This check is exercised when jni_CallStaticVoidMethod is called, while aforementioned case is that JNI wrongly constructs an object and does a normal virtual call and gets correct result.
@y1yang0 as far as I can see it is already being called via the following macro/wrapper:
#define WRAPPER_CallMethod(ResultType, Result) \
JNI_ENTRY_CHECKED(ResultType, \
checked_jni_Call##Result##Method(JNIEnv *env, \
jobject obj, \
jmethodID methodID, \
...)) \
functionEnter(thr); \
va_list args; \
IN_VM( \
jniCheck::validate_call(thr, nullptr, methodID, obj); \
) \
va_start(args,methodID); \
ResultType result =UNCHECKED()->Call##Result##MethodV(env, obj, methodID, \
args); \
va_end(args); \
thr->set_pending_jni_exception_check("Call"#Result"Method"); \
functionExit(thr); \
return result; \
JNI_END \
-------------
PR Comment: https://git.openjdk.org/jdk/pull/8241#issuecomment-1596406550
More information about the hotspot-dev
mailing list