Enumerating Threads

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

JDI VirtualThreads.allThreads (and JDWP VirtualMachine/AllThreads) enumerates all active platform threads, as before.

Thread groups

Virtual threads are not active members of a thread group. 

JDI ThreadGroupReference::threads (and JDWP ThreadGroupReference/Children) enumerate all active platform threads in the group, as before.

ThreadStart/ThreadEnd events

JDI ThreadStartEvent/ThreadDeathEvents are sent for all threads, as before, but it may impact performance if there are a huge number of virtual threads.

JDWP EventRequest/Set defines a new filter that can be used when requesting THREAD_START and THREAD_END events. This allows these events to be filtered for virtual threads so they are not sent to the front-end/debugger.

JDI ThreadStartRequest/ThreadDeathRequest define a new method to control whether thread start/end events are sent for all threads or only platform threads.

IsVirtual

JDI ThreadReference defines isVirtual to test if a thread is a virtual thread.

JDWP ThreadReference/IsVirtual is the equivalent.

Not Supported

The following are not currently supported for virtual threads:

JDWP agent options

As a temporary solution to allow existing debuggers work with virtual threads, the JDWP agent will track virtual threads so they can be enumerated for debuggers that want to enumerate all virtual threads. The options that control this behaviour are:

Option Name and ValueDescriptionDefault
trackvthreads=some|all  track some or all vthreads some
enumeratevthreads=y|n    thread lists include vthreadsy
fakevthreadstartevent=y|n  send fake start event when needed y

Links

Java Debug Interface (JDI)

JDWP protocol details

JVM Tool Interface