853 #endif
854
855 #endif // AMD64
856
857 // return default stack size for thr_type
858 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
859 // default stack size (compiler thread needs larger stack)
860 #ifdef AMD64
861 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
862 #else
863 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
864 #endif // AMD64
865 return s;
866 }
867
868
869 // Java thread:
870 //
871 // Low memory addresses
872 // +------------------------+
873 // | |\ JavaThread created by VM does not have glibc
874 // | glibc guard page | - guard, attached Java thread usually has
875 // | |/ 1 page glibc guard.
876 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
877 // | |\
878 // | HotSpot Guard Pages | - red and yellow pages
879 // | |/
880 // +------------------------+ JavaThread::stack_yellow_zone_base()
881 // | |\
882 // | Normal Stack | -
883 // | |/
884 // P2 +------------------------+ Thread::stack_base()
885 //
886 // Non-Java thread:
887 //
888 // Low memory addresses
889 // +------------------------+
890 // | |\
891 // | glibc guard page | - usually 1 page
892 // | |/
893 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
894 // | |\
895 // | Normal Stack | -
896 // | |/
897 // P2 +------------------------+ Thread::stack_base()
898 //
899 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
900 // pthread_attr_getstack()
908 // pthread_get_stacksize_np returns 128 pages even though the actual size is 2048 pages
909 if (pthread_main_np() == 1) {
910 if ((*size) < (DEFAULT_MAIN_THREAD_STACK_PAGES * (size_t)getpagesize())) {
911 char kern_osrelease[256];
912 size_t kern_osrelease_size = sizeof(kern_osrelease);
913 int ret = sysctlbyname("kern.osrelease", kern_osrelease, &kern_osrelease_size, NULL, 0);
914 if (ret == 0) {
915 // get the major number, atoi will ignore the minor amd micro portions of the version string
916 if (atoi(kern_osrelease) >= OS_X_10_9_0_KERNEL_MAJOR_VERSION) {
917 *size = (DEFAULT_MAIN_THREAD_STACK_PAGES*getpagesize());
918 }
919 }
920 }
921 }
922 *bottom = (address) stacktop - *size;
923 #elif defined(__OpenBSD__)
924 stack_t ss;
925 int rslt = pthread_stackseg_np(pthread_self(), &ss);
926
927 if (rslt != 0)
928 fatal("pthread_stackseg_np failed with err = %d", rslt);
929
930 *bottom = (address)((char *)ss.ss_sp - ss.ss_size);
931 *size = ss.ss_size;
932 #else
933 pthread_attr_t attr;
934
935 int rslt = pthread_attr_init(&attr);
936
937 // JVM needs to know exact stack location, abort if it fails
938 if (rslt != 0)
939 fatal("pthread_attr_init failed with err = %d", rslt);
940
941 rslt = pthread_attr_get_np(pthread_self(), &attr);
942
943 if (rslt != 0)
944 fatal("pthread_attr_get_np failed with err = %d", rslt);
945
946 if (pthread_attr_getstackaddr(&attr, (void **)bottom) != 0 ||
947 pthread_attr_getstacksize(&attr, size) != 0) {
948 fatal("Can not locate current stack attributes!");
949 }
950
951 pthread_attr_destroy(&attr);
952 #endif
953 assert(os::current_stack_pointer() >= *bottom &&
954 os::current_stack_pointer() < *bottom + *size, "just checking");
955 }
956
957 address os::current_stack_base() {
958 address bottom;
959 size_t size;
960 current_stack_region(&bottom, &size);
961 return (bottom + size);
962 }
963
964 size_t os::current_stack_size() {
|
853 #endif
854
855 #endif // AMD64
856
857 // return default stack size for thr_type
858 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
859 // default stack size (compiler thread needs larger stack)
860 #ifdef AMD64
861 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
862 #else
863 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
864 #endif // AMD64
865 return s;
866 }
867
868
869 // Java thread:
870 //
871 // Low memory addresses
872 // +------------------------+
873 // | |\ Java thread created by VM does not have glibc
874 // | glibc guard page | - guard, attached Java thread usually has
875 // | |/ 1 glibc guard page.
876 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
877 // | |\
878 // | HotSpot Guard Pages | - red, yellow and reserved pages
879 // | |/
880 // +------------------------+ JavaThread::stack_reserved_zone_base()
881 // | |\
882 // | Normal Stack | -
883 // | |/
884 // P2 +------------------------+ Thread::stack_base()
885 //
886 // Non-Java thread:
887 //
888 // Low memory addresses
889 // +------------------------+
890 // | |\
891 // | glibc guard page | - usually 1 page
892 // | |/
893 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
894 // | |\
895 // | Normal Stack | -
896 // | |/
897 // P2 +------------------------+ Thread::stack_base()
898 //
899 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
900 // pthread_attr_getstack()
908 // pthread_get_stacksize_np returns 128 pages even though the actual size is 2048 pages
909 if (pthread_main_np() == 1) {
910 if ((*size) < (DEFAULT_MAIN_THREAD_STACK_PAGES * (size_t)getpagesize())) {
911 char kern_osrelease[256];
912 size_t kern_osrelease_size = sizeof(kern_osrelease);
913 int ret = sysctlbyname("kern.osrelease", kern_osrelease, &kern_osrelease_size, NULL, 0);
914 if (ret == 0) {
915 // get the major number, atoi will ignore the minor amd micro portions of the version string
916 if (atoi(kern_osrelease) >= OS_X_10_9_0_KERNEL_MAJOR_VERSION) {
917 *size = (DEFAULT_MAIN_THREAD_STACK_PAGES*getpagesize());
918 }
919 }
920 }
921 }
922 *bottom = (address) stacktop - *size;
923 #elif defined(__OpenBSD__)
924 stack_t ss;
925 int rslt = pthread_stackseg_np(pthread_self(), &ss);
926
927 if (rslt != 0)
928 fatal("pthread_stackseg_np failed with error = %d", rslt);
929
930 *bottom = (address)((char *)ss.ss_sp - ss.ss_size);
931 *size = ss.ss_size;
932 #else
933 pthread_attr_t attr;
934
935 int rslt = pthread_attr_init(&attr);
936
937 // JVM needs to know exact stack location, abort if it fails
938 if (rslt != 0)
939 fatal("pthread_attr_init failed with error = %d", rslt);
940
941 rslt = pthread_attr_get_np(pthread_self(), &attr);
942
943 if (rslt != 0)
944 fatal("pthread_attr_get_np failed with error = %d", rslt);
945
946 if (pthread_attr_getstackaddr(&attr, (void **)bottom) != 0 ||
947 pthread_attr_getstacksize(&attr, size) != 0) {
948 fatal("Can not locate current stack attributes!");
949 }
950
951 pthread_attr_destroy(&attr);
952 #endif
953 assert(os::current_stack_pointer() >= *bottom &&
954 os::current_stack_pointer() < *bottom + *size, "just checking");
955 }
956
957 address os::current_stack_base() {
958 address bottom;
959 size_t size;
960 current_stack_region(&bottom, &size);
961 return (bottom + size);
962 }
963
964 size_t os::current_stack_size() {
|