RFR: 8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getJObjectValue
Dean Long
dlong at openjdk.org
Wed Jul 17 23:44:32 UTC 2024
On Wed, 17 Jul 2024 18:57:31 GMT, Tom Rodriguez <never at openjdk.org> wrote:
>> The `HotSpotJVMCIRuntime#getJObjectValue` method returns a real JNI local handle instead of a JVMCI handle to prevent random crashes on ZGC.
>
> src/hotspot/share/jvmci/jvmciCompilerToVM.cpp line 715:
>
>> 713: JVMCIObject constant = JVMCIENV->wrap(constant_jobject);
>> 714: Handle constant_value = JVMCIENV->asConstant(constant, JVMCI_CHECK_0);
>> 715: jobject jni_handle = JNIHandles::make_local(THREAD, constant_value());
>
> Who is responsible for cleaning up these local refs? My recollection is that they are allocated in the top most containing scope but if you haven't introduced new JNI scope they will never get released.
We reset JNIHandleBlock::_top to 0 when exiting the native method frame, so I don't think a local ref wrapped as a jlong is safe to return here, as it will be stale when the caller returns. You probably need a global ref and manage the lifecycle somehow.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20219#discussion_r1681896542
More information about the hotspot-compiler-dev
mailing list