I am trying to use the extension event com.sun.hotspot.events.VirtualThreadMount.
I spent a large amount of time to figure out why my callback never got called, even though all JVMTI functions I used returned no errors.
With the sample code inJDK-8312174 I figured out adding a SetEventNotificationMode() call fixed it and the callback is called.
However, the documentation at https://docs.oracle.com/en/java/javase/21/docs/specs/jvmti.html#SetExtensionEventCallback (and also in jdk master) states:
SetExtensionEventCallback:
Sets the callback function for an extension event and enables the event.
Or, if the callback is NULL, disables the event.
Note that unlike standard events, setting the callback and enabling the event are a single operation.
The last sentence states clearly that there is no need to enable the event separately. But there is, the event is never emitted without it.
Other parts of the documentation make it pretty clear that "enabling an event" is using SetEventNotificationMode with JVMTI_ENABLE.
So this should either be clarified in the documentation or fixed in the code so that SetExtensionEventCallback actually enables the event, as it was always documented so far to do so.
---
As an aside, why are VirtualThreadMount/VirtualThreadUnmount extension and not regular events like VirtualThreadStart/VirtualThreadEnd?
It seems inconsistent and makes it much harder to use them (maybe that's the intention, if so why?).
I spent a large amount of time to figure out why my callback never got called, even though all JVMTI functions I used returned no errors.
With the sample code in
However, the documentation at https://docs.oracle.com/en/java/javase/21/docs/specs/jvmti.html#SetExtensionEventCallback (and also in jdk master) states:
SetExtensionEventCallback:
Sets the callback function for an extension event and enables the event.
Or, if the callback is NULL, disables the event.
Note that unlike standard events, setting the callback and enabling the event are a single operation.
The last sentence states clearly that there is no need to enable the event separately. But there is, the event is never emitted without it.
Other parts of the documentation make it pretty clear that "enabling an event" is using SetEventNotificationMode with JVMTI_ENABLE.
So this should either be clarified in the documentation or fixed in the code so that SetExtensionEventCallback actually enables the event, as it was always documented so far to do so.
---
As an aside, why are VirtualThreadMount/VirtualThreadUnmount extension and not regular events like VirtualThreadStart/VirtualThreadEnd?
It seems inconsistent and makes it much harder to use them (maybe that's the intention, if so why?).