471 } |
471 } |
472 |
472 |
473 //////////////////////////////////////////////////////////////////////////////// |
473 //////////////////////////////////////////////////////////////////////////////// |
474 // thread stack |
474 // thread stack |
475 |
475 |
476 size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K; |
476 // Minimum usable stack sizes required to get to user code. Space for |
477 size_t os::Posix::_java_thread_min_stack_allowed = 64 * K; |
477 // HotSpot guard pages is added later. |
|
478 size_t os::Posix::_compiler_thread_min_stack_allowed = 32 * K; |
|
479 size_t os::Posix::_java_thread_min_stack_allowed = 32 * K; |
478 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K; |
480 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K; |
479 |
481 |
480 // return default stack size for thr_type |
482 // return default stack size for thr_type |
481 size_t os::Posix::default_stack_size(os::ThreadType thr_type) { |
483 size_t os::Posix::default_stack_size(os::ThreadType thr_type) { |
482 // default stack size (compiler thread needs larger stack) |
484 // default stack size (compiler thread needs larger stack) |
483 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); |
485 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); |
484 return s; |
486 return s; |
485 } |
|
486 |
|
487 size_t os::Linux::default_guard_size(os::ThreadType thr_type) { |
|
488 // Creating guard page is very expensive. Java thread has HotSpot |
|
489 // guard page, only enable glibc guard page for non-Java threads. |
|
490 return (thr_type == java_thread ? 0 : page_size()); |
|
491 } |
|
492 |
|
493 // Java thread: |
|
494 // |
|
495 // Low memory addresses |
|
496 // +------------------------+ |
|
497 // | |\ JavaThread created by VM does not have glibc |
|
498 // | glibc guard page | - guard, attached Java thread usually has |
|
499 // | |/ 1 page glibc guard. |
|
500 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size() |
|
501 // | |\ |
|
502 // | HotSpot Guard Pages | - red and yellow pages |
|
503 // | |/ |
|
504 // +------------------------+ JavaThread::stack_yellow_zone_base() |
|
505 // | |\ |
|
506 // | Normal Stack | - |
|
507 // | |/ |
|
508 // P2 +------------------------+ Thread::stack_base() |
|
509 // |
|
510 // Non-Java thread: |
|
511 // |
|
512 // Low memory addresses |
|
513 // +------------------------+ |
|
514 // | |\ |
|
515 // | glibc guard page | - usually 1 page |
|
516 // | |/ |
|
517 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size() |
|
518 // | |\ |
|
519 // | Normal Stack | - |
|
520 // | |/ |
|
521 // P2 +------------------------+ Thread::stack_base() |
|
522 // |
|
523 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from |
|
524 // pthread_attr_getstack() |
|
525 |
|
526 static void current_stack_region(address * bottom, size_t * size) { |
|
527 if (os::Linux::is_initial_thread()) { |
|
528 // initial thread needs special handling because pthread_getattr_np() |
|
529 // may return bogus value. |
|
530 *bottom = os::Linux::initial_thread_stack_bottom(); |
|
531 *size = os::Linux::initial_thread_stack_size(); |
|
532 } else { |
|
533 pthread_attr_t attr; |
|
534 |
|
535 int rslt = pthread_getattr_np(pthread_self(), &attr); |
|
536 |
|
537 // JVM needs to know exact stack location, abort if it fails |
|
538 if (rslt != 0) { |
|
539 if (rslt == ENOMEM) { |
|
540 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np"); |
|
541 } else { |
|
542 fatal("pthread_getattr_np failed with errno = %d", rslt); |
|
543 } |
|
544 } |
|
545 |
|
546 if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) { |
|
547 fatal("Can not locate current stack attributes!"); |
|
548 } |
|
549 |
|
550 pthread_attr_destroy(&attr); |
|
551 |
|
552 } |
|
553 assert(os::current_stack_pointer() >= *bottom && |
|
554 os::current_stack_pointer() < *bottom + *size, "just checking"); |
|
555 } |
|
556 |
|
557 address os::current_stack_base() { |
|
558 address bottom; |
|
559 size_t size; |
|
560 current_stack_region(&bottom, &size); |
|
561 return (bottom + size); |
|
562 } |
|
563 |
|
564 size_t os::current_stack_size() { |
|
565 // stack size includes normal stack and HotSpot guard pages |
|
566 address bottom; |
|
567 size_t size; |
|
568 current_stack_region(&bottom, &size); |
|
569 return size; |
|
570 } |
487 } |
571 |
488 |
572 ///////////////////////////////////////////////////////////////////////////// |
489 ///////////////////////////////////////////////////////////////////////////// |
573 // helper functions for fatal error handler |
490 // helper functions for fatal error handler |
574 |
491 |