Skip to content

Commit

Permalink
Merge pull request #16855 from fengxue-IS/remove_vthreadlist
Browse files Browse the repository at this point in the history
Refactor VirtualThread synchronization design
  • Loading branch information
tajila authored Mar 31, 2023
2 parents 511fc3d + c50c552 commit 55b9267
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/
public class Continuation {
private long vmRef; /* J9VMContinuation */
protected Thread vthread; /* Parent VirtualThread */

private final ContinuationScope scope;
private final Runnable runnable;
Expand Down
93 changes: 48 additions & 45 deletions runtime/compiler/control/HookedByTheJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "mmhook.h"
#include "mmomrhook.h"
#include "vmaccess.h"
#include "HeapIteratorAPI.h"
#include "codegen/CodeGenerator.hpp"
#include "compile/CompilationTypes.hpp"
#include "compile/Method.hpp"
Expand Down Expand Up @@ -6597,8 +6598,46 @@ static UDATA jitReleaseCodeStackWalkFrame(J9VMThread *vmThread, J9StackWalkState
return J9_STACKWALK_KEEP_ITERATING;
}

static void jitReleaseCodeStackWalk(OMR_VMThread *omrVMThread, condYieldFromGCFunctionPtr condYield = NULL)
static jvmtiIterationControl jitWalkContinuationCallBack(J9VMThread *vmThread, J9MM_IterateObjectDescriptor *object, void *userData)
{
J9InternalVMFunctions *vmFuncs = vmThread->javaVM->internalVMFunctions;
J9VMContinuation *continuation = J9VMJDKINTERNALVMCONTINUATION_VMREF(vmThread, object->object);
if (NULL != continuation)
{
bool yieldHappened = false;
if ((continuation->dropFlags & 0x1) ? false : true)
{
J9StackWalkState walkState;
walkState.flags = J9_STACKWALK_ITERATE_HIDDEN_JIT_FRAMES | J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_SKIP_INLINES;
walkState.skipCount = 0;
walkState.frameWalkFunction = jitReleaseCodeStackWalkFrame;
vmFuncs->walkContinuationStackFrames(vmThread, continuation, &walkState);
continuation->dropFlags = 0x1;
condYieldFromGCFunctionPtr condYield = (condYieldFromGCFunctionPtr)userData;
yieldHappened = condYield(vmThread->omrVMThread, J9_GC_METRONOME_UTILIZATION_COMPONENT_JIT);
}

if (yieldHappened)
{
/* Stop the iteration, will resume later. */
return JVMTI_ITERATION_ABORT;
}
}
return JVMTI_ITERATION_CONTINUE;
}

static jvmtiIterationControl jitResetContinuationFlag(J9VMThread *vmThread, J9MM_IterateObjectDescriptor *object, void *userData)
{
J9VMContinuation *continuation = J9VMJDKINTERNALVMCONTINUATION_VMREF(vmThread, object->object);
if (NULL != continuation)
{
continuation->dropFlags = 0;
}

return JVMTI_ITERATION_CONTINUE;
}

static void jitReleaseCodeStackWalk(OMR_VMThread *omrVMThread, condYieldFromGCFunctionPtr condYield = NULL)
{
J9VMThread *vmThread = (J9VMThread *)omrVMThread->_language_vmthread;
J9JITConfig *jitConfig = vmThread->javaVM->jitConfig;
Expand All @@ -6613,6 +6652,7 @@ static void jitReleaseCodeStackWalk(OMR_VMThread *omrVMThread, condYieldFromGCFu
#if JAVA_SPEC_VERSION >= 19
J9JavaVM *vm = vmThread->javaVM;
J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
PORT_ACCESS_FROM_VMC(vmThread);
if (isRealTimeGC && !TR::Options::getCmdLineOptions()->getOption(TR_DisableIncrementalCCR))
{
bool yieldHappened = false;
Expand Down Expand Up @@ -6653,34 +6693,14 @@ static void jitReleaseCodeStackWalk(OMR_VMThread *omrVMThread, condYieldFromGCFu
}
while (yieldHappened);

if (NULL != vm->liveVirtualThreadList)
do
{
do
{
yieldHappened = false;
/* Skip the root, which is a dummy virtual thread and global ref. */
j9object_t walkVirtualThread = J9OBJECT_OBJECT_LOAD(vmThread, *(vm->liveVirtualThreadList), vm->virtualThreadLinkNextOffset);
while ((*(vm->liveVirtualThreadList) != walkVirtualThread) && !yieldHappened)
{
j9object_t contObject = (j9object_t)J9VMJAVALANGVIRTUALTHREAD_CONT(vmThread, walkVirtualThread);
J9VMContinuation *continuation = J9VMJDKINTERNALVMCONTINUATION_VMREF(vmThread, contObject);
if ((continuation->dropFlags & 0x1) ? false : true)
{
J9StackWalkState walkState;
walkState.flags = J9_STACKWALK_ITERATE_HIDDEN_JIT_FRAMES | J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_SKIP_INLINES;
walkState.skipCount = 0;
walkState.frameWalkFunction = jitReleaseCodeStackWalkFrame;
vmFuncs->walkContinuationStackFrames(vmThread, continuation, &walkState);
continuation->dropFlags |= 0x1;
yieldHappened = condYield(omrVMThread, J9_GC_METRONOME_UTILIZATION_COMPONENT_JIT);
}

if (!yieldHappened)
walkVirtualThread = J9OBJECT_OBJECT_LOAD(vmThread, walkVirtualThread, vm->virtualThreadLinkNextOffset);
}
}
while (yieldHappened);
vm->memoryManagerFunctions->j9gc_flush_nonAllocationCaches_for_walk(vm);
jvmtiIterationControl rc = vm->memoryManagerFunctions->j9mm_iterate_all_continuation_objects(vmThread, PORTLIB, 0, jitWalkContinuationCallBack, (void*)condYield);
if (JVMTI_ITERATION_ABORT == rc)
yieldHappened = true;
}
while (yieldHappened);
} else {
J9StackWalkState walkState;
walkState.flags = J9_STACKWALK_ITERATE_HIDDEN_JIT_FRAMES | J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_SKIP_INLINES;
Expand Down Expand Up @@ -6803,31 +6823,14 @@ static void jitReleaseCodeStackWalk(OMR_VMThread *omrVMThread, condYieldFromGCFu
do
{
thr->dropFlags &=0x0;
#if JAVA_SPEC_VERSION >= 19
if (NULL != thr->currentContinuation) {
thr->currentContinuation->dropFlags &=0x0;
}
#endif /* JAVA_SPEC_VERSION >= 19 */
thr = thr->linkNext;
}
while (thr != vmThread);
#if JAVA_SPEC_VERSION >= 19
if (NULL != vm->liveVirtualThreadList)
{
/* Skip the root, which is a dummy virtual thread and global ref. */
j9object_t walkVirtualThread = J9OBJECT_OBJECT_LOAD(vmThread, *(vm->liveVirtualThreadList), vm->virtualThreadLinkNextOffset);
while (*(vm->liveVirtualThreadList) != walkVirtualThread)
{
j9object_t contObject = (j9object_t)J9VMJAVALANGVIRTUALTHREAD_CONT(vmThread, walkVirtualThread);
J9VMContinuation *continuation = J9VMJDKINTERNALVMCONTINUATION_VMREF(vmThread, contObject);
continuation->dropFlags &= 0x0;
walkVirtualThread = J9OBJECT_OBJECT_LOAD(vmThread, walkVirtualThread, vm->virtualThreadLinkNextOffset);
}
}
vm->memoryManagerFunctions->j9mm_iterate_all_continuation_objects(vmThread, PORTLIB, 0, jitResetContinuationFlag, NULL);
#endif /* JAVA_SPEC_VERSION >= 19 */
}


}

static void jitHookReleaseCodeGlobalGCEnd(J9HookInterface **hook, UDATA eventNum, void *eventData, void *userData)
Expand Down
2 changes: 1 addition & 1 deletion runtime/gc_base/GCExtensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class MM_GCExtensions : public MM_GCExtensionsBase {
, minimumFreeSizeForSurvivor(DEFAULT_SURVIVOR_MINIMUM_FREESIZE)
, freeSizeThresholdForSurvivor(DEFAULT_SURVIVOR_THRESHOLD)
, recycleRemainders(true)
, continuationListOption(verify_continuation_list)
, continuationListOption(enable_continuation_list)
{
_typeId = __FUNCTION__;
}
Expand Down
Loading

0 comments on commit 55b9267

Please sign in to comment.