From b2c392c359b3ae2ae6e17eaa34db3b80b01137b1 Mon Sep 17 00:00:00 2001 From: mikael Date: Tue, 3 Jul 2012 17:35:00 -0700 Subject: [PATCH] 7129724: MAC: Core file location is wrong in crash report Summary: Updated core path location to reflect macosx default Reviewed-by: dholmes, kamg --- src/os/bsd/vm/os_bsd.cpp | 11 +++++++++++ src/os/linux/vm/os_linux.cpp | 12 ++++++++++++ src/os/posix/vm/os_posix.cpp | 10 +++++----- src/os/solaris/vm/os_solaris.cpp | 13 +++++++++++++ src/share/vm/runtime/os.hpp | 4 ++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/os/bsd/vm/os_bsd.cpp b/src/os/bsd/vm/os_bsd.cpp index 0305b3df0..68ab3fc4c 100644 --- a/src/os/bsd/vm/os_bsd.cpp +++ b/src/os/bsd/vm/os_bsd.cpp @@ -5801,3 +5801,14 @@ bool os::is_headless_jre() { return true; } + +// Get the default path to the core file +// Returns the length of the string +int os::get_core_path(char* buffer, size_t bufferSize) { + int n = jio_snprintf(buffer, bufferSize, "/cores"); + + // Truncate if theoretical string was longer than bufferSize + n = MIN2(n, (int)bufferSize); + + return n; +} diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp index ce7c71b9d..df6eb0e71 100644 --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -5447,6 +5447,18 @@ bool os::is_headless_jre() { return true; } +// Get the default path to the core file +// Returns the length of the string +int os::get_core_path(char* buffer, size_t bufferSize) { + const char* p = get_current_directory(buffer, bufferSize); + + if (p == NULL) { + assert(p != NULL, "failed to get current directory"); + return 0; + } + + return strlen(buffer); +} #ifdef JAVASE_EMBEDDED // diff --git a/src/os/posix/vm/os_posix.cpp b/src/os/posix/vm/os_posix.cpp index 3e49b8b9d..ce355c1cc 100644 --- a/src/os/posix/vm/os_posix.cpp +++ b/src/os/posix/vm/os_posix.cpp @@ -34,19 +34,19 @@ // Check core dump limit and report possible place where core can be found void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) { + int n; struct rlimit rlim; - static char cwd[O_BUFLEN]; bool success; - get_current_directory(cwd, sizeof(cwd)); + n = get_core_path(buffer, bufferSize); if (getrlimit(RLIMIT_CORE, &rlim) != 0) { - jio_snprintf(buffer, bufferSize, "%s/core or core.%d (may not exist)", cwd, current_process_id()); + jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (may not exist)", current_process_id()); success = true; } else { switch(rlim.rlim_cur) { case RLIM_INFINITY: - jio_snprintf(buffer, bufferSize, "%s/core or core.%d", cwd, current_process_id()); + jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d", current_process_id()); success = true; break; case 0: @@ -54,7 +54,7 @@ void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* success = false; break; default: - jio_snprintf(buffer, bufferSize, "%s/core or core.%d (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", cwd, current_process_id(), (unsigned long)(rlim.rlim_cur >> 10)); + jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", current_process_id(), (unsigned long)(rlim.rlim_cur >> 10)); success = true; break; } diff --git a/src/os/solaris/vm/os_solaris.cpp b/src/os/solaris/vm/os_solaris.cpp index 1d241d650..5e11a9d55 100644 --- a/src/os/solaris/vm/os_solaris.cpp +++ b/src/os/solaris/vm/os_solaris.cpp @@ -6537,3 +6537,16 @@ int os::bind(int fd, struct sockaddr* him, socklen_t len) { INTERRUPTIBLE_RETURN_INT_NORESTART(::bind(fd, him, len),\ os::Solaris::clear_interrupted); } + +// Get the default path to the core file +// Returns the length of the string +int os::get_core_path(char* buffer, size_t bufferSize) { + const char* p = get_current_directory(buffer, bufferSize); + + if (p == NULL) { + assert(p != NULL, "failed to get current directory"); + return 0; + } + + return strlen(buffer); +} diff --git a/src/share/vm/runtime/os.hpp b/src/share/vm/runtime/os.hpp index 3be7248a9..508edba8a 100644 --- a/src/share/vm/runtime/os.hpp +++ b/src/share/vm/runtime/os.hpp @@ -665,6 +665,10 @@ class os: AllStatic { // On Windows this will create an actual minidump, on Linux/Solaris it will simply check core dump limits static void check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize); + // Get the default path to the core file + // Returns the length of the string + static int get_core_path(char* buffer, size_t bufferSize); + // JVMTI & JVM monitoring and management support // The thread_cpu_time() and current_thread_cpu_time() are only // supported if is_thread_cpu_time_supported() returns true. -- GitLab