src/os/solaris/vm/jvm_solaris.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 2314
f95d63e2154a
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "prims/jvm.h"
aoqi@0 27 #include "runtime/interfaceSupport.hpp"
aoqi@0 28 #include "runtime/osThread.hpp"
aoqi@0 29
aoqi@0 30 #include <signal.h>
aoqi@0 31
aoqi@0 32 // sun.misc.Signal ///////////////////////////////////////////////////////////
aoqi@0 33 // Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/23
aoqi@0 34 /*
aoqi@0 35 * This function is included primarily as a debugging aid. If Java is
aoqi@0 36 * running in a console window, then pressing <CTRL-\\> will cause
aoqi@0 37 * the current state of all active threads and monitors to be written
aoqi@0 38 * to the console window.
aoqi@0 39 */
aoqi@0 40
aoqi@0 41 JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))
aoqi@0 42 // Copied from classic vm
aoqi@0 43 // signals_md.c 1.4 98/08/23
aoqi@0 44 void* newHandler = handler == (void *)2
aoqi@0 45 ? os::user_handler()
aoqi@0 46 : handler;
aoqi@0 47 switch (sig) {
aoqi@0 48 /* The following are already used by the VM. */
aoqi@0 49 case SIGFPE:
aoqi@0 50 case SIGILL:
aoqi@0 51 case SIGSEGV:
aoqi@0 52
aoqi@0 53 /* The following signal is used by the VM to dump thread stacks unless
aoqi@0 54 ReduceSignalUsage is set, in which case the user is allowed to set
aoqi@0 55 his own _native_ handler for this signal; thus, in either case,
aoqi@0 56 we do not allow JVM_RegisterSignal to change the handler. */
aoqi@0 57 case BREAK_SIGNAL:
aoqi@0 58 return (void *)-1;
aoqi@0 59
aoqi@0 60 /* The following signals are used for Shutdown Hooks support. However, if
aoqi@0 61 ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via
aoqi@0 62 System.exit(), Java is not allowed to use these signals, and the the
aoqi@0 63 user is allowed to set his own _native_ handler for these signals and
aoqi@0 64 invoke System.exit() as needed. Terminator.setup() is avoiding
aoqi@0 65 registration of these signals when -Xrs is present.
aoqi@0 66 - If the HUP signal is ignored (from the nohup) command, then Java
aoqi@0 67 is not allowed to use this signal.
aoqi@0 68 */
aoqi@0 69 case SHUTDOWN1_SIGNAL:
aoqi@0 70 case SHUTDOWN2_SIGNAL:
aoqi@0 71 case SHUTDOWN3_SIGNAL:
aoqi@0 72 if (ReduceSignalUsage) return (void*)-1;
aoqi@0 73 if (os::Solaris::is_sig_ignored(sig)) return (void*)1;
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 /* Check parameterized signals. Don't allow sharing of our interrupt signal */
aoqi@0 77 if (sig == os::Solaris::SIGinterrupt()) {
aoqi@0 78 return (void *)-1;
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 void* oldHandler = os::signal(sig, newHandler);
aoqi@0 82 if (oldHandler == os::user_handler()) {
aoqi@0 83 return (void *)2;
aoqi@0 84 } else {
aoqi@0 85 return oldHandler;
aoqi@0 86 }
aoqi@0 87 JVM_END
aoqi@0 88
aoqi@0 89
aoqi@0 90 JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))
aoqi@0 91 if (ReduceSignalUsage) {
aoqi@0 92 // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL,
aoqi@0 93 // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since
aoqi@0 94 // no handler for them is actually registered in JVM or via
aoqi@0 95 // JVM_RegisterSignal.
aoqi@0 96 if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
aoqi@0 97 sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) {
aoqi@0 98 return JNI_FALSE;
aoqi@0 99 }
aoqi@0 100 }
aoqi@0 101 else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
aoqi@0 102 sig == SHUTDOWN3_SIGNAL) && os::Solaris::is_sig_ignored(sig)) {
aoqi@0 103 // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL
aoqi@0 104 // is ignored, since no handler for them is actually registered in JVM
aoqi@0 105 // or via JVM_RegisterSignal.
aoqi@0 106 // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL
aoqi@0 107 return JNI_FALSE;
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 os::signal_raise(sig);
aoqi@0 111 return JNI_TRUE;
aoqi@0 112 JVM_END
aoqi@0 113
aoqi@0 114
aoqi@0 115 /*
aoqi@0 116 All the defined signal names for Solaris are defined by str2sig().
aoqi@0 117
aoqi@0 118 NOTE that not all of these names are accepted by our Java implementation
aoqi@0 119
aoqi@0 120 Via an existing claim by the VM, sigaction restrictions, or
aoqi@0 121 the "rules of Unix" some of these names will be rejected at runtime.
aoqi@0 122 For example the VM sets up to handle USR1, sigaction returns EINVAL for
aoqi@0 123 CANCEL, and Solaris simply doesn't allow catching of KILL.
aoqi@0 124
aoqi@0 125 Here are the names currently accepted by a user of sun.misc.Signal with
aoqi@0 126 1.4.1 (ignoring potential interaction with use of chaining, etc):
aoqi@0 127
aoqi@0 128 HUP, INT, TRAP, IOT, ABRT, EMT, BUS, SYS, PIPE, ALRM, TERM, USR2,
aoqi@0 129 CLD, CHLD, PWR, WINCH, URG, POLL, IO, TSTP, CONT, TTIN, TTOU, VTALRM,
aoqi@0 130 PROF, XCPU, XFSZ, FREEZE, THAW, LOST
aoqi@0 131 */
aoqi@0 132
aoqi@0 133 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
aoqi@0 134
aoqi@0 135 int sig;
aoqi@0 136
aoqi@0 137 /* return the named signal's number */
aoqi@0 138
aoqi@0 139 if(str2sig(name, &sig))
aoqi@0 140 return -1;
aoqi@0 141 else
aoqi@0 142 return sig;
aoqi@0 143
aoqi@0 144 JVM_END
aoqi@0 145
aoqi@0 146
aoqi@0 147 //Reconciliation History
aoqi@0 148 // 1.4 98/10/07 13:39:41 jvm_win32.cpp
aoqi@0 149 // 1.6 99/06/22 16:39:00 jvm_win32.cpp
aoqi@0 150 //End

mercurial