Ejemplo n.º 1
0
ObjectEntry *
GCConfigTest::createObject(const char *namePrefix, OMRGCObjectType objType, int32_t depth, int32_t nthInRow, uintptr_t size)
{
	OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib);
	ObjectEntry *objEntry = NULL;

	char *objName = (char *)omrmem_allocate_memory(MAX_NAME_LENGTH, OMRMEM_CATEGORY_MM);
	if (NULL == objName) {
		omrtty_printf("%s:%d Failed to allocate native memory.\n", __FILE__, __LINE__);
		goto done;
	}
	omrstr_printf(objName, MAX_NAME_LENGTH, "%s_%d_%d", namePrefix, depth, nthInRow);

	objEntry = find(objName);
	if (NULL != objEntry) {
#if defined(OMRGCTEST_DEBUG)
		omrtty_printf("Found object %s in object table.\n", objEntry->name);
#endif
		omrmem_free_memory(objName);
	} else {
		objEntry = allocateHelper(objName, size);
		if (NULL != objEntry) {
			/* Keep count of the new allocated non-garbage object size for garbage insertion. If the object exists in objectTable, its size is ignored. */
			if ((ROOT == objType) || (NORMAL == objType)) {
				gp.accumulatedSize += env->getExtensions()->objectModel.getSizeInBytesWithHeader(objEntry->objPtr);
			}
		} else {
			omrmem_free_memory(objName);
		}
	}

done:
	return objEntry;
}
Ejemplo n.º 2
0
int32_t
GCConfigTest::createObject(omrobjectptr_t *obj, char **objName, const char *namePrefix, OMRGCObjectType objType, int32_t depth, int32_t nthInRow, uintptr_t size)
{
	OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib);
	int32_t rt = 0;
	ObjectEntry *objEntry = NULL;

	*objName = (char *)omrmem_allocate_memory(MAX_NAME_LENGTH, OMRMEM_CATEGORY_MM);
	if (NULL == *objName) {
		rt = 1;
		omrtty_printf("%s:%d Failed to allocate native memory.\n", __FILE__, __LINE__);
		goto done;
	}
	omrstr_printf(*objName, MAX_NAME_LENGTH, "%s_%d_%d", namePrefix, depth, nthInRow);

	if (0 == objectTable.find(&objEntry, *objName)) {
#if defined(OMRGCTEST_DEBUG)
		omrtty_printf("Find object %s in hash table.\n", *objName);
#endif
		*obj = objEntry->objPtr;
	} else {
		rt = allocateHelper(obj, *objName, size);
		OMRGCTEST_CHECK_RT(rt);

		/* keep object in table */
		rt = objectTable.add(*objName, *obj, 0);
		OMRGCTEST_CHECK_RT(rt)

		/* Keep count of the new allocated non-garbage object size for garbage insertion. If the object exists in objectTable, its size is ignored. */
		if ((ROOT == objType) || (NORMAL == objType)) {
			gp.accumulatedSize += env->getExtensions()->objectModel.getSizeInBytesWithHeader(*obj);
		}
	}

done:
	return rt;
}