hotspot/src/os/posix/vm/os_posix.cpp
author rbackman
Wed, 17 Jul 2013 13:48:15 +0200
changeset 18943 7d0ef675e808
parent 17121 e40a97c700d9
child 19691 5116fb76692a
child 19553 9bbd930be684
child 22826 3ee6886e718d
permissions -rw-r--r--
8020701: Avoid crashes in WatcherThread Reviewed-by: acorn, dcubed, dsimms
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13198
diff changeset
     2
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     4
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     7
* published by the Free Software Foundation.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     8
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    13
* accompanied this code).
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    14
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    18
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    21
* questions.
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    22
*
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    23
*/
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    24
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    25
#include "prims/jvm.h"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    26
#include "runtime/frame.inline.hpp"
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    27
#include "runtime/os.hpp"
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    28
#include "utilities/vmError.hpp"
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    29
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    30
#include <unistd.h>
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    31
#include <sys/resource.h>
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    32
#include <sys/utsname.h>
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    33
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    34
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    35
// Check core dump limit and report possible place where core can be found
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    36
void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
13198
271c557a7623 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 13195
diff changeset
    37
  int n;
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    38
  struct rlimit rlim;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    39
  bool success;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    40
13198
271c557a7623 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 13195
diff changeset
    41
  n = get_core_path(buffer, bufferSize);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    42
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    43
  if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
13198
271c557a7623 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 13195
diff changeset
    44
    jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (may not exist)", current_process_id());
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    45
    success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    46
  } else {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    47
    switch(rlim.rlim_cur) {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    48
      case RLIM_INFINITY:
13198
271c557a7623 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 13195
diff changeset
    49
        jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d", current_process_id());
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    50
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    51
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    52
      case 0:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    53
        jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    54
        success = false;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    55
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    56
      default:
13198
271c557a7623 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 13195
diff changeset
    57
        jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", current_process_id(), (unsigned long)(rlim.rlim_cur >> 10));
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    58
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    59
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    60
    }
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    61
  }
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    62
  VMError::report_coredump_status(buffer, success);
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    63
}
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    64
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    65
address os::get_caller_pc(int n) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    66
#ifdef _NMT_NOINLINE_
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    67
  n ++;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    68
#endif
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    69
  frame fr = os::current_frame();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    70
  while (n > 0 && fr.pc() &&
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    71
    !os::is_first_C_frame(&fr) && fr.sender_pc()) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    72
    fr = os::get_sender_for_C_frame(&fr);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    73
    n --;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    74
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    75
  if (n == 0) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    76
    return fr.pc();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    77
  } else {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    78
    return NULL;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    79
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    80
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    81
11418
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    82
int os::get_last_error() {
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    83
  return errno;
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    84
}
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
    85
8476
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    86
bool os::is_debugger_attached() {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    87
  // not implemented
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    88
  return false;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    89
}
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    90
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    91
void os::wait_for_keypress_at_exit(void) {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    92
  // don't do anything on posix platforms
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    93
  return;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
    94
}
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    95
14840
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
    96
// Multiple threads can race in this code, and can remap over each other with MAP_FIXED,
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
    97
// so on posix, unmap the section at the start and at the end of the chunk that we mapped
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
    98
// rather than unmapping and remapping the whole chunk to get requested alignment.
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
    99
char* os::reserve_memory_aligned(size_t size, size_t alignment) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   100
  assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   101
      "Alignment must be a multiple of allocation granularity (page size)");
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   102
  assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   103
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   104
  size_t extra_size = size + alignment;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   105
  assert(extra_size >= size, "overflow, size is too large to allow alignment");
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   106
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   107
  char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   108
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   109
  if (extra_base == NULL) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   110
    return NULL;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   111
  }
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   112
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   113
  // Do manual alignment
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   114
  char* aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   115
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   116
  // [  |                                       |  ]
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   117
  // ^ extra_base
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   118
  //    ^ extra_base + begin_offset == aligned_base
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   119
  //     extra_base + begin_offset + size       ^
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   120
  //                       extra_base + extra_size ^
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   121
  // |<>| == begin_offset
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   122
  //                              end_offset == |<>|
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   123
  size_t begin_offset = aligned_base - extra_base;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   124
  size_t end_offset = (extra_base + extra_size) - (aligned_base + size);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   125
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   126
  if (begin_offset > 0) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   127
      os::release_memory(extra_base, begin_offset);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   128
  }
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   129
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   130
  if (end_offset > 0) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   131
      os::release_memory(extra_base + begin_offset + size, end_offset);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   132
  }
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   133
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   134
  return aligned_base;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   135
}
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   136
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   137
void os::Posix::print_load_average(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   138
  st->print("load average:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   139
  double loadavg[3];
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   140
  os::loadavg(loadavg, 3);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   141
  st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   142
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   143
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   144
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   145
void os::Posix::print_rlimit_info(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   146
  st->print("rlimit:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   147
  struct rlimit rlim;
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   148
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   149
  st->print(" STACK ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   150
  getrlimit(RLIMIT_STACK, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   151
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   152
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   153
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   154
  st->print(", CORE ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   155
  getrlimit(RLIMIT_CORE, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   156
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   157
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   158
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   159
  //Isn't there on solaris
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   160
#ifndef TARGET_OS_FAMILY_solaris
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   161
  st->print(", NPROC ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   162
  getrlimit(RLIMIT_NPROC, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   163
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   164
  else st->print("%d", rlim.rlim_cur);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   165
#endif
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   166
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   167
  st->print(", NOFILE ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   168
  getrlimit(RLIMIT_NOFILE, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   169
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   170
  else st->print("%d", rlim.rlim_cur);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   171
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   172
  st->print(", AS ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   173
  getrlimit(RLIMIT_AS, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   174
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   175
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   176
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   177
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   178
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   179
void os::Posix::print_uname_info(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   180
  // kernel
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   181
  st->print("uname:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   182
  struct utsname name;
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   183
  uname(&name);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   184
  st->print(name.sysname); st->print(" ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   185
  st->print(name.release); st->print(" ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   186
  st->print(name.version); st->print(" ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   187
  st->print(name.machine);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   188
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   189
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   190
16605
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   191
bool os::has_allocatable_memory_limit(julong* limit) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   192
  struct rlimit rlim;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   193
  int getrlimit_res = getrlimit(RLIMIT_AS, &rlim);
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   194
  // if there was an error when calling getrlimit, assume that there is no limitation
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   195
  // on virtual memory.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   196
  bool result;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   197
  if ((getrlimit_res != 0) || (rlim.rlim_cur == RLIM_INFINITY)) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   198
    result = false;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   199
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   200
    *limit = (julong)rlim.rlim_cur;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   201
    result = true;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   202
  }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   203
#ifdef _LP64
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   204
  return result;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   205
#else
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   206
  // arbitrary virtual space limit for 32 bit Unices found by testing. If
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   207
  // getrlimit above returned a limit, bound it with this limit. Otherwise
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   208
  // directly use it.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   209
  const julong max_virtual_limit = (julong)3800*M;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   210
  if (result) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   211
    *limit = MIN2(*limit, max_virtual_limit);
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   212
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   213
    *limit = max_virtual_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   214
  }
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   215
16605
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   216
  // bound by actually allocatable memory. The algorithm uses two bounds, an
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   217
  // upper and a lower limit. The upper limit is the current highest amount of
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   218
  // memory that could not be allocated, the lower limit is the current highest
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   219
  // amount of memory that could be allocated.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   220
  // The algorithm iteratively refines the result by halving the difference
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   221
  // between these limits, updating either the upper limit (if that value could
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   222
  // not be allocated) or the lower limit (if the that value could be allocated)
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   223
  // until the difference between these limits is "small".
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   224
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   225
  // the minimum amount of memory we care about allocating.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   226
  const julong min_allocation_size = M;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   227
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   228
  julong upper_limit = *limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   229
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   230
  // first check a few trivial cases
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   231
  if (is_allocatable(upper_limit) || (upper_limit <= min_allocation_size)) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   232
    *limit = upper_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   233
  } else if (!is_allocatable(min_allocation_size)) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   234
    // we found that not even min_allocation_size is allocatable. Return it
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   235
    // anyway. There is no point to search for a better value any more.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   236
    *limit = min_allocation_size;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   237
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   238
    // perform the binary search.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   239
    julong lower_limit = min_allocation_size;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   240
    while ((upper_limit - lower_limit) > min_allocation_size) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   241
      julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   242
      temp_limit = align_size_down_(temp_limit, min_allocation_size);
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   243
      if (is_allocatable(temp_limit)) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   244
        lower_limit = temp_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   245
      } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   246
        upper_limit = temp_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   247
      }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   248
    }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   249
    *limit = lower_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   250
  }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   251
  return true;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   252
#endif
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   253
}
17121
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   254
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   255
const char* os::get_current_directory(char *buf, size_t buflen) {
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   256
  return getcwd(buf, buflen);
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   257
}
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   258
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   259
FILE* os::open(int fd, const char* mode) {
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   260
  return ::fdopen(fd, mode);
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   261
}
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   262
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   263
os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   264
  assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   265
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   266
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   267
/*
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   268
 * See the caveats for this class in os_posix.hpp
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   269
 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   270
 * method and returns false. If none of the signals are raised, returns true.
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   271
 * The callback is supposed to provide the method that should be protected.
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   272
 */
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   273
bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   274
  assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   275
  assert(!WatcherThread::watcher_thread()->has_crash_protection(),
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   276
      "crash_protection already set?");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   277
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   278
  if (sigsetjmp(_jmpbuf, 1) == 0) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   279
    // make sure we can see in the signal handler that we have crash protection
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   280
    // installed
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   281
    WatcherThread::watcher_thread()->set_crash_protection(this);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   282
    cb.call();
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   283
    // and clear the crash protection
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   284
    WatcherThread::watcher_thread()->set_crash_protection(NULL);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   285
    return true;
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   286
  }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   287
  // this happens when we siglongjmp() back
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   288
  WatcherThread::watcher_thread()->set_crash_protection(NULL);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   289
  return false;
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   290
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   291
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   292
void os::WatcherThreadCrashProtection::restore() {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   293
  assert(WatcherThread::watcher_thread()->has_crash_protection(),
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   294
      "must have crash protection");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   295
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   296
  siglongjmp(_jmpbuf, 1);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   297
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   298
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   299
void os::WatcherThreadCrashProtection::check_crash_protection(int sig,
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   300
    Thread* thread) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   301
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   302
  if (thread != NULL &&
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   303
      thread->is_Watcher_thread() &&
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   304
      WatcherThread::watcher_thread()->has_crash_protection()) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   305
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   306
    if (sig == SIGSEGV || sig == SIGBUS) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   307
      WatcherThread::watcher_thread()->crash_protection()->restore();
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   308
    }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   309
  }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   310
}