static J9Pool * createNewPool(OMRPortLibrary *portLib, PoolInputData *input) { uint32_t expectedNumElems = (input->numberElements == 0) ? 1 : input->numberElements; uint32_t expectedAlignment = (input->elementAlignment == 0) ? MIN_GRANULARITY : input->elementAlignment; J9Pool *pool = pool_new( input->structSize, input->numberElements, input->elementAlignment, input->poolFlags, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_VM, POOL_FOR_PORT(portLib)); /* Check that creation succeeded */ if (NULL == pool) { return NULL; } if (pool->puddleAllocSize < ((expectedNumElems * ROUND_TO(expectedAlignment, input->structSize)) + ROUND_TO(expectedAlignment, sizeof(J9PoolPuddle)))) { pool_kill(pool); return NULL; } else if ((input->poolFlags & POOL_ROUND_TO_PAGE_SIZE) && (pool->puddleAllocSize < OS_PAGE_SIZE)) { pool_kill(pool); return NULL; } return pool; }
/* * Shuts down the specified hook interface. * * This function should not be called directly. It should be called through the hook interface */ static void J9HookShutdownInterface(struct J9HookInterface **hookInterface) { J9CommonHookInterface *commonInterface = (J9CommonHookInterface *)hookInterface; if (commonInterface->lock) { omrthread_monitor_destroy(commonInterface->lock); } if (commonInterface->pool) { pool_kill(commonInterface->pool); } }
void * handle_daemon (void *arg) { struct daemon *d; struct daemon_request *tmp; d = (struct daemon *)arg; if (!d) goto out; sem_wait (&daemons_lock); daemons = daemon_add (daemons, d); sem_post (&daemons_lock); if (!daemons) { daemon_free (d); goto out; } log_success (log_file, "BEGIN daemon %s", d->addr); handle_requests (d); log_success (log_file, "END daemon %s", d->addr); sem_wait (&daemons_lock); daemons = daemon_remove (daemons, d); sem_post (&daemons_lock); /* Let's clean all remaining requests for this daemon */ sem_wait (&d->req_lock); for (tmp = d->requests; tmp; tmp = tmp->next) { /* Either it's been assigned to a thread in the pool */ if (tmp->assigned) pool_kill (tmp->pool, tmp->tid); /* Or it's still in the queue */ else pool_flush_by_arg (tmp->pool, tmp); daemon_request_free (tmp); } sem_post (&d->req_lock); daemon_free (d); out: sem_wait (&nb_daemons.lock); --nb_daemons.count; sem_post (&nb_daemons.lock); return NULL; }
/** * Tear down internal structures. */ void MM_ParallelSweepScheme::tearDown(MM_EnvironmentBase *env) { MM_GCExtensionsBase *extensions = env->getExtensions(); if(NULL != extensions->sweepHeapSectioning) { extensions->sweepHeapSectioning->kill(env); extensions->sweepHeapSectioning = NULL; _sweepHeapSectioning = NULL; } if (NULL != _poolSweepPoolState) { pool_kill(_poolSweepPoolState); _poolSweepPoolState = NULL; } if (0 != _mutexSweepPoolState) { omrthread_monitor_destroy(_mutexSweepPoolState); } }
int32_t createAndVerifyPool(OMRPortLibrary *portLib, PoolInputData *input) { J9Pool *pool = createNewPool(portLib, input); int32_t elementCount = 0; int32_t rc = 0; if (NULL == pool) { return -1; } elementCount = testPoolNewElement(portLib, input, pool); if (elementCount < 0) { return elementCount; } rc = testPoolWalkFunctions(portLib, input, pool, elementCount); if (0 != rc) { return rc; } /* Clear the pools, and test new, walk, and remove again. */ rc = testPoolClear(portLib, pool); if (0 != rc) { return rc; } elementCount = testPoolNewElement(portLib, input, pool); if (elementCount < 0) { return elementCount; } rc = testPoolWalkFunctions(portLib, input, pool, elementCount); if (0 != rc) { return rc; } rc = testPoolRemoveElement(portLib, pool); if (0 != rc) { return rc; } pool_kill(pool); return 0; }
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; }