RFR: 8371474: Wrong object class or methodID passed to JNI call in TestSharedCloseJvmti with -Xshare:off

Alan Bateman alanb at openjdk.org
Sat Nov 8 07:17:05 UTC 2025


On Fri, 7 Nov 2025 17:29:37 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> The existing test uses the JVMTI `VMStart` callback to look up a class. This works when using CDS, because the class is already available, but because `VMStart` is called while the VM is still being initialized, it fails to find the target class when CDS is turned off.
> 
> Instead, the `VMInit` callback should be used instead, which runs after the VM has been initialized. This patch does this. Additionally, it delays the call to allocate `OTHER_SEGMENT`. If we call `FindClass` during `VMInit`, the `<clinit>` of the class will run, which then ends up calling `checkValidStateRaw` as a result of allocating `OTHER_SEGMENT`, and we get to our method exit event code before the target class and method ID have been initialized.
> 
> As a side note: I had know about the difference between `VMInit` and `VMStart`, and had actually intended to use `VMInit` in the first place, but I seem to have gotten the two confused, because they are listed in reverse chronological order in the list under 'Set Event Notification Mode' in the JVMTI spec (https://docs.oracle.com/en/java/javase/25/docs/specs/jvmti.html#SetEventNotificationMode).

Yes, using VMInit so the code executes when the VM is fully initialized is right.

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

Marked as reviewed by alanb (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28202#pullrequestreview-3437716082


More information about the core-libs-dev mailing list