コード例 #1
0
ファイル: GCConfigTest.cpp プロジェクト: DanHeidinga/omr
int32_t
GCConfigTest::removeObjectFromParentSlot(const char *name, omrobjectptr_t parentPtr)
{
	OMRPORT_ACCESS_FROM_OMRVM(exampleVM->_omrVM);
	int32_t rt = 1;
	GC_ObjectIterator objectIterator(exampleVM->_omrVM, parentPtr);
	GC_SlotObject *slotObject = NULL;

	ObjectEntry *objEntry;
	rt = objectTable.find(&objEntry, name);
	if (0 != rt) {
		omrtty_printf("%s:%d Could not find object %s in hash table.\n", __FILE__, __LINE__, name);
		goto done;
	}

	while (NULL != (slotObject = objectIterator.nextSlot())) {
		if (objEntry->objPtr == slotObject->readReferenceFromSlot()) {
			slotObject->writeReferenceToSlot(NULL);
			rt = 0;
			break;
		}
	}
	if (0 != rt) {
		omrtty_printf("%s:%d Failed to find object %s from its parent's slot.\n", __FILE__, __LINE__, name);
		goto done;
	}

#if defined(OMRGCTEST_DEBUG)
	omrtty_printf("Remove object %s from its parent's slot.\n", name);
#endif

done:
	return rt;
}
コード例 #2
0
ファイル: MarkingScheme.cpp プロジェクト: dinogun/omr
/**
 * Private internal. Called exclusively from completeScan();
 */
uintptr_t
MM_MarkingScheme::scanObject(MM_EnvironmentBase *env, omrobjectptr_t objectPtr)
{
	uintptr_t sizeToDo = UDATA_MAX;
	GC_ObjectScannerState objectScannerState;
	GC_ObjectScanner *objectScanner = _delegate.getObjectScanner(env, objectPtr, &objectScannerState, SCAN_REASON_PACKET, &sizeToDo);
	if (NULL != objectScanner) {
		bool isLeafSlot = false;
		GC_SlotObject *slotObject;
#if defined(OMR_GC_LEAF_BITS)
		while (NULL != (slotObject = objectScanner->getNextSlot(isLeafSlot))) {
#else /* OMR_GC_LEAF_BITS */
		while (NULL != (slotObject = objectScanner->getNextSlot())) {
#endif /* OMR_GC_LEAF_BITS */
			fixupForwardedSlot(slotObject);

			inlineMarkObjectNoCheck(env, slotObject->readReferenceFromSlot(), isLeafSlot);
		}
	}
	return sizeToDo;
}


/**
 * Scan until there are no more work packets to be processed.
 * @note This is a joining scan: a thread will not exit this method until
 * all threads have entered and all work packets are empty.
 */
void
MM_MarkingScheme::completeScan(MM_EnvironmentBase *env)
{
	do {
		omrobjectptr_t objectPtr = NULL;
		while (NULL != (objectPtr = (omrobjectptr_t )env->_workStack.pop(env))) {
			env->_markStats._bytesScanned += scanObject(env, objectPtr);
			env->_markStats._objectsScanned += 1;
		}
	} while (_workPackets->handleWorkPacketOverflow(env));
}

/****************************************
 * Marking Core Functionality
 ****************************************/

/**
 *  Initialization for Mark
 *  Actual startup for Mark procedure
 *  @param[in] env - passed Environment 
 *  @param[in] initMarkMap instruct should mark map be initialized too
 */
void
MM_MarkingScheme::markLiveObjectsInit(MM_EnvironmentBase *env, bool initMarkMap)
{
	workerSetupForGC(env);

	if(initMarkMap) {
		_markMap->initializeMarkMap(env);
		env->_currentTask->synchronizeGCThreads(env, UNIQUE_ID);
	}
}
コード例 #3
0
uintptr_t
MM_CollectorLanguageInterfaceImpl::markingScheme_scanObject(MM_EnvironmentBase *env, omrobjectptr_t objectPtr, MarkingSchemeScanReason reason)
{
	GC_ObjectIterator objectIterator(_omrVM, objectPtr);
	GC_SlotObject *slotObject = NULL;
	while (NULL != (slotObject = objectIterator.nextSlot())) {
		omrobjectptr_t slot = slotObject->readReferenceFromSlot();
		if (_markingScheme->isHeapObject(slot)) {
			_markingScheme->markObject(env, slot);
		}
	}
	return env->getExtensions()->objectModel.getSizeInBytesWithHeader(objectPtr);
}
コード例 #4
0
ファイル: GCConfigTest.cpp プロジェクト: DanHeidinga/omr
int32_t
GCConfigTest::processObjNode(pugi::xml_node node, const char *namePrefixStr, OMRGCObjectType objType, AttributeElem *numOfFieldsElem, AttributeElem *breadthElem, int32_t depth)
{
	OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib);

	int32_t rt = 0;
	OMR_VM *omrVMPtr = exampleVM->_omrVM;
	int32_t numOfParents = 0;

	/* Create objects and store them in the root table or the slot object based on objType. */
	if ((ROOT == objType) || (GARBAGE_ROOT == objType)) {
		for (int32_t i = 0; i < breadthElem->value; i++) {
			omrobjectptr_t obj;
			char *objName = NULL;

			uintptr_t sizeCalculated = numOfFieldsElem->value * sizeof(fomrobject_t) + sizeof(uintptr_t);
			rt = createObject(&obj, &objName, namePrefixStr, objType, 0, i, sizeCalculated);
			OMRGCTEST_CHECK_RT(rt);
			numOfFieldsElem = numOfFieldsElem->linkNext;

			/* Add object to root hash table. If it's the root of the garbage tree, temporarily keep it as root for allocating
			 * the rest of the tree. Remove it from the root set after the entire garbage tree is allocated.*/
			RootEntry rEntry;
			rEntry.name = objName;
			rEntry.rootPtr = obj;
			if (NULL == hashTableAdd(exampleVM->rootTable, &rEntry)) {
				rt = 1;
				omrtty_printf("%s:%d Failed to add new root entry to root table!\n", __FILE__, __LINE__);
				goto done;
			}

			/* insert garbage per node */
			if ((ROOT == objType) && (0 == strcmp(gp.frequency, "perObject"))) {
				rt = insertGarbage();
				OMRGCTEST_CHECK_RT(rt);
			}
		}
	} else if ((NORMAL == objType) || (GARBAGE_TOP == objType) || (GARBAGE_CHILD == objType)) {
		char parentName[MAX_NAME_LENGTH];
		omrstr_printf(parentName, MAX_NAME_LENGTH, "%s_%d_%d", node.parent().attribute("namePrefix").value(), 0, 0);
		ObjectEntry *parentEntry;
		rt = objectTable.find(&parentEntry, parentName);
		if (0 != rt) {
			omrtty_printf("%s:%d Could not find object %s in hash table.\n", __FILE__, __LINE__, parentName);
			goto done;
		}
		omrobjectptr_t parent = parentEntry->objPtr;
		GC_ObjectIterator objectIterator(omrVMPtr, parent);
		objectIterator.restore(parentEntry->numOfRef);
		for (int32_t i = 0; i < breadthElem->value; i++) {
			omrobjectptr_t obj;
			char *objName = NULL;
			uintptr_t sizeCalculated = numOfFieldsElem->value * sizeof(fomrobject_t) + sizeof(uintptr_t);
			rt = createObject(&obj, &objName, namePrefixStr, objType, 0, i, sizeCalculated);
			OMRGCTEST_CHECK_RT(rt);
			numOfFieldsElem = numOfFieldsElem->linkNext;
			GC_SlotObject *slotObject = NULL;
			if (NULL != (slotObject = objectIterator.nextSlot())) {
#if defined(OMRGCTEST_DEBUG)
				omrtty_printf("\tadd to slot of parent(%llu) %d\n", parent, parentEntry->numOfRef + i);
#endif
				/* Add object to parent's slot. If it's the top of the garbage tree, temporarily keep it in the slot until
				 * the rest of the tree is allocated. */
				slotObject->writeReferenceToSlot(obj);
			} else {
				rt = 1;
				omrtty_printf("%s:%d Invalid XML input: numOfFields defined for %s is not enough to hold all children references.\n", __FILE__, __LINE__, parentName);
				goto done;
			}

			/* insert garbage per node */
			if ((NORMAL == objType) && (0 == strcmp(gp.frequency, "perObject"))) {
				rt = insertGarbage();
				OMRGCTEST_CHECK_RT(rt);
			}
		}
		parentEntry->numOfRef += breadthElem->value;
	} else {
		rt = 1;
		goto done;
	}

	/* Create the rest of the tree, if any, defined with depth. First, we set the child object with correct objType. */
	if (ROOT == objType) {
		objType = NORMAL;
	} else if ((GARBAGE_TOP == objType) || (GARBAGE_ROOT == objType)) {
		objType = GARBAGE_CHILD;
	}
	numOfParents = breadthElem->value;
	breadthElem = breadthElem->linkNext;
	for (int32_t i = 1; i < depth; i++) {
		int32_t nthInRow = 0;
		for (int32_t j = 0; j < numOfParents; j++) {
			char parentName[MAX_NAME_LENGTH];
			omrstr_printf(parentName, sizeof(parentName), "%s_%d_%d", namePrefixStr, (i - 1), j);
			ObjectEntry *parentEntry;
			rt = objectTable.find(&parentEntry, parentName);
			if (0 != rt) {
				omrtty_printf("%s:%d Could not find object %s in hash table.\n", __FILE__, __LINE__, parentName);
				goto done;
			}
			omrobjectptr_t parent = parentEntry->objPtr;
			GC_ObjectIterator objectIterator(omrVMPtr, parent);
			objectIterator.restore(parentEntry->numOfRef);
			for (int32_t k = 0; k < breadthElem->value; k++) {
				omrobjectptr_t obj;
				char *objName = NULL;
				uintptr_t sizeCalculated = numOfFieldsElem->value * sizeof(fomrobject_t) + sizeof(uintptr_t);
				rt = createObject(&obj, &objName, namePrefixStr, objType, i, nthInRow, sizeCalculated);
				OMRGCTEST_CHECK_RT(rt);
				numOfFieldsElem = numOfFieldsElem->linkNext;
				nthInRow += 1;
				GC_SlotObject *slotObject = NULL;
				if (NULL != (slotObject = objectIterator.nextSlot())) {
#if defined(OMRGCTEST_DEBUG)
					omrtty_printf("\tadd to parent(%llu) slot %d.\n", parent, parentEntry->numOfRef + k);
#endif
					slotObject->writeReferenceToSlot(obj);
				} else {
					rt = 1;
					omrtty_printf("%s:%d Invalid XML input: numOfFields defined for %s is not enough to hold all children references.\n", __FILE__, __LINE__, parentName);
					goto done;
				}

				/* insert garbage per node */
				if ((NORMAL == objType) && (0 == strcmp(gp.frequency, "perObject"))) {
					rt = insertGarbage();
					OMRGCTEST_CHECK_RT(rt);
				}
			}
			parentEntry->numOfRef += breadthElem->value;
		}
		numOfParents = nthInRow;
		breadthElem = breadthElem->linkNext;
	}

done:
	return rt;
}
コード例 #5
0
ファイル: GCConfigTest.cpp プロジェクト: DanHeidinga/omr
int32_t
GCConfigTest::createFixedSizeTree(omrobjectptr_t *rootObj, const char *namePrefixStr, OMRGCObjectType objType, uintptr_t totalSize, uintptr_t objSize, int32_t breadth)
{
	OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib);
	int32_t rt = 0;
	OMR_VM *omrVMPtr = exampleVM->_omrVM;
	int32_t depth = 1;
	int32_t numOfParents = 1;
	uintptr_t bytesLeft = totalSize;

	if (bytesLeft < objSize) {
		objSize = bytesLeft;
		if (objSize <= 0) {
			return rt;
		}
	}

	/* allocate the root object */
	char *rootObjName = NULL;
	rt = createObject(rootObj, &rootObjName, namePrefixStr, objType, 0, 0, objSize);
	OMRGCTEST_CHECK_RT(rt);
	bytesLeft -= objSize;

	/* Add object to root hash table. If it's the root of the garbage tree, temporarily keep it as root for allocating
	 * the rest of the tree. Remove it from the root set after the entire garbage tree is allocated.*/
	RootEntry rEntry;
	rEntry.name = rootObjName;
	rEntry.rootPtr = *rootObj;
	if (NULL == hashTableAdd(exampleVM->rootTable, &rEntry)) {
		rt = 1;
		omrtty_printf("%s:%d Failed to add new root entry to root table!\n", __FILE__, __LINE__);
		goto done;
	}

	/* create the rest of the tree */
	if (ROOT == objType) {
		objType = NORMAL;
	} else if ((GARBAGE_TOP == objType) || (GARBAGE_ROOT == objType)) {
		objType = GARBAGE_CHILD;
	}
	while (bytesLeft > 0) {
		int32_t nthInRow = 0;
		for (int32_t j = 0; j < numOfParents; j++) {
			char parentName[MAX_NAME_LENGTH];
			omrstr_printf(parentName, sizeof(parentName), "%s_%d_%d", namePrefixStr, (depth - 1), j);
			ObjectEntry *parentEntry;
			rt = objectTable.find(&parentEntry, parentName);
			if (0 != rt) {
				omrtty_printf("%s:%d Could not find object %s in hash table.\n", __FILE__, __LINE__, parentName);
				goto done;
			}
			omrobjectptr_t parent = parentEntry->objPtr;
			GC_ObjectIterator objectIterator(omrVMPtr, parent);
			objectIterator.restore(parentEntry->numOfRef);
			for (int32_t k = 0; k < breadth; k++) {
				if (bytesLeft < objSize) {
					objSize = bytesLeft;
					if (objSize <= 0) {
						goto done;
					}
				}
				omrobjectptr_t obj;
				char *objName = NULL;
				rt = createObject(&obj, &objName, namePrefixStr, objType, depth, nthInRow, objSize);
				OMRGCTEST_CHECK_RT(rt);
				bytesLeft -= objSize;
				nthInRow += 1;
				GC_SlotObject *slotObject = NULL;
				if (NULL != (slotObject = objectIterator.nextSlot())) {
#if defined(OMRGCTEST_DEBUG)
					omrtty_printf("\tadd to parent(%llu) slot %d.\n", parent, parentEntry->numOfRef + k);
#endif
					slotObject->writeReferenceToSlot(obj);
				} else {
					rt = 1;
					omrtty_printf("%s:%d Invalid XML input: numOfFields defined for %s is not enough to hold all children references.\n", __FILE__, __LINE__, parentName);
					goto done;
				}
			}
			parentEntry->numOfRef += breadth;
		}
		numOfParents = nthInRow;
		depth += 1;
	}

done:
	return rt;
}