Skip to content

Commit a868230

Browse files
committed
Spec updates to get consistent view of threads
1 parent 83bb66b commit a868230

File tree

6 files changed

+44
-25
lines changed

6 files changed

+44
-25
lines changed

make/data/jdwp/jdwp.spec

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ JDWP "Java(tm) Debug Wire Protocol"
9292
)
9393
)
9494
(Command AllThreads=4
95-
"Returns all threads currently running in the target VM . "
95+
"Returns the live threads in the target VM. "
96+
"The returned list contains all live threads that are attached to the VM. "
97+
"It does not contain virtual threads. "
9698
"The returned list contains threads created through "
9799
"java.lang.Thread, all native threads attached to "
98100
"the target VM through JNI, and system threads created "
@@ -2188,10 +2190,11 @@ JDWP "Java(tm) Debug Wire Protocol"
21882190
)
21892191
(Command Children=3
21902192
"Returns the live threads and active thread groups directly contained "
2191-
"in this thread group. Threads and thread groups in child "
2193+
"in this thread group. Virtual threads are not considered live threads "
2194+
"in a thread group and are not included. Threads and thread groups in child "
21922195
"thread groups are not included. "
21932196
"A thread is alive if it has been started and has not yet been stopped. "
2194-
"See <a href=../../api/java.base/java/lang/ThreadGroup.html>java.lang.ThreadGroup </a>
2197+
"See <a href=../../api/java.base/java/lang/ThreadGroup.html>java.lang.ThreadGroup </a> "
21952198
"for information about active ThreadGroups.
21962199
(Out
21972200
(threadGroupObject group "The thread group object ID. ")

src/hotspot/share/prims/jvmti.xml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,16 +1513,15 @@ jvmtiEnv *jvmti;
15131513
<function id="GetAllThreads" num="4">
15141514
<synopsis>Get All Threads</synopsis>
15151515
<description>
1516-
Get all live threads.
1517-
The threads are Java programming language threads;
1518-
that is, threads that are attached to the VM.
1516+
Get all live threads that are attached to the VM.
1517+
The list of threads includes
1518+
<internallink id="RunAgentThread">agent threads</internallink>.
1519+
It does not include virtual threads.
15191520
A thread is live if <code>java.lang.Thread.isAlive()</code>
15201521
would return <code>true</code>, that is, the thread has
15211522
been started and has not yet died.
15221523
The universe of threads is determined by the context of the <jvmti/>
15231524
environment, which typically is all threads attached to the VM.
1524-
Note that this includes <jvmti/> agent threads
1525-
(see <functionlink id="RunAgentThread"/>).
15261525
</description>
15271526
<origin>jvmdi</origin>
15281527
<capabilities>
@@ -1531,14 +1530,14 @@ jvmtiEnv *jvmti;
15311530
<param id="threads_count_ptr">
15321531
<outptr><jint/></outptr>
15331532
<description>
1534-
On return, points to the number of running threads.
1533+
On return, points to the number of threads.
15351534
</description>
15361535
</param>
15371536
<param id="threads_ptr">
15381537
<allocbuf outcount="threads_count_ptr"><jthread/></allocbuf>
15391538
<description>
15401539
On return, points to an array of references, one
1541-
for each running thread.
1540+
for each thread.
15421541
</description>
15431542
</param>
15441543
</parameters>
@@ -2433,6 +2432,8 @@ jvmtiEnv *jvmti;
24332432
<synopsis>Get Thread Group Children</synopsis>
24342433
<description>
24352434
Get the live threads and the child thread groups in this thread group.
2435+
Virtual threads are not considered live threads in a thread group
2436+
and not returned by this function.
24362437
</description>
24372438
<origin>jvmdi</origin>
24382439
<capabilities>
@@ -2652,8 +2653,11 @@ if (err == JVMTI_ERROR_NONE &amp;&amp; count &gt;= 1) {
26522653
<function id="GetAllStackTraces" num="100">
26532654
<synopsis>Get All Stack Traces</synopsis>
26542655
<description>
2655-
Get information about the stacks of all live threads
2656-
(including <internallink id="RunAgentThread">agent threads</internallink>).
2656+
Get the stack traces of all live threads attached to the VM.
2657+
The list includes the stack traces of
2658+
<internallink id="RunAgentThread">agent threads</internallink>.
2659+
It does not include the stack traces of virtual threads.
2660+
<p/>
26572661
If <paramlink id="max_frame_count"/> is less than the depth of a stack,
26582662
the <paramlink id="max_frame_count"/> topmost frames are returned for that thread,
26592663
otherwise the entire stack is returned.

src/java.base/share/classes/java/lang/Thread.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,8 +2658,8 @@ StackTraceElement[] asyncGetStackTrace() {
26582658
private native Object getStackTrace0();
26592659

26602660
/**
2661-
* Returns a map of stack traces for all live threads. The map does not
2662-
* include virtual threads.
2661+
* Returns a map of stack traces for all live threads that are scheduled
2662+
* by the operating system. The map does not include virtual threads.
26632663
* The map keys are threads and each map value is an array of
26642664
* {@code StackTraceElement} that represents the stack dump
26652665
* of the corresponding {@code Thread}.

src/java.management/share/classes/java/lang/management/ThreadMXBean.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232
* the Java virtual machine.
3333
*
3434
* <p> {@code ThreadMXBean} supports monitoring and management of <em>live
35-
* threads</em> in the Java virtual machine. <em>Live threads</em> are threads
36-
* scheduled by the operating system that have been started but have not yet
37-
* terminated. {@code ThreadMXBean} does not support monitoring or management
38-
* of {@linkplain Thread#isVirtual() virtual threads}.
35+
* threads</em> in the Java virtual machine that are scheduled by the operating
36+
* system. {@code ThreadMXBean} does not support monitoring or management
37+
* of {@linkplain Thread#isVirtual() virtual threads} at this time.
3938
*
4039
* <p> A Java virtual machine has a single instance of the implementation
4140
* class of this interface. This instance implementing this interface is
@@ -131,6 +130,7 @@ public interface ThreadMXBean extends PlatformManagedObject {
131130
/**
132131
* Returns the current number of live threads including both
133132
* daemon and non-daemon threads.
133+
* The count does not include virtual threads.
134134
*
135135
* @return the current number of live threads.
136136
*/
@@ -139,6 +139,7 @@ public interface ThreadMXBean extends PlatformManagedObject {
139139
/**
140140
* Returns the peak live thread count since the Java virtual machine
141141
* started or peak was reset.
142+
* The count does not include virtual threads.
142143
*
143144
* @return the peak live thread count.
144145
*/
@@ -147,20 +148,23 @@ public interface ThreadMXBean extends PlatformManagedObject {
147148
/**
148149
* Returns the total number of threads created and also started
149150
* since the Java virtual machine started.
151+
* The count does not include virtual threads.
150152
*
151153
* @return the total number of threads started.
152154
*/
153155
public long getTotalStartedThreadCount();
154156

155157
/**
156158
* Returns the current number of live daemon threads.
159+
* The count does not include virtual threads.
157160
*
158161
* @return the current number of live daemon threads.
159162
*/
160163
public int getDaemonThreadCount();
161164

162165
/**
163166
* Returns all live thread IDs.
167+
* The thread IDs of virtual threads are not included.
164168
* Some threads included in the returned array
165169
* may have been terminated when this method returns.
166170
*
@@ -607,6 +611,8 @@ public interface ThreadMXBean extends PlatformManagedObject {
607611
* the {@link #findDeadlockedThreads findDeadlockedThreads} method
608612
* should be used.
609613
*
614+
* @apiNote TBD, need to specify behavior for virtual threads.
615+
*
610616
* @return an array of IDs of the threads that are monitor
611617
* deadlocked, if any; {@code null} otherwise.
612618
*
@@ -644,6 +650,8 @@ public interface ThreadMXBean extends PlatformManagedObject {
644650
* This method is designed for troubleshooting use, but not for
645651
* synchronization control. It might be an expensive operation.
646652
*
653+
* @apiNote TBD, need to specify behavior for virtual threads.
654+
*
647655
* @return an array of IDs of the threads that are
648656
* deadlocked waiting for object monitors or ownable synchronizers, if any;
649657
* {@code null} otherwise.
@@ -829,7 +837,8 @@ public default ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors,
829837
/**
830838
* Returns the thread info for all live threads with stack trace
831839
* and synchronization information.
832-
* This is equivalent to calling:
840+
* The thread IDs of virtual threads are not included.
841+
* This method is equivalent to calling:
833842
* <blockquote>
834843
* {@link #dumpAllThreads(boolean, boolean, int)
835844
* dumpAllThreads(lockedMonitors, lockedSynchronizers, Integer.MAX_VALUE)}
@@ -870,6 +879,7 @@ public default ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors,
870879
* and synchronization information.
871880
* if {@code maxDepth == 0}, no stack trace of the thread
872881
* will be dumped.
882+
* The thread IDs of virtual threads are not included.
873883
* Some threads included in the returned array
874884
* may have been terminated when this method returns.
875885
*

src/jdk.jdi/share/classes/com/sun/jdi/ThreadGroupReference.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ public interface ThreadGroupReference extends ObjectReference {
7979

8080
/**
8181
* Returns a List containing a {@link ThreadReference} for each live thread
82-
* in this thread group. Only the live threads in this immediate thread group
83-
* (and not its subgroups) are returned. A thread is alive if it
84-
* has been started and has not yet been stopped.
82+
* in this thread group. Virtual threads are not considered live threads in
83+
* a thread group and are not included. Only the live threads in this
84+
* immediate thread group (and not its subgroups) are returned. A thread is
85+
* alive if it has been started and has not yet been stopped.
8586
*
8687
* @return a List of {@link ThreadReference} objects mirroring the
8788
* live threads from this thread group in the target VM.

src/jdk.jdi/share/classes/com/sun/jdi/VirtualMachine.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@ default List<ModuleReference> allModules() {
250250
void redefineClasses(Map<? extends ReferenceType,byte[]> classToBytes);
251251

252252
/**
253-
* Returns a list of the currently running threads. For each
254-
* running thread in the target VM, a {@link ThreadReference}
255-
* that mirrors it is placed in the list.
253+
* Returns a list of the live threads in the target VM. The returned list
254+
* contains a {@link ThreadReference} mirror for each live thread that
255+
* is attached to the VM. It does not contain elements for virtual threads.
256+
* <p>
256257
* The returned list contains threads created through
257258
* java.lang.Thread, all native threads attached to
258259
* the target VM through JNI, and system threads created

0 commit comments

Comments
 (0)