Skip to content

Commit

Permalink
Use GC continuation list in walkAllStackFrames
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
  • Loading branch information
fengxue-IS committed Mar 14, 2023
1 parent 3b4f8c9 commit beb1d89
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions runtime/vm/ContinuationHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "vm_api.h"
#include "AtomicSupport.hpp"
#include "ContinuationHelpers.hpp"
#include "HeapIteratorAPI.h"
#include "OutOfLineINL.hpp"
#include "VMHelpers.hpp"

Expand Down Expand Up @@ -292,6 +293,19 @@ walkContinuationStackFrames(J9VMThread *currentThread, J9VMContinuation *continu
return rc;
}


jvmtiIterationControl
walkContinuationCallBack(J9VMThread *vmThread, J9MM_IterateObjectDescriptor *object, void *userData)
{
J9VMContinuation *continuation = J9VMJDKINTERNALVMCONTINUATION_VMREF(vmThread, object->object);
if (NULL != continuation) {
J9StackWalkState localWalkState = *(J9StackWalkState*)userData;
/* Walk non-null continuation's stack */
walkContinuationStackFrames(vmThread, continuation, &localWalkState);
}
return JVMTI_ITERATION_CONTINUE;
}

UDATA
walkAllStackFrames(J9VMThread *currentThread, J9StackWalkState *walkState)
{
Expand All @@ -309,47 +323,17 @@ walkAllStackFrames(J9VMThread *currentThread, J9StackWalkState *walkState)
localWalkState.walkThread = targetThread;
rc = vm->walkStackFrames(currentThread, &localWalkState);

if (NULL != targetThread->currentContinuation) {
localWalkState = *walkState;
walkContinuationStackFrames(currentThread, targetThread->currentContinuation, &localWalkState);
}
targetThread = targetThread->linkNext;
} while (targetThread != vm->mainThread);

/* Walk all contination stacks */
if (NULL != vm->liveVirtualThreadList) {
j9object_t rootNode = J9_JNI_UNWRAP_REFERENCE(vm->liveVirtualThreadList);
j9object_t nextVThread = J9OBJECT_OBJECT_LOAD(currentThread, rootNode, vm->virtualThreadLinkNextOffset);
J9VMContinuation *continuation = NULL;
while (nextVThread != rootNode) {
j9object_t cont = J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, nextVThread);
continuation = J9VMJDKINTERNALVMCONTINUATION_VMREF(currentThread, cont);
if (NULL != continuation) {
/* Reset localWalkState */
localWalkState = *walkState;
/* walk live continuation's stack */
rc = walkContinuationStackFrames(currentThread, continuation, &localWalkState);
}
nextVThread = J9OBJECT_OBJECT_LOAD(currentThread, nextVThread, vm->virtualThreadLinkNextOffset);
}
}
/* Alternate approach to rely on GC Continuation object iterator
GC_ContinuationIterator iter = getContinuationIterator();
J9VMContinuation *continuation = NULL;
while(NULL != iter) {
continuation = J9VMJDKINTERNALVMCONTINUATION_VMREF(currentThread, nextCont);
if (NULL != continuation) {
// Reset localWalkState
localWalkState = *walkState;
// walk live continuation's stack
rc = walkContinuationStackFrames(currentThread, continuation, &localWalkState);
if (J9_STACKWALK_RC_NONE != rc) {
goto exit;
}
}
iter = iter.next();
}
*/
/* Walk all live continuation stacks using the GC Continuation object iterator */
PORT_ACCESS_FROM_VMC(currentThread);
vm->memoryManagerFunctions->j9mm_iterate_all_continuation_objects(
currentThread,
PORTLIB,
0,
walkContinuationCallBack,
(void*)walkState);
return rc;
}
} /* extern "C" */

0 comments on commit beb1d89

Please sign in to comment.