hotspot/src/os/posix/vm/os_posix.cpp
author coleenp
Wed, 22 Jul 2015 00:03:45 -0400
changeset 31963 641ed52732ec
parent 31610 b05ea6f92971
child 31991 a7dd5bba0fd8
permissions -rw-r--r--
8026324: hs_err improvement: Add summary section to hs_err file 8026333: hs_err improvement: Print GC Strategy 8026336: hs_err improvement: Print compilation mode, server, client or tiered Summary: Added command line, summary cpu and os information to summary section. Moved time of crash and duration in summary section. Add GC strategy and compiler setting (tiered) to enhanced version string in error report. Moved the stack trace sooner in hs_err file. Reviewed-by: dholmes, ctornqvi, ddmitriev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     1
/*
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 28172
diff changeset
     2
 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
     4
 *
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
     7
 * published by the Free Software Foundation.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
     8
 *
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    13
 * accompanied this code).
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    14
 *
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    18
 *
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    21
 * questions.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    22
 *
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    23
 */
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    24
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    25
#include "utilities/globalDefinitions.hpp"
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    26
#include "prims/jvm.h"
31610
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
    27
#include "semaphore_posix.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    28
#include "runtime/frame.inline.hpp"
22891
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
    29
#include "runtime/interfaceSupport.hpp"
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    30
#include "runtime/os.hpp"
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    31
#include "utilities/vmError.hpp"
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    32
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    33
#include <signal.h>
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    34
#include <unistd.h>
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    35
#include <sys/resource.h>
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    36
#include <sys/utsname.h>
19691
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
    37
#include <pthread.h>
31610
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
    38
#include <semaphore.h>
19691
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
    39
#include <signal.h>
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
    40
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
    41
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
    42
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    43
// Todo: provide a os::get_max_process_id() or similar. Number of processes
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    44
// may have been configured, can be read more accurately from proc fs etc.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    45
#ifndef MAX_PID
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    46
#define MAX_PID INT_MAX
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    47
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
    48
#define IS_VALID_PID(p) (p > 0 && p < MAX_PID)
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    49
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    50
// Check core dump limit and report possible place where core can be found
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 28172
diff changeset
    51
void os::check_dump_limit(char* buffer, size_t bufferSize) {
13198
271c557a7623 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 13195
diff changeset
    52
  int n;
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    53
  struct rlimit rlim;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    54
  bool success;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    55
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    56
  char core_path[PATH_MAX];
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    57
  n = get_core_path(core_path, PATH_MAX);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    58
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    59
  if (n <= 0) {
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    60
    jio_snprintf(buffer, bufferSize, "core.%d (may not exist)", current_process_id());
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    61
    success = true;
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    62
#ifdef LINUX
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    63
  } else if (core_path[0] == '"') { // redirect to user process
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    64
    jio_snprintf(buffer, bufferSize, "Core dumps may be processed with %s", core_path);
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    65
    success = true;
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    66
#endif
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    67
  } else if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    68
    jio_snprintf(buffer, bufferSize, "%s (may not exist)", core_path);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    69
    success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    70
  } else {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    71
    switch(rlim.rlim_cur) {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    72
      case RLIM_INFINITY:
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    73
        jio_snprintf(buffer, bufferSize, "%s", core_path);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    74
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    75
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    76
      case 0:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    77
        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
    78
        success = false;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    79
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    80
      default:
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    81
        jio_snprintf(buffer, bufferSize, "%s (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", core_path, (unsigned long)(rlim.rlim_cur >> 10));
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    82
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    83
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    84
    }
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    85
  }
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    86
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 28172
diff changeset
    87
  VMError::record_coredump_status(buffer, success);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    88
}
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    89
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    90
int os::get_native_stack(address* stack, int frames, int toSkip) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    91
#ifdef _NMT_NOINLINE_
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    92
  toSkip++;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    93
#endif
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    94
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    95
  int frame_idx = 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    96
  int num_of_frames;  // number of frames captured
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    97
  frame fr = os::current_frame();
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    98
  while (fr.pc() && frame_idx < frames) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    99
    if (toSkip > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   100
      toSkip --;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   101
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   102
      stack[frame_idx ++] = fr.pc();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   103
    }
28166
e42212b64568 8066803: compiler/intrinsics/mathexact/SubExactINonConstantTest.java crashed in os::is_first_C_frame(frame*)
coleenp
parents: 27471
diff changeset
   104
    if (fr.fp() == NULL || fr.cb() != NULL ||
e42212b64568 8066803: compiler/intrinsics/mathexact/SubExactINonConstantTest.java crashed in os::is_first_C_frame(frame*)
coleenp
parents: 27471
diff changeset
   105
        fr.sender_pc() == NULL || os::is_first_C_frame(&fr)) break;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   106
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   107
    if (fr.sender_pc() && !os::is_first_C_frame(&fr)) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   108
      fr = os::get_sender_for_C_frame(&fr);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   109
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   110
      break;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   111
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
   112
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   113
  num_of_frames = frame_idx;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   114
  for (; frame_idx < frames; frame_idx ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   115
    stack[frame_idx] = NULL;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
   116
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   117
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   118
  return num_of_frames;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   119
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   120
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   121
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   122
bool os::unsetenv(const char* name) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   123
  assert(name != NULL, "Null pointer");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   124
  return (::unsetenv(name) == 0);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
   125
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
   126
11418
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
   127
int os::get_last_error() {
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
   128
  return errno;
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
   129
}
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
   130
8476
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   131
bool os::is_debugger_attached() {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   132
  // not implemented
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   133
  return false;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   134
}
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   135
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   136
void os::wait_for_keypress_at_exit(void) {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   137
  // don't do anything on posix platforms
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   138
  return;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   139
}
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   140
14840
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   141
// 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
   142
// 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
   143
// 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
   144
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
   145
  assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   146
      "Alignment must be a multiple of allocation granularity (page size)");
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   147
  assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   148
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   149
  size_t extra_size = size + alignment;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   150
  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
   151
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   152
  char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   153
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   154
  if (extra_base == NULL) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   155
    return NULL;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   156
  }
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   157
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   158
  // Do manual alignment
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   159
  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
   160
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   161
  // [  |                                       |  ]
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   162
  // ^ extra_base
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   163
  //    ^ extra_base + begin_offset == aligned_base
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   164
  //     extra_base + begin_offset + size       ^
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   165
  //                       extra_base + extra_size ^
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   166
  // |<>| == begin_offset
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   167
  //                              end_offset == |<>|
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   168
  size_t begin_offset = aligned_base - extra_base;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   169
  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
   170
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   171
  if (begin_offset > 0) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   172
      os::release_memory(extra_base, begin_offset);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   173
  }
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   174
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   175
  if (end_offset > 0) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   176
      os::release_memory(extra_base + begin_offset + size, end_offset);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   177
  }
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   178
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   179
  return aligned_base;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   180
}
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   181
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   182
void os::Posix::print_load_average(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   183
  st->print("load average:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   184
  double loadavg[3];
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   185
  os::loadavg(loadavg, 3);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   186
  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
   187
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   188
}
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
void os::Posix::print_rlimit_info(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   191
  st->print("rlimit:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   192
  struct rlimit rlim;
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   193
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   194
  st->print(" STACK ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   195
  getrlimit(RLIMIT_STACK, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   196
  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
   197
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   198
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   199
  st->print(", CORE ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   200
  getrlimit(RLIMIT_CORE, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   201
  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
   202
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   203
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   204
  // Isn't there on solaris
22828
kvn
parents: 22827 19553
diff changeset
   205
#if !defined(TARGET_OS_FAMILY_solaris) && !defined(TARGET_OS_FAMILY_aix)
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   206
  st->print(", NPROC ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   207
  getrlimit(RLIMIT_NPROC, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   208
  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
   209
  else st->print("%d", rlim.rlim_cur);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   210
#endif
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   211
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   212
  st->print(", NOFILE ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   213
  getrlimit(RLIMIT_NOFILE, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   214
  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
   215
  else st->print("%d", rlim.rlim_cur);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   216
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   217
  st->print(", AS ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   218
  getrlimit(RLIMIT_AS, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   219
  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
   220
  else st->print("%uk", rlim.rlim_cur >> 10);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   221
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   222
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   223
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   224
void os::Posix::print_uname_info(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   225
  // kernel
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   226
  st->print("uname:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   227
  struct utsname name;
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   228
  uname(&name);
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   229
  st->print("%s ", name.sysname);
26569
5fcbc13c071c 8056930: Output host info under some condition for core dump
minqi
parents: 25946
diff changeset
   230
#ifdef ASSERT
5fcbc13c071c 8056930: Output host info under some condition for core dump
minqi
parents: 25946
diff changeset
   231
  st->print("%s ", name.nodename);
5fcbc13c071c 8056930: Output host info under some condition for core dump
minqi
parents: 25946
diff changeset
   232
#endif
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   233
  st->print("%s ", name.release);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   234
  st->print("%s ", name.version);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   235
  st->print("%s", name.machine);
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   236
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   237
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   238
31963
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   239
#ifndef PRODUCT
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   240
bool os::get_host_name(char* buf, size_t buflen) {
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   241
  struct utsname name;
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   242
  uname(&name);
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   243
  jio_snprintf(buf, buflen, "%s", name.nodename);
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   244
  return true;
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   245
}
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   246
#endif // PRODUCT
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   247
16605
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   248
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
   249
  struct rlimit rlim;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   250
  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
   251
  // 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
   252
  // on virtual memory.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   253
  bool result;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   254
  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
   255
    result = false;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   256
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   257
    *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
   258
    result = true;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   259
  }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   260
#ifdef _LP64
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   261
  return result;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   262
#else
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   263
  // 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
   264
  // 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
   265
  // directly use it.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   266
  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
   267
  if (result) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   268
    *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
   269
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   270
    *limit = max_virtual_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   271
  }
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   272
16605
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   273
  // 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
   274
  // 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
   275
  // 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
   276
  // 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
   277
  // 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
   278
  // 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
   279
  // 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
   280
  // 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
   281
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   282
  // 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
   283
  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
   284
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   285
  julong upper_limit = *limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   286
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   287
  // 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
   288
  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
   289
    *limit = upper_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   290
  } 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
   291
    // 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
   292
    // 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
   293
    *limit = min_allocation_size;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   294
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   295
    // perform the binary search.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   296
    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
   297
    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
   298
      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
   299
      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
   300
      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
   301
        lower_limit = temp_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   302
      } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   303
        upper_limit = temp_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   304
      }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   305
    }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   306
    *limit = lower_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   307
  }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   308
  return true;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   309
#endif
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   310
}
17121
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   311
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   312
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
   313
  return getcwd(buf, buflen);
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   314
}
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   315
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   316
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
   317
  return ::fdopen(fd, mode);
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   318
}
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   319
19553
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   320
// Builds a platform dependent Agent_OnLoad_<lib_name> function name
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   321
// which is used to find statically linked in agents.
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   322
// Parameters:
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   323
//            sym_name: Symbol in library we are looking for
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   324
//            lib_name: Name of library to look in, NULL for shared libs.
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   325
//            is_absolute_path == true if lib_name is absolute path to agent
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   326
//                                     such as "/a/b/libL.so"
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   327
//            == false if only the base name of the library is passed in
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   328
//               such as "L"
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   329
char* os::build_agent_function_name(const char *sym_name, const char *lib_name,
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   330
                                    bool is_absolute_path) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   331
  char *agent_entry_name;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   332
  size_t len;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   333
  size_t name_len;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   334
  size_t prefix_len = strlen(JNI_LIB_PREFIX);
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   335
  size_t suffix_len = strlen(JNI_LIB_SUFFIX);
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   336
  const char *start;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   337
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   338
  if (lib_name != NULL) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   339
    len = name_len = strlen(lib_name);
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   340
    if (is_absolute_path) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   341
      // Need to strip path, prefix and suffix
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   342
      if ((start = strrchr(lib_name, *os::file_separator())) != NULL) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   343
        lib_name = ++start;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   344
      }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   345
      if (len <= (prefix_len + suffix_len)) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   346
        return NULL;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   347
      }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   348
      lib_name += prefix_len;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   349
      name_len = strlen(lib_name) - suffix_len;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   350
    }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   351
  }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   352
  len = (lib_name != NULL ? name_len : 0) + strlen(sym_name) + 2;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   353
  agent_entry_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtThread);
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   354
  if (agent_entry_name == NULL) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   355
    return NULL;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   356
  }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   357
  strcpy(agent_entry_name, sym_name);
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   358
  if (lib_name != NULL) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   359
    strcat(agent_entry_name, "_");
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   360
    strncat(agent_entry_name, lib_name, name_len);
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   361
  }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   362
  return agent_entry_name;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   363
}
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   364
22891
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   365
int os::sleep(Thread* thread, jlong millis, bool interruptible) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   366
  assert(thread == Thread::current(),  "thread consistency check");
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   367
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   368
  ParkEvent * const slp = thread->_SleepEvent ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   369
  slp->reset() ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   370
  OrderAccess::fence() ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   371
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   372
  if (interruptible) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   373
    jlong prevtime = javaTimeNanos();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   374
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   375
    for (;;) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   376
      if (os::is_interrupted(thread, true)) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   377
        return OS_INTRPT;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   378
      }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   379
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   380
      jlong newtime = javaTimeNanos();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   381
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   382
      if (newtime - prevtime < 0) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   383
        // time moving backwards, should only happen if no monotonic clock
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   384
        // not a guarantee() because JVM should not abort on kernel/glibc bugs
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   385
        assert(!os::supports_monotonic_clock(), "unexpected time moving backwards detected in os::sleep(interruptible)");
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   386
      } else {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   387
        millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   388
      }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   389
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   390
      if (millis <= 0) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   391
        return OS_OK;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   392
      }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   393
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   394
      prevtime = newtime;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   395
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   396
      {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   397
        assert(thread->is_Java_thread(), "sanity check");
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   398
        JavaThread *jt = (JavaThread *) thread;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   399
        ThreadBlockInVM tbivm(jt);
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   400
        OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */);
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   401
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   402
        jt->set_suspend_equivalent();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   403
        // cleared by handle_special_suspend_equivalent_condition() or
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   404
        // java_suspend_self() via check_and_wait_while_suspended()
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   405
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   406
        slp->park(millis);
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   407
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   408
        // were we externally suspended while we were waiting?
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   409
        jt->check_and_wait_while_suspended();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   410
      }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   411
    }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   412
  } else {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   413
    OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   414
    jlong prevtime = javaTimeNanos();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   415
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   416
    for (;;) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   417
      // It'd be nice to avoid the back-to-back javaTimeNanos() calls on
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   418
      // the 1st iteration ...
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   419
      jlong newtime = javaTimeNanos();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   420
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   421
      if (newtime - prevtime < 0) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   422
        // time moving backwards, should only happen if no monotonic clock
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   423
        // not a guarantee() because JVM should not abort on kernel/glibc bugs
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   424
        assert(!os::supports_monotonic_clock(), "unexpected time moving backwards detected on os::sleep(!interruptible)");
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   425
      } else {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   426
        millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   427
      }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   428
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   429
      if (millis <= 0) break ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   430
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   431
      prevtime = newtime;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   432
      slp->park(millis);
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   433
    }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   434
    return OS_OK ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   435
  }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   436
}
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   437
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   438
////////////////////////////////////////////////////////////////////////////////
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   439
// interrupt support
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   440
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   441
void os::interrupt(Thread* thread) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   442
  assert(Thread::current() == thread || Threads_lock->owned_by_self(),
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   443
    "possibility of dangling Thread pointer");
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   444
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   445
  OSThread* osthread = thread->osthread();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   446
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   447
  if (!osthread->interrupted()) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   448
    osthread->set_interrupted(true);
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   449
    // More than one thread can get here with the same value of osthread,
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   450
    // resulting in multiple notifications.  We do, however, want the store
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   451
    // to interrupted() to be visible to other threads before we execute unpark().
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   452
    OrderAccess::fence();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   453
    ParkEvent * const slp = thread->_SleepEvent ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   454
    if (slp != NULL) slp->unpark() ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   455
  }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   456
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   457
  // For JSR166. Unpark even if interrupt status already was set
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   458
  if (thread->is_Java_thread())
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   459
    ((JavaThread*)thread)->parker()->unpark();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   460
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   461
  ParkEvent * ev = thread->_ParkEvent ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   462
  if (ev != NULL) ev->unpark() ;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   463
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   464
}
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   465
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   466
bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   467
  assert(Thread::current() == thread || Threads_lock->owned_by_self(),
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   468
    "possibility of dangling Thread pointer");
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   469
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   470
  OSThread* osthread = thread->osthread();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   471
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   472
  bool interrupted = osthread->interrupted();
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   473
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   474
  // NOTE that since there is no "lock" around the interrupt and
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   475
  // is_interrupted operations, there is the possibility that the
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   476
  // interrupted flag (in osThread) will be "false" but that the
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   477
  // low-level events will be in the signaled state. This is
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   478
  // intentional. The effect of this is that Object.wait() and
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   479
  // LockSupport.park() will appear to have a spurious wakeup, which
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   480
  // is allowed and not harmful, and the possibility is so rare that
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   481
  // it is not worth the added complexity to add yet another lock.
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   482
  // For the sleep event an explicit reset is performed on entry
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   483
  // to os::sleep, so there is no early return. It has also been
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   484
  // recommended not to put the interrupted flag into the "event"
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   485
  // structure because it hides the issue.
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   486
  if (interrupted && clear_interrupted) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   487
    osthread->set_interrupted(false);
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   488
    // consider thread->_SleepEvent->reset() ... optional optimization
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   489
  }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   490
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   491
  return interrupted;
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   492
}
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   493
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   494
// Returned string is a constant. For unknown signals "UNKNOWN" is returned.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   495
const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   496
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   497
  static const struct {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   498
    int sig; const char* name;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   499
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   500
  info[] =
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   501
  {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   502
    {  SIGABRT,     "SIGABRT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   503
#ifdef SIGAIO
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   504
    {  SIGAIO,      "SIGAIO" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   505
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   506
    {  SIGALRM,     "SIGALRM" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   507
#ifdef SIGALRM1
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   508
    {  SIGALRM1,    "SIGALRM1" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   509
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   510
    {  SIGBUS,      "SIGBUS" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   511
#ifdef SIGCANCEL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   512
    {  SIGCANCEL,   "SIGCANCEL" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   513
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   514
    {  SIGCHLD,     "SIGCHLD" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   515
#ifdef SIGCLD
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   516
    {  SIGCLD,      "SIGCLD" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   517
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   518
    {  SIGCONT,     "SIGCONT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   519
#ifdef SIGCPUFAIL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   520
    {  SIGCPUFAIL,  "SIGCPUFAIL" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   521
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   522
#ifdef SIGDANGER
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   523
    {  SIGDANGER,   "SIGDANGER" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   524
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   525
#ifdef SIGDIL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   526
    {  SIGDIL,      "SIGDIL" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   527
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   528
#ifdef SIGEMT
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   529
    {  SIGEMT,      "SIGEMT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   530
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   531
    {  SIGFPE,      "SIGFPE" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   532
#ifdef SIGFREEZE
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   533
    {  SIGFREEZE,   "SIGFREEZE" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   534
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   535
#ifdef SIGGFAULT
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   536
    {  SIGGFAULT,   "SIGGFAULT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   537
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   538
#ifdef SIGGRANT
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   539
    {  SIGGRANT,    "SIGGRANT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   540
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   541
    {  SIGHUP,      "SIGHUP" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   542
    {  SIGILL,      "SIGILL" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   543
    {  SIGINT,      "SIGINT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   544
#ifdef SIGIO
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   545
    {  SIGIO,       "SIGIO" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   546
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   547
#ifdef SIGIOINT
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   548
    {  SIGIOINT,    "SIGIOINT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   549
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   550
#ifdef SIGIOT
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   551
  // SIGIOT is there for BSD compatibility, but on most Unices just a
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   552
  // synonym for SIGABRT. The result should be "SIGABRT", not
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   553
  // "SIGIOT".
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   554
  #if (SIGIOT != SIGABRT )
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   555
    {  SIGIOT,      "SIGIOT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   556
  #endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   557
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   558
#ifdef SIGKAP
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   559
    {  SIGKAP,      "SIGKAP" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   560
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   561
    {  SIGKILL,     "SIGKILL" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   562
#ifdef SIGLOST
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   563
    {  SIGLOST,     "SIGLOST" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   564
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   565
#ifdef SIGLWP
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   566
    {  SIGLWP,      "SIGLWP" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   567
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   568
#ifdef SIGLWPTIMER
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   569
    {  SIGLWPTIMER, "SIGLWPTIMER" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   570
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   571
#ifdef SIGMIGRATE
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   572
    {  SIGMIGRATE,  "SIGMIGRATE" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   573
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   574
#ifdef SIGMSG
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   575
    {  SIGMSG,      "SIGMSG" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   576
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   577
    {  SIGPIPE,     "SIGPIPE" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   578
#ifdef SIGPOLL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   579
    {  SIGPOLL,     "SIGPOLL" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   580
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   581
#ifdef SIGPRE
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   582
    {  SIGPRE,      "SIGPRE" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   583
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   584
    {  SIGPROF,     "SIGPROF" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   585
#ifdef SIGPTY
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   586
    {  SIGPTY,      "SIGPTY" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   587
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   588
#ifdef SIGPWR
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   589
    {  SIGPWR,      "SIGPWR" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   590
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   591
    {  SIGQUIT,     "SIGQUIT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   592
#ifdef SIGRECONFIG
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   593
    {  SIGRECONFIG, "SIGRECONFIG" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   594
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   595
#ifdef SIGRECOVERY
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   596
    {  SIGRECOVERY, "SIGRECOVERY" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   597
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   598
#ifdef SIGRESERVE
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   599
    {  SIGRESERVE,  "SIGRESERVE" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   600
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   601
#ifdef SIGRETRACT
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   602
    {  SIGRETRACT,  "SIGRETRACT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   603
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   604
#ifdef SIGSAK
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   605
    {  SIGSAK,      "SIGSAK" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   606
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   607
    {  SIGSEGV,     "SIGSEGV" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   608
#ifdef SIGSOUND
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   609
    {  SIGSOUND,    "SIGSOUND" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   610
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   611
    {  SIGSTOP,     "SIGSTOP" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   612
    {  SIGSYS,      "SIGSYS" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   613
#ifdef SIGSYSERROR
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   614
    {  SIGSYSERROR, "SIGSYSERROR" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   615
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   616
#ifdef SIGTALRM
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   617
    {  SIGTALRM,    "SIGTALRM" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   618
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   619
    {  SIGTERM,     "SIGTERM" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   620
#ifdef SIGTHAW
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   621
    {  SIGTHAW,     "SIGTHAW" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   622
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   623
    {  SIGTRAP,     "SIGTRAP" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   624
#ifdef SIGTSTP
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   625
    {  SIGTSTP,     "SIGTSTP" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   626
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   627
    {  SIGTTIN,     "SIGTTIN" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   628
    {  SIGTTOU,     "SIGTTOU" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   629
#ifdef SIGURG
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   630
    {  SIGURG,      "SIGURG" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   631
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   632
    {  SIGUSR1,     "SIGUSR1" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   633
    {  SIGUSR2,     "SIGUSR2" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   634
#ifdef SIGVIRT
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   635
    {  SIGVIRT,     "SIGVIRT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   636
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   637
    {  SIGVTALRM,   "SIGVTALRM" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   638
#ifdef SIGWAITING
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   639
    {  SIGWAITING,  "SIGWAITING" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   640
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   641
#ifdef SIGWINCH
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   642
    {  SIGWINCH,    "SIGWINCH" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   643
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   644
#ifdef SIGWINDOW
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   645
    {  SIGWINDOW,   "SIGWINDOW" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   646
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   647
    {  SIGXCPU,     "SIGXCPU" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   648
    {  SIGXFSZ,     "SIGXFSZ" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   649
#ifdef SIGXRES
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   650
    {  SIGXRES,     "SIGXRES" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   651
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   652
    { -1, NULL }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   653
  };
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   654
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   655
  const char* ret = NULL;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   656
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   657
#ifdef SIGRTMIN
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   658
  if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   659
    if (sig == SIGRTMIN) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   660
      ret = "SIGRTMIN";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   661
    } else if (sig == SIGRTMAX) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   662
      ret = "SIGRTMAX";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   663
    } else {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   664
      jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   665
      return out;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   666
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   667
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   668
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   669
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   670
  if (sig > 0) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   671
    for (int idx = 0; info[idx].sig != -1; idx ++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   672
      if (info[idx].sig == sig) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   673
        ret = info[idx].name;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   674
        break;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   675
      }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   676
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   677
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   678
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   679
  if (!ret) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   680
    if (!is_valid_signal(sig)) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   681
      ret = "INVALID";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   682
    } else {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   683
      ret = "UNKNOWN";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   684
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   685
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   686
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 26569
diff changeset
   687
  if (out && outlen > 0) {
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 26569
diff changeset
   688
    strncpy(out, ret, outlen);
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 26569
diff changeset
   689
    out[outlen - 1] = '\0';
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 26569
diff changeset
   690
  }
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   691
  return out;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   692
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   693
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   694
// Returns true if signal number is valid.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   695
bool os::Posix::is_valid_signal(int sig) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   696
  // MacOS not really POSIX compliant: sigaddset does not return
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   697
  // an error for invalid signal numbers. However, MacOS does not
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   698
  // support real time signals and simply seems to have just 33
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   699
  // signals with no holes in the signal range.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   700
#ifdef __APPLE__
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   701
  return sig >= 1 && sig < NSIG;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   702
#else
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   703
  // Use sigaddset to check for signal validity.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   704
  sigset_t set;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   705
  if (sigaddset(&set, sig) == -1 && errno == EINVAL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   706
    return false;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   707
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   708
  return true;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   709
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   710
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   711
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   712
#define NUM_IMPORTANT_SIGS 32
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   713
// Returns one-line short description of a signal set in a user provided buffer.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   714
const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) {
22827
07d991d45a51 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 22826
diff changeset
   715
  assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size");
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   716
  // Note: for shortness, just print out the first 32. That should
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   717
  // cover most of the useful ones, apart from realtime signals.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   718
  for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   719
    const int rc = sigismember(set, sig);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   720
    if (rc == -1 && errno == EINVAL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   721
      buffer[sig-1] = '?';
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   722
    } else {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   723
      buffer[sig-1] = rc == 0 ? '0' : '1';
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   724
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   725
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   726
  buffer[NUM_IMPORTANT_SIGS] = 0;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   727
  return buffer;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   728
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   729
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   730
// Prints one-line description of a signal set.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   731
void os::Posix::print_signal_set_short(outputStream* st, const sigset_t* set) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   732
  char buf[NUM_IMPORTANT_SIGS + 1];
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   733
  os::Posix::describe_signal_set_short(set, buf, sizeof(buf));
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   734
  st->print("%s", buf);
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   735
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   736
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   737
// Writes one-line description of a combination of sigaction.sa_flags into a user
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   738
// provided buffer. Returns that buffer.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   739
const char* os::Posix::describe_sa_flags(int flags, char* buffer, size_t size) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   740
  char* p = buffer;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   741
  size_t remaining = size;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   742
  bool first = true;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   743
  int idx = 0;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   744
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   745
  assert(buffer, "invalid argument");
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   746
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   747
  if (size == 0) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   748
    return buffer;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   749
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   750
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   751
  strncpy(buffer, "none", size);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   752
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   753
  const struct {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   754
    int i;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   755
    const char* s;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   756
  } flaginfo [] = {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   757
    { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   758
    { SA_ONSTACK,   "SA_ONSTACK"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   759
    { SA_RESETHAND, "SA_RESETHAND" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   760
    { SA_RESTART,   "SA_RESTART"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   761
    { SA_SIGINFO,   "SA_SIGINFO"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   762
    { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   763
    { SA_NODEFER,   "SA_NODEFER"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   764
#ifdef AIX
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   765
    { SA_ONSTACK,   "SA_ONSTACK"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   766
    { SA_OLDSTYLE,  "SA_OLDSTYLE"  },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   767
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   768
    { 0, NULL }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   769
  };
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   770
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   771
  for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   772
    if (flags & flaginfo[idx].i) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   773
      if (first) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   774
        jio_snprintf(p, remaining, "%s", flaginfo[idx].s);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   775
        first = false;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   776
      } else {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   777
        jio_snprintf(p, remaining, "|%s", flaginfo[idx].s);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   778
      }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   779
      const size_t len = strlen(p);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   780
      p += len;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   781
      remaining -= len;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   782
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   783
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   784
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   785
  buffer[size - 1] = '\0';
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   786
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   787
  return buffer;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   788
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   789
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   790
// Prints one-line description of a combination of sigaction.sa_flags.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   791
void os::Posix::print_sa_flags(outputStream* st, int flags) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   792
  char buffer[0x100];
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   793
  os::Posix::describe_sa_flags(flags, buffer, sizeof(buffer));
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   794
  st->print("%s", buffer);
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   795
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   796
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   797
// Helper function for os::Posix::print_siginfo_...():
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   798
// return a textual description for signal code.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   799
struct enum_sigcode_desc_t {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   800
  const char* s_name;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   801
  const char* s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   802
};
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   803
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   804
static bool get_signal_code_description(const siginfo_t* si, enum_sigcode_desc_t* out) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   805
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   806
  const struct {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   807
    int sig; int code; const char* s_code; const char* s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   808
  } t1 [] = {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   809
    { SIGILL,  ILL_ILLOPC,   "ILL_ILLOPC",   "Illegal opcode." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   810
    { SIGILL,  ILL_ILLOPN,   "ILL_ILLOPN",   "Illegal operand." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   811
    { SIGILL,  ILL_ILLADR,   "ILL_ILLADR",   "Illegal addressing mode." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   812
    { SIGILL,  ILL_ILLTRP,   "ILL_ILLTRP",   "Illegal trap." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   813
    { SIGILL,  ILL_PRVOPC,   "ILL_PRVOPC",   "Privileged opcode." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   814
    { SIGILL,  ILL_PRVREG,   "ILL_PRVREG",   "Privileged register." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   815
    { SIGILL,  ILL_COPROC,   "ILL_COPROC",   "Coprocessor error." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   816
    { SIGILL,  ILL_BADSTK,   "ILL_BADSTK",   "Internal stack error." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   817
#if defined(IA64) && defined(LINUX)
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   818
    { SIGILL,  ILL_BADIADDR, "ILL_BADIADDR", "Unimplemented instruction address" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   819
    { SIGILL,  ILL_BREAK,    "ILL_BREAK",    "Application Break instruction" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   820
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   821
    { SIGFPE,  FPE_INTDIV,   "FPE_INTDIV",   "Integer divide by zero." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   822
    { SIGFPE,  FPE_INTOVF,   "FPE_INTOVF",   "Integer overflow." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   823
    { SIGFPE,  FPE_FLTDIV,   "FPE_FLTDIV",   "Floating-point divide by zero." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   824
    { SIGFPE,  FPE_FLTOVF,   "FPE_FLTOVF",   "Floating-point overflow." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   825
    { SIGFPE,  FPE_FLTUND,   "FPE_FLTUND",   "Floating-point underflow." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   826
    { SIGFPE,  FPE_FLTRES,   "FPE_FLTRES",   "Floating-point inexact result." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   827
    { SIGFPE,  FPE_FLTINV,   "FPE_FLTINV",   "Invalid floating-point operation." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   828
    { SIGFPE,  FPE_FLTSUB,   "FPE_FLTSUB",   "Subscript out of range." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   829
    { SIGSEGV, SEGV_MAPERR,  "SEGV_MAPERR",  "Address not mapped to object." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   830
    { SIGSEGV, SEGV_ACCERR,  "SEGV_ACCERR",  "Invalid permissions for mapped object." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   831
#ifdef AIX
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   832
    // no explanation found what keyerr would be
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   833
    { SIGSEGV, SEGV_KEYERR,  "SEGV_KEYERR",  "key error" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   834
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   835
#if defined(IA64) && !defined(AIX)
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   836
    { SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   837
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   838
    { SIGBUS,  BUS_ADRALN,   "BUS_ADRALN",   "Invalid address alignment." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   839
    { SIGBUS,  BUS_ADRERR,   "BUS_ADRERR",   "Nonexistent physical address." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   840
    { SIGBUS,  BUS_OBJERR,   "BUS_OBJERR",   "Object-specific hardware error." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   841
    { SIGTRAP, TRAP_BRKPT,   "TRAP_BRKPT",   "Process breakpoint." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   842
    { SIGTRAP, TRAP_TRACE,   "TRAP_TRACE",   "Process trace trap." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   843
    { SIGCHLD, CLD_EXITED,   "CLD_EXITED",   "Child has exited." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   844
    { SIGCHLD, CLD_KILLED,   "CLD_KILLED",   "Child has terminated abnormally and did not create a core file." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   845
    { SIGCHLD, CLD_DUMPED,   "CLD_DUMPED",   "Child has terminated abnormally and created a core file." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   846
    { SIGCHLD, CLD_TRAPPED,  "CLD_TRAPPED",  "Traced child has trapped." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   847
    { SIGCHLD, CLD_STOPPED,  "CLD_STOPPED",  "Child has stopped." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   848
    { SIGCHLD, CLD_CONTINUED,"CLD_CONTINUED","Stopped child has continued." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   849
#ifdef SIGPOLL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   850
    { SIGPOLL, POLL_OUT,     "POLL_OUT",     "Output buffers available." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   851
    { SIGPOLL, POLL_MSG,     "POLL_MSG",     "Input message available." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   852
    { SIGPOLL, POLL_ERR,     "POLL_ERR",     "I/O error." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   853
    { SIGPOLL, POLL_PRI,     "POLL_PRI",     "High priority input available." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   854
    { SIGPOLL, POLL_HUP,     "POLL_HUP",     "Device disconnected. [Option End]" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   855
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   856
    { -1, -1, NULL, NULL }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   857
  };
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   858
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   859
  // Codes valid in any signal context.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   860
  const struct {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   861
    int code; const char* s_code; const char* s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   862
  } t2 [] = {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   863
    { SI_USER,      "SI_USER",     "Signal sent by kill()." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   864
    { SI_QUEUE,     "SI_QUEUE",    "Signal sent by the sigqueue()." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   865
    { SI_TIMER,     "SI_TIMER",    "Signal generated by expiration of a timer set by timer_settime()." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   866
    { SI_ASYNCIO,   "SI_ASYNCIO",  "Signal generated by completion of an asynchronous I/O request." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   867
    { SI_MESGQ,     "SI_MESGQ",    "Signal generated by arrival of a message on an empty message queue." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   868
    // Linux specific
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   869
#ifdef SI_TKILL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   870
    { SI_TKILL,     "SI_TKILL",    "Signal sent by tkill (pthread_kill)" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   871
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   872
#ifdef SI_DETHREAD
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   873
    { SI_DETHREAD,  "SI_DETHREAD", "Signal sent by execve() killing subsidiary threads" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   874
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   875
#ifdef SI_KERNEL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   876
    { SI_KERNEL,    "SI_KERNEL",   "Signal sent by kernel." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   877
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   878
#ifdef SI_SIGIO
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   879
    { SI_SIGIO,     "SI_SIGIO",    "Signal sent by queued SIGIO" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   880
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   881
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   882
#ifdef AIX
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   883
    { SI_UNDEFINED, "SI_UNDEFINED","siginfo contains partial information" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   884
    { SI_EMPTY,     "SI_EMPTY",    "siginfo contains no useful information" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   885
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   886
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   887
#ifdef __sun
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   888
    { SI_NOINFO,    "SI_NOINFO",   "No signal information" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   889
    { SI_RCTL,      "SI_RCTL",     "kernel generated signal via rctl action" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   890
    { SI_LWP,       "SI_LWP",      "Signal sent via lwp_kill" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   891
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   892
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   893
    { -1, NULL, NULL }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   894
  };
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   895
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   896
  const char* s_code = NULL;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   897
  const char* s_desc = NULL;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   898
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   899
  for (int i = 0; t1[i].sig != -1; i ++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   900
    if (t1[i].sig == si->si_signo && t1[i].code == si->si_code) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   901
      s_code = t1[i].s_code;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   902
      s_desc = t1[i].s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   903
      break;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   904
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   905
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   906
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   907
  if (s_code == NULL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   908
    for (int i = 0; t2[i].s_code != NULL; i ++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   909
      if (t2[i].code == si->si_code) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   910
        s_code = t2[i].s_code;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   911
        s_desc = t2[i].s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   912
      }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   913
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   914
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   915
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   916
  if (s_code == NULL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   917
    out->s_name = "unknown";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   918
    out->s_desc = "unknown";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   919
    return false;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   920
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   921
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   922
  out->s_name = s_code;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   923
  out->s_desc = s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   924
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   925
  return true;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   926
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   927
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   928
// A POSIX conform, platform-independend siginfo print routine.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   929
// Short print out on one line.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   930
void os::Posix::print_siginfo_brief(outputStream* os, const siginfo_t* si) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   931
  char buf[20];
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   932
  os->print("siginfo: ");
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   933
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   934
  if (!si) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   935
    os->print("<null>");
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   936
    return;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   937
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   938
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   939
  // See print_siginfo_full() for details.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   940
  const int sig = si->si_signo;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   941
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   942
  os->print("si_signo: %d (%s)", sig, os::Posix::get_signal_name(sig, buf, sizeof(buf)));
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   943
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   944
  enum_sigcode_desc_t ed;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   945
  if (get_signal_code_description(si, &ed)) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   946
    os->print(", si_code: %d (%s)", si->si_code, ed.s_name);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   947
  } else {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   948
    os->print(", si_code: %d (unknown)", si->si_code);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   949
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   950
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   951
  if (si->si_errno) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   952
    os->print(", si_errno: %d", si->si_errno);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   953
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   954
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   955
  const int me = (int) ::getpid();
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   956
  const int pid = (int) si->si_pid;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   957
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   958
  if (si->si_code == SI_USER || si->si_code == SI_QUEUE) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   959
    if (IS_VALID_PID(pid) && pid != me) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   960
      os->print(", sent from pid: %d (uid: %d)", pid, (int) si->si_uid);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   961
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   962
  } else if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   963
             sig == SIGTRAP || sig == SIGFPE) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   964
    os->print(", si_addr: " PTR_FORMAT, si->si_addr);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   965
#ifdef SIGPOLL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   966
  } else if (sig == SIGPOLL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   967
    os->print(", si_band: " PTR64_FORMAT, (uint64_t)si->si_band);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   968
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   969
  } else if (sig == SIGCHLD) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   970
    os->print_cr(", si_pid: %d, si_uid: %d, si_status: %d", (int) si->si_pid, si->si_uid, si->si_status);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   971
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   972
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   973
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   974
os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   975
  assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   976
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   977
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   978
/*
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   979
 * See the caveats for this class in os_posix.hpp
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   980
 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   981
 * method and returns false. If none of the signals are raised, returns true.
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   982
 * The callback is supposed to provide the method that should be protected.
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   983
 */
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   984
bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
19691
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
   985
  sigset_t saved_sig_mask;
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
   986
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   987
  assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   988
  assert(!WatcherThread::watcher_thread()->has_crash_protection(),
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   989
      "crash_protection already set?");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   990
19691
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
   991
  // we cannot rely on sigsetjmp/siglongjmp to save/restore the signal mask
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
   992
  // since on at least some systems (OS X) siglongjmp will restore the mask
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
   993
  // for the process, not the thread
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
   994
  pthread_sigmask(0, NULL, &saved_sig_mask);
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
   995
  if (sigsetjmp(_jmpbuf, 0) == 0) {
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   996
    // 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
   997
    // installed
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   998
    WatcherThread::watcher_thread()->set_crash_protection(this);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   999
    cb.call();
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1000
    // and clear the crash protection
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1001
    WatcherThread::watcher_thread()->set_crash_protection(NULL);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1002
    return true;
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1003
  }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1004
  // this happens when we siglongjmp() back
19691
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
  1005
  pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL);
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1006
  WatcherThread::watcher_thread()->set_crash_protection(NULL);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1007
  return false;
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1008
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1009
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1010
void os::WatcherThreadCrashProtection::restore() {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1011
  assert(WatcherThread::watcher_thread()->has_crash_protection(),
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1012
      "must have crash protection");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1013
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1014
  siglongjmp(_jmpbuf, 1);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1015
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1016
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1017
void os::WatcherThreadCrashProtection::check_crash_protection(int sig,
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1018
    Thread* thread) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1019
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1020
  if (thread != NULL &&
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1021
      thread->is_Watcher_thread() &&
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1022
      WatcherThread::watcher_thread()->has_crash_protection()) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1023
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1024
    if (sig == SIGSEGV || sig == SIGBUS) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1025
      WatcherThread::watcher_thread()->crash_protection()->restore();
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1026
    }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1027
  }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1028
}
31610
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1029
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1030
#define check_with_errno(check_type, cond, msg)                                      \
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1031
  do {                                                                               \
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1032
    int err = errno;                                                                 \
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1033
    check_type(cond, err_msg("%s; error='%s' (errno=%d)", msg, strerror(err), err)); \
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1034
} while (false)
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1035
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1036
#define assert_with_errno(cond, msg)    check_with_errno(assert, cond, msg)
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1037
#define guarantee_with_errno(cond, msg) check_with_errno(guarantee, cond, msg)
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1038
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1039
// POSIX unamed semaphores are not supported on OS X.
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1040
#ifndef __APPLE__
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1041
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1042
PosixSemaphore::PosixSemaphore(uint value) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1043
  int ret = sem_init(&_semaphore, 0, value);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1044
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1045
  guarantee_with_errno(ret == 0, "Failed to initialize semaphore");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1046
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1047
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1048
PosixSemaphore::~PosixSemaphore() {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1049
  sem_destroy(&_semaphore);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1050
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1051
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1052
void PosixSemaphore::signal(uint count) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1053
  for (uint i = 0; i < count; i++) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1054
    int ret = sem_post(&_semaphore);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1055
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1056
    assert_with_errno(ret == 0, "sem_post failed");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1057
  }
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1058
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1059
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1060
void PosixSemaphore::wait() {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1061
  int ret;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1062
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1063
  do {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1064
    ret = sem_wait(&_semaphore);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1065
  } while (ret != 0 && errno == EINTR);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1066
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1067
  assert_with_errno(ret == 0, "sem_wait failed");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1068
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1069
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1070
bool PosixSemaphore::trywait() {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1071
  int ret;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1072
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1073
  do {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1074
    ret = sem_trywait(&_semaphore);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1075
  } while (ret != 0 && errno == EINTR);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1076
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1077
  assert_with_errno(ret == 0 || errno == EAGAIN, "trywait failed");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1078
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1079
  return ret == 0;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1080
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1081
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1082
bool PosixSemaphore::timedwait(const struct timespec ts) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1083
  while (true) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1084
    int result = sem_timedwait(&_semaphore, &ts);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1085
    if (result == 0) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1086
      return true;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1087
    } else if (errno == EINTR) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1088
      continue;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1089
    } else if (errno == ETIMEDOUT) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1090
      return false;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1091
    } else {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1092
      assert_with_errno(false, "timedwait failed");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1093
      return false;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1094
    }
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1095
  }
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1096
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1097
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1098
#endif // __APPLE__