< prev index next >

src/hotspot/os/solaris/os_solaris.cpp

Print this page




1854 }
1855 
1856 
1857 static const char* get_signal_handler_name(address handler,
1858                                            char* buf, int buflen) {
1859   int offset;
1860   bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
1861   if (found) {
1862     // skip directory names
1863     const char *p1, *p2;
1864     p1 = buf;
1865     size_t len = strlen(os::file_separator());
1866     while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
1867     jio_snprintf(buf, buflen, "%s+0x%x", p1, offset);
1868   } else {
1869     jio_snprintf(buf, buflen, PTR_FORMAT, handler);
1870   }
1871   return buf;
1872 }
1873 


1874 static void print_signal_handler(outputStream* st, int sig,
1875                                  char* buf, size_t buflen) {
1876   struct sigaction sa;
1877 
1878   sigaction(sig, NULL, &sa);
1879 
1880   st->print("%s: ", os::exception_name(sig, buf, buflen));
1881 
1882   address handler = (sa.sa_flags & SA_SIGINFO)
1883                   ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
1884                   : CAST_FROM_FN_PTR(address, sa.sa_handler);
1885 
1886   if (handler == CAST_FROM_FN_PTR(address, SIG_DFL)) {
1887     st->print("SIG_DFL");
1888   } else if (handler == CAST_FROM_FN_PTR(address, SIG_IGN)) {
1889     st->print("SIG_IGN");
1890   } else {
1891     st->print("[%s]", get_signal_handler_name(handler, buf, buflen));
1892   }
1893 


2113   Sigexit = Maxsignum+1;
2114   assert(Maxsignum >0, "Unable to obtain max signal number");
2115 
2116   // Initialize signal structures
2117   // pending_signals has one int per signal
2118   // The additional signal is for SIGEXIT - exit signal to signal_thread
2119   pending_signals = (jint *)os::malloc(sizeof(jint) * (Sigexit+1), mtInternal);
2120   memset(pending_signals, 0, (sizeof(jint) * (Sigexit+1)));
2121 
2122   if (UseSignalChaining) {
2123     chainedsigactions = (struct sigaction *)malloc(sizeof(struct sigaction)
2124                                                    * (Maxsignum + 1), mtInternal);
2125     memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1)));
2126     preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
2127     memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1)));
2128   }
2129   ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
2130   memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1));
2131 }
2132 
2133 void os::signal_init_pd() {
2134   // Initialize signal semaphore
2135   sig_sem = new Semaphore();
2136 }
2137 
2138 void os::signal_notify(int sig) {
2139   if (sig_sem != NULL) {
2140     Atomic::inc(&pending_signals[sig]);
2141     sig_sem->signal();
2142   } else {
2143     // Signal thread is not created with ReduceSignalUsage and signal_init_pd
2144     // initialization isn't called.
2145     assert(ReduceSignalUsage, "signal semaphore should be created");
2146   }
2147 }
2148 
2149 static int check_pending_signals() {
2150   int ret;
2151   while (true) {
2152     for (int i = 0; i < Sigexit + 1; i++) {
2153       jint n = pending_signals[i];
2154       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
2155         return i;
2156       }
2157     }
2158     JavaThread *thread = JavaThread::current();
2159     ThreadBlockInVM tbivm(thread);
2160 
2161     bool threadIsSuspended;
2162     do {
2163       thread->set_suspend_equivalent();


3666 //
3667 // This routine may recognize any of the following kinds of signals:
3668 // SIGBUS, SIGSEGV, SIGILL, SIGFPE, BREAK_SIGNAL, SIGPIPE, SIGXFSZ,
3669 // ASYNC_SIGNAL.
3670 // It should be consulted by handlers for any of those signals.
3671 //
3672 // The caller of this routine must pass in the three arguments supplied
3673 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
3674 // field of the structure passed to sigaction().  This routine assumes that
3675 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
3676 //
3677 // Note that the VM will print warnings if it detects conflicting signal
3678 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
3679 //
3680 extern "C" JNIEXPORT int JVM_handle_solaris_signal(int signo,
3681                                                    siginfo_t* siginfo,
3682                                                    void* ucontext,
3683                                                    int abort_if_unrecognized);
3684 
3685 
3686 void signalHandler(int sig, siginfo_t* info, void* ucVoid) {
3687   int orig_errno = errno;  // Preserve errno value over signal handler.
3688   JVM_handle_solaris_signal(sig, info, ucVoid, true);
3689   errno = orig_errno;
3690 }
3691 
3692 // This boolean allows users to forward their own non-matching signals
3693 // to JVM_handle_solaris_signal, harmlessly.
3694 bool os::Solaris::signal_handlers_are_installed = false;
3695 
3696 // For signal-chaining
3697 bool os::Solaris::libjsig_is_loaded = false;
3698 typedef struct sigaction *(*get_signal_t)(int);
3699 get_signal_t os::Solaris::get_signal_action = NULL;
3700 
3701 struct sigaction* os::Solaris::get_chained_signal_action(int sig) {
3702   struct sigaction *actp = NULL;
3703 
3704   if ((libjsig_is_loaded)  && (sig <= Maxsignum)) {
3705     // Retrieve the old signal handler from libjsig
3706     actp = (*get_signal_action)(sig);


4232     if (!Solaris::liblgrp_init()) {
4233       UseNUMA = false;
4234     } else {
4235       size_t lgrp_limit = os::numa_get_groups_num();
4236       int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit, mtInternal);
4237       size_t lgrp_num = os::numa_get_leaf_groups(lgrp_ids, lgrp_limit);
4238       FREE_C_HEAP_ARRAY(int, lgrp_ids);
4239       if (lgrp_num < 2) {
4240         // There's only one locality group, disable NUMA.
4241         UseNUMA = false;
4242       }
4243     }
4244     if (!UseNUMA && ForceNUMA) {
4245       UseNUMA = true;
4246     }
4247   }
4248 
4249   Solaris::signal_sets_init();
4250   Solaris::init_signal_mem();
4251   Solaris::install_signal_handlers();




4252 
4253   // initialize synchronization primitives to use either thread or
4254   // lwp synchronization (controlled by UseLWPSynchronization)
4255   Solaris::synchronization_init();
4256 
4257   if (MaxFDLimit) {
4258     // set the number of file descriptors to max. print out error
4259     // if getrlimit/setrlimit fails but continue regardless.
4260     struct rlimit nbr_files;
4261     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
4262     if (status != 0) {
4263       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
4264     } else {
4265       nbr_files.rlim_cur = nbr_files.rlim_max;
4266       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
4267       if (status != 0) {
4268         log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
4269       }
4270     }
4271   }




1854 }
1855 
1856 
1857 static const char* get_signal_handler_name(address handler,
1858                                            char* buf, int buflen) {
1859   int offset;
1860   bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
1861   if (found) {
1862     // skip directory names
1863     const char *p1, *p2;
1864     p1 = buf;
1865     size_t len = strlen(os::file_separator());
1866     while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
1867     jio_snprintf(buf, buflen, "%s+0x%x", p1, offset);
1868   } else {
1869     jio_snprintf(buf, buflen, PTR_FORMAT, handler);
1870   }
1871   return buf;
1872 }
1873 
1874 void signalHandler(int sig, siginfo_t* info, void* ucVoid);
1875 
1876 static void print_signal_handler(outputStream* st, int sig,
1877                                  char* buf, size_t buflen) {
1878   struct sigaction sa;
1879 
1880   sigaction(sig, NULL, &sa);
1881 
1882   st->print("%s: ", os::exception_name(sig, buf, buflen));
1883 
1884   address handler = (sa.sa_flags & SA_SIGINFO)
1885                   ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
1886                   : CAST_FROM_FN_PTR(address, sa.sa_handler);
1887 
1888   if (handler == CAST_FROM_FN_PTR(address, SIG_DFL)) {
1889     st->print("SIG_DFL");
1890   } else if (handler == CAST_FROM_FN_PTR(address, SIG_IGN)) {
1891     st->print("SIG_IGN");
1892   } else {
1893     st->print("[%s]", get_signal_handler_name(handler, buf, buflen));
1894   }
1895 


2115   Sigexit = Maxsignum+1;
2116   assert(Maxsignum >0, "Unable to obtain max signal number");
2117 
2118   // Initialize signal structures
2119   // pending_signals has one int per signal
2120   // The additional signal is for SIGEXIT - exit signal to signal_thread
2121   pending_signals = (jint *)os::malloc(sizeof(jint) * (Sigexit+1), mtInternal);
2122   memset(pending_signals, 0, (sizeof(jint) * (Sigexit+1)));
2123 
2124   if (UseSignalChaining) {
2125     chainedsigactions = (struct sigaction *)malloc(sizeof(struct sigaction)
2126                                                    * (Maxsignum + 1), mtInternal);
2127     memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1)));
2128     preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
2129     memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1)));
2130   }
2131   ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
2132   memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1));
2133 }
2134 
2135 static void jdk_misc_signal_init() {
2136   // Initialize signal semaphore
2137   sig_sem = new Semaphore();
2138 }
2139 
2140 void os::signal_notify(int sig) {
2141   if (sig_sem != NULL) {
2142     Atomic::inc(&pending_signals[sig]);
2143     sig_sem->signal();
2144   } else {
2145     // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
2146     // initialization isn't called.
2147     assert(ReduceSignalUsage, "signal semaphore should be created");
2148   }
2149 }
2150 
2151 static int check_pending_signals() {
2152   int ret;
2153   while (true) {
2154     for (int i = 0; i < Sigexit + 1; i++) {
2155       jint n = pending_signals[i];
2156       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
2157         return i;
2158       }
2159     }
2160     JavaThread *thread = JavaThread::current();
2161     ThreadBlockInVM tbivm(thread);
2162 
2163     bool threadIsSuspended;
2164     do {
2165       thread->set_suspend_equivalent();


3668 //
3669 // This routine may recognize any of the following kinds of signals:
3670 // SIGBUS, SIGSEGV, SIGILL, SIGFPE, BREAK_SIGNAL, SIGPIPE, SIGXFSZ,
3671 // ASYNC_SIGNAL.
3672 // It should be consulted by handlers for any of those signals.
3673 //
3674 // The caller of this routine must pass in the three arguments supplied
3675 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
3676 // field of the structure passed to sigaction().  This routine assumes that
3677 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
3678 //
3679 // Note that the VM will print warnings if it detects conflicting signal
3680 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
3681 //
3682 extern "C" JNIEXPORT int JVM_handle_solaris_signal(int signo,
3683                                                    siginfo_t* siginfo,
3684                                                    void* ucontext,
3685                                                    int abort_if_unrecognized);
3686 
3687 
3688 static void signalHandler(int sig, siginfo_t* info, void* ucVoid) {
3689   int orig_errno = errno;  // Preserve errno value over signal handler.
3690   JVM_handle_solaris_signal(sig, info, ucVoid, true);
3691   errno = orig_errno;
3692 }
3693 
3694 // This boolean allows users to forward their own non-matching signals
3695 // to JVM_handle_solaris_signal, harmlessly.
3696 bool os::Solaris::signal_handlers_are_installed = false;
3697 
3698 // For signal-chaining
3699 bool os::Solaris::libjsig_is_loaded = false;
3700 typedef struct sigaction *(*get_signal_t)(int);
3701 get_signal_t os::Solaris::get_signal_action = NULL;
3702 
3703 struct sigaction* os::Solaris::get_chained_signal_action(int sig) {
3704   struct sigaction *actp = NULL;
3705 
3706   if ((libjsig_is_loaded)  && (sig <= Maxsignum)) {
3707     // Retrieve the old signal handler from libjsig
3708     actp = (*get_signal_action)(sig);


4234     if (!Solaris::liblgrp_init()) {
4235       UseNUMA = false;
4236     } else {
4237       size_t lgrp_limit = os::numa_get_groups_num();
4238       int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit, mtInternal);
4239       size_t lgrp_num = os::numa_get_leaf_groups(lgrp_ids, lgrp_limit);
4240       FREE_C_HEAP_ARRAY(int, lgrp_ids);
4241       if (lgrp_num < 2) {
4242         // There's only one locality group, disable NUMA.
4243         UseNUMA = false;
4244       }
4245     }
4246     if (!UseNUMA && ForceNUMA) {
4247       UseNUMA = true;
4248     }
4249   }
4250 
4251   Solaris::signal_sets_init();
4252   Solaris::init_signal_mem();
4253   Solaris::install_signal_handlers();
4254   // Initialize data for jdk.internal.misc.Signal
4255   if (!ReduceSignalUsage) {
4256     jdk_misc_signal_init();
4257   }
4258 
4259   // initialize synchronization primitives to use either thread or
4260   // lwp synchronization (controlled by UseLWPSynchronization)
4261   Solaris::synchronization_init();
4262 
4263   if (MaxFDLimit) {
4264     // set the number of file descriptors to max. print out error
4265     // if getrlimit/setrlimit fails but continue regardless.
4266     struct rlimit nbr_files;
4267     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
4268     if (status != 0) {
4269       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
4270     } else {
4271       nbr_files.rlim_cur = nbr_files.rlim_max;
4272       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
4273       if (status != 0) {
4274         log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
4275       }
4276     }
4277   }


< prev index next >