comparison src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp @ 6918:0af5da0c9d9d

8001619: Remove usage of _ALLBSD_SOURCE in bsd files Reviewed-by: coleenp, dholmes
author sla
date Mon, 29 Oct 2012 21:04:17 +0100
parents bf2edd3c9b0f
children f34d701e952e cd3d6a6b95d9
comparison
equal deleted inserted replaced
6917:e81fbc04a942 6918:0af5da0c9d9d
74 # include <poll.h> 74 # include <poll.h>
75 #ifndef __OpenBSD__ 75 #ifndef __OpenBSD__
76 # include <ucontext.h> 76 # include <ucontext.h>
77 #endif 77 #endif
78 78
79 #if defined(_ALLBSD_SOURCE) && !defined(__APPLE__) && !defined(__NetBSD__) 79 #if !defined(__APPLE__) && !defined(__NetBSD__)
80 # include <pthread_np.h> 80 # include <pthread_np.h>
81 #endif 81 #endif
82 82
83 #ifdef AMD64 83 #ifdef AMD64
84 #define SPELL_REG_SP "rsp" 84 #define SPELL_REG_SP "rsp"
487 } else if (thread->in_stack_red_zone(addr)) { 487 } else if (thread->in_stack_red_zone(addr)) {
488 // Fatal red zone violation. Disable the guard pages and fall through 488 // Fatal red zone violation. Disable the guard pages and fall through
489 // to handle_unexpected_exception way down below. 489 // to handle_unexpected_exception way down below.
490 thread->disable_stack_red_zone(); 490 thread->disable_stack_red_zone();
491 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 491 tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
492 #ifndef _ALLBSD_SOURCE
493 } else {
494 // Accessing stack address below sp may cause SEGV if current
495 // thread has MAP_GROWSDOWN stack. This should only happen when
496 // current thread was created by user code with MAP_GROWSDOWN flag
497 // and then attached to VM. See notes in os_bsd.cpp.
498 if (thread->osthread()->expanding_stack() == 0) {
499 thread->osthread()->set_expanding_stack();
500 if (os::Bsd::manually_expand_stack(thread, addr)) {
501 thread->osthread()->clear_expanding_stack();
502 return 1;
503 }
504 thread->osthread()->clear_expanding_stack();
505 } else {
506 fatal("recursive segv. expanding stack.");
507 }
508 #endif
509 } 492 }
510 } 493 }
511 } 494 }
512 495
513 // We test if stub is already set (by the stack overflow code 496 // We test if stub is already set (by the stack overflow code
742 err.report_and_die(); 725 err.report_and_die();
743 726
744 ShouldNotReachHere(); 727 ShouldNotReachHere();
745 } 728 }
746 729
747 #ifdef _ALLBSD_SOURCE
748 // From solaris_i486.s ported to bsd_i486.s 730 // From solaris_i486.s ported to bsd_i486.s
749 extern "C" void fixcw(); 731 extern "C" void fixcw();
750 #endif
751 732
752 void os::Bsd::init_thread_fpu_state(void) { 733 void os::Bsd::init_thread_fpu_state(void) {
753 #ifndef AMD64 734 #ifndef AMD64
754 # ifdef _ALLBSD_SOURCE
755 // Set fpu to 53 bit precision. This happens too early to use a stub. 735 // Set fpu to 53 bit precision. This happens too early to use a stub.
756 fixcw(); 736 fixcw();
757 # else
758 // set fpu to 53 bit precision
759 set_fpu_control_word(0x27f);
760 # endif
761 #endif // !AMD64 737 #endif // !AMD64
762 } 738 }
763 739
764 #ifndef _ALLBSD_SOURCE
765 int os::Bsd::get_fpu_control_word(void) {
766 #ifdef AMD64
767 return 0;
768 #else
769 int fpu_control;
770 _FPU_GETCW(fpu_control);
771 return fpu_control & 0xffff;
772 #endif // AMD64
773 }
774
775 void os::Bsd::set_fpu_control_word(int fpu_control) {
776 #ifndef AMD64
777 _FPU_SETCW(fpu_control);
778 #endif // !AMD64
779 }
780 #endif
781 740
782 // Check that the bsd kernel version is 2.4 or higher since earlier 741 // Check that the bsd kernel version is 2.4 or higher since earlier
783 // versions do not support SSE without patches. 742 // versions do not support SSE without patches.
784 bool os::supports_sse() { 743 bool os::supports_sse() {
785 #if defined(AMD64) || defined(_ALLBSD_SOURCE)
786 return true; 744 return true;
787 #else
788 struct utsname uts;
789 if( uname(&uts) != 0 ) return false; // uname fails?
790 char *minor_string;
791 int major = strtol(uts.release,&minor_string,10);
792 int minor = strtol(minor_string+1,NULL,10);
793 bool result = (major > 2 || (major==2 && minor >= 4));
794 #ifndef PRODUCT
795 if (PrintMiscellaneous && Verbose) {
796 tty->print("OS version is %d.%d, which %s support SSE/SSE2\n",
797 major,minor, result ? "DOES" : "does NOT");
798 }
799 #endif
800 return result;
801 #endif // AMD64
802 } 745 }
803 746
804 bool os::is_allocatable(size_t bytes) { 747 bool os::is_allocatable(size_t bytes) {
805 #ifdef AMD64 748 #ifdef AMD64
806 // unused on amd64? 749 // unused on amd64?
834 777
835 #ifdef __GNUC__ 778 #ifdef __GNUC__
836 #define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;}) 779 #define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
837 #endif 780 #endif
838 781
839 #ifdef _ALLBSD_SOURCE
840 bool os::Bsd::supports_variable_stack_size() { return true; } 782 bool os::Bsd::supports_variable_stack_size() { return true; }
841 #else
842 // Test if pthread library can support variable thread stack size. BsdThreads
843 // in fixed stack mode allocates 2M fixed slot for each thread. BsdThreads
844 // in floating stack mode and NPTL support variable stack size.
845 bool os::Bsd::supports_variable_stack_size() {
846 if (os::Bsd::is_NPTL()) {
847 // NPTL, yes
848 return true;
849
850 } else {
851 // Note: We can't control default stack size when creating a thread.
852 // If we use non-default stack size (pthread_attr_setstacksize), both
853 // floating stack and non-floating stack BsdThreads will return the
854 // same value. This makes it impossible to implement this function by
855 // detecting thread stack size directly.
856 //
857 // An alternative approach is to check %gs. Fixed-stack BsdThreads
858 // do not use %gs, so its value is 0. Floating-stack BsdThreads use
859 // %gs (either as LDT selector or GDT selector, depending on kernel)
860 // to access thread specific data.
861 //
862 // Note that %gs is a reserved glibc register since early 2001, so
863 // applications are not allowed to change its value (Ulrich Drepper from
864 // Redhat confirmed that all known offenders have been modified to use
865 // either %fs or TSD). In the worst case scenario, when VM is embedded in
866 // a native application that plays with %gs, we might see non-zero %gs
867 // even BsdThreads is running in fixed stack mode. As the result, we'll
868 // return true and skip _thread_safety_check(), so we may not be able to
869 // detect stack-heap collisions. But otherwise it's harmless.
870 //
871 #ifdef __GNUC__
872 return (GET_GS() != 0);
873 #else
874 return false;
875 #endif
876 }
877 }
878 #endif
879 #endif // AMD64 783 #endif // AMD64
880 784
881 // return default stack size for thr_type 785 // return default stack size for thr_type
882 size_t os::Bsd::default_stack_size(os::ThreadType thr_type) { 786 size_t os::Bsd::default_stack_size(os::ThreadType thr_type) {
883 // default stack size (compiler thread needs larger stack) 787 // default stack size (compiler thread needs larger stack)
941 if (rslt != 0) 845 if (rslt != 0)
942 fatal(err_msg("pthread_stackseg_np failed with err = %d", rslt)); 846 fatal(err_msg("pthread_stackseg_np failed with err = %d", rslt));
943 847
944 *bottom = (address)((char *)ss.ss_sp - ss.ss_size); 848 *bottom = (address)((char *)ss.ss_sp - ss.ss_size);
945 *size = ss.ss_size; 849 *size = ss.ss_size;
946 #elif defined(_ALLBSD_SOURCE) 850 #else
947 pthread_attr_t attr; 851 pthread_attr_t attr;
948 852
949 int rslt = pthread_attr_init(&attr); 853 int rslt = pthread_attr_init(&attr);
950 854
951 // JVM needs to know exact stack location, abort if it fails 855 // JVM needs to know exact stack location, abort if it fails
961 pthread_attr_getstacksize(&attr, size) != 0) { 865 pthread_attr_getstacksize(&attr, size) != 0) {
962 fatal("Can not locate current stack attributes!"); 866 fatal("Can not locate current stack attributes!");
963 } 867 }
964 868
965 pthread_attr_destroy(&attr); 869 pthread_attr_destroy(&attr);
966 #else
967 if (os::Bsd::is_initial_thread()) {
968 // initial thread needs special handling because pthread_getattr_np()
969 // may return bogus value.
970 *bottom = os::Bsd::initial_thread_stack_bottom();
971 *size = os::Bsd::initial_thread_stack_size();
972 } else {
973 pthread_attr_t attr;
974
975 int rslt = pthread_getattr_np(pthread_self(), &attr);
976
977 // JVM needs to know exact stack location, abort if it fails
978 if (rslt != 0) {
979 if (rslt == ENOMEM) {
980 vm_exit_out_of_memory(0, "pthread_getattr_np");
981 } else {
982 fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
983 }
984 }
985
986 if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
987 fatal("Can not locate current stack attributes!");
988 }
989
990 pthread_attr_destroy(&attr);
991
992 }
993 #endif 870 #endif
994 assert(os::current_stack_pointer() >= *bottom && 871 assert(os::current_stack_pointer() >= *bottom &&
995 os::current_stack_pointer() < *bottom + *size, "just checking"); 872 os::current_stack_pointer() < *bottom + *size, "just checking");
996 } 873 }
997 874