The JVMTI implementation needs to be updated to work with the alternative implementation of virtual threads. At this time, JVMTI is not supported when running with the alternative implementation and --enable-previews (see check in jni_GetEnv). The alternative implementation creates an OS thread for each virtual thread and can be selected by running with -XX:+UnlockExperimentalVMOptions -XX:-VMContinuations. Ports without VM continuations supports, e.g. Zero, use the alternative implementation by default.
There are several functions that will need to be updated, e.g.
- StopThread, RunAgentThread, GetCurrentThreadCpuTime, GetThreadCpuTime should return UNSUPPORTED_OPERATION for virtual threads.
- GetAllThreads and GetAllStackTraces are specified to return only platform threads and so will need to filter out the threads where the Thread object is a BaseVirtualThread.
- SuspendAllVirtualThreads and ResumeAllVirtualThreads will need to suspend/resume threads where the Thread object is a BaseVirtualThread.
The JVMTI spec only requires PopFrame, ForceEarlyReturnXXX, SetLocalXXX, GetLocalXXX to work for limited cases with virtual threads. It does not prohibit these functions supporting a wider range of cases so it might that no changes are required here.
There may be more and searching the JVMTI spec for references to "virtual thread" may identify other functions/events with different behavior specified for virtual threads. Also, if `@requires vm.continuations` is removed from the existing JVMTI tests then they can be run in this mode to find issues.
As part of this, or as follow-on, we may need test configuration to run some or all of the JVMTI tests with these options to ensure the code is regularly tested.
There are several functions that will need to be updated, e.g.
- StopThread, RunAgentThread, GetCurrentThreadCpuTime, GetThreadCpuTime should return UNSUPPORTED_OPERATION for virtual threads.
- GetAllThreads and GetAllStackTraces are specified to return only platform threads and so will need to filter out the threads where the Thread object is a BaseVirtualThread.
- SuspendAllVirtualThreads and ResumeAllVirtualThreads will need to suspend/resume threads where the Thread object is a BaseVirtualThread.
The JVMTI spec only requires PopFrame, ForceEarlyReturnXXX, SetLocalXXX, GetLocalXXX to work for limited cases with virtual threads. It does not prohibit these functions supporting a wider range of cases so it might that no changes are required here.
There may be more and searching the JVMTI spec for references to "virtual thread" may identify other functions/events with different behavior specified for virtual threads. Also, if `@requires vm.continuations` is removed from the existing JVMTI tests then they can be run in this mode to find issues.
As part of this, or as follow-on, we may need test configuration to run some or all of the JVMTI tests with these options to ensure the code is regularly tested.
- relates to
-
JDK-8311510 SetLocalXXX fail on virtual threads with -XX:+UnlockExperimentalVMOptions -XX:-VMContinuations
-
- Closed
-