static int J9THREAD_PROC moduleUnloadAfterThreadDetachHelper(void *entryArg) { omr_error_t rc = OMR_ERROR_NONE; ChildThreadData *childData = (ChildThreadData *)entryArg; OMRTestVM *testVM = childData->testVM; OMR_VMThread *vmthread = NULL; OMRPORT_ACCESS_FROM_OMRPORT(testVM->portLibrary); rc = OMRTEST_PRINT_ERROR(OMR_Thread_Init(&testVM->omrVM, NULL, &vmthread, "moduleUnloadAfterThreadDetachHelper")); if (OMR_ERROR_NONE != rc) { childData->childRc = rc; return -1; } UT_OMR_TEST_MODULE_LOADED(testVM->omrVM._trcEngine->utIntf); Trc_OMR_Test_String(vmthread, "This tracepoint should appear."); rc = OMRTEST_PRINT_ERROR(OMR_Thread_Free(vmthread)); if (OMR_ERROR_NONE != rc) { childData->childRc = rc; return -1; } /* This should fail silently without crashing */ UT_OMR_TEST_MODULE_UNLOADED(testVM->omrVM._trcEngine->utIntf); return 0; }
static int J9THREAD_PROC shutdownTraceHelper(void *entryArg) { omr_error_t rc = OMR_ERROR_NONE; ChildThreadData *childData = (ChildThreadData *)entryArg; OMRTestVM *testVM = childData->testVM; OMR_VMThread *vmthread = NULL; OMRPORT_ACCESS_FROM_OMRPORT(testVM->portLibrary); rc = OMRTEST_PRINT_ERROR(OMR_Thread_Init(&testVM->omrVM, NULL, &vmthread, "shutdownTraceHelper")); if (OMR_ERROR_NONE != rc) { childData->childRc = rc; return -1; } rc = OMRTEST_PRINT_ERROR(omr_ras_cleanupTraceEngine(vmthread)); if (OMR_ERROR_NONE != rc) { childData->childRc = rc; return -1; } rc = OMRTEST_PRINT_ERROR(OMR_Thread_Free(vmthread)); if (OMR_ERROR_NONE != rc) { childData->childRc = rc; return -1; } return 0; }
omr_error_t OMRAgent_OnUnload(OMR_TI const *ti, OMR_VM *vm) { OMRPORT_ACCESS_FROM_OMRVM(vm); omr_error_t rc = testData.rc; OMR_VMThread *vmThread = NULL; if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(ti->BindCurrentThread(vm, NULL, &vmThread)); } if (OMR_ERROR_NONE == rc) { omr_error_t apiRc = OMRTEST_PRINT_ERROR(ti->DeregisterRecordSubscriber(vmThread, testData.subscriptionID)); if (OMR_ERROR_NONE != apiRc) { rc = OMR_ERROR_INTERNAL; } } if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(ti->UnbindCurrentThread(vmThread)); } testData.rc = rc; return rc; }
static omr_error_t testTraceAgentGetMemorySize(OMR_VMThread *vmThread, OMR_TI const *ti) { OMRPORT_ACCESS_FROM_OMRVMTHREAD(vmThread); omr_error_t rc = OMR_ERROR_NONE; omr_error_t testRc = OMR_ERROR_NONE; uint64_t memorySize = 0; #if defined(LINUX) || defined(AIXPPC) || defined(OMR_OS_WINDOWS) || defined(OSX) if (OMR_ERROR_NONE == testRc) { rc = OMRTEST_PRINT_ERROR(ti->GetFreePhysicalMemorySize(vmThread, &memorySize)); if (OMR_ERROR_NONE != rc) { omrtty_printf("%s:%d GetFreePhysicalMemorySize() failed !\n", __FILE__, __LINE__); testRc = OMR_ERROR_INTERNAL; } else { omrtty_printf("%s:%d Free physical memory size (in bytes): %llu, rc = %d (%s), the function call is successful !\n", __FILE__, __LINE__, memorySize, rc, omrErrorToString(rc)); } } #if defined(LINUX) || defined(OMR_OS_WINDOWS) || defined(OSX) if (OMR_ERROR_NONE == testRc) { rc = OMRTEST_PRINT_ERROR(ti->GetProcessVirtualMemorySize(vmThread, &memorySize)); if (OMR_ERROR_NONE != rc) { omrtty_printf("%s:%d GetProcessVirtualMemorySize() failed !\n", __FILE__, __LINE__); testRc = OMR_ERROR_INTERNAL; } else { omrtty_printf("%s:%d Process virtual memory size (in bytes): %llu, rc = %d (%s), the function call is successful !\n", __FILE__, __LINE__, memorySize, rc, omrErrorToString(rc)); } } if (OMR_ERROR_NONE == testRc) { rc = OMRTEST_PRINT_ERROR(ti->GetProcessPhysicalMemorySize(vmThread, &memorySize)); if (OMR_ERROR_NONE != rc) { omrtty_printf("%s:%d GetProcessPhysicalMemorySize() failed !\n", __FILE__, __LINE__); testRc = OMR_ERROR_INTERNAL; } else { omrtty_printf("%s:%d Process physical memory size (in bytes): %llu, rc = %d (%s), the function call is successful !\n", __FILE__, __LINE__, memorySize, rc, omrErrorToString(rc)); } } #endif /* defined(LINUX) || defined(OMR_OS_WINDOWS) || defined(OSX) */ #if defined(LINUX) || defined(AIXPPC)|| defined(OMR_OS_WINDOWS) if (OMR_ERROR_NONE == testRc) { rc = OMRTEST_PRINT_ERROR(ti->GetProcessPrivateMemorySize(vmThread, &memorySize)); if (OMR_ERROR_NONE != rc) { omrtty_printf("%s:%d GetProcessPrivateMemorySize() failed !\n", __FILE__, __LINE__); testRc = OMR_ERROR_INTERNAL; } else { omrtty_printf("%s:%d Process private memory size (in bytes): %llu, rc = %d (%s), the function call is successful !\n", __FILE__, __LINE__, memorySize, rc, omrErrorToString(rc)); } } #endif /* defined(LINUX) || defined(AIXPPC) || defined(OMR_OS_WINDOWS) */ #endif /* defined(LINUX) || defined(AIXPPC) || defined(OMR_OS_WINDOWS) || defined(OSX) */ return testRc; }
static int J9THREAD_PROC childThreadMain(void *entryArg) { omr_error_t rc = OMR_ERROR_NONE; TestChildThreadData *childData = (TestChildThreadData *)entryArg; OMRTestVM *testVM = childData->testVM; OMR_VMThread *vmthread = NULL; OMRPORT_ACCESS_FROM_OMRPORT(testVM->portLibrary); Trc_OMR_Test_String(vmthread, "This tracepoint should be ignored. Trace is not yet enabled for this thread."); rc = OMRTEST_PRINT_ERROR(OMR_Thread_Init(&testVM->omrVM, NULL, &vmthread, "traceTest-child")); if (OMR_ERROR_NONE != rc) { childData->childRc = rc; return -1; } /* Fire some trace points */ Trc_OMR_Test_Init(); Trc_OMR_Test_String(vmthread, "Child Hello World!"); Trc_OMR_Test_Ptr(vmthread, vmthread); Trc_OMR_Test_Int(vmthread, 10); Trc_OMR_Test_ManyParms(vmthread, "Child Hello again!", vmthread, 10); rc = OMRTEST_PRINT_ERROR(OMR_Thread_Free(vmthread)); if (OMR_ERROR_NONE != rc) { childData->childRc = rc; return -1; } Trc_OMR_Test_String(vmthread, "This tracepoint should be ignored. Trace has been disabled for this thread."); omrthread_monitor_enter(childData->shutdownCond); childData->isDead = TRUE; omrthread_monitor_notify_all(childData->shutdownCond); omrthread_monitor_exit(childData->shutdownCond); return 0; }
static int J9THREAD_PROC attachDetachHelper(void *entryArg) { omr_error_t rc = OMR_ERROR_NONE; ChildThreadData *childData = (ChildThreadData *)entryArg; OMRTestVM *testVM = childData->testVM; OMR_VMThread *vmthread = NULL; OMRPORT_ACCESS_FROM_OMRPORT(testVM->portLibrary); rc = OMRTEST_PRINT_ERROR(OMR_Thread_Init(&testVM->omrVM, NULL, &vmthread, "attachDetachHelper")); if (OMR_ERROR_NONE != rc) { if (OMR_ERROR_NOT_AVAILABLE == rc) { /* this is ok, it means the shutdown helper finished first */ return 0; } else { childData->childRc = rc; return -1; } } /* yield to encourage concurency */ omrthread_sleep(1); /* Fire some trace points */ const char *alphabetUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; size_t stringsPerTraceBuffer = (1024 + strlen(alphabetUpper) - 1) / strlen(alphabetUpper); for (size_t i = 0; i < stringsPerTraceBuffer * 5; i += 1) { Trc_OMR_Test_String(vmthread, alphabetUpper); omrthread_yield(); } rc = OMRTEST_PRINT_ERROR(OMR_Thread_Free(vmthread)); if (OMR_ERROR_NONE != rc) { childData->childRc = rc; return -1; } return 0; }
omr_error_t OMRAgent_OnLoad(OMR_TI const *ti, OMR_VM *vm, char const *options, OMR_AgentCallbacks *agentCallbacks, ...) { OMRPORT_ACCESS_FROM_OMRVM(vm); OMR_VMThread *vmThread = NULL; omr_error_t rc = OMR_ERROR_NONE; void *traceMeta = NULL; int32_t traceMetaLength = 0; const char *setOpts[] = { NULL }; UtSubscription *subscriptionID2 = NULL; testData.rc = OMR_ERROR_NONE; testData.subscriptionID = NULL; /* exercise trace API without attaching thread to VM */ if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(testTraceAgentFromUnattachedThread(ti, OMRPORTLIB)); } if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(ti->BindCurrentThread(vm, NULL, &vmThread)); } if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(testTraceAgentGetMemorySize(vmThread, ti)); } if (OMR_ERROR_NONE == rc) { omr_error_t apiRc = OMRTEST_PRINT_ERROR(ti->SetTraceOptions(vmThread, setOpts)); if (OMR_ERROR_NONE != apiRc) { rc = OMR_ERROR_INTERNAL; } } if (OMR_ERROR_NONE == rc) { omr_error_t apiRc = OMRTEST_PRINT_ERROR(ti->GetTraceMetadata(vmThread, &traceMeta, &traceMetaLength)); if (OMR_ERROR_NONE != apiRc) { rc = OMR_ERROR_INTERNAL; } else { omrtty_printf(" traceMetaLength=%d\n", traceMetaLength); } } if (OMR_ERROR_NONE == rc) { omr_error_t apiRc = OMRTEST_PRINT_ERROR(ti->RegisterRecordSubscriber(vmThread, "sample", subscribeFunc, alarmFunc, (void *)"my user data", &testData.subscriptionID)); if (OMR_ERROR_NONE != apiRc) { rc = OMR_ERROR_INTERNAL; } } if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(ti->RegisterRecordSubscriber(vmThread, "", subscribeFunc, NULL, NULL, &subscriptionID2)); } if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(ti->DeregisterRecordSubscriber(vmThread, subscriptionID2)); } if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(ti->FlushTraceData(vmThread)); } if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(testNegativeCases(vmThread, ti)); } if (OMR_ERROR_NONE == rc) { rc = OMRTEST_PRINT_ERROR(ti->UnbindCurrentThread(vmThread)); } testData.rc = rc; return rc; }