< prev index next >

hotspot/src/os/bsd/vm/os_bsd.cpp

Print this page




 717   }
 718 
 719   // call one more level start routine
 720   thread->run();
 721 
 722   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
 723     os::current_thread_id(), (uintx) pthread_self());
 724 
 725   // If a thread has not deleted itself ("delete this") as part of its
 726   // termination sequence, we have to ensure thread-local-storage is
 727   // cleared before we actually terminate. No threads should ever be
 728   // deleted asynchronously with respect to their termination.
 729   if (Thread::current_or_null_safe() != NULL) {
 730     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
 731     thread->clear_thread_current();
 732   }
 733 
 734   return 0;
 735 }
 736 
 737 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {

 738   assert(thread->osthread() == NULL, "caller responsible");
 739 
 740   // Allocate the OSThread object
 741   OSThread* osthread = new OSThread(NULL, NULL);
 742   if (osthread == NULL) {
 743     return false;
 744   }
 745 
 746   // set the correct thread state
 747   osthread->set_thread_type(thr_type);
 748 
 749   // Initial state is ALLOCATED but not INITIALIZED
 750   osthread->set_state(ALLOCATED);
 751 
 752   thread->set_osthread(osthread);
 753 
 754   // init thread attributes
 755   pthread_attr_t attr;
 756   pthread_attr_init(&attr);
 757   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 758 
 759   // calculate stack size if it's not specified by caller
 760   if (stack_size == 0) {
 761     stack_size = os::Bsd::default_stack_size(thr_type);
 762 
 763     switch (thr_type) {
 764     case os::java_thread:
 765       // Java threads use ThreadStackSize which default value can be
 766       // changed with the flag -Xss
 767       assert(JavaThread::stack_size_at_create() > 0, "this should be set");
 768       stack_size = JavaThread::stack_size_at_create();
 769       break;
 770     case os::compiler_thread:
 771       if (CompilerThreadStackSize > 0) {
 772         stack_size = (size_t)(CompilerThreadStackSize * K);
 773         break;
 774       } // else fall through:
 775         // use VMThreadStackSize if CompilerThreadStackSize is not defined
 776     case os::vm_thread:
 777     case os::pgc_thread:
 778     case os::cgc_thread:
 779     case os::watcher_thread:
 780       if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
 781       break;
 782     }
 783   }
 784 
 785   stack_size = MAX2(stack_size, os::Bsd::min_stack_allowed);
 786   pthread_attr_setstacksize(&attr, stack_size);
 787 
 788   ThreadState state;
 789 
 790   {
 791     pthread_t tid;
 792     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
 793 
 794     char buf[64];
 795     if (ret == 0) {
 796       log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
 797         (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 798     } else {
 799       log_warning(os, thread)("Failed to start thread - pthread_create failed (%s) for attributes: %s.",
 800         os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 801     }
 802 
 803     pthread_attr_destroy(&attr);
 804 
 805     if (ret != 0) {


3485 
3486   os::set_polling_page(polling_page);
3487   log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
3488 
3489   if (!UseMembar) {
3490     address mem_serialize_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3491     guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
3492     os::set_memory_serialize_page(mem_serialize_page);
3493     log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
3494   }
3495 
3496   // initialize suspend/resume support - must do this before signal_sets_init()
3497   if (SR_initialize() != 0) {
3498     perror("SR_initialize failed");
3499     return JNI_ERR;
3500   }
3501 
3502   Bsd::signal_sets_init();
3503   Bsd::install_signal_handlers();
3504 
3505   // Check minimum allowable stack size for thread creation and to initialize
3506   // the java system classes, including StackOverflowError - depends on page
3507   // size.  Add two 4K pages for compiler2 recursion in main thread.
3508   // Add in 4*BytesPerWord 4K pages to account for VM stack during
3509   // class initialization depending on 32 or 64 bit VM.
3510   os::Bsd::min_stack_allowed = MAX2(os::Bsd::min_stack_allowed,
3511                                     JavaThread::stack_guard_zone_size() +
3512                                     JavaThread::stack_shadow_zone_size() +
3513                                     (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K);
3514 
3515   os::Bsd::min_stack_allowed = align_size_up(os::Bsd::min_stack_allowed, os::vm_page_size());
3516 
3517   size_t threadStackSizeInBytes = ThreadStackSize * K;
3518   if (threadStackSizeInBytes != 0 &&
3519       threadStackSizeInBytes < os::Bsd::min_stack_allowed) {
3520     tty->print_cr("\nThe stack size specified is too small, "
3521                   "Specify at least %dk",
3522                   os::Bsd::min_stack_allowed/ K);
3523     return JNI_ERR;
3524   }
3525 
3526   // Make the stack size a multiple of the page size so that
3527   // the yellow/red zones can be guarded.
3528   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
3529                                                 vm_page_size()));
3530 
3531   if (MaxFDLimit) {
3532     // set the number of file descriptors to max. print out error
3533     // if getrlimit/setrlimit fails but continue regardless.
3534     struct rlimit nbr_files;
3535     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3536     if (status != 0) {
3537       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
3538     } else {
3539       nbr_files.rlim_cur = nbr_files.rlim_max;
3540 
3541 #ifdef __APPLE__
3542       // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
3543       // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
3544       // be used instead
3545       nbr_files.rlim_cur = MIN(OPEN_MAX, nbr_files.rlim_cur);
3546 #endif
3547 
3548       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
3549       if (status != 0) {
3550         log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));




 717   }
 718 
 719   // call one more level start routine
 720   thread->run();
 721 
 722   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
 723     os::current_thread_id(), (uintx) pthread_self());
 724 
 725   // If a thread has not deleted itself ("delete this") as part of its
 726   // termination sequence, we have to ensure thread-local-storage is
 727   // cleared before we actually terminate. No threads should ever be
 728   // deleted asynchronously with respect to their termination.
 729   if (Thread::current_or_null_safe() != NULL) {
 730     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
 731     thread->clear_thread_current();
 732   }
 733 
 734   return 0;
 735 }
 736 
 737 bool os::create_thread(Thread* thread, ThreadType thr_type,
 738                        size_t req_stack_size) {
 739   assert(thread->osthread() == NULL, "caller responsible");
 740 
 741   // Allocate the OSThread object
 742   OSThread* osthread = new OSThread(NULL, NULL);
 743   if (osthread == NULL) {
 744     return false;
 745   }
 746 
 747   // set the correct thread state
 748   osthread->set_thread_type(thr_type);
 749 
 750   // Initial state is ALLOCATED but not INITIALIZED
 751   osthread->set_state(ALLOCATED);
 752 
 753   thread->set_osthread(osthread);
 754 
 755   // init thread attributes
 756   pthread_attr_t attr;
 757   pthread_attr_init(&attr);
 758   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 759 
 760   // calculate stack size if it's not specified by caller
 761   size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);

























 762   pthread_attr_setstacksize(&attr, stack_size);
 763 
 764   ThreadState state;
 765 
 766   {
 767     pthread_t tid;
 768     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
 769 
 770     char buf[64];
 771     if (ret == 0) {
 772       log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
 773         (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 774     } else {
 775       log_warning(os, thread)("Failed to start thread - pthread_create failed (%s) for attributes: %s.",
 776         os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 777     }
 778 
 779     pthread_attr_destroy(&attr);
 780 
 781     if (ret != 0) {


3461 
3462   os::set_polling_page(polling_page);
3463   log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
3464 
3465   if (!UseMembar) {
3466     address mem_serialize_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3467     guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
3468     os::set_memory_serialize_page(mem_serialize_page);
3469     log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
3470   }
3471 
3472   // initialize suspend/resume support - must do this before signal_sets_init()
3473   if (SR_initialize() != 0) {
3474     perror("SR_initialize failed");
3475     return JNI_ERR;
3476   }
3477 
3478   Bsd::signal_sets_init();
3479   Bsd::install_signal_handlers();
3480 
3481   // Check and sets minimum stack sizes against command line options
3482   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
















3483     return JNI_ERR;
3484   }
3485 





3486   if (MaxFDLimit) {
3487     // set the number of file descriptors to max. print out error
3488     // if getrlimit/setrlimit fails but continue regardless.
3489     struct rlimit nbr_files;
3490     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3491     if (status != 0) {
3492       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
3493     } else {
3494       nbr_files.rlim_cur = nbr_files.rlim_max;
3495 
3496 #ifdef __APPLE__
3497       // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
3498       // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
3499       // be used instead
3500       nbr_files.rlim_cur = MIN(OPEN_MAX, nbr_files.rlim_cur);
3501 #endif
3502 
3503       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
3504       if (status != 0) {
3505         log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));


< prev index next >