• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Export Word
    • Attachments
    • Page Information

    Loading...
  1. Dashboard
  2. Loom
  3. Main
  4. Debugger Support

Page History

Versions Compared

Old Version 42

changes.mady.by.user Alan Bateman

Saved on Sep 14, 2021

compared with

New Version Current

changes.mady.by.user Chris Plummer

Saved on Oct 12, 2022

  • Previous Change: Difference between versions 41 and 42
  • View Page History

Key

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

...

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

JDI VirtualThreads.allThreads() (and JDWP VirtualMachine/AllThreads) enumerates all active live platform threads, virtual threads are not enumerated unless the JDWP agent is started with the includevirtualthreads option (see below).

For thread dumps and troubleshooting purposes the debugger can invoke the com.sun.management.ThreadsHotSpotDiagnosticMXBean.dumpThreads API in the target VM to enumerate threadsgenerate a thread dump. This can be used as stop-gap solution until there is better support in the debugging in the APIs for finding virtual threads in the debugger APIs.

Thread groups

Virtual threads are not active members of a thread group. 

JDI ThreadGroupReference::threads (and JDWP ThreadGroupReference/Children) enumerate all active live platform threads in a group, virtual threads are not enumerated.

...

JDI ThreadStartEvent/ThreadDeathEvents are sent for all threads when enabled. This may impact performance if there are a huge number of virtual threads.

JDWP EventRequest/Set defines a new PlatformThreadsOnly 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.

...

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

JDWP ThreadReference/IsVirtual is the equivalent.

Testing if target VM supports virtual threads

The following recommend way is temporary, to allow debuggers to distinguish JDK 17 EA builds from Loom EA builds.JDI VirtualMachine defines supportVirtualThreads() to test to check if the target VM supports virtual threads.The supportsVirtualThread boolean in the reply to the JDWP CapabilitiesNew command is the equivalentis version 19 or later. There is no way to determine if --enable-preview was set, but this is also unnecessary. The JDK 19 debug agent will still execute commands that are virtual thread specific, even if the JVM was not run with --enable-preview.

Not Supported

The following are not currently supported for virtual threads:

  • JDI ThreadReference.stop
  • JDI ThreadReference.popFrame
  • JDI ThreadReference.forceEarlyReturn
  • JDI StackFrame.setValue() has limited support. It can be used on the topmost frame when suspended due to certain events, such as breakpoint and single step. Details are still being refined.

JDWP agent options

As a temporary solution to allow existing debuggers to 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 option that control controls this behavior areis:

Option Name and ValueDescriptionDefault
enumeratevthreadsincludevirtualthreads=y|n   thread lists include vthreadsList of all threads includes virtual threads as well as platform threadsn
notifyvthreads=y|nsend THREAD_START/END events for all vthreadsvirtual threads
y
  • enumeratevthreads control includevirtualthreads control whether or not virtual threads are included in the list of threads returned by JDWP VirtualThread.GetAllThreads and ThreadGroupReference. Children commands. This flag can be turned on for compatibility purposes. This flag will may eventually go away and the debug agent will operate as if it was set to 'n'. Note that the debug agent will only return virtual threads that are created after the debugger attaches. If the debugger detaches, the debug agent will forget about all discovered virtual threads, and the list will once again be empty when the debugger attaches again.
  • [notifyvthreads has been removed. To disable THREAD_START and THREAD_END events for vthreads, use the PlatformThreadsOnly filter as described in this section] notifyvthreads controls whether or not THREAD_START and THREAD_END events are sent for vthreadsvirtual threads. The default is to send them. The purpose is to allow debugger writers to set to 'n' use notifyvthreads=n to see how the debugger works without getting these events. This is meant as a short term convenience flag rather than having to set the PlatformThreadsOnly filter as described above. In the long run Once support for notifyvthreads=n is gone, if debuggers don't want these eventswant THREAD_START and THREAD_END events for virtual threads, they will need to set the PlatformThreadsOnly filter. When using the PlatformThreadsOnly filter. Since this means no , the debugger can learn about virtual threads when events are delivered for them, such as a BreakpointEvent. Since no THREAD_END event will be sent for the virtual thread, the debugger will then need to figure out how to "forget" about virtual Threads that the virtual threads it is tracking when they have terminated. This could possibly be done with an ObjectReference.IsCollected commanda ThreadDeathRequest that filters on the virtual thread. This would need to be done for each virtual thread being tracked by the debugger. Please note that notifyvthreads=y will not override any PlatformThreadsOnly filter that is in place.

Issues with too many virtual threads hitting breakpoints

...

Overview
Content Tools
ThemeBuilder

Terms of Use
• License: GPLv2
• Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Kolekti ThemeBuilder Powered by Atlassian Confluence 8.5.23
  • Kolekti ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Kolekti ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 293, "requestCorrelationId": "875487e6edad32d8"}