src/os/aix/vm/jvm_aix.cpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 0
f90c822e73f8
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * Copyright 2012, 2013 SAP AG. All rights reserved.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #include "precompiled.hpp"
aoqi@0 27 #include "prims/jvm.h"
aoqi@0 28 #include "runtime/interfaceSupport.hpp"
aoqi@0 29 #include "runtime/osThread.hpp"
aoqi@0 30
aoqi@0 31 #include <signal.h>
aoqi@0 32
aoqi@0 33
aoqi@0 34 // sun.misc.Signal ///////////////////////////////////////////////////////////
aoqi@0 35 // Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/23
aoqi@0 36 /*
aoqi@0 37 * This function is included primarily as a debugging aid. If Java is
aoqi@0 38 * running in a console window, then pressing <CTRL-\\> will cause
aoqi@0 39 * the current state of all active threads and monitors to be written
aoqi@0 40 * to the console window.
aoqi@0 41 */
aoqi@0 42
aoqi@0 43 JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))
aoqi@0 44 // Copied from classic vm
aoqi@0 45 // signals_md.c 1.4 98/08/23
aoqi@0 46 void* newHandler = handler == (void *)2
aoqi@0 47 ? os::user_handler()
aoqi@0 48 : handler;
aoqi@0 49 switch (sig) {
aoqi@0 50 /* The following are already used by the VM. */
aoqi@0 51 case INTERRUPT_SIGNAL:
aoqi@0 52 case SIGFPE:
aoqi@0 53 case SIGILL:
aoqi@0 54 case SIGSEGV:
aoqi@0 55
aoqi@0 56 /* The following signal is used by the VM to dump thread stacks unless
aoqi@0 57 ReduceSignalUsage is set, in which case the user is allowed to set
aoqi@0 58 his own _native_ handler for this signal; thus, in either case,
aoqi@0 59 we do not allow JVM_RegisterSignal to change the handler. */
aoqi@0 60 case BREAK_SIGNAL:
aoqi@0 61 return (void *)-1;
aoqi@0 62
aoqi@0 63 /* The following signals are used for Shutdown Hooks support. However, if
aoqi@0 64 ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via
aoqi@0 65 System.exit(), Java is not allowed to use these signals, and the the
aoqi@0 66 user is allowed to set his own _native_ handler for these signals and
aoqi@0 67 invoke System.exit() as needed. Terminator.setup() is avoiding
aoqi@0 68 registration of these signals when -Xrs is present.
aoqi@0 69 - If the HUP signal is ignored (from the nohup) command, then Java
aoqi@0 70 is not allowed to use this signal.
aoqi@0 71 */
aoqi@0 72
aoqi@0 73 case SHUTDOWN1_SIGNAL:
aoqi@0 74 case SHUTDOWN2_SIGNAL:
aoqi@0 75 case SHUTDOWN3_SIGNAL:
aoqi@0 76 if (ReduceSignalUsage) return (void*)-1;
aoqi@0 77 if (os::Aix::is_sig_ignored(sig)) return (void*)1;
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 void* oldHandler = os::signal(sig, newHandler);
aoqi@0 81 if (oldHandler == os::user_handler()) {
aoqi@0 82 return (void *)2;
aoqi@0 83 } else {
aoqi@0 84 return oldHandler;
aoqi@0 85 }
aoqi@0 86 JVM_END
aoqi@0 87
aoqi@0 88
aoqi@0 89 JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))
aoqi@0 90 if (ReduceSignalUsage) {
aoqi@0 91 // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL,
aoqi@0 92 // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since
aoqi@0 93 // no handler for them is actually registered in JVM or via
aoqi@0 94 // JVM_RegisterSignal.
aoqi@0 95 if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
aoqi@0 96 sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) {
aoqi@0 97 return JNI_FALSE;
aoqi@0 98 }
aoqi@0 99 }
aoqi@0 100 else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
aoqi@0 101 sig == SHUTDOWN3_SIGNAL) && os::Aix::is_sig_ignored(sig)) {
aoqi@0 102 // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL
aoqi@0 103 // is ignored, since no handler for them is actually registered in JVM
aoqi@0 104 // or via JVM_RegisterSignal.
aoqi@0 105 // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL
aoqi@0 106 return JNI_FALSE;
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 os::signal_raise(sig);
aoqi@0 110 return JNI_TRUE;
aoqi@0 111 JVM_END
aoqi@0 112
aoqi@0 113 /*
aoqi@0 114 All the defined signal names for Linux.
aoqi@0 115
aoqi@0 116 NOTE that not all of these names are accepted by our Java implementation
aoqi@0 117
aoqi@0 118 Via an existing claim by the VM, sigaction restrictions, or
aoqi@0 119 the "rules of Unix" some of these names will be rejected at runtime.
aoqi@0 120 For example the VM sets up to handle USR1, sigaction returns EINVAL for
aoqi@0 121 STOP, and Linux simply doesn't allow catching of KILL.
aoqi@0 122
aoqi@0 123 Here are the names currently accepted by a user of sun.misc.Signal with
aoqi@0 124 1.4.1 (ignoring potential interaction with use of chaining, etc):
aoqi@0 125
aoqi@0 126 HUP, INT, TRAP, ABRT, IOT, BUS, USR2, PIPE, ALRM, TERM, STKFLT,
aoqi@0 127 CLD, CHLD, CONT, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF,
aoqi@0 128 WINCH, POLL, IO, PWR, SYS
aoqi@0 129
aoqi@0 130 */
aoqi@0 131
aoqi@0 132 struct siglabel {
aoqi@0 133 const char *name;
aoqi@0 134 int number;
aoqi@0 135 };
aoqi@0 136
aoqi@0 137 struct siglabel siglabels[] = {
aoqi@0 138 /* derived from /usr/include/bits/signum.h on RH7.2 */
aoqi@0 139 "HUP", SIGHUP, /* Hangup (POSIX). */
aoqi@0 140 "INT", SIGINT, /* Interrupt (ANSI). */
aoqi@0 141 "QUIT", SIGQUIT, /* Quit (POSIX). */
aoqi@0 142 "ILL", SIGILL, /* Illegal instruction (ANSI). */
aoqi@0 143 "TRAP", SIGTRAP, /* Trace trap (POSIX). */
aoqi@0 144 "ABRT", SIGABRT, /* Abort (ANSI). */
aoqi@0 145 "IOT", SIGIOT, /* IOT trap (4.2 BSD). */
aoqi@0 146 "BUS", SIGBUS, /* BUS error (4.2 BSD). */
aoqi@0 147 "FPE", SIGFPE, /* Floating-point exception (ANSI). */
aoqi@0 148 "KILL", SIGKILL, /* Kill, unblockable (POSIX). */
aoqi@0 149 "USR1", SIGUSR1, /* User-defined signal 1 (POSIX). */
aoqi@0 150 "SEGV", SIGSEGV, /* Segmentation violation (ANSI). */
aoqi@0 151 "USR2", SIGUSR2, /* User-defined signal 2 (POSIX). */
aoqi@0 152 "PIPE", SIGPIPE, /* Broken pipe (POSIX). */
aoqi@0 153 "ALRM", SIGALRM, /* Alarm clock (POSIX). */
aoqi@0 154 "TERM", SIGTERM, /* Termination (ANSI). */
aoqi@0 155 #ifdef SIGSTKFLT
aoqi@0 156 "STKFLT", SIGSTKFLT, /* Stack fault. */
aoqi@0 157 #endif
aoqi@0 158 "CLD", SIGCLD, /* Same as SIGCHLD (System V). */
aoqi@0 159 "CHLD", SIGCHLD, /* Child status has changed (POSIX). */
aoqi@0 160 "CONT", SIGCONT, /* Continue (POSIX). */
aoqi@0 161 "STOP", SIGSTOP, /* Stop, unblockable (POSIX). */
aoqi@0 162 "TSTP", SIGTSTP, /* Keyboard stop (POSIX). */
aoqi@0 163 "TTIN", SIGTTIN, /* Background read from tty (POSIX). */
aoqi@0 164 "TTOU", SIGTTOU, /* Background write to tty (POSIX). */
aoqi@0 165 "URG", SIGURG, /* Urgent condition on socket (4.2 BSD). */
aoqi@0 166 "XCPU", SIGXCPU, /* CPU limit exceeded (4.2 BSD). */
aoqi@0 167 "XFSZ", SIGXFSZ, /* File size limit exceeded (4.2 BSD). */
aoqi@0 168 "DANGER", SIGDANGER, /* System crash imminent; free up some page space (AIX). */
aoqi@0 169 "VTALRM", SIGVTALRM, /* Virtual alarm clock (4.2 BSD). */
aoqi@0 170 "PROF", SIGPROF, /* Profiling alarm clock (4.2 BSD). */
aoqi@0 171 "WINCH", SIGWINCH, /* Window size change (4.3 BSD, Sun). */
aoqi@0 172 "POLL", SIGPOLL, /* Pollable event occurred (System V). */
aoqi@0 173 "IO", SIGIO, /* I/O now possible (4.2 BSD). */
aoqi@0 174 "PWR", SIGPWR, /* Power failure restart (System V). */
aoqi@0 175 #ifdef SIGSYS
aoqi@0 176 "SYS", SIGSYS /* Bad system call. Only on some Linuxen! */
aoqi@0 177 #endif
aoqi@0 178 };
aoqi@0 179
aoqi@0 180 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
aoqi@0 181
aoqi@0 182 /* find and return the named signal's number */
aoqi@0 183
aoqi@0 184 for(uint i=0; i<ARRAY_SIZE(siglabels); i++)
aoqi@0 185 if(!strcmp(name, siglabels[i].name))
aoqi@0 186 return siglabels[i].number;
aoqi@0 187
aoqi@0 188 return -1;
aoqi@0 189
aoqi@0 190 JVM_END
aoqi@0 191
aoqi@0 192 // used by os::exception_name()
aoqi@0 193 extern bool signal_name(int signo, char* buf, size_t len) {
aoqi@0 194 for(uint i = 0; i < ARRAY_SIZE(siglabels); i++) {
aoqi@0 195 if (signo == siglabels[i].number) {
aoqi@0 196 jio_snprintf(buf, len, "SIG%s", siglabels[i].name);
aoqi@0 197 return true;
aoqi@0 198 }
aoqi@0 199 }
aoqi@0 200 return false;
aoqi@0 201 }

mercurial