From 6757b972bc08440962989a43440e26a649561454 Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Fri, 19 Oct 2018 13:05:18 -0400 Subject: [PATCH] Enable RAS Dump support on OSX More details here: https://github.com/eclipse/openj9/issues/3380. closes: https://github.com/eclipse/openj9/issues/3380. closes: https://github.com/eclipse/openj9/issues/3343. Signed-off-by: Babneet Singh --- runtime/rasdump/dmpagent.c | 36 +++++++++++++++++++----------------- runtime/rasdump/dmpsup.c | 8 ++++---- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/runtime/rasdump/dmpagent.c b/runtime/rasdump/dmpagent.c index 914a8bc30c6..85bce466fe7 100644 --- a/runtime/rasdump/dmpagent.c +++ b/runtime/rasdump/dmpagent.c @@ -37,12 +37,12 @@ #include #include #endif -#ifdef LINUX +#if defined(LINUX) || defined(OSX) #include #include #include #include -#endif +#endif /* defined(LINUX) || defined(OSX) */ #include "ut_j9dmp.h" @@ -287,15 +287,17 @@ static const J9RASdumpSpec rasDumpSpecs[] = 1, 1, #if defined(WIN32) "windbg -p %pid -c \".setdll %vmbin\\j9windbg\"", -#elif defined(LINUX) +#elif defined(LINUX) /* defined(WIN32) */ "gdb -p %pid", -#elif defined(AIXPPC) +#elif defined(AIXPPC) /* defined(WIN32) */ "dbx -a %pid", -#elif defined(J9ZOS390) +#elif defined(J9ZOS390) /* defined(WIN32) */ "dbx -a %pid", -#else +#elif defined(OSX) /* defined(WIN32) */ + "lldb -p %pid", +#else /* defined(WIN32) */ NULL, -#endif +#endif /* defined(WIN32) */ NULL, 0, J9RAS_DUMP_DO_SUSPEND_OTHER_DUMPS, @@ -677,7 +679,7 @@ doSystemDump(J9RASdumpAgent *agent, char *label, J9RASdumpContext *context) const char* cacheDir = NULL; J9RAS* rasStruct = vm->j9ras; -#if defined(J9VM_OPT_SHARED_CLASSES) && defined(LINUX) +#if defined(J9VM_OPT_SHARED_CLASSES) && (defined(LINUX) || defined(OSX)) J9SharedClassJavacoreDataDescriptor sharedClassData; /* set up cacheDir with the Shared Classes Cache file if it is in use. */ @@ -689,7 +691,7 @@ doSystemDump(J9RASdumpAgent *agent, char *label, J9RASdumpContext *context) } } } -#endif +#endif /* defined(J9VM_OPT_SHARED_CLASSES) && (defined(LINUX) || defined(OSX)) */ reportDumpRequest(privatePortLibrary,context,"System",label); @@ -821,7 +823,7 @@ doToolDump(J9RASdumpAgent *agent, char *label, J9RASdumpContext *context) j9mem_free_memory(unicodePath); } } -#elif (defined(LINUX) && !defined(J9ZTPF)) || defined(AIXPPC) +#elif (defined(LINUX) && !defined(J9ZTPF)) || defined(AIXPPC) || defined(OSX) /* defined(WIN32) */ { IDATA retVal; @@ -842,7 +844,7 @@ doToolDump(J9RASdumpAgent *agent, char *label, J9RASdumpContext *context) omrthread_sleep(msec); } } -#elif defined(J9ZOS390) +#elif defined(J9ZOS390) /* defined(WIN32) */ { const char *argv[] = {"/bin/sh", "-c", NULL, NULL}; extern const char **environ; @@ -869,9 +871,9 @@ doToolDump(J9RASdumpAgent *agent, char *label, J9RASdumpContext *context) omrthread_sleep(msec); } } -#else +#else /* defined(WIN32) */ j9nls_printf(PORTLIB, J9NLS_INFO | J9NLS_STDERR, J9NLS_DMP_DUMP_NOT_AVAILABLE_STR, "Tool"); -#endif +#endif /* defined(WIN32) */ } else { j9nls_printf(PORTLIB, J9NLS_ERROR | J9NLS_STDERR, J9NLS_DMP_MISSING_EXECUTABLE_STR); } @@ -1339,16 +1341,16 @@ fixDumpLabel(J9JavaVM *vm, const J9RASdumpSpec *spec, char **labelPtr, IDATA new int ok = 0; /* Get absolute name */ -#if defined (WIN32) +#if defined(WIN32) ok = (GetCurrentDirectoryW(J9_MAX_DUMP_PATH, unicodeTemp) != 0); if (ok) { WideCharToMultiByte(OS_ENCODING_CODE_PAGE, OS_ENCODING_WC_FLAGS, unicodeTemp, -1, prefix, J9_MAX_DUMP_PATH, NULL, NULL); } -#elif defined(LINUX) || defined(AIXPPC) +#elif defined(LINUX) || defined(AIXPPC) || defined(OSX) /* defined(WIN32) */ ok = (getcwd(prefix, J9_MAX_DUMP_PATH) != 0); -#elif defined(J9ZOS390) +#elif defined(J9ZOS390) /* defined(WIN32) */ ok = (atoe_getcwd(prefix, J9_MAX_DUMP_PATH) != 0); -#endif +#endif /* defined(WIN32) */ if (ok) { prefix[J9_MAX_DUMP_PATH-1] = '\0'; diff --git a/runtime/rasdump/dmpsup.c b/runtime/rasdump/dmpsup.c index 8e97d47c6a0..565075f509f 100644 --- a/runtime/rasdump/dmpsup.c +++ b/runtime/rasdump/dmpsup.c @@ -1206,8 +1206,8 @@ JVM_OnUnload(JavaVM *vm, void *reserved) } /** - * On Linux the first call to get a backtrace can cause some initialisation work. - * If this is called in a signal handler with other threads paused then one of + * On Linux and OSX the first call to get a backtrace can cause some initialisation + * work. If this is called in a signal handler with other threads paused then one of * those can hold a lock required for the initialisation to complete. This causes * a hang. Therefore we do one redundant call to backtrace at startup to prevent * java dumps hanging the VM. @@ -1217,7 +1217,7 @@ JVM_OnUnload(JavaVM *vm, void *reserved) static void initBackTrace(J9JavaVM *vm) { -#ifdef LINUX +#if defined(LINUX) || defined(OSX) J9PlatformThread threadInfo; J9Heap *heap; char backingStore[8096]; @@ -1229,7 +1229,7 @@ initBackTrace(J9JavaVM *vm) if( j9introspect_backtrace_thread(&threadInfo, heap, NULL) != 0 ) { j9introspect_backtrace_symbols(&threadInfo, heap); } -#endif +#endif /* defined(LINUX) || defined(OSX) */ } /**