ObjectEntry * GCConfigTest::createObject(const char *namePrefix, OMRGCObjectType objType, int32_t depth, int32_t nthInRow, uintptr_t size) { OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib); ObjectEntry *objEntry = NULL; char *objName = (char *)omrmem_allocate_memory(MAX_NAME_LENGTH, OMRMEM_CATEGORY_MM); if (NULL == objName) { omrtty_printf("%s:%d Failed to allocate native memory.\n", __FILE__, __LINE__); goto done; } omrstr_printf(objName, MAX_NAME_LENGTH, "%s_%d_%d", namePrefix, depth, nthInRow); objEntry = find(objName); if (NULL != objEntry) { #if defined(OMRGCTEST_DEBUG) omrtty_printf("Found object %s in object table.\n", objEntry->name); #endif omrmem_free_memory(objName); } else { objEntry = allocateHelper(objName, size); if (NULL != objEntry) { /* Keep count of the new allocated non-garbage object size for garbage insertion. If the object exists in objectTable, its size is ignored. */ if ((ROOT == objType) || (NORMAL == objType)) { gp.accumulatedSize += env->getExtensions()->objectModel.getSizeInBytesWithHeader(objEntry->objPtr); } } else { omrmem_free_memory(objName); } } done: return objEntry; }
/** * Write a formatted string to the console, lookup the last port error message and port error number, then store it. * * Update the number of failed tests * * * @param[in] portLibrary The port library * @param[in] fileName File requesting message output * @param[in] lineNumber Line number in the file of request * @param[in] testName Name of the test requesting output * @param[in] foramt Format of string to be output * @param[in] ... argument list for format string */ void outputErrorMessage(struct OMRPortLibrary *portLibrary, const char *fileName, int32_t lineNumber, const char *testName, const char *format, ...) { char *buf, *portErrorBuf = NULL; uintptr_t sizeBuf; size_t sizePortErrorBuf; va_list args; char *lastErrorMessage = NULL; int32_t lastErrorNumber = 0; OMRPORT_ACCESS_FROM_OMRPORT(portLibrary); lastErrorMessage = (char *)omrerror_last_error_message(); lastErrorNumber = omrerror_last_error_number(); /* Capture the error message now * Get the size needed to hold the last error message (don't use str_printf to avoid polluting error message */ sizePortErrorBuf = strlen(lastErrorMessage) + 1 /* for the null terminator */; portErrorBuf = (char *)omrmem_allocate_memory(sizePortErrorBuf, OMRMEM_CATEGORY_PORT_LIBRARY); if (NULL != portErrorBuf) { strncpy(portErrorBuf, lastErrorMessage, sizePortErrorBuf); } else { portTestEnv->log(LEVEL_ERROR, "\n\n******* omrmem_allocate_memory failed to allocate %i bytes, exiting.\n\n", sizePortErrorBuf); exit(EXIT_OUT_OF_MEMORY); } va_start(args, format); /* get the size needed to hold the error message that was passed in */ sizeBuf = omrstr_vprintf(NULL, 0, format, args); buf = (char *)omrmem_allocate_memory(sizeBuf, OMRMEM_CATEGORY_PORT_LIBRARY); if (NULL != buf) { omrstr_vprintf(buf, sizeBuf, format, args); } else { portTestEnv->log(LEVEL_ERROR, "\n\n******* omrmem_allocate_memory failed to allocate %i bytes, exiting.\n\n", sizeBuf); exit(EXIT_OUT_OF_MEMORY); } va_end(args); portTestEnv->log(LEVEL_ERROR, "%s line %4zi: %s ", fileName, lineNumber, testName); portTestEnv->log(LEVEL_ERROR, "%s\n", buf); portTestEnv->log(LEVEL_ERROR, "\t\tLastErrorNumber: %i\n", lastErrorNumber); portTestEnv->log(LEVEL_ERROR, "\t\tLastErrorMessage: %s\n\n", portErrorBuf); logTestFailure(OMRPORTLIB, fileName, lineNumber, testName, lastErrorNumber, portErrorBuf, buf); omrmem_free_memory(portErrorBuf); omrmem_free_memory(buf); numberFailedTestsInComponent++; }
void OMR_Agent::destroyAgent(OMR_Agent *agent) { if (NULL != agent) { OMRPORT_ACCESS_FROM_OMRVM(agent->_vm); if ((0 != agent->_handle) && (ONUNLOAD_SUCCESS == agent->_state)) { omrsl_close_shared_library(agent->_handle); } omrmem_free_memory((void *)agent->_dllpath); omrmem_free_memory((void *)agent); } }
wchar_t * convertFromUTF8(OMRPortLibrary *portLibrary, const char *string, wchar_t *unicodeBuffer, uintptr_t unicodeBufferSize) { wchar_t *unicodeString; uintptr_t length; OMRPORT_ACCESS_FROM_OMRPORT(portLibrary); if (NULL == string) { return NULL; } length = (uintptr_t)strlen(string); if (length < unicodeBufferSize) { unicodeString = unicodeBuffer; } else { unicodeString = (wchar_t *)omrmem_allocate_memory((length + 1) * 2, OMRMEM_CATEGORY_PORT_LIBRARY); if (NULL == unicodeString) { return NULL; } } if (0 == MultiByteToWideChar(OS_ENCODING_CODE_PAGE, OS_ENCODING_MB_FLAGS, string, -1, unicodeString, (int)length + 1)) { omrerror_set_last_error(GetLastError(), OMRPORT_ERROR_OPFAILED); if (unicodeString != unicodeBuffer) { omrmem_free_memory(unicodeString); } return NULL; } return unicodeString; }
/** * Re-allocate memory. * * @param[in] portLibrary The port library * @param[in] memoryPointer Base address of memory to be re-allocated. * @param[in] byteAmount Number of bytes to re-allocated. * @param[in] callSite Allocation callsite, or NULL if the callsite from the original allocation should be inherited * @param[in] category Memory allocation category code * * @return pointer to memory on success, NULL on error or if byteAmount * is 0 and memoryPointer is non-NULL * * @note if memoryPointer is NULL, this function will behave like mem_allocate_memory * for the specified byteAmount * * @note If byteAmount is 0 and memoryPointer is non-NULL, this function will * behave like mem_free_memory for the specified memoryPointer and * returns NULL * * @note If this function is unable to allocate the requested memory, the original * memory is not freed and may still be used. * * @internal @warning Do not call error handling code @ref omrerror upon error as * the error handling code uses per thread buffers to store the last error. If memory * can not be allocated the result would be an infinite loop. */ void * omrmem_reallocate_memory(struct OMRPortLibrary *portLibrary, void *memoryPointer, uintptr_t byteAmount, const char *callSite, uint32_t category) { void *pointer = NULL; uintptr_t allocationByteAmount; reallocate_memory_func_t reallocateFunction = omrmem_reallocate_memory_basic; Trc_PRT_mem_omrmem_reallocate_memory_Entry(memoryPointer, byteAmount, callSite, category); if (memoryPointer == NULL) { pointer = omrmem_allocate_memory(portLibrary, byteAmount, NULL == callSite ? OMR_GET_CALLSITE() : callSite, category); } else if (byteAmount == 0) { omrmem_free_memory(portLibrary, memoryPointer); } else { memoryPointer = unwrapBlockAndCheckTags(portLibrary, memoryPointer); if (NULL == callSite) { /* Inherit the callsite from the original allocation */ callSite = ((J9MemTag *) memoryPointer)->callSite; } allocationByteAmount = ROUNDED_BYTE_AMOUNT(byteAmount); pointer = reallocateFunction(portLibrary, memoryPointer, allocationByteAmount); if (NULL != pointer) { pointer = wrapBlockAndSetTags(portLibrary, pointer, byteAmount, callSite, category); } if (NULL == pointer) { Trc_PRT_mem_omrmem_reallocate_memory_failed_2(callSite, memoryPointer, allocationByteAmount); } } Trc_PRT_mem_omrmem_reallocate_memory_Exit(pointer); return pointer; }
void MM_VerboseManagerImpl::tearDown(MM_EnvironmentBase *env) { OMRPORT_ACCESS_FROM_OMRPORT(env->getPortLibrary()); MM_VerboseManager::tearDown(env); omrmem_free_memory(this->filename); }
omr_error_t OMR_MethodDictionary::dupEntryStrings(OMR_MethodDictionaryEntry *dest, const OMR_MethodDictionaryEntry *src) { omr_error_t rc = OMR_ERROR_NONE; OMRPORT_ACCESS_FROM_OMRVM(_vm); for (size_t i = 0; i < _numProperties; i++) { if (NULL != src->propertyValues[i]) { size_t len = strlen(src->propertyValues[i]) + 1; void *copy = omrmem_allocate_memory(len, OMRMEM_CATEGORY_OMRTI); if (NULL != copy) { memcpy(copy, src->propertyValues[i], len); dest->propertyValues[i] = (const char *)copy; } else { rc = OMR_ERROR_OUT_OF_NATIVE_MEMORY; dest->propertyValues[i] = NULL; /* Release previously allocated strings */ for (size_t j = 0; j < i; j++) { omrmem_free_memory((void *)dest->propertyValues[j]); dest->propertyValues[j] = NULL; } break; } } } return rc; }
/* Utility function for parsing command line options */ static void freeSubString(char *buffer) { OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary)); UT_DBGOUT(2, ("<UT> freeSubString: buffer %p\n", buffer)); omrmem_free_memory(buffer); return; }
void spaceSavingFree(OMRSpaceSaving *spaceSaving) { OMRPORT_ACCESS_FROM_OMRPORT(spaceSaving->portLib); rankingFree(spaceSaving->ranking); omrmem_free_memory(spaceSaving); return; }
static void sharedPuddleListFree(OMRPortLibrary *portLib, void *address, uint32_t type) { OMRPORT_ACCESS_FROM_OMRPORT(portLib); if (type == POOL_ALLOC_TYPE_PUDDLE_LIST) { sharedPuddleListReferenceCount--; if (sharedPuddleListReferenceCount == 0) { omrmem_free_memory(address); sharedPuddleList = NULL; } } else if (type == POOL_ALLOC_TYPE_PUDDLE) { if (sharedPuddleListReferenceCount == 1) { omrmem_free_memory(address); } } else { omrmem_free_memory(address); } }
void omr_ras_cleanupMethodDictionary(OMR_VM *vm) { if (NULL != vm->_methodDictionary) { OMRPORT_ACCESS_FROM_OMRVM(vm); ((OMR_MethodDictionary *)vm->_methodDictionary)->cleanup(); omrmem_free_memory(vm->_methodDictionary); vm->_methodDictionary = NULL; } }
void pool_portLibFree32(OMRPortLibrary *portLibrary, void *address, uint32_t type) { OMRPORT_ACCESS_FROM_OMRPORT(portLibrary); if (POOL_ALLOC_TYPE_PUDDLE == type) { omrmem_free_memory32(address); } else { omrmem_free_memory(address); } }
void GCConfigTest::freeAttributeList(AttributeElem *root) { OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib); AttributeElem *cur = root; while (NULL != cur) { J9_LINKED_LIST_REMOVE(root, cur); omrmem_free_memory(cur); cur = root; } }
static omr_error_t startTestChildThread(OMRTestVM *testVM, OMR_VMThread *curVMThread, omrthread_t *childThread, TestChildThreadData **childData) { omr_error_t rc = OMR_ERROR_NONE; OMRPORT_ACCESS_FROM_OMRPORT(testVM->portLibrary); TestChildThreadData *newChildData = (TestChildThreadData *)omrmem_allocate_memory(sizeof(*newChildData), OMRMEM_CATEGORY_VM); if (NULL == newChildData) { rc = OMR_ERROR_OUT_OF_NATIVE_MEMORY; omrtty_printf("%s:%d ERROR: Failed to alloc newChildData\n", __FILE__, __LINE__); } if (OMR_ERROR_NONE == rc) { if (0 != omrthread_monitor_init_with_name(&newChildData->shutdownCond, 0, "traceTestChildShutdown")) { rc = OMR_ERROR_FAILED_TO_ALLOCATE_MONITOR; omrtty_printf("%s:%d ERROR: Failed to init shutdownCond monitor\n", __FILE__, __LINE__); omrmem_free_memory(newChildData); } else { newChildData->testVM = testVM; newChildData->isDead = FALSE; newChildData->childRc = OMR_ERROR_NONE; } } if (OMR_ERROR_NONE == rc) { if (0 != omrthread_create_ex( NULL, /* handle */ J9THREAD_ATTR_DEFAULT, /* attr */ FALSE, /* suspend */ childThreadMain, /* entrypoint */ newChildData) /* entryarg */ ) { rc = OMR_ERROR_OUT_OF_NATIVE_MEMORY; omrtty_printf("%s:%d ERROR: Failed to init shutdownCond monitor\n", __FILE__, __LINE__); omrthread_monitor_destroy(newChildData->shutdownCond); omrmem_free_memory(newChildData); } else { *childData = newChildData; } } return rc; }
/** * This method free the internal structures and memory for a SupportThreadInfo * @param info the SupportThreadInfo instance to be freed */ void freeSupportThreadInfo(SupportThreadInfo *info) { OMRPORT_ACCESS_FROM_OMRPORT(omrTestEnv->getPortLibrary()); if (info->synchronization != NULL) { omrthread_monitor_destroy(info->synchronization); } if (info->handle != NULL) { omrthread_rwmutex_destroy(info->handle); } omrmem_free_memory(info); }
static omr_error_t waitForChildThread(OMRTestVM *testVM, omrthread_t childThread, ChildThreadData *childData) { OMRPORT_ACCESS_FROM_OMRPORT(testVM->portLibrary); omr_error_t childRc = OMR_ERROR_INTERNAL; if (J9THREAD_SUCCESS == joinThread(childThread)) { childRc = childData->childRc; } omrmem_free_memory(childData); return childRc; }
uintptr_t OMR_MethodDictionary::cleanupEntryStrings(void *entry, void *userData) { OMR_MethodDictionary *md = (OMR_MethodDictionary *)userData; OMR_MethodDictionaryEntry *mdEntry = (OMR_MethodDictionaryEntry *)entry; OMRPORT_ACCESS_FROM_OMRVM(md->_vm); for (size_t i = 0; i < md->_numProperties; ++i) { omrmem_free_memory((void *)mdEntry->propertyValues[i]); mdEntry->propertyValues[i] = NULL; } return FALSE; /* don't remove the entry */ }
/* * This function is used during trace shutdown. * omrTraceGlobal has been NULLed here. Don't use UT_DBGOUT() macro. */ omr_error_t freeComponentList(OMR_TraceGlobal *global, UtComponentList *componentList) { UtComponentData *compData = componentList->head; UtComponentData *tempCD; UtDeferredConfigInfo *configInfo = componentList->deferredConfigInfoHead; UtDeferredConfigInfo *tempCI; OMRPORT_ACCESS_FROM_OMRPORT(global->portLibrary); UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentList: %p\n", componentList)); while (compData != NULL) { tempCD = compData->next; UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentList: freeing CI [%p] from [%p]\n", compData, componentList)); freeComponentData(global, compData); compData = tempCD; } while (configInfo != NULL) { tempCI = configInfo->next; UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentList: freeing CI [%p] from [%p]\n", configInfo, componentList)); if (configInfo->groupName != NULL) { omrmem_free_memory(configInfo->groupName); } if (configInfo->componentName != NULL) { omrmem_free_memory(configInfo->componentName); } omrmem_free_memory(configInfo); configInfo = tempCI; } omrmem_free_memory(componentList); UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentList: %p finished processing\n", componentList)); return OMR_ERROR_NONE; }
intptr_t j9process_close(OMRPortLibrary *portLibrary, OMRProcessHandle *processHandle, uint32_t options) { OMRPORT_ACCESS_FROM_OMRPORT(portLibrary); int32_t rc = 0; OMRProcessHandleStruct *processHandleStruct = (OMRProcessHandleStruct *)*processHandle; #if defined(WIN32) if (!CloseHandle((HANDLE)processHandleStruct->procHandle)) { rc = OMRPROCESS_ERROR; } if (OMRPROCESS_INVALID_FD != processHandleStruct->inHandle) { if (!CloseHandle((HANDLE)processHandleStruct->inHandle)) { rc = OMRPROCESS_ERROR; } } if (OMRPROCESS_INVALID_FD != processHandleStruct->outHandle) { if (!CloseHandle((HANDLE)processHandleStruct->outHandle)) { rc = OMRPROCESS_ERROR; } } if (OMRPROCESS_INVALID_FD != processHandleStruct->errHandle) { if (!CloseHandle((HANDLE)processHandleStruct->errHandle)) { rc = OMRPROCESS_ERROR; } } #else /* defined(WIN32) */ if (OMRPROCESS_INVALID_FD != processHandleStruct->inHandle) { if (0 != close((int) processHandleStruct->inHandle)) { rc = OMRPROCESS_ERROR; } } if (OMRPROCESS_INVALID_FD != processHandleStruct->outHandle) { if (0 != close((int) processHandleStruct->outHandle)) { rc = OMRPROCESS_ERROR; } } if (OMRPROCESS_INVALID_FD != processHandleStruct->errHandle) { if (0 != (close((int) processHandleStruct->errHandle) != 0)) { rc = OMRPROCESS_ERROR; } } #endif /* defined(WIN32) */ omrmem_free_memory(processHandleStruct); processHandleStruct = *processHandle = NULL; return rc; }
void OMR_MethodDictionary::traceInsertEntryFailed(omr_error_t rc, const OMR_MethodDictionaryEntry *newEntry) const { if (TrcEnabled_Trc_OMRPROF_insertMethodDictionary_failed) { OMRPORT_ACCESS_FROM_OMRVM(_vm); char *propertyStr = NULL; formatEntryProperties(newEntry, &propertyStr); if (NULL == propertyStr) { Trc_OMRPROF_insertMethodDictionary_failed(rc, newEntry->key, ""); } else { Trc_OMRPROF_insertMethodDictionary_failed(rc, newEntry->key, propertyStr); omrmem_free_memory(propertyStr); } } }
void OMR_MethodDictionary::traceInsertEntryReplace(const OMR_MethodDictionaryEntry *newEntry) const { if (TrcEnabled_Trc_OMRPROF_insertMethodDictionary_replaceExistingEntry) { OMRPORT_ACCESS_FROM_OMRVM(_vm); char *propertyStr = NULL; formatEntryProperties(newEntry, &propertyStr); if (NULL == propertyStr) { Trc_OMRPROF_insertMethodDictionary_replaceExistingEntry(newEntry->key, ""); } else { Trc_OMRPROF_insertMethodDictionary_replaceExistingEntry(newEntry->key, propertyStr); omrmem_free_memory(propertyStr); } } }
/** * Iterate through the global @ref testFailures printing out each failed test case * * The memory for each string in testFailers is freed after writing the string to the console. * * @param[in] portLibrary * @param[out] dest container for pointer to copied memory * @param[in] source string to be copied into dest */ void dumpTestFailuresToConsole(struct OMRPortLibrary *portLibrary) { int32_t i; OMRPORT_ACCESS_FROM_OMRPORT(portLibrary); portTestEnv->log(LEVEL_ERROR, "-------------------------------------------------------------------------\n"); portTestEnv->log(LEVEL_ERROR, "-------------------------------------------------------------------------\n\n"); portTestEnv->log(LEVEL_ERROR, "FAILURES DETECTED. Number of failed tests: %u\n\n", numTestFailures); for (i = 0; i < numTestFailures ; i++) { portTestEnv->log(LEVEL_ERROR, "%i: %s\n", i + 1, testFailures[i].testName); portTestEnv->log(LEVEL_ERROR, "\t%s line %4zi: %s\n", testFailures[i].fileName, testFailures[i].lineNumber, testFailures[i].errorMessage); portTestEnv->log(LEVEL_ERROR, "\t\tLastErrorNumber: %i\n", testFailures[i].portErrorNumber); portTestEnv->log(LEVEL_ERROR, "\t\tLastErrorMessage: %s\n\n", testFailures[i].portErrorMessage); omrmem_free_memory(testFailures[i].fileName); omrmem_free_memory(testFailures[i].testName); omrmem_free_memory(testFailures[i].errorMessage); omrmem_free_memory(testFailures[i].portErrorMessage); } }
void MM_MarkingDelegate::masterCleanupAfterGC(MM_EnvironmentBase *env) { OMRPORT_ACCESS_FROM_OMRVM(env->getOmrVM()); J9HashTableState state; ObjectEntry *objEntry = NULL; OMR_VM_Example *omrVM = (OMR_VM_Example *)env->getOmrVM()->_language_vm; objEntry = (ObjectEntry *)hashTableStartDo(omrVM->objectTable, &state); while (objEntry != NULL) { if (!_markingScheme->isMarked(objEntry->objPtr)) { omrmem_free_memory((void *)objEntry->name); objEntry->name = NULL; hashTableDoRemove(&state); } objEntry = (ObjectEntry *)hashTableNextDo(&state); } }
static omr_error_t waitForTestChildThread(OMRTestVM *testVM, omrthread_t childThead, TestChildThreadData *childData) { omr_error_t childRc = OMR_ERROR_NONE; OMRPORT_ACCESS_FROM_OMRPORT(testVM->portLibrary); omrthread_monitor_enter(childData->shutdownCond); while (!childData->isDead) { omrthread_monitor_wait(childData->shutdownCond); } omrthread_monitor_exit(childData->shutdownCond); childRc = childData->childRc; omrthread_monitor_destroy(childData->shutdownCond); omrmem_free_memory(childData); return childRc; }
int32_t GCConfigTest::parseAttribute(AttributeElem **root, const char *attrStr) { OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib); int32_t rt = 0; const char DELIM = ','; char *copyOfAttrStr = (char *)omrmem_allocate_memory(strlen(attrStr) + 1, OMRMEM_CATEGORY_MM); char *attrStart = NULL; char *attrEnd = NULL; if (NULL == copyOfAttrStr) { rt = 1; omrtty_printf("%s:%d Failed to allocate native memory.\n", __FILE__, __LINE__); goto done; } strcpy(copyOfAttrStr, attrStr); attrStart = copyOfAttrStr; attrEnd = attrStart; while (NULL != attrEnd) { attrEnd = strchr(attrStart, DELIM); int32_t attr = 0; if (NULL != attrEnd) { *attrEnd = '\0'; attr = atoi(attrStart); attrStart = attrEnd + 1; } else { attr = atoi(attrStart); } AttributeElem *attrNode = (AttributeElem *)omrmem_allocate_memory(sizeof(AttributeElem), OMRMEM_CATEGORY_MM); if (NULL == attrNode) { rt = 1; omrtty_printf("%s:%d Failed to allocate native memory.\n", __FILE__, __LINE__); goto done; } attrNode->value = attr; J9_LINKED_LIST_ADD_LAST(*root, attrNode); } omrmem_free_memory(copyOfAttrStr); done: return rt; }
/* * This function is used during trace shutdown. * omrTraceGlobal may have been NULLed before calling this function. * Don't use UT_DBGOUT() macro. */ void freeComponentData(OMR_TraceGlobal *global, UtComponentData *componentDataPtr) { int numFormats, i; char *tempString; OMRPORT_ACCESS_FROM_OMRPORT(global->portLibrary); UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentData: %s\n", componentDataPtr->componentName)); numFormats = componentDataPtr->numFormats; /* free any storage allocated for the format strings and names */ if (componentDataPtr->tracepointFormattingStrings != NULL) { for (i = 0; i < numFormats; i++) { tempString = componentDataPtr->tracepointFormattingStrings[i]; if (tempString != NULL && tempString != UT_MISSING_TRACE_FORMAT) { omrmem_free_memory(tempString); } } omrmem_free_memory(componentDataPtr->tracepointFormattingStrings); } if (componentDataPtr->tracepointcounters != NULL) { omrmem_free_memory(componentDataPtr->tracepointcounters); } if (componentDataPtr->qualifiedComponentName != componentDataPtr->componentName && componentDataPtr->qualifiedComponentName != NULL) { omrmem_free_memory(componentDataPtr->qualifiedComponentName); } if (componentDataPtr->componentName != NULL) { omrmem_free_memory(componentDataPtr->componentName); } if (componentDataPtr->formatStringsFileName != NULL) { omrmem_free_memory(componentDataPtr->formatStringsFileName); } omrmem_free_memory(componentDataPtr); UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentData completed\n")); return; }
omr_error_t omr_ras_initMethodDictionary(OMR_VM *vm, size_t numProperties, const char * const *propertyNames) { omr_error_t rc = OMR_ERROR_NONE; if (NULL == vm->_methodDictionary) { OMRPORT_ACCESS_FROM_OMRVM(vm); OMR_MethodDictionary *methodDictionary = (OMR_MethodDictionary *)omrmem_allocate_memory(sizeof(*methodDictionary), OMRMEM_CATEGORY_OMRTI); if (NULL != methodDictionary) { rc = methodDictionary->init(vm, numProperties, propertyNames); if (OMR_ERROR_NONE == rc) { vm->_methodDictionary = methodDictionary; } else { omrmem_free_memory(methodDictionary); } } else { rc = OMR_ERROR_OUT_OF_NATIVE_MEMORY; } } return rc; }
bool MM_VerboseManagerImpl::reconfigureVerboseGC(OMR_VM *omrVM) { OMRPORT_ACCESS_FROM_OMRVM(omrVM); /* If the pid is specified in the filename, then the pid of the * new process will be used during verbose reinitialization, * otherwise we append the pid of the child before the extension. */ WriterType type = parseWriterType(NULL, filename, 0, 0); /* All parameters other than filename aren't used */ if ( ((type == VERBOSE_WRITER_FILE_LOGGING_SYNCHRONOUS) || (type == VERBOSE_WRITER_FILE_LOGGING_BUFFERED)) && (NULL == strstr(filename, "%p")) && (NULL == strstr(filename, "%pid")) ) { #define MAX_PID_LENGTH 16 char pidStr[MAX_PID_LENGTH]; uintptr_t pid = omrsysinfo_get_pid(); int pidLen = snprintf(pidStr,MAX_PID_LENGTH, "_%lu",(long unsigned int)pid); /* Allocate new buffer */ char *newLog = (char *)omrmem_allocate_memory(pidLen+strlen(filename)+1, OMRMEM_CATEGORY_MM); /* Locate extension, if any */ char *extension = strchr(filename, '.'); if (NULL != extension) { size_t nameLen = extension - filename; size_t extLen = strlen(filename) - nameLen; strncpy(newLog, filename, nameLen); strncpy(newLog + nameLen, pidStr, pidLen); strncpy(newLog + nameLen + pidLen, extension, extLen); newLog[nameLen + pidLen + extLen] = '\0'; /* strncpy does NOT NULL terminate */ } else { size_t len = strlen(filename); strncpy(newLog,filename,len); newLog[len] = '\0'; /* strncpy does NOT NULL terminate */ strncat(newLog,pidStr,pidLen); /* strncat does NULL terminate */ } omrmem_free_memory(this->filename); filename = newLog; } return MM_VerboseManager::configureVerboseGC(omrVM, filename, 1, 0); }
static intptr_t translateModifiedUtf8ToPlatform(OMRPortLibrary *portLibrary, const char *inBuffer, uintptr_t inBufferSize, char **outBuffer) { OMRPORT_ACCESS_FROM_OMRPORT(portLibrary); char *result = 0; int32_t bufferLength = 0; int32_t resultLength = 0; *outBuffer = NULL; bufferLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW, inBuffer, inBufferSize, NULL, 0); /* get the size of the platform string */ if (bufferLength < 0) { return bufferLength; /* some error occurred */ } else { bufferLength += MAX_STRING_TERMINATOR_LENGTH; } result = (char *)omrmem_allocate_memory(bufferLength, OMRMEM_CATEGORY_PORT_LIBRARY); if (NULL == result) { return OMRPORT_ERROR_STRING_MEM_ALLOCATE_FAILED; } resultLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW, inBuffer, inBufferSize, result, bufferLength); /* do the conversion */ if (resultLength < 0) { omrmem_free_memory(result); return resultLength; /* some error occurred */ } else { memset(result + resultLength, 0, MAX_STRING_TERMINATOR_LENGTH); *outBuffer = result; return 0; } }
omr_error_t setTracePointsToParsed(const char *componentName, UtComponentList *componentList, int32_t all, int32_t first, int32_t last, unsigned char value, int level, const char *groupName, BOOLEAN suppressMessages, int32_t setActive) { const char *tempstr = NULL; char *newstr = NULL; char *newstr2 = NULL; size_t namelength = 0; size_t groupnamelength = 0; omr_error_t rc = OMR_ERROR_NONE; OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary)); UT_DBGOUT(2, ("<UT> setTracePointsToParsed: %s\n", componentName)); if (strchr(componentName, '.') != NULL) { /* we have a range of tracepoints */ rc = parseAndSetTracePointsInRange(componentName, value, setActive, suppressMessages); /* can't combine ranges and levels etc, so just duck out now */ return rc; } if ((tempstr = strchr(componentName, '{')) != NULL || (tempstr = strchr(componentName, '(')) != NULL) { char closingBrace; UT_DBGOUT(2, ("<UT> setTracePointsTo: has detected a suboption %s in %s\n", tempstr, componentName)); namelength = tempstr - componentName; if (*tempstr == '{') { closingBrace = '}'; } else { closingBrace = ')'; } /* Look for empty braces - this is always an error */ if (*(tempstr + 1) == closingBrace) { reportCommandLineError(suppressMessages, "Error: found empty braces or parentheses"); return OMR_ERROR_ILLEGAL_ARGUMENT; } /* Look for unclosed braces - another error */ if (strchr(tempstr, closingBrace) == NULL) { reportCommandLineError(suppressMessages, "Error: unclosed braces or parentheses"); return OMR_ERROR_ILLEGAL_ARGUMENT; } tempstr++; /* points at first option char now */ if (0 == j9_cmdla_strnicmp(tempstr, UT_LEVEL_KEYWORD, strlen(UT_LEVEL_KEYWORD)) || *tempstr == 'l' || *tempstr == 'L') { while (!isdigit(*tempstr)) { if (*tempstr == ',' || *tempstr == '}' || *tempstr == '\0') { reportCommandLineError(suppressMessages, "Trace level required without an integer level specifier"); return OMR_ERROR_ILLEGAL_ARGUMENT; } tempstr++; } sscanf(tempstr, "%d", &level); newstr = (char *)omrmem_allocate_memory(namelength + 1, OMRMEM_CATEGORY_TRACE); if (newstr == NULL) { UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate tempname info\n", componentName)); return OMR_ERROR_OUT_OF_NATIVE_MEMORY; } strncpy(newstr, componentName, namelength); newstr[namelength] = '\0'; UT_DBGOUT(2, ("<UT> setTracePointsTo: Level detected %d in %s\n", level, newstr)); componentName = newstr; /* actual configuration of the component will now fall through to below */ } else { /* must be a group name note - types are now groups */ UT_DBGOUT(2, ("<UT> setTracePointsTo: A Group detected \n")); newstr = (char *)omrmem_allocate_memory(namelength + 1, OMRMEM_CATEGORY_TRACE); if (newstr == NULL) { UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate tempname info\n", componentName)); return OMR_ERROR_OUT_OF_NATIVE_MEMORY; } strncpy(newstr, componentName, namelength); newstr[namelength] = '\0'; groupnamelength = strlen(componentName) - namelength; newstr2 = (char *)omrmem_allocate_memory(groupnamelength - 1, OMRMEM_CATEGORY_TRACE); if (newstr2 == NULL) { UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate tempname info\n", componentName)); return OMR_ERROR_OUT_OF_NATIVE_MEMORY; } strncpy(newstr2, componentName + namelength + 1, groupnamelength - 2); newstr2[groupnamelength - 2] = '\0'; groupName = newstr2; UT_DBGOUT(2, ("<UT> setTracePointsTo: Group %s detected in %s\n", groupName, newstr)); componentName = newstr; } } rc = setTracePointsForComponent(componentName, componentList, all, first, last, value, level, groupName, suppressMessages, setActive); /* tidy up */ if (newstr != NULL) { omrmem_free_memory(newstr); } if (newstr2 != NULL) { omrmem_free_memory(newstr2); } return rc; }