524 } |
524 } |
525 |
525 |
526 //////////////////////////////////////////////////////////////////////////////// |
526 //////////////////////////////////////////////////////////////////////////////// |
527 // thread stack |
527 // thread stack |
528 |
528 |
529 size_t os::Posix::_compiler_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K; |
529 // Minimum usable stack sizes required to get to user code. Space for |
530 size_t os::Posix::_java_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K; |
530 // HotSpot guard pages is added later. |
|
531 size_t os::Posix::_compiler_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 4)) * K; |
|
532 size_t os::Posix::_java_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 4)) * K; |
531 size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K; |
533 size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K; |
532 |
534 |
533 // return default stack size for thr_type |
535 // return default stack size for thr_type |
534 size_t os::Posix::default_stack_size(os::ThreadType thr_type) { |
536 size_t os::Posix::default_stack_size(os::ThreadType thr_type) { |
535 // default stack size (compiler thread needs larger stack) |
537 // default stack size (compiler thread needs larger stack) |
536 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K); |
538 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K); |
537 return s; |
539 return s; |
538 } |
|
539 |
|
540 size_t os::Linux::default_guard_size(os::ThreadType thr_type) { |
|
541 // Creating guard page is very expensive. Java thread has HotSpot |
|
542 // guard page, only enable glibc guard page for non-Java threads. |
|
543 return (thr_type == java_thread ? 0 : page_size()); |
|
544 } |
|
545 |
|
546 // Java thread: |
|
547 // |
|
548 // Low memory addresses |
|
549 // +------------------------+ |
|
550 // | |\ JavaThread created by VM does not have glibc |
|
551 // | glibc guard page | - guard, attached Java thread usually has |
|
552 // | |/ 1 page glibc guard. |
|
553 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size() |
|
554 // | |\ |
|
555 // | HotSpot Guard Pages | - red and yellow pages |
|
556 // | |/ |
|
557 // +------------------------+ JavaThread::stack_yellow_zone_base() |
|
558 // | |\ |
|
559 // | Normal Stack | - |
|
560 // | |/ |
|
561 // P2 +------------------------+ Thread::stack_base() |
|
562 // |
|
563 // Non-Java thread: |
|
564 // |
|
565 // Low memory addresses |
|
566 // +------------------------+ |
|
567 // | |\ |
|
568 // | glibc guard page | - usually 1 page |
|
569 // | |/ |
|
570 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size() |
|
571 // | |\ |
|
572 // | Normal Stack | - |
|
573 // | |/ |
|
574 // P2 +------------------------+ Thread::stack_base() |
|
575 // |
|
576 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from |
|
577 // pthread_attr_getstack() |
|
578 |
|
579 static void current_stack_region(address * bottom, size_t * size) { |
|
580 if (os::Linux::is_initial_thread()) { |
|
581 // initial thread needs special handling because pthread_getattr_np() |
|
582 // may return bogus value. |
|
583 *bottom = os::Linux::initial_thread_stack_bottom(); |
|
584 *size = os::Linux::initial_thread_stack_size(); |
|
585 } else { |
|
586 pthread_attr_t attr; |
|
587 |
|
588 int rslt = pthread_getattr_np(pthread_self(), &attr); |
|
589 |
|
590 // JVM needs to know exact stack location, abort if it fails |
|
591 if (rslt != 0) { |
|
592 if (rslt == ENOMEM) { |
|
593 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np"); |
|
594 } else { |
|
595 fatal("pthread_getattr_np failed"); |
|
596 } |
|
597 } |
|
598 |
|
599 if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) { |
|
600 fatal("Can not locate current stack attributes!"); |
|
601 } |
|
602 |
|
603 pthread_attr_destroy(&attr); |
|
604 |
|
605 } |
|
606 assert(os::current_stack_pointer() >= *bottom && |
|
607 os::current_stack_pointer() < *bottom + *size, "just checking"); |
|
608 } |
|
609 |
|
610 address os::current_stack_base() { |
|
611 address bottom; |
|
612 size_t size; |
|
613 current_stack_region(&bottom, &size); |
|
614 return (bottom + size); |
|
615 } |
|
616 |
|
617 size_t os::current_stack_size() { |
|
618 // stack size includes normal stack and HotSpot guard pages |
|
619 address bottom; |
|
620 size_t size; |
|
621 current_stack_region(&bottom, &size); |
|
622 return size; |
|
623 } |
540 } |
624 |
541 |
625 ///////////////////////////////////////////////////////////////////////////// |
542 ///////////////////////////////////////////////////////////////////////////// |
626 // helper functions for fatal error handler |
543 // helper functions for fatal error handler |
627 |
544 |