コード例 #1
0
ファイル: VerboseManagerImpl.cpp プロジェクト: dinogun/omr
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);
}
コード例 #2
0
ファイル: GCConfigTest.cpp プロジェクト: DanHeidinga/omr
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);
}