Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate GC Restore With Delegate Reinit APIs #7274

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions example/glue/ConfigurationDelegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class MM_ConfigurationDelegate
* allow the heap to grow to a stable operational size. Frequent transitions true->false will limit the quality
* of heap fragmentation stats.
*
* @param[in] env The environment for the calling thread.
* @param[in] env The environment for the calling thread
* @return true to allow heap fragmentation tracking to start or continue
*/
bool canCollectFragmentationStats(MM_EnvironmentBase *env) { return false; }
Expand All @@ -175,6 +175,16 @@ class MM_ConfigurationDelegate
*/
MM_GCPolicy getGCPolicy() { return _gcPolicy; }

#if defined(J9VM_OPT_CRIU_SUPPORT)
/**
* Reinitialize the language specific configuration structures.
*
* @param[in] env The environment for the calling thread
* @return boolean indicating whether configuration reinitialization was successful
*/
bool reinitializeForRestore(MM_EnvironmentBase *env) { return true; }
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

#if defined(J9VM_OPT_CRIU_SUPPORT)
/**
* If checkpointGCthreadCount is specified by the user, it is verified
Expand All @@ -189,7 +199,7 @@ class MM_ConfigurationDelegate

/**
* Constructor.
* @param gcPolicy The GC policy preselected for the GC configuration.
* @param gcPolicy The GC policy preselected for the GC configuration
*/
MM_ConfigurationDelegate(MM_GCPolicy gcPolicy)
: _gcPolicy(gcPolicy)
Expand Down
9 changes: 9 additions & 0 deletions example/glue/EnvironmentDelegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ class MM_EnvironmentDelegate
uintptr_t getAllocatedSizeInsideTLH() { return 0; }
#endif /* OMR_GC_THREAD_LOCAL_HEAP */

#if defined(J9VM_OPT_CRIU_SUPPORT)
/**
* Reinitialize the env's language specific structures.
*
* @return boolean indicating whether the thread env was successfully reinitialized
*/
bool reinitializeForRestore() { return true; }
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

MM_EnvironmentDelegate()
: _env(NULL)
{ }
Expand Down
79 changes: 46 additions & 33 deletions gc/base/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@
#endif /* defined(OMR_GC_SEGREGATED_HEAP) */

void
MM_Configuration::kill(MM_EnvironmentBase* env)
MM_Configuration::kill(MM_EnvironmentBase *env)
{
tearDown(env);
env->getForge()->free(this);
}

bool
MM_Configuration::initialize(MM_EnvironmentBase* env)
MM_Configuration::initialize(MM_EnvironmentBase *env)
{
bool result = false;

if (initializeRegionSize(env) && initializeArrayletLeafSize(env)) {
if (_delegate.initialize(env, _writeBarrierType, _allocationType)) {
MM_GCExtensionsBase* extensions = env->getExtensions();
MM_GCExtensionsBase *extensions = env->getExtensions();
/* excessivegc is enabled by default */
if (!extensions->excessiveGCEnabled._wasSpecified) {
extensions->excessiveGCEnabled._valueSpecified = true;
Expand All @@ -84,7 +84,7 @@ MM_Configuration::initialize(MM_EnvironmentBase* env)
void
MM_Configuration::tearDown(MM_EnvironmentBase* env)
{
MM_GCExtensionsBase* extensions = env->getExtensions();
MM_GCExtensionsBase *extensions = env->getExtensions();

/* DefaultMemorySpace needs to be killed before
* ext->heap is freed in MM_Configuration::tearDown. */
Expand Down Expand Up @@ -152,8 +152,8 @@ MM_Configuration::tearDown(MM_EnvironmentBase* env)
void
MM_Configuration::destroyCollectors(MM_EnvironmentBase* env)
{
MM_GCExtensionsBase* extensions = env->getExtensions();
MM_Collector* collector = extensions->getGlobalCollector();
MM_GCExtensionsBase *extensions = env->getExtensions();
MM_Collector *collector = extensions->getGlobalCollector();

if (NULL != collector) {
collector->kill(env);
Expand All @@ -170,9 +170,9 @@ MM_Configuration::destroyCollectors(MM_EnvironmentBase* env)
* @return env The newly allocated env or NULL
*/
MM_EnvironmentBase*
MM_Configuration::createEnvironment(MM_GCExtensionsBase* extensions, OMR_VMThread* omrVMThread)
MM_Configuration::createEnvironment(MM_GCExtensionsBase *extensions, OMR_VMThread *omrVMThread)
{
MM_EnvironmentBase* env = allocateNewEnvironment(extensions, omrVMThread);
MM_EnvironmentBase *env = allocateNewEnvironment(extensions, omrVMThread);
if (NULL != env) {
if (!initializeEnvironment(env)) {
env->kill();
Expand All @@ -191,7 +191,7 @@ MM_Configuration::createEnvironment(MM_GCExtensionsBase* extensions, OMR_VMThrea
* @param env The environment to initialize
*/
bool
MM_Configuration::initializeEnvironment(MM_EnvironmentBase* env)
MM_Configuration::initializeEnvironment(MM_EnvironmentBase *env)
{
bool result = false;

Expand Down Expand Up @@ -221,15 +221,15 @@ MM_Configuration::initializeEnvironment(MM_EnvironmentBase* env)
}

void
MM_Configuration::defaultMemorySpaceAllocated(MM_GCExtensionsBase* extensions, void* defaultMemorySpace)
MM_Configuration::defaultMemorySpaceAllocated(MM_GCExtensionsBase *extensions, void *defaultMemorySpace)
{
/* do nothing */
}

MM_Heap*
MM_Configuration::createHeap(MM_EnvironmentBase* env, uintptr_t heapBytesRequested)
MM_Configuration::createHeap(MM_EnvironmentBase *env, uintptr_t heapBytesRequested)
{
MM_GCExtensionsBase* extensions = env->getExtensions();
MM_GCExtensionsBase *extensions = env->getExtensions();

if (NULL == extensions->memoryManager) {
extensions->memoryManager = MM_MemoryManager::newInstance(env);
Expand All @@ -245,7 +245,7 @@ MM_Configuration::createHeap(MM_EnvironmentBase* env, uintptr_t heapBytesRequest
}
}

MM_Heap* heap = createHeapWithManager(env, heapBytesRequested, extensions->heapRegionManager);
MM_Heap *heap = createHeapWithManager(env, heapBytesRequested, extensions->heapRegionManager);
if (NULL != heap) {
if (!heap->initializeHeapRegionManager(env, extensions->heapRegionManager)) {
heap->kill(env);
Expand Down Expand Up @@ -276,10 +276,10 @@ MM_Configuration::createHeap(MM_EnvironmentBase* env, uintptr_t heapBytesRequest
}

bool
MM_Configuration::initializeRunTimeObjectAlignmentAndCRShift(MM_EnvironmentBase* env, MM_Heap* heap)
MM_Configuration::initializeRunTimeObjectAlignmentAndCRShift(MM_EnvironmentBase *env, MM_Heap *heap)
{
MM_GCExtensionsBase* extensions = env->getExtensions();
OMR_VM* omrVM = env->getOmrVM();
MM_GCExtensionsBase *extensions = env->getExtensions();
OMR_VM *omrVM = env->getOmrVM();

#if defined(OMR_GC_COMPRESSED_POINTERS)
if (env->compressObjectReferences()) {
Expand Down Expand Up @@ -334,7 +334,7 @@ MM_Configuration::initializeRunTimeObjectAlignmentAndCRShift(MM_EnvironmentBase*
}

void
MM_Configuration::prepareParameters(OMR_VM* omrVM,
MM_Configuration::prepareParameters(OMR_VM *omrVM,
uintptr_t minimumSpaceSize,
uintptr_t minimumNewSpaceSize,
uintptr_t initialNewSpaceSize,
Expand All @@ -344,10 +344,10 @@ MM_Configuration::prepareParameters(OMR_VM* omrVM,
uintptr_t maximumTenureSpaceSize,
uintptr_t memoryMax,
uintptr_t tenureFlags,
MM_InitializationParameters* parameters)
MM_InitializationParameters *parameters)
{
MM_GCExtensionsBase* extensions = MM_GCExtensionsBase::getExtensions(omrVM);
MM_Heap* heap = extensions->heap;
MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(omrVM);
MM_Heap *heap = extensions->heap;
uintptr_t alignment = getAlignment(extensions, _alignmentType);

uintptr_t maximumHeapSize = MM_Math::roundToFloor(alignment, heap->getMaximumMemorySize());
Expand Down Expand Up @@ -381,7 +381,7 @@ MM_Configuration::prepareParameters(OMR_VM* omrVM,
}

uintptr_t
MM_Configuration::getAlignment(MM_GCExtensionsBase* extensions, MM_AlignmentType type)
MM_Configuration::getAlignment(MM_GCExtensionsBase *extensions, MM_AlignmentType type)
{
uintptr_t result = 0;

Expand All @@ -399,10 +399,10 @@ MM_Configuration::getAlignment(MM_GCExtensionsBase* extensions, MM_AlignmentType
}

bool
MM_Configuration::initializeRegionSize(MM_EnvironmentBase* env)
MM_Configuration::initializeRegionSize(MM_EnvironmentBase *env)
{
bool result = true;
MM_GCExtensionsBase* extensions = env->getExtensions();
MM_GCExtensionsBase *extensions = env->getExtensions();
uintptr_t regionSize = extensions->regionSize;
if (0 == regionSize) {
regionSize = _defaultRegionSize;
Expand All @@ -422,10 +422,10 @@ MM_Configuration::initializeRegionSize(MM_EnvironmentBase* env)
}

bool
MM_Configuration::initializeArrayletLeafSize(MM_EnvironmentBase* env)
MM_Configuration::initializeArrayletLeafSize(MM_EnvironmentBase *env)
{
bool result = true;
OMR_VM* omrVM = env->getOmrVM();
OMR_VM *omrVM = env->getOmrVM();
if (UDATA_MAX != _defaultArrayletLeafSize) {
uintptr_t arrayletLeafSize = (0 != _defaultArrayletLeafSize) ? _defaultArrayletLeafSize : env->getExtensions()->regionSize;
uintptr_t shift = calculatePowerOfTwoShift(env, arrayletLeafSize);
Expand All @@ -443,9 +443,9 @@ MM_Configuration::initializeArrayletLeafSize(MM_EnvironmentBase* env)
}

void
MM_Configuration::initializeGCThreadCount(MM_EnvironmentBase* env)
MM_Configuration::initializeGCThreadCount(MM_EnvironmentBase *env)
{
MM_GCExtensionsBase* extensions = env->getExtensions();
MM_GCExtensionsBase *extensions = env->getExtensions();

if (!extensions->gcThreadCountSpecified) {
extensions->gcThreadCount = defaultGCThreadCount(env);
Expand All @@ -456,7 +456,7 @@ MM_Configuration::initializeGCThreadCount(MM_EnvironmentBase* env)
}

uintptr_t
MM_Configuration::defaultGCThreadCount(MM_EnvironmentBase* env)
MM_Configuration::defaultGCThreadCount(MM_EnvironmentBase *env)
{
OMRPORT_ACCESS_FROM_OMRPORT(env->getPortLibrary());
uintptr_t threadCount = omrsysinfo_get_number_CPUs_by_type(OMRPORT_CPU_TARGET);
Expand All @@ -470,7 +470,7 @@ MM_Configuration::defaultGCThreadCount(MM_EnvironmentBase* env)
}

void
MM_Configuration::initializeGCParameters(MM_EnvironmentBase* env)
MM_Configuration::initializeGCParameters(MM_EnvironmentBase *env)
{
MM_GCExtensionsBase* extensions = env->getExtensions();

Expand Down Expand Up @@ -518,22 +518,22 @@ MM_Configuration::initializeGCParameters(MM_EnvironmentBase* env)
}

bool
MM_Configuration::initializeNUMAManager(MM_EnvironmentBase* env)
MM_Configuration::initializeNUMAManager(MM_EnvironmentBase *env)
{
return env->getExtensions()->_numaManager.recacheNUMASupport(env);
}

MM_ParallelDispatcher *
MM_Configuration::createParallelDispatcher(MM_EnvironmentBase* env, omrsig_handler_fn handler, void* handler_arg, uintptr_t defaultOSStackSize)
MM_Configuration::createParallelDispatcher(MM_EnvironmentBase *env, omrsig_handler_fn handler, void *handler_arg, uintptr_t defaultOSStackSize)
{
return MM_ParallelDispatcher::newInstance(env, handler, handler_arg, defaultOSStackSize);
}

#if defined(J9VM_OPT_CRIU_SUPPORT)
bool
MM_Configuration::reinitializeForRestore(MM_EnvironmentBase* env)
MM_Configuration::reinitializeForRestore(MM_EnvironmentBase *env)
{
MM_GCExtensionsBase* extensions = env->getExtensions();
MM_GCExtensionsBase *extensions = env->getExtensions();

/* The initialization of the GC thread count can only happen if it is not enforced by the user. */
initializeGCThreadCount(env);
Expand All @@ -549,6 +549,19 @@ MM_Configuration::reinitializeForRestore(MM_EnvironmentBase* env)

initializeGCParameters(env);

if (!_delegate.reinitializeForRestore(env)) {
return false;
}

OMR_VMThread *walkThread = NULL;
GC_OMRVMThreadListIterator threadListIterator(env->getOmrVM());
while (NULL != (walkThread = threadListIterator.nextOMRVMThread())) {
MM_EnvironmentBase *walkEnv = MM_EnvironmentBase::getEnvironment(walkThread);
babsingh marked this conversation as resolved.
Show resolved Hide resolved
if (!walkEnv->reinitializeForRestore()) {
return false;
}
}

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