Skip to content

Commit

Permalink
Unbounded GC Thread Pool Expansion for CRIU Restore
Browse files Browse the repository at this point in the history
Initial set of changes to expand the GC thread pool beyond the
dispatcher initialization done at VM startup. These changes are required
by the consumed OMR GC dispatcher/configuration APIs called for restore.

- Converted reference obj list iteration count from `gcThreadCount` to
`regionExtension->_maxListIndex`, this is more correct. This is the only
instance in the code where iteration implies the listCount from GC
thread count. This inference was not an issue as the lists are inited
based on the GC thread count, however now that the thread count may
change, it is incorrect to assume the list count from the thread count.
- Release restore thread's VM access for the duration of
`reinitializeGCThreadCountForRestore`

Signed-off-by: Salman Rana <salman.rana@ibm.com>
  • Loading branch information
RSalman committed Feb 6, 2023
1 parent 114c390 commit a7ee9b5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
5 changes: 3 additions & 2 deletions runtime/gc/gctable.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2022 IBM Corp. and others
* Copyright (c) 1991, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -260,6 +260,7 @@ J9MemoryManagerFunctions MemoryManagerFunctions = {
j9gc_ensureLockedSynchronizersIntegrity,
#if defined(J9VM_OPT_CRIU_SUPPORT)
j9gc_prepare_for_checkpoint,
j9gc_reinitialize_for_restore
j9gc_reinitialize_for_restore,
j9gc_reinitializeDefaults
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
};
3 changes: 2 additions & 1 deletion runtime/gc_base/gc_internal.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2022 IBM Corp. and others
* Copyright (c) 1991, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -262,6 +262,7 @@ extern J9_CFUNC void j9gc_ensureLockedSynchronizersIntegrity(J9VMThread *vmThrea
#if defined(J9VM_OPT_CRIU_SUPPORT)
extern J9_CFUNC void j9gc_prepare_for_checkpoint(J9VMThread *vmThread);
extern J9_CFUNC BOOLEAN j9gc_reinitialize_for_restore(J9VMThread *vmThread);
extern J9_CFUNC BOOLEAN j9gc_reinitializeDefaults(J9VMThread *vmThread);
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

/* J9VMFinalizeSupport*/
Expand Down
16 changes: 12 additions & 4 deletions runtime/gc_base/modronapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
#include "modronapi.hpp"
#include "modronopt.h"

#if defined(J9VM_OPT_CRIU_SUPPORT)
#include "Configuration.hpp"
#include "VerboseManager.hpp"
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#include "EnvironmentBase.hpp"
#include "GCExtensions.hpp"
#include "HeapMemorySnapshot.hpp"
Expand All @@ -54,6 +50,12 @@
#include "VMThreadListIterator.hpp"
#include "VMAccess.hpp"

#if defined(J9VM_OPT_CRIU_SUPPORT)
#include "Configuration.hpp"
#include "VerboseManager.hpp"
#include "vmaccess.h"
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

extern "C" {

UDATA
Expand Down Expand Up @@ -1123,7 +1125,13 @@ j9gc_reinitialize_for_restore(J9VMThread *vmThread)
MM_GCExtensionsBase *extensions = env->getExtensions();
MM_VerboseManagerBase *verboseGCManager = extensions->verboseGCManager;

j9gc_reinitializeDefaults(vmThread);

/* The checkpoint thread must release VM access for the duration of reinitializeGCThreadCountForRestore,
* since new GC threads could be started and the startup/attach of a new GC thread involves allocation and may trigger GC. */
releaseVMAccess(vmThread);
bool result = extensions->configuration->reinitializeGCThreadCountForRestore(env);
acquireVMAccess(vmThread);

if (NULL != verboseGCManager) {
/* Verbose gc reinit failure can be ignored, it is safe for restore to continue on. */
Expand Down
9 changes: 7 additions & 2 deletions runtime/gc_glue_java/ConfigurationDelegate.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 IBM Corp. and others
* Copyright (c) 2017, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -61,7 +61,7 @@ class MM_ConfigurationDelegate
* Member data and types
*/
private:
static const uintptr_t _maximumDefaultNumberOfGCThreads = 64;
uintptr_t _maximumDefaultNumberOfGCThreads = 64;
const MM_GCPolicy _gcPolicy;

protected:
Expand Down Expand Up @@ -354,6 +354,11 @@ class MM_ConfigurationDelegate
return _maximumDefaultNumberOfGCThreads;
}

void setMaxGCThreadCount(MM_EnvironmentBase* env, uintptr_t maxGCThreads)
{
_maximumDefaultNumberOfGCThreads = maxGCThreads;
}

MM_GCPolicy getGCPolicy() { return _gcPolicy; }

/**
Expand Down
5 changes: 2 additions & 3 deletions runtime/gc_glue_java/GlobalCollectorDelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2021 IBM Corp. and others
* Copyright (c) 2017, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -183,13 +183,12 @@ MM_GlobalCollectorDelegate::mainThreadGarbageCollectFinished(MM_EnvironmentBase
/* Check that all reference object lists are empty:
* lists must be processed at Mark and nothing should be flushed after
*/
UDATA listCount = _extensions->gcThreadCount;
MM_HeapRegionDescriptorStandard *region = NULL;
GC_HeapRegionIteratorStandard regionIterator(_extensions->heap->getHeapRegionManager());
while(NULL != (region = regionIterator.nextRegion())) {
/* check all lists for regions, they should be empty */
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
for (UDATA i = 0; i < listCount; i++) {
for (UDATA i = 0; i < regionExtension->_maxListIndex; i++) {
MM_ReferenceObjectList *list = &regionExtension->_referenceObjectLists[i];
Assert_MM_true(list->isWeakListEmpty());
Assert_MM_true(list->isSoftListEmpty());
Expand Down
21 changes: 20 additions & 1 deletion runtime/gc_modron_startup/mminit.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2022 IBM Corp. and others
* Copyright (c) 1991, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -3030,6 +3030,25 @@ gcInitializeDefaults(J9JavaVM* vm)
return J9VMDLLMAIN_FAILED;
}

#if defined(J9VM_OPT_CRIU_SUPPORT)
/**
* Initialize GC parameters for Restore.
* Initialize GC parameters with default values, parse the command line, massage values
* as required and finally verify values.
* @return
*/
BOOLEAN
j9gc_reinitializeDefaults(J9VMThread* vmThread)
{
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(vmThread);

/* TODO: Parse restore options to set gc thread count */
extensions->gcThreadCountForced = false;

return true;
}
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

#if defined(OMR_GC_CONCURRENT_SCAVENGER)
static void
hookAcquireVMAccess(J9HookInterface** hook, UDATA eventNum, void* voidEventData, void* userData)
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4540,6 +4540,7 @@ typedef struct J9MemoryManagerFunctions {
#if defined(J9VM_OPT_CRIU_SUPPORT)
void ( *j9gc_prepare_for_checkpoint)(struct J9VMThread *vmThread) ;
BOOLEAN ( *j9gc_reinitialize_for_restore)(struct J9VMThread *vmThread) ;
BOOLEAN ( *j9gc_reinitializeDefaults)(struct J9VMThread *vmThread) ;
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
} J9MemoryManagerFunctions;

Expand Down

0 comments on commit a7ee9b5

Please sign in to comment.