hotspot/src/os/posix/vm/os_posix.cpp
author stuefe
Tue, 13 Jun 2017 08:09:17 +0200
changeset 46558 13de3946d61e
parent 46508 278005442848
child 46618 d503911aa948
permissions -rw-r--r--
8182034: os::Posix::is_valid_signal() should, if it uses sigaddset, initialize the signal set Summary: Added missing sigemptyset. Reviewed-by: kbarrett, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
     1
/*
46331
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
     2
 * Copyright (c) 1999, 2017, 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"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
    31
#include "utilities/macros.hpp"
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    32
#include "utilities/vmError.hpp"
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    33
46507
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
    34
#include <dlfcn.h>
19691
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
    35
#include <pthread.h>
31610
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
    36
#include <semaphore.h>
19691
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
    37
#include <signal.h>
46507
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
    38
#include <sys/resource.h>
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
    39
#include <sys/utsname.h>
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
    40
#include <time.h>
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
    41
#include <unistd.h>
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
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) {
38254
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents: 38065
diff changeset
    52
  if (!FLAG_IS_DEFAULT(CreateCoredumpOnCrash) && !CreateCoredumpOnCrash) {
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents: 38065
diff changeset
    53
    jio_snprintf(buffer, bufferSize, "CreateCoredumpOnCrash is disabled from command line");
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents: 38065
diff changeset
    54
    VMError::record_coredump_status(buffer, false);
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents: 38065
diff changeset
    55
    return;
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents: 38065
diff changeset
    56
  }
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents: 38065
diff changeset
    57
13198
271c557a7623 7129724: MAC: Core file location is wrong in crash report
mikael
parents: 13195
diff changeset
    58
  int n;
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    59
  struct rlimit rlim;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    60
  bool success;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    61
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    62
  char core_path[PATH_MAX];
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    63
  n = get_core_path(core_path, PATH_MAX);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    64
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    65
  if (n <= 0) {
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    66
    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
    67
    success = true;
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    68
#ifdef LINUX
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    69
  } else if (core_path[0] == '"') { // redirect to user process
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    70
    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
    71
    success = true;
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    72
#endif
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    73
  } else if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    74
    jio_snprintf(buffer, bufferSize, "%s (may not exist)", core_path);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    75
    success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    76
  } else {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    77
    switch(rlim.rlim_cur) {
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    78
      case RLIM_INFINITY:
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    79
        jio_snprintf(buffer, bufferSize, "%s", core_path);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    80
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    81
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    82
      case 0:
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    83
        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
    84
        success = false;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    85
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    86
      default:
46508
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
    87
        jio_snprintf(buffer, bufferSize, "%s (max size " UINT64_FORMAT " kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", core_path, uint64_t(rlim.rlim_cur) / 1024);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    88
        success = true;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    89
        break;
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    90
    }
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    91
  }
28172
19ae5c844e75 8059586: hs_err report should treat redirected core pattern
dholmes
parents: 28166
diff changeset
    92
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 28172
diff changeset
    93
  VMError::record_coredump_status(buffer, success);
8119
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    94
}
81eef1b06988 7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
diff changeset
    95
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    96
int os::get_native_stack(address* stack, int frames, int toSkip) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    97
  int frame_idx = 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    98
  int num_of_frames;  // number of frames captured
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
    99
  frame fr = os::current_frame();
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   100
  while (fr.pc() && frame_idx < frames) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   101
    if (toSkip > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   102
      toSkip --;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   103
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   104
      stack[frame_idx ++] = fr.pc();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   105
    }
28166
e42212b64568 8066803: compiler/intrinsics/mathexact/SubExactINonConstantTest.java crashed in os::is_first_C_frame(frame*)
coleenp
parents: 27471
diff changeset
   106
    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
   107
        fr.sender_pc() == NULL || os::is_first_C_frame(&fr)) break;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   108
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   109
    if (fr.sender_pc() && !os::is_first_C_frame(&fr)) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   110
      fr = os::get_sender_for_C_frame(&fr);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   111
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   112
      break;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   113
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
   114
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   115
  num_of_frames = frame_idx;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   116
  for (; frame_idx < frames; frame_idx ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   117
    stack[frame_idx] = NULL;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
   118
  }
25946
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
  return num_of_frames;
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   123
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   124
bool os::unsetenv(const char* name) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   125
  assert(name != NULL, "Null pointer");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   126
  return (::unsetenv(name) == 0);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
   127
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12735
diff changeset
   128
11418
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
   129
int os::get_last_error() {
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
   130
  return errno;
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
   131
}
66ca80da30e2 7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents: 8476
diff changeset
   132
8476
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   133
bool os::is_debugger_attached() {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   134
  // not implemented
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   135
  return false;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   136
}
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   137
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   138
void os::wait_for_keypress_at_exit(void) {
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   139
  // don't do anything on posix platforms
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   140
  return;
7e34c2d4cf9b 7022037: Pause when exiting if debugger is attached on windows
sla
parents: 8119
diff changeset
   141
}
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   142
14840
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   143
// 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
   144
// 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
   145
// 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
   146
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
   147
  assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   148
      "Alignment must be a multiple of allocation granularity (page size)");
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   149
  assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   150
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   151
  size_t extra_size = size + alignment;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   152
  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
   153
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   154
  char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   155
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   156
  if (extra_base == NULL) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   157
    return NULL;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   158
  }
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   159
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   160
  // Do manual alignment
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   161
  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
   162
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   163
  // [  |                                       |  ]
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   164
  // ^ extra_base
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   165
  //    ^ extra_base + begin_offset == aligned_base
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   166
  //     extra_base + begin_offset + size       ^
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   167
  //                       extra_base + extra_size ^
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   168
  // |<>| == begin_offset
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   169
  //                              end_offset == |<>|
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   170
  size_t begin_offset = aligned_base - extra_base;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   171
  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
   172
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   173
  if (begin_offset > 0) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   174
      os::release_memory(extra_base, begin_offset);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   175
  }
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   176
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   177
  if (end_offset > 0) {
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   178
      os::release_memory(extra_base + begin_offset + size, end_offset);
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   179
  }
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
  return aligned_base;
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   182
}
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13963
diff changeset
   183
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents: 33148
diff changeset
   184
int os::log_vsnprintf(char* buf, size_t len, const char* fmt, va_list args) {
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents: 33148
diff changeset
   185
    return vsnprintf(buf, len, fmt, args);
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents: 33148
diff changeset
   186
}
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents: 33148
diff changeset
   187
38065
025c784d9333 8154921: Fix aix after "8146879: Add option for handling existing log files in UL"
goetz
parents: 37465
diff changeset
   188
int os::get_fileno(FILE* fp) {
025c784d9333 8154921: Fix aix after "8146879: Add option for handling existing log files in UL"
goetz
parents: 37465
diff changeset
   189
  return NOT_AIX(::)fileno(fp);
37465
1d5551f466ee 8146879: Add option for handling existing log files in UL
mlarsson
parents: 37113
diff changeset
   190
}
1d5551f466ee 8146879: Add option for handling existing log files in UL
mlarsson
parents: 37113
diff changeset
   191
42066
46f6db750b17 8166117: Add UTC timestamp decorator for UL
mlarsson
parents: 41070
diff changeset
   192
struct tm* os::gmtime_pd(const time_t* clock, struct tm*  res) {
46f6db750b17 8166117: Add UTC timestamp decorator for UL
mlarsson
parents: 41070
diff changeset
   193
  return gmtime_r(clock, res);
46f6db750b17 8166117: Add UTC timestamp decorator for UL
mlarsson
parents: 41070
diff changeset
   194
}
46f6db750b17 8166117: Add UTC timestamp decorator for UL
mlarsson
parents: 41070
diff changeset
   195
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   196
void os::Posix::print_load_average(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   197
  st->print("load average:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   198
  double loadavg[3];
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   199
  os::loadavg(loadavg, 3);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   200
  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
   201
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   202
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   203
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   204
void os::Posix::print_rlimit_info(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   205
  st->print("rlimit:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   206
  struct rlimit rlim;
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   207
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   208
  st->print(" STACK ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   209
  getrlimit(RLIMIT_STACK, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   210
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
46508
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   211
  else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   212
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   213
  st->print(", CORE ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   214
  getrlimit(RLIMIT_CORE, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   215
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
46508
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   216
  else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   217
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   218
  // Isn't there on solaris
46508
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   219
#if defined(AIX)
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   220
  st->print(", NPROC ");
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   221
  st->print("%d", sysconf(_SC_CHILD_MAX));
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   222
#elif !defined(SOLARIS)
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   223
  st->print(", NPROC ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   224
  getrlimit(RLIMIT_NPROC, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   225
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
46451
a4a8613c08e9 8180039: Use more portable print format/arguments for rlim_t
mikael
parents: 46346
diff changeset
   226
  else st->print(UINT64_FORMAT, uint64_t(rlim.rlim_cur));
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   227
#endif
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   228
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   229
  st->print(", NOFILE ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   230
  getrlimit(RLIMIT_NOFILE, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   231
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
46451
a4a8613c08e9 8180039: Use more portable print format/arguments for rlim_t
mikael
parents: 46346
diff changeset
   232
  else st->print(UINT64_FORMAT, uint64_t(rlim.rlim_cur));
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   233
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   234
  st->print(", AS ");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   235
  getrlimit(RLIMIT_AS, &rlim);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   236
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
46508
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   237
  else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   238
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   239
  st->print(", DATA ");
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   240
  getrlimit(RLIMIT_DATA, &rlim);
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   241
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   242
  else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   243
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   244
  st->print(", FSIZE ");
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   245
  getrlimit(RLIMIT_FSIZE, &rlim);
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   246
  if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   247
  else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
278005442848 8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents: 46507
diff changeset
   248
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   249
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   250
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   251
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   252
void os::Posix::print_uname_info(outputStream* st) {
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   253
  // kernel
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   254
  st->print("uname:");
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   255
  struct utsname name;
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   256
  uname(&name);
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   257
  st->print("%s ", name.sysname);
26569
5fcbc13c071c 8056930: Output host info under some condition for core dump
minqi
parents: 25946
diff changeset
   258
#ifdef ASSERT
5fcbc13c071c 8056930: Output host info under some condition for core dump
minqi
parents: 25946
diff changeset
   259
  st->print("%s ", name.nodename);
5fcbc13c071c 8056930: Output host info under some condition for core dump
minqi
parents: 25946
diff changeset
   260
#endif
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   261
  st->print("%s ", name.release);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   262
  st->print("%s ", name.version);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22894
diff changeset
   263
  st->print("%s", name.machine);
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   264
  st->cr();
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   265
}
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   266
31963
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   267
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
   268
  struct utsname name;
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   269
  uname(&name);
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   270
  jio_snprintf(buf, buflen, "%s", name.nodename);
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   271
  return true;
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   272
}
641ed52732ec 8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents: 31610
diff changeset
   273
16605
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   274
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
   275
  struct rlimit rlim;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   276
  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
   277
  // 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
   278
  // on virtual memory.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   279
  bool result;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   280
  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
   281
    result = false;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   282
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   283
    *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
   284
    result = true;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   285
  }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   286
#ifdef _LP64
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   287
  return result;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   288
#else
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   289
  // 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
   290
  // 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
   291
  // directly use it.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   292
  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
   293
  if (result) {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   294
    *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
   295
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   296
    *limit = max_virtual_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   297
  }
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 11418
diff changeset
   298
16605
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   299
  // 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
   300
  // 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
   301
  // 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
   302
  // 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
   303
  // 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
   304
  // 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
   305
  // 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
   306
  // 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
   307
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   308
  // 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
   309
  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
   310
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   311
  julong upper_limit = *limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   312
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   313
  // 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
   314
  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
   315
    *limit = upper_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   316
  } 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
   317
    // 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
   318
    // 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
   319
    *limit = min_allocation_size;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   320
  } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   321
    // perform the binary search.
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   322
    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
   323
    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
   324
      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
   325
      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
   326
      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
   327
        lower_limit = temp_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   328
      } else {
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   329
        upper_limit = temp_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   330
      }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   331
    }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   332
    *limit = lower_limit;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   333
  }
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   334
  return true;
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   335
#endif
ba13efd453bc 7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents: 14840
diff changeset
   336
}
17121
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   337
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   338
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
   339
  return getcwd(buf, buflen);
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   340
}
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   341
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   342
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
   343
  return ::fdopen(fd, mode);
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 16605
diff changeset
   344
}
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
   345
38263
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 38254
diff changeset
   346
void os::flockfile(FILE* fp) {
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 38254
diff changeset
   347
  ::flockfile(fp);
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 38254
diff changeset
   348
}
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 38254
diff changeset
   349
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 38254
diff changeset
   350
void os::funlockfile(FILE* fp) {
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 38254
diff changeset
   351
  ::funlockfile(fp);
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 38254
diff changeset
   352
}
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 38254
diff changeset
   353
19553
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   354
// 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
   355
// 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
   356
// Parameters:
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   357
//            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
   358
//            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
   359
//            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
   360
//                                     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
   361
//            == 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
   362
//               such as "L"
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   363
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
   364
                                    bool is_absolute_path) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   365
  char *agent_entry_name;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   366
  size_t len;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   367
  size_t name_len;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   368
  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
   369
  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
   370
  const char *start;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   371
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   372
  if (lib_name != NULL) {
36585
00416e804a66 8147456: Parsing of argument for -agentpath can write outside of allocated memory
dsamersoff
parents: 36355
diff changeset
   373
    name_len = strlen(lib_name);
19553
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   374
    if (is_absolute_path) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   375
      // 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
   376
      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
   377
        lib_name = ++start;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   378
      }
36585
00416e804a66 8147456: Parsing of argument for -agentpath can write outside of allocated memory
dsamersoff
parents: 36355
diff changeset
   379
      if (strlen(lib_name) <= (prefix_len + suffix_len)) {
19553
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   380
        return NULL;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   381
      }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   382
      lib_name += prefix_len;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   383
      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
   384
    }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   385
  }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   386
  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
   387
  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
   388
  if (agent_entry_name == NULL) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   389
    return NULL;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   390
  }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   391
  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
   392
  if (lib_name != NULL) {
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   393
    strcat(agent_entry_name, "_");
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   394
    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
   395
  }
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   396
  return agent_entry_name;
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   397
}
9bbd930be684 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 18943
diff changeset
   398
22891
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   399
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
   400
  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
   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
  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
   403
  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
   404
  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
   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
  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
   407
    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
   408
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   409
    for (;;) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   410
      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
   411
        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
   412
      }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   413
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 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
   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
      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
   417
        // 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
   418
        // 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
   419
        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
   420
      } else {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   421
        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
   422
      }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   423
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   424
      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
   425
        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
   426
      }
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
      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
   429
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
        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
   432
        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
   433
        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
   434
        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
   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
        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
   437
        // 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
   438
        // 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
   439
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   440
        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
   441
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   442
        // 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
   443
        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
   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
    }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   446
  } else {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   447
    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
   448
    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
   449
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   450
    for (;;) {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   451
      // 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
   452
      // 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
   453
      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
   454
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   455
      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
   456
        // 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
   457
        // 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
   458
        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
   459
      } else {
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   460
        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
   461
      }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   462
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   463
      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
   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
      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
   466
      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
   467
    }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   468
    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
   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
}
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
////////////////////////////////////////////////////////////////////////////////
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   473
// 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
   474
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   475
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
   476
  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
   477
    "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
   478
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   479
  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
   480
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   481
  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
   482
    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
   483
    // 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
   484
    // 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
   485
    // 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
   486
    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
   487
    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
   488
    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
   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
  // 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
   492
  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
   493
    ((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
   494
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   495
  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
   496
  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
   497
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   498
}
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   499
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   500
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
   501
  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
   502
    "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
   503
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   504
  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
   505
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   506
  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
   507
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   508
  // 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
   509
  // 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
   510
  // 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
   511
  // 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
   512
  // 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
   513
  // 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
   514
  // 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
   515
  // 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
   516
  // 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
   517
  // 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
   518
  // 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
   519
  // 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
   520
  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
   521
    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
   522
    // 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
   523
  }
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   524
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   525
  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
   526
}
1f5d1fff23fa 6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents: 22528
diff changeset
   527
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   528
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   529
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   530
static const struct {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   531
  int sig; const char* name;
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   532
}
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   533
 g_signal_info[] =
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   534
  {
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   535
  {  SIGABRT,     "SIGABRT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   536
#ifdef SIGAIO
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   537
  {  SIGAIO,      "SIGAIO" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   538
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   539
  {  SIGALRM,     "SIGALRM" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   540
#ifdef SIGALRM1
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   541
  {  SIGALRM1,    "SIGALRM1" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   542
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   543
  {  SIGBUS,      "SIGBUS" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   544
#ifdef SIGCANCEL
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   545
  {  SIGCANCEL,   "SIGCANCEL" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   546
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   547
  {  SIGCHLD,     "SIGCHLD" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   548
#ifdef SIGCLD
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   549
  {  SIGCLD,      "SIGCLD" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   550
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   551
  {  SIGCONT,     "SIGCONT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   552
#ifdef SIGCPUFAIL
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   553
  {  SIGCPUFAIL,  "SIGCPUFAIL" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   554
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   555
#ifdef SIGDANGER
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   556
  {  SIGDANGER,   "SIGDANGER" },
22826
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 SIGDIL
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   559
  {  SIGDIL,      "SIGDIL" },
22826
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
#ifdef SIGEMT
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   562
  {  SIGEMT,      "SIGEMT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   563
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   564
  {  SIGFPE,      "SIGFPE" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   565
#ifdef SIGFREEZE
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   566
  {  SIGFREEZE,   "SIGFREEZE" },
22826
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 SIGGFAULT
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   569
  {  SIGGFAULT,   "SIGGFAULT" },
22826
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 SIGGRANT
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   572
  {  SIGGRANT,    "SIGGRANT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   573
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   574
  {  SIGHUP,      "SIGHUP" },
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   575
  {  SIGILL,      "SIGILL" },
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   576
  {  SIGINT,      "SIGINT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   577
#ifdef SIGIO
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   578
  {  SIGIO,       "SIGIO" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   579
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   580
#ifdef SIGIOINT
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   581
  {  SIGIOINT,    "SIGIOINT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   582
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   583
#ifdef SIGIOT
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   584
// SIGIOT is there for BSD compatibility, but on most Unices just a
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   585
// synonym for SIGABRT. The result should be "SIGABRT", not
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   586
// "SIGIOT".
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   587
#if (SIGIOT != SIGABRT )
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   588
  {  SIGIOT,      "SIGIOT" },
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   589
#endif
22826
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
#ifdef SIGKAP
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   592
  {  SIGKAP,      "SIGKAP" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   593
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   594
  {  SIGKILL,     "SIGKILL" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   595
#ifdef SIGLOST
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   596
  {  SIGLOST,     "SIGLOST" },
22826
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 SIGLWP
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   599
  {  SIGLWP,      "SIGLWP" },
22826
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 SIGLWPTIMER
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   602
  {  SIGLWPTIMER, "SIGLWPTIMER" },
22826
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 SIGMIGRATE
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   605
  {  SIGMIGRATE,  "SIGMIGRATE" },
22826
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
#ifdef SIGMSG
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   608
  {  SIGMSG,      "SIGMSG" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   609
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   610
  {  SIGPIPE,     "SIGPIPE" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   611
#ifdef SIGPOLL
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   612
  {  SIGPOLL,     "SIGPOLL" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   613
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   614
#ifdef SIGPRE
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   615
  {  SIGPRE,      "SIGPRE" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   616
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   617
  {  SIGPROF,     "SIGPROF" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   618
#ifdef SIGPTY
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   619
  {  SIGPTY,      "SIGPTY" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   620
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   621
#ifdef SIGPWR
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   622
  {  SIGPWR,      "SIGPWR" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   623
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   624
  {  SIGQUIT,     "SIGQUIT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   625
#ifdef SIGRECONFIG
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   626
  {  SIGRECONFIG, "SIGRECONFIG" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   627
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   628
#ifdef SIGRECOVERY
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   629
  {  SIGRECOVERY, "SIGRECOVERY" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   630
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   631
#ifdef SIGRESERVE
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   632
  {  SIGRESERVE,  "SIGRESERVE" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   633
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   634
#ifdef SIGRETRACT
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   635
  {  SIGRETRACT,  "SIGRETRACT" },
22826
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
#ifdef SIGSAK
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   638
  {  SIGSAK,      "SIGSAK" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   639
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   640
  {  SIGSEGV,     "SIGSEGV" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   641
#ifdef SIGSOUND
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   642
  {  SIGSOUND,    "SIGSOUND" },
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   643
#endif
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   644
#ifdef SIGSTKFLT
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   645
  {  SIGSTKFLT,    "SIGSTKFLT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   646
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   647
  {  SIGSTOP,     "SIGSTOP" },
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   648
  {  SIGSYS,      "SIGSYS" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   649
#ifdef SIGSYSERROR
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   650
  {  SIGSYSERROR, "SIGSYSERROR" },
22826
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
#ifdef SIGTALRM
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   653
  {  SIGTALRM,    "SIGTALRM" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   654
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   655
  {  SIGTERM,     "SIGTERM" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   656
#ifdef SIGTHAW
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   657
  {  SIGTHAW,     "SIGTHAW" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   658
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   659
  {  SIGTRAP,     "SIGTRAP" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   660
#ifdef SIGTSTP
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   661
  {  SIGTSTP,     "SIGTSTP" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   662
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   663
  {  SIGTTIN,     "SIGTTIN" },
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   664
  {  SIGTTOU,     "SIGTTOU" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   665
#ifdef SIGURG
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   666
  {  SIGURG,      "SIGURG" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   667
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   668
  {  SIGUSR1,     "SIGUSR1" },
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   669
  {  SIGUSR2,     "SIGUSR2" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   670
#ifdef SIGVIRT
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   671
  {  SIGVIRT,     "SIGVIRT" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   672
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   673
  {  SIGVTALRM,   "SIGVTALRM" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   674
#ifdef SIGWAITING
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   675
  {  SIGWAITING,  "SIGWAITING" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   676
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   677
#ifdef SIGWINCH
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   678
  {  SIGWINCH,    "SIGWINCH" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   679
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   680
#ifdef SIGWINDOW
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   681
  {  SIGWINDOW,   "SIGWINDOW" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   682
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   683
  {  SIGXCPU,     "SIGXCPU" },
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   684
  {  SIGXFSZ,     "SIGXFSZ" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   685
#ifdef SIGXRES
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   686
  {  SIGXRES,     "SIGXRES" },
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   687
#endif
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   688
  { -1, NULL }
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   689
};
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   690
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   691
// Returned string is a constant. For unknown signals "UNKNOWN" is returned.
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   692
const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) {
22826
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
  const char* ret = NULL;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   695
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   696
#ifdef SIGRTMIN
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   697
  if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   698
    if (sig == SIGRTMIN) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   699
      ret = "SIGRTMIN";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   700
    } else if (sig == SIGRTMAX) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   701
      ret = "SIGRTMAX";
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
      jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   704
      return out;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   705
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   706
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   707
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   708
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   709
  if (sig > 0) {
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   710
    for (int idx = 0; g_signal_info[idx].sig != -1; idx ++) {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   711
      if (g_signal_info[idx].sig == sig) {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   712
        ret = g_signal_info[idx].name;
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   713
        break;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   714
      }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   715
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   716
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   717
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   718
  if (!ret) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   719
    if (!is_valid_signal(sig)) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   720
      ret = "INVALID";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   721
    } else {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   722
      ret = "UNKNOWN";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   723
    }
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
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 26569
diff changeset
   726
  if (out && outlen > 0) {
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 26569
diff changeset
   727
    strncpy(out, ret, outlen);
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 26569
diff changeset
   728
    out[outlen - 1] = '\0';
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 26569
diff changeset
   729
  }
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   730
  return out;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   731
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   732
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   733
int os::Posix::get_signal_number(const char* signal_name) {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   734
  char tmp[30];
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   735
  const char* s = signal_name;
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   736
  if (s[0] != 'S' || s[1] != 'I' || s[2] != 'G') {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   737
    jio_snprintf(tmp, sizeof(tmp), "SIG%s", signal_name);
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   738
    s = tmp;
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   739
  }
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   740
  for (int idx = 0; g_signal_info[idx].sig != -1; idx ++) {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   741
    if (strcmp(g_signal_info[idx].name, s) == 0) {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   742
      return g_signal_info[idx].sig;
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   743
    }
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   744
  }
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   745
  return -1;
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   746
}
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   747
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   748
int os::get_signal_number(const char* signal_name) {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   749
  return os::Posix::get_signal_number(signal_name);
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   750
}
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   751
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   752
// Returns true if signal number is valid.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   753
bool os::Posix::is_valid_signal(int sig) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   754
  // MacOS not really POSIX compliant: sigaddset does not return
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   755
  // an error for invalid signal numbers. However, MacOS does not
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   756
  // support real time signals and simply seems to have just 33
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   757
  // signals with no holes in the signal range.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   758
#ifdef __APPLE__
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   759
  return sig >= 1 && sig < NSIG;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   760
#else
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   761
  // Use sigaddset to check for signal validity.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   762
  sigset_t set;
46558
13de3946d61e 8182034: os::Posix::is_valid_signal() should, if it uses sigaddset, initialize the signal set
stuefe
parents: 46508
diff changeset
   763
  sigemptyset(&set);
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   764
  if (sigaddset(&set, sig) == -1 && errno == EINVAL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   765
    return false;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   766
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   767
  return true;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   768
#endif
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
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   771
// Returns:
35047
b1f924d2efe8 8145073: Filename and linenumber are not printed for asserts any more.
david
parents: 34621
diff changeset
   772
// NULL for an invalid signal number
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   773
// "SIG<num>" for a valid but unknown signal number
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   774
// signal name otherwise.
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   775
const char* os::exception_name(int sig, char* buf, size_t size) {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   776
  if (!os::Posix::is_valid_signal(sig)) {
35047
b1f924d2efe8 8145073: Filename and linenumber are not printed for asserts any more.
david
parents: 34621
diff changeset
   777
    return NULL;
34621
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   778
  }
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   779
  const char* const name = os::Posix::get_signal_name(sig, buf, size);
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   780
  if (strcmp(name, "UNKNOWN") == 0) {
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   781
    jio_snprintf(buf, size, "SIG%d", sig);
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   782
  }
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   783
  return buf;
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   784
}
7676bec20997 8143291: Remove redundant coding around os::exception_name
stuefe
parents: 34305
diff changeset
   785
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   786
#define NUM_IMPORTANT_SIGS 32
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   787
// 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
   788
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
   789
  assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size");
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   790
  // Note: for shortness, just print out the first 32. That should
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   791
  // cover most of the useful ones, apart from realtime signals.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   792
  for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   793
    const int rc = sigismember(set, sig);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   794
    if (rc == -1 && errno == EINVAL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   795
      buffer[sig-1] = '?';
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   796
    } else {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   797
      buffer[sig-1] = rc == 0 ? '0' : '1';
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   798
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   799
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   800
  buffer[NUM_IMPORTANT_SIGS] = 0;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   801
  return buffer;
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
// Prints one-line description of a signal set.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   805
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
   806
  char buf[NUM_IMPORTANT_SIGS + 1];
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   807
  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
   808
  st->print("%s", buf);
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   809
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   810
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   811
// 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
   812
// provided buffer. Returns that buffer.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   813
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
   814
  char* p = buffer;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   815
  size_t remaining = size;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   816
  bool first = true;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   817
  int idx = 0;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   818
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   819
  assert(buffer, "invalid argument");
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   820
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   821
  if (size == 0) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   822
    return buffer;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   823
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   824
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   825
  strncpy(buffer, "none", size);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   827
  const struct {
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35077
diff changeset
   828
    // NB: i is an unsigned int here because SA_RESETHAND is on some
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35077
diff changeset
   829
    // systems 0x80000000, which is implicitly unsigned.  Assignining
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35077
diff changeset
   830
    // it to an int field would be an overflow in unsigned-to-signed
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35077
diff changeset
   831
    // conversion.
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35077
diff changeset
   832
    unsigned int i;
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   833
    const char* s;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   834
  } flaginfo [] = {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   835
    { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   836
    { SA_ONSTACK,   "SA_ONSTACK"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   837
    { SA_RESETHAND, "SA_RESETHAND" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   838
    { SA_RESTART,   "SA_RESTART"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   839
    { SA_SIGINFO,   "SA_SIGINFO"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   840
    { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   841
    { SA_NODEFER,   "SA_NODEFER"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   842
#ifdef AIX
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   843
    { SA_ONSTACK,   "SA_ONSTACK"   },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   844
    { SA_OLDSTYLE,  "SA_OLDSTYLE"  },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   845
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   846
    { 0, NULL }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   847
  };
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   848
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   849
  for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   850
    if (flags & flaginfo[idx].i) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   851
      if (first) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   852
        jio_snprintf(p, remaining, "%s", flaginfo[idx].s);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   853
        first = false;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   854
      } else {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   855
        jio_snprintf(p, remaining, "|%s", flaginfo[idx].s);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   856
      }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   857
      const size_t len = strlen(p);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   858
      p += len;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   859
      remaining -= len;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   860
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   861
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   862
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   863
  buffer[size - 1] = '\0';
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   864
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   865
  return buffer;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   866
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   867
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   868
// Prints one-line description of a combination of sigaction.sa_flags.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   869
void os::Posix::print_sa_flags(outputStream* st, int flags) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   870
  char buffer[0x100];
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   871
  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
   872
  st->print("%s", buffer);
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   873
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   874
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   875
// Helper function for os::Posix::print_siginfo_...():
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   876
// return a textual description for signal code.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   877
struct enum_sigcode_desc_t {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   878
  const char* s_name;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   879
  const char* s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   880
};
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
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
   883
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   884
  const struct {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   885
    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
   886
  } t1 [] = {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   887
    { SIGILL,  ILL_ILLOPC,   "ILL_ILLOPC",   "Illegal opcode." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   888
    { SIGILL,  ILL_ILLOPN,   "ILL_ILLOPN",   "Illegal operand." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   889
    { SIGILL,  ILL_ILLADR,   "ILL_ILLADR",   "Illegal addressing mode." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   890
    { SIGILL,  ILL_ILLTRP,   "ILL_ILLTRP",   "Illegal trap." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   891
    { SIGILL,  ILL_PRVOPC,   "ILL_PRVOPC",   "Privileged opcode." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   892
    { SIGILL,  ILL_PRVREG,   "ILL_PRVREG",   "Privileged register." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   893
    { SIGILL,  ILL_COPROC,   "ILL_COPROC",   "Coprocessor error." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   894
    { SIGILL,  ILL_BADSTK,   "ILL_BADSTK",   "Internal stack error." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   895
#if defined(IA64) && defined(LINUX)
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   896
    { SIGILL,  ILL_BADIADDR, "ILL_BADIADDR", "Unimplemented instruction address" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   897
    { SIGILL,  ILL_BREAK,    "ILL_BREAK",    "Application Break instruction" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   898
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   899
    { SIGFPE,  FPE_INTDIV,   "FPE_INTDIV",   "Integer divide by zero." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   900
    { SIGFPE,  FPE_INTOVF,   "FPE_INTOVF",   "Integer overflow." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   901
    { SIGFPE,  FPE_FLTDIV,   "FPE_FLTDIV",   "Floating-point divide by zero." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   902
    { SIGFPE,  FPE_FLTOVF,   "FPE_FLTOVF",   "Floating-point overflow." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   903
    { SIGFPE,  FPE_FLTUND,   "FPE_FLTUND",   "Floating-point underflow." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   904
    { SIGFPE,  FPE_FLTRES,   "FPE_FLTRES",   "Floating-point inexact result." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   905
    { SIGFPE,  FPE_FLTINV,   "FPE_FLTINV",   "Invalid floating-point operation." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   906
    { SIGFPE,  FPE_FLTSUB,   "FPE_FLTSUB",   "Subscript out of range." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   907
    { SIGSEGV, SEGV_MAPERR,  "SEGV_MAPERR",  "Address not mapped to object." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   908
    { SIGSEGV, SEGV_ACCERR,  "SEGV_ACCERR",  "Invalid permissions for mapped object." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   909
#ifdef AIX
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   910
    // no explanation found what keyerr would be
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   911
    { SIGSEGV, SEGV_KEYERR,  "SEGV_KEYERR",  "key error" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   912
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   913
#if defined(IA64) && !defined(AIX)
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   914
    { SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   915
#endif
34233
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   916
#if defined(__sparc) && defined(SOLARIS)
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   917
// define Solaris Sparc M7 ADI SEGV signals
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   918
#if !defined(SEGV_ACCADI)
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   919
#define SEGV_ACCADI 3
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   920
#endif
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   921
    { SIGSEGV, SEGV_ACCADI,  "SEGV_ACCADI",  "ADI not enabled for mapped object." },
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   922
#if !defined(SEGV_ACCDERR)
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   923
#define SEGV_ACCDERR 4
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   924
#endif
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   925
    { SIGSEGV, SEGV_ACCDERR, "SEGV_ACCDERR", "ADI disrupting exception." },
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   926
#if !defined(SEGV_ACCPERR)
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   927
#define SEGV_ACCPERR 5
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   928
#endif
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   929
    { SIGSEGV, SEGV_ACCPERR, "SEGV_ACCPERR", "ADI precise exception." },
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents: 33766
diff changeset
   930
#endif // defined(__sparc) && defined(SOLARIS)
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   931
    { SIGBUS,  BUS_ADRALN,   "BUS_ADRALN",   "Invalid address alignment." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   932
    { SIGBUS,  BUS_ADRERR,   "BUS_ADRERR",   "Nonexistent physical address." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   933
    { SIGBUS,  BUS_OBJERR,   "BUS_OBJERR",   "Object-specific hardware error." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   934
    { SIGTRAP, TRAP_BRKPT,   "TRAP_BRKPT",   "Process breakpoint." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   935
    { SIGTRAP, TRAP_TRACE,   "TRAP_TRACE",   "Process trace trap." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   936
    { SIGCHLD, CLD_EXITED,   "CLD_EXITED",   "Child has exited." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   937
    { 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
   938
    { 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
   939
    { SIGCHLD, CLD_TRAPPED,  "CLD_TRAPPED",  "Traced child has trapped." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   940
    { SIGCHLD, CLD_STOPPED,  "CLD_STOPPED",  "Child has stopped." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   941
    { SIGCHLD, CLD_CONTINUED,"CLD_CONTINUED","Stopped child has continued." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   942
#ifdef SIGPOLL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   943
    { SIGPOLL, POLL_OUT,     "POLL_OUT",     "Output buffers available." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   944
    { SIGPOLL, POLL_MSG,     "POLL_MSG",     "Input message available." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   945
    { SIGPOLL, POLL_ERR,     "POLL_ERR",     "I/O error." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   946
    { SIGPOLL, POLL_PRI,     "POLL_PRI",     "High priority input available." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   947
    { SIGPOLL, POLL_HUP,     "POLL_HUP",     "Device disconnected. [Option End]" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   948
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   949
    { -1, -1, NULL, NULL }
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
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   952
  // Codes valid in any signal context.
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   953
  const struct {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   954
    int code; const char* s_code; const char* s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   955
  } t2 [] = {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   956
    { SI_USER,      "SI_USER",     "Signal sent by kill()." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   957
    { SI_QUEUE,     "SI_QUEUE",    "Signal sent by the sigqueue()." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   958
    { 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
   959
    { 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
   960
    { 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
   961
    // Linux specific
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   962
#ifdef SI_TKILL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   963
    { SI_TKILL,     "SI_TKILL",    "Signal sent by tkill (pthread_kill)" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   964
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   965
#ifdef SI_DETHREAD
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   966
    { SI_DETHREAD,  "SI_DETHREAD", "Signal sent by execve() killing subsidiary threads" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   967
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   968
#ifdef SI_KERNEL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   969
    { SI_KERNEL,    "SI_KERNEL",   "Signal sent by kernel." },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   970
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   971
#ifdef SI_SIGIO
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   972
    { SI_SIGIO,     "SI_SIGIO",    "Signal sent by queued SIGIO" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   973
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   974
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   975
#ifdef AIX
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   976
    { SI_UNDEFINED, "SI_UNDEFINED","siginfo contains partial information" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   977
    { SI_EMPTY,     "SI_EMPTY",    "siginfo contains no useful information" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   978
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   979
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   980
#ifdef __sun
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   981
    { SI_NOINFO,    "SI_NOINFO",   "No signal information" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   982
    { SI_RCTL,      "SI_RCTL",     "kernel generated signal via rctl action" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   983
    { SI_LWP,       "SI_LWP",      "Signal sent via lwp_kill" },
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   984
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   985
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   986
    { -1, NULL, NULL }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   987
  };
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   988
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   989
  const char* s_code = NULL;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   990
  const char* s_desc = NULL;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   991
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   992
  for (int i = 0; t1[i].sig != -1; i ++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   993
    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
   994
      s_code = t1[i].s_code;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   995
      s_desc = t1[i].s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   996
      break;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   997
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   998
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
   999
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1000
  if (s_code == NULL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1001
    for (int i = 0; t2[i].s_code != NULL; i ++) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1002
      if (t2[i].code == si->si_code) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1003
        s_code = t2[i].s_code;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1004
        s_desc = t2[i].s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1005
      }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1006
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1007
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1008
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1009
  if (s_code == NULL) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1010
    out->s_name = "unknown";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1011
    out->s_desc = "unknown";
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1012
    return false;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1013
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1014
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1015
  out->s_name = s_code;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1016
  out->s_desc = s_desc;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1017
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1018
  return true;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1019
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1020
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1021
void os::print_siginfo(outputStream* os, const void* si0) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1022
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1023
  const siginfo_t* const si = (const siginfo_t*) si0;
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1024
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1025
  char buf[20];
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1026
  os->print("siginfo:");
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1027
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1028
  if (!si) {
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1029
    os->print(" <null>");
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1030
    return;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1031
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1032
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1033
  const int sig = si->si_signo;
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1034
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1035
  os->print(" si_signo: %d (%s)", sig, os::Posix::get_signal_name(sig, buf, sizeof(buf)));
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1036
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1037
  enum_sigcode_desc_t ed;
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1038
  get_signal_code_description(si, &ed);
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1039
  os->print(", si_code: %d (%s)", si->si_code, ed.s_name);
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1040
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1041
  if (si->si_errno) {
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1042
    os->print(", si_errno: %d", si->si_errno);
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1043
  }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1044
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1045
  // Output additional information depending on the signal code.
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1046
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1047
  // Note: Many implementations lump si_addr, si_pid, si_uid etc. together as unions,
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1048
  // so it depends on the context which member to use. For synchronous error signals,
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1049
  // we print si_addr, unless the signal was sent by another process or thread, in
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1050
  // which case we print out pid or tid of the sender.
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1051
  if (si->si_code == SI_USER || si->si_code == SI_QUEUE) {
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1052
    const pid_t pid = si->si_pid;
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1053
    os->print(", si_pid: %ld", (long) pid);
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1054
    if (IS_VALID_PID(pid)) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1055
      const pid_t me = getpid();
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1056
      if (me == pid) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1057
        os->print(" (current process)");
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1058
      }
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1059
    } else {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1060
      os->print(" (invalid)");
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1061
    }
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1062
    os->print(", si_uid: %ld", (long) si->si_uid);
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1063
    if (sig == SIGCHLD) {
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1064
      os->print(", si_status: %d", si->si_status);
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1065
    }
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1066
  } else if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1067
             sig == SIGTRAP || sig == SIGFPE) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
  1068
    os->print(", si_addr: " PTR_FORMAT, p2i(si->si_addr));
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1069
#ifdef SIGPOLL
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1070
  } else if (sig == SIGPOLL) {
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1071
    os->print(", si_band: %ld", si->si_band);
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1072
#endif
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1073
  }
35176
11a9d4022d9e 8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents: 35077
diff changeset
  1074
22826
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1075
}
3ee6886e718d 8020775: PPC64 (part 12): posix signal printing
goetz
parents: 18943
diff changeset
  1076
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1077
int os::Posix::unblock_thread_signal_mask(const sigset_t *set) {
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1078
  return pthread_sigmask(SIG_UNBLOCK, set, NULL);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1079
}
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1080
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35047
diff changeset
  1081
address os::Posix::ucontext_get_pc(const ucontext_t* ctx) {
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1082
#if defined(AIX)
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1083
   return Aix::ucontext_get_pc(ctx);
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1084
#elif defined(BSD)
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1085
   return Bsd::ucontext_get_pc(ctx);
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1086
#elif defined(LINUX)
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1087
   return Linux::ucontext_get_pc(ctx);
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1088
#elif defined(SOLARIS)
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1089
   return Solaris::ucontext_get_pc(ctx);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1090
#else
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1091
   VMError::report_and_die("unimplemented ucontext_get_pc");
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1092
#endif
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1093
}
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1094
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1095
void os::Posix::ucontext_set_pc(ucontext_t* ctx, address pc) {
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1096
#if defined(AIX)
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1097
   Aix::ucontext_set_pc(ctx, pc);
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1098
#elif defined(BSD)
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1099
   Bsd::ucontext_set_pc(ctx, pc);
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1100
#elif defined(LINUX)
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1101
   Linux::ucontext_set_pc(ctx, pc);
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38263
diff changeset
  1102
#elif defined(SOLARIS)
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1103
   Solaris::ucontext_set_pc(ctx, pc);
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1104
#else
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1105
   VMError::report_and_die("unimplemented ucontext_get_pc");
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1106
#endif
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1107
}
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1108
36355
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1109
char* os::Posix::describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr) {
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1110
  size_t stack_size = 0;
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1111
  size_t guard_size = 0;
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1112
  int detachstate = 0;
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1113
  pthread_attr_getstacksize(attr, &stack_size);
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1114
  pthread_attr_getguardsize(attr, &guard_size);
42905
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 42066
diff changeset
  1115
  // Work around linux NPTL implementation error, see also os::create_thread() in os_linux.cpp.
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 42066
diff changeset
  1116
  LINUX_ONLY(stack_size -= guard_size);
36355
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1117
  pthread_attr_getdetachstate(attr, &detachstate);
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1118
  jio_snprintf(buf, buflen, "stacksize: " SIZE_FORMAT "k, guardsize: " SIZE_FORMAT "k, %s",
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1119
    stack_size / 1024, guard_size / 1024,
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1120
    (detachstate == PTHREAD_CREATE_DETACHED ? "detached" : "joinable"));
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1121
  return buf;
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1122
}
dd339cbafd31 8149036: Add tracing for thread related events at os level
stuefe
parents: 36174
diff changeset
  1123
46331
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1124
char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen) {
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1125
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1126
  if (filename == NULL || outbuf == NULL || outbuflen < 1) {
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1127
    assert(false, "os::Posix::realpath: invalid arguments.");
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1128
    errno = EINVAL;
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1129
    return NULL;
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1130
  }
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1131
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1132
  char* result = NULL;
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1133
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1134
  // This assumes platform realpath() is implemented according to POSIX.1-2008.
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1135
  // POSIX.1-2008 allows to specify NULL for the output buffer, in which case
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1136
  // output buffer is dynamically allocated and must be ::free()'d by the caller.
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1137
  char* p = ::realpath(filename, NULL);
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1138
  if (p != NULL) {
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1139
    if (strlen(p) < outbuflen) {
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1140
      strcpy(outbuf, p);
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1141
      result = outbuf;
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1142
    } else {
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1143
      errno = ENAMETOOLONG;
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1144
    }
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1145
    ::free(p); // *not* os::free
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1146
  } else {
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1147
    // Fallback for platforms struggling with modern Posix standards (AIX 5.3, 6.1). If realpath
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1148
    // returns EINVAL, this may indicate that realpath is not POSIX.1-2008 compatible and
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1149
    // that it complains about the NULL we handed down as user buffer.
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1150
    // In this case, use the user provided buffer but at least check whether realpath caused
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1151
    // a memory overwrite.
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1152
    if (errno == EINVAL) {
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1153
      outbuf[outbuflen - 1] = '\0';
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1154
      p = ::realpath(filename, outbuf);
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1155
      if (p != NULL) {
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1156
        guarantee(outbuf[outbuflen - 1] == '\0', "realpath buffer overwrite detected.");
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1157
        result = p;
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1158
      }
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1159
    }
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1160
  }
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1161
  return result;
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1162
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1163
}
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1164
e3017116b9e5 8173848: realpath is unsafe
stuefe
parents: 42906
diff changeset
  1165
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1166
// Check minimum allowable stack sizes for thread creation and to initialize
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1167
// the java system classes, including StackOverflowError - depends on page
42906
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1168
// size.
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1169
// The space needed for frames during startup is platform dependent. It
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1170
// depends on word size, platform calling conventions, C frame layout and
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1171
// interpreter/C1/C2 design decisions. Therefore this is given in a
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1172
// platform (os/cpu) dependent constant.
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1173
// To this, space for guard mechanisms is added, which depends on the
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1174
// page size which again depends on the concrete system the VM is running
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1175
// on. Space for libc guard pages is not included in this size.
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1176
jint os::Posix::set_minimum_stack_sizes() {
46346
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1177
  size_t os_min_stack_allowed = SOLARIS_ONLY(thr_min_stack()) NOT_SOLARIS(PTHREAD_STACK_MIN);
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1178
42906
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1179
  _java_thread_min_stack_allowed = _java_thread_min_stack_allowed +
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1180
                                   JavaThread::stack_guard_zone_size() +
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1181
                                   JavaThread::stack_shadow_zone_size();
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1182
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1183
  _java_thread_min_stack_allowed = align_size_up(_java_thread_min_stack_allowed, vm_page_size());
46346
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1184
  _java_thread_min_stack_allowed = MAX2(_java_thread_min_stack_allowed, os_min_stack_allowed);
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1185
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1186
  size_t stack_size_in_bytes = ThreadStackSize * K;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1187
  if (stack_size_in_bytes != 0 &&
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1188
      stack_size_in_bytes < _java_thread_min_stack_allowed) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1189
    // The '-Xss' and '-XX:ThreadStackSize=N' options both set
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1190
    // ThreadStackSize so we go with "Java thread stack size" instead
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1191
    // of "ThreadStackSize" to be more friendly.
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1192
    tty->print_cr("\nThe Java thread stack size specified is too small. "
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1193
                  "Specify at least " SIZE_FORMAT "k",
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1194
                  _java_thread_min_stack_allowed / K);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1195
    return JNI_ERR;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1196
  }
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1197
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1198
  // Make the stack size a multiple of the page size so that
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1199
  // the yellow/red zones can be guarded.
42906
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1200
  JavaThread::set_stack_size_at_create(round_to(stack_size_in_bytes, vm_page_size()));
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1201
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1202
  // Reminder: a compiler thread is a Java thread.
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1203
  _compiler_thread_min_stack_allowed = _compiler_thread_min_stack_allowed +
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1204
                                       JavaThread::stack_guard_zone_size() +
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
  1205
                                       JavaThread::stack_shadow_zone_size();
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1206
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1207
  _compiler_thread_min_stack_allowed = align_size_up(_compiler_thread_min_stack_allowed, vm_page_size());
46346
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1208
  _compiler_thread_min_stack_allowed = MAX2(_compiler_thread_min_stack_allowed, os_min_stack_allowed);
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1209
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1210
  stack_size_in_bytes = CompilerThreadStackSize * K;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1211
  if (stack_size_in_bytes != 0 &&
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1212
      stack_size_in_bytes < _compiler_thread_min_stack_allowed) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1213
    tty->print_cr("\nThe CompilerThreadStackSize specified is too small. "
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1214
                  "Specify at least " SIZE_FORMAT "k",
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1215
                  _compiler_thread_min_stack_allowed / K);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1216
    return JNI_ERR;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1217
  }
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1218
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1219
  _vm_internal_thread_min_stack_allowed = align_size_up(_vm_internal_thread_min_stack_allowed, vm_page_size());
46346
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1220
  _vm_internal_thread_min_stack_allowed = MAX2(_vm_internal_thread_min_stack_allowed, os_min_stack_allowed);
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1221
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1222
  stack_size_in_bytes = VMThreadStackSize * K;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1223
  if (stack_size_in_bytes != 0 &&
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1224
      stack_size_in_bytes < _vm_internal_thread_min_stack_allowed) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1225
    tty->print_cr("\nThe VMThreadStackSize specified is too small. "
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1226
                  "Specify at least " SIZE_FORMAT "k",
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1227
                  _vm_internal_thread_min_stack_allowed / K);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1228
    return JNI_ERR;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1229
  }
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1230
  return JNI_OK;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1231
}
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1232
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1233
// Called when creating the thread.  The minimum stack sizes have already been calculated
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1234
size_t os::Posix::get_initial_stack_size(ThreadType thr_type, size_t req_stack_size) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1235
  size_t stack_size;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1236
  if (req_stack_size == 0) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1237
    stack_size = default_stack_size(thr_type);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1238
  } else {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1239
    stack_size = req_stack_size;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1240
  }
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1241
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1242
  switch (thr_type) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1243
  case os::java_thread:
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1244
    // Java threads use ThreadStackSize which default value can be
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1245
    // changed with the flag -Xss
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1246
    if (req_stack_size == 0 && JavaThread::stack_size_at_create() > 0) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1247
      // no requested size and we have a more specific default value
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1248
      stack_size = JavaThread::stack_size_at_create();
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1249
    }
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1250
    stack_size = MAX2(stack_size,
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1251
                      _java_thread_min_stack_allowed);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1252
    break;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1253
  case os::compiler_thread:
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1254
    if (req_stack_size == 0 && CompilerThreadStackSize > 0) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1255
      // no requested size and we have a more specific default value
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1256
      stack_size = (size_t)(CompilerThreadStackSize * K);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1257
    }
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1258
    stack_size = MAX2(stack_size,
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1259
                      _compiler_thread_min_stack_allowed);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1260
    break;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1261
  case os::vm_thread:
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1262
  case os::pgc_thread:
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1263
  case os::cgc_thread:
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1264
  case os::watcher_thread:
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1265
  default:  // presume the unknown thr_type is a VM internal
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1266
    if (req_stack_size == 0 && VMThreadStackSize > 0) {
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1267
      // no requested size and we have a more specific default value
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1268
      stack_size = (size_t)(VMThreadStackSize * K);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1269
    }
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1270
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1271
    stack_size = MAX2(stack_size,
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1272
                      _vm_internal_thread_min_stack_allowed);
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1273
    break;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1274
  }
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1275
46346
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1276
  // pthread_attr_setstacksize() may require that the size be rounded up to the OS page size.
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1277
  // Be careful not to round up to 0. Align down in that case.
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1278
  if (stack_size <= SIZE_MAX - vm_page_size()) {
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1279
    stack_size = align_size_up(stack_size, vm_page_size());
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1280
  } else {
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1281
    stack_size = align_size_down(stack_size, vm_page_size());
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1282
  }
4085295dcf51 8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents: 46331
diff changeset
  1283
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1284
  return stack_size;
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40383
diff changeset
  1285
}
34305
e399e6b44631 8136978: Much nearly duplicated code for vmError support
sebastian
parents: 34233
diff changeset
  1286
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1287
os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1288
  assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1289
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1290
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1291
/*
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1292
 * See the caveats for this class in os_posix.hpp
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1293
 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1294
 * method and returns false. If none of the signals are raised, returns true.
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1295
 * The callback is supposed to provide the method that should be protected.
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1296
 */
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1297
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
  1298
  sigset_t saved_sig_mask;
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
  1299
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1300
  assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1301
  assert(!WatcherThread::watcher_thread()->has_crash_protection(),
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1302
      "crash_protection already set?");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1303
19691
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
  1304
  // 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
  1305
  // 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
  1306
  // for the process, not the thread
5116fb76692a 8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents: 18943
diff changeset
  1307
  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
  1308
  if (sigsetjmp(_jmpbuf, 0) == 0) {
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1309
    // 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
  1310
    // installed
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1311
    WatcherThread::watcher_thread()->set_crash_protection(this);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1312
    cb.call();
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1313
    // and clear the crash protection
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1314
    WatcherThread::watcher_thread()->set_crash_protection(NULL);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1315
    return true;
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1316
  }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1317
  // 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
  1318
  pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL);
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1319
  WatcherThread::watcher_thread()->set_crash_protection(NULL);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1320
  return false;
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1321
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1322
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1323
void os::WatcherThreadCrashProtection::restore() {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1324
  assert(WatcherThread::watcher_thread()->has_crash_protection(),
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1325
      "must have crash protection");
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1326
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1327
  siglongjmp(_jmpbuf, 1);
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1328
}
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1329
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1330
void os::WatcherThreadCrashProtection::check_crash_protection(int sig,
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1331
    Thread* thread) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1332
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1333
  if (thread != NULL &&
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1334
      thread->is_Watcher_thread() &&
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1335
      WatcherThread::watcher_thread()->has_crash_protection()) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1336
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1337
    if (sig == SIGSEGV || sig == SIGBUS) {
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1338
      WatcherThread::watcher_thread()->crash_protection()->restore();
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1339
    }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1340
  }
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 17121
diff changeset
  1341
}
31610
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1342
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31991
diff changeset
  1343
#define check_with_errno(check_type, cond, msg)                             \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31991
diff changeset
  1344
  do {                                                                      \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31991
diff changeset
  1345
    int err = errno;                                                        \
37113
5a33bf5089ac 8148425: strerror() function is not thread-safe
stuefe
parents: 36585
diff changeset
  1346
    check_type(cond, "%s; error='%s' (errno=%s)", msg, os::strerror(err),   \
5a33bf5089ac 8148425: strerror() function is not thread-safe
stuefe
parents: 36585
diff changeset
  1347
               os::errno_name(err));                                        \
31610
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1348
} while (false)
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1349
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1350
#define assert_with_errno(cond, msg)    check_with_errno(assert, cond, msg)
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1351
#define guarantee_with_errno(cond, msg) check_with_errno(guarantee, cond, msg)
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1352
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1353
// POSIX unamed semaphores are not supported on OS X.
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1354
#ifndef __APPLE__
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1355
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1356
PosixSemaphore::PosixSemaphore(uint value) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1357
  int ret = sem_init(&_semaphore, 0, value);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1358
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1359
  guarantee_with_errno(ret == 0, "Failed to initialize semaphore");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1360
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1361
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1362
PosixSemaphore::~PosixSemaphore() {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1363
  sem_destroy(&_semaphore);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1364
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1365
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1366
void PosixSemaphore::signal(uint count) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1367
  for (uint i = 0; i < count; i++) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1368
    int ret = sem_post(&_semaphore);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1369
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1370
    assert_with_errno(ret == 0, "sem_post failed");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1371
  }
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1372
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1373
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1374
void PosixSemaphore::wait() {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1375
  int ret;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1376
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1377
  do {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1378
    ret = sem_wait(&_semaphore);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1379
  } while (ret != 0 && errno == EINTR);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1380
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1381
  assert_with_errno(ret == 0, "sem_wait failed");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1382
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1383
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1384
bool PosixSemaphore::trywait() {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1385
  int ret;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1386
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1387
  do {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1388
    ret = sem_trywait(&_semaphore);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1389
  } while (ret != 0 && errno == EINTR);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1390
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1391
  assert_with_errno(ret == 0 || errno == EAGAIN, "trywait failed");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1392
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1393
  return ret == 0;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1394
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1395
31991
a7dd5bba0fd8 8132232: Signature mismatch between declaration and definition of PosixSemaphore::timedwait
simonis
parents: 31963
diff changeset
  1396
bool PosixSemaphore::timedwait(struct timespec ts) {
31610
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1397
  while (true) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1398
    int result = sem_timedwait(&_semaphore, &ts);
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1399
    if (result == 0) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1400
      return true;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1401
    } else if (errno == EINTR) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1402
      continue;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1403
    } else if (errno == ETIMEDOUT) {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1404
      return false;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1405
    } else {
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1406
      assert_with_errno(false, "timedwait failed");
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1407
      return false;
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1408
    }
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1409
  }
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1410
}
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1411
b05ea6f92971 8087322: Implement a Semaphore utility class
stefank
parents: 30240
diff changeset
  1412
#endif // __APPLE__
46507
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1413
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1414
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1415
// Shared pthread_mutex/cond based PlatformEvent implementation.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1416
// Not currently usable by Solaris.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1417
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1418
#ifndef SOLARIS
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1419
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1420
// Shared condattr object for use with relative timed-waits. Will be associated
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1421
// with CLOCK_MONOTONIC if available to avoid issues with time-of-day changes,
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1422
// but otherwise whatever default is used by the platform - generally the
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1423
// time-of-day clock.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1424
static pthread_condattr_t _condAttr[1];
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1425
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1426
// Shared mutexattr to explicitly set the type to PTHREAD_MUTEX_NORMAL as not
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1427
// all systems (e.g. FreeBSD) map the default to "normal".
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1428
static pthread_mutexattr_t _mutexAttr[1];
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1429
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1430
// common basic initialization that is always supported
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1431
static void pthread_init_common(void) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1432
  int status;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1433
  if ((status = pthread_condattr_init(_condAttr)) != 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1434
    fatal("pthread_condattr_init: %s", os::strerror(status));
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1435
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1436
  if ((status = pthread_mutexattr_init(_mutexAttr)) != 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1437
    fatal("pthread_mutexattr_init: %s", os::strerror(status));
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1438
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1439
  if ((status = pthread_mutexattr_settype(_mutexAttr, PTHREAD_MUTEX_NORMAL)) != 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1440
    fatal("pthread_mutexattr_settype: %s", os::strerror(status));
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1441
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1442
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1443
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1444
// Not all POSIX types and API's are available on all notionally "posix"
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1445
// platforms. If we have build-time support then we will check for actual
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1446
// runtime support via dlopen/dlsym lookup. This allows for running on an
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1447
// older OS version compared to the build platform. But if there is no
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1448
// build time support then there cannot be any runtime support as we do not
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1449
// know what the runtime types would be (for example clockid_t might be an
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1450
// int or int64_t).
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1451
//
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1452
#ifdef SUPPORTS_CLOCK_MONOTONIC
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1453
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1454
// This means we have clockid_t, clock_gettime et al and CLOCK_MONOTONIC
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1455
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1456
static int (*_clock_gettime)(clockid_t, struct timespec *);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1457
static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1458
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1459
static bool _use_clock_monotonic_condattr;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1460
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1461
// Determine what POSIX API's are present and do appropriate
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1462
// configuration.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1463
void os::Posix::init(void) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1464
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1465
  // NOTE: no logging available when this is called. Put logging
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1466
  // statements in init_2().
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1467
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1468
  // Copied from os::Linux::clock_init(). The duplication is temporary.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1469
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1470
  // 1. Check for CLOCK_MONOTONIC support.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1471
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1472
  void* handle = NULL;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1473
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1474
  // For linux we need librt, for other OS we can find
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1475
  // this function in regular libc.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1476
#ifdef NEEDS_LIBRT
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1477
  // We do dlopen's in this particular order due to bug in linux
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1478
  // dynamic loader (see 6348968) leading to crash on exit.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1479
  handle = dlopen("librt.so.1", RTLD_LAZY);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1480
  if (handle == NULL) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1481
    handle = dlopen("librt.so", RTLD_LAZY);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1482
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1483
#endif
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1484
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1485
  if (handle == NULL) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1486
    handle = RTLD_DEFAULT;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1487
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1488
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1489
  _clock_gettime = NULL;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1490
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1491
  int (*clock_getres_func)(clockid_t, struct timespec*) =
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1492
    (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1493
  int (*clock_gettime_func)(clockid_t, struct timespec*) =
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1494
    (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1495
  if (clock_getres_func != NULL && clock_gettime_func != NULL) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1496
    // We assume that if both clock_gettime and clock_getres support
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1497
    // CLOCK_MONOTONIC then the OS provides true high-res monotonic clock.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1498
    struct timespec res;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1499
    struct timespec tp;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1500
    if (clock_getres_func(CLOCK_MONOTONIC, &res) == 0 &&
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1501
        clock_gettime_func(CLOCK_MONOTONIC, &tp) == 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1502
      // Yes, monotonic clock is supported.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1503
      _clock_gettime = clock_gettime_func;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1504
    } else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1505
#ifdef NEEDS_LIBRT
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1506
      // Close librt if there is no monotonic clock.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1507
      if (handle != RTLD_DEFAULT) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1508
        dlclose(handle);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1509
      }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1510
#endif
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1511
    }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1512
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1513
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1514
  // 2. Check for pthread_condattr_setclock support.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1515
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1516
  _pthread_condattr_setclock = NULL;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1517
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1518
  // libpthread is already loaded.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1519
  int (*condattr_setclock_func)(pthread_condattr_t*, clockid_t) =
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1520
    (int (*)(pthread_condattr_t*, clockid_t))dlsym(RTLD_DEFAULT,
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1521
                                                   "pthread_condattr_setclock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1522
  if (condattr_setclock_func != NULL) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1523
    _pthread_condattr_setclock = condattr_setclock_func;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1524
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1525
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1526
  // Now do general initialization.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1527
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1528
  pthread_init_common();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1529
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1530
  int status;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1531
  if (_pthread_condattr_setclock != NULL && _clock_gettime != NULL) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1532
    if ((status = _pthread_condattr_setclock(_condAttr, CLOCK_MONOTONIC)) != 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1533
      if (status == EINVAL) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1534
        _use_clock_monotonic_condattr = false;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1535
        warning("Unable to use monotonic clock with relative timed-waits" \
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1536
                " - changes to the time-of-day clock may have adverse affects");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1537
      } else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1538
        fatal("pthread_condattr_setclock: %s", os::strerror(status));
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1539
      }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1540
    } else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1541
      _use_clock_monotonic_condattr = true;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1542
    }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1543
  } else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1544
    _use_clock_monotonic_condattr = false;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1545
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1546
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1547
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1548
void os::Posix::init_2(void) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1549
  log_info(os)("Use of CLOCK_MONOTONIC is%s supported",
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1550
               (_clock_gettime != NULL ? "" : " not"));
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1551
  log_info(os)("Use of pthread_condattr_setclock is%s supported",
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1552
               (_pthread_condattr_setclock != NULL ? "" : " not"));
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1553
  log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with %s",
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1554
               _use_clock_monotonic_condattr ? "CLOCK_MONOTONIC" : "the default clock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1555
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1556
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1557
#else // !SUPPORTS_CLOCK_MONOTONIC
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1558
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1559
void os::Posix::init(void) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1560
  pthread_init_common();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1561
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1562
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1563
void os::Posix::init_2(void) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1564
  log_info(os)("Use of CLOCK_MONOTONIC is not supported");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1565
  log_info(os)("Use of pthread_condattr_setclock is not supported");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1566
  log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with the default clock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1567
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1568
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1569
#endif // SUPPORTS_CLOCK_MONOTONIC
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1570
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1571
os::PlatformEvent::PlatformEvent() {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1572
  int status = pthread_cond_init(_cond, _condAttr);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1573
  assert_status(status == 0, status, "cond_init");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1574
  status = pthread_mutex_init(_mutex, _mutexAttr);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1575
  assert_status(status == 0, status, "mutex_init");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1576
  _event   = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1577
  _nParked = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1578
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1579
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1580
// Utility to convert the given timeout to an absolute timespec
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1581
// (based on the appropriate clock) to use with pthread_cond_timewait.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1582
// The clock queried here must be the clock used to manage the
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1583
// timeout of the condition variable.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1584
//
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1585
// The passed in timeout value is either a relative time in nanoseconds
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1586
// or an absolute time in milliseconds. A relative timeout will be
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1587
// associated with CLOCK_MONOTONIC if available; otherwise, or if absolute,
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1588
// the default time-of-day clock will be used.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1589
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1590
// Given time is a 64-bit value and the time_t used in the timespec is
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1591
// sometimes a signed-32-bit value we have to watch for overflow if times
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1592
// way in the future are given. Further on Solaris versions
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1593
// prior to 10 there is a restriction (see cond_timedwait) that the specified
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1594
// number of seconds, in abstime, is less than current_time + 100000000.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1595
// As it will be over 20 years before "now + 100000000" will overflow we can
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1596
// ignore overflow and just impose a hard-limit on seconds using the value
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1597
// of "now + 100000000". This places a limit on the timeout of about 3.17
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1598
// years from "now".
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1599
//
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1600
#define MAX_SECS 100000000
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1601
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1602
// Calculate a new absolute time that is "timeout" nanoseconds from "now".
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1603
// "unit" indicates the unit of "now_part_sec" (may be nanos or micros depending
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1604
// on which clock is being used).
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1605
static void calc_rel_time(timespec* abstime, jlong timeout, jlong now_sec,
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1606
                          jlong now_part_sec, jlong unit) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1607
  time_t max_secs = now_sec + MAX_SECS;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1608
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1609
  jlong seconds = timeout / NANOUNITS;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1610
  timeout %= NANOUNITS; // remaining nanos
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1611
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1612
  if (seconds >= MAX_SECS) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1613
    // More seconds than we can add, so pin to max_secs.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1614
    abstime->tv_sec = max_secs;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1615
    abstime->tv_nsec = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1616
  } else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1617
    abstime->tv_sec = now_sec  + seconds;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1618
    long nanos = (now_part_sec * (NANOUNITS / unit)) + timeout;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1619
    if (nanos >= NANOUNITS) { // overflow
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1620
      abstime->tv_sec += 1;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1621
      nanos -= NANOUNITS;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1622
    }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1623
    abstime->tv_nsec = nanos;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1624
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1625
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1626
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1627
// Unpack the given deadline in milliseconds since the epoch, into the given timespec.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1628
// The current time in seconds is also passed in to enforce an upper bound as discussed above.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1629
static void unpack_abs_time(timespec* abstime, jlong deadline, jlong now_sec) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1630
  time_t max_secs = now_sec + MAX_SECS;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1631
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1632
  jlong seconds = deadline / MILLIUNITS;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1633
  jlong millis = deadline % MILLIUNITS;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1634
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1635
  if (seconds >= max_secs) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1636
    // Absolute seconds exceeds allowed max, so pin to max_secs.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1637
    abstime->tv_sec = max_secs;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1638
    abstime->tv_nsec = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1639
  } else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1640
    abstime->tv_sec = seconds;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1641
    abstime->tv_nsec = millis * (NANOUNITS / MILLIUNITS);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1642
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1643
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1644
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1645
static void to_abstime(timespec* abstime, jlong timeout, bool isAbsolute) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1646
  DEBUG_ONLY(int max_secs = MAX_SECS;)
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1647
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1648
  if (timeout < 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1649
    timeout = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1650
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1651
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1652
#ifdef SUPPORTS_CLOCK_MONOTONIC
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1653
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1654
  if (_use_clock_monotonic_condattr && !isAbsolute) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1655
    struct timespec now;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1656
    int status = _clock_gettime(CLOCK_MONOTONIC, &now);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1657
    assert_status(status == 0, status, "clock_gettime");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1658
    calc_rel_time(abstime, timeout, now.tv_sec, now.tv_nsec, NANOUNITS);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1659
    DEBUG_ONLY(max_secs += now.tv_sec;)
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1660
  } else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1661
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1662
#else
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1663
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1664
  { // Match the block scope.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1665
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1666
#endif // SUPPORTS_CLOCK_MONOTONIC
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1667
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1668
    // Time-of-day clock is all we can reliably use.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1669
    struct timeval now;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1670
    int status = gettimeofday(&now, NULL);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1671
    assert_status(status == 0, errno, "gettimeofday");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1672
    if (isAbsolute) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1673
      unpack_abs_time(abstime, timeout, now.tv_sec);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1674
    } else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1675
      calc_rel_time(abstime, timeout, now.tv_sec, now.tv_usec, MICROUNITS);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1676
    }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1677
    DEBUG_ONLY(max_secs += now.tv_sec;)
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1678
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1679
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1680
  assert(abstime->tv_sec >= 0, "tv_sec < 0");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1681
  assert(abstime->tv_sec <= max_secs, "tv_sec > max_secs");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1682
  assert(abstime->tv_nsec >= 0, "tv_nsec < 0");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1683
  assert(abstime->tv_nsec < NANOUNITS, "tv_nsec >= NANOUNITS");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1684
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1685
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1686
// PlatformEvent
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1687
//
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1688
// Assumption:
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1689
//    Only one parker can exist on an event, which is why we allocate
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1690
//    them per-thread. Multiple unparkers can coexist.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1691
//
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1692
// _event serves as a restricted-range semaphore.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1693
//   -1 : thread is blocked, i.e. there is a waiter
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1694
//    0 : neutral: thread is running or ready,
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1695
//        could have been signaled after a wait started
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1696
//    1 : signaled - thread is running or ready
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1697
//
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1698
//    Having three states allows for some detection of bad usage - see
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1699
//    comments on unpark().
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1700
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1701
void os::PlatformEvent::park() {       // AKA "down()"
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1702
  // Transitions for _event:
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1703
  //   -1 => -1 : illegal
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1704
  //    1 =>  0 : pass - return immediately
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1705
  //    0 => -1 : block; then set _event to 0 before returning
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1706
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1707
  // Invariant: Only the thread associated with the PlatformEvent
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1708
  // may call park().
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1709
  assert(_nParked == 0, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1710
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1711
  int v;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1712
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1713
  // atomically decrement _event
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1714
  for (;;) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1715
    v = _event;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1716
    if (Atomic::cmpxchg(v - 1, &_event, v) == v) break;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1717
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1718
  guarantee(v >= 0, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1719
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1720
  if (v == 0) { // Do this the hard way by blocking ...
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1721
    int status = pthread_mutex_lock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1722
    assert_status(status == 0, status, "mutex_lock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1723
    guarantee(_nParked == 0, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1724
    ++_nParked;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1725
    while (_event < 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1726
      // OS-level "spurious wakeups" are ignored
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1727
      status = pthread_cond_wait(_cond, _mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1728
      assert_status(status == 0, status, "cond_wait");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1729
    }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1730
    --_nParked;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1731
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1732
    _event = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1733
    status = pthread_mutex_unlock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1734
    assert_status(status == 0, status, "mutex_unlock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1735
    // Paranoia to ensure our locked and lock-free paths interact
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1736
    // correctly with each other.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1737
    OrderAccess::fence();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1738
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1739
  guarantee(_event >= 0, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1740
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1741
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1742
int os::PlatformEvent::park(jlong millis) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1743
  // Transitions for _event:
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1744
  //   -1 => -1 : illegal
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1745
  //    1 =>  0 : pass - return immediately
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1746
  //    0 => -1 : block; then set _event to 0 before returning
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1747
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1748
  // Invariant: Only the thread associated with the Event/PlatformEvent
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1749
  // may call park().
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1750
  assert(_nParked == 0, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1751
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1752
  int v;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1753
  // atomically decrement _event
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1754
  for (;;) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1755
    v = _event;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1756
    if (Atomic::cmpxchg(v - 1, &_event, v) == v) break;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1757
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1758
  guarantee(v >= 0, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1759
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1760
  if (v == 0) { // Do this the hard way by blocking ...
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1761
    struct timespec abst;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1762
    to_abstime(&abst, millis * (NANOUNITS / MILLIUNITS), false);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1763
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1764
    int ret = OS_TIMEOUT;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1765
    int status = pthread_mutex_lock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1766
    assert_status(status == 0, status, "mutex_lock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1767
    guarantee(_nParked == 0, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1768
    ++_nParked;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1769
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1770
    while (_event < 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1771
      status = pthread_cond_timedwait(_cond, _mutex, &abst);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1772
      assert_status(status == 0 || status == ETIMEDOUT,
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1773
                    status, "cond_timedwait");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1774
      // OS-level "spurious wakeups" are ignored unless the archaic
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1775
      // FilterSpuriousWakeups is set false. That flag should be obsoleted.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1776
      if (!FilterSpuriousWakeups) break;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1777
      if (status == ETIMEDOUT) break;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1778
    }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1779
    --_nParked;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1780
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1781
    if (_event >= 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1782
      ret = OS_OK;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1783
    }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1784
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1785
    _event = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1786
    status = pthread_mutex_unlock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1787
    assert_status(status == 0, status, "mutex_unlock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1788
    // Paranoia to ensure our locked and lock-free paths interact
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1789
    // correctly with each other.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1790
    OrderAccess::fence();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1791
    return ret;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1792
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1793
  return OS_OK;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1794
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1795
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1796
void os::PlatformEvent::unpark() {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1797
  // Transitions for _event:
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1798
  //    0 => 1 : just return
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1799
  //    1 => 1 : just return
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1800
  //   -1 => either 0 or 1; must signal target thread
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1801
  //         That is, we can safely transition _event from -1 to either
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1802
  //         0 or 1.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1803
  // See also: "Semaphores in Plan 9" by Mullender & Cox
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1804
  //
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1805
  // Note: Forcing a transition from "-1" to "1" on an unpark() means
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1806
  // that it will take two back-to-back park() calls for the owning
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1807
  // thread to block. This has the benefit of forcing a spurious return
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1808
  // from the first park() call after an unpark() call which will help
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1809
  // shake out uses of park() and unpark() without checking state conditions
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1810
  // properly. This spurious return doesn't manifest itself in any user code
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1811
  // but only in the correctly written condition checking loops of ObjectMonitor,
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1812
  // Mutex/Monitor, Thread::muxAcquire and os::sleep
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1813
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1814
  if (Atomic::xchg(1, &_event) >= 0) return;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1815
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1816
  int status = pthread_mutex_lock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1817
  assert_status(status == 0, status, "mutex_lock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1818
  int anyWaiters = _nParked;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1819
  assert(anyWaiters == 0 || anyWaiters == 1, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1820
  status = pthread_mutex_unlock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1821
  assert_status(status == 0, status, "mutex_unlock");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1822
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1823
  // Note that we signal() *after* dropping the lock for "immortal" Events.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1824
  // This is safe and avoids a common class of futile wakeups.  In rare
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1825
  // circumstances this can cause a thread to return prematurely from
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1826
  // cond_{timed}wait() but the spurious wakeup is benign and the victim
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1827
  // will simply re-test the condition and re-park itself.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1828
  // This provides particular benefit if the underlying platform does not
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1829
  // provide wait morphing.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1830
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1831
  if (anyWaiters != 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1832
    status = pthread_cond_signal(_cond);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1833
    assert_status(status == 0, status, "cond_signal");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1834
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1835
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1836
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1837
// JSR166 support
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1838
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1839
 os::PlatformParker::PlatformParker() {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1840
  int status;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1841
  status = pthread_cond_init(&_cond[REL_INDEX], _condAttr);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1842
  assert_status(status == 0, status, "cond_init rel");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1843
  status = pthread_cond_init(&_cond[ABS_INDEX], NULL);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1844
  assert_status(status == 0, status, "cond_init abs");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1845
  status = pthread_mutex_init(_mutex, _mutexAttr);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1846
  assert_status(status == 0, status, "mutex_init");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1847
  _cur_index = -1; // mark as unused
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1848
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1849
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1850
// Parker::park decrements count if > 0, else does a condvar wait.  Unpark
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1851
// sets count to 1 and signals condvar.  Only one thread ever waits
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1852
// on the condvar. Contention seen when trying to park implies that someone
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1853
// is unparking you, so don't wait. And spurious returns are fine, so there
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1854
// is no need to track notifications.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1855
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1856
void Parker::park(bool isAbsolute, jlong time) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1857
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1858
  // Optional fast-path check:
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1859
  // Return immediately if a permit is available.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1860
  // We depend on Atomic::xchg() having full barrier semantics
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1861
  // since we are doing a lock-free update to _counter.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1862
  if (Atomic::xchg(0, &_counter) > 0) return;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1863
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1864
  Thread* thread = Thread::current();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1865
  assert(thread->is_Java_thread(), "Must be JavaThread");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1866
  JavaThread *jt = (JavaThread *)thread;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1867
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1868
  // Optional optimization -- avoid state transitions if there's
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1869
  // an interrupt pending.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1870
  if (Thread::is_interrupted(thread, false)) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1871
    return;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1872
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1873
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1874
  // Next, demultiplex/decode time arguments
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1875
  struct timespec absTime;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1876
  if (time < 0 || (isAbsolute && time == 0)) { // don't wait at all
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1877
    return;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1878
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1879
  if (time > 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1880
    to_abstime(&absTime, time, isAbsolute);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1881
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1882
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1883
  // Enter safepoint region
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1884
  // Beware of deadlocks such as 6317397.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1885
  // The per-thread Parker:: mutex is a classic leaf-lock.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1886
  // In particular a thread must never block on the Threads_lock while
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1887
  // holding the Parker:: mutex.  If safepoints are pending both the
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1888
  // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1889
  ThreadBlockInVM tbivm(jt);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1890
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1891
  // Don't wait if cannot get lock since interference arises from
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1892
  // unparking. Also re-check interrupt before trying wait.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1893
  if (Thread::is_interrupted(thread, false) ||
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1894
      pthread_mutex_trylock(_mutex) != 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1895
    return;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1896
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1897
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1898
  int status;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1899
  if (_counter > 0)  { // no wait needed
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1900
    _counter = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1901
    status = pthread_mutex_unlock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1902
    assert_status(status == 0, status, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1903
    // Paranoia to ensure our locked and lock-free paths interact
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1904
    // correctly with each other and Java-level accesses.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1905
    OrderAccess::fence();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1906
    return;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1907
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1908
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1909
  OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1910
  jt->set_suspend_equivalent();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1911
  // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1912
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1913
  assert(_cur_index == -1, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1914
  if (time == 0) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1915
    _cur_index = REL_INDEX; // arbitrary choice when not timed
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1916
    status = pthread_cond_wait(&_cond[_cur_index], _mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1917
    assert_status(status == 0, status, "cond_timedwait");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1918
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1919
  else {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1920
    _cur_index = isAbsolute ? ABS_INDEX : REL_INDEX;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1921
    status = pthread_cond_timedwait(&_cond[_cur_index], _mutex, &absTime);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1922
    assert_status(status == 0 || status == ETIMEDOUT,
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1923
                  status, "cond_timedwait");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1924
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1925
  _cur_index = -1;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1926
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1927
  _counter = 0;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1928
  status = pthread_mutex_unlock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1929
  assert_status(status == 0, status, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1930
  // Paranoia to ensure our locked and lock-free paths interact
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1931
  // correctly with each other and Java-level accesses.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1932
  OrderAccess::fence();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1933
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1934
  // If externally suspended while waiting, re-suspend
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1935
  if (jt->handle_special_suspend_equivalent_condition()) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1936
    jt->java_suspend_self();
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1937
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1938
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1939
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1940
void Parker::unpark() {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1941
  int status = pthread_mutex_lock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1942
  assert_status(status == 0, status, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1943
  const int s = _counter;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1944
  _counter = 1;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1945
  // must capture correct index before unlocking
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1946
  int index = _cur_index;
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1947
  status = pthread_mutex_unlock(_mutex);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1948
  assert_status(status == 0, status, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1949
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1950
  // Note that we signal() *after* dropping the lock for "immortal" Events.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1951
  // This is safe and avoids a common class of futile wakeups.  In rare
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1952
  // circumstances this can cause a thread to return prematurely from
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1953
  // cond_{timed}wait() but the spurious wakeup is benign and the victim
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1954
  // will simply re-test the condition and re-park itself.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1955
  // This provides particular benefit if the underlying platform does not
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1956
  // provide wait morphing.
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1957
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1958
  if (s < 1 && index != -1) {
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1959
    // thread is definitely parked
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1960
    status = pthread_cond_signal(&_cond[index]);
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1961
    assert_status(status == 0, status, "invariant");
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1962
  }
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1963
}
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1964
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1965
7db40fa6eff7 8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents: 46451
diff changeset
  1966
#endif // !SOLARIS