RFR: 8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getJObjectValue

Tomáš Zezula duke at openjdk.org
Thu Jul 18 10:58:31 UTC 2024


On Wed, 17 Jul 2024 17:09:46 GMT, Tomáš Zezula <duke 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.

I believe there is a misunderstanding regarding the method's usage. I need to extend the Javadoc, as the current documentation only states that the method can be called when `IS_IN_NATIVE_IMAGE` is `true`, which is insufficient. All calls to `getJObjectValue` are made from the JVMCI shared library. From HotSpot's perspective, the call to `getJObjectValue` represents a native-to-VM transition, which does not affect JNI local frames. The returned `jlong` is converted into the nativeimage `PointerBase` type  and becomes a `jobject` pointing to an object in the HotSpot heap. The method cannot return a `jobject` directly because it is called within the JVMCI shared library but returns a pointer to an object in the HotSpot heap.

The method is used to "unwrap" the object held by the `IndirectObjectConstant` in the JVMCI shared library. The unwrapped object resides in the HotSpot heap, and the JVMCI shared library is considered native code from HotSpot's perspective. The overall usage is as follows:

1. A Java thread in the HotSpot heap calls the native `compile` method, causing HotSpot Java-to-native transition.
2. In the JVMCI shared library, we call `getJObjectValue`, causing HotSpot native-to-VM transition.
3. `getJObjectValue` returns a `jobject` as a `jlong`, resulting in HotSpot VM-to-native transition.
4. We create a nativeimage pointer type from the `jlong` and use it as a receiver or parameter while making JNI calls to objects in the HotSpot heap.
5. The native compile method ends, causing HotSpot native-to-Java transition, and local handles, including the handle returned by `getJObjectValue`, are freed.

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

PR Comment: https://git.openjdk.org/jdk/pull/20219#issuecomment-2236213179


More information about the hotspot-compiler-dev mailing list