On Mon, 11 May 2026 23:15:37 GMT, Chris Plummer <[email protected]> wrote:

>> Please review following test fix that improve synchronization of compiled 
>> method load/unload events.
>> 
>> The CompiledMethodLoad/CompiledMethodUnload might be already executing while 
>> SetEventCallbacks removed their callbacks.
>> Thus they hit 'newEventCount' after setting it to zero and cause test to 
>> fail.
>> 
>> The simple monitor inside event doesn't help, because race might happen 
>> while callback is calling in VM or before it obtain lock.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003/em02t003.cpp
>  line 481:
> 
>> 479: 
>> 480:     /* Give some time to complete already processing cbNew* events. */
>> 481:     nsk_jvmti_sleep(100);
> 
> Are you sure this is always long enough? I would be nice if there was some 
> sort of synchronization that could be done to ensure that events in progress 
> have completed, but it seems that is not possible.

I think so, there are no java code invocations between setting and the actual 
code updating counters in jvmti callback.

The synchronization is impossible (I think),.
To be more detailed. There is a gap between reading callback and executing it 
in the.


      jvmtiEventCompiledMethodUnload callback = 
env->callbacks()->CompiledMethodUnload;
      if (callback != nullptr) {
        (*callback)(env->jvmti_external(), method, code_begin);
      }


the` env->callbacks()->CompiledMethodUnload` might be updated after read and 
before callback is invoked.
This is done while thread is already in native state, so it is not synced with 
callback setting.

The issue is known. The synchronization has major performance issues and not 
strictly required by JVMTi specification. 


However, it might be possible to put in the Monitor blocks the jvmt event 
handling and events resetting to minimize the gap.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/31128#discussion_r3224143070

Reply via email to