--- old/src/hotspot/os/aix/os_aix.cpp 2019-02-28 17:45:57.094620581 +0800 +++ new/src/hotspot/os/aix/os_aix.cpp 2019-02-28 17:45:56.699104739 +0800 @@ -2996,8 +2996,6 @@ bool os::Aix::signal_handlers_are_installed = false; // For signal-chaining -struct sigaction sigact[NSIG]; -sigset_t sigs; bool os::Aix::libjsig_is_loaded = false; typedef struct sigaction *(*get_signal_t)(int); get_signal_t os::Aix::get_signal_action = NULL; @@ -3011,7 +3009,7 @@ } if (actp == NULL) { // Retrieve the preinstalled signal handler from jvm - actp = get_preinstalled_handler(sig); + actp = os::Posix::get_preinstalled_handler(sig); } return actp; @@ -3074,19 +3072,6 @@ return chained; } -struct sigaction* os::Aix::get_preinstalled_handler(int sig) { - if (sigismember(&sigs, sig)) { - return &sigact[sig]; - } - return NULL; -} - -void os::Aix::save_preinstalled_handler(int sig, struct sigaction& oldAct) { - assert(sig > 0 && sig < NSIG, "vm signal out of expected range"); - sigact[sig] = oldAct; - sigaddset(&sigs, sig); -} - // for diagnostic int sigflags[NSIG]; @@ -3118,7 +3103,7 @@ return; } else if (UseSignalChaining) { // save the old handler in jvm - save_preinstalled_handler(sig, oldAct); + os::Posix::save_preinstalled_handler(sig, oldAct); // libjsig also interposes the sigaction() call below and saves the // old sigaction on it own. } else { @@ -3174,7 +3159,7 @@ (*begin_signal_setting)(); } - ::sigemptyset(&sigs); + os::Posix::init_sigs(); set_signal_handler(SIGSEGV, true); set_signal_handler(SIGPIPE, true); set_signal_handler(SIGBUS, true); --- old/src/hotspot/os/aix/os_aix.hpp 2019-02-28 17:45:58.465220030 +0800 +++ new/src/hotspot/os/aix/os_aix.hpp 2019-02-28 17:45:58.061872192 +0800 @@ -37,8 +37,6 @@ static bool libjsig_is_loaded; // libjsig that interposes sigaction(), // __sigaction(), signal() is loaded static struct sigaction *(*get_signal_action)(int); - static struct sigaction *get_preinstalled_handler(int); - static void save_preinstalled_handler(int, struct sigaction&); static void check_signal_handler(int sig); --- old/src/hotspot/os/bsd/os_bsd.cpp 2019-02-28 17:45:59.655683552 +0800 +++ new/src/hotspot/os/bsd/os_bsd.cpp 2019-02-28 17:45:59.264083709 +0800 @@ -2658,11 +2658,6 @@ bool os::Bsd::signal_handlers_are_installed = false; // For signal-chaining -struct sigaction sigact[NSIG]; -uint32_t sigs = 0; -#if (32 < NSIG-1) -#error "Not all signals can be encoded in sigs. Adapt its type!" -#endif bool os::Bsd::libjsig_is_loaded = false; typedef struct sigaction *(*get_signal_t)(int); get_signal_t os::Bsd::get_signal_action = NULL; @@ -2676,7 +2671,7 @@ } if (actp == NULL) { // Retrieve the preinstalled signal handler from jvm - actp = get_preinstalled_handler(sig); + actp = os::Posix::get_preinstalled_handler(sig); } return actp; @@ -2739,19 +2734,6 @@ return chained; } -struct sigaction* os::Bsd::get_preinstalled_handler(int sig) { - if ((((uint32_t)1 << (sig-1)) & sigs) != 0) { - return &sigact[sig]; - } - return NULL; -} - -void os::Bsd::save_preinstalled_handler(int sig, struct sigaction& oldAct) { - assert(sig > 0 && sig < NSIG, "vm signal out of expected range"); - sigact[sig] = oldAct; - sigs |= (uint32_t)1 << (sig-1); -} - // for diagnostic int sigflags[NSIG]; @@ -2783,7 +2765,7 @@ return; } else if (UseSignalChaining) { // save the old handler in jvm - save_preinstalled_handler(sig, oldAct); + os::Posix::save_preinstalled_handler(sig, oldAct); // libjsig also interposes the sigaction() call below and saves the // old sigaction on it own. } else { @@ -2853,6 +2835,7 @@ (*begin_signal_setting)(); } + os::Posix::init_sigs(); set_signal_handler(SIGSEGV, true); set_signal_handler(SIGPIPE, true); set_signal_handler(SIGBUS, true); --- old/src/hotspot/os/bsd/os_bsd.hpp 2019-02-28 17:46:00.983207018 +0800 +++ new/src/hotspot/os/bsd/os_bsd.hpp 2019-02-28 17:46:00.587691177 +0800 @@ -37,8 +37,6 @@ static bool libjsig_is_loaded; // libjsig that interposes sigaction(), // __sigaction(), signal() is loaded static struct sigaction *(*get_signal_action)(int); - static struct sigaction *get_preinstalled_handler(int); - static void save_preinstalled_handler(int, struct sigaction&); static void check_signal_handler(int sig); --- old/src/hotspot/os/linux/os_linux.cpp 2019-02-28 17:46:02.173670540 +0800 +++ new/src/hotspot/os/linux/os_linux.cpp 2019-02-28 17:46:01.774238701 +0800 @@ -4444,11 +4444,6 @@ bool os::Linux::signal_handlers_are_installed = false; // For signal-chaining -struct sigaction sigact[NSIG]; -uint64_t sigs = 0; -#if (64 < NSIG-1) -#error "Not all signals can be encoded in sigs. Adapt its type!" -#endif bool os::Linux::libjsig_is_loaded = false; typedef struct sigaction *(*get_signal_t)(int); get_signal_t os::Linux::get_signal_action = NULL; @@ -4462,7 +4457,7 @@ } if (actp == NULL) { // Retrieve the preinstalled signal handler from jvm - actp = get_preinstalled_handler(sig); + actp = os::Posix::get_preinstalled_handler(sig); } return actp; @@ -4526,19 +4521,6 @@ return chained; } -struct sigaction* os::Linux::get_preinstalled_handler(int sig) { - if ((((uint64_t)1 << (sig-1)) & sigs) != 0) { - return &sigact[sig]; - } - return NULL; -} - -void os::Linux::save_preinstalled_handler(int sig, struct sigaction& oldAct) { - assert(sig > 0 && sig < NSIG, "vm signal out of expected range"); - sigact[sig] = oldAct; - sigs |= (uint64_t)1 << (sig-1); -} - // for diagnostic int sigflags[NSIG]; @@ -4570,7 +4552,7 @@ return; } else if (UseSignalChaining) { // save the old handler in jvm - save_preinstalled_handler(sig, oldAct); + os::Posix::save_preinstalled_handler(sig, oldAct); // libjsig also interposes the sigaction() call below and saves the // old sigaction on it own. } else { @@ -4627,6 +4609,7 @@ (*begin_signal_setting)(); } + os::Posix::init_sigs(); set_signal_handler(SIGSEGV, true); set_signal_handler(SIGPIPE, true); set_signal_handler(SIGBUS, true); --- old/src/hotspot/os/linux/os_linux.hpp 2019-02-28 17:46:03.587345972 +0800 +++ new/src/hotspot/os/linux/os_linux.hpp 2019-02-28 17:46:03.187914133 +0800 @@ -38,8 +38,6 @@ static bool libjsig_is_loaded; // libjsig that interposes sigaction(), // __sigaction(), signal() is loaded static struct sigaction *(*get_signal_action)(int); - static struct sigaction *get_preinstalled_handler(int); - static void save_preinstalled_handler(int, struct sigaction&); static void check_signal_handler(int sig); --- old/src/hotspot/os/posix/os_posix.cpp 2019-02-28 17:46:04.785641491 +0800 +++ new/src/hotspot/os/posix/os_posix.cpp 2019-02-28 17:46:04.390125650 +0800 @@ -1906,6 +1906,59 @@ true /* use real-time clock */); } +#ifndef SOLARIS +sigset_t sigs; +struct sigaction sigact[NSIG]; +#else +static int *sigs = NULL; +static struct sigaction *sigact = NULL; +static int Maxsignum = 0; +#endif + +struct sigaction* os::Posix::get_preinstalled_handler(int sig) { +#ifndef SOLARIS + if (sigismember(&sigs, sig)) { + return &sigact[sig]; + } +#else + assert((sigact != (struct sigaction *)NULL) && + (sigs != (int *)NULL), "signals not yet initialized"); + if (sigs[sig] != 0) { + return &sigact[sig]; + } +#endif + return NULL; +} + +void os::Posix::save_preinstalled_handler(int sig, struct sigaction& oldAct) { +#ifndef SOLARIS + assert(sig > 0 && sig < NSIG, "vm signal out of expected range"); + sigact[sig] = oldAct; + sigaddset(&sigs, sig); +#else + assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range"); + assert((sigact != (struct sigaction *)NULL) && + (sigs != (int *)NULL), "signals not yet initialized"); + sigact[sig] = oldAct; + sigs[sig] = 1; +#endif +} + +void os::Posix::init_sigs() { +#ifndef SOLARIS + sigemptyset(&sigs); +#else + Maxsignum = SIGRTMAX; + if (UseSignalChaining) { + sigact = (struct sigaction *)malloc(sizeof(struct sigaction) + * (Maxsignum + 1), mtInternal); + memset(sigact, 0, (sizeof(struct sigaction) * (Maxsignum + 1))); + sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal); + memset(sigs, 0, (sizeof(int) * (Maxsignum + 1))); + } +#endif +} + // Shared pthread_mutex/cond based PlatformEvent implementation. // Not currently usable by Solaris. --- old/src/hotspot/os/posix/os_posix.hpp 2019-02-28 17:46:06.058340980 +0800 +++ new/src/hotspot/os/posix/os_posix.hpp 2019-02-28 17:46:05.670657135 +0800 @@ -117,6 +117,10 @@ // effective gid, or if given uid is root. static bool matches_effective_uid_and_gid_or_root(uid_t uid, gid_t gid); + static struct sigaction *get_preinstalled_handler(int); + static void save_preinstalled_handler(int, struct sigaction&); + static void init_sigs(); + static void print_umask(outputStream* st, mode_t umsk); static void print_user_info(outputStream* st); --- old/src/hotspot/os/solaris/os_solaris.cpp 2019-02-28 17:46:07.252720500 +0800 +++ new/src/hotspot/os/solaris/os_solaris.cpp 2019-02-28 17:46:06.857204659 +0800 @@ -2040,8 +2040,6 @@ // a counter for each possible signal value static int Sigexit = 0; static jint *pending_signals = NULL; -static int *preinstalled_sigs = NULL; -static struct sigaction *chainedsigactions = NULL; static Semaphore* sig_sem = NULL; int os::sigexitnum_pd() { @@ -2061,13 +2059,7 @@ pending_signals = (jint *)os::malloc(sizeof(jint) * (Sigexit+1), mtInternal); memset(pending_signals, 0, (sizeof(jint) * (Sigexit+1))); - if (UseSignalChaining) { - chainedsigactions = (struct sigaction *)malloc(sizeof(struct sigaction) - * (Maxsignum + 1), mtInternal); - memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1))); - preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal); - memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1))); - } + os::Posix::init_sigs(); ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1), mtInternal); memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1)); } @@ -3605,7 +3597,7 @@ } if (actp == NULL) { // Retrieve the preinstalled signal handler from jvm - actp = get_preinstalled_handler(sig); + actp = os::Posix::get_preinstalled_handler(sig); } return actp; @@ -3668,24 +3660,6 @@ return chained; } -struct sigaction* os::Solaris::get_preinstalled_handler(int sig) { - assert((chainedsigactions != (struct sigaction *)NULL) && - (preinstalled_sigs != (int *)NULL), "signals not yet initialized"); - if (preinstalled_sigs[sig] != 0) { - return &chainedsigactions[sig]; - } - return NULL; -} - -void os::Solaris::save_preinstalled_handler(int sig, - struct sigaction& oldAct) { - assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range"); - assert((chainedsigactions != (struct sigaction *)NULL) && - (preinstalled_sigs != (int *)NULL), "signals not yet initialized"); - chainedsigactions[sig] = oldAct; - preinstalled_sigs[sig] = 1; -} - void os::Solaris::set_signal_handler(int sig, bool set_installed, bool oktochain) { // Check for overwrite. @@ -3703,7 +3677,7 @@ } else if (UseSignalChaining) { if (oktochain) { // save the old handler in jvm - save_preinstalled_handler(sig, oldAct); + os::Posix::save_preinstalled_handler(sig, oldAct); } else { vm_exit_during_initialization("Signal chaining not allowed for VM interrupt signal."); } @@ -3871,7 +3845,7 @@ // Tell libjsig jvm is setting signal handlers (*begin_signal_setting)(); } - + set_signal_handler(SIGSEGV, true, true); set_signal_handler(SIGPIPE, true, true); set_signal_handler(SIGXFSZ, true, true); --- old/src/hotspot/os/solaris/os_solaris.hpp 2019-02-28 17:46:08.638983943 +0800 +++ new/src/hotspot/os/solaris/os_solaris.hpp 2019-02-28 17:46:08.247384100 +0800 @@ -105,9 +105,7 @@ static void try_enable_extended_io(); static struct sigaction *(*get_signal_action)(int); - static struct sigaction *get_preinstalled_handler(int); static int (*get_libjsig_version)(); - static void save_preinstalled_handler(int, struct sigaction&); static void check_signal_handler(int sig); typedef int (*pthread_setname_np_func_t)(pthread_t, const char*);