RFR: 8367142: Avoid InstanceKlass::cast when converting java mirror to InstanceKlass [v3]

Ioi Lam iklam at openjdk.org
Wed Sep 10 22:50:30 UTC 2025


On Wed, 10 Sep 2025 22:46:00 GMT, Ioi Lam <iklam at openjdk.org> wrote:

>> The purpose of this PR is to simplify JNI code and also to avoid unnecessary `InstanceKlass::cast()` calls by adding a new  function:
>> 
>> 
>> static InstanceKlass* java_lang_Class::as_InstanceKlass(oop java_class);
>> 
>> 
>> This PR is intended to be a strict clean-up that preserves existing behaviors.
>
> Ioi Lam has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Removed the (jobject) version of as_Klass/as_InstanceKlass

I didn't realize that my attempt to remove the `JNIHandles::resolve()` boilerplate can be conversional. I can't put a helper function in jni.cpp because this pattern is used in several files. I've reverted to the old code that makes the explicit calls to `JNIHandles::resolve()`.

I updated the JBS issue text as this PR is now only for reducing the number of InstanceKlass::cast() calls.

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

PR Comment: https://git.openjdk.org/jdk/pull/27158#issuecomment-3276767203


More information about the serviceability-dev mailing list