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

Jorn Vernee jvernee at openjdk.org
Mon Nov 10 15:00:47 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, 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).

This pull request has now been integrated.

Changeset: 6e838d6f
Author:    Jorn Vernee <jvernee at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/6e838d6f9a59e4f14d4d1a6d4ff6ea857c0615e9
Stats:     7 lines in 2 files changed: 2 ins; 1 del; 4 mod

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

Reviewed-by: alanb, mdoerr

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

PR: https://git.openjdk.org/jdk/pull/28202


More information about the core-libs-dev mailing list