681 size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
682 size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
683 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
684 #else
685 size_t os::Posix::_compiler_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
686 size_t os::Posix::_java_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
687 size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
688 #endif // AMD64
689
690 // return default stack size for thr_type
691 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
692 // default stack size (compiler thread needs larger stack)
693 #ifdef AMD64
694 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
695 #else
696 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
697 #endif // AMD64
698 return s;
699 }
700
701 size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
702 // Creating guard page is very expensive. Java thread has HotSpot
703 // guard page, only enable glibc guard page for non-Java threads.
704 return (thr_type == java_thread ? 0 : page_size());
705 }
706
707 // Java thread:
708 //
709 // Low memory addresses
710 // +------------------------+
711 // | |\ JavaThread created by VM does not have glibc
712 // | glibc guard page | - guard, attached Java thread usually has
713 // | |/ 1 page glibc guard.
714 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
715 // | |\
716 // | HotSpot Guard Pages | - red and yellow pages
717 // | |/
718 // +------------------------+ JavaThread::stack_yellow_zone_base()
719 // | |\
720 // | Normal Stack | -
721 // | |/
722 // P2 +------------------------+ Thread::stack_base()
723 //
724 // Non-Java thread:
725 //
726 // Low memory addresses
727 // +------------------------+
728 // | |\
729 // | glibc guard page | - usually 1 page
730 // | |/
731 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
732 // | |\
733 // | Normal Stack | -
734 // | |/
735 // P2 +------------------------+ Thread::stack_base()
736 //
737 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
738 // pthread_attr_getstack()
739
740 static void current_stack_region(address * bottom, size_t * size) {
741 if (os::Linux::is_initial_thread()) {
742 // initial thread needs special handling because pthread_getattr_np()
743 // may return bogus value.
744 *bottom = os::Linux::initial_thread_stack_bottom();
745 *size = os::Linux::initial_thread_stack_size();
746 } else {
747 pthread_attr_t attr;
748
749 int rslt = pthread_getattr_np(pthread_self(), &attr);
750
751 // JVM needs to know exact stack location, abort if it fails
752 if (rslt != 0) {
753 if (rslt == ENOMEM) {
754 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
755 } else {
756 fatal("pthread_getattr_np failed with errno = %d", rslt);
757 }
758 }
759
760 if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
761 fatal("Can not locate current stack attributes!");
762 }
763
764 pthread_attr_destroy(&attr);
765
766 }
767 assert(os::current_stack_pointer() >= *bottom &&
768 os::current_stack_pointer() < *bottom + *size, "just checking");
769 }
770
771 address os::current_stack_base() {
772 address bottom;
773 size_t size;
774 current_stack_region(&bottom, &size);
775 return (bottom + size);
776 }
777
778 size_t os::current_stack_size() {
779 // stack size includes normal stack and HotSpot guard pages
780 address bottom;
781 size_t size;
782 current_stack_region(&bottom, &size);
783 return size;
784 }
785
786 /////////////////////////////////////////////////////////////////////////////
787 // helper functions for fatal error handler
788
789 void os::print_context(outputStream *st, const void *context) {
790 if (context == NULL) return;
791
792 const ucontext_t *uc = (const ucontext_t*)context;
793 st->print_cr("Registers:");
794 #ifdef AMD64
795 st->print( "RAX=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RAX]);
796 st->print(", RBX=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RBX]);
797 st->print(", RCX=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RCX]);
798 st->print(", RDX=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RDX]);
799 st->cr();
800 st->print( "RSP=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RSP]);
801 st->print(", RBP=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RBP]);
802 st->print(", RSI=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RSI]);
803 st->print(", RDI=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RDI]);
804 st->cr();
805 st->print( "R8 =" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_R8]);
|
681 size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
682 size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
683 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
684 #else
685 size_t os::Posix::_compiler_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
686 size_t os::Posix::_java_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
687 size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
688 #endif // AMD64
689
690 // return default stack size for thr_type
691 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
692 // default stack size (compiler thread needs larger stack)
693 #ifdef AMD64
694 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
695 #else
696 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
697 #endif // AMD64
698 return s;
699 }
700
701 /////////////////////////////////////////////////////////////////////////////
702 // helper functions for fatal error handler
703
704 void os::print_context(outputStream *st, const void *context) {
705 if (context == NULL) return;
706
707 const ucontext_t *uc = (const ucontext_t*)context;
708 st->print_cr("Registers:");
709 #ifdef AMD64
710 st->print( "RAX=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RAX]);
711 st->print(", RBX=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RBX]);
712 st->print(", RCX=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RCX]);
713 st->print(", RDX=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RDX]);
714 st->cr();
715 st->print( "RSP=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RSP]);
716 st->print(", RBP=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RBP]);
717 st->print(", RSI=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RSI]);
718 st->print(", RDI=" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_RDI]);
719 st->cr();
720 st->print( "R8 =" INTPTR_FORMAT, (intptr_t)uc->uc_mcontext.gregs[REG_R8]);
|