# HG changeset patch # User stuefe # Date 1449023434 18000 # Node ID 7676bec2099715fe08bce6e0b19448424520e546 # Parent 77ef20312eb2179616180006243eccd87ba4c121 8143291: Remove redundant coding around os::exception_name Reviewed-by: dholmes, coleenp diff -r 77ef20312eb2 -r 7676bec20997 hotspot/src/os/aix/vm/jvm_aix.cpp --- a/hotspot/src/os/aix/vm/jvm_aix.cpp Tue Dec 01 21:08:00 2015 +0100 +++ b/hotspot/src/os/aix/vm/jvm_aix.cpp Tue Dec 01 21:30:34 2015 -0500 @@ -109,92 +109,3 @@ return JNI_TRUE; JVM_END -/* - All the defined signal names for Linux. - - NOTE that not all of these names are accepted by our Java implementation - - Via an existing claim by the VM, sigaction restrictions, or - the "rules of Unix" some of these names will be rejected at runtime. - For example the VM sets up to handle USR1, sigaction returns EINVAL for - STOP, and Linux simply doesn't allow catching of KILL. - - Here are the names currently accepted by a user of sun.misc.Signal with - 1.4.1 (ignoring potential interaction with use of chaining, etc): - - HUP, INT, TRAP, ABRT, IOT, BUS, USR2, PIPE, ALRM, TERM, STKFLT, - CLD, CHLD, CONT, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF, - WINCH, POLL, IO, PWR, SYS - -*/ - -struct siglabel { - const char *name; - int number; -}; - -struct siglabel siglabels[] = { - /* derived from /usr/include/bits/signum.h on RH7.2 */ - "HUP", SIGHUP, /* Hangup (POSIX). */ - "INT", SIGINT, /* Interrupt (ANSI). */ - "QUIT", SIGQUIT, /* Quit (POSIX). */ - "ILL", SIGILL, /* Illegal instruction (ANSI). */ - "TRAP", SIGTRAP, /* Trace trap (POSIX). */ - "ABRT", SIGABRT, /* Abort (ANSI). */ - "IOT", SIGIOT, /* IOT trap (4.2 BSD). */ - "BUS", SIGBUS, /* BUS error (4.2 BSD). */ - "FPE", SIGFPE, /* Floating-point exception (ANSI). */ - "KILL", SIGKILL, /* Kill, unblockable (POSIX). */ - "USR1", SIGUSR1, /* User-defined signal 1 (POSIX). */ - "SEGV", SIGSEGV, /* Segmentation violation (ANSI). */ - "USR2", SIGUSR2, /* User-defined signal 2 (POSIX). */ - "PIPE", SIGPIPE, /* Broken pipe (POSIX). */ - "ALRM", SIGALRM, /* Alarm clock (POSIX). */ - "TERM", SIGTERM, /* Termination (ANSI). */ -#ifdef SIGSTKFLT - "STKFLT", SIGSTKFLT, /* Stack fault. */ -#endif - "CLD", SIGCLD, /* Same as SIGCHLD (System V). */ - "CHLD", SIGCHLD, /* Child status has changed (POSIX). */ - "CONT", SIGCONT, /* Continue (POSIX). */ - "STOP", SIGSTOP, /* Stop, unblockable (POSIX). */ - "TSTP", SIGTSTP, /* Keyboard stop (POSIX). */ - "TTIN", SIGTTIN, /* Background read from tty (POSIX). */ - "TTOU", SIGTTOU, /* Background write to tty (POSIX). */ - "URG", SIGURG, /* Urgent condition on socket (4.2 BSD). */ - "XCPU", SIGXCPU, /* CPU limit exceeded (4.2 BSD). */ - "XFSZ", SIGXFSZ, /* File size limit exceeded (4.2 BSD). */ - "DANGER", SIGDANGER, /* System crash imminent; free up some page space (AIX). */ - "VTALRM", SIGVTALRM, /* Virtual alarm clock (4.2 BSD). */ - "PROF", SIGPROF, /* Profiling alarm clock (4.2 BSD). */ - "WINCH", SIGWINCH, /* Window size change (4.3 BSD, Sun). */ - "POLL", SIGPOLL, /* Pollable event occurred (System V). */ - "IO", SIGIO, /* I/O now possible (4.2 BSD). */ - "PWR", SIGPWR, /* Power failure restart (System V). */ -#ifdef SIGSYS - "SYS", SIGSYS /* Bad system call. Only on some Linuxen! */ -#endif - }; - -JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name)) - - /* find and return the named signal's number */ - - for(uint i=0; i 0) { - for (int idx = 0; info[idx].sig != -1; idx ++) { - if (info[idx].sig == sig) { - ret = info[idx].name; + for (int idx = 0; g_signal_info[idx].sig != -1; idx ++) { + if (g_signal_info[idx].sig == sig) { + ret = g_signal_info[idx].name; break; } } @@ -693,6 +698,25 @@ return out; } +int os::Posix::get_signal_number(const char* signal_name) { + char tmp[30]; + const char* s = signal_name; + if (s[0] != 'S' || s[1] != 'I' || s[2] != 'G') { + jio_snprintf(tmp, sizeof(tmp), "SIG%s", signal_name); + s = tmp; + } + for (int idx = 0; g_signal_info[idx].sig != -1; idx ++) { + if (strcmp(g_signal_info[idx].name, s) == 0) { + return g_signal_info[idx].sig; + } + } + return -1; +} + +int os::get_signal_number(const char* signal_name) { + return os::Posix::get_signal_number(signal_name); +} + // Returns true if signal number is valid. bool os::Posix::is_valid_signal(int sig) { // MacOS not really POSIX compliant: sigaddset does not return @@ -711,6 +735,21 @@ #endif } +// Returns: +// "invalid ()" for an invalid signal number +// "SIG" for a valid but unknown signal number +// signal name otherwise. +const char* os::exception_name(int sig, char* buf, size_t size) { + if (!os::Posix::is_valid_signal(sig)) { + jio_snprintf(buf, size, "invalid (%d)", sig); + } + const char* const name = os::Posix::get_signal_name(sig, buf, size); + if (strcmp(name, "UNKNOWN") == 0) { + jio_snprintf(buf, size, "SIG%d", sig); + } + return buf; +} + #define NUM_IMPORTANT_SIGS 32 // Returns one-line short description of a signal set in a user provided buffer. const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) { diff -r 77ef20312eb2 -r 7676bec20997 hotspot/src/os/posix/vm/os_posix.hpp --- a/hotspot/src/os/posix/vm/os_posix.hpp Tue Dec 01 21:08:00 2015 +0100 +++ b/hotspot/src/os/posix/vm/os_posix.hpp Tue Dec 01 21:30:34 2015 -0500 @@ -51,6 +51,12 @@ // Returned string is a constant. For unknown signals "UNKNOWN" is returned. static const char* get_signal_name(int sig, char* out, size_t outlen); + // Helper function, returns a signal number for a given signal name, e.g. 11 + // for "SIGSEGV". Name can be given with or without "SIG" prefix, so both + // "SEGV" or "SIGSEGV" work. Name must be uppercase. + // Returns -1 for an unknown signal name. + static int get_signal_number(const char* signal_name); + // Returns one-line short description of a signal set in a user provided buffer. static const char* describe_signal_set_short(const sigset_t* set, char* buffer, size_t size); diff -r 77ef20312eb2 -r 7676bec20997 hotspot/src/os/solaris/vm/jvm_solaris.cpp --- a/hotspot/src/os/solaris/vm/jvm_solaris.cpp Tue Dec 01 21:08:00 2015 +0100 +++ b/hotspot/src/os/solaris/vm/jvm_solaris.cpp Tue Dec 01 21:30:34 2015 -0500 @@ -106,40 +106,3 @@ return JNI_TRUE; JVM_END - -/* - All the defined signal names for Solaris are defined by str2sig(). - - NOTE that not all of these names are accepted by our Java implementation - - Via an existing claim by the VM, sigaction restrictions, or - the "rules of Unix" some of these names will be rejected at runtime. - For example the VM sets up to handle USR1, sigaction returns EINVAL for - CANCEL, and Solaris simply doesn't allow catching of KILL. - - Here are the names currently accepted by a user of sun.misc.Signal with - 1.4.1 (ignoring potential interaction with use of chaining, etc): - - HUP, INT, TRAP, IOT, ABRT, EMT, BUS, SYS, PIPE, ALRM, TERM, USR2, - CLD, CHLD, PWR, WINCH, URG, POLL, IO, TSTP, CONT, TTIN, TTOU, VTALRM, - PROF, XCPU, XFSZ, FREEZE, THAW, LOST -*/ - -JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name)) - - int sig; - - /* return the named signal's number */ - - if(str2sig(name, &sig)) - return -1; - else - return sig; - -JVM_END - - -//Reconciliation History -// 1.4 98/10/07 13:39:41 jvm_win32.cpp -// 1.6 99/06/22 16:39:00 jvm_win32.cpp -//End diff -r 77ef20312eb2 -r 7676bec20997 hotspot/src/os/solaris/vm/os_solaris.cpp --- a/hotspot/src/os/solaris/vm/os_solaris.cpp Tue Dec 01 21:08:00 2015 +0100 +++ b/hotspot/src/os/solaris/vm/os_solaris.cpp Tue Dec 01 21:30:34 2015 -0500 @@ -4144,32 +4144,6 @@ void report_error(const char* file_name, int line_no, const char* title, const char* format, ...); -const char * signames[] = { - "SIG0", - "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP", - "SIGABRT", "SIGEMT", "SIGFPE", "SIGKILL", "SIGBUS", - "SIGSEGV", "SIGSYS", "SIGPIPE", "SIGALRM", "SIGTERM", - "SIGUSR1", "SIGUSR2", "SIGCLD", "SIGPWR", "SIGWINCH", - "SIGURG", "SIGPOLL", "SIGSTOP", "SIGTSTP", "SIGCONT", - "SIGTTIN", "SIGTTOU", "SIGVTALRM", "SIGPROF", "SIGXCPU", - "SIGXFSZ", "SIGWAITING", "SIGLWP", "SIGFREEZE", "SIGTHAW", - "SIGCANCEL", "SIGLOST" -}; - -const char* os::exception_name(int exception_code, char* buf, size_t size) { - if (0 < exception_code && exception_code <= SIGRTMAX) { - // signal - if (exception_code < sizeof(signames)/sizeof(const char*)) { - jio_snprintf(buf, size, "%s", signames[exception_code]); - } else { - jio_snprintf(buf, size, "SIG%d", exception_code); - } - return buf; - } else { - return NULL; - } -} - // (Static) wrapper for getisax(2) call. os::Solaris::getisax_func_t os::Solaris::_getisax = 0; diff -r 77ef20312eb2 -r 7676bec20997 hotspot/src/os/windows/vm/jvm_windows.cpp --- a/hotspot/src/os/windows/vm/jvm_windows.cpp Tue Dec 01 21:08:00 2015 +0100 +++ b/hotspot/src/os/windows/vm/jvm_windows.cpp Tue Dec 01 21:30:34 2015 -0500 @@ -89,39 +89,3 @@ JVM_END -/* - All the defined signal names for Windows. - - NOTE that not all of these names are accepted by FindSignal! - - For various reasons some of these may be rejected at runtime. - - Here are the names currently accepted by a user of sun.misc.Signal with - 1.4.1 (ignoring potential interaction with use of chaining, etc): - - (LIST TBD) - -*/ -struct siglabel { - char *name; - int number; -}; - -struct siglabel siglabels[] = - /* derived from version 6.0 VC98/include/signal.h */ - {"ABRT", SIGABRT, /* abnormal termination triggered by abort cl */ - "FPE", SIGFPE, /* floating point exception */ - "SEGV", SIGSEGV, /* segment violation */ - "INT", SIGINT, /* interrupt */ - "TERM", SIGTERM, /* software term signal from kill */ - "BREAK", SIGBREAK, /* Ctrl-Break sequence */ - "ILL", SIGILL}; /* illegal instruction */ - -JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name)) - /* find and return the named signal's number */ - - for(int i=0;iis_attachable = AttachListener::is_attach_supported(); } JVM_END + +JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name)) + return os::get_signal_number(name); +JVM_END + diff -r 77ef20312eb2 -r 7676bec20997 hotspot/src/share/vm/runtime/os.hpp --- a/hotspot/src/share/vm/runtime/os.hpp Tue Dec 01 21:08:00 2015 +0100 +++ b/hotspot/src/share/vm/runtime/os.hpp Tue Dec 01 21:30:34 2015 -0500 @@ -642,6 +642,9 @@ // returns NULL if exception_code is not an OS exception/signal. static const char* exception_name(int exception_code, char* buf, size_t buflen); + // Returns the signal number (e.g. 11) for a given signal name (SIGSEGV). + static int get_signal_number(const char* signal_name); + // Returns native Java library, loads if necessary static void* native_java_library();