From 5035035b63319b007f69adbb90d103cb4dc02faf Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Wed, 8 Nov 2023 20:43:38 -0500 Subject: [PATCH] Update acquireVThreadInspector and enterVThreadTransitionCritical 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: https://github.com/eclipse-openj9/openj9/pull/18420#issuecomment-1802476741 Signed-off-by: Babneet Singh --- runtime/j9vm/javanextvmi.cpp | 4 ++-- runtime/vm/ContinuationHelpers.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/j9vm/javanextvmi.cpp b/runtime/j9vm/javanextvmi.cpp index 97f9fe4c450..a50c0b07665 100644 --- a/runtime/j9vm/javanextvmi.cpp +++ b/runtime/j9vm/javanextvmi.cpp @@ -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); } } diff --git a/runtime/vm/ContinuationHelpers.cpp b/runtime/vm/ContinuationHelpers.cpp index e88f7e7652c..2b5931b4fda 100644 --- a/runtime/vm/ContinuationHelpers.cpp +++ b/runtime/vm/ContinuationHelpers.cpp @@ -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 {