Skip to content

Commit

Permalink
Merge pull request #17461 from RSalman/rework-region-lists-init
Browse files Browse the repository at this point in the history
Rework RegionExtenstion/Object List Initialization
  • Loading branch information
amicic committed May 31, 2023
2 parents 69d50bc + 50231db commit 9797bca
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 87 deletions.
32 changes: 32 additions & 0 deletions runtime/gc_base/ContinuationObjectList.cpp
Expand Up @@ -45,6 +45,38 @@ MM_ContinuationObjectList::MM_ContinuationObjectList()
_typeId = __FUNCTION__;
}

MM_ContinuationObjectList *
MM_ContinuationObjectList::newInstanceArray(MM_EnvironmentBase *env, uintptr_t arrayElements)
{
MM_ContinuationObjectList *continuationObjectLists;

continuationObjectLists = (MM_ContinuationObjectList *)env->getForge()->allocate(sizeof(MM_ContinuationObjectList) * arrayElements, MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if (NULL != continuationObjectLists) {
new(continuationObjectLists) MM_ContinuationObjectList[arrayElements]();

for (uintptr_t index = 0; index < arrayElements; index++) {
continuationObjectLists[index].initialize(env);
}
}

return continuationObjectLists;
}

bool
MM_ContinuationObjectList::initialize(MM_EnvironmentBase *env)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);

setNextList(extensions->getContinuationObjectLists());
setPreviousList(NULL);
if (NULL != extensions->getContinuationObjectLists()) {
extensions->getContinuationObjectLists()->setPreviousList(this);
}
extensions->setContinuationObjectLists(this);

return true;
}

void
MM_ContinuationObjectList::addAll(MM_EnvironmentBase* env, j9object_t head, j9object_t tail)
{
Expand Down
11 changes: 11 additions & 0 deletions runtime/gc_base/ContinuationObjectList.hpp
Expand Up @@ -53,6 +53,17 @@ class MM_ContinuationObjectList : public MM_BaseNonVirtual
private:
protected:
public:
/**
* Allocate and initialize an array of MM_ContinuationObjectList instances, resembling the functionality of operator new[].
*
* @param env the current thread
* @param arrayElements the number of lists to create
*
* @return a pointer to the first list in the array, or NULL if we failed to allocate/init the array
*/
static MM_ContinuationObjectList *newInstanceArray(MM_EnvironmentBase *env, uintptr_t arrayElements);
bool initialize(MM_EnvironmentBase *env);

/**
* Add the specified linked list of objects to the buffer.
* The objects are expected to be in a NULL terminated linked
Expand Down
32 changes: 32 additions & 0 deletions runtime/gc_base/OwnableSynchronizerObjectList.cpp
Expand Up @@ -45,6 +45,38 @@ MM_OwnableSynchronizerObjectList::MM_OwnableSynchronizerObjectList()
_typeId = __FUNCTION__;
}

MM_OwnableSynchronizerObjectList *
MM_OwnableSynchronizerObjectList::newInstanceArray(MM_EnvironmentBase *env, uintptr_t arrayElements)
{
MM_OwnableSynchronizerObjectList *ownableSynchronizerObjectLists;

ownableSynchronizerObjectLists = (MM_OwnableSynchronizerObjectList *)env->getForge()->allocate(sizeof(MM_OwnableSynchronizerObjectList) * arrayElements, MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if (NULL != ownableSynchronizerObjectLists) {
new(ownableSynchronizerObjectLists) MM_OwnableSynchronizerObjectList[arrayElements]();

for (uintptr_t index = 0; index < arrayElements; index++) {
ownableSynchronizerObjectLists[index].initialize(env);
}
}

return ownableSynchronizerObjectLists;
}

bool
MM_OwnableSynchronizerObjectList::initialize(MM_EnvironmentBase *env)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);

setNextList(extensions->getOwnableSynchronizerObjectLists());
setPreviousList(NULL);
if (NULL != extensions->getOwnableSynchronizerObjectLists()) {
extensions->getOwnableSynchronizerObjectLists()->setPreviousList(this);
}
extensions->setOwnableSynchronizerObjectLists(this);

return true;
}

void
MM_OwnableSynchronizerObjectList::addAll(MM_EnvironmentBase* env, j9object_t head, j9object_t tail)
{
Expand Down
11 changes: 11 additions & 0 deletions runtime/gc_base/OwnableSynchronizerObjectList.hpp
Expand Up @@ -54,6 +54,17 @@ class MM_OwnableSynchronizerObjectList : public MM_BaseNonVirtual
private:
protected:
public:
/**
* Allocate and initialize an array of MM_OwnableSynchronizerObjectList instances, resembling the functionality of operator new[].
*
* @param env the current thread
* @param arrayElements the number of lists to create
*
* @return a pointer to the first list in the array, or NULL if we failed to allocate/init the array
*/
static MM_OwnableSynchronizerObjectList *newInstanceArray(MM_EnvironmentBase *env, uintptr_t arrayElements);
bool initialize(MM_EnvironmentBase *env);

/**
* Add the specified linked list of objects to the buffer.
* The objects are expected to be in a NULL terminated linked
Expand Down
17 changes: 17 additions & 0 deletions runtime/gc_base/ReferenceObjectList.cpp
Expand Up @@ -44,6 +44,23 @@ MM_ReferenceObjectList::MM_ReferenceObjectList()
_typeId = __FUNCTION__;
}

MM_ReferenceObjectList *
MM_ReferenceObjectList::newInstanceArray(MM_EnvironmentBase *env, uintptr_t arrayElements)
{
MM_ReferenceObjectList *referenceObjectLists;

referenceObjectLists = (MM_ReferenceObjectList *)env->getForge()->allocate(sizeof(MM_ReferenceObjectList) * arrayElements, MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if (NULL != referenceObjectLists) {
new(referenceObjectLists) MM_ReferenceObjectList[arrayElements]();

for (uintptr_t index = 0; index < arrayElements; index++) {
referenceObjectLists[index].initialize(env);
}
}

return referenceObjectLists;
}

void
MM_ReferenceObjectList::addAll(MM_EnvironmentBase* env, UDATA referenceObjectType, j9object_t head, j9object_t tail)
{
Expand Down
11 changes: 11 additions & 0 deletions runtime/gc_base/ReferenceObjectList.hpp
Expand Up @@ -51,6 +51,17 @@ class MM_ReferenceObjectList : public MM_BaseNonVirtual
private:
protected:
public:
/**
* Allocate and initialize an array of MM_ReferenceObjectList instances, resembling the functionality of operator new[].
*
* @param env the current thread
* @param arrayElements the number of lists to create
*
* @return a pointer to the first list in the array, or NULL if we failed to allocate/init the array
*/
static MM_ReferenceObjectList *newInstanceArray(MM_EnvironmentBase *env, uintptr_t arrayElements);
bool initialize(MM_EnvironmentBase *env) { return true; }

/**
* Add the specified linked list of objects to the buffer.
* The objects are expected to be in a NULL terminated linked
Expand Down
32 changes: 32 additions & 0 deletions runtime/gc_base/UnfinalizedObjectList.cpp
Expand Up @@ -42,6 +42,38 @@ MM_UnfinalizedObjectList::MM_UnfinalizedObjectList()
_typeId = __FUNCTION__;
}

MM_UnfinalizedObjectList *
MM_UnfinalizedObjectList::newInstanceArray(MM_EnvironmentBase *env, uintptr_t arrayElements)
{
MM_UnfinalizedObjectList *unfinalizedObjectLists;

unfinalizedObjectLists = (MM_UnfinalizedObjectList *)env->getForge()->allocate(sizeof(MM_UnfinalizedObjectList) * arrayElements, MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if (NULL != unfinalizedObjectLists) {
new(unfinalizedObjectLists) MM_UnfinalizedObjectList[arrayElements]();

for (uintptr_t index = 0; index < arrayElements; index++) {
unfinalizedObjectLists[index].initialize(env);
}
}

return unfinalizedObjectLists;
}

bool
MM_UnfinalizedObjectList::initialize(MM_EnvironmentBase *env)
{
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);

setNextList(extensions->unfinalizedObjectLists);
setPreviousList(NULL);
if (NULL != extensions->unfinalizedObjectLists) {
extensions->unfinalizedObjectLists->setPreviousList(this);
}
extensions->unfinalizedObjectLists = this;

return true;
}

void
MM_UnfinalizedObjectList::addAll(MM_EnvironmentBase* env, j9object_t head, j9object_t tail)
{
Expand Down
11 changes: 11 additions & 0 deletions runtime/gc_base/UnfinalizedObjectList.hpp
Expand Up @@ -50,6 +50,17 @@ class MM_UnfinalizedObjectList : public MM_BaseNonVirtual
private:
protected:
public:
/**
* Allocate and initialize an array of MM_UnfinalizedObjectList instances, resembling the functionality of operator new[].
*
* @param env the current thread
* @param arrayElements the number of lists to create
*
* @return a pointer to the first list in the array, or NULL if we failed to allocate/init the array
*/
static MM_UnfinalizedObjectList *newInstanceArray(MM_EnvironmentBase *env, uintptr_t arrayElements);
bool initialize(MM_EnvironmentBase *env);

/**
* Add the specified linked list of objects to the buffer.
* The objects are expected to be in a NULL terminated linked
Expand Down
93 changes: 6 additions & 87 deletions runtime/gc_glue_java/ConfigurationDelegate.hpp
Expand Up @@ -37,24 +37,12 @@
#include "GlobalAllocationManager.hpp"
#include "Heap.hpp"
#include "HeapRegionDescriptor.hpp"
#include "HeapRegionDescriptorStandardExtension.hpp"
#include "HeapRegionManager.hpp"
#include "ObjectAccessBarrier.hpp"
#include "ObjectAllocationInterface.hpp"
#include "StringTable.hpp"

#include "OwnableSynchronizerObjectList.hpp"
#include "ContinuationObjectList.hpp"
#include "ReferenceObjectList.hpp"
#include "UnfinalizedObjectList.hpp"

typedef struct MM_HeapRegionDescriptorStandardExtension {
uintptr_t _maxListIndex; /**< Max index for _*ObjectLists[index] */
MM_UnfinalizedObjectList *_unfinalizedObjectLists; /**< An array of lists of unfinalized objects in this region */
MM_OwnableSynchronizerObjectList *_ownableSynchronizerObjectLists; /**< An array of lists of ownable synchronizer objects in this region */
MM_ContinuationObjectList *_continuationObjectLists; /**< An array of lists of continuation objects in this region */
MM_ReferenceObjectList *_referenceObjectLists; /**< An array of lists of reference objects (i.e. weak/soft/phantom) in this region */
} MM_HeapRegionDescriptorStandardExtension;

class MM_ConfigurationDelegate
{
/*
Expand All @@ -72,68 +60,7 @@ class MM_ConfigurationDelegate
* Member functions
*/
private:
MM_HeapRegionDescriptorStandardExtension *
allocateHeapRegionDescriptorExtension(MM_EnvironmentBase *env, uintptr_t listCount) {
uintptr_t allocSize = sizeof(MM_HeapRegionDescriptorStandardExtension) + (listCount * (sizeof(MM_UnfinalizedObjectList) + sizeof(MM_OwnableSynchronizerObjectList) + sizeof(MM_ContinuationObjectList) + sizeof(MM_ReferenceObjectList)));

MM_HeapRegionDescriptorStandardExtension *regionExtension = (MM_HeapRegionDescriptorStandardExtension *)env->getForge()->allocate(allocSize, MM_AllocationCategory::FIXED, J9_GET_CALLSITE());

if (NULL == regionExtension) {
return NULL;
}

regionExtension->_maxListIndex = listCount;
regionExtension->_unfinalizedObjectLists = (MM_UnfinalizedObjectList *) ((uintptr_t)regionExtension + sizeof(MM_HeapRegionDescriptorStandardExtension));
regionExtension->_ownableSynchronizerObjectLists = (MM_OwnableSynchronizerObjectList *) (regionExtension->_unfinalizedObjectLists + listCount);
regionExtension->_continuationObjectLists = (MM_ContinuationObjectList *) (regionExtension->_ownableSynchronizerObjectLists + listCount);
regionExtension->_referenceObjectLists = (MM_ReferenceObjectList *) (regionExtension->_continuationObjectLists + listCount);

return regionExtension;
}

void
initalizeUnfinalizedObjectList(MM_EnvironmentBase *env, MM_UnfinalizedObjectList *list)
{
new(list) MM_UnfinalizedObjectList();
list->setNextList(_extensions->unfinalizedObjectLists);
list->setPreviousList(NULL);
if (NULL != _extensions->unfinalizedObjectLists) {
_extensions->unfinalizedObjectLists->setPreviousList(list);
}
_extensions->unfinalizedObjectLists = list;
}

void
initalizeOwnableSynchronizerObjectList(MM_EnvironmentBase *env, MM_OwnableSynchronizerObjectList *list)
{
new(list) MM_OwnableSynchronizerObjectList();
list->setNextList(_extensions->getOwnableSynchronizerObjectLists());
list->setPreviousList(NULL);
if (NULL != _extensions->getOwnableSynchronizerObjectLists()) {
_extensions->getOwnableSynchronizerObjectLists()->setPreviousList(list);
}
_extensions->setOwnableSynchronizerObjectLists(list);
}

void
initalizeContinuationObjectList(MM_EnvironmentBase *env, MM_ContinuationObjectList *list)
{
new(list) MM_ContinuationObjectList();
list->setNextList(_extensions->getContinuationObjectLists());
list->setPreviousList(NULL);
if (NULL != _extensions->getContinuationObjectLists()) {
_extensions->getContinuationObjectLists()->setPreviousList(list);
}
_extensions->setContinuationObjectLists(list);
}

void
initalizeReferenceObjectList(MM_EnvironmentBase *env, MM_ReferenceObjectList *list)
{
new(list) MM_ReferenceObjectList();
}
protected:

public:
bool
initialize(MM_EnvironmentBase *env, MM_GCWriteBarrierType writeBarrierType, MM_GCAllocationType allocationType)
Expand Down Expand Up @@ -233,19 +160,10 @@ class MM_ConfigurationDelegate
if (_extensions->isStandardGC()) {
uintptr_t listCount = _extensions->gcThreadCount;

MM_HeapRegionDescriptorStandardExtension *regionExtension = allocateHeapRegionDescriptorExtension(env, listCount);
if (NULL == regionExtension) {
region->_heapRegionDescriptorExtension = MM_HeapRegionDescriptorStandardExtension::newInstance(env, listCount);
if (NULL == region->_heapRegionDescriptorExtension) {
return false;
}

for (uintptr_t list = 0; list < listCount; list++) {
initalizeUnfinalizedObjectList(env, &regionExtension->_unfinalizedObjectLists[list]);
initalizeOwnableSynchronizerObjectList(env, &regionExtension->_ownableSynchronizerObjectLists[list]);
initalizeContinuationObjectList(env, &regionExtension->_continuationObjectLists[list]);
initalizeReferenceObjectList(env, &regionExtension->_referenceObjectLists[list]);
}

region->_heapRegionDescriptorExtension = regionExtension;
}

return true;
Expand All @@ -255,8 +173,9 @@ class MM_ConfigurationDelegate
teardownHeapRegionDescriptorExtension(MM_EnvironmentBase *env, MM_HeapRegionDescriptor *region)
{
if (env->getExtensions()->isStandardGC()) {
if (NULL != region->_heapRegionDescriptorExtension) {
env->getForge()->free(region->_heapRegionDescriptorExtension);
MM_HeapRegionDescriptorStandardExtension *regionExtension = (MM_HeapRegionDescriptorStandardExtension *)region->_heapRegionDescriptorExtension;
if (NULL != regionExtension) {
regionExtension->kill(env);
region->_heapRegionDescriptorExtension = NULL;
}
}
Expand Down

0 comments on commit 9797bca

Please sign in to comment.