RFR: 8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getJObjectValue
Tomáš Zezula
duke at openjdk.org
Thu Jul 18 08:38:34 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.
@tkrodriguez The Truffle shared library compiler is always invoked from Java code by calling a native method. The JNI local reference is allocated within the JNI locals frame of the native method. When the method ends, this frame is removed, and the handle is cleared.
For host method compilation, where the caller thread lacks a Java frame anchor, a new JNI local frame is pushed, which is subsequently popped at the end of the method. In this case, the handle is cleared by the `PopLocalFrame`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20219#discussion_r1682444891
More information about the hotspot-compiler-dev
mailing list