hotspot/src/os/posix/vm/vmError_posix.cpp
author goetz
Wed, 13 Jul 2016 12:23:05 +0200
changeset 40010 e32d5e545789
parent 35176 11a9d4022d9e
child 46284 ad578adff5df
permissions -rw-r--r--
8161258: Simplify including platform files. Summary: Include patform files with macros cpu_header() etc. Do various cleanups of macro usages. Remove _64/_32 from adlc generated files and platform .hpp files. Merge stubRoutines_x86*.hpp. Remove empty mutex_<os>* files. Reviewed-by: dholmes, coleenp, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
     1
/*
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 35176
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
     4
 *
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
     8
 *
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    13
 * accompanied this code).
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    14
 *
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    18
 *
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    21
 * questions.
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    22
 *
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    23
 */
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    24
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    25
#include "precompiled.hpp"
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
    26
#include "memory/filemap.hpp"
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    27
#include "runtime/arguments.hpp"
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    28
#include "runtime/os.hpp"
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    29
#include "runtime/thread.hpp"
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    30
#include "utilities/vmError.hpp"
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    31
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    32
#include <sys/types.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    33
#include <sys/wait.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    34
#include <signal.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    35
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 35176
diff changeset
    36
#ifdef LINUX
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    37
#include <sys/syscall.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    38
#include <unistd.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    39
#endif
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 35176
diff changeset
    40
#ifdef SOLARIS
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    41
#include <thread.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    42
#endif
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 35176
diff changeset
    43
#ifdef AIX
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    44
#include <unistd.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    45
#endif
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 35176
diff changeset
    46
#ifdef BSD
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    47
#include <sys/syscall.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    48
#include <unistd.h>
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    49
#endif
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    50
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    51
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    52
// handle all synchronous program error signals which may happen during error
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    53
// reporting. They must be unblocked, caught, handled.
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    54
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    55
static const int SIGNALS[] = { SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP }; // add more if needed
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    56
static const int NUM_SIGNALS = sizeof(SIGNALS) / sizeof(int);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    57
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    58
// Space for our "saved" signal flags and handlers
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    59
static int resettedSigflags[NUM_SIGNALS];
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    60
static address resettedSighandler[NUM_SIGNALS];
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    61
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    62
static void save_signal(int idx, int sig)
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    63
{
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    64
  struct sigaction sa;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    65
  sigaction(sig, NULL, &sa);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    66
  resettedSigflags[idx]   = sa.sa_flags;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    67
  resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    68
                              ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    69
                              : CAST_FROM_FN_PTR(address, sa.sa_handler);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    70
}
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    71
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    72
int VMError::get_resetted_sigflags(int sig) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    73
  for (int i = 0; i < NUM_SIGNALS; i++) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    74
    if (SIGNALS[i] == sig) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    75
      return resettedSigflags[i];
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    76
    }
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    77
  }
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    78
  return -1;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    79
}
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    80
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    81
address VMError::get_resetted_sighandler(int sig) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    82
  for (int i = 0; i < NUM_SIGNALS; i++) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    83
    if (SIGNALS[i] == sig) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    84
      return resettedSighandler[i];
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    85
    }
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    86
  }
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    87
  return NULL;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    88
}
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    89
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    90
static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    91
  // unmask current signal
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    92
  sigset_t newset;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    93
  sigemptyset(&newset);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    94
  sigaddset(&newset, sig);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    95
  // also unmask other synchronous signals
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    96
  for (int i = 0; i < NUM_SIGNALS; i++) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    97
    sigaddset(&newset, SIGNALS[i]);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    98
  }
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
    99
  os::Posix::unblock_thread_signal_mask(&newset);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   100
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   101
  // support safefetch faults in error handling
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   102
  ucontext_t* const uc = (ucontext_t*) ucVoid;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   103
  address const pc = uc ? os::Posix::ucontext_get_pc(uc) : NULL;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   104
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   105
  if (uc && pc && StubRoutines::is_safefetch_fault(pc)) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   106
    os::Posix::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   107
    return;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   108
  }
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   109
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   110
  VMError::report_and_die(NULL, sig, pc, info, ucVoid);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   111
}
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   112
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   113
void VMError::reset_signal_handlers() {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   114
  // install signal handlers for all synchronous program error signals
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   115
  sigset_t newset;
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   116
  sigemptyset(&newset);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   117
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   118
  for (int i = 0; i < NUM_SIGNALS; i++) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   119
    save_signal(i, SIGNALS[i]);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   120
    os::signal(SIGNALS[i], CAST_FROM_FN_PTR(void *, crash_handler));
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   121
    sigaddset(&newset, SIGNALS[i]);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   122
  }
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   123
  os::Posix::unblock_thread_signal_mask(&newset);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   124
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents:
diff changeset
   125
}
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   126
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   127
// Write a hint to the stream in case siginfo relates to a segv/bus error
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   128
// and the offending address points into CDS archive.
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   129
void VMError::check_failing_cds_access(outputStream* st, const void* siginfo) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   130
  if (siginfo && UseSharedSpaces) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   131
    const siginfo_t* const si = (siginfo_t*)siginfo;
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   132
    if (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   133
      const void* const fault_addr = si->si_addr;
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   134
      if (fault_addr != NULL) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   135
        FileMapInfo* const mapinfo = FileMapInfo::current_info();
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   136
        if (mapinfo->is_in_shared_space(fault_addr)) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   137
          st->print("Error accessing class data sharing archive. "
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   138
            "Mapped file inaccessible during execution, possible disk/network problem.");
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   139
        }
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   140
      }
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   141
    }
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   142
  }
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   143
}
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 34305
diff changeset
   144