< prev index next >

hotspot/src/os/aix/vm/os_aix.cpp

Print this page




 830   assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
 831 
 832   // Call one more level start routine.
 833   thread->run();
 834 
 835   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
 836     os::current_thread_id(), (uintx) kernel_thread_id);
 837 
 838   // If a thread has not deleted itself ("delete this") as part of its
 839   // termination sequence, we have to ensure thread-local-storage is
 840   // cleared before we actually terminate. No threads should ever be
 841   // deleted asynchronously with respect to their termination.
 842   if (Thread::current_or_null_safe() != NULL) {
 843     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
 844     thread->clear_thread_current();
 845   }
 846 
 847   return 0;
 848 }
 849 
 850 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {

 851 
 852   assert(thread->osthread() == NULL, "caller responsible");
 853 
 854   // Allocate the OSThread object
 855   OSThread* osthread = new OSThread(NULL, NULL);
 856   if (osthread == NULL) {
 857     return false;
 858   }
 859 
 860   // set the correct thread state
 861   osthread->set_thread_type(thr_type);
 862 
 863   // Initial state is ALLOCATED but not INITIALIZED
 864   osthread->set_state(ALLOCATED);
 865 
 866   thread->set_osthread(osthread);
 867 
 868   // init thread attributes
 869   pthread_attr_t attr;
 870   pthread_attr_init(&attr);
 871   guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
 872 
 873   // Make sure we run in 1:1 kernel-user-thread mode.
 874   if (os::Aix::on_aix()) {
 875     guarantee(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0, "???");
 876     guarantee(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0, "???");
 877   } // end: aix
 878 
 879   // 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 
 882   // calculate stack size if it's not specified by caller
 883   if (stack_size == 0) {
 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);
 909 
 910   pthread_t tid;
 911   int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
 912 
 913 
 914   char buf[64];
 915   if (ret == 0) {
 916     log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
 917       (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 918   } else {
 919     log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
 920       ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 921   }
 922 
 923   pthread_attr_destroy(&attr);
 924 
 925   if (ret != 0) {
 926     // Need to clean up stuff we've allocated so far
 927     thread->set_osthread(NULL);
 928     delete osthread;
 929     return false;
 930   }
 931 
 932   // OSThread::thread_id is the pthread id.
 933   osthread->set_thread_id(tid);


3576 
3577   if (!UseMembar) {
3578     address mem_serialize_page = (address) ::mmap(NULL, Aix::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3579     guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
3580     os::set_memory_serialize_page(mem_serialize_page);
3581 
3582     trcVerbose("Memory Serialize  Page address: %p - %p, size %IX (%IB)",
3583         mem_serialize_page, mem_serialize_page + Aix::page_size(),
3584         Aix::page_size(), Aix::page_size());
3585   }
3586 
3587   // initialize suspend/resume support - must do this before signal_sets_init()
3588   if (SR_initialize() != 0) {
3589     perror("SR_initialize failed");
3590     return JNI_ERR;
3591   }
3592 
3593   Aix::signal_sets_init();
3594   Aix::install_signal_handlers();
3595 
3596   // Check minimum allowable stack size for thread creation and to initialize
3597   // the java system classes, including StackOverflowError - depends on page
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;
3615   }
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 
3622   if (UseNUMA) {
3623     UseNUMA = false;
3624     warning("NUMA optimizations are not available on this OS.");
3625   }
3626 
3627   if (MaxFDLimit) {
3628     // Set the number of file descriptors to max. print out error
3629     // if getrlimit/setrlimit fails but continue regardless.
3630     struct rlimit nbr_files;
3631     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3632     if (status != 0) {
3633       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
3634     } else {
3635       nbr_files.rlim_cur = nbr_files.rlim_max;
3636       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
3637       if (status != 0) {
3638         log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
3639       }
3640     }
3641   }




 830   assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
 831 
 832   // Call one more level start routine.
 833   thread->run();
 834 
 835   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
 836     os::current_thread_id(), (uintx) kernel_thread_id);
 837 
 838   // If a thread has not deleted itself ("delete this") as part of its
 839   // termination sequence, we have to ensure thread-local-storage is
 840   // cleared before we actually terminate. No threads should ever be
 841   // deleted asynchronously with respect to their termination.
 842   if (Thread::current_or_null_safe() != NULL) {
 843     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
 844     thread->clear_thread_current();
 845   }
 846 
 847   return 0;
 848 }
 849 
 850 bool os::create_thread(Thread* thread, ThreadType thr_type,
 851                        size_t req_stack_size) {
 852 
 853   assert(thread->osthread() == NULL, "caller responsible");
 854 
 855   // Allocate the OSThread object
 856   OSThread* osthread = new OSThread(NULL, NULL);
 857   if (osthread == NULL) {
 858     return false;
 859   }
 860 
 861   // set the correct thread state
 862   osthread->set_thread_type(thr_type);
 863 
 864   // Initial state is ALLOCATED but not INITIALIZED
 865   osthread->set_state(ALLOCATED);
 866 
 867   thread->set_osthread(osthread);
 868 
 869   // init thread attributes
 870   pthread_attr_t attr;
 871   pthread_attr_init(&attr);
 872   guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
 873 
 874   // Make sure we run in 1:1 kernel-user-thread mode.
 875   if (os::Aix::on_aix()) {
 876     guarantee(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0, "???");
 877     guarantee(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0, "???");
 878   } // end: aix
 879 
 880   // Start in suspended state, and in os::thread_start, wake the thread up.
 881   guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???");
 882 
 883   // calculate stack size if it's not specified by caller
 884   size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
























 885   pthread_attr_setstacksize(&attr, stack_size);
 886 
 887   pthread_t tid;
 888   int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
 889 

 890   char buf[64];
 891   if (ret == 0) {
 892     log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
 893       (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 894   } else {
 895     log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
 896       ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 897   }
 898 
 899   pthread_attr_destroy(&attr);
 900 
 901   if (ret != 0) {
 902     // Need to clean up stuff we've allocated so far
 903     thread->set_osthread(NULL);
 904     delete osthread;
 905     return false;
 906   }
 907 
 908   // OSThread::thread_id is the pthread id.
 909   osthread->set_thread_id(tid);


3552 
3553   if (!UseMembar) {
3554     address mem_serialize_page = (address) ::mmap(NULL, Aix::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3555     guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
3556     os::set_memory_serialize_page(mem_serialize_page);
3557 
3558     trcVerbose("Memory Serialize  Page address: %p - %p, size %IX (%IB)",
3559         mem_serialize_page, mem_serialize_page + Aix::page_size(),
3560         Aix::page_size(), Aix::page_size());
3561   }
3562 
3563   // initialize suspend/resume support - must do this before signal_sets_init()
3564   if (SR_initialize() != 0) {
3565     perror("SR_initialize failed");
3566     return JNI_ERR;
3567   }
3568 
3569   Aix::signal_sets_init();
3570   Aix::install_signal_handlers();
3571 
3572   // Check and sets minimum stack sizes against command line options
3573   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
















3574     return JNI_ERR;
3575   }
3576 





3577   if (UseNUMA) {
3578     UseNUMA = false;
3579     warning("NUMA optimizations are not available on this OS.");
3580   }
3581 
3582   if (MaxFDLimit) {
3583     // Set the number of file descriptors to max. print out error
3584     // if getrlimit/setrlimit fails but continue regardless.
3585     struct rlimit nbr_files;
3586     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3587     if (status != 0) {
3588       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
3589     } else {
3590       nbr_files.rlim_cur = nbr_files.rlim_max;
3591       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
3592       if (status != 0) {
3593         log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
3594       }
3595     }
3596   }


< prev index next >