On Thu, 25 Sep 2025 21:43:46 GMT, Leonid Mesnik <[email protected]> wrote:

> The JVMTI spec says: 
> https://docs.oracle.com/en/java/javase/24/docs/specs/jvmti.html#VMDeath
> `The VM death event notifies the agent of the termination of the VM. No 
> events will occur after the VMDeath event.`
> 
> However, current implementation changes state and only after this start 
> disabling events.  
> 
> It might be not a conformance issue, because there is no way to get thread 
> state in the very beginning of event. 
> The main practical issue is that currently certain events are generated when 
> VM is becoming dead. So any function in event should check error against 
> JVMTI_PHASE_DEAD. We can easily trigger it by running tests with enabled 
> https://bugs.openjdk.org/browse/JDK-8352654
> 
> The proposed fix to disable all event generation and then post the last 
> (VMDeath) event. After this event is completed  change VM phase to death. 
> It's guaranteed that no any events are generated after VMDeath completion.
> 
> After this fix the VMDeath callback also can't generate any events. 
> The alternative is to disable events posting after VMDeath completion and 
> before changing VM state. However, seems it is still a gap between vm death 
> event completion and disabling events. So user can see events after VMDeath 
> completion.
> 
> It might be still possible also to wait while all currently executing  events 
> are completed. It is not required be specification, might add unneeded 
> complexity. So  I want to apply this fix first and then to check if we still 
> any problems.
> Then, I plan to wait with timeout until all current (and queued) jvmti events 
> are completed with some reasonable timeout.
> Currently, I haven't seen problems with this fix and  
> https://bugs.openjdk.org/browse/JDK-8352654.

It is a nice move to a right direction in fixing this long standing issue, so 
thank you for attacking it now! It should fix all WRONG_PHASE failures we are 
constantly observing with our mach5 test runs. We had and fixed a similar issue 
in the JDWP agent a long time ago, so a similar approach can be used here. 
Disabling all JVMTI events (except the VM_DEATH) is one part of the solution. 
Another part is that we should wait for all agent callbacks in progress to 
complete their work at the VM_DEATH point before the VM_DEATH event is posted. 
I see it has been already discussed in the PR comments. I'd suggest to consider 
to handle it here.

-------------

PR Review: https://git.openjdk.org/jdk/pull/27504#pullrequestreview-3287099388

Reply via email to