< prev index next >

src/os/aix/vm/os_aix.cpp

Print this page
rev 12334 : 8169373: Work around linux NPTL stack guard error.
Summary: Also skip OS guard page for compiler thread, merge similar code on linux platforms, and streamline OS guard page handling on linuxs390, linuxppc, aixppc.


 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);
 910 
 911   return true;
 912 }
 913 
 914 /////////////////////////////////////////////////////////////////////////////
 915 // attach existing thread
 916 
 917 // bootstrap the main thread
 918 bool os::create_main_thread(JavaThread* thread) {
 919   assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread");
 920   return create_attached_thread(thread);
 921 }
 922 


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












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




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


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


< prev index next >