From c7a03382954555f931631d30d5d29a8354eaeb42 Mon Sep 17 00:00:00 2001 From: Lin Hu Date: Thu, 20 Oct 2022 17:08:55 -0400 Subject: [PATCH] Handle Continuation scan during Concurrent Scavenger and Metronome For CS and Metronome, due to synchronous nature of their barriers (they read the value of the slot and act on it immediately, for example they may evacuate object for CS and mark object for Metronome), We fully scan java stacks of related continuation during the virtual thread mount. Signed-off-by: Lin Hu --- runtime/gc/gctable.c | 4 +- runtime/gc_base/GCExtensions.cpp | 11 ++++ runtime/gc_base/GCExtensions.hpp | 2 + runtime/gc_base/ObjectAccessBarrier.hpp | 2 + runtime/gc_base/accessBarrier.cpp | 14 +++++ runtime/gc_base/gc_internal.h | 5 +- runtime/gc_base/modronapi.cpp | 14 ----- runtime/gc_base/module.xml | 4 +- runtime/gc_glue_java/ScavengerDelegate.hpp | 2 +- .../StandardAccessBarrier.cpp | 57 +++++++++++++------ .../StandardAccessBarrier.hpp | 18 +++++- runtime/gc_realtime/RealtimeAccessBarrier.cpp | 9 +++ runtime/gc_realtime/RealtimeAccessBarrier.hpp | 4 +- runtime/gc_vlhgc/VLHGCAccessBarrier.cpp | 9 +++ runtime/gc_vlhgc/VLHGCAccessBarrier.hpp | 4 +- runtime/oti/j9nonbuilder.h | 4 +- 16 files changed, 119 insertions(+), 44 deletions(-) diff --git a/runtime/gc/gctable.c b/runtime/gc/gctable.c index 706a3c7e4ba..45564804873 100644 --- a/runtime/gc/gctable.c +++ b/runtime/gc/gctable.c @@ -33,6 +33,8 @@ J9MemoryManagerFunctions MemoryManagerFunctions = { J9WriteBarrierBatch, J9WriteBarrierPostClass, J9WriteBarrierClassBatch, + preMountContinuation, + postUnmountContinuation, allocateMemoryForSublistFragment, j9gc_heap_free_memory, j9gc_heap_total_memory, @@ -251,8 +253,6 @@ J9MemoryManagerFunctions MemoryManagerFunctions = { j9mm_iterate_all_continuation_objects, ownableSynchronizerObjectCreated, continuationObjectCreated, - preMountContinuation, - postUnmountContinuation, j9gc_notifyGCOfClassReplacement, j9gc_get_jit_string_dedup_policy, j9gc_stringHashFn, diff --git a/runtime/gc_base/GCExtensions.cpp b/runtime/gc_base/GCExtensions.cpp index ea828b0fe9f..0c9eb17b522 100644 --- a/runtime/gc_base/GCExtensions.cpp +++ b/runtime/gc_base/GCExtensions.cpp @@ -37,6 +37,7 @@ #endif /* defined(OMR_GC_IDLE_HEAP_MANAGER) */ #include "MemorySpace.hpp" #include "MemorySubSpace.hpp" +#include "StandardAccessBarrier.hpp" #include "ObjectModel.hpp" #include "ReferenceChainWalkerMarkMap.hpp" #include "SublistPool.hpp" @@ -284,3 +285,13 @@ MM_GCExtensions::getContinuationObjectListsExternal(J9VMThread *vmThread) { return continuationObjectLists; } + + +void +MM_GCExtensions::registerScavenger(MM_Scavenger *scavenger) +{ + MM_GCExtensionsBase::registerScavenger(scavenger); + Assert_MM_true(isStandardGC()); + Assert_MM_true(isScavengerEnabled()); + ((MM_StandardAccessBarrier *)accessBarrier)->registerScavenger(scavenger); +} diff --git a/runtime/gc_base/GCExtensions.hpp b/runtime/gc_base/GCExtensions.hpp index ab07b504e42..9ff9d2d31d9 100644 --- a/runtime/gc_base/GCExtensions.hpp +++ b/runtime/gc_base/GCExtensions.hpp @@ -209,6 +209,8 @@ class MM_GCExtensions : public MM_GCExtensionsBase { void computeDefaultMaxHeapForJava(bool enableOriginalJDK8HeapSizeCompatibilityOption); + virtual void registerScavenger(MM_Scavenger *scavenger); + MMINLINE J9HookInterface** getHookInterface() { return J9_HOOK_INTERFACE(hookInterface); }; /** diff --git a/runtime/gc_base/ObjectAccessBarrier.hpp b/runtime/gc_base/ObjectAccessBarrier.hpp index 10a131812ac..a8b62aab64a 100644 --- a/runtime/gc_base/ObjectAccessBarrier.hpp +++ b/runtime/gc_base/ObjectAccessBarrier.hpp @@ -267,6 +267,8 @@ class MM_ObjectAccessBarrier : public MM_BaseVirtual virtual bool postObjectRead(J9VMThread *vmThread, J9Object *srcObject, fj9object_t *srcAddress); virtual bool postObjectRead(J9VMThread *vmThread, J9Class *srcClass, J9Object **srcAddress); + virtual void preMountContinuation(J9VMThread *vmThread, j9object_t contObject) {} + virtual void postUnmountContinuation(J9VMThread *vmThread, j9object_t contObject) {} /** * Return back true if object references are compressed * @return true, if object references are compressed diff --git a/runtime/gc_base/accessBarrier.cpp b/runtime/gc_base/accessBarrier.cpp index f8864fc7b7f..2a90131d6b6 100644 --- a/runtime/gc_base/accessBarrier.cpp +++ b/runtime/gc_base/accessBarrier.cpp @@ -835,5 +835,19 @@ j9gc_objaccess_jniDeleteGlobalReference(J9VMThread *vmThread, J9Object *referenc barrier->jniDeleteGlobalReference(vmThread, reference); } +void +preMountContinuation(J9VMThread *vmThread, j9object_t object) +{ + MM_ObjectAccessBarrier *barrier = MM_GCExtensions::getExtensions(vmThread->javaVM)->accessBarrier; + barrier->preMountContinuation(vmThread, object); +} + +void +postUnmountContinuation(J9VMThread *vmThread, j9object_t object) +{ + MM_ObjectAccessBarrier *barrier = MM_GCExtensions::getExtensions(vmThread->javaVM)->accessBarrier; + barrier->postUnmountContinuation(vmThread, object); +} + } /* extern "C" */ diff --git a/runtime/gc_base/gc_internal.h b/runtime/gc_base/gc_internal.h index ff5e8689a15..65694363a4b 100644 --- a/runtime/gc_base/gc_internal.h +++ b/runtime/gc_base/gc_internal.h @@ -67,6 +67,8 @@ extern J9_CFUNC UDATA alwaysCallReferenceArrayCopyHelper(J9JavaVM *javaVM); extern J9_CFUNC void J9WriteBarrierBatch(J9VMThread *vmThread, j9object_t destinationObject); extern J9_CFUNC IDATA j9gc_objaccess_indexableReadI16(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 index, UDATA isVolatile); extern J9_CFUNC void J9WriteBarrierPost(J9VMThread *vmThread, j9object_t destinationObject, j9object_t storedObject); +extern J9_CFUNC void preMountContinuation(J9VMThread *vmThread, j9object_t object); +extern J9_CFUNC void postUnmountContinuation(J9VMThread *vmThread, j9object_t object); extern J9_CFUNC UDATA j9gc_heap_total_memory(J9JavaVM *javaVM); extern J9_CFUNC UDATA j9gc_is_garbagecollection_disabled(J9JavaVM *javaVM); extern J9_CFUNC UDATA j9gc_allsupported_memorypools(J9JavaVM* javaVM); @@ -268,9 +270,6 @@ extern J9_CFUNC void* finalizeForcedClassLoaderUnload(J9VMThread *vmThread); extern J9_CFUNC UDATA ownableSynchronizerObjectCreated(J9VMThread *vmThread, j9object_t object); extern J9_CFUNC UDATA continuationObjectCreated(J9VMThread *vmThread, j9object_t object); -extern J9_CFUNC void preMountContinuation(J9VMThread *vmThread, j9object_t object); -extern J9_CFUNC void postUnmountContinuation(J9VMThread *vmThread, j9object_t object); - extern J9_CFUNC void j9gc_notifyGCOfClassReplacement(J9VMThread *vmThread, J9Class *originalClass, J9Class *replacementClass, UDATA isFastHCR); /* GuaranteedNurseryRange.cpp */ diff --git a/runtime/gc_base/modronapi.cpp b/runtime/gc_base/modronapi.cpp index 160e1913b03..e2a2b5dbee5 100644 --- a/runtime/gc_base/modronapi.cpp +++ b/runtime/gc_base/modronapi.cpp @@ -52,20 +52,6 @@ extern "C" { -void -preMountContinuation(J9VMThread *vmThread, j9object_t object) -{ - /* need read barrier to handle concurrent scavenger and gcpolicy:metronome case */ -} - -void -postUnmountContinuation(J9VMThread *vmThread, j9object_t object) -{ - /* Conservatively assume that via mutations of stack slots (which are not subject to access barriers), - * all post-write barriers have been triggered on this Continuation object, since it's been mounted. */ - vmThread->javaVM->memoryManagerFunctions->J9WriteBarrierBatch(vmThread, object); -} - UDATA j9gc_modron_global_collect(J9VMThread *vmThread) { diff --git a/runtime/gc_base/module.xml b/runtime/gc_base/module.xml index deea72b9ea7..b58e5bd441a 100644 --- a/runtime/gc_base/module.xml +++ b/runtime/gc_base/module.xml @@ -1,6 +1,6 @@