void mpeg2PmtFree(Mpeg2Pmt mpeg2Pmt) { int cni; mpeg2PmtRecover(mpeg2Pmt); for (cni = 0; cni < NELEM(mpeg2Pmt->pmtTable); cni++) { ASSERT(hashTableUsed(mpeg2Pmt->pmtTable[cni]) == 0); hashTableFree(mpeg2Pmt->pmtTable[cni]); mpeg2Pmt->pmtTable[cni] = NULL; } free(mpeg2Pmt); }
void valgrindDestroyMempool(MM_GCExtensionsBase *extensions) { if (extensions->valgrindMempoolAddr != 0) { //All objects should have been freed by now! VALGRIND_DESTROY_MEMPOOL(extensions->valgrindMempoolAddr); MUTEX_ENTER(extensions->memcheckHashTableMutex); extensions->valgrindMempoolAddr = 0; hashTableFree(extensions->memcheckHashTable); extensions->memcheckHashTable = NULL; MUTEX_EXIT(extensions->memcheckHashTableMutex); MUTEX_DESTROY(extensions->memcheckHashTableMutex); } }
void OMR_MethodDictionary::cleanup() { if (NULL != _vm) { omrthread_t self = NULL; if (0 == omrthread_attach_ex(&self, J9THREAD_ATTR_DEFAULT)) { Trc_OMRPROF_methodDictionaryHighWaterMark(_maxBytes, _maxEntries, _sizeofEntry, _maxBytes - (_maxEntries * _sizeofEntry)); if (NULL != _hashTable) { hashTableForEachDo(_hashTable, OMR_MethodDictionary::cleanupEntryStrings, this); hashTableFree(_hashTable); _hashTable = NULL; } if (NULL != _lock) { omrthread_monitor_destroy(_lock); _lock = NULL; } _vm = NULL; omrthread_detach(self); } } }
Mesh *meshObjIndex(Mesh *mesh) { Mesh *indexed = malloc(sizeof(Mesh)); indexed->vertices.data = malloc(mesh->indices.length * sizeof(Vec3)); indexed->uvs.data = malloc(mesh->indices.length * sizeof(Vec2)); indexed->normals.data = malloc(mesh->indices.length * sizeof(Vec3)); indexed->indices.data = malloc(mesh->indices.length * sizeof(unsigned)); indexed->vertices.length = 0; indexed->uvs.length = 0; indexed->normals.length = 0; indexed->indices.length = mesh->indices.length; HashTable *indexTable = hashTableNew(); unsigned index = 0; unsigned *duplicate = NULL; for (unsigned i = 0; i < mesh->indices.length; i++) { unsigned x = i * 3; /** * Create a unique key from all 3 index * variables. */ int keyLength = snprintf(NULL, 0, "%i/%i/%i", (int)mesh->indices.data[x], (int)mesh->indices.data[x + 1], (int)mesh->indices.data[x + 2]); if (keyLength > 0) { char key[keyLength + 1]; sprintf(key, "%i/%i/%i", (int)mesh->indices.data[x], (int)mesh->indices.data[x + 1], (int)mesh->indices.data[x + 2]); if ((duplicate = (unsigned*)hashTableGet(indexTable, hashMurmur3(key))) == NULL) { if ((int)mesh->indices.data[x] > 0) { indexed->vertices.data[index] = mesh->vertices.data[(int)mesh->indices.data[x] - 1]; indexed->vertices.length++; } else if ((int)mesh->indices.data[x] < 0) { indexed->vertices.data[index] = mesh->vertices.data[mesh->vertices.length + (int)mesh->indices.data[x]]; indexed->vertices.length++; } else { /** * If vertex data is missing nullify * the mesh and break out. */ indexed = meshObjEmpty(indexed); break; } if ((int)mesh->indices.data[x + 1] > 0) { indexed->uvs.data[index] = mesh->uvs.data[(int)mesh->indices.data[x + 1] - 1]; indexed->uvs.length++; } else if ((int)mesh->indices.data[x + 1] < 0) { indexed->uvs.data[index] = mesh->uvs.data[mesh->uvs.length + (int)mesh->indices.data[x + 1]]; indexed->uvs.length++; } if ((int)mesh->indices.data[x + 2] > 0) { indexed->normals.data[index] = mesh->normals.data[(int)mesh->indices.data[x + 2] - 1]; indexed->normals.length++; } else if ((int)mesh->indices.data[x + 2] < 0) { indexed->normals.data[index] = mesh->normals.data[mesh->normals.length + (int)mesh->indices.data[x + 2]]; indexed->normals.length++; } indexed->indices.data[i] = index; index++; hashTableSet(indexTable, hashMurmur3(key), &indexed->indices.data[i]); } else { indexed->indices.data[i] = *duplicate; } } } hashTableFree(indexTable); /** * Resize buffers to match data. */ if (indexed->uvs.length != indexed->vertices.length) { indexed->uvs.length = 0; } if (indexed->normals.length != indexed->vertices.length) { indexed->normals.length = 0; } indexed->vertices.data = realloc(indexed->vertices.data, indexed->vertices.length * sizeof(Vec3)); indexed->uvs.data = realloc(indexed->uvs.data, indexed->uvs.length * sizeof(Vec2)); indexed->normals.data = realloc(indexed->normals.data, indexed->normals.length * sizeof(Vec3)); return indexed; }
int testMain(int argc, char ** argv, char **envp) { /* Start up */ OMR_VM_Example exampleVM; OMR_VMThread *omrVMThread = NULL; omrthread_t self = NULL; exampleVM._omrVM = NULL; exampleVM.rootTable = NULL; /* Initialize the VM */ omr_error_t rc = OMR_Initialize(&exampleVM, &exampleVM._omrVM); Assert_MM_true(OMR_ERROR_NONE == rc); /* Recursive omrthread_attach() (i.e. re-attaching a thread that is already attached) is cheaper and less fragile * than non-recursive. If performing a sequence of function calls that are likely to attach & detach internally, * it is more efficient to call omrthread_attach() before the entire block. */ int j9rc = (int) omrthread_attach_ex(&self, J9THREAD_ATTR_DEFAULT); Assert_MM_true(0 == j9rc); /* Initialize root table */ exampleVM.rootTable = hashTableNew( exampleVM._omrVM->_runtime->_portLibrary, OMR_GET_CALLSITE(), 0, sizeof(RootEntry), 0, 0, OMRMEM_CATEGORY_MM, rootTableHashFn, rootTableHashEqualFn, NULL, NULL); /* Initialize heap and collector */ { /* This has to be done in local scope because MM_StartupManager has a destructor that references the OMR VM */ MM_StartupManagerImpl startupManager(exampleVM._omrVM); rc = OMR_GC_IntializeHeapAndCollector(exampleVM._omrVM, &startupManager); } Assert_MM_true(OMR_ERROR_NONE == rc); /* Attach current thread to the VM */ rc = OMR_Thread_Init(exampleVM._omrVM, NULL, &omrVMThread, "GCTestMailThread"); Assert_MM_true(OMR_ERROR_NONE == rc); /* Kick off the dispatcher therads */ rc = OMR_GC_InitializeDispatcherThreads(omrVMThread); Assert_MM_true(OMR_ERROR_NONE == rc); OMRPORT_ACCESS_FROM_OMRVM(exampleVM._omrVM); omrtty_printf("VM/GC INITIALIZED\n"); /* Do stuff */ MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(omrVMThread); MM_ObjectAllocationInterface *allocationInterface = env->_objectAllocationInterface; MM_GCExtensionsBase *extensions = env->getExtensions(); omrtty_printf("configuration is %s\n", extensions->configuration->getBaseVirtualTypeId()); omrtty_printf("collector interface is %s\n", env->getExtensions()->collectorLanguageInterface->getBaseVirtualTypeId()); omrtty_printf("garbage collector is %s\n", env->getExtensions()->getGlobalCollector()->getBaseVirtualTypeId()); omrtty_printf("allocation interface is %s\n", allocationInterface->getBaseVirtualTypeId()); /* Allocate objects without collection until heap exhausted */ uintptr_t allocatedFlags = 0; uintptr_t size = extensions->objectModel.adjustSizeInBytes(24); MM_AllocateDescription mm_allocdescription(size, allocatedFlags, true, true); uintptr_t allocatedCount = 0; while (true) { omrobjectptr_t obj = (omrobjectptr_t)allocationInterface->allocateObject(env, &mm_allocdescription, env->getMemorySpace(), false); if (NULL != obj) { extensions->objectModel.setObjectSize(obj, mm_allocdescription.getBytesRequested()); RootEntry rEntry = {"root1", obj}; RootEntry *entryInTable = (RootEntry *)hashTableAdd(exampleVM.rootTable, &rEntry); if (NULL == entryInTable) { omrtty_printf("failed to add new root to root table!\n"); } /* update entry if it already exists in table */ entryInTable->rootPtr = obj; allocatedCount++; } else { break; } } /* Print/verify thread allocation stats before GC */ MM_AllocationStats *allocationStats = allocationInterface->getAllocationStats(); omrtty_printf("thread allocated %d tlh bytes, %d non-tlh bytes, from %d allocations before NULL\n", allocationStats->tlhBytesAllocated(), allocationStats->nontlhBytesAllocated(), allocatedCount); uintptr_t allocationTotalBytes = allocationStats->tlhBytesAllocated() + allocationStats->nontlhBytesAllocated(); uintptr_t allocatedTotalBytes = size * allocatedCount; Assert_MM_true(allocatedTotalBytes == allocationTotalBytes); /* Force GC to print verbose system allocation stats -- should match thread allocation stats from before GC */ omrobjectptr_t obj = (omrobjectptr_t)allocationInterface->allocateObject(env, &mm_allocdescription, env->getMemorySpace(), true); env->unwindExclusiveVMAccessForGC(); Assert_MM_false(NULL == obj); extensions->objectModel.setObjectSize(obj, mm_allocdescription.getBytesRequested()); omrtty_printf("ALL TESTS PASSED\n"); /* Shut down */ /* Shut down the dispatcher therads */ rc = OMR_GC_ShutdownDispatcherThreads(omrVMThread); Assert_MM_true(OMR_ERROR_NONE == rc); /* Shut down collector */ rc = OMR_GC_ShutdownCollector(omrVMThread); Assert_MM_true(OMR_ERROR_NONE == rc); /* Detach from VM */ rc = OMR_Thread_Free(omrVMThread); Assert_MM_true(OMR_ERROR_NONE == rc); /* Shut down heap */ rc = OMR_GC_ShutdownHeap(exampleVM._omrVM); Assert_MM_true(OMR_ERROR_NONE == rc); /* Free root hash table */ hashTableFree(exampleVM.rootTable); /* Balance the omrthread_attach_ex() issued above */ omrthread_detach(self); /* Shut down VM * This destroys the port library and the omrthread library. * Don't use any port library or omrthread functions after this. * * (This also shuts down trace functionality, so the trace assertion * macros might not work after this.) */ rc = OMR_Shutdown(exampleVM._omrVM); Assert_MM_true(OMR_ERROR_NONE == rc); return rc; }
void GCConfigTest::TearDown() { OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib); /* free root table */ hashTableFree(exampleVM->rootTable); /* free object table */ objectTable.free(); /* close verboseManager and clean up verbose files */ verboseManager->closeStreams(env); verboseManager->disableVerboseGC(); verboseManager->kill(env); if (false == gcTestEnv->keepLog) { if (0 == numOfFiles) { J9FileStat buf; int32_t fileStatRC = -1; fileStatRC = omrfile_stat(verboseFile, 0, &buf); if (0 == fileStatRC) { if (1 == buf.isFile) { omrfile_unlink(verboseFile); } } } else { for (int32_t seq = 1; seq <= (int32_t)numOfFiles; seq++) { char verboseFileSeq[MAX_NAME_LENGTH]; omrstr_printf(verboseFileSeq, MAX_NAME_LENGTH, "%s.%03zu", verboseFile, seq); J9FileStat buf; int32_t fileStatRC = -1; fileStatRC = omrfile_stat(verboseFileSeq, 0, &buf); if (0 > fileStatRC) { if (1 != buf.isFile) { break; } } omrfile_unlink(verboseFileSeq); } } } omrmem_free_memory((void *)verboseFile); /* Shut down the dispatcher threads */ omr_error_t rc = OMR_GC_ShutdownDispatcherThreads(exampleVM->_omrVMThread); ASSERT_EQ(OMR_ERROR_NONE, rc) << "TearDown(): OMR_GC_ShutdownDispatcherThreads failed, rc=" << rc; /* Shut down collector */ rc = OMR_GC_ShutdownCollector(exampleVM->_omrVMThread); ASSERT_EQ(OMR_ERROR_NONE, rc) << "TearDown(): OMR_GC_ShutdownCollector failed, rc=" << rc; /* Detach from VM */ rc = OMR_Thread_Free(exampleVM->_omrVMThread); ASSERT_EQ(OMR_ERROR_NONE, rc) << "TearDown(): OMR_Thread_Free failed, rc=" << rc; /* Shut down heap */ rc = OMR_GC_ShutdownHeap(exampleVM->_omrVM); ASSERT_EQ(OMR_ERROR_NONE, rc) << "TearDown(): OMR_GC_ShutdownHeap failed, rc=" << rc; printMemUsed("TearDown()", gcTestEnv->portLib); }