/** * Discards a lock object. * An lock must be discarded to free the resources associated with it. * * @note A lock must not be destroyed if threads are waiting on it, or * if it is currently owned. */ void MM_LightweightNonReentrantLock::tearDown() { if(NULL != _extensions) { if(NULL != _tracing) { if (NULL != _tracing->monitor_name) { _tracing->monitor_name = NULL; } J9Pool* tracingPool = _extensions->_lightweightNonReentrantLockPool; if(NULL != tracingPool) { omrthread_monitor_enter(_extensions->_lightweightNonReentrantLockPoolMutex); pool_removeElement(tracingPool, _tracing); omrthread_monitor_exit(_extensions->_lightweightNonReentrantLockPoolMutex); } _tracing = NULL; } } if (_initialized) { #if defined(J9MODRON_USE_CUSTOM_SPINLOCKS) omrgc_spinlock_destroy(&_spinlock); #else /* J9MODRON_USE_CUSTOM_SPINLOCKS */ MUTEX_DESTROY(_mutex); #endif /* J9MODRON_USE_CUSTOM_SPINLOCKS */ _initialized = false; } }
void MM_EnvironmentBase::kill() { MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(_omrVM); tearDown(extensions); /* This requires that the environments pool be locked */ pool_removeElement(extensions->environments, (void *)this); }
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; }