845 } |
845 } |
846 |
846 |
847 return 0; |
847 return 0; |
848 } |
848 } |
849 |
849 |
850 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) { |
850 bool os::create_thread(Thread* thread, ThreadType thr_type, |
|
851 size_t req_stack_size) { |
851 |
852 |
852 assert(thread->osthread() == NULL, "caller responsible"); |
853 assert(thread->osthread() == NULL, "caller responsible"); |
853 |
854 |
854 // Allocate the OSThread object |
855 // Allocate the OSThread object |
855 OSThread* osthread = new OSThread(NULL, NULL); |
856 OSThread* osthread = new OSThread(NULL, NULL); |
878 |
879 |
879 // Start in suspended state, and in os::thread_start, wake the thread up. |
880 // Start in suspended state, and in os::thread_start, wake the thread up. |
880 guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???"); |
881 guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???"); |
881 |
882 |
882 // calculate stack size if it's not specified by caller |
883 // calculate stack size if it's not specified by caller |
883 if (stack_size == 0) { |
884 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size); |
884 stack_size = os::Aix::default_stack_size(thr_type); |
|
885 |
|
886 switch (thr_type) { |
|
887 case os::java_thread: |
|
888 // Java threads use ThreadStackSize whose default value can be changed with the flag -Xss. |
|
889 assert(JavaThread::stack_size_at_create() > 0, "this should be set"); |
|
890 stack_size = JavaThread::stack_size_at_create(); |
|
891 break; |
|
892 case os::compiler_thread: |
|
893 if (CompilerThreadStackSize > 0) { |
|
894 stack_size = (size_t)(CompilerThreadStackSize * K); |
|
895 break; |
|
896 } // else fall through: |
|
897 // use VMThreadStackSize if CompilerThreadStackSize is not defined |
|
898 case os::vm_thread: |
|
899 case os::pgc_thread: |
|
900 case os::cgc_thread: |
|
901 case os::watcher_thread: |
|
902 if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K); |
|
903 break; |
|
904 } |
|
905 } |
|
906 |
|
907 stack_size = MAX2(stack_size, os::Aix::min_stack_allowed); |
|
908 pthread_attr_setstacksize(&attr, stack_size); |
885 pthread_attr_setstacksize(&attr, stack_size); |
909 |
886 |
910 pthread_t tid; |
887 pthread_t tid; |
911 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread); |
888 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread); |
912 |
|
913 |
889 |
914 char buf[64]; |
890 char buf[64]; |
915 if (ret == 0) { |
891 if (ret == 0) { |
916 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ", |
892 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ", |
917 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); |
893 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); |
3591 } |
3567 } |
3592 |
3568 |
3593 Aix::signal_sets_init(); |
3569 Aix::signal_sets_init(); |
3594 Aix::install_signal_handlers(); |
3570 Aix::install_signal_handlers(); |
3595 |
3571 |
3596 // Check minimum allowable stack size for thread creation and to initialize |
3572 // Check and sets minimum stack sizes against command line options |
3597 // the java system classes, including StackOverflowError - depends on page |
3573 if (Posix::set_minimum_stack_sizes() == JNI_ERR) { |
3598 // size. Add two 4K pages for compiler2 recursion in main thread. |
|
3599 // Add in 4*BytesPerWord 4K pages to account for VM stack during |
|
3600 // class initialization depending on 32 or 64 bit VM. |
|
3601 os::Aix::min_stack_allowed = MAX2(os::Aix::min_stack_allowed, |
|
3602 JavaThread::stack_guard_zone_size() + |
|
3603 JavaThread::stack_shadow_zone_size() + |
|
3604 (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K); |
|
3605 |
|
3606 os::Aix::min_stack_allowed = align_size_up(os::Aix::min_stack_allowed, os::vm_page_size()); |
|
3607 |
|
3608 size_t threadStackSizeInBytes = ThreadStackSize * K; |
|
3609 if (threadStackSizeInBytes != 0 && |
|
3610 threadStackSizeInBytes < os::Aix::min_stack_allowed) { |
|
3611 tty->print_cr("\nThe stack size specified is too small, " |
|
3612 "Specify at least %dk", |
|
3613 os::Aix::min_stack_allowed / K); |
|
3614 return JNI_ERR; |
3574 return JNI_ERR; |
3615 } |
3575 } |
3616 |
|
3617 // Make the stack size a multiple of the page size so that |
|
3618 // the yellow/red zones can be guarded. |
|
3619 // Note that this can be 0, if no default stacksize was set. |
|
3620 JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes, vm_page_size())); |
|
3621 |
3576 |
3622 if (UseNUMA) { |
3577 if (UseNUMA) { |
3623 UseNUMA = false; |
3578 UseNUMA = false; |
3624 warning("NUMA optimizations are not available on this OS."); |
3579 warning("NUMA optimizations are not available on this OS."); |
3625 } |
3580 } |