RFR: 8306034: add support of virtual threads to JVMTI StopThread [v2]

Alan Bateman alanb at openjdk.org
Fri Apr 21 13:38:43 UTC 2023


On Fri, 21 Apr 2023 13:09:58 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> The JVMTI `StopThread` spec has this description:
>>> The StopThread function may be used to send an asynchronous
>>> exception to a virtual thread when it is suspended at an event.
>>> An implementation may support sending an asynchronous exception
>>> to a suspended virtual thread in other cases.
>>> . . .
>>> JVMTI_ERROR_OPAQUE_FRAME:
>>> The thread is a suspended virtual thread and the implementation 
>>> was unable to throw an asynchronous exception from this frame.
>> 
>> This update supports all suspended mounted cases of virtual threads and returns OPAQUE_FRAME only if the target virtual thread is suspended and unmounted.
>> But we avoid using the mount/unmount terms in the JVMTI spec.
>
> What does "suspended at an event" mean? As a programmer trying to use this how am I supposed to know when it can be used without getting an error?
> 
> I find it very surprising that the error would occur with an unmounted thread - having a VT throw when it was remounted seems the most natural way to implement this.

I think "suspended at an event" is okay. It means the callback for an event has been triggered and the agent suspended the thread. The typical use-case for JVMTI StopThread is when at a breakpoint or when single stepping and the user asks the debugger to throw some exception so that the code's handling of the exception can been debugged/tested. Debugger and JDWP agent aside, I don't know if there are other agents using this JVMTI function. If there are other and they call this function on some random virtual thread at some random time then the function will fail.

One other point around this is that the plan is to have StopThread, ForceEarlyReturn, PopFrame and SetLocalXXX work more consistently. Right now, SetLocalXXX minimally requires a virtual thread be suspended at a breakpoint or single step event. The minimum support can be broader to be suspended at any event.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13546#discussion_r1173774433


More information about the serviceability-dev mailing list