Skip to content

Commit

Permalink
Update acquireVThreadInspector and enterVThreadTransitionCritical
Browse files Browse the repository at this point in the history
VM is entered by the invocation of internalEnterVMFromJNI.
VM is exited by the invocation of internalExitVMToJNI

VM is always entered before acquireVThreadInspector and
enterVThreadTransitionCritical are invoked.

In these functions, the goal can be achieved by just releasing
and re-acquiring VM access. The new changes just release and
re-acquire VM access instead of exiting and entering the VM.
This has less overhead.

Addresses: eclipse-openj9#18420 (comment)

Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh committed Nov 9, 2023
1 parent b00a6cd commit 5035035
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions runtime/j9vm/javanextvmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ enterVThreadTransitionCritical(J9VMThread *currentThread, jobject thread)

while(!objectAccessBarrier.inlineMixedObjectCompareAndSwapU64(currentThread, threadObj, vm->virtualThreadInspectorCountOffset, 0, (U_64)-1)) {
/* Thread is being inspected or unmounted, wait. */
vmFuncs->internalExitVMToJNI(currentThread);
vmFuncs->internalReleaseVMAccess(currentThread);
VM_AtomicSupport::yieldCPU();
/* After wait, the thread may suspend here. */
vmFuncs->internalEnterVMFromJNI(currentThread);
vmFuncs->internalAcquireVMAccess(currentThread);
threadObj = J9_JNI_UNWRAP_REFERENCE(thread);
}
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/ContinuationHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,10 @@ acquireVThreadInspector(J9VMThread *currentThread, jobject thread, BOOLEAN spin)
vthreadInspectorCount = J9OBJECT_I64_LOAD(currentThread, threadObj, vm->virtualThreadInspectorCountOffset);
if (vthreadInspectorCount < 0) {
/* Thread is in transition, wait. */
vmFuncs->internalExitVMToJNI(currentThread);
vmFuncs->internalReleaseVMAccess(currentThread);
VM_AtomicSupport::yieldCPU();
/* After wait, the thread may suspend here. */
vmFuncs->internalEnterVMFromJNI(currentThread);
vmFuncs->internalAcquireVMAccess(currentThread);
if (spin) {
goto retry;
} else {
Expand Down

0 comments on commit 5035035

Please sign in to comment.