Skip to content

Commit

Permalink
Integrate with downstream delegate restore reinit APIs
Browse files Browse the repository at this point in the history
Thread Local (env) Obj Buffers
Region Extensions Object Lists
Continue Salman's work, after fixing eclipse-openj9/openj9#17731
Also fix some comments.

Signed-off-by: [email protected]
  • Loading branch information
kangyining committed Feb 27, 2024
1 parent 1f5293c commit 94867ba
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 33 deletions.
9 changes: 9 additions & 0 deletions example/glue/ConfigurationDelegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ class MM_ConfigurationDelegate
*/
MM_GCPolicy getGCPolicy() { return _gcPolicy; }

#if defined(J9VM_OPT_CRIU_SUPPORT)
/**
* Reinitialize the language specific configuration structures.
*
* @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 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);
if (!walkEnv->reinitializeForRestore()) {
return false;
}
}

return true;
}
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
9 changes: 9 additions & 0 deletions gc/base/EnvironmentBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,15 @@ class MM_EnvironmentBase : public MM_BaseVirtual
MMINLINE MM_HeapRegionQueue *getRegionLocalFull() const { return _regionLocalFull; }
#endif /* OMR_GC_SEGREGATED_HEAP */

#if defined(J9VM_OPT_CRIU_SUPPORT)
/**
* Reinitialize the env's language specific object buffers based on the the number of restore GC threads.
*
* @return boolean indicating whether thread buffers were reinitialized successfully.
*/
MMINLINE bool reinitializeForRestore() { return _delegate.reinitializeForRestore(this); }
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

/**
* Create an EnvironmentBase object.
*/
Expand Down

0 comments on commit 94867ba

Please sign in to comment.