From 7268bef341b5668169892f5ac0569d5161d25ec9 Mon Sep 17 00:00:00 2001 Message-Id: <7268bef341b5668169892f5ac0569d5161d25ec9.1368289639.git.agx@sigxcpu.org> From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 11 May 2013 18:26:43 +0200 Subject: [PATCH] kfreebsd-support-hotspot.diff --- agent/src/os/linux/LinuxDebuggerLocal.c | 44 ++++++++- agent/src/os/linux/libproc.h | 8 ++ agent/src/os/linux/ps_core.c | 38 ++++++++ agent/src/os/linux/ps_proc.c | 54 +++++++++++ make/defs.make | 7 +- make/linux/Makefile | 3 + make/linux/makefiles/defs.make | 2 +- src/os/linux/vm/attachListener_linux.cpp | 18 +++- src/os/linux/vm/jvm_linux.cpp | 2 + src/os/linux/vm/os_linux.cpp | 32 +++++++ src/os/posix/launcher/java_md.c | 12 +-- src/os_cpu/linux_x86/vm/os_linux_x86.cpp | 150 ++++++++++++++++++++++++++++++ src/share/vm/memory/allocation.hpp | 6 +- src/share/vm/oops/generateOopMap.cpp | 10 +- 14 files changed, 362 insertions(+), 24 deletions(-) diff --git openjdk/hotspot/agent/src/os/linux/LinuxDebuggerLocal.c openjdk/agent/src/os/linux/LinuxDebuggerLocal.c index 5771fdd..5019266 100644 --- openjdk/hotspot/agent/src/os/linux/LinuxDebuggerLocal.c +++ openjdk/hotspot/agent/src/os/linux/LinuxDebuggerLocal.c @@ -316,7 +316,7 @@ JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLo #ifdef i386 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg - +#ifdef __linux__ regs[REG_INDEX(GS)] = (uintptr_t) gregs.xgs; regs[REG_INDEX(FS)] = (uintptr_t) gregs.xfs; regs[REG_INDEX(ES)] = (uintptr_t) gregs.xes; @@ -332,7 +332,23 @@ JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLo regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip; regs[REG_INDEX(CS)] = (uintptr_t) gregs.xcs; regs[REG_INDEX(SS)] = (uintptr_t) gregs.xss; - +#elif defined(__FreeBSD_kernel__) + regs[REG_INDEX(GS)] = (uintptr_t) gregs.r_gs; + regs[REG_INDEX(FS)] = (uintptr_t) gregs.r_fs; + regs[REG_INDEX(ES)] = (uintptr_t) gregs.r_es; + regs[REG_INDEX(DS)] = (uintptr_t) gregs.r_ds; + regs[REG_INDEX(EDI)] = (uintptr_t) gregs.r_edi; + regs[REG_INDEX(ESI)] = (uintptr_t) gregs.r_esi; + regs[REG_INDEX(FP)] = (uintptr_t) gregs.r_ebp; + regs[REG_INDEX(SP)] = (uintptr_t) gregs.r_isp; + regs[REG_INDEX(EBX)] = (uintptr_t) gregs.r_ebx; + regs[REG_INDEX(EDX)] = (uintptr_t) gregs.r_edx; + regs[REG_INDEX(ECX)] = (uintptr_t) gregs.r_ecx; + regs[REG_INDEX(EAX)] = (uintptr_t) gregs.r_eax; + regs[REG_INDEX(PC)] = (uintptr_t) gregs.r_eip; + regs[REG_INDEX(CS)] = (uintptr_t) gregs.r_cs; + regs[REG_INDEX(SS)] = (uintptr_t) gregs.r_ss; +#endif #endif /* i386 */ #if ia64 @@ -344,7 +360,7 @@ JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLo #ifdef amd64 #define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg - +#ifdef __linux__ regs[REG_INDEX(R15)] = gregs.r15; regs[REG_INDEX(R14)] = gregs.r14; regs[REG_INDEX(R13)] = gregs.r13; @@ -370,7 +386,27 @@ JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLo regs[REG_INDEX(ES)] = gregs.es; regs[REG_INDEX(FS)] = gregs.fs; regs[REG_INDEX(GS)] = gregs.gs; - +#elif defined(__FreeBSD_kernel__) + regs[REG_INDEX(R15)] = gregs.r_r15; + regs[REG_INDEX(R14)] = gregs.r_r14; + regs[REG_INDEX(R13)] = gregs.r_r13; + regs[REG_INDEX(R12)] = gregs.r_r12; + regs[REG_INDEX(RBP)] = gregs.r_rbp; + regs[REG_INDEX(RBX)] = gregs.r_rbx; + regs[REG_INDEX(R11)] = gregs.r_r11; + regs[REG_INDEX(R10)] = gregs.r_r10; + regs[REG_INDEX(R9)] = gregs.r_r9; + regs[REG_INDEX(R8)] = gregs.r_r8; + regs[REG_INDEX(RAX)] = gregs.r_rax; + regs[REG_INDEX(RCX)] = gregs.r_rcx; + regs[REG_INDEX(RDX)] = gregs.r_rdx; + regs[REG_INDEX(RSI)] = gregs.r_rsi; + regs[REG_INDEX(RDI)] = gregs.r_rdi; + regs[REG_INDEX(RIP)] = gregs.r_rip; + regs[REG_INDEX(CS)] = gregs.r_cs; + regs[REG_INDEX(RSP)] = gregs.r_rsp; + regs[REG_INDEX(SS)] = gregs.r_ss; +#endif #endif /* amd64 */ #if defined(sparc) || defined(sparcv9) diff --git openjdk/hotspot/agent/src/os/linux/libproc.h openjdk/agent/src/os/linux/libproc.h index 7edaa9c..8c2511c 100644 --- openjdk/hotspot/agent/src/os/linux/libproc.h +++ openjdk/hotspot/agent/src/os/linux/libproc.h @@ -27,6 +27,10 @@ #include #include +#if defined(__FreeBSD_kernel__) +#include +#include +#endif #include "proc_service.h" #if defined(sparc) || defined(sparcv9) @@ -112,6 +116,10 @@ unsigned long regs[IA64_REG_COUNT]; /* integer and fp regs */ #define user_regs_struct pt_regs #endif +#if defined(__FreeBSD_kernel__) +#define user_regs_struct reg +#endif + // This C bool type must be int for compatibility with Linux calls and // it would be a mistake to equivalence it to C++ bool on many platforms diff --git openjdk/hotspot/agent/src/os/linux/ps_core.c openjdk/agent/src/os/linux/ps_core.c index 9739e16..abf4da6 100644 --- openjdk/hotspot/agent/src/os/linux/ps_core.c +++ openjdk/hotspot/agent/src/os/linux/ps_core.c @@ -539,11 +539,16 @@ static bool core_handle_prstatus(struct ps_prochandle* ph, const char* buf, size return false; // copy regs +#if defined(__FreeBSD_kernel__) + memcpy(&newthr->regs, &prstat->pr_reg, sizeof(struct user_regs_struct)); +#else memcpy(&newthr->regs, prstat->pr_reg, sizeof(struct user_regs_struct)); +#endif if (is_debug()) { print_debug("integer regset\n"); #ifdef i386 +#ifdef __linux__ // print the regset print_debug("\teax = 0x%x\n", newthr->regs.eax); print_debug("\tebx = 0x%x\n", newthr->regs.ebx); @@ -554,9 +559,21 @@ static bool core_handle_prstatus(struct ps_prochandle* ph, const char* buf, size print_debug("\tesi = 0x%x\n", newthr->regs.esi); print_debug("\tedi = 0x%x\n", newthr->regs.edi); print_debug("\teip = 0x%x\n", newthr->regs.eip); +#elif defined(__FreeBSD_kernel__) + print_debug("\teax = 0x%x\n", newthr->regs.r_eax); + print_debug("\tebx = 0x%x\n", newthr->regs.r_ebx); + print_debug("\tecx = 0x%x\n", newthr->regs.r_ecx); + print_debug("\tedx = 0x%x\n", newthr->regs.r_edx); + print_debug("\tesp = 0x%x\n", newthr->regs.r_esp); + print_debug("\tebp = 0x%x\n", newthr->regs.r_ebp); + print_debug("\tesi = 0x%x\n", newthr->regs.r_esi); + print_debug("\tedi = 0x%x\n", newthr->regs.r_edi); + print_debug("\teip = 0x%x\n", newthr->regs.r_eip); +#endif #endif #if defined(amd64) || defined(x86_64) +#ifdef __linux__ // print the regset print_debug("\tr15 = 0x%lx\n", newthr->regs.r15); print_debug("\tr14 = 0x%lx\n", newthr->regs.r14); @@ -585,6 +602,27 @@ static bool core_handle_prstatus(struct ps_prochandle* ph, const char* buf, size print_debug("\tes = 0x%lx\n", newthr->regs.es); print_debug("\tfs = 0x%lx\n", newthr->regs.fs); print_debug("\tgs = 0x%lx\n", newthr->regs.gs); +#elif defined(__FreeBSD_kernel__) + print_debug("\tr15 = 0x%lx\n", newthr->regs.r_r15); + print_debug("\tr14 = 0x%lx\n", newthr->regs.r_r14); + print_debug("\tr13 = 0x%lx\n", newthr->regs.r_r13); + print_debug("\tr12 = 0x%lx\n", newthr->regs.r_r12); + print_debug("\trbp = 0x%lx\n", newthr->regs.r_rbp); + print_debug("\trbx = 0x%lx\n", newthr->regs.r_rbx); + print_debug("\tr11 = 0x%lx\n", newthr->regs.r_r11); + print_debug("\tr10 = 0x%lx\n", newthr->regs.r_r10); + print_debug("\tr9 = 0x%lx\n", newthr->regs.r_r9); + print_debug("\tr8 = 0x%lx\n", newthr->regs.r_r8); + print_debug("\trax = 0x%lx\n", newthr->regs.r_rax); + print_debug("\trcx = 0x%lx\n", newthr->regs.r_rcx); + print_debug("\trdx = 0x%lx\n", newthr->regs.r_rdx); + print_debug("\trsi = 0x%lx\n", newthr->regs.r_rsi); + print_debug("\trdi = 0x%lx\n", newthr->regs.r_rdi); + print_debug("\trip = 0x%lx\n", newthr->regs.r_rip); + print_debug("\tcs = 0x%lx\n", newthr->regs.r_cs); + print_debug("\trsp = 0x%lx\n", newthr->regs.r_rsp); + print_debug("\tss = 0x%lx\n", newthr->regs.r_ss); +#endif #endif } diff --git openjdk/hotspot/agent/src/os/linux/ps_proc.c openjdk/agent/src/os/linux/ps_proc.c index 676e88a..e3c678a 100644 --- openjdk/hotspot/agent/src/os/linux/ps_proc.c +++ openjdk/hotspot/agent/src/os/linux/ps_proc.c @@ -37,6 +37,18 @@ #define __WALL 0x40000000 // Copied from /usr/include/linux/wait.h #endif +#ifndef PTRACE_PEEKDATA +#define PTRACE_PEEKDATA PT_READ_D +#endif + +#ifndef PTRACE_ATTACH +#define PTRACE_ATTACH PT_ATTACH +#endif + +#ifndef PTRACE_DETACH +#define PTRACE_DETACH PT_DETACH +#endif + // This file has the libproc implementation specific to live process // For core files, refer to ps_core.c @@ -54,7 +66,11 @@ static inline uintptr_t align(uintptr_t ptr, size_t size) { // before calling process_read_data. static bool process_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf, size_t size) { +#if defined(__FreeBSD_kernel__) + int rslt; +#else long rslt; +#endif size_t i, words; uintptr_t end_addr = addr + size; uintptr_t aligned_addr = align(addr, sizeof(long)); @@ -62,36 +78,62 @@ static bool process_read_data(struct ps_prochandle* ph, uintptr_t addr, char *bu if (aligned_addr != addr) { char *ptr = (char *)&rslt; errno = 0; +#if defined(__FreeBSD_kernel__) + rslt = ptrace(PTRACE_PEEKDATA, ph->pid, (caddr_t) aligned_addr, 0); +#else rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0); +#endif if (errno) { print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr); return false; } for (; aligned_addr != addr; aligned_addr++, ptr++); +#if defined(__FreeBSD_kernel__) + for (; ((intptr_t)aligned_addr % sizeof(int)) && aligned_addr < end_addr; +#else for (; ((intptr_t)aligned_addr % sizeof(long)) && aligned_addr < end_addr; +#endif aligned_addr++) *(buf++) = *(ptr++); } +#if defined(__FreeBSD_kernel__) + words = (end_addr - aligned_addr) / sizeof(int); +#else words = (end_addr - aligned_addr) / sizeof(long); +#endif // assert((intptr_t)aligned_addr % sizeof(long) == 0); for (i = 0; i < words; i++) { errno = 0; +#if defined(__FreeBSD_kernel__) + rslt = ptrace(PTRACE_PEEKDATA, ph->pid, (caddr_t) aligned_addr, 0); +#else rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0); +#endif if (errno) { print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr); return false; } +#if defined(__FreeBSD_kernel__) + *(int *)buf = rslt; + buf += sizeof(int); + aligned_addr += sizeof(int); +#else *(long *)buf = rslt; buf += sizeof(long); aligned_addr += sizeof(long); +#endif } if (aligned_addr != end_addr) { char *ptr = (char *)&rslt; errno = 0; +#if defined(__FreeBSD_kernel__) + rslt = ptrace(PTRACE_PEEKDATA, ph->pid, (caddr_t) aligned_addr, 0); +#else rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0); +#endif if (errno) { print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr); return false; @@ -130,7 +172,11 @@ static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct use #endif #ifdef PTRACE_GETREGS_REQ +#if defined(__FreeBSD_kernel__) + if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, (caddr_t) user, 0) < 0) { +#else if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, user, NULL) < 0) { +#endif print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp %d\n", pid); return false; } @@ -144,7 +190,11 @@ static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct use // attach to a process/thread specified by "pid" static bool ptrace_attach(pid_t pid) { +#if defined(__FreeBSD_kernel__) + if (ptrace(PTRACE_ATTACH, pid, NULL, 0) < 0) { +#else if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) { +#endif print_debug("ptrace(PTRACE_ATTACH, ..) failed for %d\n", pid); return false; } else { @@ -271,7 +321,11 @@ static bool read_lib_info(struct ps_prochandle* ph) { // detach a given pid static bool ptrace_detach(pid_t pid) { +#if defined(__FreeBSD_kernel__) + if (pid && ptrace(PTRACE_DETACH, pid, NULL, 0) < 0) { +#else if (pid && ptrace(PTRACE_DETACH, pid, NULL, NULL) < 0) { +#endif print_debug("ptrace(PTRACE_DETACH, ..) failed for %d\n", pid); return false; } else { diff --git openjdk/hotspot/make/defs.make openjdk/make/defs.make index a0aa0e5..efd8995 100644 --- openjdk/hotspot/make/defs.make +++ openjdk/hotspot/make/defs.make @@ -118,9 +118,6 @@ endif # Windows should have OS predefined ifeq ($(OS),) OS := $(shell uname -s) - ifneq ($(findstring BSD,$(OS)),) - OS=bsd - endif ifeq ($(OS), Darwin) OS=bsd endif @@ -142,6 +139,10 @@ else OSNAME=linux endif +ifeq ($(OS), GNU/kFreeBSD) + OSNAME=linux +endif + # Determinations of default make arguments and platform specific settings MAKE_ARGS= diff --git openjdk/hotspot/make/linux/Makefile openjdk/make/linux/Makefile index 0ae3f4c..572c3e9 100644 --- openjdk/hotspot/make/linux/Makefile +++ openjdk/hotspot/make/linux/Makefile @@ -234,6 +234,9 @@ checks: check_os_version check_j2se_version SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3% OS_VERSION := $(shell uname -r) EMPTY_IF_NOT_SUPPORTED = $(filter $(SUPPORTED_OS_VERSION),$(OS_VERSION)) +ifeq ($(shell uname -s), GNU/kFreeBSD) +EMPTY_IF_NOT_SUPPORTED = supported +endif check_os_version: ifeq ($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),) diff --git openjdk/hotspot/make/linux/makefiles/defs.make openjdk/make/linux/makefiles/defs.make index 70f502f..8bd7c4e 100644 --- openjdk/hotspot/make/linux/makefiles/defs.make +++ openjdk/hotspot/make/linux/makefiles/defs.make @@ -91,7 +91,7 @@ ifeq ($(ARCH), x86_64) endif # i686 -ifeq ($(ARCH), i686) +ifneq (,$(filter i686 i386, $(ARCH))) ARCH_DATA_MODEL = 32 PLATFORM = linux-i586 VM_PLATFORM = linux_i486 diff --git openjdk/hotspot/src/os/linux/vm/attachListener_linux.cpp openjdk/src/os/linux/vm/attachListener_linux.cpp index 5b9c729..e88faa3 100644 --- openjdk/hotspot/src/os/linux/vm/attachListener_linux.cpp +++ openjdk/hotspot/src/os/linux/vm/attachListener_linux.cpp @@ -39,6 +39,10 @@ #define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)0)->sun_path) #endif +#if defined(__FreeBSD_kernel__) +#include +#endif + // The attach mechanism on Linux uses a UNIX domain socket. An attach listener // thread is created at startup or is created on-demand via a signal from // the client tool. The attach listener creates a socket and binds it to a file @@ -337,9 +341,15 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() { // get the credentials of the peer and check the effective uid/guid // - check with jeff on this. +#if defined(LOCAL_PEERCRED) /* GNU/kFreeBSD */ + struct xucred cred_info; + socklen_t optlen = sizeof(cred_info); + if (::getsockopt(s, SOL_SOCKET, LOCAL_PEERCRED, (void*)&cred_info, &optlen) == -1) { +#else struct ucred cred_info; socklen_t optlen = sizeof(cred_info); if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) { +#endif int res; RESTARTABLE(::close(s), res); continue; @@ -347,10 +357,14 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() { uid_t euid = geteuid(); gid_t egid = getegid(); +#if defined(LOCAL_PEERCRED) /* GNU/kFreeBSD */ + if (cred_info.cr_uid != euid || cred_info.cr_gid != egid) { +#else if (cred_info.uid != euid || cred_info.gid != egid) { - int res; +#endif + int res; RESTARTABLE(::close(s), res); - continue; + continue; } // peer credential look okay so we read the request diff --git openjdk/hotspot/src/os/linux/vm/jvm_linux.cpp openjdk/src/os/linux/vm/jvm_linux.cpp index ba84788..8c4937a 100644 --- openjdk/hotspot/src/os/linux/vm/jvm_linux.cpp +++ openjdk/hotspot/src/os/linux/vm/jvm_linux.cpp @@ -169,7 +169,9 @@ struct siglabel siglabels[] = { "WINCH", SIGWINCH, /* Window size change (4.3 BSD, Sun). */ "POLL", SIGPOLL, /* Pollable event occurred (System V). */ "IO", SIGIO, /* I/O now possible (4.2 BSD). */ +#ifdef SIGPWR "PWR", SIGPWR, /* Power failure restart (System V). */ +#endif #ifdef SIGSYS "SYS", SIGSYS /* Bad system call. Only on some Linuxen! */ #endif diff --git openjdk/hotspot/src/os/linux/vm/os_linux.cpp openjdk/src/os/linux/vm/os_linux.cpp index 55f52c3..a82f627 100644 --- openjdk/hotspot/src/os/linux/vm/os_linux.cpp +++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp @@ -113,8 +113,16 @@ # include # include # include +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +# include +# include +#ifndef ETIME +# define ETIME ETIMEDOUT +#endif +#else # include # include +#endif # include # include # include @@ -205,11 +214,22 @@ julong os::available_memory() { } julong os::Linux::available_memory() { +#ifndef __FreeBSD_kernel__ // values in struct sysinfo are "unsigned long" struct sysinfo si; sysinfo(&si); return (julong)si.freeram * si.mem_unit; +#else + int mib[2] = {CTL_HW, HW_USERMEM}, mem; + size_t len; + len = sizeof(mem); + if (sysctl(mib, 2, &mem, &len, NULL, 0) == 0) { + return (julong) mem; + } else { + return 0; + } +#endif } julong os::physical_memory() { @@ -2128,18 +2148,22 @@ void os::print_memory_info(outputStream* st) { st->print("Memory:"); st->print(" %dk page", os::vm_page_size()>>10); +#ifndef __FreeBSD_kernel__ // values in struct sysinfo are "unsigned long" struct sysinfo si; sysinfo(&si); +#endif st->print(", physical " UINT64_FORMAT "k", os::physical_memory() >> 10); st->print("(" UINT64_FORMAT "k free)", os::available_memory() >> 10); +#ifndef __FreeBSD_kernel__ st->print(", swap " UINT64_FORMAT "k", ((jlong)si.totalswap * si.mem_unit) >> 10); st->print("(" UINT64_FORMAT "k free)", ((jlong)si.freeswap * si.mem_unit) >> 10); +#endif st->cr(); } @@ -5372,6 +5396,7 @@ extern char** environ; int os::fork_and_exec(char* cmd) { const char * argv[4] = {"sh", "-c", cmd, NULL}; +#ifdef __linux__ // fork() in LinuxThreads/NPTL is not async-safe. It needs to run // pthread_atfork handlers and reset pthread library. All we need is a // separate process to execve. Make a direct syscall to fork process. @@ -5379,6 +5404,9 @@ int os::fork_and_exec(char* cmd) { // the best... pid_t pid = NOT_IA64(syscall(__NR_fork);) IA64_ONLY(fork();) +#else + pid_t pid = fork(); +#endif if (pid < 0) { // fork failed @@ -5387,6 +5415,7 @@ int os::fork_and_exec(char* cmd) { } else if (pid == 0) { // child process +#ifdef __linux__ // execve() in LinuxThreads will call pthread_kill_other_threads_np() // first to kill every thread on the thread list. Because this list is // not reset by fork() (see notes above), execve() will instead kill @@ -5396,6 +5425,9 @@ int os::fork_and_exec(char* cmd) { // above. NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);) IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);) +#else + execve("/bin/sh", (char* const*)argv, environ); +#endif // execve failed _exit(-1); diff --git openjdk/hotspot/src/os/posix/launcher/java_md.c openjdk/src/os/posix/launcher/java_md.c index 8b1542e..69e0832 100644 --- openjdk/hotspot/src/os/posix/launcher/java_md.c +++ openjdk/hotspot/src/os/posix/launcher/java_md.c @@ -41,7 +41,7 @@ #include "version_comp.h" #endif -#if defined(__linux__) || defined(_ALLBSD_SOURCE) +#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(__GLIBC__) #include #else #include @@ -96,7 +96,7 @@ extern char **environ; * A collection of useful strings. One should think of these as #define * entries, but actual strings can be more efficient (with many compilers). */ -#ifdef __linux__ +#if defined(__linux__) || defined(__GLIBC__) static const char *system_dir = "/usr/java"; static const char *user_dir = "/java"; #else /* Solaris */ @@ -433,7 +433,7 @@ CreateExecutionEnvironment(int *_argcp, runpath = getenv(LD_LIBRARY_PATH); #endif /* __sun */ -#if defined(__linux__) +#if defined(__linux__) || defined(__GLIBC__) /* * On linux, if a binary is running as sgid or suid, glibc sets * LD_LIBRARY_PATH to the empty string for security purposes. (In @@ -823,7 +823,7 @@ error: jboolean GetApplicationHome(char *buf, jint bufsize) { -#if defined(__linux__) || defined(_ALLBSD_SOURCE) +#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(__GLIBC__) char *execname = GetExecname(); if (execname) { strncpy(buf, execname, bufsize-1); @@ -992,7 +992,7 @@ SetExecname(char **argv) } } } -#elif defined(__linux__) +#elif defined(__linux__) || defined(__GLIBC__) { const char* self = "/proc/self/exe"; char buf[PATH_MAX+1]; @@ -1887,7 +1887,7 @@ jlong_format_specifier() { int ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { int rslt; -#if defined(__linux__) || defined(_ALLBSD_SOURCE) +#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(__GLIBC__) pthread_t tid; pthread_attr_t attr; pthread_attr_init(&attr); diff --git openjdk/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp openjdk/src/os_cpu/linux_x86/vm/os_linux_x86.cpp index ba484b9..d1e7b6f 100644 --- openjdk/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp +++ openjdk/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp @@ -81,6 +81,7 @@ # include # include +#ifdef __linux__ #ifdef AMD64 #define REG_SP REG_RSP #define REG_PC REG_RIP @@ -94,6 +95,54 @@ #define SPELL_REG_SP "esp" #define SPELL_REG_FP "ebp" #endif // AMD64 +#endif + +#if defined(__FreeBSD_kernel__) +#define context_trapno uc_mcontext.mc_trapno +#ifdef AMD64 +#define SPELL_REG_SP "rsp" +#define SPELL_REG_FP "rbp" +#define context_sp uc_mcontext.mc_rsp +#define context_pc uc_mcontext.mc_rip +#define context_fp uc_mcontext.mc_rbp +#define context_rip uc_mcontext.mc_rip +#define context_rsp uc_mcontext.mc_rsp +#define context_rbp uc_mcontext.mc_rbp +#define context_flags uc_mcontext.mc_flags +#define context_err uc_mcontext.mc_err +#define context_rax uc_mcontext.mc_rax +#define context_rbx uc_mcontext.mc_rbx +#define context_rcx uc_mcontext.mc_rcx +#define context_rdx uc_mcontext.mc_rdx +#define context_rsi uc_mcontext.mc_rsi +#define context_rdi uc_mcontext.mc_rdi +#define context_r8 uc_mcontext.mc_r8 +#define context_r9 uc_mcontext.mc_r9 +#define context_r10 uc_mcontext.mc_r10 +#define context_r11 uc_mcontext.mc_r11 +#define context_r12 uc_mcontext.mc_r12 +#define context_r13 uc_mcontext.mc_r13 +#define context_r14 uc_mcontext.mc_r14 +#define context_r15 uc_mcontext.mc_r15 +#else +#define SPELL_REG_SP "esp" +#define SPELL_REG_FP "ebp" +#define context_sp uc_mcontext.mc_esp +#define context_pc uc_mcontext.mc_eip +#define context_fp uc_mcontext.mc_ebp +#define context_eip uc_mcontext.mc_eip +#define context_esp uc_mcontext.mc_esp +#define context_eax uc_mcontext.mc_eax +#define context_ebx uc_mcontext.mc_ebx +#define context_ecx uc_mcontext.mc_ecx +#define context_edx uc_mcontext.mc_edx +#define context_ebp uc_mcontext.mc_ebp +#define context_esi uc_mcontext.mc_esi +#define context_edi uc_mcontext.mc_edi +#define context_eflags uc_mcontext.mc_eflags +#define context_trapno uc_mcontext.mc_trapno +#endif // AMD64 +#endif address os::current_stack_pointer() { #ifdef SPARC_WORKS @@ -119,15 +168,27 @@ void os::initialize_thread() { } address os::Linux::ucontext_get_pc(ucontext_t * uc) { +#if defined(__FreeBSD_kernel__) + return (address)uc->context_pc; +#else return (address)uc->uc_mcontext.gregs[REG_PC]; +#endif } intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) { +#if defined(__FreeBSD_kernel__) + return (intptr_t*)uc->context_sp; +#else return (intptr_t*)uc->uc_mcontext.gregs[REG_SP]; +#endif } intptr_t* os::Linux::ucontext_get_fp(ucontext_t * uc) { +#if defined(__FreeBSD_kernel__) + return (intptr_t*)uc->context_fp; +#else return (intptr_t*)uc->uc_mcontext.gregs[REG_FP]; +#endif } // For Forte Analyzer AsyncGetCallTrace profiling support - thread @@ -279,12 +340,20 @@ JVM_handle_linux_signal(int sig, pc = (address) os::Linux::ucontext_get_pc(uc); if (pc == (address) Fetch32PFI) { +#if defined(__FreeBSD_kernel__) + uc->context_pc = intptr_t(Fetch32Resume) ; +#else uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ; +#endif return 1 ; } #ifdef AMD64 if (pc == (address) FetchNPFI) { +#if defined(__FreeBSD_kernel__) + uc->context_pc = intptr_t (FetchNResume) ; +#else uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ; +#endif return 1 ; } #endif // AMD64 @@ -430,7 +499,11 @@ JVM_handle_linux_signal(int sig, // Furthermore, a false-positive should be harmless. if (UnguardOnExecutionViolation > 0 && (sig == SIGSEGV || sig == SIGBUS) && +#if defined(__FreeBSD_kernel__) + uc->context_trapno == trap_page_fault) { +#else uc->uc_mcontext.gregs[REG_TRAPNO] == trap_page_fault) { +#endif int page_size = os::vm_page_size(); address addr = (address) info->si_addr; address pc = os::Linux::ucontext_get_pc(uc); @@ -500,7 +573,11 @@ JVM_handle_linux_signal(int sig, // save all thread context in case we need to restore it if (thread != NULL) thread->set_saved_exception_pc(pc); +#if defined(__FreeBSD_kernel__) + uc->context_pc = (intptr_t)stub; +#else uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub; +#endif return true; } @@ -752,6 +829,7 @@ void os::print_context(outputStream *st, void *context) { ucontext_t *uc = (ucontext_t*)context; st->print_cr("Registers:"); +#ifdef __linux__ #ifdef AMD64 st->print( "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]); st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]); @@ -794,6 +872,48 @@ void os::print_context(outputStream *st, void *context) { st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]); st->print(", CR2=" INTPTR_FORMAT, uc->uc_mcontext.cr2); #endif // AMD64 +#elif defined(__FreeBSD_kernel__) +#ifdef AMD64 + st->print( "RAX=" INTPTR_FORMAT, uc->context_rax); + st->print(", RBX=" INTPTR_FORMAT, uc->context_rbx); + st->print(", RCX=" INTPTR_FORMAT, uc->context_rcx); + st->print(", RDX=" INTPTR_FORMAT, uc->context_rdx); + st->cr(); + st->print( "RSP=" INTPTR_FORMAT, uc->context_rsp); + st->print(", RBP=" INTPTR_FORMAT, uc->context_rbp); + st->print(", RSI=" INTPTR_FORMAT, uc->context_rsi); + st->print(", RDI=" INTPTR_FORMAT, uc->context_rdi); + st->cr(); + st->print( "R8 =" INTPTR_FORMAT, uc->context_r8); + st->print(", R9 =" INTPTR_FORMAT, uc->context_r9); + st->print(", R10=" INTPTR_FORMAT, uc->context_r10); + st->print(", R11=" INTPTR_FORMAT, uc->context_r11); + st->cr(); + st->print( "R12=" INTPTR_FORMAT, uc->context_r12); + st->print(", R13=" INTPTR_FORMAT, uc->context_r13); + st->print(", R14=" INTPTR_FORMAT, uc->context_r14); + st->print(", R15=" INTPTR_FORMAT, uc->context_r15); + st->cr(); + st->print( "RIP=" INTPTR_FORMAT, uc->context_rip); + st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_flags); + st->print(", ERR=" INTPTR_FORMAT, uc->context_err); + st->cr(); + st->print(" TRAPNO=" INTPTR_FORMAT, uc->context_trapno); +#else + st->print( "EAX=" INTPTR_FORMAT, uc->context_eax); + st->print(", EBX=" INTPTR_FORMAT, uc->context_ebx); + st->print(", ECX=" INTPTR_FORMAT, uc->context_ecx); + st->print(", EDX=" INTPTR_FORMAT, uc->context_edx); + st->cr(); + st->print( "ESP=" INTPTR_FORMAT, uc->context_esp); + st->print(", EBP=" INTPTR_FORMAT, uc->context_ebp); + st->print(", ESI=" INTPTR_FORMAT, uc->context_esi); + st->print(", EDI=" INTPTR_FORMAT, uc->context_edi); + st->cr(); + st->print( "EIP=" INTPTR_FORMAT, uc->context_eip); + st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_eflags); +#endif // AMD64 +#endif st->cr(); st->cr(); @@ -824,6 +944,7 @@ void os::print_register_info(outputStream *st, void *context) { // this is only for the "general purpose" registers +#ifdef __linux__ #ifdef AMD64 st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]); st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]); @@ -851,6 +972,35 @@ void os::print_register_info(outputStream *st, void *context) { st->print("ESI="); print_location(st, uc->uc_mcontext.gregs[REG_ESI]); st->print("EDI="); print_location(st, uc->uc_mcontext.gregs[REG_EDI]); #endif // AMD64 +#elif defined(__FreeBSD_kernel__) +#ifdef AMD64 + st->print("RAX="); print_location(st, uc->context_rax); + st->print("RBX="); print_location(st, uc->context_rbx); + st->print("RCX="); print_location(st, uc->context_rcx); + st->print("RDX="); print_location(st, uc->context_rdx); + st->print("RSP="); print_location(st, uc->context_rsp); + st->print("RBP="); print_location(st, uc->context_rbp); + st->print("RSI="); print_location(st, uc->context_rsi); + st->print("RDI="); print_location(st, uc->context_rdi); + st->print("R8 ="); print_location(st, uc->context_r8); + st->print("R9 ="); print_location(st, uc->context_r9); + st->print("R10="); print_location(st, uc->context_r10); + st->print("R11="); print_location(st, uc->context_r11); + st->print("R12="); print_location(st, uc->context_r12); + st->print("R13="); print_location(st, uc->context_r13); + st->print("R14="); print_location(st, uc->context_r14); + st->print("R15="); print_location(st, uc->context_r15); +#else + st->print("EAX="); print_location(st, uc->context_eax); + st->print("EBX="); print_location(st, uc->context_ebx); + st->print("ECX="); print_location(st, uc->context_ecx); + st->print("EDX="); print_location(st, uc->context_edx); + st->print("ESP="); print_location(st, uc->context_esp); + st->print("EBP="); print_location(st, uc->context_ebp); + st->print("ESI="); print_location(st, uc->context_esi); + st->print("EDI="); print_location(st, uc->context_edi); +#endif // AMD64 +#endif st->cr(); } diff --git openjdk/hotspot/src/share/vm/memory/allocation.hpp openjdk/src/share/vm/memory/allocation.hpp index 4c2f1e8..d2cbfe1 100644 --- openjdk/hotspot/src/share/vm/memory/allocation.hpp +++ openjdk/hotspot/src/share/vm/memory/allocation.hpp @@ -218,9 +218,9 @@ protected: void signal_out_of_memory(size_t request, const char* whence) const; void check_for_overflow(size_t request, const char* whence) const { - if (UINTPTR_MAX - request < (uintptr_t)_hwm) { - signal_out_of_memory(request, whence); - } +// if (UINTPTR_MAX - request < (uintptr_t)_hwm) { +// signal_out_of_memory(request, whence); +// } } public: diff --git openjdk/hotspot/src/share/vm/oops/generateOopMap.cpp openjdk/src/share/vm/oops/generateOopMap.cpp index 58ef931..9448389 100644 --- openjdk/hotspot/src/share/vm/oops/generateOopMap.cpp +++ openjdk/hotspot/src/share/vm/oops/generateOopMap.cpp @@ -970,11 +970,11 @@ void GenerateOopMap::init_basic_blocks() { // The product of bbNo and _state_len can get large if there are lots of // basic blocks and stack/locals/monitors. Need to check to make sure // we don't overflow the capacity of a pointer. - if ((unsigned)bbNo > UINTPTR_MAX / sizeof(CellTypeState) / _state_len) { - report_error("The amount of memory required to analyze this method " - "exceeds addressable range"); - return; - } +// if ((unsigned)bbNo > UINTPTR_MAX / sizeof(CellTypeState) / _state_len) { +// report_error("The amount of memory required to analyze this method " +// "exceeds addressable range"); +// return; +// } CellTypeState *basicBlockState = NEW_RESOURCE_ARRAY(CellTypeState, bbNo * _state_len); --- openjdk/hotspot/src/share/vm/ci/ciObject.hpp.orig 2013-05-12 18:20:12.688303624 +0200 +++ openjdk/hotspot/src/share/vm/ci/ciObject.hpp 2013-05-12 18:20:18.500302224 +0200 @@ -25,6 +25,7 @@ #ifndef SHARE_VM_CI_CIOBJECT_HPP #define SHARE_VM_CI_CIOBJECT_HPP +#include "utilities/globalDefinitions.hpp" #include "ci/ciClassList.hpp" #include "memory/allocation.hpp" #include "runtime/handles.hpp" --- openjdk/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp.orig 2013-05-12 23:38:04.815301011 +0200 +++ openjdk/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp 2013-05-12 23:38:13.159314491 +0200 @@ -22,6 +22,7 @@ * */ +#include "utilities/globalDefinitions.hpp" // no precompiled headers #include "classfile/vmSymbols.hpp" #include "gc_interface/collectedHeap.hpp" --- openjdk/hotspot/src/os/linux/vm/os_linux.cpp.orig 2013-05-13 08:26:02.233299403 +0200 +++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp 2013-05-13 08:26:11.662320533 +0200 @@ -22,6 +22,7 @@ * */ +#include "utilities/globalDefinitions.hpp" // no precompiled headers #include "classfile/classLoader.hpp" #include "classfile/systemDictionary.hpp" --- openjdk/hotspot/src/os/linux/vm/osThread_linux.cpp.orig 2013-05-13 10:14:54.977305814 +0200 +++ openjdk/hotspot/src/os/linux/vm/osThread_linux.cpp 2013-05-13 10:15:12.863586024 +0200 @@ -22,6 +22,7 @@ * */ +#include "utilities/globalDefinitions.hpp" // no precompiled headers #include "runtime/atomic.hpp" #include "runtime/handles.inline.hpp" --- openjdk/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp.orig 2013-05-13 11:34:51.322318085 +0200 +++ openjdk/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp 2013-05-13 11:35:02.410309395 +0200 @@ -22,6 +22,7 @@ * */ +#include "utilities/globalDefinitions.hpp" // no precompiled headers #include "assembler_x86.inline.hpp" #include "classfile/classLoader.hpp" --- openjdk/jdk/src/solaris/bin/java_md_solinux.h.orig 2013-05-13 12:53:02.145315788 +0200 +++ openjdk/jdk/src/solaris/bin/java_md_solinux.h 2013-05-13 12:53:29.657604967 +0200 @@ -45,7 +45,7 @@ * A collection of useful strings. One should think of these as #define * entries, but actual strings can be more efficient (with many compilers). */ -#ifdef __linux__ +#if defined(__linux__) || defined(__GLIBC__) static const char *system_dir = "/usr/java"; static const char *user_dir = "/java"; #else /* Solaris */ @@ -54,7 +54,7 @@ #endif #include -#ifdef __linux__ +#if defined(__linux__) || defined(__GLIBC__) #include #else #include --- openjdk/jdk/src/solaris/bin/java_md_solinux.c.orig 2013-05-13 17:14:31.953312685 +0200 +++ openjdk/jdk/src/solaris/bin/java_md_solinux.c 2013-05-13 17:18:01.426302853 +0200 @@ -298,7 +298,7 @@ if (llp == NULL && dmllp == NULL) { return JNI_FALSE; } -#ifdef __linux +#if defined(__linux) || defined(__GLIBC__) /* * On linux, if a binary is running as sgid or suid, glibc sets * LD_LIBRARY_PATH to the empty string for security purposes. (In contrast, @@ -928,7 +928,7 @@ } } } -#elif defined(__linux__) +#elif defined(__linux__) || defined(__FreeBSD_kernel__) { const char* self = "/proc/self/exe"; char buf[PATH_MAX+1]; @@ -982,7 +982,7 @@ int ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { int rslt; -#ifdef __linux__ +#if defined(__linux__) || defined(__GLIBC__) pthread_t tid; pthread_attr_t attr; pthread_attr_init(&attr); @@ -1027,7 +1027,7 @@ void SetJavaLauncherPlatformProps() { /* Linux only */ -#ifdef __linux__ +#if defined(__linux__) || defined(__GLIBC__) const char *substr = "-Dsun.java.launcher.pid="; char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1); sprintf(pid_prop_str, "%s%d", substr, getpid());