RFR: 8367719: Refactor JNI code that uses class_to_verify_considering_redefinition()
Coleen Phillimore
coleenp at openjdk.org
Tue Sep 16 16:00:22 UTC 2025
On Tue, 16 Sep 2025 02:44:26 GMT, Ioi Lam <iklam at openjdk.org> wrote:
> Simplify the boilerplate code in jvm.cpp that calls `JvmtiThreadState::class_to_verify_considering_redefinition()`, and reduce the number of `InstanceKlass::cast()` calls.
>
> I also changed a few fields/arguments from `Klass*` to `InstanceKlass*` as these are used exclusively with `InstanceKlass*`.
This looks good pending David's and my suggested changes (hope it works).
I sort of think there's no need for the Klass* version of get_class_considering_redefinition since its callers seem to really want an InstanceKlass. Since it's jvm.cpp, you can probably verify that it's never Klass in these callers.
src/hotspot/share/prims/jvm.cpp line 2265:
> 2263: inline Klass* get_klass_considering_redefinition(jclass cls, JavaThread *thread) {
> 2264: Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
> 2265: k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
Suggestion:
return JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
src/hotspot/share/prims/jvm.cpp line 2266:
> 2264: Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
> 2265: k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
> 2266: return k;
Suggestion:
src/hotspot/share/prims/jvm.cpp line 2271:
> 2269: inline InstanceKlass* get_instance_klass_considering_redefinition(jclass cls, JavaThread *thread) {
> 2270: InstanceKlass* ik = java_lang_Class::as_InstanceKlass(JNIHandles::resolve_non_null(cls));
> 2271: ik = JvmtiThreadState::class_to_verify_considering_redefinition(ik, thread);
Suggestion:
return JvmtiThreadState::class_to_verify_considering_redefinition(ik, thread);
src/hotspot/share/prims/jvm.cpp line 2272:
> 2270: InstanceKlass* ik = java_lang_Class::as_InstanceKlass(JNIHandles::resolve_non_null(cls));
> 2271: ik = JvmtiThreadState::class_to_verify_considering_redefinition(ik, thread);
> 2272: return ik;
Suggestion:
src/hotspot/share/prims/jvm.cpp line 2291:
> 2289:
> 2290: JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
> 2291: Klass* k = get_klass_considering_redefinition(cls, thread);
Even if it's a redefined class, it'll have the same name so this isn't necessary.
-------------
PR Review: https://git.openjdk.org/jdk/pull/27303#pullrequestreview-3230659598
PR Review Comment: https://git.openjdk.org/jdk/pull/27303#discussion_r2352957988
PR Review Comment: https://git.openjdk.org/jdk/pull/27303#discussion_r2352958544
PR Review Comment: https://git.openjdk.org/jdk/pull/27303#discussion_r2352959692
PR Review Comment: https://git.openjdk.org/jdk/pull/27303#discussion_r2352960240
PR Review Comment: https://git.openjdk.org/jdk/pull/27303#discussion_r2352970204
More information about the serviceability-dev
mailing list