Skip to content

Commit

Permalink
Merge pull request #18060 from babsingh/fix_scopedvaluecache
Browse files Browse the repository at this point in the history
Store J9VMThread->scopedValueCache in the Continuation object
  • Loading branch information
tajila committed Sep 1, 2023
2 parents 2b34667 + 92cb9c9 commit 2cbea41
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public class Continuation {
private long vmRef; /* J9VMContinuation */
protected Thread vthread; /* Parent VirtualThread */

/* The live thread's scopedValueCache is always kept in J9VMThread->scopedValueCache
* whereas the unmounted thread's scopedValueCache is stored in this field. This
* field is modified in ContinuationHelpers.hpp::swapFieldsWithContinuation. This
* assures a one to one mapping between a java.lang.Thread and scopedValueCache.
*/
private Object[] scopedValueCache;

private final ContinuationScope scope;
private final Runnable runnable;
private Continuation parent;
Expand Down
6 changes: 5 additions & 1 deletion runtime/oti/ContinuationHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class VM_ContinuationHelpers {
public:

static VMINLINE void
swapFieldsWithContinuation(J9VMThread *vmThread, J9VMContinuation *continuation, bool swapJ9VMthreadSavedRegisters = true)
swapFieldsWithContinuation(J9VMThread *vmThread, J9VMContinuation *continuation, j9object_t continuationObject, bool swapJ9VMthreadSavedRegisters = true)
{
/* Helper macro to swap fields between the two J9Class structs. */
#define SWAP_MEMBER(fieldName, fieldType, class1, class2) \
Expand Down Expand Up @@ -84,6 +84,10 @@ class VM_ContinuationHelpers {
}
threadELS->i2jState = tempI2J;
SWAP_MEMBER(oldEntryLocalStorage, J9VMEntryLocalStorage*, threadELS, continuation);

j9object_t scopedValueCache = J9VMJDKINTERNALVMCONTINUATION_SCOPEDVALUECACHE(vmThread, continuationObject);
J9VMJDKINTERNALVMCONTINUATION_SET_SCOPEDVALUECACHE(vmThread, continuationObject, vmThread->scopedValueCache);
vmThread->scopedValueCache = scopedValueCache;
}

static VMINLINE ContinuationState volatile *
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/vmconstantpool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
<fieldref class="jdk/internal/vm/Continuation" name="state" signature="J" versions="19-"/>
<fieldref class="jdk/internal/vm/Continuation" name="parent" signature="Ljdk/internal/vm/Continuation;" versions="19-"/>
<fieldref class="jdk/internal/vm/Continuation" name="vthread" signature="Ljava/lang/Thread;" versions="19-"/>
<fieldref class="jdk/internal/vm/Continuation" name="scopedValueCache" signature="[Ljava/lang/Object;" versions="19-"/>

<!-- Field references needed to support Foreign Linker API. -->
<fieldref class="openj9/internal/foreign/abi/InternalDowncallHandler" name="cifNativeThunkAddr" signature="J" flags="opt_openjdkFfi" versions="17-"/>
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/ContinuationHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ enterContinuation(J9VMThread *currentThread, j9object_t continuationObject)
currentThread->javaVM->memoryManagerFunctions->preMountContinuation(currentThread, continuationObject);
}

VM_ContinuationHelpers::swapFieldsWithContinuation(currentThread, continuation, started);
VM_ContinuationHelpers::swapFieldsWithContinuation(currentThread, continuation, continuationObject, started);

currentThread->currentContinuation = continuation;
/* Reset counters which determine if the current continuation is pinned. */
Expand Down Expand Up @@ -285,7 +285,7 @@ yieldContinuation(J9VMThread *currentThread, BOOLEAN isFinished)
}

currentThread->currentContinuation = NULL;
VM_ContinuationHelpers::swapFieldsWithContinuation(currentThread, continuation);
VM_ContinuationHelpers::swapFieldsWithContinuation(currentThread, continuation, continuationObject);

/* We need a full fence here to preserve happens-before relationship on PPC and other weakly
* ordered architectures since learning/reservation is turned on by default. Since we have the
Expand Down

0 comments on commit 2cbea41

Please sign in to comment.