src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 7089790_bsd_vs_linux Cdiff src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp

src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp

Print this page
rev 2698 : new bsd files

*** 21,43 **** * or visit www.oracle.com if you need additional information or have any * questions. * */ // no precompiled headers #include "assembler_zero.inline.hpp" #include "classfile/classLoader.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" #include "code/icBuffer.hpp" #include "code/vtableStubs.hpp" #include "interpreter/interpreter.hpp" ! #include "jvm_linux.h" #include "memory/allocation.inline.hpp" ! #include "mutex_linux.inline.hpp" #include "nativeInst_zero.hpp" ! #include "os_share_linux.hpp" #include "prims/jniFastGetField.hpp" #include "prims/jvm.h" #include "prims/jvm_misc.hpp" #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" --- 21,47 ---- * or visit www.oracle.com if you need additional information or have any * questions. * */ + #if defined(_ALLBSD_SOURCE) && !defined(__APPLE__) && !defined(__NetBSD__) + # include <pthread_np.h> /* For pthread_attr_get_np */ + #endif + // no precompiled headers #include "assembler_zero.inline.hpp" #include "classfile/classLoader.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" #include "code/icBuffer.hpp" #include "code/vtableStubs.hpp" #include "interpreter/interpreter.hpp" ! #include "jvm_bsd.h" #include "memory/allocation.inline.hpp" ! #include "mutex_bsd.inline.hpp" #include "nativeInst_zero.hpp" ! #include "os_share_bsd.hpp" #include "prims/jniFastGetField.hpp" #include "prims/jvm.h" #include "prims/jvm_misc.hpp" #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp"
*** 48,58 **** #include "runtime/mutexLocker.hpp" #include "runtime/osThread.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "runtime/timer.hpp" ! #include "thread_linux.inline.hpp" #include "utilities/events.hpp" #include "utilities/vmError.hpp" #ifdef COMPILER1 #include "c1/c1_Runtime1.hpp" #endif --- 52,62 ---- #include "runtime/mutexLocker.hpp" #include "runtime/osThread.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "runtime/timer.hpp" ! #include "thread_bsd.inline.hpp" #include "utilities/events.hpp" #include "utilities/vmError.hpp" #ifdef COMPILER1 #include "c1/c1_Runtime1.hpp" #endif
*** 100,110 **** void os::initialize_thread() { // Nothing to do. } ! address os::Linux::ucontext_get_pc(ucontext_t* uc) { ShouldNotCallThis(); } ExtendedPC os::fetch_frame_from_context(void* ucVoid, intptr_t** ret_sp, --- 104,114 ---- void os::initialize_thread() { // Nothing to do. } ! address os::Bsd::ucontext_get_pc(ucontext_t* uc) { ShouldNotCallThis(); } ExtendedPC os::fetch_frame_from_context(void* ucVoid, intptr_t** ret_sp,
*** 115,125 **** frame os::fetch_frame_from_context(void* ucVoid) { ShouldNotCallThis(); } extern "C" JNIEXPORT int ! JVM_handle_linux_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { ucontext_t* uc = (ucontext_t*) ucVoid; --- 119,129 ---- frame os::fetch_frame_from_context(void* ucVoid) { ShouldNotCallThis(); } extern "C" JNIEXPORT int ! JVM_handle_bsd_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { ucontext_t* uc = (ucontext_t*) ucVoid;
*** 128,145 **** SignalHandlerMark shm(t); // Note: it's not uncommon that JNI code uses signal/sigset to // install then restore certain signal handler (e.g. to temporarily // block SIGPIPE, or have a SIGILL handler when detecting CPU ! // type). When that happens, JVM_handle_linux_signal() might be // invoked with junk info/ucVoid. To avoid unnecessary crash when // libjsig is not preloaded, try handle signals that do not require // siginfo/ucontext first. if (sig == SIGPIPE || sig == SIGXFSZ) { // allow chained handler to go first ! if (os::Linux::chained_handler(sig, info, ucVoid)) { return true; } else { if (PrintMiscellaneous && (WizardMode || Verbose)) { char buf[64]; warning("Ignoring %s - see bugs 4229104 or 646499219", --- 132,149 ---- SignalHandlerMark shm(t); // Note: it's not uncommon that JNI code uses signal/sigset to // install then restore certain signal handler (e.g. to temporarily // block SIGPIPE, or have a SIGILL handler when detecting CPU ! // type). When that happens, JVM_handle_bsd_signal() might be // invoked with junk info/ucVoid. To avoid unnecessary crash when // libjsig is not preloaded, try handle signals that do not require // siginfo/ucontext first. if (sig == SIGPIPE || sig == SIGXFSZ) { // allow chained handler to go first ! if (os::Bsd::chained_handler(sig, info, ucVoid)) { return true; } else { if (PrintMiscellaneous && (WizardMode || Verbose)) { char buf[64]; warning("Ignoring %s - see bugs 4229104 or 646499219",
*** 149,159 **** } } JavaThread* thread = NULL; VMThread* vmthread = NULL; ! if (os::Linux::signal_handlers_are_installed) { if (t != NULL ){ if(t->is_Java_thread()) { thread = (JavaThread*)t; } else if(t->is_VM_thread()){ --- 153,163 ---- } } JavaThread* thread = NULL; VMThread* vmthread = NULL; ! if (os::Bsd::signal_handlers_are_installed) { if (t != NULL ){ if(t->is_Java_thread()) { thread = (JavaThread*)t; } else if(t->is_VM_thread()){
*** 177,204 **** } else if (thread->in_stack_red_zone(addr)) { thread->disable_stack_red_zone(); ShouldNotCallThis(); } else { // Accessing stack address below sp may cause SEGV if // current thread has MAP_GROWSDOWN stack. This should // only happen when current thread was created by user // code with MAP_GROWSDOWN flag and then attached to VM. ! // See notes in os_linux.cpp. if (thread->osthread()->expanding_stack() == 0) { thread->osthread()->set_expanding_stack(); ! if (os::Linux::manually_expand_stack(thread, addr)) { thread->osthread()->clear_expanding_stack(); return true; } thread->osthread()->clear_expanding_stack(); } else { fatal("recursive segv. expanding stack."); } } } } /*if (thread->thread_state() == _thread_in_Java) { ShouldNotCallThis(); --- 181,210 ---- } else if (thread->in_stack_red_zone(addr)) { thread->disable_stack_red_zone(); ShouldNotCallThis(); } + #ifndef _ALLBSD_SOURCE else { // Accessing stack address below sp may cause SEGV if // current thread has MAP_GROWSDOWN stack. This should // only happen when current thread was created by user // code with MAP_GROWSDOWN flag and then attached to VM. ! // See notes in os_bsd.cpp. if (thread->osthread()->expanding_stack() == 0) { thread->osthread()->set_expanding_stack(); ! if (os::Bsd::manually_expand_stack(thread, addr)) { thread->osthread()->clear_expanding_stack(); return true; } thread->osthread()->clear_expanding_stack(); } else { fatal("recursive segv. expanding stack."); } } + #endif } } /*if (thread->thread_state() == _thread_in_Java) { ShouldNotCallThis();
*** 228,238 **** return true; } } // signal-chaining ! if (os::Linux::chained_handler(sig, info, ucVoid)) { return true; } if (!abort_if_unrecognized) { // caller wants another chance, so give it to him --- 234,244 ---- return true; } } // signal-chaining ! if (os::Bsd::chained_handler(sig, info, ucVoid)) { return true; } if (!abort_if_unrecognized) { // caller wants another chance, so give it to him
*** 258,278 **** sprintf(buf, fmt, sig); fatal(buf); } ! void os::Linux::init_thread_fpu_state(void) { // Nothing to do } ! int os::Linux::get_fpu_control_word() { ShouldNotCallThis(); } ! void os::Linux::set_fpu_control_word(int fpu) { ShouldNotCallThis(); } bool os::is_allocatable(size_t bytes) { #ifdef _LP64 return true; #else --- 264,286 ---- sprintf(buf, fmt, sig); fatal(buf); } ! void os::Bsd::init_thread_fpu_state(void) { // Nothing to do } ! #ifndef _ALLBSD_SOURCE ! int os::Bsd::get_fpu_control_word() { ShouldNotCallThis(); } ! void os::Bsd::set_fpu_control_word(int fpu) { ShouldNotCallThis(); } + #endif bool os::is_allocatable(size_t bytes) { #ifdef _LP64 return true; #else
*** 291,323 **** } /////////////////////////////////////////////////////////////////////////////// // thread stack ! size_t os::Linux::min_stack_allowed = 64 * K; ! bool os::Linux::supports_variable_stack_size() { return true; } ! size_t os::Linux::default_stack_size(os::ThreadType thr_type) { #ifdef _LP64 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); #else size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K); #endif // _LP64 return s; } ! size_t os::Linux::default_guard_size(os::ThreadType thr_type) { // Only enable glibc guard pages for non-Java threads // (Java threads have HotSpot guard pages) return (thr_type == java_thread ? 0 : page_size()); } static void current_stack_region(address *bottom, size_t *size) { pthread_attr_t attr; int res = pthread_getattr_np(pthread_self(), &attr); if (res != 0) { if (res == ENOMEM) { vm_exit_out_of_memory(0, "pthread_getattr_np"); } --- 299,373 ---- } /////////////////////////////////////////////////////////////////////////////// // thread stack ! size_t os::Bsd::min_stack_allowed = 64 * K; ! bool os::Bsd::supports_variable_stack_size() { return true; } ! size_t os::Bsd::default_stack_size(os::ThreadType thr_type) { #ifdef _LP64 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); #else size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K); #endif // _LP64 return s; } ! size_t os::Bsd::default_guard_size(os::ThreadType thr_type) { // Only enable glibc guard pages for non-Java threads // (Java threads have HotSpot guard pages) return (thr_type == java_thread ? 0 : page_size()); } static void current_stack_region(address *bottom, size_t *size) { + address stack_bottom; + address stack_top; + size_t stack_bytes; + + #ifdef __APPLE__ + pthread_t self = pthread_self(); + stack_top = (address) pthread_get_stackaddr_np(self); + stack_bytes = pthread_get_stacksize_np(self); + stack_bottom = stack_top - stack_bytes; + #elif defined(__OpenBSD__) + stack_t ss; + int rslt = pthread_stackseg_np(pthread_self(), &ss); + + if (rslt != 0) + fatal(err_msg("pthread_stackseg_np failed with err = %d", rslt)); + + stack_top = (address) ss.ss_sp; + stack_bytes = ss.ss_size; + stack_bottom = stacktop - stack_bytes; + #elif defined(_ALLBSD_SOURCE) pthread_attr_t attr; + + int rslt = pthread_attr_init(&attr); + + // JVM needs to know exact stack location, abort if it fails + if (rslt != 0) + fatal(err_msg("pthread_attr_init failed with err = %d", rslt)); + + rslt = pthread_attr_get_np(pthread_self(), &attr); + + if (rslt != 0) + fatal(err_msg("pthread_attr_get_np failed with err = %d", rslt)); + + if (pthread_attr_getstackaddr(&attr, (void **) &stack_bottom) != 0 || + pthread_attr_getstacksize(&attr, &stack_bytes) != 0) { + fatal("Can not locate current stack attributes!"); + } + + pthread_attr_destroy(&attr); + + stack_top = stack_bottom + stack_bytes; + #else /* Linux */ + pthread_attr_t attr; int res = pthread_getattr_np(pthread_self(), &attr); if (res != 0) { if (res == ENOMEM) { vm_exit_out_of_memory(0, "pthread_getattr_np"); }
*** 324,344 **** else { fatal(err_msg("pthread_getattr_np failed with errno = %d", res)); } } - address stack_bottom; - size_t stack_bytes; res = pthread_attr_getstack(&attr, (void **) &stack_bottom, &stack_bytes); if (res != 0) { fatal(err_msg("pthread_attr_getstack failed with errno = %d", res)); } ! address stack_top = stack_bottom + stack_bytes; // The block of memory returned by pthread_attr_getstack() includes // guard pages where present. We need to trim these off. ! size_t page_bytes = os::Linux::page_size(); assert(((intptr_t) stack_bottom & (page_bytes - 1)) == 0, "unaligned stack"); size_t guard_bytes; res = pthread_attr_getguardsize(&attr, &guard_bytes); if (res != 0) { --- 374,392 ---- else { fatal(err_msg("pthread_getattr_np failed with errno = %d", res)); } } res = pthread_attr_getstack(&attr, (void **) &stack_bottom, &stack_bytes); if (res != 0) { fatal(err_msg("pthread_attr_getstack failed with errno = %d", res)); } ! stack_top = stack_bottom + stack_bytes; // The block of memory returned by pthread_attr_getstack() includes // guard pages where present. We need to trim these off. ! size_t page_bytes = os::Bsd::page_size(); assert(((intptr_t) stack_bottom & (page_bytes - 1)) == 0, "unaligned stack"); size_t guard_bytes; res = pthread_attr_getguardsize(&attr, &guard_bytes); if (res != 0) {
*** 364,381 **** pthread_attr_destroy(&attr); // The initial thread has a growable stack, and the size reported // by pthread_attr_getstack is the maximum size it could possibly // be given what currently mapped. This can be huge, so we cap it. ! if (os::Linux::is_initial_thread()) { stack_bytes = stack_top - stack_bottom; if (stack_bytes > JavaThread::stack_size_at_create()) stack_bytes = JavaThread::stack_size_at_create(); stack_bottom = stack_top - stack_bytes; } assert(os::current_stack_pointer() >= stack_bottom, "should do"); assert(os::current_stack_pointer() < stack_top, "should do"); *bottom = stack_bottom; --- 412,430 ---- pthread_attr_destroy(&attr); // The initial thread has a growable stack, and the size reported // by pthread_attr_getstack is the maximum size it could possibly // be given what currently mapped. This can be huge, so we cap it. ! if (os::Bsd::is_initial_thread()) { stack_bytes = stack_top - stack_bottom; if (stack_bytes > JavaThread::stack_size_at_create()) stack_bytes = JavaThread::stack_size_at_create(); stack_bottom = stack_top - stack_bytes; } + #endif assert(os::current_stack_pointer() >= stack_bottom, "should do"); assert(os::current_stack_pointer() < stack_top, "should do"); *bottom = stack_bottom;
*** 407,417 **** void os::print_register_info(outputStream *st, void *context) { ShouldNotCallThis(); } ///////////////////////////////////////////////////////////////////////////// ! // Stubs for things that would be in linux_zero.s if it existed. // You probably want to disassemble these monkeys to check they're ok. extern "C" { int SpinPause() { } --- 456,466 ---- void os::print_register_info(outputStream *st, void *context) { ShouldNotCallThis(); } ///////////////////////////////////////////////////////////////////////////// ! // Stubs for things that would be in bsd_zero.s if it existed. // You probably want to disassemble these monkeys to check they're ok. extern "C" { int SpinPause() { }
src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File