872 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
873
874 // JDK-8187028: It was observed that on some configurations (4K backed thread stacks)
875 // the real thread stack size may be smaller than the requested stack size, by as much as 64K.
876 // This very much looks like a pthread lib error. As a workaround, increase the stack size
877 // by 64K for small thread stacks (arbitrarily choosen to be < 4MB)
878 if (stack_size < 4096 * K) {
879 stack_size += 64 * K;
880 }
881
882 // On Aix, pthread_attr_setstacksize fails with huge values and leaves the
883 // thread size in attr unchanged. If this is the minimal stack size as set
884 // by pthread_attr_init this leads to crashes after thread creation. E.g. the
885 // guard pages might not fit on the tiny stack created.
886 int ret = pthread_attr_setstacksize(&attr, stack_size);
887 if (ret != 0) {
888 log_warning(os, thread)("The thread stack size specified is invalid: " SIZE_FORMAT "k",
889 stack_size / K);
890 }
891
892 // Configure libc guard page.
893 ret = pthread_attr_setguardsize(&attr, os::Aix::default_guard_size(thr_type));
894
895 pthread_t tid = 0;
896 if (ret == 0) {
897 ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
898 }
899
900 if (ret == 0) {
901 char buf[64];
902 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
903 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
904 } else {
905 char buf[64];
906 log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
907 ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
908 }
909
910 pthread_attr_destroy(&attr);
911
912 if (ret != 0) {
913 // Need to clean up stuff we've allocated so far.
3002
3003 // restore the signal mask
3004 pthread_sigmask(SIG_SETMASK, &oset, 0);
3005 }
3006 // Tell jvm's signal handler the signal is taken care of.
3007 return true;
3008 }
3009
3010 bool os::Aix::chained_handler(int sig, siginfo_t* siginfo, void* context) {
3011 bool chained = false;
3012 // signal-chaining
3013 if (UseSignalChaining) {
3014 struct sigaction *actp = get_chained_signal_action(sig);
3015 if (actp != NULL) {
3016 chained = call_chained_handler(actp, sig, siginfo, context);
3017 }
3018 }
3019 return chained;
3020 }
3021
3022 size_t os::Aix::default_guard_size(os::ThreadType thr_type) {
3023 // Creating guard page is very expensive. Java thread has HotSpot
3024 // guard pages, only enable glibc guard page for non-Java threads.
3025 // (Remember: compiler thread is a Java thread, too!)
3026 //
3027 // Aix can have different page sizes for stack (4K) and heap (64K).
3028 // As Hotspot knows only one page size, we assume the stack has
3029 // the same page size as the heap. Returning page_size() here can
3030 // cause 16 guard pages which we want to avoid. Thus we return 4K
3031 // which will be rounded to the real page size by the OS.
3032 return ((thr_type == java_thread || thr_type == compiler_thread) ? 0 : 4 * K);
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");
3053 return sigflags[sig];
3054 }
|
872 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
873
874 // JDK-8187028: It was observed that on some configurations (4K backed thread stacks)
875 // the real thread stack size may be smaller than the requested stack size, by as much as 64K.
876 // This very much looks like a pthread lib error. As a workaround, increase the stack size
877 // by 64K for small thread stacks (arbitrarily choosen to be < 4MB)
878 if (stack_size < 4096 * K) {
879 stack_size += 64 * K;
880 }
881
882 // On Aix, pthread_attr_setstacksize fails with huge values and leaves the
883 // thread size in attr unchanged. If this is the minimal stack size as set
884 // by pthread_attr_init this leads to crashes after thread creation. E.g. the
885 // guard pages might not fit on the tiny stack created.
886 int ret = pthread_attr_setstacksize(&attr, stack_size);
887 if (ret != 0) {
888 log_warning(os, thread)("The thread stack size specified is invalid: " SIZE_FORMAT "k",
889 stack_size / K);
890 }
891
892 // Save some cycles and a page by disabling OS guard pages where we have our own
893 // VM guard pages (in java threads). For other threads, keep system default guard
894 // pages in place.
895 if (thr_type == java_thread || thr_type == compiler_thread) {
896 ret = pthread_attr_setguardsize(&attr, 0);
897 }
898
899 pthread_t tid = 0;
900 if (ret == 0) {
901 ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
902 }
903
904 if (ret == 0) {
905 char buf[64];
906 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
907 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
908 } else {
909 char buf[64];
910 log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
911 ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
912 }
913
914 pthread_attr_destroy(&attr);
915
916 if (ret != 0) {
917 // Need to clean up stuff we've allocated so far.
3006
3007 // restore the signal mask
3008 pthread_sigmask(SIG_SETMASK, &oset, 0);
3009 }
3010 // Tell jvm's signal handler the signal is taken care of.
3011 return true;
3012 }
3013
3014 bool os::Aix::chained_handler(int sig, siginfo_t* siginfo, void* context) {
3015 bool chained = false;
3016 // signal-chaining
3017 if (UseSignalChaining) {
3018 struct sigaction *actp = get_chained_signal_action(sig);
3019 if (actp != NULL) {
3020 chained = call_chained_handler(actp, sig, siginfo, context);
3021 }
3022 }
3023 return chained;
3024 }
3025
3026 struct sigaction* os::Aix::get_preinstalled_handler(int sig) {
3027 if (sigismember(&sigs, sig)) {
3028 return &sigact[sig];
3029 }
3030 return NULL;
3031 }
3032
3033 void os::Aix::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
3034 assert(sig > 0 && sig < NSIG, "vm signal out of expected range");
3035 sigact[sig] = oldAct;
3036 sigaddset(&sigs, sig);
3037 }
3038
3039 // for diagnostic
3040 int sigflags[NSIG];
3041
3042 int os::Aix::get_our_sigflags(int sig) {
3043 assert(sig > 0 && sig < NSIG, "vm signal out of expected range");
3044 return sigflags[sig];
3045 }
|