src/os/aix/vm/jvm_aix.cpp

changeset 0
f90c822e73f8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/os/aix/vm/jvm_aix.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,201 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright 2012, 2013 SAP AG. All rights reserved.
     1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 + *
     1.9 + * This code is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License version 2 only, as
    1.11 + * published by the Free Software Foundation.
    1.12 + *
    1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 + * version 2 for more details (a copy is included in the LICENSE file that
    1.17 + * accompanied this code).
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License version
    1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 + *
    1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 + * or visit www.oracle.com if you need additional information or have any
    1.25 + * questions.
    1.26 + *
    1.27 + */
    1.28 +
    1.29 +#include "precompiled.hpp"
    1.30 +#include "prims/jvm.h"
    1.31 +#include "runtime/interfaceSupport.hpp"
    1.32 +#include "runtime/osThread.hpp"
    1.33 +
    1.34 +#include <signal.h>
    1.35 +
    1.36 +
    1.37 +// sun.misc.Signal ///////////////////////////////////////////////////////////
    1.38 +// Signal code is mostly copied from classic vm, signals_md.c   1.4 98/08/23
    1.39 +/*
    1.40 + * This function is included primarily as a debugging aid. If Java is
    1.41 + * running in a console window, then pressing <CTRL-\\> will cause
    1.42 + * the current state of all active threads and monitors to be written
    1.43 + * to the console window.
    1.44 + */
    1.45 +
    1.46 +JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))
    1.47 +  // Copied from classic vm
    1.48 +  // signals_md.c       1.4 98/08/23
    1.49 +  void* newHandler = handler == (void *)2
    1.50 +                   ? os::user_handler()
    1.51 +                   : handler;
    1.52 +  switch (sig) {
    1.53 +    /* The following are already used by the VM. */
    1.54 +    case INTERRUPT_SIGNAL:
    1.55 +    case SIGFPE:
    1.56 +    case SIGILL:
    1.57 +    case SIGSEGV:
    1.58 +
    1.59 +    /* The following signal is used by the VM to dump thread stacks unless
    1.60 +       ReduceSignalUsage is set, in which case the user is allowed to set
    1.61 +       his own _native_ handler for this signal; thus, in either case,
    1.62 +       we do not allow JVM_RegisterSignal to change the handler. */
    1.63 +    case BREAK_SIGNAL:
    1.64 +      return (void *)-1;
    1.65 +
    1.66 +    /* The following signals are used for Shutdown Hooks support. However, if
    1.67 +       ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via
    1.68 +       System.exit(), Java is not allowed to use these signals, and the the
    1.69 +       user is allowed to set his own _native_ handler for these signals and
    1.70 +       invoke System.exit() as needed. Terminator.setup() is avoiding
    1.71 +       registration of these signals when -Xrs is present.
    1.72 +       - If the HUP signal is ignored (from the nohup) command, then Java
    1.73 +         is not allowed to use this signal.
    1.74 +     */
    1.75 +
    1.76 +    case SHUTDOWN1_SIGNAL:
    1.77 +    case SHUTDOWN2_SIGNAL:
    1.78 +    case SHUTDOWN3_SIGNAL:
    1.79 +      if (ReduceSignalUsage) return (void*)-1;
    1.80 +      if (os::Aix::is_sig_ignored(sig)) return (void*)1;
    1.81 +  }
    1.82 +
    1.83 +  void* oldHandler = os::signal(sig, newHandler);
    1.84 +  if (oldHandler == os::user_handler()) {
    1.85 +      return (void *)2;
    1.86 +  } else {
    1.87 +      return oldHandler;
    1.88 +  }
    1.89 +JVM_END
    1.90 +
    1.91 +
    1.92 +JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))
    1.93 +  if (ReduceSignalUsage) {
    1.94 +    // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL,
    1.95 +    // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since
    1.96 +    // no handler for them is actually registered in JVM or via
    1.97 +    // JVM_RegisterSignal.
    1.98 +    if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
    1.99 +        sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) {
   1.100 +      return JNI_FALSE;
   1.101 +    }
   1.102 +  }
   1.103 +  else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
   1.104 +            sig == SHUTDOWN3_SIGNAL) && os::Aix::is_sig_ignored(sig)) {
   1.105 +    // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL
   1.106 +    // is ignored, since no handler for them is actually registered in JVM
   1.107 +    // or via JVM_RegisterSignal.
   1.108 +    // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL
   1.109 +    return JNI_FALSE;
   1.110 +  }
   1.111 +
   1.112 +  os::signal_raise(sig);
   1.113 +  return JNI_TRUE;
   1.114 +JVM_END
   1.115 +
   1.116 +/*
   1.117 +  All the defined signal names for Linux.
   1.118 +
   1.119 +  NOTE that not all of these names are accepted by our Java implementation
   1.120 +
   1.121 +  Via an existing claim by the VM, sigaction restrictions, or
   1.122 +  the "rules of Unix" some of these names will be rejected at runtime.
   1.123 +  For example the VM sets up to handle USR1, sigaction returns EINVAL for
   1.124 +  STOP, and Linux simply doesn't allow catching of KILL.
   1.125 +
   1.126 +  Here are the names currently accepted by a user of sun.misc.Signal with
   1.127 +  1.4.1 (ignoring potential interaction with use of chaining, etc):
   1.128 +
   1.129 +    HUP, INT, TRAP, ABRT, IOT, BUS, USR2, PIPE, ALRM, TERM, STKFLT,
   1.130 +    CLD, CHLD, CONT, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF,
   1.131 +    WINCH, POLL, IO, PWR, SYS
   1.132 +
   1.133 +*/
   1.134 +
   1.135 +struct siglabel {
   1.136 +  const char *name;
   1.137 +  int   number;
   1.138 +};
   1.139 +
   1.140 +struct siglabel siglabels[] = {
   1.141 +  /* derived from /usr/include/bits/signum.h on RH7.2 */
   1.142 +   "HUP",       SIGHUP,         /* Hangup (POSIX).  */
   1.143 +  "INT",        SIGINT,         /* Interrupt (ANSI).  */
   1.144 +  "QUIT",       SIGQUIT,        /* Quit (POSIX).  */
   1.145 +  "ILL",        SIGILL,         /* Illegal instruction (ANSI).  */
   1.146 +  "TRAP",       SIGTRAP,        /* Trace trap (POSIX).  */
   1.147 +  "ABRT",       SIGABRT,        /* Abort (ANSI).  */
   1.148 +  "IOT",        SIGIOT,         /* IOT trap (4.2 BSD).  */
   1.149 +  "BUS",        SIGBUS,         /* BUS error (4.2 BSD).  */
   1.150 +  "FPE",        SIGFPE,         /* Floating-point exception (ANSI).  */
   1.151 +  "KILL",       SIGKILL,        /* Kill, unblockable (POSIX).  */
   1.152 +  "USR1",       SIGUSR1,        /* User-defined signal 1 (POSIX).  */
   1.153 +  "SEGV",       SIGSEGV,        /* Segmentation violation (ANSI).  */
   1.154 +  "USR2",       SIGUSR2,        /* User-defined signal 2 (POSIX).  */
   1.155 +  "PIPE",       SIGPIPE,        /* Broken pipe (POSIX).  */
   1.156 +  "ALRM",       SIGALRM,        /* Alarm clock (POSIX).  */
   1.157 +  "TERM",       SIGTERM,        /* Termination (ANSI).  */
   1.158 +#ifdef SIGSTKFLT
   1.159 +  "STKFLT",     SIGSTKFLT,      /* Stack fault.  */
   1.160 +#endif
   1.161 +  "CLD",        SIGCLD,         /* Same as SIGCHLD (System V).  */
   1.162 +  "CHLD",       SIGCHLD,        /* Child status has changed (POSIX).  */
   1.163 +  "CONT",       SIGCONT,        /* Continue (POSIX).  */
   1.164 +  "STOP",       SIGSTOP,        /* Stop, unblockable (POSIX).  */
   1.165 +  "TSTP",       SIGTSTP,        /* Keyboard stop (POSIX).  */
   1.166 +  "TTIN",       SIGTTIN,        /* Background read from tty (POSIX).  */
   1.167 +  "TTOU",       SIGTTOU,        /* Background write to tty (POSIX).  */
   1.168 +  "URG",        SIGURG,         /* Urgent condition on socket (4.2 BSD).  */
   1.169 +  "XCPU",       SIGXCPU,        /* CPU limit exceeded (4.2 BSD).  */
   1.170 +  "XFSZ",       SIGXFSZ,        /* File size limit exceeded (4.2 BSD).  */
   1.171 +  "DANGER",     SIGDANGER,      /* System crash imminent; free up some page space (AIX). */
   1.172 +  "VTALRM",     SIGVTALRM,      /* Virtual alarm clock (4.2 BSD).  */
   1.173 +  "PROF",       SIGPROF,        /* Profiling alarm clock (4.2 BSD).  */
   1.174 +  "WINCH",      SIGWINCH,       /* Window size change (4.3 BSD, Sun).  */
   1.175 +  "POLL",       SIGPOLL,        /* Pollable event occurred (System V).  */
   1.176 +  "IO",         SIGIO,          /* I/O now possible (4.2 BSD).  */
   1.177 +  "PWR",        SIGPWR,         /* Power failure restart (System V).  */
   1.178 +#ifdef SIGSYS
   1.179 +  "SYS",        SIGSYS          /* Bad system call. Only on some Linuxen! */
   1.180 +#endif
   1.181 +  };
   1.182 +
   1.183 +JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
   1.184 +
   1.185 +  /* find and return the named signal's number */
   1.186 +
   1.187 +  for(uint i=0; i<ARRAY_SIZE(siglabels); i++)
   1.188 +    if(!strcmp(name, siglabels[i].name))
   1.189 +      return siglabels[i].number;
   1.190 +
   1.191 +  return -1;
   1.192 +
   1.193 +JVM_END
   1.194 +
   1.195 +// used by os::exception_name()
   1.196 +extern bool signal_name(int signo, char* buf, size_t len) {
   1.197 +  for(uint i = 0; i < ARRAY_SIZE(siglabels); i++) {
   1.198 +    if (signo == siglabels[i].number) {
   1.199 +      jio_snprintf(buf, len, "SIG%s", siglabels[i].name);
   1.200 +      return true;
   1.201 +    }
   1.202 +  }
   1.203 +  return false;
   1.204 +}

mercurial