Summary
Change the JVM TI ThreadStart/ThreadEnd events so they are only sent for platform threads. Agents that wish to get events when virtual Threads start or end can enable the VirtualThreadStart/VirtualThreadEnd events.
Problem
It is possible to create much more virtual threads than platform threads as they are light wight.
In such cases the execution of ThreadStart/ThreadEnd
event callbacks will give a significant performance overhead.
To overcome this potential problem the VirtualThreadStart/VirtualThreadEnd
events for virtual trheads can be enabled/disabled separately from the ThreadStart/ThreadEnd
events for platform threads. The can_support_virtual_threads
has to be enabled for that.
If this capability is disabled then the ThreadStart/ThreadEnd
events will be generated for virtual threads as well as for platform threads. This was for compatibility with old/legacy JVMTI agents which were not upgraded to support virtual threads.
The problem with this is that there can still can be a unexpectedly big performance overhead when profiled applications create a lot of virtual threads.
Solution
The solution is to get rid of the compatibility ThreadStart/ThreadEnd
events for virtual threads when the can_support_virtual_threads
capability is disabled. The existing agents are expected to be upgraded to support virtual threads and enable the can_support_virtual_threads
capability if they need to be notified about virtual threads creation and termination.
Specification
There are the following changes in the JVMTI spec:
- ThreadStart event spec:
Replace the fragment:
This event is generated by platform threads. It is also generated by
`virtual threads when the capability `can_support_virtual_threads`
`can_support_virtual_threads` is not enabled. Agents without support
for virtual threads that enable this event will therefore be notified by all
newly started threads. If the capability `can_support_virtual_threads` is
enabled then this event is not generated by virtual threads.
Agents with support for virtual threads can enable `VirtualThreadStart`
to be notified by newly started virtual threads.
with the fragment:
This event is generated by platform thread. It is not generated by virtual threads.
Agents with the `can_support_virtual_threads` capability can enable the
VirtualThreadStart event to be notified by newly started virtual threads.
- ThreadEnd event spec:
Replace the fragment:
This event is generated by platform threads. It is also generated by
`virtual threads when the capability `can_support_virtual_threads`
`can_support_virtual_threads` is not enabled. Agents without support for
virtual threads that enable this event for all threads will therefore be notified
by all terminating threads. If the capability `can_support_virtual_threads` is
enabled then this event is not generated by virtual threads.
Agents with support for virtual threads can enable `VirtualThreadEnd`
to be notified by terminating virtual threads.
with the fragment:
This event is generated by platform thread. It is not generated by virtual threads.
Agents with the `can_support_virtual_threads` capability can enable the
VirtualThreadEnd event to be notified by newly started virtual threads.
The jvmti.xml update is:
diff --git a/src/hotspot/share/prims/jvmti.xml b/src/hotspot/share/prims/jvmti.xml
index 456876fbcb9..546b45ac86e 100644
--- a/src/hotspot/share/prims/jvmti.xml
+++ b/src/hotspot/share/prims/jvmti.xml
@@ -12937,16 +12940,10 @@ myInit() {
A thread start event is generated by a new thread before its initial
method executes.
<p/>
- This event is generated by platform threads. It is also generated by
- virtual threads when the capability
- <internallink id="jvmtiCapabilities.can_support_virtual_threads">
- <code>can_support_virtual_threads</code></internallink> is not enabled.
- Agents without support for virtual threads that enable this event will
- therefore be notified by all newly started threads.
+ This event is generated by platform thread. It is not generated by virtual threads.
<p/>
- If the capability <code>can_support_virtual_threads</code> is enabled then
- this event is not generated by virtual threads. Agents with support for
- virtual threads can enable <eventlink id="VirtualThreadStart"></eventlink>
+ Agents with the <code>can_support_virtual_threads</code> capability
+ can enable the <eventlink id="VirtualThreadStart"></eventlink> event
to be notified by newly started virtual threads.
<p/>
A platform thread may be listed in the array returned by
@@ -12984,16 +12981,10 @@ myInit() {
A thread end event is generated by a terminating thread after its
initial method has finished execution.
<p/>
- This event is generated by platform threads. It is also generated by
- virtual threads when the capability
- <internallink id="jvmtiCapabilities.can_support_virtual_threads">
- <code>can_support_virtual_threads</code></internallink> is not enabled.
- Agents without support for virtual threads that enable this event for
- all threads will therefore be notified by all terminating threads.
+ This event is generated by platform thread. It is not generated by virtual threads.
<p/>
- If the capability <code>can_support_virtual_threads</code> is enabled then
- this event is not generated by virtual threads. Agents with support for
- virtual threads can enable <eventlink id="VirtualThreadEnd"></eventlink>
+ Agents with the <code>can_support_virtual_threads</code> capability
+ can enable the <eventlink id="VirtualThreadSEnd"></eventlink> event
to be notified by terminating virtual threads.
<p/>
A platform thread may be listed in the array returned by
- csr of
-
JDK-8307399 get rid of compatibility ThreadStart/ThreadEnd events for virtual threads
-
- Resolved
-