extern void registerYamlParserClient (struct yamlParserClient *client) { if (!yamlParserClients) yamlParserClients = hashTableNew (5, hashInthash, hashInteq, NULL, NULL); hashTablePutItem (yamlParserClients, &client->lang, client); }
extern struct circularRefChecker * circularRefCheckerNew (void) { Assert (sizeof(void *) >= sizeof(int)); struct circularRefChecker *c = xMalloc (1, struct circularRefChecker); c->visitTable = hashTableNew (17, hashPtrhash, hashPtreq, NULL, NULL); c->counter = 0; return c; }
static void findAutomakeTags (void) { int index = CORK_NIL; void *backup_newMacro = newMacroCB; void *backup_valuesFound = valuesFoundCB; AutomakeDirectories = hashTableNew (11, hashCstrhash, hashCstreq, eFree, eFree); newMacroCB = newMacroAM; valuesFoundCB = valuesFoundAM; findMakeTagsCommon (&index); valuesFoundCB = backup_valuesFound; newMacroCB = backup_newMacro; hashTableDelete (AutomakeDirectories); }
omr_error_t OMR_MethodDictionary::init(OMR_VM *vm, size_t numProperties, const char * const *propertyNames) { _lock = NULL; _hashTable = NULL; _currentBytes = 0; _maxBytes = 0; _maxEntries = 0; _vm = vm; _numProperties = numProperties; _propertyNames = propertyNames; _sizeofEntry = (uint32_t)(sizeof(OMR_MethodDictionaryEntry) + (_numProperties * sizeof(char *))); omr_error_t rc = OMR_ERROR_NONE; omrthread_t self = NULL; if (0 == omrthread_attach_ex(&self, J9THREAD_ATTR_DEFAULT)) { OMRPORT_ACCESS_FROM_OMRVM(vm); _hashTable = hashTableNew( OMRPORTLIB, OMR_GET_CALLSITE(), 0, _sizeofEntry, 0, 0, OMRMEM_CATEGORY_OMRTI, entryHash, entryEquals, NULL, NULL); if (NULL != _hashTable) { if (0 != omrthread_monitor_init_with_name(&_lock, 0, "omrVM->_methodDictionary")) { rc = OMR_ERROR_FAILED_TO_ALLOCATE_MONITOR; } } else { rc = OMR_ERROR_OUT_OF_NATIVE_MEMORY; } if (OMR_ERROR_NONE != rc) { cleanup(); } omrthread_detach(self); } else { rc = OMR_ERROR_FAILED_TO_ATTACH_NATIVE_THREAD; } return rc; }
void valgrindCreateMempool(MM_GCExtensionsBase *extensions, MM_EnvironmentBase *env, uintptr_t poolAddr) { //1 lets valgrind know that objects will be defined when allocated VALGRIND_CREATE_MEMPOOL(poolAddr, 0, 1); extensions->valgrindMempoolAddr = poolAddr; MUTEX_INIT(extensions->memcheckHashTableMutex); MUTEX_ENTER(extensions->memcheckHashTableMutex); const char *tableName = "MemcheckWrapper"; uint32_t entrySize = sizeof(uintptr_t); extensions->memcheckHashTable = hashTableNew(env->getPortLibrary(), tableName, 0, entrySize, 0, 0, OMRMEM_CATEGORY_VM, hashFn, hashEqualFn, 0, 0); MUTEX_EXIT(extensions->memcheckHashTableMutex); }
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::SetUp() { OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib); printMemUsed("Setup()", gcTestEnv->portLib); /* Initialize heap and collector */ MM_StartupManagerTestExample startupManager(exampleVM->_omrVM, GetParam()); omr_error_t rc = OMR_GC_IntializeHeapAndCollector(exampleVM->_omrVM, &startupManager); ASSERT_EQ(OMR_ERROR_NONE, rc) << "Setup(): OMR_GC_IntializeHeapAndCollector failed, rc=" << rc; /* Attach calling thread to the VM */ exampleVM->_omrVMThread = NULL; rc = OMR_Thread_Init(exampleVM->_omrVM, NULL, &exampleVM->_omrVMThread, "OMRTestThread"); ASSERT_EQ(OMR_ERROR_NONE, rc) << "Setup(): OMR_Thread_Init failed, rc=" << rc; /* Kick off the dispatcher threads */ rc = OMR_GC_InitializeDispatcherThreads(exampleVM->_omrVMThread); ASSERT_EQ(OMR_ERROR_NONE, rc) << "Setup(): OMR_GC_InitializeDispatcherThreads failed, rc=" << rc; env = MM_EnvironmentBase::getEnvironment(exampleVM->_omrVMThread); /* load config file */ omrtty_printf("Configuration File: %s\n", GetParam()); #if defined(OMRGCTEST_PRINTFILE) printFile(GetParam()); #endif pugi::xml_parse_result result = doc.load_file(GetParam()); if (!result) { FAIL() << "Failed to load test configuration file (" << GetParam() << ") with error description: " << result.description() << "."; } /* parse verbose information and initialize verbose manager */ pugi::xml_node optionNode = doc.select_node("/gc-config/option").node(); const char *verboseFileNamePrefix = optionNode.attribute("verboseLog").value(); numOfFiles = (uintptr_t)optionNode.attribute("numOfFiles").as_int(); uintptr_t numOfCycles = (uintptr_t)optionNode.attribute("numOfCycles").as_int(); if (0 == strcmp(verboseFileNamePrefix, "")) { verboseFileNamePrefix = "VerboseGCOutput"; } verboseFile = (char *)omrmem_allocate_memory(MAX_NAME_LENGTH, OMRMEM_CATEGORY_MM); if (NULL == verboseFile) { FAIL() << "Failed to allocate native memory."; } omrstr_printf(verboseFile, MAX_NAME_LENGTH, "%s_%d_%lld.xml", verboseFileNamePrefix, omrsysinfo_get_pid(), omrtime_current_time_millis()); verboseManager = MM_VerboseManager::newInstance(env, exampleVM->_omrVM); verboseManager->configureVerboseGC(exampleVM->_omrVM, verboseFile, numOfFiles, numOfCycles); omrtty_printf("Verbose File: %s\n", verboseFile); #if defined(OMRGCTEST_DEBUG) omrtty_printf("Verbose GC log name: %s; numOfFiles: %d; numOfCycles: %d.\n", verboseFile, numOfFiles, numOfCycles); #endif verboseManager->enableVerboseGC(); verboseManager->setInitializedTime(omrtime_hires_clock()); /* create object table */ objectTable.create(); /* create root table */ exampleVM->rootTable = hashTableNew( gcTestEnv->portLib, OMR_GET_CALLSITE(), 0, sizeof(RootEntry), 0, 0, OMRMEM_CATEGORY_MM, rootTableHashFn, rootTableHashEqualFn, NULL, NULL); }