src/os/posix/vm/os_posix.cpp

Wed, 27 Aug 2014 08:19:12 -0400

author
zgu
date
Wed, 27 Aug 2014 08:19:12 -0400
changeset 7074
833b0f92429a
parent 6680
78bbf4d43a14
child 7535
7ae4e26cb1e0
child 8423
2988e5adeb8c
permissions
-rw-r--r--

8046598: Scalable Native memory tracking development
Summary: Enhance scalability of native memory tracking
Reviewed-by: coleenp, ctornqvi, gtriantafill

ctornqvi@2520 1 /*
drchase@6680 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
goetz@6460 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
goetz@6460 4 *
goetz@6460 5 * This code is free software; you can redistribute it and/or modify it
goetz@6460 6 * under the terms of the GNU General Public License version 2 only, as
goetz@6460 7 * published by the Free Software Foundation.
goetz@6460 8 *
goetz@6460 9 * This code is distributed in the hope that it will be useful, but WITHOUT
goetz@6460 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
goetz@6460 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
goetz@6460 12 * version 2 for more details (a copy is included in the LICENSE file that
goetz@6460 13 * accompanied this code).
goetz@6460 14 *
goetz@6460 15 * You should have received a copy of the GNU General Public License version
goetz@6460 16 * 2 along with this work; if not, write to the Free Software Foundation,
goetz@6460 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
goetz@6460 18 *
goetz@6460 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
goetz@6460 20 * or visit www.oracle.com if you need additional information or have any
goetz@6460 21 * questions.
goetz@6460 22 *
goetz@6460 23 */
ctornqvi@2520 24
goetz@6460 25 #include "utilities/globalDefinitions.hpp"
ctornqvi@2520 26 #include "prims/jvm.h"
zgu@3900 27 #include "runtime/frame.inline.hpp"
ctornqvi@2520 28 #include "runtime/os.hpp"
ctornqvi@2520 29 #include "utilities/vmError.hpp"
ctornqvi@2520 30
goetz@6460 31 #include <signal.h>
ctornqvi@2520 32 #include <unistd.h>
ctornqvi@2520 33 #include <sys/resource.h>
nloodin@3783 34 #include <sys/utsname.h>
sla@5609 35 #include <pthread.h>
sla@5609 36 #include <signal.h>
nloodin@3783 37
drchase@6680 38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 39
goetz@6460 40 // Todo: provide a os::get_max_process_id() or similar. Number of processes
goetz@6460 41 // may have been configured, can be read more accurately from proc fs etc.
goetz@6460 42 #ifndef MAX_PID
goetz@6460 43 #define MAX_PID INT_MAX
goetz@6460 44 #endif
goetz@6460 45 #define IS_VALID_PID(p) (p > 0 && p < MAX_PID)
ctornqvi@2520 46
ctornqvi@2520 47 // Check core dump limit and report possible place where core can be found
ctornqvi@2520 48 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
mikael@3903 49 int n;
ctornqvi@2520 50 struct rlimit rlim;
ctornqvi@2520 51 bool success;
ctornqvi@2520 52
mikael@3903 53 n = get_core_path(buffer, bufferSize);
ctornqvi@2520 54
ctornqvi@2520 55 if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
mikael@3903 56 jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (may not exist)", current_process_id());
ctornqvi@2520 57 success = true;
ctornqvi@2520 58 } else {
ctornqvi@2520 59 switch(rlim.rlim_cur) {
ctornqvi@2520 60 case RLIM_INFINITY:
mikael@3903 61 jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d", current_process_id());
ctornqvi@2520 62 success = true;
ctornqvi@2520 63 break;
ctornqvi@2520 64 case 0:
ctornqvi@2520 65 jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
ctornqvi@2520 66 success = false;
ctornqvi@2520 67 break;
ctornqvi@2520 68 default:
mikael@3903 69 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));
ctornqvi@2520 70 success = true;
ctornqvi@2520 71 break;
ctornqvi@2520 72 }
ctornqvi@2520 73 }
ctornqvi@2520 74 VMError::report_coredump_status(buffer, success);
ctornqvi@2520 75 }
ctornqvi@2520 76
zgu@7074 77 int os::get_native_stack(address* stack, int frames, int toSkip) {
zgu@3900 78 #ifdef _NMT_NOINLINE_
zgu@7074 79 toSkip++;
zgu@3900 80 #endif
zgu@7074 81
zgu@7074 82 int frame_idx = 0;
zgu@7074 83 int num_of_frames; // number of frames captured
zgu@3900 84 frame fr = os::current_frame();
zgu@7074 85 while (fr.pc() && frame_idx < frames) {
zgu@7074 86 if (toSkip > 0) {
zgu@7074 87 toSkip --;
zgu@7074 88 } else {
zgu@7074 89 stack[frame_idx ++] = fr.pc();
zgu@7074 90 }
zgu@7074 91 if (fr.fp() == NULL || os::is_first_C_frame(&fr)
zgu@7074 92 ||fr.sender_pc() == NULL || fr.cb() != NULL) break;
zgu@7074 93
zgu@7074 94 if (fr.sender_pc() && !os::is_first_C_frame(&fr)) {
zgu@7074 95 fr = os::get_sender_for_C_frame(&fr);
zgu@7074 96 } else {
zgu@7074 97 break;
zgu@7074 98 }
zgu@3900 99 }
zgu@7074 100 num_of_frames = frame_idx;
zgu@7074 101 for (; frame_idx < frames; frame_idx ++) {
zgu@7074 102 stack[frame_idx] = NULL;
zgu@3900 103 }
zgu@7074 104
zgu@7074 105 return num_of_frames;
zgu@7074 106 }
zgu@7074 107
zgu@7074 108
zgu@7074 109 bool os::unsetenv(const char* name) {
zgu@7074 110 assert(name != NULL, "Null pointer");
zgu@7074 111 return (::unsetenv(name) == 0);
zgu@3900 112 }
zgu@3900 113
phh@3379 114 int os::get_last_error() {
phh@3379 115 return errno;
phh@3379 116 }
phh@3379 117
sla@2584 118 bool os::is_debugger_attached() {
sla@2584 119 // not implemented
sla@2584 120 return false;
sla@2584 121 }
sla@2584 122
sla@2584 123 void os::wait_for_keypress_at_exit(void) {
sla@2584 124 // don't do anything on posix platforms
sla@2584 125 return;
sla@2584 126 }
nloodin@3783 127
brutisso@4369 128 // Multiple threads can race in this code, and can remap over each other with MAP_FIXED,
brutisso@4369 129 // so on posix, unmap the section at the start and at the end of the chunk that we mapped
brutisso@4369 130 // rather than unmapping and remapping the whole chunk to get requested alignment.
brutisso@4369 131 char* os::reserve_memory_aligned(size_t size, size_t alignment) {
brutisso@4369 132 assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
brutisso@4369 133 "Alignment must be a multiple of allocation granularity (page size)");
brutisso@4369 134 assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
brutisso@4369 135
brutisso@4369 136 size_t extra_size = size + alignment;
brutisso@4369 137 assert(extra_size >= size, "overflow, size is too large to allow alignment");
brutisso@4369 138
brutisso@4369 139 char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
brutisso@4369 140
brutisso@4369 141 if (extra_base == NULL) {
brutisso@4369 142 return NULL;
brutisso@4369 143 }
brutisso@4369 144
brutisso@4369 145 // Do manual alignment
brutisso@4369 146 char* aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment);
brutisso@4369 147
brutisso@4369 148 // [ | | ]
brutisso@4369 149 // ^ extra_base
brutisso@4369 150 // ^ extra_base + begin_offset == aligned_base
brutisso@4369 151 // extra_base + begin_offset + size ^
brutisso@4369 152 // extra_base + extra_size ^
brutisso@4369 153 // |<>| == begin_offset
brutisso@4369 154 // end_offset == |<>|
brutisso@4369 155 size_t begin_offset = aligned_base - extra_base;
brutisso@4369 156 size_t end_offset = (extra_base + extra_size) - (aligned_base + size);
brutisso@4369 157
brutisso@4369 158 if (begin_offset > 0) {
brutisso@4369 159 os::release_memory(extra_base, begin_offset);
brutisso@4369 160 }
brutisso@4369 161
brutisso@4369 162 if (end_offset > 0) {
brutisso@4369 163 os::release_memory(extra_base + begin_offset + size, end_offset);
brutisso@4369 164 }
brutisso@4369 165
brutisso@4369 166 return aligned_base;
brutisso@4369 167 }
brutisso@4369 168
nloodin@3783 169 void os::Posix::print_load_average(outputStream* st) {
nloodin@3783 170 st->print("load average:");
nloodin@3783 171 double loadavg[3];
nloodin@3783 172 os::loadavg(loadavg, 3);
nloodin@3783 173 st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
nloodin@3783 174 st->cr();
nloodin@3783 175 }
nloodin@3783 176
nloodin@3783 177 void os::Posix::print_rlimit_info(outputStream* st) {
nloodin@3783 178 st->print("rlimit:");
nloodin@3783 179 struct rlimit rlim;
nloodin@3783 180
nloodin@3783 181 st->print(" STACK ");
nloodin@3783 182 getrlimit(RLIMIT_STACK, &rlim);
nloodin@3783 183 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3783 184 else st->print("%uk", rlim.rlim_cur >> 10);
nloodin@3783 185
nloodin@3783 186 st->print(", CORE ");
nloodin@3783 187 getrlimit(RLIMIT_CORE, &rlim);
nloodin@3783 188 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3783 189 else st->print("%uk", rlim.rlim_cur >> 10);
nloodin@3783 190
goetz@6460 191 // Isn't there on solaris
kvn@6462 192 #if !defined(TARGET_OS_FAMILY_solaris) && !defined(TARGET_OS_FAMILY_aix)
nloodin@3783 193 st->print(", NPROC ");
nloodin@3783 194 getrlimit(RLIMIT_NPROC, &rlim);
nloodin@3783 195 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3783 196 else st->print("%d", rlim.rlim_cur);
nloodin@3783 197 #endif
nloodin@3783 198
nloodin@3783 199 st->print(", NOFILE ");
nloodin@3783 200 getrlimit(RLIMIT_NOFILE, &rlim);
nloodin@3783 201 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3783 202 else st->print("%d", rlim.rlim_cur);
nloodin@3783 203
nloodin@3783 204 st->print(", AS ");
nloodin@3783 205 getrlimit(RLIMIT_AS, &rlim);
nloodin@3783 206 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
nloodin@3783 207 else st->print("%uk", rlim.rlim_cur >> 10);
nloodin@3783 208 st->cr();
nloodin@3783 209 }
nloodin@3783 210
nloodin@3783 211 void os::Posix::print_uname_info(outputStream* st) {
nloodin@3783 212 // kernel
nloodin@3783 213 st->print("uname:");
nloodin@3783 214 struct utsname name;
nloodin@3783 215 uname(&name);
drchase@6680 216 st->print("%s ", name.sysname);
drchase@6680 217 st->print("%s ", name.release);
drchase@6680 218 st->print("%s ", name.version);
drchase@6680 219 st->print("%s", name.machine);
nloodin@3783 220 st->cr();
nloodin@3783 221 }
nloodin@3783 222
tschatzl@4854 223 bool os::has_allocatable_memory_limit(julong* limit) {
tschatzl@4854 224 struct rlimit rlim;
tschatzl@4854 225 int getrlimit_res = getrlimit(RLIMIT_AS, &rlim);
tschatzl@4854 226 // if there was an error when calling getrlimit, assume that there is no limitation
tschatzl@4854 227 // on virtual memory.
tschatzl@4854 228 bool result;
tschatzl@4854 229 if ((getrlimit_res != 0) || (rlim.rlim_cur == RLIM_INFINITY)) {
tschatzl@4854 230 result = false;
tschatzl@4854 231 } else {
tschatzl@4854 232 *limit = (julong)rlim.rlim_cur;
tschatzl@4854 233 result = true;
tschatzl@4854 234 }
tschatzl@4854 235 #ifdef _LP64
tschatzl@4854 236 return result;
tschatzl@4854 237 #else
tschatzl@4854 238 // arbitrary virtual space limit for 32 bit Unices found by testing. If
tschatzl@4854 239 // getrlimit above returned a limit, bound it with this limit. Otherwise
tschatzl@4854 240 // directly use it.
tschatzl@4854 241 const julong max_virtual_limit = (julong)3800*M;
tschatzl@4854 242 if (result) {
tschatzl@4854 243 *limit = MIN2(*limit, max_virtual_limit);
tschatzl@4854 244 } else {
tschatzl@4854 245 *limit = max_virtual_limit;
tschatzl@4854 246 }
nloodin@3783 247
tschatzl@4854 248 // bound by actually allocatable memory. The algorithm uses two bounds, an
tschatzl@4854 249 // upper and a lower limit. The upper limit is the current highest amount of
tschatzl@4854 250 // memory that could not be allocated, the lower limit is the current highest
tschatzl@4854 251 // amount of memory that could be allocated.
tschatzl@4854 252 // The algorithm iteratively refines the result by halving the difference
tschatzl@4854 253 // between these limits, updating either the upper limit (if that value could
tschatzl@4854 254 // not be allocated) or the lower limit (if the that value could be allocated)
tschatzl@4854 255 // until the difference between these limits is "small".
tschatzl@4854 256
tschatzl@4854 257 // the minimum amount of memory we care about allocating.
tschatzl@4854 258 const julong min_allocation_size = M;
tschatzl@4854 259
tschatzl@4854 260 julong upper_limit = *limit;
tschatzl@4854 261
tschatzl@4854 262 // first check a few trivial cases
tschatzl@4854 263 if (is_allocatable(upper_limit) || (upper_limit <= min_allocation_size)) {
tschatzl@4854 264 *limit = upper_limit;
tschatzl@4854 265 } else if (!is_allocatable(min_allocation_size)) {
tschatzl@4854 266 // we found that not even min_allocation_size is allocatable. Return it
tschatzl@4854 267 // anyway. There is no point to search for a better value any more.
tschatzl@4854 268 *limit = min_allocation_size;
tschatzl@4854 269 } else {
tschatzl@4854 270 // perform the binary search.
tschatzl@4854 271 julong lower_limit = min_allocation_size;
tschatzl@4854 272 while ((upper_limit - lower_limit) > min_allocation_size) {
tschatzl@4854 273 julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
tschatzl@4854 274 temp_limit = align_size_down_(temp_limit, min_allocation_size);
tschatzl@4854 275 if (is_allocatable(temp_limit)) {
tschatzl@4854 276 lower_limit = temp_limit;
tschatzl@4854 277 } else {
tschatzl@4854 278 upper_limit = temp_limit;
tschatzl@4854 279 }
tschatzl@4854 280 }
tschatzl@4854 281 *limit = lower_limit;
tschatzl@4854 282 }
tschatzl@4854 283 return true;
tschatzl@4854 284 #endif
tschatzl@4854 285 }
vlivanov@5027 286
vlivanov@5027 287 const char* os::get_current_directory(char *buf, size_t buflen) {
vlivanov@5027 288 return getcwd(buf, buflen);
vlivanov@5027 289 }
vlivanov@5027 290
vlivanov@5027 291 FILE* os::open(int fd, const char* mode) {
vlivanov@5027 292 return ::fdopen(fd, mode);
vlivanov@5027 293 }
rbackman@5424 294
bpittore@5585 295 // Builds a platform dependent Agent_OnLoad_<lib_name> function name
bpittore@5585 296 // which is used to find statically linked in agents.
bpittore@5585 297 // Parameters:
bpittore@5585 298 // sym_name: Symbol in library we are looking for
bpittore@5585 299 // lib_name: Name of library to look in, NULL for shared libs.
bpittore@5585 300 // is_absolute_path == true if lib_name is absolute path to agent
bpittore@5585 301 // such as "/a/b/libL.so"
bpittore@5585 302 // == false if only the base name of the library is passed in
bpittore@5585 303 // such as "L"
bpittore@5585 304 char* os::build_agent_function_name(const char *sym_name, const char *lib_name,
bpittore@5585 305 bool is_absolute_path) {
bpittore@5585 306 char *agent_entry_name;
bpittore@5585 307 size_t len;
bpittore@5585 308 size_t name_len;
bpittore@5585 309 size_t prefix_len = strlen(JNI_LIB_PREFIX);
bpittore@5585 310 size_t suffix_len = strlen(JNI_LIB_SUFFIX);
bpittore@5585 311 const char *start;
bpittore@5585 312
bpittore@5585 313 if (lib_name != NULL) {
bpittore@5585 314 len = name_len = strlen(lib_name);
bpittore@5585 315 if (is_absolute_path) {
bpittore@5585 316 // Need to strip path, prefix and suffix
bpittore@5585 317 if ((start = strrchr(lib_name, *os::file_separator())) != NULL) {
bpittore@5585 318 lib_name = ++start;
bpittore@5585 319 }
bpittore@5585 320 if (len <= (prefix_len + suffix_len)) {
bpittore@5585 321 return NULL;
bpittore@5585 322 }
bpittore@5585 323 lib_name += prefix_len;
bpittore@5585 324 name_len = strlen(lib_name) - suffix_len;
bpittore@5585 325 }
bpittore@5585 326 }
bpittore@5585 327 len = (lib_name != NULL ? name_len : 0) + strlen(sym_name) + 2;
bpittore@5585 328 agent_entry_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtThread);
bpittore@5585 329 if (agent_entry_name == NULL) {
bpittore@5585 330 return NULL;
bpittore@5585 331 }
bpittore@5585 332 strcpy(agent_entry_name, sym_name);
bpittore@5585 333 if (lib_name != NULL) {
bpittore@5585 334 strcat(agent_entry_name, "_");
bpittore@5585 335 strncat(agent_entry_name, lib_name, name_len);
bpittore@5585 336 }
bpittore@5585 337 return agent_entry_name;
bpittore@5585 338 }
bpittore@5585 339
goetz@6460 340 // Returned string is a constant. For unknown signals "UNKNOWN" is returned.
goetz@6460 341 const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) {
goetz@6460 342
goetz@6460 343 static const struct {
goetz@6460 344 int sig; const char* name;
goetz@6460 345 }
goetz@6460 346 info[] =
goetz@6460 347 {
goetz@6460 348 { SIGABRT, "SIGABRT" },
goetz@6460 349 #ifdef SIGAIO
goetz@6460 350 { SIGAIO, "SIGAIO" },
goetz@6460 351 #endif
goetz@6460 352 { SIGALRM, "SIGALRM" },
goetz@6460 353 #ifdef SIGALRM1
goetz@6460 354 { SIGALRM1, "SIGALRM1" },
goetz@6460 355 #endif
goetz@6460 356 { SIGBUS, "SIGBUS" },
goetz@6460 357 #ifdef SIGCANCEL
goetz@6460 358 { SIGCANCEL, "SIGCANCEL" },
goetz@6460 359 #endif
goetz@6460 360 { SIGCHLD, "SIGCHLD" },
goetz@6460 361 #ifdef SIGCLD
goetz@6460 362 { SIGCLD, "SIGCLD" },
goetz@6460 363 #endif
goetz@6460 364 { SIGCONT, "SIGCONT" },
goetz@6460 365 #ifdef SIGCPUFAIL
goetz@6460 366 { SIGCPUFAIL, "SIGCPUFAIL" },
goetz@6460 367 #endif
goetz@6460 368 #ifdef SIGDANGER
goetz@6460 369 { SIGDANGER, "SIGDANGER" },
goetz@6460 370 #endif
goetz@6460 371 #ifdef SIGDIL
goetz@6460 372 { SIGDIL, "SIGDIL" },
goetz@6460 373 #endif
goetz@6460 374 #ifdef SIGEMT
goetz@6460 375 { SIGEMT, "SIGEMT" },
goetz@6460 376 #endif
goetz@6460 377 { SIGFPE, "SIGFPE" },
goetz@6460 378 #ifdef SIGFREEZE
goetz@6460 379 { SIGFREEZE, "SIGFREEZE" },
goetz@6460 380 #endif
goetz@6460 381 #ifdef SIGGFAULT
goetz@6460 382 { SIGGFAULT, "SIGGFAULT" },
goetz@6460 383 #endif
goetz@6460 384 #ifdef SIGGRANT
goetz@6460 385 { SIGGRANT, "SIGGRANT" },
goetz@6460 386 #endif
goetz@6460 387 { SIGHUP, "SIGHUP" },
goetz@6460 388 { SIGILL, "SIGILL" },
goetz@6460 389 { SIGINT, "SIGINT" },
goetz@6460 390 #ifdef SIGIO
goetz@6460 391 { SIGIO, "SIGIO" },
goetz@6460 392 #endif
goetz@6460 393 #ifdef SIGIOINT
goetz@6460 394 { SIGIOINT, "SIGIOINT" },
goetz@6460 395 #endif
goetz@6460 396 #ifdef SIGIOT
goetz@6460 397 // SIGIOT is there for BSD compatibility, but on most Unices just a
goetz@6460 398 // synonym for SIGABRT. The result should be "SIGABRT", not
goetz@6460 399 // "SIGIOT".
goetz@6460 400 #if (SIGIOT != SIGABRT )
goetz@6460 401 { SIGIOT, "SIGIOT" },
goetz@6460 402 #endif
goetz@6460 403 #endif
goetz@6460 404 #ifdef SIGKAP
goetz@6460 405 { SIGKAP, "SIGKAP" },
goetz@6460 406 #endif
goetz@6460 407 { SIGKILL, "SIGKILL" },
goetz@6460 408 #ifdef SIGLOST
goetz@6460 409 { SIGLOST, "SIGLOST" },
goetz@6460 410 #endif
goetz@6460 411 #ifdef SIGLWP
goetz@6460 412 { SIGLWP, "SIGLWP" },
goetz@6460 413 #endif
goetz@6460 414 #ifdef SIGLWPTIMER
goetz@6460 415 { SIGLWPTIMER, "SIGLWPTIMER" },
goetz@6460 416 #endif
goetz@6460 417 #ifdef SIGMIGRATE
goetz@6460 418 { SIGMIGRATE, "SIGMIGRATE" },
goetz@6460 419 #endif
goetz@6460 420 #ifdef SIGMSG
goetz@6460 421 { SIGMSG, "SIGMSG" },
goetz@6460 422 #endif
goetz@6460 423 { SIGPIPE, "SIGPIPE" },
goetz@6460 424 #ifdef SIGPOLL
goetz@6460 425 { SIGPOLL, "SIGPOLL" },
goetz@6460 426 #endif
goetz@6460 427 #ifdef SIGPRE
goetz@6460 428 { SIGPRE, "SIGPRE" },
goetz@6460 429 #endif
goetz@6460 430 { SIGPROF, "SIGPROF" },
goetz@6460 431 #ifdef SIGPTY
goetz@6460 432 { SIGPTY, "SIGPTY" },
goetz@6460 433 #endif
goetz@6460 434 #ifdef SIGPWR
goetz@6460 435 { SIGPWR, "SIGPWR" },
goetz@6460 436 #endif
goetz@6460 437 { SIGQUIT, "SIGQUIT" },
goetz@6460 438 #ifdef SIGRECONFIG
goetz@6460 439 { SIGRECONFIG, "SIGRECONFIG" },
goetz@6460 440 #endif
goetz@6460 441 #ifdef SIGRECOVERY
goetz@6460 442 { SIGRECOVERY, "SIGRECOVERY" },
goetz@6460 443 #endif
goetz@6460 444 #ifdef SIGRESERVE
goetz@6460 445 { SIGRESERVE, "SIGRESERVE" },
goetz@6460 446 #endif
goetz@6460 447 #ifdef SIGRETRACT
goetz@6460 448 { SIGRETRACT, "SIGRETRACT" },
goetz@6460 449 #endif
goetz@6460 450 #ifdef SIGSAK
goetz@6460 451 { SIGSAK, "SIGSAK" },
goetz@6460 452 #endif
goetz@6460 453 { SIGSEGV, "SIGSEGV" },
goetz@6460 454 #ifdef SIGSOUND
goetz@6460 455 { SIGSOUND, "SIGSOUND" },
goetz@6460 456 #endif
goetz@6460 457 { SIGSTOP, "SIGSTOP" },
goetz@6460 458 { SIGSYS, "SIGSYS" },
goetz@6460 459 #ifdef SIGSYSERROR
goetz@6460 460 { SIGSYSERROR, "SIGSYSERROR" },
goetz@6460 461 #endif
goetz@6460 462 #ifdef SIGTALRM
goetz@6460 463 { SIGTALRM, "SIGTALRM" },
goetz@6460 464 #endif
goetz@6460 465 { SIGTERM, "SIGTERM" },
goetz@6460 466 #ifdef SIGTHAW
goetz@6460 467 { SIGTHAW, "SIGTHAW" },
goetz@6460 468 #endif
goetz@6460 469 { SIGTRAP, "SIGTRAP" },
goetz@6460 470 #ifdef SIGTSTP
goetz@6460 471 { SIGTSTP, "SIGTSTP" },
goetz@6460 472 #endif
goetz@6460 473 { SIGTTIN, "SIGTTIN" },
goetz@6460 474 { SIGTTOU, "SIGTTOU" },
goetz@6460 475 #ifdef SIGURG
goetz@6460 476 { SIGURG, "SIGURG" },
goetz@6460 477 #endif
goetz@6460 478 { SIGUSR1, "SIGUSR1" },
goetz@6460 479 { SIGUSR2, "SIGUSR2" },
goetz@6460 480 #ifdef SIGVIRT
goetz@6460 481 { SIGVIRT, "SIGVIRT" },
goetz@6460 482 #endif
goetz@6460 483 { SIGVTALRM, "SIGVTALRM" },
goetz@6460 484 #ifdef SIGWAITING
goetz@6460 485 { SIGWAITING, "SIGWAITING" },
goetz@6460 486 #endif
goetz@6460 487 #ifdef SIGWINCH
goetz@6460 488 { SIGWINCH, "SIGWINCH" },
goetz@6460 489 #endif
goetz@6460 490 #ifdef SIGWINDOW
goetz@6460 491 { SIGWINDOW, "SIGWINDOW" },
goetz@6460 492 #endif
goetz@6460 493 { SIGXCPU, "SIGXCPU" },
goetz@6460 494 { SIGXFSZ, "SIGXFSZ" },
goetz@6460 495 #ifdef SIGXRES
goetz@6460 496 { SIGXRES, "SIGXRES" },
goetz@6460 497 #endif
goetz@6460 498 { -1, NULL }
goetz@6460 499 };
goetz@6460 500
goetz@6460 501 const char* ret = NULL;
goetz@6460 502
goetz@6460 503 #ifdef SIGRTMIN
goetz@6460 504 if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
goetz@6460 505 if (sig == SIGRTMIN) {
goetz@6460 506 ret = "SIGRTMIN";
goetz@6460 507 } else if (sig == SIGRTMAX) {
goetz@6460 508 ret = "SIGRTMAX";
goetz@6460 509 } else {
goetz@6460 510 jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN);
goetz@6460 511 return out;
goetz@6460 512 }
goetz@6460 513 }
goetz@6460 514 #endif
goetz@6460 515
goetz@6460 516 if (sig > 0) {
goetz@6460 517 for (int idx = 0; info[idx].sig != -1; idx ++) {
goetz@6460 518 if (info[idx].sig == sig) {
goetz@6460 519 ret = info[idx].name;
goetz@6460 520 break;
goetz@6460 521 }
goetz@6460 522 }
goetz@6460 523 }
goetz@6460 524
goetz@6460 525 if (!ret) {
goetz@6460 526 if (!is_valid_signal(sig)) {
goetz@6460 527 ret = "INVALID";
goetz@6460 528 } else {
goetz@6460 529 ret = "UNKNOWN";
goetz@6460 530 }
goetz@6460 531 }
goetz@6460 532
goetz@6460 533 jio_snprintf(out, outlen, ret);
goetz@6460 534 return out;
goetz@6460 535 }
goetz@6460 536
goetz@6460 537 // Returns true if signal number is valid.
goetz@6460 538 bool os::Posix::is_valid_signal(int sig) {
goetz@6460 539 // MacOS not really POSIX compliant: sigaddset does not return
goetz@6460 540 // an error for invalid signal numbers. However, MacOS does not
goetz@6460 541 // support real time signals and simply seems to have just 33
goetz@6460 542 // signals with no holes in the signal range.
goetz@6460 543 #ifdef __APPLE__
goetz@6460 544 return sig >= 1 && sig < NSIG;
goetz@6460 545 #else
goetz@6460 546 // Use sigaddset to check for signal validity.
goetz@6460 547 sigset_t set;
goetz@6460 548 if (sigaddset(&set, sig) == -1 && errno == EINVAL) {
goetz@6460 549 return false;
goetz@6460 550 }
goetz@6460 551 return true;
goetz@6460 552 #endif
goetz@6460 553 }
goetz@6460 554
goetz@6460 555 #define NUM_IMPORTANT_SIGS 32
goetz@6460 556 // Returns one-line short description of a signal set in a user provided buffer.
goetz@6460 557 const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) {
goetz@6461 558 assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size");
goetz@6460 559 // Note: for shortness, just print out the first 32. That should
goetz@6460 560 // cover most of the useful ones, apart from realtime signals.
goetz@6460 561 for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) {
goetz@6460 562 const int rc = sigismember(set, sig);
goetz@6460 563 if (rc == -1 && errno == EINVAL) {
goetz@6460 564 buffer[sig-1] = '?';
goetz@6460 565 } else {
goetz@6460 566 buffer[sig-1] = rc == 0 ? '0' : '1';
goetz@6460 567 }
goetz@6460 568 }
goetz@6460 569 buffer[NUM_IMPORTANT_SIGS] = 0;
goetz@6460 570 return buffer;
goetz@6460 571 }
goetz@6460 572
goetz@6460 573 // Prints one-line description of a signal set.
goetz@6460 574 void os::Posix::print_signal_set_short(outputStream* st, const sigset_t* set) {
goetz@6460 575 char buf[NUM_IMPORTANT_SIGS + 1];
goetz@6460 576 os::Posix::describe_signal_set_short(set, buf, sizeof(buf));
drchase@6680 577 st->print("%s", buf);
goetz@6460 578 }
goetz@6460 579
goetz@6460 580 // Writes one-line description of a combination of sigaction.sa_flags into a user
goetz@6460 581 // provided buffer. Returns that buffer.
goetz@6460 582 const char* os::Posix::describe_sa_flags(int flags, char* buffer, size_t size) {
goetz@6460 583 char* p = buffer;
goetz@6460 584 size_t remaining = size;
goetz@6460 585 bool first = true;
goetz@6460 586 int idx = 0;
goetz@6460 587
goetz@6460 588 assert(buffer, "invalid argument");
goetz@6460 589
goetz@6460 590 if (size == 0) {
goetz@6460 591 return buffer;
goetz@6460 592 }
goetz@6460 593
goetz@6460 594 strncpy(buffer, "none", size);
goetz@6460 595
goetz@6460 596 const struct {
goetz@6460 597 int i;
goetz@6460 598 const char* s;
goetz@6460 599 } flaginfo [] = {
goetz@6460 600 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
goetz@6460 601 { SA_ONSTACK, "SA_ONSTACK" },
goetz@6460 602 { SA_RESETHAND, "SA_RESETHAND" },
goetz@6460 603 { SA_RESTART, "SA_RESTART" },
goetz@6460 604 { SA_SIGINFO, "SA_SIGINFO" },
goetz@6460 605 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
goetz@6460 606 { SA_NODEFER, "SA_NODEFER" },
goetz@6460 607 #ifdef AIX
goetz@6460 608 { SA_ONSTACK, "SA_ONSTACK" },
goetz@6460 609 { SA_OLDSTYLE, "SA_OLDSTYLE" },
goetz@6460 610 #endif
goetz@6460 611 { 0, NULL }
goetz@6460 612 };
goetz@6460 613
goetz@6460 614 for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) {
goetz@6460 615 if (flags & flaginfo[idx].i) {
goetz@6460 616 if (first) {
goetz@6460 617 jio_snprintf(p, remaining, "%s", flaginfo[idx].s);
goetz@6460 618 first = false;
goetz@6460 619 } else {
goetz@6460 620 jio_snprintf(p, remaining, "|%s", flaginfo[idx].s);
goetz@6460 621 }
goetz@6460 622 const size_t len = strlen(p);
goetz@6460 623 p += len;
goetz@6460 624 remaining -= len;
goetz@6460 625 }
goetz@6460 626 }
goetz@6460 627
goetz@6460 628 buffer[size - 1] = '\0';
goetz@6460 629
goetz@6460 630 return buffer;
goetz@6460 631 }
goetz@6460 632
goetz@6460 633 // Prints one-line description of a combination of sigaction.sa_flags.
goetz@6460 634 void os::Posix::print_sa_flags(outputStream* st, int flags) {
goetz@6460 635 char buffer[0x100];
goetz@6460 636 os::Posix::describe_sa_flags(flags, buffer, sizeof(buffer));
drchase@6680 637 st->print("%s", buffer);
goetz@6460 638 }
goetz@6460 639
goetz@6460 640 // Helper function for os::Posix::print_siginfo_...():
goetz@6460 641 // return a textual description for signal code.
goetz@6460 642 struct enum_sigcode_desc_t {
goetz@6460 643 const char* s_name;
goetz@6460 644 const char* s_desc;
goetz@6460 645 };
goetz@6460 646
goetz@6460 647 static bool get_signal_code_description(const siginfo_t* si, enum_sigcode_desc_t* out) {
goetz@6460 648
goetz@6460 649 const struct {
goetz@6460 650 int sig; int code; const char* s_code; const char* s_desc;
goetz@6460 651 } t1 [] = {
goetz@6460 652 { SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode." },
goetz@6460 653 { SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand." },
goetz@6460 654 { SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode." },
goetz@6460 655 { SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap." },
goetz@6460 656 { SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode." },
goetz@6460 657 { SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register." },
goetz@6460 658 { SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error." },
goetz@6460 659 { SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error." },
goetz@6460 660 #if defined(IA64) && defined(LINUX)
goetz@6460 661 { SIGILL, ILL_BADIADDR, "ILL_BADIADDR", "Unimplemented instruction address" },
goetz@6460 662 { SIGILL, ILL_BREAK, "ILL_BREAK", "Application Break instruction" },
goetz@6460 663 #endif
goetz@6460 664 { SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero." },
goetz@6460 665 { SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow." },
goetz@6460 666 { SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating-point divide by zero." },
goetz@6460 667 { SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating-point overflow." },
goetz@6460 668 { SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating-point underflow." },
goetz@6460 669 { SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating-point inexact result." },
goetz@6460 670 { SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating-point operation." },
goetz@6460 671 { SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range." },
goetz@6460 672 { SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object." },
goetz@6460 673 { SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for mapped object." },
goetz@6460 674 #ifdef AIX
goetz@6460 675 // no explanation found what keyerr would be
goetz@6460 676 { SIGSEGV, SEGV_KEYERR, "SEGV_KEYERR", "key error" },
goetz@6460 677 #endif
goetz@6460 678 #if defined(IA64) && !defined(AIX)
goetz@6460 679 { SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" },
goetz@6460 680 #endif
goetz@6460 681 { SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment." },
goetz@6460 682 { SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Nonexistent physical address." },
goetz@6460 683 { SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object-specific hardware error." },
goetz@6460 684 { SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint." },
goetz@6460 685 { SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap." },
goetz@6460 686 { SIGCHLD, CLD_EXITED, "CLD_EXITED", "Child has exited." },
goetz@6460 687 { SIGCHLD, CLD_KILLED, "CLD_KILLED", "Child has terminated abnormally and did not create a core file." },
goetz@6460 688 { SIGCHLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally and created a core file." },
goetz@6460 689 { SIGCHLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped." },
goetz@6460 690 { SIGCHLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped." },
goetz@6460 691 { SIGCHLD, CLD_CONTINUED,"CLD_CONTINUED","Stopped child has continued." },
goetz@6460 692 #ifdef SIGPOLL
goetz@6460 693 { SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available." },
goetz@6460 694 { SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available." },
goetz@6460 695 { SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error." },
goetz@6460 696 { SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available." },
goetz@6460 697 { SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected. [Option End]" },
goetz@6460 698 #endif
goetz@6460 699 { -1, -1, NULL, NULL }
goetz@6460 700 };
goetz@6460 701
goetz@6460 702 // Codes valid in any signal context.
goetz@6460 703 const struct {
goetz@6460 704 int code; const char* s_code; const char* s_desc;
goetz@6460 705 } t2 [] = {
goetz@6460 706 { SI_USER, "SI_USER", "Signal sent by kill()." },
goetz@6460 707 { SI_QUEUE, "SI_QUEUE", "Signal sent by the sigqueue()." },
goetz@6460 708 { SI_TIMER, "SI_TIMER", "Signal generated by expiration of a timer set by timer_settime()." },
goetz@6460 709 { SI_ASYNCIO, "SI_ASYNCIO", "Signal generated by completion of an asynchronous I/O request." },
goetz@6460 710 { SI_MESGQ, "SI_MESGQ", "Signal generated by arrival of a message on an empty message queue." },
goetz@6460 711 // Linux specific
goetz@6460 712 #ifdef SI_TKILL
goetz@6460 713 { SI_TKILL, "SI_TKILL", "Signal sent by tkill (pthread_kill)" },
goetz@6460 714 #endif
goetz@6460 715 #ifdef SI_DETHREAD
goetz@6460 716 { SI_DETHREAD, "SI_DETHREAD", "Signal sent by execve() killing subsidiary threads" },
goetz@6460 717 #endif
goetz@6460 718 #ifdef SI_KERNEL
goetz@6460 719 { SI_KERNEL, "SI_KERNEL", "Signal sent by kernel." },
goetz@6460 720 #endif
goetz@6460 721 #ifdef SI_SIGIO
goetz@6460 722 { SI_SIGIO, "SI_SIGIO", "Signal sent by queued SIGIO" },
goetz@6460 723 #endif
goetz@6460 724
goetz@6460 725 #ifdef AIX
goetz@6460 726 { SI_UNDEFINED, "SI_UNDEFINED","siginfo contains partial information" },
goetz@6460 727 { SI_EMPTY, "SI_EMPTY", "siginfo contains no useful information" },
goetz@6460 728 #endif
goetz@6460 729
goetz@6460 730 #ifdef __sun
goetz@6460 731 { SI_NOINFO, "SI_NOINFO", "No signal information" },
goetz@6460 732 { SI_RCTL, "SI_RCTL", "kernel generated signal via rctl action" },
goetz@6460 733 { SI_LWP, "SI_LWP", "Signal sent via lwp_kill" },
goetz@6460 734 #endif
goetz@6460 735
goetz@6460 736 { -1, NULL, NULL }
goetz@6460 737 };
goetz@6460 738
goetz@6460 739 const char* s_code = NULL;
goetz@6460 740 const char* s_desc = NULL;
goetz@6460 741
goetz@6460 742 for (int i = 0; t1[i].sig != -1; i ++) {
goetz@6460 743 if (t1[i].sig == si->si_signo && t1[i].code == si->si_code) {
goetz@6460 744 s_code = t1[i].s_code;
goetz@6460 745 s_desc = t1[i].s_desc;
goetz@6460 746 break;
goetz@6460 747 }
goetz@6460 748 }
goetz@6460 749
goetz@6460 750 if (s_code == NULL) {
goetz@6460 751 for (int i = 0; t2[i].s_code != NULL; i ++) {
goetz@6460 752 if (t2[i].code == si->si_code) {
goetz@6460 753 s_code = t2[i].s_code;
goetz@6460 754 s_desc = t2[i].s_desc;
goetz@6460 755 }
goetz@6460 756 }
goetz@6460 757 }
goetz@6460 758
goetz@6460 759 if (s_code == NULL) {
goetz@6460 760 out->s_name = "unknown";
goetz@6460 761 out->s_desc = "unknown";
goetz@6460 762 return false;
goetz@6460 763 }
goetz@6460 764
goetz@6460 765 out->s_name = s_code;
goetz@6460 766 out->s_desc = s_desc;
goetz@6460 767
goetz@6460 768 return true;
goetz@6460 769 }
goetz@6460 770
goetz@6460 771 // A POSIX conform, platform-independend siginfo print routine.
goetz@6460 772 // Short print out on one line.
goetz@6460 773 void os::Posix::print_siginfo_brief(outputStream* os, const siginfo_t* si) {
goetz@6460 774 char buf[20];
goetz@6460 775 os->print("siginfo: ");
goetz@6460 776
goetz@6460 777 if (!si) {
goetz@6460 778 os->print("<null>");
goetz@6460 779 return;
goetz@6460 780 }
goetz@6460 781
goetz@6460 782 // See print_siginfo_full() for details.
goetz@6460 783 const int sig = si->si_signo;
goetz@6460 784
goetz@6460 785 os->print("si_signo: %d (%s)", sig, os::Posix::get_signal_name(sig, buf, sizeof(buf)));
goetz@6460 786
goetz@6460 787 enum_sigcode_desc_t ed;
goetz@6460 788 if (get_signal_code_description(si, &ed)) {
goetz@6460 789 os->print(", si_code: %d (%s)", si->si_code, ed.s_name);
goetz@6460 790 } else {
goetz@6460 791 os->print(", si_code: %d (unknown)", si->si_code);
goetz@6460 792 }
goetz@6460 793
goetz@6460 794 if (si->si_errno) {
goetz@6460 795 os->print(", si_errno: %d", si->si_errno);
goetz@6460 796 }
goetz@6460 797
goetz@6460 798 const int me = (int) ::getpid();
goetz@6460 799 const int pid = (int) si->si_pid;
goetz@6460 800
goetz@6460 801 if (si->si_code == SI_USER || si->si_code == SI_QUEUE) {
goetz@6460 802 if (IS_VALID_PID(pid) && pid != me) {
goetz@6460 803 os->print(", sent from pid: %d (uid: %d)", pid, (int) si->si_uid);
goetz@6460 804 }
goetz@6460 805 } else if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
goetz@6460 806 sig == SIGTRAP || sig == SIGFPE) {
goetz@6460 807 os->print(", si_addr: " PTR_FORMAT, si->si_addr);
goetz@6460 808 #ifdef SIGPOLL
goetz@6460 809 } else if (sig == SIGPOLL) {
goetz@6460 810 os->print(", si_band: " PTR64_FORMAT, (uint64_t)si->si_band);
goetz@6460 811 #endif
goetz@6460 812 } else if (sig == SIGCHLD) {
goetz@6460 813 os->print_cr(", si_pid: %d, si_uid: %d, si_status: %d", (int) si->si_pid, si->si_uid, si->si_status);
goetz@6460 814 }
goetz@6460 815 }
goetz@6460 816
rbackman@5424 817 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
rbackman@5424 818 assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
rbackman@5424 819 }
rbackman@5424 820
rbackman@5424 821 /*
rbackman@5424 822 * See the caveats for this class in os_posix.hpp
rbackman@5424 823 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
rbackman@5424 824 * method and returns false. If none of the signals are raised, returns true.
rbackman@5424 825 * The callback is supposed to provide the method that should be protected.
rbackman@5424 826 */
rbackman@5424 827 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
sla@5609 828 sigset_t saved_sig_mask;
sla@5609 829
rbackman@5424 830 assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
rbackman@5424 831 assert(!WatcherThread::watcher_thread()->has_crash_protection(),
rbackman@5424 832 "crash_protection already set?");
rbackman@5424 833
sla@5609 834 // we cannot rely on sigsetjmp/siglongjmp to save/restore the signal mask
sla@5609 835 // since on at least some systems (OS X) siglongjmp will restore the mask
sla@5609 836 // for the process, not the thread
sla@5609 837 pthread_sigmask(0, NULL, &saved_sig_mask);
sla@5609 838 if (sigsetjmp(_jmpbuf, 0) == 0) {
rbackman@5424 839 // make sure we can see in the signal handler that we have crash protection
rbackman@5424 840 // installed
rbackman@5424 841 WatcherThread::watcher_thread()->set_crash_protection(this);
rbackman@5424 842 cb.call();
rbackman@5424 843 // and clear the crash protection
rbackman@5424 844 WatcherThread::watcher_thread()->set_crash_protection(NULL);
rbackman@5424 845 return true;
rbackman@5424 846 }
rbackman@5424 847 // this happens when we siglongjmp() back
sla@5609 848 pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL);
rbackman@5424 849 WatcherThread::watcher_thread()->set_crash_protection(NULL);
rbackman@5424 850 return false;
rbackman@5424 851 }
rbackman@5424 852
rbackman@5424 853 void os::WatcherThreadCrashProtection::restore() {
rbackman@5424 854 assert(WatcherThread::watcher_thread()->has_crash_protection(),
rbackman@5424 855 "must have crash protection");
rbackman@5424 856
rbackman@5424 857 siglongjmp(_jmpbuf, 1);
rbackman@5424 858 }
rbackman@5424 859
rbackman@5424 860 void os::WatcherThreadCrashProtection::check_crash_protection(int sig,
rbackman@5424 861 Thread* thread) {
rbackman@5424 862
rbackman@5424 863 if (thread != NULL &&
rbackman@5424 864 thread->is_Watcher_thread() &&
rbackman@5424 865 WatcherThread::watcher_thread()->has_crash_protection()) {
rbackman@5424 866
rbackman@5424 867 if (sig == SIGSEGV || sig == SIGBUS) {
rbackman@5424 868 WatcherThread::watcher_thread()->crash_protection()->restore();
rbackman@5424 869 }
rbackman@5424 870 }
rbackman@5424 871 }

mercurial