Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Enumerating Threads

Virtual threads are just objects in the heap, there may be millions of them. There are no APIs for enumerating all virtual threads.

...

JDI VirtualThreads.allThreads (

...

and JDWP VirtualMachine/AllThreads

...

) continue to enumerate all platform threads.

Thread groups

Virtual threads are not active members of a thread group

JDI ThreadGroupReference::threads

...

(and JDWP ThreadGroupReference/Children

...

Thread start/end events

  • New JDI ThreadStartRequest/ThreadEndRequest removeVirtualThreadFilter method to virtual events for virtual threads, filter is opt-out

) continue to enumerate all platform threads in the group.

ThreadStart/ThreadEnd events

JDWP EventRequest/Set defines a new modifier VirtualThreadsExclude that can be used when request event kinds THREAD_START and THREAD_END to filer those events for virtual threads.

JDI ThreadStartRequest/ThreadDeathRequest define a new method removeVirtualThreadFilter that can be used to remove the filtering of

...

thread start/end events for virtual threads

...

. This may be changed so that JDI clients opt-out rather than opt-in

...

Test if a thread is a virtual thread

  • New JDI ThreadReference::isVirtual

  • New JDWP ThreadReference/IsVirtual

for these events.

Not Supported

The following are current not supported

...

for virtual threads:

  • JDI ThreadReference::stop / JDWP ThreadReference/Stop
  • JDI ThreadReference::interrupt / JDWP ThreadReference/Interrupt

...

Force early return, set locals, .... what else?

Debuggers and tools using the Java Debug Interface API observe the following differences:

  1. com.sun.jdi.VirtualMachine::allThreads enumerates platform threads only, the list does not include mirrors for virtual threads.
  2. Virtual threads are not live threads in a thread group so ThreadGroupReference::threads only lists platform threads.
  3. ThreadStartRequest/ThreadDeathRequest request notifications of thread start/termination of platform threads by default. Tools have to opt-in to get start/death events for virtual threads (by invoking the removeVirtualThreadFilter method on the event request.

...

  • ForceEarlyReturn
  • Set locals


JDWP agent options (temporary)

Option Name and Value           Description                       Default
---------------------           -----------                       -------
trackvthreads=some|all           track some or all vthreads       some
enumeratevthreads=y|n           thread lists include vthreads     y
fakevthreadstartevent=y|n       send fake start event when needed y
  1. enumeratevthreads control whether or not vthreads are included in VM.allThreads and ThreadGroupReference.children.

  2. trackvthreads determines what vthreads will be returned if enumeratevthreads=y, so it doesn’t carry any meaning to the user if enumeratevthreads=n, but will still impact with the debug agent does internally

  3. fakevthreadstartevent is independent of the two others. If y, then before sending an event, send a fake THREAD_START event for if the debugger hasn’t already been notified about the vthread the event occurred on. Intellij needs this. Note currently there is a bug, and if trackvthreads=all, no fake THREAD_START will ever be sent. This is only an issue if the debug agent is started after some vthreads have been created (a mode I haven’t even tested yet, and I don’t think is commonly used). (edited)

...