Skip to content

Commit

Permalink
Merge pull request #16385 from RSalman/criu-final
Browse files Browse the repository at this point in the history
GC Thread Pool Tuning for CRIU
  • Loading branch information
tajila committed Dec 9, 2022
2 parents 9e897d3 + 0d73b3c commit 38c0a73
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 9 deletions.
13 changes: 10 additions & 3 deletions runtime/criusupport/criusupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "j9jclnls.h"
#include "jni.h"
#include "jvmtinls.h"
#include "modronnls.h"
#include "omrlinkedlist.h"
#include "omrthread.h"
#include "ut_j9criu.h"
Expand Down Expand Up @@ -550,9 +551,7 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,
Trc_CRIU_checkpoint_nano_times(currentThread, checkpointNanoTimeMonotonic, checkpointNanoUTCTime);
TRIGGER_J9HOOK_VM_PREPARING_FOR_CHECKPOINT(vm->hookInterface, currentThread);

/* trigger a GC to disclaim memory */
vm->memoryManagerFunctions->j9gc_modron_global_collect_with_overrides(currentThread, J9MMCONSTANT_EXPLICIT_GC_SYSTEM_GC);
vm->memoryManagerFunctions->j9gc_modron_global_collect_with_overrides(currentThread, J9MMCONSTANT_EXPLICIT_GC_PREPARE_FOR_CHECKPOINT);
vm->memoryManagerFunctions->j9gc_prepare_for_checkpoint(currentThread);

acquireSafeOrExcusiveVMAccess(currentThread, vmFuncs, safePoint);

Expand Down Expand Up @@ -651,6 +650,14 @@ Java_org_eclipse_openj9_criu_CRIUSupport_checkpointJVMImpl(JNIEnv *env,

releaseSafeOrExcusiveVMAccess(currentThread, vmFuncs, safePoint);

if (FALSE == vm->memoryManagerFunctions->j9gc_reinitialize_for_restore(currentThread)) {
currentExceptionClass = vm->checkpointState.criuJVMRestoreExceptionClass;
/* The only way for j9gc_reinitialize_for_restore to fail is if GC dispatcher failed to startup threads. */
nlsMsgFormat = j9nls_lookup_message(J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
J9NLS_GC_FAILED_TO_INSTANTIATE_TASK_DISPATCHER, NULL);
goto wakeJavaThreads;
}

VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_INTERNAL_HOOKS);

if (FALSE == vmFuncs->jvmRestoreHooks(currentThread)) {
Expand Down
6 changes: 5 additions & 1 deletion runtime/gc/gctable.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,9 @@ J9MemoryManagerFunctions MemoryManagerFunctions = {
j9gc_get_jit_string_dedup_policy,
j9gc_stringHashFn,
j9gc_stringHashEqualFn,
j9gc_ensureLockedSynchronizersIntegrity
j9gc_ensureLockedSynchronizersIntegrity,
#if defined(J9VM_OPT_CRIU_SUPPORT)
j9gc_prepare_for_checkpoint,
j9gc_reinitialize_for_restore
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
};
4 changes: 4 additions & 0 deletions runtime/gc_base/gc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ extern J9_CFUNC UDATA j9gc_arraylet_getLeafLogSize(J9JavaVM* javaVM);
extern J9_CFUNC void j9gc_get_CPU_times(J9JavaVM *javaVM, U_64* mainCpuMillis, U_64* workerCpuMillis, U_32* maxThreads, U_32* currentThreads);
extern J9_CFUNC void j9gc_ensureLockedSynchronizersIntegrity(J9VMThread *vmThread);

#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);
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

/* J9VMFinalizeSupport*/
extern J9_CFUNC void runFinalization(J9VMThread *vmThread);
Expand Down
27 changes: 27 additions & 0 deletions runtime/gc_base/modronapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include "modronapi.hpp"
#include "modronopt.h"

#if defined(J9VM_OPT_CRIU_SUPPORT)
#include "Configuration.hpp"
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#include "EnvironmentBase.hpp"
#include "GCExtensions.hpp"
#include "HeapMemorySnapshot.hpp"
Expand Down Expand Up @@ -1089,6 +1092,30 @@ j9gc_notifyGCOfClassReplacement(J9VMThread *vmThread, J9Class *oldClass, J9Class
}
}

#if defined(J9VM_OPT_CRIU_SUPPORT)
void
j9gc_prepare_for_checkpoint(J9VMThread *vmThread)
{
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(vmThread->omrVMThread);
MM_GCExtensionsBase *extensions = env->getExtensions();

/* trigger a GC to disclaim memory */
j9gc_modron_global_collect_with_overrides(vmThread, J9MMCONSTANT_EXPLICIT_GC_SYSTEM_GC);
j9gc_modron_global_collect_with_overrides(vmThread, J9MMCONSTANT_EXPLICIT_GC_PREPARE_FOR_CHECKPOINT);

extensions->configuration->adjustGCThreadCountOnCheckpoint(env);
}

BOOLEAN
j9gc_reinitialize_for_restore(J9VMThread *vmThread)
{
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(vmThread->omrVMThread);
MM_GCExtensionsBase *extensions = env->getExtensions();

return extensions->configuration->reinitializeGCThreadCountOnRestore(env);
}
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

/* JAZZ 90354 Temporarily move obsolete GC table exported functions, to be removed shortly. */
/* These calls remain, due to legacy symbol names - see Jazz 13097 for more information */
#if defined (OMR_GC_MODRON_CONCURRENT_MARK) || defined (J9VM_GC_VLHGC)
Expand Down
31 changes: 31 additions & 0 deletions runtime/gc_modron_startup/mmparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,38 @@ gcParseXXArguments(J9JavaVM *vm)
}
}

#if defined(J9VM_OPT_CRIU_SUPPORT)
{
IDATA index = -1;
IDATA result = 0;

PORT_ACCESS_FROM_JAVAVM(vm);

if (-1 != FIND_ARG_IN_VMARGS(EXACT_MEMORY_MATCH, "-XX:CheckpointGCThreads=", NULL)) {
result = option_set_to_opt_integer(vm, "-XX:CheckpointGCThreads=", &index, EXACT_MEMORY_MATCH, &extensions->checkpointGCthreadCount);
if (OPTION_OK != result) {
if (OPTION_MALFORMED == result) {
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_MUST_BE_NUMBER, "-XX:CheckpointGCThreads=");
} else {
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_VALUE_OVERFLOWED, "-XX:CheckpointGCThreads=");
}
goto _error;
}

if (0 == extensions->checkpointGCthreadCount) {
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_VALUE_MUST_BE_ABOVE, "-XX:CheckpointGCThreads=", (UDATA)0);
goto _error;
}
}
}
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

return 1;

#if defined(J9VM_OPT_CRIU_SUPPORT)
_error:
return 0;
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
}

/**
Expand Down
7 changes: 6 additions & 1 deletion runtime/gc_realtime/Scheduler.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2020 IBM Corp. and others
* Copyright (c) 1991, 2022 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 @@ -239,6 +239,11 @@ class MM_Scheduler : public MM_ParallelDispatcher

void collectorInitialized(MM_RealtimeGC *gc);

#if defined(J9VM_OPT_CRIU_SUPPORT)
virtual bool expandThreadPool(MM_EnvironmentBase *env) { return true; }
virtual void contractThreadPool(MM_EnvironmentBase *env, uintptr_t newThreadCount) {};
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

MM_Scheduler(MM_EnvironmentBase *env, omrsig_handler_fn handler, void* handler_arg, uintptr_t defaultOSStackSize) :
MM_ParallelDispatcher(env, handler, handler_arg, defaultOSStackSize),
_mutatorStartTimeInNanos(J9CONST64(0)),
Expand Down
4 changes: 4 additions & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4534,6 +4534,10 @@ typedef struct J9MemoryManagerFunctions {
UDATA ( *j9gc_stringHashFn)(void *key, void *userData);
BOOLEAN ( *j9gc_stringHashEqualFn)(void *leftKey, void *rightKey, void *userData);
void ( *j9gc_ensureLockedSynchronizersIntegrity)(struct J9VMThread *vmThread) ;
#if defined(J9VM_OPT_CRIU_SUPPORT)
void ( *j9gc_prepare_for_checkpoint)(struct J9VMThread *vmThread) ;
BOOLEAN ( *j9gc_reinitialize_for_restore)(struct J9VMThread *vmThread) ;
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
} J9MemoryManagerFunctions;

typedef struct J9InternalVMFunctions {
Expand Down
13 changes: 9 additions & 4 deletions runtime/vm/vmthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,15 @@ void threadCleanup(J9VMThread * vmThread, UDATA forkedByVM)
omrthread_monitor_exit(vm->vmThreadListMutex);

/* Do the java dance to indicate thread death */

acquireVMAccess(vmThread);
cleanUpAttachedThread(vmThread);
releaseVMAccess(vmThread);
#if defined(J9VM_OPT_CRIU_SUPPORT)
/* Dont allow non-java threads to run cleanup code in single thread mode */
if (!VM_CRIUHelpers::isJVMInSingleThreadMode(vm) && VM_VMHelpers::threadCanRunJavaCode(vmThread))
#endif
{
acquireVMAccess(vmThread);
cleanUpAttachedThread(vmThread);
releaseVMAccess(vmThread);
}

#if defined(OMR_GC_CONCURRENT_SCAVENGER) && defined(J9VM_ARCH_S390)
/* Concurrent scavenge enabled and JIT loaded implies running on supported h/w.
Expand Down

0 comments on commit 38c0a73

Please sign in to comment.