On Tue, 12 May 2026 06:22:33 GMT, Leonid Mesnik <[email protected]> wrote:
>> 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.
The JVMTI code that sends events is intentionally racy. The agents can do their
own synchronization if necessary.
The fragment below is kind of strange:
494 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
495
496 int i;
497
498 for (i = 1; i <= STEP_AMOUNT; i++) {
499
500 if (!nsk_jvmti_waitForSync(timeout))
501 return;
502
503 NSK_DISPLAY0("Check received events\n");
504
505 if (i < STEP_AMOUNT) {
506 showEventStatistics(i);
507 if (!checkEvents(i))
508 nsk_jvmti_setFailStatus();
509
510 if (!setCallBacks(i + 1)) { <== ???
511 return;
512 }
513 }
514
515 if (!nsk_jvmti_resumeSync())
516 return;
517 }
. . .
It seems, the `setCallBacks()` is never called with the step 1 while the
function is expecting step 1.
Do I read this code correctly?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/31128#discussion_r3238643575