< prev index next >

src/os/aix/vm/os_aix.cpp

Print this page
rev 12406 : 8169373: Work around linux NPTL stack guard error.
Summary: Also skip libc guard page for compiler thread, merge similar code on linux platforms, and streamline libc guard page handling on linuxs390, linuxppc, aixppc.
Reviewed-by: dholmes, dcubed, kvn


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



 883   pthread_t tid;
 884   int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
 885 
 886   char buf[64];
 887   if (ret == 0) {
 888     log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
 889       (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 890   } else {
 891     log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
 892       ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 893   }
 894 
 895   pthread_attr_destroy(&attr);
 896 
 897   if (ret != 0) {
 898     // Need to clean up stuff we've allocated so far
 899     thread->set_osthread(NULL);
 900     delete osthread;
 901     return false;
 902   }
 903 
 904   // OSThread::thread_id is the pthread id.
 905   osthread->set_thread_id(tid);
 906 
 907   return true;
 908 }
 909 
 910 /////////////////////////////////////////////////////////////////////////////
 911 // attach existing thread
 912 
 913 // bootstrap the main thread
 914 bool os::create_main_thread(JavaThread* thread) {
 915   assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread");
 916   return create_attached_thread(thread);
 917 }
 918 


3013       (*hand)(sig);
3014     }
3015 
3016     // restore the signal mask
3017     pthread_sigmask(SIG_SETMASK, &oset, 0);
3018   }
3019   // Tell jvm's signal handler the signal is taken care of.
3020   return true;
3021 }
3022 
3023 bool os::Aix::chained_handler(int sig, siginfo_t* siginfo, void* context) {
3024   bool chained = false;
3025   // signal-chaining
3026   if (UseSignalChaining) {
3027     struct sigaction *actp = get_chained_signal_action(sig);
3028     if (actp != NULL) {
3029       chained = call_chained_handler(actp, sig, siginfo, context);
3030     }
3031   }
3032   return chained;













3033 }
3034 
3035 struct sigaction* os::Aix::get_preinstalled_handler(int sig) {
3036   if (sigismember(&sigs, sig)) {
3037     return &sigact[sig];
3038   }
3039   return NULL;
3040 }
3041 
3042 void os::Aix::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
3043   assert(sig > 0 && sig < NSIG, "vm signal out of expected range");
3044   sigact[sig] = oldAct;
3045   sigaddset(&sigs, sig);
3046 }
3047 
3048 // for diagnostic
3049 int sigflags[NSIG];
3050 
3051 int os::Aix::get_our_sigflags(int sig) {
3052   assert(sig > 0 && sig < NSIG, "vm signal out of expected range");




 831   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
 832     os::current_thread_id(), (uintx) kernel_thread_id);
 833 
 834   // If a thread has not deleted itself ("delete this") as part of its
 835   // termination sequence, we have to ensure thread-local-storage is
 836   // cleared before we actually terminate. No threads should ever be
 837   // deleted asynchronously with respect to their termination.
 838   if (Thread::current_or_null_safe() != NULL) {
 839     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
 840     thread->clear_thread_current();
 841   }
 842 
 843   return 0;
 844 }
 845 
 846 bool os::create_thread(Thread* thread, ThreadType thr_type,
 847                        size_t req_stack_size) {
 848 
 849   assert(thread->osthread() == NULL, "caller responsible");
 850 
 851   // Allocate the OSThread object.
 852   OSThread* osthread = new OSThread(NULL, NULL);
 853   if (osthread == NULL) {
 854     return false;
 855   }
 856 
 857   // Set the correct thread state.
 858   osthread->set_thread_type(thr_type);
 859 
 860   // Initial state is ALLOCATED but not INITIALIZED
 861   osthread->set_state(ALLOCATED);
 862 
 863   thread->set_osthread(osthread);
 864 
 865   // Init thread attributes.
 866   pthread_attr_t attr;
 867   pthread_attr_init(&attr);
 868   guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
 869 
 870   // Make sure we run in 1:1 kernel-user-thread mode.
 871   if (os::Aix::on_aix()) {
 872     guarantee(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0, "???");
 873     guarantee(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0, "???");
 874   }
 875 
 876   // Start in suspended state, and in os::thread_start, wake the thread up.
 877   guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???");
 878 
 879   // Calculate stack size if it's not specified by caller.
 880   size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
 881   pthread_attr_setstacksize(&attr, stack_size);
 882 
 883   // Configure libc guard page.
 884   pthread_attr_setguardsize(&attr, os::Aix::default_guard_size(thr_type));
 885 
 886   pthread_t tid;
 887   int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
 888 
 889   char buf[64];
 890   if (ret == 0) {
 891     log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
 892       (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 893   } else {
 894     log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
 895       ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
 896   }
 897 
 898   pthread_attr_destroy(&attr);
 899 
 900   if (ret != 0) {
 901     // Need to clean up stuff we've allocated so far.
 902     thread->set_osthread(NULL);
 903     delete osthread;
 904     return false;
 905   }
 906 
 907   // OSThread::thread_id is the pthread id.
 908   osthread->set_thread_id(tid);
 909 
 910   return true;
 911 }
 912 
 913 /////////////////////////////////////////////////////////////////////////////
 914 // attach existing thread
 915 
 916 // bootstrap the main thread
 917 bool os::create_main_thread(JavaThread* thread) {
 918   assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread");
 919   return create_attached_thread(thread);
 920 }
 921 


3016       (*hand)(sig);
3017     }
3018 
3019     // restore the signal mask
3020     pthread_sigmask(SIG_SETMASK, &oset, 0);
3021   }
3022   // Tell jvm's signal handler the signal is taken care of.
3023   return true;
3024 }
3025 
3026 bool os::Aix::chained_handler(int sig, siginfo_t* siginfo, void* context) {
3027   bool chained = false;
3028   // signal-chaining
3029   if (UseSignalChaining) {
3030     struct sigaction *actp = get_chained_signal_action(sig);
3031     if (actp != NULL) {
3032       chained = call_chained_handler(actp, sig, siginfo, context);
3033     }
3034   }
3035   return chained;
3036 }
3037 
3038 size_t os::Aix::default_guard_size(os::ThreadType thr_type) {
3039   // Creating guard page is very expensive. Java thread has HotSpot
3040   // guard pages, only enable glibc guard page for non-Java threads.
3041   // (Remember: compiler thread is a Java thread, too!)
3042   //
3043   // Aix can have different page sizes for stack (4K) and heap (64K).
3044   // As Hotspot knows only one page size, we assume the stack has
3045   // the same page size as the heap. Returning page_size() here can
3046   // cause 16 guard pages which we want to avoid.  Thus we return 4K
3047   // which will be rounded to the real page size by the OS.
3048   return ((thr_type == java_thread || thr_type == compiler_thread) ? 0 : 4 * K);
3049 }
3050 
3051 struct sigaction* os::Aix::get_preinstalled_handler(int sig) {
3052   if (sigismember(&sigs, sig)) {
3053     return &sigact[sig];
3054   }
3055   return NULL;
3056 }
3057 
3058 void os::Aix::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
3059   assert(sig > 0 && sig < NSIG, "vm signal out of expected range");
3060   sigact[sig] = oldAct;
3061   sigaddset(&sigs, sig);
3062 }
3063 
3064 // for diagnostic
3065 int sigflags[NSIG];
3066 
3067 int os::Aix::get_our_sigflags(int sig) {
3068   assert(sig > 0 && sig < NSIG, "vm signal out of expected range");


< prev index next >