RFR: 8284877: Check type compatibility before looking up method from receiver's vtable [v2]

David Holmes dholmes at openjdk.org
Mon Jun 19 02:07:08 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  if the `validate_call` is not be applied to virtual calls then we should fix that in `jniCheck.cpp`.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/8241#issuecomment-1596379178


More information about the hotspot-dev mailing list