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

Jorn Vernee jvernee at openjdk.org
Sat Nov 8 01:18:13 UTC 2025


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).

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

Commit messages:
 - Make test work without CDS

Changes: https://git.openjdk.org/jdk/pull/28202/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28202&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8371474
  Stats: 7 lines in 2 files changed: 2 ins; 1 del; 4 mod
  Patch: https://git.openjdk.org/jdk/pull/28202.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28202/head:pull/28202

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


More information about the core-libs-dev mailing list