コード例 #1
0
ファイル: pooltest.c プロジェクト: LinHu2016/omr
static int32_t
testPoolWalkFunctions(OMRPortLibrary *portLib, PoolInputData *inputData, J9Pool *currentPool, uint32_t elementsAllocated)
{
	pool_state state;
	uint8_t *element = NULL;
	uint32_t walkCount = 0;

	element = (uint8_t *)pool_startDo(currentPool, &state);
	do {
		if (element[0] != FIRST_BYTE_MARKER) {
			return -1;
		}
		if ((inputData->structSize > 1) && (element[inputData->structSize - 1] != LAST_BYTE_MARKER)) {
			return -2;
		}
		if (!pool_includesElement(currentPool, element)) {
			return -3;
		}
		walkCount++;
		element = pool_nextDo(&state);
	} while (element != NULL);

	if (walkCount != elementsAllocated) {
		return -4;
	}
	if (pool_numElements(currentPool) != elementsAllocated) {
		return -5;
	}
	return 0;
}
コード例 #2
0
ファイル: pooltest.c プロジェクト: LinHu2016/omr
static int32_t
testPoolRemoveElement(OMRPortLibrary *portLib, J9Pool *currentPool)
{
	uintptr_t expectedNumElements = pool_numElements(currentPool);
	pool_state state;
	uintptr_t startCount, endCount;
	uintptr_t expectedCapacityAfterRemovals = currentPool->elementsPerPuddle;

	if (currentPool->flags & POOL_NEVER_FREE_PUDDLES) {
		expectedCapacityAfterRemovals = pool_capacity(currentPool);
	}

	do {
		uint8_t *element = (uint8_t *)pool_startDo(currentPool, &state);

		startCount = pool_numElements(currentPool);
		do {
			expectedNumElements--;
			if (!pool_includesElement(currentPool, element)) {
				return -1;
			}
			pool_removeElement(currentPool, element);
			if (pool_numElements(currentPool) != expectedNumElements) {
				return -2;
			}
			if (pool_includesElement(currentPool, element)) {
				return -3;
			}
			/* Remove every other element each time - this deliberately creates fragmentation */
			element = pool_nextDo(&state);
			if (NULL != element) {
				element = pool_nextDo(&state);
			}
		} while (NULL != element);
		endCount = pool_numElements(currentPool);
	} while ((endCount > 0) && (startCount != endCount));

	if (expectedNumElements != 0) {
		return -5;
	} else if (expectedCapacityAfterRemovals != pool_capacity(currentPool)) {
		return -6;
	}

	return 0;
}
コード例 #3
0
ファイル: omrthreadtls.c プロジェクト: ChengJin01/omr
/**
 * Release a TLS key.
 *
 * Release a TLS key previously allocated by omrthread_tls_alloc.
 *
 * @param[in] key TLS key to be freed
 * @return 0 on success or negative value on failure
 *
 * @see omrthread_tls_alloc, omrthread_tls_set
 *
 */
intptr_t
omrthread_tls_free(omrthread_tls_key_t key)
{
	J9PoolState state;
	omrthread_t each;
	omrthread_library_t lib = GLOBAL_DATA(default_library);
	ASSERT(lib);

	/* clear the TLS in every existing thread */
	GLOBAL_LOCK_SIMPLE(lib);
	each = pool_startDo(lib->thread_pool, &state);
	while (each) {
		each->tls[key - 1] = NULL;
		each = pool_nextDo(&state);
	}
	GLOBAL_UNLOCK_SIMPLE(lib);

	/* now return the key to the free set */
	J9OSMUTEX_ENTER(lib->tls_mutex);
	lib->tls_finalizers[key - 1] = NULL;
	J9OSMUTEX_EXIT(lib->tls_mutex);

	return 0;
}
コード例 #4
0
ファイル: pooltest.c プロジェクト: LinHu2016/omr
int32_t
testPoolPuddleListSharing(OMRPortLibrary *portLib)
{
	uint32_t index = 0;
	uintptr_t numElements = 0;
	void *element = NULL;
	J9Pool *pool[NUM_POOLS_TO_SHARE_PUDDLE_LIST];
	pool_state state[NUM_POOLS_TO_SHARE_PUDDLE_LIST];
	int32_t result = 0;

	memset(pool, 0, sizeof(pool));

	for (index = 0; index < NUM_POOLS_TO_SHARE_PUDDLE_LIST; index++) {
		pool[index] = pool_new(sizeof(U_64), 0, 0, 0,
							   OMR_GET_CALLSITE(), OMRMEM_CATEGORY_VM,
							   (omrmemAlloc_fptr_t) sharedPuddleListAlloc,
							   (omrmemFree_fptr_t) sharedPuddleListFree,
							   portLib);

		if (NULL == pool[index]) {
			result = -1;
			goto error;
		}

		/* Create an element every time we create a pool. */
		pool_newElement(pool[index]);

		/*
		 * Since the underlying puddle list is shared, the number of elements in the pool
		 * should be the same as the 1 + index of the pool we're on.
		 */
		numElements = pool_numElements(pool[index]);
		if (numElements != (1 + index)) {
			result = -2;
			goto error;
		}
	}

	/* Verify again that numElements is the same for all pools. */
	numElements = pool_numElements(pool[0]);
	for (index = 1; index < NUM_POOLS_TO_SHARE_PUDDLE_LIST; index++) {
		if (numElements != pool_numElements(pool[index])) {
			result = -3;
			goto error;
		}
	}

	/* Iterate over the elements in each pool, and verify that they match. */
	element = pool_startDo(pool[0], &state[0]);
	/* Check the first element. */
	for (index = 1; index < NUM_POOLS_TO_SHARE_PUDDLE_LIST; index++) {
		if (element != pool_startDo(pool[index], &state[index])) {
			result = -4;
			goto error;
		}
	}
	/* And all other elements. */
	while (element) {
		element = pool_nextDo(&state[0]);
		for (index = 1; index < NUM_POOLS_TO_SHARE_PUDDLE_LIST; index++) {
			if (element != pool_nextDo(&state[index])) {
				result = -5;
				goto error;
			}
		}
	}

	/* Now, kill the pools. */
	for (index = 0; index < NUM_POOLS_TO_SHARE_PUDDLE_LIST; index++) {
		if (numElements != pool_numElements(pool[index])) {
			result = -6;
			goto error;
		}
		pool_kill(pool[index]);
		pool[index] = NULL;
	}

	if (sharedPuddleList != NULL) {
		result = -7;
		goto error;
	}

	return result;

error:
	for (index = 0; index < NUM_POOLS_TO_SHARE_PUDDLE_LIST; index++) {
		if (NULL != pool[index]) {
			pool_kill(pool[index]);
			pool[index] = NULL;
		}
	}

	return result;
}