- Fix broken preprocessor directives.

- Use sysctl(3) instead of procfs(5) when we need executable path from PID.

MFH:		2015Q3
This commit is contained in:
Jung-uk Kim
2015-07-02 18:17:12 +00:00
parent 6d3cd0eac4
commit fd492a9fe5
4 changed files with 148 additions and 1 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
PORTNAME= openjdk
PORTVERSION= ${JDK_MAJOR_VERSION}.${JDK_UPDATE_VERSION}.${JDK_BUILD_NUMBER:S/^0//}
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= java devel
MASTER_SITES= http://download.java.net/openjdk/jdk${JDK_MAJOR_VERSION}/promoted/b${DIST_BUILD_NUMBER}/:jdk \
https://adopt-openjdk.ci.cloudbees.com/job/jtreg/${JTREG_JENKINS_BUILD}/artifact/:jtreg \
@@ -0,0 +1,31 @@
--- hotspot/src/os/bsd/vm/os_bsd.cpp.orig
+++ hotspot/src/os/bsd/vm/os_bsd.cpp
@@ -1234,14 +1234,14 @@
pid_t os::Bsd::gettid() {
int retval = -1;
-#ifdef __APPLE__ //XNU kernel
+#if defined(__APPLE__) //XNU kernel
// despite the fact mach port is actually not a thread id use it
// instead of syscall(SYS_thread_selfid) as it certainly fits to u4
retval = ::pthread_mach_thread_np(::pthread_self());
guarantee(retval != 0, "just checking");
return retval;
-#elifdef __FreeBSD__
+#elif defined(__FreeBSD__)
#if __FreeBSD_version > 900030
return ::pthread_getthreadid_np();
#else
@@ -1249,9 +1249,9 @@
thr_self(&tid);
return (pid_t)tid;
#endif
-#elifdef __OpenBSD__
+#elif defined(__OpenBSD__)
retval = syscall(SYS_getthrid);
-#elifdef __NetBSD__
+#elif defined(__NetBSD__)
retval = (pid_t) _lwp_self();
#endif
@@ -0,0 +1,63 @@
--- hotspot/src/os/bsd/vm/vmError_bsd.cpp.orig
+++ hotspot/src/os/bsd/vm/vmError_bsd.cpp
@@ -33,30 +33,50 @@
#include <sys/syscall.h>
#include <unistd.h>
#include <signal.h>
+#ifdef __FreeBSD__
+#include <limits.h>
+#include <sys/sysctl.h>
+#endif
+
+#define GDB_CMD "gdb"
+
+static void set_debugger(char *buf, int buflen) {
+ int pid = os::current_process_id();
+#ifdef __FreeBSD__
+ char cmd[PATH_MAX+1];
+ int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid };
+ size_t len = sizeof(cmd);
+ if (sysctl(name, 4, cmd, &len, NULL, 0) == 0 && len > 0) {
+ cmd[len] = '\0';
+ jio_snprintf(buf, buflen, "%s %s %d", GDB_CMD, cmd, pid);
+ } else
+#endif
+ jio_snprintf(buf, buflen, "%s /proc/%d/file %d", GDB_CMD, pid, pid);
+}
void VMError::show_message_box(char *buf, int buflen) {
bool yes;
do {
- error_string(buf, buflen);
- int len = (int)strlen(buf);
+ intx tid = os::current_thread_id();
+ set_debugger(buf, buflen);
+ int len = (int)strlen(buf) + 1;
+ char *msg = &buf[len];
+ error_string(msg, buflen - len);
+ len += (int)strlen(msg);
char *p = &buf[len];
jio_snprintf(p, buflen - len,
"\n\n"
"Do you want to debug the problem?\n\n"
- "To debug, run 'gdb /proc/%d/file %d'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n"
- "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
+ "To debug, run '%s'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n"
+ "Enter 'yes' to launch " GDB_CMD " automatically (PATH must include " GDB_CMD ")\n"
"Otherwise, press RETURN to abort...",
- os::current_process_id(), os::current_process_id(),
- os::current_thread_id(), os::current_thread_id());
+ buf, tid, tid);
- yes = os::message_box("Unexpected Error", buf);
+ yes = os::message_box("Unexpected Error", msg);
if (yes) {
// yes, user asked VM to launch debugger
- jio_snprintf(buf, buflen, "gdb /proc/%d/file %d",
- os::current_process_id(), os::current_process_id());
-
os::fork_and_exec(buf);
yes = false;
}
@@ -0,0 +1,53 @@
--- jdk/src/solaris/bin/java_md_solinux.c.orig
+++ jdk/src/solaris/bin/java_md_solinux.c
@@ -35,6 +35,9 @@
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
+#ifdef __FreeBSD__
+#include <sys/sysctl.h>
+#endif
#include "manifest_info.h"
#include "version_comp.h"
@@ -925,7 +928,7 @@
* onwards the filename returned in DL_info structure from dladdr is
* an absolute pathname so technically realpath isn't required.
* On Linux we read the executable name from /proc/self/exe.
- * On FreeBSD we read the executable name from /proc/curproc/file.
+ * On FreeBSD, we get the executable name via sysctl(3).
* As a fallback, and for platforms other than Solaris, Linux, and
* FreeBSD, we use FindExecName to compute the executable name.
*/
@@ -954,13 +957,9 @@
}
}
}
-#elif defined(__linux__) || defined(__FreeBSD__)
+#elif defined(__linux__)
{
-#if defined(__FreeBSD__)
- const char* self = "/proc/curproc/file";
-#else
const char* self = "/proc/self/exe";
-#endif
char buf[PATH_MAX+1];
int len = readlink(self, buf, PATH_MAX);
if (len >= 0) {
@@ -968,6 +967,16 @@
exec_path = JLI_StringDup(buf);
}
}
+#elif defined(__FreeBSD__)
+ {
+ char buf[PATH_MAX+1];
+ int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+ size_t len = sizeof(buf);
+ if (sysctl(name, 4, buf, &len, NULL, 0) == 0 && len > 0) {
+ buf[len] = '\0';
+ exec_path = JLI_StringDup(buf);
+ }
+ }
#else /* !__solaris__ && !__linux__ && !__FreeBSD__ */
{
/* Not implemented */