author | stefank |
Mon, 25 Nov 2019 12:33:15 +0100 | |
changeset 59252 | 623722a6aeb9 |
parent 59251 | 4cbfa5077d68 |
child 59290 | 97d13893ec3c |
permissions | -rw-r--r-- |
8119 | 1 |
/* |
53266
57d8566a2732
8214816: os::read() should not transition to _thread_blocked with safepoint check on Solaris
dholmes
parents:
53077
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
22826 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
8119 | 24 |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47604
diff
changeset
|
25 |
#include "jvm.h" |
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
26 |
#include "logging/log.hpp" |
49360 | 27 |
#include "memory/allocation.inline.hpp" |
53654
7054249afee5
8217843: Performance regression related to os::supports_monotonic_clock() on linux
dholmes
parents:
53646
diff
changeset
|
28 |
#include "os_posix.inline.hpp" |
22826 | 29 |
#include "utilities/globalDefinitions.hpp" |
13195 | 30 |
#include "runtime/frame.inline.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49360
diff
changeset
|
31 |
#include "runtime/interfaceSupport.inline.hpp" |
49360 | 32 |
#include "services/memTracker.hpp" |
46625 | 33 |
#include "utilities/align.hpp" |
54031
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
34 |
#include "utilities/events.hpp" |
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
35 |
#include "utilities/formatBuffer.hpp" |
40010 | 36 |
#include "utilities/macros.hpp" |
8119 | 37 |
#include "utilities/vmError.hpp" |
38 |
||
51106
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
39 |
#include <dirent.h> |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
40 |
#include <dlfcn.h> |
52585
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
41 |
#include <grp.h> |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
42 |
#include <pwd.h> |
19691
5116fb76692a
8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents:
18943
diff
changeset
|
43 |
#include <pthread.h> |
5116fb76692a
8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents:
18943
diff
changeset
|
44 |
#include <signal.h> |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
45 |
#include <sys/mman.h> |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
46 |
#include <sys/resource.h> |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
47 |
#include <sys/utsname.h> |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
48 |
#include <time.h> |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
49 |
#include <unistd.h> |
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
50 |
|
22826 | 51 |
// Todo: provide a os::get_max_process_id() or similar. Number of processes |
52 |
// may have been configured, can be read more accurately from proc fs etc. |
|
53 |
#ifndef MAX_PID |
|
54 |
#define MAX_PID INT_MAX |
|
55 |
#endif |
|
56 |
#define IS_VALID_PID(p) (p > 0 && p < MAX_PID) |
|
8119 | 57 |
|
50333
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
58 |
#define ROOT_UID 0 |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
59 |
|
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
60 |
#ifndef MAP_ANONYMOUS |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
61 |
#define MAP_ANONYMOUS MAP_ANON |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
62 |
#endif |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
63 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
64 |
#define check_with_errno(check_type, cond, msg) \ |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
65 |
do { \ |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
66 |
int err = errno; \ |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
67 |
check_type(cond, "%s; error='%s' (errno=%s)", msg, os::strerror(err), \ |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
68 |
os::errno_name(err)); \ |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
69 |
} while (false) |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
70 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
71 |
#define assert_with_errno(cond, msg) check_with_errno(assert, cond, msg) |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
72 |
#define guarantee_with_errno(cond, msg) check_with_errno(guarantee, cond, msg) |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
73 |
|
8119 | 74 |
// 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
|
75 |
void os::check_dump_limit(char* buffer, size_t bufferSize) { |
38254 | 76 |
if (!FLAG_IS_DEFAULT(CreateCoredumpOnCrash) && !CreateCoredumpOnCrash) { |
77 |
jio_snprintf(buffer, bufferSize, "CreateCoredumpOnCrash is disabled from command line"); |
|
78 |
VMError::record_coredump_status(buffer, false); |
|
79 |
return; |
|
80 |
} |
|
81 |
||
13198
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
82 |
int n; |
8119 | 83 |
struct rlimit rlim; |
84 |
bool success; |
|
85 |
||
28172
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
86 |
char core_path[PATH_MAX]; |
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
87 |
n = get_core_path(core_path, PATH_MAX); |
8119 | 88 |
|
28172
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
89 |
if (n <= 0) { |
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
90 |
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
|
91 |
success = true; |
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
92 |
#ifdef LINUX |
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
93 |
} else if (core_path[0] == '"') { // redirect to user process |
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
94 |
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
|
95 |
success = true; |
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
96 |
#endif |
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
97 |
} else if (getrlimit(RLIMIT_CORE, &rlim) != 0) { |
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
98 |
jio_snprintf(buffer, bufferSize, "%s (may not exist)", core_path); |
8119 | 99 |
success = true; |
100 |
} else { |
|
101 |
switch(rlim.rlim_cur) { |
|
102 |
case RLIM_INFINITY: |
|
28172
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
103 |
jio_snprintf(buffer, bufferSize, "%s", core_path); |
8119 | 104 |
success = true; |
105 |
break; |
|
106 |
case 0: |
|
107 |
jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again"); |
|
108 |
success = false; |
|
109 |
break; |
|
110 |
default: |
|
46508
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
111 |
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 | 112 |
success = true; |
113 |
break; |
|
114 |
} |
|
115 |
} |
|
28172
19ae5c844e75
8059586: hs_err report should treat redirected core pattern
dholmes
parents:
28166
diff
changeset
|
116 |
|
30240
a7ba42fa1df6
8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents:
28172
diff
changeset
|
117 |
VMError::record_coredump_status(buffer, success); |
8119 | 118 |
} |
119 |
||
25946 | 120 |
int os::get_native_stack(address* stack, int frames, int toSkip) { |
121 |
int frame_idx = 0; |
|
122 |
int num_of_frames; // number of frames captured |
|
13195 | 123 |
frame fr = os::current_frame(); |
25946 | 124 |
while (fr.pc() && frame_idx < frames) { |
125 |
if (toSkip > 0) { |
|
126 |
toSkip --; |
|
127 |
} else { |
|
128 |
stack[frame_idx ++] = fr.pc(); |
|
129 |
} |
|
28166
e42212b64568
8066803: compiler/intrinsics/mathexact/SubExactINonConstantTest.java crashed in os::is_first_C_frame(frame*)
coleenp
parents:
27471
diff
changeset
|
130 |
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
|
131 |
fr.sender_pc() == NULL || os::is_first_C_frame(&fr)) break; |
25946 | 132 |
|
133 |
if (fr.sender_pc() && !os::is_first_C_frame(&fr)) { |
|
134 |
fr = os::get_sender_for_C_frame(&fr); |
|
135 |
} else { |
|
136 |
break; |
|
137 |
} |
|
13195 | 138 |
} |
25946 | 139 |
num_of_frames = frame_idx; |
140 |
for (; frame_idx < frames; frame_idx ++) { |
|
141 |
stack[frame_idx] = NULL; |
|
13195 | 142 |
} |
25946 | 143 |
|
144 |
return num_of_frames; |
|
145 |
} |
|
146 |
||
147 |
||
148 |
bool os::unsetenv(const char* name) { |
|
149 |
assert(name != NULL, "Null pointer"); |
|
150 |
return (::unsetenv(name) == 0); |
|
13195 | 151 |
} |
152 |
||
11418
66ca80da30e2
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
8476
diff
changeset
|
153 |
int os::get_last_error() { |
66ca80da30e2
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
8476
diff
changeset
|
154 |
return errno; |
66ca80da30e2
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
8476
diff
changeset
|
155 |
} |
66ca80da30e2
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
8476
diff
changeset
|
156 |
|
50930
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
157 |
size_t os::lasterror(char *buf, size_t len) { |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
158 |
if (errno == 0) return 0; |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
159 |
|
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
160 |
const char *s = os::strerror(errno); |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
161 |
size_t n = ::strlen(s); |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
162 |
if (n >= len) { |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
163 |
n = len - 1; |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
164 |
} |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
165 |
::strncpy(buf, s, n); |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
166 |
buf[n] = '\0'; |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
167 |
return n; |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
168 |
} |
6a5f1195e15f
8134538: Duplicate implementations of os::lasterror
coleenp
parents:
50667
diff
changeset
|
169 |
|
8476
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
170 |
void os::wait_for_keypress_at_exit(void) { |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
171 |
// don't do anything on posix platforms |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
172 |
return; |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
173 |
} |
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
174 |
|
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
175 |
int os::create_file_for_heap(const char* dir) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
176 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
177 |
const char name_template[] = "/jvmheap.XXXXXX"; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
178 |
|
53882
ca682d9d8db5
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents:
53654
diff
changeset
|
179 |
size_t fullname_len = strlen(dir) + strlen(name_template); |
ca682d9d8db5
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents:
53654
diff
changeset
|
180 |
char *fullname = (char*)os::malloc(fullname_len + 1, mtInternal); |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
181 |
if (fullname == NULL) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
182 |
vm_exit_during_initialization(err_msg("Malloc failed during creation of backing file for heap (%s)", os::strerror(errno))); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
183 |
return -1; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
184 |
} |
53882
ca682d9d8db5
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents:
53654
diff
changeset
|
185 |
int n = snprintf(fullname, fullname_len + 1, "%s%s", dir, name_template); |
ca682d9d8db5
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents:
53654
diff
changeset
|
186 |
assert((size_t)n == fullname_len, "Unexpected number of characters in string"); |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
187 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
188 |
os::native_path(fullname); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
189 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
190 |
// set the file creation mask. |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
191 |
mode_t file_mode = S_IRUSR | S_IWUSR; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
192 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
193 |
// create a new file. |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
194 |
int fd = mkstemp(fullname); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
195 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
196 |
if (fd < 0) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
197 |
warning("Could not create file for heap with template %s", fullname); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
198 |
os::free(fullname); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
199 |
return -1; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
200 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
201 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
202 |
// delete the name from the filesystem. When 'fd' is closed, the file (and space) will be deleted. |
53907 | 203 |
int ret = unlink(fullname); |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
204 |
assert_with_errno(ret == 0, "unlink returned error"); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
205 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
206 |
os::free(fullname); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
207 |
return fd; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
208 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
209 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
210 |
static char* reserve_mmapped_memory(size_t bytes, char* requested_addr) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
211 |
char * addr; |
48188 | 212 |
int flags = MAP_PRIVATE NOT_AIX( | MAP_NORESERVE ) | MAP_ANONYMOUS; |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
213 |
if (requested_addr != NULL) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
214 |
assert((uintptr_t)requested_addr % os::vm_page_size() == 0, "Requested address should be aligned to OS page size"); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
215 |
flags |= MAP_FIXED; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
216 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
217 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
218 |
// Map reserved/uncommitted pages PROT_NONE so we fail early if we |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
219 |
// touch an uncommitted page. Otherwise, the read/write might |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
220 |
// succeed if we have enough swap space to back the physical page. |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
221 |
addr = (char*)::mmap(requested_addr, bytes, PROT_NONE, |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
222 |
flags, -1, 0); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
223 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
224 |
if (addr != MAP_FAILED) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
225 |
MemTracker::record_virtual_memory_reserve((address)addr, bytes, CALLER_PC); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
226 |
return addr; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
227 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
228 |
return NULL; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
229 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
230 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
231 |
static int util_posix_fallocate(int fd, off_t offset, off_t len) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
232 |
#ifdef __APPLE__ |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
233 |
fstore_t store = { F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, len }; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
234 |
// First we try to get a continuous chunk of disk space |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
235 |
int ret = fcntl(fd, F_PREALLOCATE, &store); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
236 |
if (ret == -1) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
237 |
// Maybe we are too fragmented, try to allocate non-continuous range |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
238 |
store.fst_flags = F_ALLOCATEALL; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
239 |
ret = fcntl(fd, F_PREALLOCATE, &store); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
240 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
241 |
if(ret != -1) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
242 |
return ftruncate(fd, len); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
243 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
244 |
return -1; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
245 |
#else |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
246 |
return posix_fallocate(fd, offset, len); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
247 |
#endif |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
248 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
249 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
250 |
// Map the given address range to the provided file descriptor. |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
251 |
char* os::map_memory_to_file(char* base, size_t size, int fd) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
252 |
assert(fd != -1, "File descriptor is not valid"); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
253 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
254 |
// allocate space for the file |
48317
8bb6cdfa44eb
8193105: Print error code when map_memory_to_file() fails
sangheki
parents:
48188
diff
changeset
|
255 |
int ret = util_posix_fallocate(fd, 0, (off_t)size); |
8bb6cdfa44eb
8193105: Print error code when map_memory_to_file() fails
sangheki
parents:
48188
diff
changeset
|
256 |
if (ret != 0) { |
8bb6cdfa44eb
8193105: Print error code when map_memory_to_file() fails
sangheki
parents:
48188
diff
changeset
|
257 |
vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory. error(%d)", ret)); |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
258 |
return NULL; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
259 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
260 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
261 |
int prot = PROT_READ | PROT_WRITE; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
262 |
int flags = MAP_SHARED; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
263 |
if (base != NULL) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
264 |
flags |= MAP_FIXED; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
265 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
266 |
char* addr = (char*)mmap(base, size, prot, flags, fd, 0); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
267 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
268 |
if (addr == MAP_FAILED) { |
48317
8bb6cdfa44eb
8193105: Print error code when map_memory_to_file() fails
sangheki
parents:
48188
diff
changeset
|
269 |
warning("Failed mmap to file. (%s)", os::strerror(errno)); |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
270 |
return NULL; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
271 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
272 |
if (base != NULL && addr != base) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
273 |
if (!os::release_memory(addr, size)) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
274 |
warning("Could not release memory on unsuccessful file mapping"); |
48317
8bb6cdfa44eb
8193105: Print error code when map_memory_to_file() fails
sangheki
parents:
48188
diff
changeset
|
275 |
} |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
276 |
return NULL; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
277 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
278 |
return addr; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
279 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
280 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
281 |
char* os::replace_existing_mapping_with_file_mapping(char* base, size_t size, int fd) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
282 |
assert(fd != -1, "File descriptor is not valid"); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
283 |
assert(base != NULL, "Base cannot be NULL"); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
284 |
|
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
285 |
return map_memory_to_file(base, size, fd); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
286 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
287 |
|
14840
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
288 |
// 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
|
289 |
// 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
|
290 |
// rather than unmapping and remapping the whole chunk to get requested alignment. |
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
291 |
char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) { |
14840
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
292 |
assert((alignment & (os::vm_allocation_granularity() - 1)) == 0, |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
293 |
"Alignment must be a multiple of allocation granularity (page size)"); |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
294 |
assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned"); |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
295 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
296 |
size_t extra_size = size + alignment; |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
297 |
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
|
298 |
|
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
299 |
char* extra_base; |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
300 |
if (file_desc != -1) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
301 |
// For file mapping, we do not call os:reserve_memory(extra_size, NULL, alignment, file_desc) because |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
302 |
// we need to deal with shrinking of the file space later when we release extra memory after alignment. |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
303 |
// We also cannot called os:reserve_memory() with file_desc set to -1 because on aix we might get SHM memory. |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
304 |
// So here to call a helper function while reserve memory for us. After we have a aligned base, |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
305 |
// we will replace anonymous mapping with file mapping. |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
306 |
extra_base = reserve_mmapped_memory(extra_size, NULL); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
307 |
if (extra_base != NULL) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
308 |
MemTracker::record_virtual_memory_reserve((address)extra_base, extra_size, CALLER_PC); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
309 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
310 |
} else { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
311 |
extra_base = os::reserve_memory(extra_size, NULL, alignment); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
312 |
} |
14840
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
313 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
314 |
if (extra_base == NULL) { |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
315 |
return NULL; |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
316 |
} |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
317 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
318 |
// Do manual alignment |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46618
diff
changeset
|
319 |
char* aligned_base = align_up(extra_base, alignment); |
14840
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
320 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
321 |
// [ | | ] |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
322 |
// ^ extra_base |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
323 |
// ^ extra_base + begin_offset == aligned_base |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
324 |
// extra_base + begin_offset + size ^ |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
325 |
// extra_base + extra_size ^ |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
326 |
// |<>| == begin_offset |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
327 |
// end_offset == |<>| |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
328 |
size_t begin_offset = aligned_base - extra_base; |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
329 |
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
|
330 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
331 |
if (begin_offset > 0) { |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
332 |
os::release_memory(extra_base, begin_offset); |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
333 |
} |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
334 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
335 |
if (end_offset > 0) { |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
336 |
os::release_memory(extra_base + begin_offset + size, end_offset); |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
337 |
} |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
338 |
|
48153
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
339 |
if (file_desc != -1) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
340 |
// After we have an aligned address, we can replace anonymous mapping with file mapping |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
341 |
if (replace_existing_mapping_with_file_mapping(aligned_base, size, file_desc) == NULL) { |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
342 |
vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
343 |
} |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
344 |
MemTracker::record_virtual_memory_commit((address)aligned_base, size, CALLER_PC); |
cfa2c43e58c2
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
48105
diff
changeset
|
345 |
} |
14840
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
346 |
return aligned_base; |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
347 |
} |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
348 |
|
49177
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
349 |
int os::vsnprintf(char* buf, size_t len, const char* fmt, va_list args) { |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
350 |
// All supported POSIX platforms provide C99 semantics. |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
351 |
int result = ::vsnprintf(buf, len, fmt, args); |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
352 |
// If an encoding error occurred (result < 0) then it's not clear |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
353 |
// whether the buffer is NUL terminated, so ensure it is. |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
354 |
if ((result < 0) && (len > 0)) { |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
355 |
buf[len - 1] = '\0'; |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
356 |
} |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48635
diff
changeset
|
357 |
return result; |
33766
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
33148
diff
changeset
|
358 |
} |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
33148
diff
changeset
|
359 |
|
38065
025c784d9333
8154921: Fix aix after "8146879: Add option for handling existing log files in UL"
goetz
parents:
37465
diff
changeset
|
360 |
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
|
361 |
return NOT_AIX(::)fileno(fp); |
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37113
diff
changeset
|
362 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37113
diff
changeset
|
363 |
|
42066 | 364 |
struct tm* os::gmtime_pd(const time_t* clock, struct tm* res) { |
365 |
return gmtime_r(clock, res); |
|
366 |
} |
|
367 |
||
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
368 |
void os::Posix::print_load_average(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
369 |
st->print("load average:"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
370 |
double loadavg[3]; |
58492
227ddf1ff93d
8231753: use more Posix functionality in aix os::print_os_info
mbaesken
parents:
58196
diff
changeset
|
371 |
int res = os::loadavg(loadavg, 3); |
227ddf1ff93d
8231753: use more Posix functionality in aix os::print_os_info
mbaesken
parents:
58196
diff
changeset
|
372 |
if (res != -1) { |
227ddf1ff93d
8231753: use more Posix functionality in aix os::print_os_info
mbaesken
parents:
58196
diff
changeset
|
373 |
st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]); |
227ddf1ff93d
8231753: use more Posix functionality in aix os::print_os_info
mbaesken
parents:
58196
diff
changeset
|
374 |
} else { |
227ddf1ff93d
8231753: use more Posix functionality in aix os::print_os_info
mbaesken
parents:
58196
diff
changeset
|
375 |
st->print(" Unavailable"); |
227ddf1ff93d
8231753: use more Posix functionality in aix os::print_os_info
mbaesken
parents:
58196
diff
changeset
|
376 |
} |
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
377 |
st->cr(); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
378 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
379 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
380 |
void os::Posix::print_rlimit_info(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
381 |
st->print("rlimit:"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
382 |
struct rlimit rlim; |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
383 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
384 |
st->print(" STACK "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
385 |
getrlimit(RLIMIT_STACK, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
389 |
st->print(", CORE "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
390 |
getrlimit(RLIMIT_CORE, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
391 |
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
|
392 |
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
|
393 |
|
22826 | 394 |
// Isn't there on solaris |
46508
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
395 |
#if defined(AIX) |
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
396 |
st->print(", NPROC "); |
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
397 |
st->print("%d", sysconf(_SC_CHILD_MAX)); |
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
398 |
#elif !defined(SOLARIS) |
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
399 |
st->print(", NPROC "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
400 |
getrlimit(RLIMIT_NPROC, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
401 |
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
|
402 |
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
|
403 |
#endif |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
404 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
405 |
st->print(", NOFILE "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
406 |
getrlimit(RLIMIT_NOFILE, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
407 |
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
|
408 |
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
|
409 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
410 |
st->print(", AS "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
411 |
getrlimit(RLIMIT_AS, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
412 |
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
|
413 |
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
|
414 |
|
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
415 |
st->print(", DATA "); |
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
416 |
getrlimit(RLIMIT_DATA, &rlim); |
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
417 |
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
|
418 |
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
|
419 |
|
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
420 |
st->print(", FSIZE "); |
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
421 |
getrlimit(RLIMIT_FSIZE, &rlim); |
278005442848
8180184: Add DATA and FSIZE to os::Posix::print_rlimit_info
mikael
parents:
46507
diff
changeset
|
422 |
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
|
423 |
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
|
424 |
|
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
425 |
st->cr(); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
426 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
427 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
428 |
void os::Posix::print_uname_info(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
429 |
// kernel |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
430 |
st->print("uname:"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
431 |
struct utsname name; |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
432 |
uname(&name); |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22894
diff
changeset
|
433 |
st->print("%s ", name.sysname); |
26569
5fcbc13c071c
8056930: Output host info under some condition for core dump
minqi
parents:
25946
diff
changeset
|
434 |
#ifdef ASSERT |
5fcbc13c071c
8056930: Output host info under some condition for core dump
minqi
parents:
25946
diff
changeset
|
435 |
st->print("%s ", name.nodename); |
5fcbc13c071c
8056930: Output host info under some condition for core dump
minqi
parents:
25946
diff
changeset
|
436 |
#endif |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22894
diff
changeset
|
437 |
st->print("%s ", name.release); |
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22894
diff
changeset
|
438 |
st->print("%s ", name.version); |
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22894
diff
changeset
|
439 |
st->print("%s", name.machine); |
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
440 |
st->cr(); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
441 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
442 |
|
52585
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
443 |
void os::Posix::print_umask(outputStream* st, mode_t umsk) { |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
444 |
st->print((umsk & S_IRUSR) ? "r" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
445 |
st->print((umsk & S_IWUSR) ? "w" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
446 |
st->print((umsk & S_IXUSR) ? "x" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
447 |
st->print((umsk & S_IRGRP) ? "r" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
448 |
st->print((umsk & S_IWGRP) ? "w" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
449 |
st->print((umsk & S_IXGRP) ? "x" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
450 |
st->print((umsk & S_IROTH) ? "r" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
451 |
st->print((umsk & S_IWOTH) ? "w" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
452 |
st->print((umsk & S_IXOTH) ? "x" : "-"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
453 |
} |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
454 |
|
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
455 |
void os::Posix::print_user_info(outputStream* st) { |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
456 |
unsigned id = (unsigned) ::getuid(); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
457 |
st->print("uid : %u ", id); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
458 |
id = (unsigned) ::geteuid(); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
459 |
st->print("euid : %u ", id); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
460 |
id = (unsigned) ::getgid(); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
461 |
st->print("gid : %u ", id); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
462 |
id = (unsigned) ::getegid(); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
463 |
st->print_cr("egid : %u", id); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
464 |
st->cr(); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
465 |
|
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
466 |
mode_t umsk = ::umask(0); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
467 |
::umask(umsk); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
468 |
st->print("umask: %04o (", (unsigned) umsk); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
469 |
print_umask(st, umsk); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
470 |
st->print_cr(")"); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
471 |
st->cr(); |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
472 |
} |
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
473 |
|
f7f90fddce02
8211326: add OS user related information to hs_err file
mbaesken
parents:
51989
diff
changeset
|
474 |
|
31963
641ed52732ec
8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents:
31610
diff
changeset
|
475 |
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
|
476 |
struct utsname name; |
641ed52732ec
8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents:
31610
diff
changeset
|
477 |
uname(&name); |
641ed52732ec
8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents:
31610
diff
changeset
|
478 |
jio_snprintf(buf, buflen, "%s", name.nodename); |
641ed52732ec
8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents:
31610
diff
changeset
|
479 |
return true; |
641ed52732ec
8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents:
31610
diff
changeset
|
480 |
} |
641ed52732ec
8026324: hs_err improvement: Add summary section to hs_err file
coleenp
parents:
31610
diff
changeset
|
481 |
|
16605
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
482 |
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
|
483 |
struct rlimit rlim; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
484 |
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
|
485 |
// 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
|
486 |
// on virtual memory. |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
487 |
bool result; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
488 |
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
|
489 |
result = false; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
490 |
} else { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
491 |
*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
|
492 |
result = true; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
493 |
} |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
494 |
#ifdef _LP64 |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
495 |
return result; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
496 |
#else |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
497 |
// 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
|
498 |
// 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
|
499 |
// directly use it. |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
500 |
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
|
501 |
if (result) { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
502 |
*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
|
503 |
} else { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
504 |
*limit = max_virtual_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
505 |
} |
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
506 |
|
16605
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
507 |
// 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
|
508 |
// 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
|
509 |
// 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
|
510 |
// 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
|
511 |
// 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
|
512 |
// 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
|
513 |
// 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
|
514 |
// 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
|
515 |
|
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
516 |
// 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
|
517 |
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
|
518 |
|
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
519 |
julong upper_limit = *limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
520 |
|
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
521 |
// 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
|
522 |
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
|
523 |
*limit = upper_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
524 |
} 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
|
525 |
// 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
|
526 |
// 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
|
527 |
*limit = min_allocation_size; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
528 |
} else { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
529 |
// perform the binary search. |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
530 |
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
|
531 |
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
|
532 |
julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit; |
46622
910fc72c03e8
8178501: Replace usages of align macros with calls to the align inline functions
stefank
parents:
46620
diff
changeset
|
533 |
temp_limit = align_down(temp_limit, min_allocation_size); |
16605
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
534 |
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
|
535 |
lower_limit = temp_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
536 |
} else { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
537 |
upper_limit = temp_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
538 |
} |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
539 |
} |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
540 |
*limit = lower_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
541 |
} |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
542 |
return true; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
543 |
#endif |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
544 |
} |
17121
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
545 |
|
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
546 |
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
|
547 |
return getcwd(buf, buflen); |
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
548 |
} |
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
549 |
|
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
550 |
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
|
551 |
return ::fdopen(fd, mode); |
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
552 |
} |
18943 | 553 |
|
53266
57d8566a2732
8214816: os::read() should not transition to _thread_blocked with safepoint check on Solaris
dholmes
parents:
53077
diff
changeset
|
554 |
ssize_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) { |
57d8566a2732
8214816: os::read() should not transition to _thread_blocked with safepoint check on Solaris
dholmes
parents:
53077
diff
changeset
|
555 |
return ::pread(fd, buf, nBytes, offset); |
57d8566a2732
8214816: os::read() should not transition to _thread_blocked with safepoint check on Solaris
dholmes
parents:
53077
diff
changeset
|
556 |
} |
57d8566a2732
8214816: os::read() should not transition to _thread_blocked with safepoint check on Solaris
dholmes
parents:
53077
diff
changeset
|
557 |
|
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
38254
diff
changeset
|
558 |
void os::flockfile(FILE* fp) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
38254
diff
changeset
|
559 |
::flockfile(fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
38254
diff
changeset
|
560 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
38254
diff
changeset
|
561 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
38254
diff
changeset
|
562 |
void os::funlockfile(FILE* fp) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
38254
diff
changeset
|
563 |
::funlockfile(fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
38254
diff
changeset
|
564 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
38254
diff
changeset
|
565 |
|
51106
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
566 |
DIR* os::opendir(const char* dirname) { |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
567 |
assert(dirname != NULL, "just checking"); |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
568 |
return ::opendir(dirname); |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
569 |
} |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
570 |
|
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
571 |
struct dirent* os::readdir(DIR* dirp) { |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
572 |
assert(dirp != NULL, "just checking"); |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
573 |
return ::readdir(dirp); |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
574 |
} |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
575 |
|
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
576 |
int os::closedir(DIR *dirp) { |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
577 |
assert(dirp != NULL, "just checking"); |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
578 |
return ::closedir(dirp); |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
579 |
} |
f605c91e5219
8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents:
50930
diff
changeset
|
580 |
|
19553
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
581 |
// 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
|
582 |
// 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
|
583 |
// Parameters: |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
584 |
// 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
|
585 |
// 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
|
586 |
// 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
|
587 |
// 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
|
588 |
// == 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
|
589 |
// such as "L" |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
590 |
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
|
591 |
bool is_absolute_path) { |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
592 |
char *agent_entry_name; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
593 |
size_t len; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
594 |
size_t name_len; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
595 |
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
|
596 |
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
|
597 |
const char *start; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
598 |
|
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
599 |
if (lib_name != NULL) { |
36585
00416e804a66
8147456: Parsing of argument for -agentpath can write outside of allocated memory
dsamersoff
parents:
36355
diff
changeset
|
600 |
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
|
601 |
if (is_absolute_path) { |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
602 |
// 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
|
603 |
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
|
604 |
lib_name = ++start; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
605 |
} |
36585
00416e804a66
8147456: Parsing of argument for -agentpath can write outside of allocated memory
dsamersoff
parents:
36355
diff
changeset
|
606 |
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
|
607 |
return NULL; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
608 |
} |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
609 |
lib_name += prefix_len; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
610 |
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
|
611 |
} |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
612 |
} |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
613 |
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
|
614 |
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
|
615 |
if (agent_entry_name == NULL) { |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
616 |
return NULL; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
617 |
} |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
618 |
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
|
619 |
if (lib_name != NULL) { |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
620 |
strcat(agent_entry_name, "_"); |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
621 |
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
|
622 |
} |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
623 |
return agent_entry_name; |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
624 |
} |
9bbd930be684
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
18943
diff
changeset
|
625 |
|
22891
1f5d1fff23fa
6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents:
22528
diff
changeset
|
626 |
|
53077 | 627 |
void os::naked_short_nanosleep(jlong ns) { |
628 |
struct timespec req; |
|
629 |
assert(ns > -1 && ns < NANOUNITS, "Un-interruptable sleep, short time use only"); |
|
630 |
req.tv_sec = 0; |
|
631 |
req.tv_nsec = ns; |
|
632 |
::nanosleep(&req, NULL); |
|
633 |
return; |
|
634 |
} |
|
635 |
||
636 |
void os::naked_short_sleep(jlong ms) { |
|
637 |
assert(ms < MILLIUNITS, "Un-interruptable sleep, short time use only"); |
|
638 |
os::naked_short_nanosleep(ms * (NANOUNITS / MILLIUNITS)); |
|
639 |
return; |
|
640 |
} |
|
641 |
||
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
642 |
static const struct { |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
643 |
int sig; const char* name; |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
644 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
645 |
g_signal_info[] = |
22826 | 646 |
{ |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
647 |
{ SIGABRT, "SIGABRT" }, |
22826 | 648 |
#ifdef SIGAIO |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
649 |
{ SIGAIO, "SIGAIO" }, |
22826 | 650 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
651 |
{ SIGALRM, "SIGALRM" }, |
22826 | 652 |
#ifdef SIGALRM1 |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
653 |
{ SIGALRM1, "SIGALRM1" }, |
22826 | 654 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
655 |
{ SIGBUS, "SIGBUS" }, |
22826 | 656 |
#ifdef SIGCANCEL |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
657 |
{ SIGCANCEL, "SIGCANCEL" }, |
22826 | 658 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
659 |
{ SIGCHLD, "SIGCHLD" }, |
22826 | 660 |
#ifdef SIGCLD |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
661 |
{ SIGCLD, "SIGCLD" }, |
22826 | 662 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
663 |
{ SIGCONT, "SIGCONT" }, |
22826 | 664 |
#ifdef SIGCPUFAIL |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
665 |
{ SIGCPUFAIL, "SIGCPUFAIL" }, |
22826 | 666 |
#endif |
667 |
#ifdef SIGDANGER |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
668 |
{ SIGDANGER, "SIGDANGER" }, |
22826 | 669 |
#endif |
670 |
#ifdef SIGDIL |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
671 |
{ SIGDIL, "SIGDIL" }, |
22826 | 672 |
#endif |
673 |
#ifdef SIGEMT |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
674 |
{ SIGEMT, "SIGEMT" }, |
22826 | 675 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
676 |
{ SIGFPE, "SIGFPE" }, |
22826 | 677 |
#ifdef SIGFREEZE |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
678 |
{ SIGFREEZE, "SIGFREEZE" }, |
22826 | 679 |
#endif |
680 |
#ifdef SIGGFAULT |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
681 |
{ SIGGFAULT, "SIGGFAULT" }, |
22826 | 682 |
#endif |
683 |
#ifdef SIGGRANT |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
684 |
{ SIGGRANT, "SIGGRANT" }, |
22826 | 685 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
686 |
{ SIGHUP, "SIGHUP" }, |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
687 |
{ SIGILL, "SIGILL" }, |
58744 | 688 |
#ifdef SIGINFO |
689 |
{ SIGINFO, "SIGINFO" }, |
|
690 |
#endif |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
691 |
{ SIGINT, "SIGINT" }, |
22826 | 692 |
#ifdef SIGIO |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
693 |
{ SIGIO, "SIGIO" }, |
22826 | 694 |
#endif |
695 |
#ifdef SIGIOINT |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
696 |
{ SIGIOINT, "SIGIOINT" }, |
22826 | 697 |
#endif |
698 |
#ifdef SIGIOT |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
699 |
// 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
|
700 |
// synonym for SIGABRT. The result should be "SIGABRT", not |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
701 |
// "SIGIOT". |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
702 |
#if (SIGIOT != SIGABRT ) |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
703 |
{ SIGIOT, "SIGIOT" }, |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
704 |
#endif |
22826 | 705 |
#endif |
706 |
#ifdef SIGKAP |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
707 |
{ SIGKAP, "SIGKAP" }, |
22826 | 708 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
709 |
{ SIGKILL, "SIGKILL" }, |
22826 | 710 |
#ifdef SIGLOST |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
711 |
{ SIGLOST, "SIGLOST" }, |
22826 | 712 |
#endif |
713 |
#ifdef SIGLWP |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
714 |
{ SIGLWP, "SIGLWP" }, |
22826 | 715 |
#endif |
716 |
#ifdef SIGLWPTIMER |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
717 |
{ SIGLWPTIMER, "SIGLWPTIMER" }, |
22826 | 718 |
#endif |
719 |
#ifdef SIGMIGRATE |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
720 |
{ SIGMIGRATE, "SIGMIGRATE" }, |
22826 | 721 |
#endif |
722 |
#ifdef SIGMSG |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
723 |
{ SIGMSG, "SIGMSG" }, |
22826 | 724 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
725 |
{ SIGPIPE, "SIGPIPE" }, |
22826 | 726 |
#ifdef SIGPOLL |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
727 |
{ SIGPOLL, "SIGPOLL" }, |
22826 | 728 |
#endif |
729 |
#ifdef SIGPRE |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
730 |
{ SIGPRE, "SIGPRE" }, |
22826 | 731 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
732 |
{ SIGPROF, "SIGPROF" }, |
22826 | 733 |
#ifdef SIGPTY |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
734 |
{ SIGPTY, "SIGPTY" }, |
22826 | 735 |
#endif |
736 |
#ifdef SIGPWR |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
737 |
{ SIGPWR, "SIGPWR" }, |
22826 | 738 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
739 |
{ SIGQUIT, "SIGQUIT" }, |
22826 | 740 |
#ifdef SIGRECONFIG |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
741 |
{ SIGRECONFIG, "SIGRECONFIG" }, |
22826 | 742 |
#endif |
743 |
#ifdef SIGRECOVERY |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
744 |
{ SIGRECOVERY, "SIGRECOVERY" }, |
22826 | 745 |
#endif |
746 |
#ifdef SIGRESERVE |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
747 |
{ SIGRESERVE, "SIGRESERVE" }, |
22826 | 748 |
#endif |
749 |
#ifdef SIGRETRACT |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
750 |
{ SIGRETRACT, "SIGRETRACT" }, |
22826 | 751 |
#endif |
752 |
#ifdef SIGSAK |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
753 |
{ SIGSAK, "SIGSAK" }, |
22826 | 754 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
755 |
{ SIGSEGV, "SIGSEGV" }, |
22826 | 756 |
#ifdef SIGSOUND |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
757 |
{ SIGSOUND, "SIGSOUND" }, |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
758 |
#endif |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
759 |
#ifdef SIGSTKFLT |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
760 |
{ SIGSTKFLT, "SIGSTKFLT" }, |
22826 | 761 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
762 |
{ SIGSTOP, "SIGSTOP" }, |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
763 |
{ SIGSYS, "SIGSYS" }, |
22826 | 764 |
#ifdef SIGSYSERROR |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
765 |
{ SIGSYSERROR, "SIGSYSERROR" }, |
22826 | 766 |
#endif |
767 |
#ifdef SIGTALRM |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
768 |
{ SIGTALRM, "SIGTALRM" }, |
22826 | 769 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
770 |
{ SIGTERM, "SIGTERM" }, |
22826 | 771 |
#ifdef SIGTHAW |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
772 |
{ SIGTHAW, "SIGTHAW" }, |
22826 | 773 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
774 |
{ SIGTRAP, "SIGTRAP" }, |
22826 | 775 |
#ifdef SIGTSTP |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
776 |
{ SIGTSTP, "SIGTSTP" }, |
22826 | 777 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
778 |
{ SIGTTIN, "SIGTTIN" }, |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
779 |
{ SIGTTOU, "SIGTTOU" }, |
22826 | 780 |
#ifdef SIGURG |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
781 |
{ SIGURG, "SIGURG" }, |
22826 | 782 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
783 |
{ SIGUSR1, "SIGUSR1" }, |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
784 |
{ SIGUSR2, "SIGUSR2" }, |
22826 | 785 |
#ifdef SIGVIRT |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
786 |
{ SIGVIRT, "SIGVIRT" }, |
22826 | 787 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
788 |
{ SIGVTALRM, "SIGVTALRM" }, |
22826 | 789 |
#ifdef SIGWAITING |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
790 |
{ SIGWAITING, "SIGWAITING" }, |
22826 | 791 |
#endif |
792 |
#ifdef SIGWINCH |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
793 |
{ SIGWINCH, "SIGWINCH" }, |
22826 | 794 |
#endif |
795 |
#ifdef SIGWINDOW |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
796 |
{ SIGWINDOW, "SIGWINDOW" }, |
22826 | 797 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
798 |
{ SIGXCPU, "SIGXCPU" }, |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
799 |
{ SIGXFSZ, "SIGXFSZ" }, |
22826 | 800 |
#ifdef SIGXRES |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
801 |
{ SIGXRES, "SIGXRES" }, |
22826 | 802 |
#endif |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
803 |
{ -1, NULL } |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
804 |
}; |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
805 |
|
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
806 |
// 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
|
807 |
const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) { |
22826 | 808 |
|
809 |
const char* ret = NULL; |
|
810 |
||
811 |
#ifdef SIGRTMIN |
|
812 |
if (sig >= SIGRTMIN && sig <= SIGRTMAX) { |
|
813 |
if (sig == SIGRTMIN) { |
|
814 |
ret = "SIGRTMIN"; |
|
815 |
} else if (sig == SIGRTMAX) { |
|
816 |
ret = "SIGRTMAX"; |
|
817 |
} else { |
|
818 |
jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN); |
|
819 |
return out; |
|
820 |
} |
|
821 |
} |
|
822 |
#endif |
|
823 |
||
824 |
if (sig > 0) { |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
825 |
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
|
826 |
if (g_signal_info[idx].sig == sig) { |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
827 |
ret = g_signal_info[idx].name; |
22826 | 828 |
break; |
829 |
} |
|
830 |
} |
|
831 |
} |
|
832 |
||
833 |
if (!ret) { |
|
834 |
if (!is_valid_signal(sig)) { |
|
835 |
ret = "INVALID"; |
|
836 |
} else { |
|
837 |
ret = "UNKNOWN"; |
|
838 |
} |
|
839 |
} |
|
840 |
||
27471 | 841 |
if (out && outlen > 0) { |
842 |
strncpy(out, ret, outlen); |
|
843 |
out[outlen - 1] = '\0'; |
|
844 |
} |
|
22826 | 845 |
return out; |
846 |
} |
|
847 |
||
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
848 |
int os::Posix::get_signal_number(const char* signal_name) { |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
849 |
char tmp[30]; |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
850 |
const char* s = signal_name; |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
851 |
if (s[0] != 'S' || s[1] != 'I' || s[2] != 'G') { |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
852 |
jio_snprintf(tmp, sizeof(tmp), "SIG%s", signal_name); |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
853 |
s = tmp; |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
854 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
855 |
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
|
856 |
if (strcmp(g_signal_info[idx].name, s) == 0) { |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
857 |
return g_signal_info[idx].sig; |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
858 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
859 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
860 |
return -1; |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
861 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
862 |
|
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
863 |
int os::get_signal_number(const char* signal_name) { |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
864 |
return os::Posix::get_signal_number(signal_name); |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
865 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
866 |
|
22826 | 867 |
// Returns true if signal number is valid. |
868 |
bool os::Posix::is_valid_signal(int sig) { |
|
869 |
// MacOS not really POSIX compliant: sigaddset does not return |
|
870 |
// an error for invalid signal numbers. However, MacOS does not |
|
871 |
// support real time signals and simply seems to have just 33 |
|
872 |
// signals with no holes in the signal range. |
|
873 |
#ifdef __APPLE__ |
|
874 |
return sig >= 1 && sig < NSIG; |
|
875 |
#else |
|
876 |
// Use sigaddset to check for signal validity. |
|
877 |
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
|
878 |
sigemptyset(&set); |
22826 | 879 |
if (sigaddset(&set, sig) == -1 && errno == EINVAL) { |
880 |
return false; |
|
881 |
} |
|
882 |
return true; |
|
883 |
#endif |
|
884 |
} |
|
885 |
||
50177
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
886 |
bool os::Posix::is_sig_ignored(int sig) { |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
887 |
struct sigaction oact; |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
888 |
sigaction(sig, (struct sigaction*)NULL, &oact); |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
889 |
void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
890 |
: CAST_FROM_FN_PTR(void*, oact.sa_handler); |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
891 |
if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) { |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
892 |
return true; |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
893 |
} else { |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
894 |
return false; |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
895 |
} |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
896 |
} |
9806f23d5e5e
8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents:
49594
diff
changeset
|
897 |
|
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
898 |
// Returns: |
35047
b1f924d2efe8
8145073: Filename and linenumber are not printed for asserts any more.
david
parents:
34621
diff
changeset
|
899 |
// NULL for an invalid signal number |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
900 |
// "SIG<num>" for a valid but unknown signal number |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
901 |
// signal name otherwise. |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
902 |
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
|
903 |
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
|
904 |
return NULL; |
34621
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
905 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
906 |
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
|
907 |
if (strcmp(name, "UNKNOWN") == 0) { |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
908 |
jio_snprintf(buf, size, "SIG%d", sig); |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
909 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
910 |
return buf; |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
911 |
} |
7676bec20997
8143291: Remove redundant coding around os::exception_name
stuefe
parents:
34305
diff
changeset
|
912 |
|
22826 | 913 |
#define NUM_IMPORTANT_SIGS 32 |
914 |
// Returns one-line short description of a signal set in a user provided buffer. |
|
915 |
const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) { |
|
22827 | 916 |
assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size"); |
22826 | 917 |
// Note: for shortness, just print out the first 32. That should |
918 |
// cover most of the useful ones, apart from realtime signals. |
|
919 |
for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) { |
|
920 |
const int rc = sigismember(set, sig); |
|
921 |
if (rc == -1 && errno == EINVAL) { |
|
922 |
buffer[sig-1] = '?'; |
|
923 |
} else { |
|
924 |
buffer[sig-1] = rc == 0 ? '0' : '1'; |
|
925 |
} |
|
926 |
} |
|
927 |
buffer[NUM_IMPORTANT_SIGS] = 0; |
|
928 |
return buffer; |
|
929 |
} |
|
930 |
||
931 |
// Prints one-line description of a signal set. |
|
932 |
void os::Posix::print_signal_set_short(outputStream* st, const sigset_t* set) { |
|
933 |
char buf[NUM_IMPORTANT_SIGS + 1]; |
|
934 |
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
|
935 |
st->print("%s", buf); |
22826 | 936 |
} |
937 |
||
938 |
// Writes one-line description of a combination of sigaction.sa_flags into a user |
|
939 |
// provided buffer. Returns that buffer. |
|
940 |
const char* os::Posix::describe_sa_flags(int flags, char* buffer, size_t size) { |
|
941 |
char* p = buffer; |
|
942 |
size_t remaining = size; |
|
943 |
bool first = true; |
|
944 |
int idx = 0; |
|
945 |
||
946 |
assert(buffer, "invalid argument"); |
|
947 |
||
948 |
if (size == 0) { |
|
949 |
return buffer; |
|
950 |
} |
|
951 |
||
952 |
strncpy(buffer, "none", size); |
|
953 |
||
954 |
const struct { |
|
35155 | 955 |
// NB: i is an unsigned int here because SA_RESETHAND is on some |
956 |
// systems 0x80000000, which is implicitly unsigned. Assignining |
|
957 |
// it to an int field would be an overflow in unsigned-to-signed |
|
958 |
// conversion. |
|
959 |
unsigned int i; |
|
22826 | 960 |
const char* s; |
961 |
} flaginfo [] = { |
|
962 |
{ SA_NOCLDSTOP, "SA_NOCLDSTOP" }, |
|
963 |
{ SA_ONSTACK, "SA_ONSTACK" }, |
|
964 |
{ SA_RESETHAND, "SA_RESETHAND" }, |
|
965 |
{ SA_RESTART, "SA_RESTART" }, |
|
966 |
{ SA_SIGINFO, "SA_SIGINFO" }, |
|
967 |
{ SA_NOCLDWAIT, "SA_NOCLDWAIT" }, |
|
968 |
{ SA_NODEFER, "SA_NODEFER" }, |
|
969 |
#ifdef AIX |
|
970 |
{ SA_ONSTACK, "SA_ONSTACK" }, |
|
971 |
{ SA_OLDSTYLE, "SA_OLDSTYLE" }, |
|
972 |
#endif |
|
973 |
{ 0, NULL } |
|
974 |
}; |
|
975 |
||
976 |
for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) { |
|
977 |
if (flags & flaginfo[idx].i) { |
|
978 |
if (first) { |
|
979 |
jio_snprintf(p, remaining, "%s", flaginfo[idx].s); |
|
980 |
first = false; |
|
981 |
} else { |
|
982 |
jio_snprintf(p, remaining, "|%s", flaginfo[idx].s); |
|
983 |
} |
|
984 |
const size_t len = strlen(p); |
|
985 |
p += len; |
|
986 |
remaining -= len; |
|
987 |
} |
|
988 |
} |
|
989 |
||
990 |
buffer[size - 1] = '\0'; |
|
991 |
||
992 |
return buffer; |
|
993 |
} |
|
994 |
||
995 |
// Prints one-line description of a combination of sigaction.sa_flags. |
|
996 |
void os::Posix::print_sa_flags(outputStream* st, int flags) { |
|
997 |
char buffer[0x100]; |
|
998 |
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
|
999 |
st->print("%s", buffer); |
22826 | 1000 |
} |
1001 |
||
1002 |
// Helper function for os::Posix::print_siginfo_...(): |
|
1003 |
// return a textual description for signal code. |
|
1004 |
struct enum_sigcode_desc_t { |
|
1005 |
const char* s_name; |
|
1006 |
const char* s_desc; |
|
1007 |
}; |
|
1008 |
||
1009 |
static bool get_signal_code_description(const siginfo_t* si, enum_sigcode_desc_t* out) { |
|
1010 |
||
1011 |
const struct { |
|
1012 |
int sig; int code; const char* s_code; const char* s_desc; |
|
1013 |
} t1 [] = { |
|
1014 |
{ SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode." }, |
|
1015 |
{ SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand." }, |
|
1016 |
{ SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode." }, |
|
1017 |
{ SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap." }, |
|
1018 |
{ SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode." }, |
|
1019 |
{ SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register." }, |
|
1020 |
{ SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error." }, |
|
1021 |
{ SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error." }, |
|
1022 |
#if defined(IA64) && defined(LINUX) |
|
1023 |
{ SIGILL, ILL_BADIADDR, "ILL_BADIADDR", "Unimplemented instruction address" }, |
|
1024 |
{ SIGILL, ILL_BREAK, "ILL_BREAK", "Application Break instruction" }, |
|
1025 |
#endif |
|
1026 |
{ SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero." }, |
|
1027 |
{ SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow." }, |
|
1028 |
{ SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating-point divide by zero." }, |
|
1029 |
{ SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating-point overflow." }, |
|
1030 |
{ SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating-point underflow." }, |
|
1031 |
{ SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating-point inexact result." }, |
|
1032 |
{ SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating-point operation." }, |
|
1033 |
{ SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range." }, |
|
1034 |
{ SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object." }, |
|
1035 |
{ SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for mapped object." }, |
|
1036 |
#ifdef AIX |
|
1037 |
// no explanation found what keyerr would be |
|
1038 |
{ SIGSEGV, SEGV_KEYERR, "SEGV_KEYERR", "key error" }, |
|
1039 |
#endif |
|
1040 |
#if defined(IA64) && !defined(AIX) |
|
1041 |
{ SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" }, |
|
1042 |
#endif |
|
34233
2cf348387c44
8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
33766
diff
changeset
|
1043 |
#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
|
1044 |
// 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
|
1045 |
#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
|
1046 |
#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
|
1047 |
#endif |
2cf348387c44
8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
33766
diff
changeset
|
1048 |
{ 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
|
1049 |
#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
|
1050 |
#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
|
1051 |
#endif |
2cf348387c44
8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
33766
diff
changeset
|
1052 |
{ 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
|
1053 |
#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
|
1054 |
#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
|
1055 |
#endif |
2cf348387c44
8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
33766
diff
changeset
|
1056 |
{ 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
|
1057 |
#endif // defined(__sparc) && defined(SOLARIS) |
22826 | 1058 |
{ SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment." }, |
1059 |
{ SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Nonexistent physical address." }, |
|
1060 |
{ SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object-specific hardware error." }, |
|
1061 |
{ SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint." }, |
|
1062 |
{ SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap." }, |
|
1063 |
{ SIGCHLD, CLD_EXITED, "CLD_EXITED", "Child has exited." }, |
|
1064 |
{ SIGCHLD, CLD_KILLED, "CLD_KILLED", "Child has terminated abnormally and did not create a core file." }, |
|
1065 |
{ SIGCHLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally and created a core file." }, |
|
1066 |
{ SIGCHLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped." }, |
|
1067 |
{ SIGCHLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped." }, |
|
1068 |
{ SIGCHLD, CLD_CONTINUED,"CLD_CONTINUED","Stopped child has continued." }, |
|
1069 |
#ifdef SIGPOLL |
|
1070 |
{ SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available." }, |
|
1071 |
{ SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available." }, |
|
1072 |
{ SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error." }, |
|
1073 |
{ SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available." }, |
|
1074 |
{ SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected. [Option End]" }, |
|
1075 |
#endif |
|
1076 |
{ -1, -1, NULL, NULL } |
|
1077 |
}; |
|
1078 |
||
1079 |
// Codes valid in any signal context. |
|
1080 |
const struct { |
|
1081 |
int code; const char* s_code; const char* s_desc; |
|
1082 |
} t2 [] = { |
|
1083 |
{ SI_USER, "SI_USER", "Signal sent by kill()." }, |
|
1084 |
{ SI_QUEUE, "SI_QUEUE", "Signal sent by the sigqueue()." }, |
|
1085 |
{ SI_TIMER, "SI_TIMER", "Signal generated by expiration of a timer set by timer_settime()." }, |
|
1086 |
{ SI_ASYNCIO, "SI_ASYNCIO", "Signal generated by completion of an asynchronous I/O request." }, |
|
1087 |
{ SI_MESGQ, "SI_MESGQ", "Signal generated by arrival of a message on an empty message queue." }, |
|
1088 |
// Linux specific |
|
1089 |
#ifdef SI_TKILL |
|
1090 |
{ SI_TKILL, "SI_TKILL", "Signal sent by tkill (pthread_kill)" }, |
|
1091 |
#endif |
|
1092 |
#ifdef SI_DETHREAD |
|
1093 |
{ SI_DETHREAD, "SI_DETHREAD", "Signal sent by execve() killing subsidiary threads" }, |
|
1094 |
#endif |
|
1095 |
#ifdef SI_KERNEL |
|
1096 |
{ SI_KERNEL, "SI_KERNEL", "Signal sent by kernel." }, |
|
1097 |
#endif |
|
1098 |
#ifdef SI_SIGIO |
|
1099 |
{ SI_SIGIO, "SI_SIGIO", "Signal sent by queued SIGIO" }, |
|
1100 |
#endif |
|
1101 |
||
1102 |
#ifdef AIX |
|
1103 |
{ SI_UNDEFINED, "SI_UNDEFINED","siginfo contains partial information" }, |
|
1104 |
{ SI_EMPTY, "SI_EMPTY", "siginfo contains no useful information" }, |
|
1105 |
#endif |
|
1106 |
||
1107 |
#ifdef __sun |
|
1108 |
{ SI_NOINFO, "SI_NOINFO", "No signal information" }, |
|
1109 |
{ SI_RCTL, "SI_RCTL", "kernel generated signal via rctl action" }, |
|
1110 |
{ SI_LWP, "SI_LWP", "Signal sent via lwp_kill" }, |
|
1111 |
#endif |
|
1112 |
||
1113 |
{ -1, NULL, NULL } |
|
1114 |
}; |
|
1115 |
||
1116 |
const char* s_code = NULL; |
|
1117 |
const char* s_desc = NULL; |
|
1118 |
||
1119 |
for (int i = 0; t1[i].sig != -1; i ++) { |
|
1120 |
if (t1[i].sig == si->si_signo && t1[i].code == si->si_code) { |
|
1121 |
s_code = t1[i].s_code; |
|
1122 |
s_desc = t1[i].s_desc; |
|
1123 |
break; |
|
1124 |
} |
|
1125 |
} |
|
1126 |
||
1127 |
if (s_code == NULL) { |
|
1128 |
for (int i = 0; t2[i].s_code != NULL; i ++) { |
|
1129 |
if (t2[i].code == si->si_code) { |
|
1130 |
s_code = t2[i].s_code; |
|
1131 |
s_desc = t2[i].s_desc; |
|
1132 |
} |
|
1133 |
} |
|
1134 |
} |
|
1135 |
||
1136 |
if (s_code == NULL) { |
|
1137 |
out->s_name = "unknown"; |
|
1138 |
out->s_desc = "unknown"; |
|
1139 |
return false; |
|
1140 |
} |
|
1141 |
||
1142 |
out->s_name = s_code; |
|
1143 |
out->s_desc = s_desc; |
|
1144 |
||
1145 |
return true; |
|
1146 |
} |
|
1147 |
||
54031
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1148 |
bool os::signal_sent_by_kill(const void* siginfo) { |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1149 |
const siginfo_t* const si = (const siginfo_t*)siginfo; |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1150 |
return si->si_code == SI_USER || si->si_code == SI_QUEUE |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1151 |
#ifdef SI_TKILL |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1152 |
|| si->si_code == SI_TKILL |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1153 |
#endif |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1154 |
; |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1155 |
} |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1156 |
|
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1157 |
void os::print_siginfo(outputStream* os, const void* si0) { |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1158 |
|
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1159 |
const siginfo_t* const si = (const siginfo_t*) si0; |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1160 |
|
22826 | 1161 |
char buf[20]; |
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1162 |
os->print("siginfo:"); |
22826 | 1163 |
|
1164 |
if (!si) { |
|
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1165 |
os->print(" <null>"); |
22826 | 1166 |
return; |
1167 |
} |
|
1168 |
||
1169 |
const int sig = si->si_signo; |
|
1170 |
||
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1171 |
os->print(" si_signo: %d (%s)", sig, os::Posix::get_signal_name(sig, buf, sizeof(buf))); |
22826 | 1172 |
|
1173 |
enum_sigcode_desc_t ed; |
|
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1174 |
get_signal_code_description(si, &ed); |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1175 |
os->print(", si_code: %d (%s)", si->si_code, ed.s_name); |
22826 | 1176 |
|
1177 |
if (si->si_errno) { |
|
1178 |
os->print(", si_errno: %d", si->si_errno); |
|
1179 |
} |
|
1180 |
||
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1181 |
// Output additional information depending on the signal code. |
22826 | 1182 |
|
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1183 |
// 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
|
1184 |
// 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
|
1185 |
// 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
|
1186 |
// which case we print out pid or tid of the sender. |
54031
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1187 |
if (signal_sent_by_kill(si)) { |
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1188 |
const pid_t pid = si->si_pid; |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1189 |
os->print(", si_pid: %ld", (long) pid); |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1190 |
if (IS_VALID_PID(pid)) { |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1191 |
const pid_t me = getpid(); |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1192 |
if (me == pid) { |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1193 |
os->print(" (current process)"); |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1194 |
} |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1195 |
} else { |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1196 |
os->print(" (invalid)"); |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1197 |
} |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1198 |
os->print(", si_uid: %ld", (long) si->si_uid); |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1199 |
if (sig == SIGCHLD) { |
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1200 |
os->print(", si_status: %d", si->si_status); |
22826 | 1201 |
} |
1202 |
} else if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || |
|
1203 |
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
|
1204 |
os->print(", si_addr: " PTR_FORMAT, p2i(si->si_addr)); |
22826 | 1205 |
#ifdef SIGPOLL |
1206 |
} else if (sig == SIGPOLL) { |
|
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1207 |
os->print(", si_band: %ld", si->si_band); |
22826 | 1208 |
#endif |
1209 |
} |
|
35176
11a9d4022d9e
8144219: [posix] Remove redundant code around os::print_siginfo()
stuefe
parents:
35077
diff
changeset
|
1210 |
|
22826 | 1211 |
} |
1212 |
||
54031
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1213 |
bool os::signal_thread(Thread* thread, int sig, const char* reason) { |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1214 |
OSThread* osthread = thread->osthread(); |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1215 |
if (osthread) { |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1216 |
#if defined (SOLARIS) |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1217 |
// Note: we cannot use pthread_kill on Solaris - not because |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1218 |
// its missing, but because we do not have the pthread_t id. |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1219 |
int status = thr_kill(osthread->thread_id(), sig); |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1220 |
#else |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1221 |
int status = pthread_kill(osthread->pthread_id(), sig); |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1222 |
#endif |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1223 |
if (status == 0) { |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1224 |
Events::log(Thread::current(), "sent signal %d to Thread " INTPTR_FORMAT " because %s.", |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1225 |
sig, p2i(thread), reason); |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1226 |
return true; |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1227 |
} |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1228 |
} |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1229 |
return false; |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1230 |
} |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
53907
diff
changeset
|
1231 |
|
34305
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1232 |
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
|
1233 |
return pthread_sigmask(SIG_UNBLOCK, set, NULL); |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1234 |
} |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1235 |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
35047
diff
changeset
|
1236 |
address os::Posix::ucontext_get_pc(const ucontext_t* ctx) { |
40010 | 1237 |
#if defined(AIX) |
1238 |
return Aix::ucontext_get_pc(ctx); |
|
1239 |
#elif defined(BSD) |
|
1240 |
return Bsd::ucontext_get_pc(ctx); |
|
1241 |
#elif defined(LINUX) |
|
34305
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1242 |
return Linux::ucontext_get_pc(ctx); |
40010 | 1243 |
#elif defined(SOLARIS) |
34305
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1244 |
return Solaris::ucontext_get_pc(ctx); |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1245 |
#else |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1246 |
VMError::report_and_die("unimplemented ucontext_get_pc"); |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1247 |
#endif |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1248 |
} |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1249 |
|
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1250 |
void os::Posix::ucontext_set_pc(ucontext_t* ctx, address pc) { |
40010 | 1251 |
#if defined(AIX) |
1252 |
Aix::ucontext_set_pc(ctx, pc); |
|
1253 |
#elif defined(BSD) |
|
1254 |
Bsd::ucontext_set_pc(ctx, pc); |
|
1255 |
#elif defined(LINUX) |
|
34305
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1256 |
Linux::ucontext_set_pc(ctx, pc); |
40010 | 1257 |
#elif defined(SOLARIS) |
34305
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1258 |
Solaris::ucontext_set_pc(ctx, pc); |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1259 |
#else |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1260 |
VMError::report_and_die("unimplemented ucontext_get_pc"); |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1261 |
#endif |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1262 |
} |
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1263 |
|
36355
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1264 |
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
|
1265 |
size_t stack_size = 0; |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1266 |
size_t guard_size = 0; |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1267 |
int detachstate = 0; |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1268 |
pthread_attr_getstacksize(attr, &stack_size); |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1269 |
pthread_attr_getguardsize(attr, &guard_size); |
42905 | 1270 |
// Work around linux NPTL implementation error, see also os::create_thread() in os_linux.cpp. |
1271 |
LINUX_ONLY(stack_size -= guard_size); |
|
36355
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1272 |
pthread_attr_getdetachstate(attr, &detachstate); |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1273 |
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
|
1274 |
stack_size / 1024, guard_size / 1024, |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1275 |
(detachstate == PTHREAD_CREATE_DETACHED ? "detached" : "joinable")); |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1276 |
return buf; |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1277 |
} |
dd339cbafd31
8149036: Add tracing for thread related events at os level
stuefe
parents:
36174
diff
changeset
|
1278 |
|
46331 | 1279 |
char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen) { |
1280 |
||
1281 |
if (filename == NULL || outbuf == NULL || outbuflen < 1) { |
|
1282 |
assert(false, "os::Posix::realpath: invalid arguments."); |
|
1283 |
errno = EINVAL; |
|
1284 |
return NULL; |
|
1285 |
} |
|
1286 |
||
1287 |
char* result = NULL; |
|
1288 |
||
1289 |
// This assumes platform realpath() is implemented according to POSIX.1-2008. |
|
1290 |
// POSIX.1-2008 allows to specify NULL for the output buffer, in which case |
|
1291 |
// output buffer is dynamically allocated and must be ::free()'d by the caller. |
|
1292 |
char* p = ::realpath(filename, NULL); |
|
1293 |
if (p != NULL) { |
|
1294 |
if (strlen(p) < outbuflen) { |
|
1295 |
strcpy(outbuf, p); |
|
1296 |
result = outbuf; |
|
1297 |
} else { |
|
1298 |
errno = ENAMETOOLONG; |
|
1299 |
} |
|
1300 |
::free(p); // *not* os::free |
|
1301 |
} else { |
|
1302 |
// Fallback for platforms struggling with modern Posix standards (AIX 5.3, 6.1). If realpath |
|
1303 |
// returns EINVAL, this may indicate that realpath is not POSIX.1-2008 compatible and |
|
1304 |
// that it complains about the NULL we handed down as user buffer. |
|
1305 |
// In this case, use the user provided buffer but at least check whether realpath caused |
|
1306 |
// a memory overwrite. |
|
1307 |
if (errno == EINVAL) { |
|
1308 |
outbuf[outbuflen - 1] = '\0'; |
|
1309 |
p = ::realpath(filename, outbuf); |
|
1310 |
if (p != NULL) { |
|
1311 |
guarantee(outbuf[outbuflen - 1] == '\0', "realpath buffer overwrite detected."); |
|
1312 |
result = p; |
|
1313 |
} |
|
1314 |
} |
|
1315 |
} |
|
1316 |
return result; |
|
1317 |
||
1318 |
} |
|
1319 |
||
50667
cc58f1fa0438
8203680: os::stat() on Posix platform does not need to copy input path
stuefe
parents:
50333
diff
changeset
|
1320 |
int os::stat(const char *path, struct stat *sbuf) { |
cc58f1fa0438
8203680: os::stat() on Posix platform does not need to copy input path
stuefe
parents:
50333
diff
changeset
|
1321 |
return ::stat(path, sbuf); |
cc58f1fa0438
8203680: os::stat() on Posix platform does not need to copy input path
stuefe
parents:
50333
diff
changeset
|
1322 |
} |
cc58f1fa0438
8203680: os::stat() on Posix platform does not need to copy input path
stuefe
parents:
50333
diff
changeset
|
1323 |
|
cc58f1fa0438
8203680: os::stat() on Posix platform does not need to copy input path
stuefe
parents:
50333
diff
changeset
|
1324 |
char * os::native_path(char *path) { |
cc58f1fa0438
8203680: os::stat() on Posix platform does not need to copy input path
stuefe
parents:
50333
diff
changeset
|
1325 |
return path; |
cc58f1fa0438
8203680: os::stat() on Posix platform does not need to copy input path
stuefe
parents:
50333
diff
changeset
|
1326 |
} |
46331 | 1327 |
|
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1328 |
bool os::same_files(const char* file1, const char* file2) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1329 |
if (strcmp(file1, file2) == 0) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1330 |
return true; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1331 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1332 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1333 |
bool is_same = false; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1334 |
struct stat st1; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1335 |
struct stat st2; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1336 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1337 |
if (os::stat(file1, &st1) < 0) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1338 |
return false; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1339 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1340 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1341 |
if (os::stat(file2, &st2) < 0) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1342 |
return false; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1343 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1344 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1345 |
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1346 |
// same files |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1347 |
is_same = true; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1348 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1349 |
return is_same; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1350 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54195
diff
changeset
|
1351 |
|
41070
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1352 |
// 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
|
1353 |
// the java system classes, including StackOverflowError - depends on page |
42906
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1354 |
// size. |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1355 |
// The space needed for frames during startup is platform dependent. It |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1356 |
// depends on word size, platform calling conventions, C frame layout and |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1357 |
// interpreter/C1/C2 design decisions. Therefore this is given in a |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1358 |
// platform (os/cpu) dependent constant. |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1359 |
// 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
|
1360 |
// 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
|
1361 |
// 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
|
1362 |
jint os::Posix::set_minimum_stack_sizes() { |
46346
4085295dcf51
8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents:
46331
diff
changeset
|
1363 |
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
|
1364 |
|
42906
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1365 |
_java_thread_min_stack_allowed = _java_thread_min_stack_allowed + |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1366 |
JavaThread::stack_guard_zone_size() + |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1367 |
JavaThread::stack_shadow_zone_size(); |
41070
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1368 |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46618
diff
changeset
|
1369 |
_java_thread_min_stack_allowed = align_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
|
1370 |
_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
|
1371 |
|
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1372 |
size_t stack_size_in_bytes = ThreadStackSize * K; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1373 |
if (stack_size_in_bytes != 0 && |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1374 |
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
|
1375 |
// 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
|
1376 |
// 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
|
1377 |
// of "ThreadStackSize" to be more friendly. |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1378 |
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
|
1379 |
"Specify at least " SIZE_FORMAT "k", |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1380 |
_java_thread_min_stack_allowed / K); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1381 |
return JNI_ERR; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1382 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1383 |
|
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1384 |
// 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
|
1385 |
// the yellow/red zones can be guarded. |
46620
750c6edff33b
8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents:
46619
diff
changeset
|
1386 |
JavaThread::set_stack_size_at_create(align_up(stack_size_in_bytes, vm_page_size())); |
42906
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1387 |
|
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1388 |
// Reminder: a compiler thread is a Java thread. |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1389 |
_compiler_thread_min_stack_allowed = _compiler_thread_min_stack_allowed + |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1390 |
JavaThread::stack_guard_zone_size() + |
1a8db9cf1407
8170655: [posix] Fix minimum stack size computations
goetz
parents:
42905
diff
changeset
|
1391 |
JavaThread::stack_shadow_zone_size(); |
41070
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1392 |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46618
diff
changeset
|
1393 |
_compiler_thread_min_stack_allowed = align_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
|
1394 |
_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
|
1395 |
|
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1396 |
stack_size_in_bytes = CompilerThreadStackSize * K; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1397 |
if (stack_size_in_bytes != 0 && |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1398 |
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
|
1399 |
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
|
1400 |
"Specify at least " SIZE_FORMAT "k", |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1401 |
_compiler_thread_min_stack_allowed / K); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1402 |
return JNI_ERR; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1403 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1404 |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46618
diff
changeset
|
1405 |
_vm_internal_thread_min_stack_allowed = align_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
|
1406 |
_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
|
1407 |
|
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1408 |
stack_size_in_bytes = VMThreadStackSize * K; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1409 |
if (stack_size_in_bytes != 0 && |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1410 |
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
|
1411 |
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
|
1412 |
"Specify at least " SIZE_FORMAT "k", |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1413 |
_vm_internal_thread_min_stack_allowed / K); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1414 |
return JNI_ERR; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1415 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1416 |
return JNI_OK; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1417 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1418 |
|
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1419 |
// 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
|
1420 |
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
|
1421 |
size_t stack_size; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1422 |
if (req_stack_size == 0) { |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1423 |
stack_size = default_stack_size(thr_type); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1424 |
} else { |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1425 |
stack_size = req_stack_size; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1426 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1427 |
|
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1428 |
switch (thr_type) { |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1429 |
case os::java_thread: |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1430 |
// 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
|
1431 |
// changed with the flag -Xss |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1432 |
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
|
1433 |
// 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
|
1434 |
stack_size = JavaThread::stack_size_at_create(); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1435 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1436 |
stack_size = MAX2(stack_size, |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1437 |
_java_thread_min_stack_allowed); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1438 |
break; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1439 |
case os::compiler_thread: |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1440 |
if (req_stack_size == 0 && CompilerThreadStackSize > 0) { |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1441 |
// 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
|
1442 |
stack_size = (size_t)(CompilerThreadStackSize * K); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1443 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1444 |
stack_size = MAX2(stack_size, |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1445 |
_compiler_thread_min_stack_allowed); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1446 |
break; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1447 |
case os::vm_thread: |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1448 |
case os::pgc_thread: |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1449 |
case os::cgc_thread: |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1450 |
case os::watcher_thread: |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1451 |
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
|
1452 |
if (req_stack_size == 0 && VMThreadStackSize > 0) { |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1453 |
// 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
|
1454 |
stack_size = (size_t)(VMThreadStackSize * K); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1455 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1456 |
|
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1457 |
stack_size = MAX2(stack_size, |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1458 |
_vm_internal_thread_min_stack_allowed); |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1459 |
break; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1460 |
} |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1461 |
|
46346
4085295dcf51
8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents:
46331
diff
changeset
|
1462 |
// 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
|
1463 |
// 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
|
1464 |
if (stack_size <= SIZE_MAX - vm_page_size()) { |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46618
diff
changeset
|
1465 |
stack_size = align_up(stack_size, vm_page_size()); |
46346
4085295dcf51
8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents:
46331
diff
changeset
|
1466 |
} else { |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46618
diff
changeset
|
1467 |
stack_size = align_down(stack_size, vm_page_size()); |
46346
4085295dcf51
8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents:
46331
diff
changeset
|
1468 |
} |
4085295dcf51
8176768: hotspot ignores PTHREAD_STACK_MIN when creating new threads
cjplummer
parents:
46331
diff
changeset
|
1469 |
|
41070
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1470 |
return stack_size; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40383
diff
changeset
|
1471 |
} |
34305
e399e6b44631
8136978: Much nearly duplicated code for vmError support
sebastian
parents:
34233
diff
changeset
|
1472 |
|
50333
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1473 |
bool os::Posix::is_root(uid_t uid){ |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1474 |
return ROOT_UID == uid; |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1475 |
} |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1476 |
|
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1477 |
bool os::Posix::matches_effective_uid_or_root(uid_t uid) { |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1478 |
return is_root(uid) || geteuid() == uid; |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1479 |
} |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1480 |
|
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1481 |
bool os::Posix::matches_effective_uid_and_gid_or_root(uid_t uid, gid_t gid) { |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1482 |
return is_root(uid) || (geteuid() == uid && getegid() == gid); |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1483 |
} |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
50177
diff
changeset
|
1484 |
|
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1485 |
Thread* os::ThreadCrashProtection::_protected_thread = NULL; |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1486 |
os::ThreadCrashProtection* os::ThreadCrashProtection::_crash_protection = NULL; |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1487 |
volatile intptr_t os::ThreadCrashProtection::_crash_mux = 0; |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1488 |
|
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1489 |
os::ThreadCrashProtection::ThreadCrashProtection() { |
18943 | 1490 |
} |
1491 |
||
1492 |
/* |
|
1493 |
* See the caveats for this class in os_posix.hpp |
|
1494 |
* Protects the callback call so that SIGSEGV / SIGBUS jumps back into this |
|
1495 |
* method and returns false. If none of the signals are raised, returns true. |
|
1496 |
* The callback is supposed to provide the method that should be protected. |
|
1497 |
*/ |
|
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1498 |
bool os::ThreadCrashProtection::call(os::CrashProtectionCallback& cb) { |
19691
5116fb76692a
8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents:
18943
diff
changeset
|
1499 |
sigset_t saved_sig_mask; |
5116fb76692a
8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents:
18943
diff
changeset
|
1500 |
|
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1501 |
Thread::muxAcquire(&_crash_mux, "CrashProtection"); |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1502 |
|
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1503 |
_protected_thread = Thread::current_or_null(); |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1504 |
assert(_protected_thread != NULL, "Cannot crash protect a NULL thread"); |
18943 | 1505 |
|
19691
5116fb76692a
8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents:
18943
diff
changeset
|
1506 |
// 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
|
1507 |
// 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
|
1508 |
// for the process, not the thread |
5116fb76692a
8023720: (hotspot) setjmp/longjmp changes the process signal mask on OS X
sla
parents:
18943
diff
changeset
|
1509 |
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
|
1510 |
if (sigsetjmp(_jmpbuf, 0) == 0) { |
18943 | 1511 |
// make sure we can see in the signal handler that we have crash protection |
1512 |
// installed |
|
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1513 |
_crash_protection = this; |
18943 | 1514 |
cb.call(); |
1515 |
// and clear the crash protection |
|
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1516 |
_crash_protection = NULL; |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1517 |
_protected_thread = NULL; |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1518 |
Thread::muxRelease(&_crash_mux); |
18943 | 1519 |
return true; |
1520 |
} |
|
1521 |
// 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
|
1522 |
pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL); |
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1523 |
_crash_protection = NULL; |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1524 |
_protected_thread = NULL; |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1525 |
Thread::muxRelease(&_crash_mux); |
18943 | 1526 |
return false; |
1527 |
} |
|
1528 |
||
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1529 |
void os::ThreadCrashProtection::restore() { |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1530 |
assert(_crash_protection != NULL, "must have crash protection"); |
18943 | 1531 |
siglongjmp(_jmpbuf, 1); |
1532 |
} |
|
1533 |
||
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1534 |
void os::ThreadCrashProtection::check_crash_protection(int sig, |
18943 | 1535 |
Thread* thread) { |
1536 |
||
1537 |
if (thread != NULL && |
|
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1538 |
thread == _protected_thread && |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1539 |
_crash_protection != NULL) { |
18943 | 1540 |
|
1541 |
if (sig == SIGSEGV || sig == SIGBUS) { |
|
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
46625
diff
changeset
|
1542 |
_crash_protection->restore(); |
18943 | 1543 |
} |
1544 |
} |
|
1545 |
} |
|
31610 | 1546 |
|
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1547 |
// Shared clock/time and other supporting routines for pthread_mutex/cond |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1548 |
// initialization. This is enabled on Solaris but only some of the clock/time |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1549 |
// functionality is actually used there. |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1550 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1551 |
// 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
|
1552 |
// 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
|
1553 |
// 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
|
1554 |
// time-of-day clock. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1555 |
static pthread_condattr_t _condAttr[1]; |
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 |
// 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
|
1558 |
// 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
|
1559 |
static pthread_mutexattr_t _mutexAttr[1]; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1560 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1561 |
// 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
|
1562 |
static void pthread_init_common(void) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1563 |
int status; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1564 |
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
|
1565 |
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
|
1566 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1567 |
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
|
1568 |
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
|
1569 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1570 |
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
|
1571 |
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
|
1572 |
} |
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
1573 |
// Solaris has it's own PlatformMutex, distinct from the one for POSIX. |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
1574 |
NOT_SOLARIS(os::PlatformMutex::init();) |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1575 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1576 |
|
54090
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1577 |
#ifndef SOLARIS |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1578 |
sigset_t sigs; |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1579 |
struct sigaction sigact[NSIG]; |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1580 |
|
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1581 |
struct sigaction* os::Posix::get_preinstalled_handler(int sig) { |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1582 |
if (sigismember(&sigs, sig)) { |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1583 |
return &sigact[sig]; |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1584 |
} |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1585 |
return NULL; |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1586 |
} |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1587 |
|
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1588 |
void os::Posix::save_preinstalled_handler(int sig, struct sigaction& oldAct) { |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1589 |
assert(sig > 0 && sig < NSIG, "vm signal out of expected range"); |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1590 |
sigact[sig] = oldAct; |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1591 |
sigaddset(&sigs, sig); |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1592 |
} |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1593 |
#endif |
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1594 |
|
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1595 |
// 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
|
1596 |
// 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
|
1597 |
// 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
|
1598 |
// 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
|
1599 |
// 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
|
1600 |
// 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
|
1601 |
// int or int64_t). |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1602 |
// |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1603 |
#ifdef SUPPORTS_CLOCK_MONOTONIC |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1604 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1605 |
// 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
|
1606 |
|
53654
7054249afee5
8217843: Performance regression related to os::supports_monotonic_clock() on linux
dholmes
parents:
53646
diff
changeset
|
1607 |
int (*os::Posix::_clock_gettime)(clockid_t, struct timespec *) = NULL; |
7054249afee5
8217843: Performance regression related to os::supports_monotonic_clock() on linux
dholmes
parents:
53646
diff
changeset
|
1608 |
int (*os::Posix::_clock_getres)(clockid_t, struct timespec *) = NULL; |
7054249afee5
8217843: Performance regression related to os::supports_monotonic_clock() on linux
dholmes
parents:
53646
diff
changeset
|
1609 |
|
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1610 |
static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t) = NULL; |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1611 |
|
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1612 |
static bool _use_clock_monotonic_condattr = false; |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1613 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1614 |
// 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
|
1615 |
// configuration. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1616 |
void os::Posix::init(void) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1617 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1618 |
// 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
|
1619 |
// statements in init_2(). |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1620 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1621 |
// 1. Check for CLOCK_MONOTONIC support. |
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 |
void* handle = NULL; |
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 |
// 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
|
1626 |
// this function in regular libc. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1627 |
#ifdef NEEDS_LIBRT |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1628 |
// 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
|
1629 |
// 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
|
1630 |
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
|
1631 |
if (handle == NULL) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1632 |
handle = dlopen("librt.so", RTLD_LAZY); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1633 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1634 |
#endif |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1635 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1636 |
if (handle == NULL) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1637 |
handle = RTLD_DEFAULT; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1638 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1639 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1640 |
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
|
1641 |
(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
|
1642 |
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
|
1643 |
(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
|
1644 |
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
|
1645 |
// 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
|
1646 |
// 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
|
1647 |
struct timespec res; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1648 |
struct timespec tp; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1649 |
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
|
1650 |
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
|
1651 |
// Yes, monotonic clock is supported. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1652 |
_clock_gettime = clock_gettime_func; |
51989
7ac0ac1e57b6
8211175: Remove temporary clock initialization duplication
dholmes
parents:
51106
diff
changeset
|
1653 |
_clock_getres = clock_getres_func; |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1654 |
} else { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1655 |
#ifdef NEEDS_LIBRT |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1656 |
// 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
|
1657 |
if (handle != RTLD_DEFAULT) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1658 |
dlclose(handle); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1659 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1660 |
#endif |
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 |
} |
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 |
// 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
|
1665 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1666 |
// libpthread is already loaded. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1667 |
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
|
1668 |
(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
|
1669 |
"pthread_condattr_setclock"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1670 |
if (condattr_setclock_func != NULL) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1671 |
_pthread_condattr_setclock = condattr_setclock_func; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1672 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1673 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1674 |
// Now do general initialization. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1675 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1676 |
pthread_init_common(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1677 |
|
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1678 |
#ifndef SOLARIS |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1679 |
int status; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1680 |
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
|
1681 |
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
|
1682 |
if (status == EINVAL) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1683 |
_use_clock_monotonic_condattr = false; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1684 |
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
|
1685 |
" - 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
|
1686 |
} else { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1687 |
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
|
1688 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1689 |
} else { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1690 |
_use_clock_monotonic_condattr = true; |
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 |
} |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1693 |
#endif // !SOLARIS |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1694 |
|
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1695 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1696 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1697 |
void os::Posix::init_2(void) { |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1698 |
#ifndef SOLARIS |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1699 |
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
|
1700 |
(_clock_gettime != NULL ? "" : " not")); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1701 |
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
|
1702 |
(_pthread_condattr_setclock != NULL ? "" : " not")); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1703 |
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
|
1704 |
_use_clock_monotonic_condattr ? "CLOCK_MONOTONIC" : "the default clock"); |
54090
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1705 |
sigemptyset(&sigs); |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1706 |
#endif // !SOLARIS |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1707 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1708 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1709 |
#else // !SUPPORTS_CLOCK_MONOTONIC |
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 |
void os::Posix::init(void) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1712 |
pthread_init_common(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1713 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1714 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1715 |
void os::Posix::init_2(void) { |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1716 |
#ifndef SOLARIS |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1717 |
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
|
1718 |
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
|
1719 |
log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with the default clock"); |
54090
3086f9259e97
8170639: [Linux] jsig is limited to a maximum of 64 signals
aoqi
parents:
54031
diff
changeset
|
1720 |
sigemptyset(&sigs); |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1721 |
#endif // !SOLARIS |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1722 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1723 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1724 |
#endif // SUPPORTS_CLOCK_MONOTONIC |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1725 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1726 |
// Utility to convert the given timeout to an absolute timespec |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1727 |
// (based on the appropriate clock) to use with pthread_cond_timewait, |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1728 |
// and sem_timedwait(). |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1729 |
// The clock queried here must be the clock used to manage the |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1730 |
// timeout of the condition variable or semaphore. |
46507
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 |
// 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
|
1733 |
// or an absolute time in milliseconds. A relative timeout will be |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1734 |
// associated with CLOCK_MONOTONIC if available, unless the real-time clock |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1735 |
// is explicitly requested; otherwise, or if absolute, |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1736 |
// 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
|
1737 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1738 |
// 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
|
1739 |
// 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
|
1740 |
// 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
|
1741 |
// 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
|
1742 |
// 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
|
1743 |
// 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
|
1744 |
// 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
|
1745 |
// 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
|
1746 |
// years from "now". |
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 |
#define MAX_SECS 100000000 |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1749 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1750 |
// 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
|
1751 |
// "unit" indicates the unit of "now_part_sec" (may be nanos or micros depending |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1752 |
// on which clock API is being used). |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1753 |
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
|
1754 |
jlong now_part_sec, jlong unit) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1755 |
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
|
1756 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1757 |
jlong seconds = timeout / NANOUNITS; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1758 |
timeout %= NANOUNITS; // remaining nanos |
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 (seconds >= MAX_SECS) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1761 |
// 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
|
1762 |
abstime->tv_sec = max_secs; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1763 |
abstime->tv_nsec = 0; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1764 |
} else { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1765 |
abstime->tv_sec = now_sec + seconds; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1766 |
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
|
1767 |
if (nanos >= NANOUNITS) { // overflow |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1768 |
abstime->tv_sec += 1; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1769 |
nanos -= NANOUNITS; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1770 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1771 |
abstime->tv_nsec = nanos; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1772 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1773 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1774 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1775 |
// 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
|
1776 |
// The current time in seconds is also passed in to enforce an upper bound as discussed above. |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1777 |
// This is only used with gettimeofday, when clock_gettime is not available. |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1778 |
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
|
1779 |
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
|
1780 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1781 |
jlong seconds = deadline / MILLIUNITS; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1782 |
jlong millis = deadline % MILLIUNITS; |
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 |
if (seconds >= max_secs) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1785 |
// 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
|
1786 |
abstime->tv_sec = max_secs; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1787 |
abstime->tv_nsec = 0; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1788 |
} else { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1789 |
abstime->tv_sec = seconds; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1790 |
abstime->tv_nsec = millis * (NANOUNITS / MILLIUNITS); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1791 |
} |
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 |
|
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1794 |
static jlong millis_to_nanos(jlong millis) { |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1795 |
// We have to watch for overflow when converting millis to nanos, |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1796 |
// but if millis is that large then we will end up limiting to |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1797 |
// MAX_SECS anyway, so just do that here. |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1798 |
if (millis / MILLIUNITS > MAX_SECS) { |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1799 |
millis = jlong(MAX_SECS) * MILLIUNITS; |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1800 |
} |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1801 |
return millis * (NANOUNITS / MILLIUNITS); |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1802 |
} |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1803 |
|
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1804 |
static void to_abstime(timespec* abstime, jlong timeout, |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1805 |
bool isAbsolute, bool isRealtime) { |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1806 |
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
|
1807 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1808 |
if (timeout < 0) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1809 |
timeout = 0; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1810 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1811 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1812 |
#ifdef SUPPORTS_CLOCK_MONOTONIC |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1813 |
|
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1814 |
clockid_t clock = CLOCK_MONOTONIC; |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1815 |
// need to ensure we have a runtime check for clock_gettime support |
53654
7054249afee5
8217843: Performance regression related to os::supports_monotonic_clock() on linux
dholmes
parents:
53646
diff
changeset
|
1816 |
if (!isAbsolute && os::Posix::supports_monotonic_clock()) { |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1817 |
if (!_use_clock_monotonic_condattr || isRealtime) { |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1818 |
clock = CLOCK_REALTIME; |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1819 |
} |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1820 |
struct timespec now; |
53654
7054249afee5
8217843: Performance regression related to os::supports_monotonic_clock() on linux
dholmes
parents:
53646
diff
changeset
|
1821 |
int status = os::Posix::clock_gettime(clock, &now); |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1822 |
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
|
1823 |
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
|
1824 |
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
|
1825 |
} else { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1826 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1827 |
#else |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1828 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1829 |
{ // Match the block scope. |
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 |
#endif // SUPPORTS_CLOCK_MONOTONIC |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1832 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1833 |
// 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
|
1834 |
struct timeval now; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1835 |
int status = gettimeofday(&now, NULL); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1836 |
assert_status(status == 0, errno, "gettimeofday"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1837 |
if (isAbsolute) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1838 |
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
|
1839 |
} else { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1840 |
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
|
1841 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1842 |
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
|
1843 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1844 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1845 |
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
|
1846 |
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
|
1847 |
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
|
1848 |
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
|
1849 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1850 |
|
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1851 |
// Create an absolute time 'millis' milliseconds in the future, using the |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1852 |
// real-time (time-of-day) clock. Used by PosixSemaphore. |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1853 |
void os::Posix::to_RTC_abstime(timespec* abstime, int64_t millis) { |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1854 |
to_abstime(abstime, millis_to_nanos(millis), |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1855 |
false /* not absolute */, |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1856 |
true /* use real-time clock */); |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1857 |
} |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1858 |
|
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1859 |
// Shared pthread_mutex/cond based PlatformEvent implementation. |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1860 |
// Not currently usable by Solaris. |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1861 |
|
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1862 |
#ifndef SOLARIS |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1863 |
|
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1864 |
// PlatformEvent |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1865 |
// |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1866 |
// Assumption: |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1867 |
// 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
|
1868 |
// 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
|
1869 |
// |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1870 |
// _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
|
1871 |
// -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
|
1872 |
// 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
|
1873 |
// 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
|
1874 |
// 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
|
1875 |
// |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1876 |
// 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
|
1877 |
// comments on unpark(). |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1878 |
|
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1879 |
os::PlatformEvent::PlatformEvent() { |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1880 |
int status = pthread_cond_init(_cond, _condAttr); |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1881 |
assert_status(status == 0, status, "cond_init"); |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1882 |
status = pthread_mutex_init(_mutex, _mutexAttr); |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1883 |
assert_status(status == 0, status, "mutex_init"); |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1884 |
_event = 0; |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1885 |
_nParked = 0; |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1886 |
} |
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1887 |
|
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1888 |
void os::PlatformEvent::park() { // AKA "down()" |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1889 |
// Transitions for _event: |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1890 |
// -1 => -1 : illegal |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1891 |
// 1 => 0 : pass - return immediately |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1892 |
// 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
|
1893 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1894 |
// 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
|
1895 |
// may call park(). |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1896 |
assert(_nParked == 0, "invariant"); |
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 v; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1899 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1900 |
// atomically decrement _event |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1901 |
for (;;) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1902 |
v = _event; |
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59251
diff
changeset
|
1903 |
if (Atomic::cmpxchg(&_event, v, v - 1) == v) break; |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1904 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1905 |
guarantee(v >= 0, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1906 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1907 |
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
|
1908 |
int status = pthread_mutex_lock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1909 |
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
|
1910 |
guarantee(_nParked == 0, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1911 |
++_nParked; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1912 |
while (_event < 0) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1913 |
// OS-level "spurious wakeups" are ignored |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1914 |
status = pthread_cond_wait(_cond, _mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1915 |
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
|
1916 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1917 |
--_nParked; |
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 |
_event = 0; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1920 |
status = pthread_mutex_unlock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1921 |
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
|
1922 |
// 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
|
1923 |
// correctly with each other. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1924 |
OrderAccess::fence(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1925 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1926 |
guarantee(_event >= 0, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1927 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1928 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1929 |
int os::PlatformEvent::park(jlong millis) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1930 |
// Transitions for _event: |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1931 |
// -1 => -1 : illegal |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1932 |
// 1 => 0 : pass - return immediately |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1933 |
// 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
|
1934 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1935 |
// 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
|
1936 |
// may call park(). |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1937 |
assert(_nParked == 0, "invariant"); |
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 |
int v; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1940 |
// atomically decrement _event |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1941 |
for (;;) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1942 |
v = _event; |
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59251
diff
changeset
|
1943 |
if (Atomic::cmpxchg(&_event, v, v - 1) == v) break; |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1944 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1945 |
guarantee(v >= 0, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1946 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1947 |
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
|
1948 |
struct timespec abst; |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
1949 |
to_abstime(&abst, millis_to_nanos(millis), false, false); |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1950 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1951 |
int ret = OS_TIMEOUT; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1952 |
int status = pthread_mutex_lock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1953 |
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
|
1954 |
guarantee(_nParked == 0, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1955 |
++_nParked; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1956 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1957 |
while (_event < 0) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1958 |
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
|
1959 |
assert_status(status == 0 || status == ETIMEDOUT, |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1960 |
status, "cond_timedwait"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1961 |
// 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
|
1962 |
// 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
|
1963 |
if (!FilterSpuriousWakeups) break; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1964 |
if (status == ETIMEDOUT) break; |
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 |
--_nParked; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1967 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1968 |
if (_event >= 0) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1969 |
ret = OS_OK; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1970 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1971 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1972 |
_event = 0; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1973 |
status = pthread_mutex_unlock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1974 |
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
|
1975 |
// 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
|
1976 |
// correctly with each other. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1977 |
OrderAccess::fence(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1978 |
return ret; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1979 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1980 |
return OS_OK; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1981 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1982 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1983 |
void os::PlatformEvent::unpark() { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1984 |
// Transitions for _event: |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1985 |
// 0 => 1 : just return |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1986 |
// 1 => 1 : just return |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1987 |
// -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
|
1988 |
// 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
|
1989 |
// 0 or 1. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1990 |
// 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
|
1991 |
// |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
1992 |
// 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
|
1993 |
// 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
|
1994 |
// 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
|
1995 |
// 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
|
1996 |
// 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
|
1997 |
// 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
|
1998 |
// but only in the correctly written condition checking loops of ObjectMonitor, |
58095 | 1999 |
// Mutex/Monitor, Thread::muxAcquire and JavaThread::sleep |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2000 |
|
59251
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59105
diff
changeset
|
2001 |
if (Atomic::xchg(&_event, 1) >= 0) return; |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2002 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2003 |
int status = pthread_mutex_lock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2004 |
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
|
2005 |
int anyWaiters = _nParked; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2006 |
assert(anyWaiters == 0 || anyWaiters == 1, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2007 |
status = pthread_mutex_unlock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2008 |
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
|
2009 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2010 |
// 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
|
2011 |
// 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
|
2012 |
// 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
|
2013 |
// 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
|
2014 |
// 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
|
2015 |
// 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
|
2016 |
// provide wait morphing. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2017 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2018 |
if (anyWaiters != 0) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2019 |
status = pthread_cond_signal(_cond); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2020 |
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
|
2021 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2022 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2023 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2024 |
// JSR166 support |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2025 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2026 |
os::PlatformParker::PlatformParker() { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2027 |
int status; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2028 |
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
|
2029 |
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
|
2030 |
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
|
2031 |
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
|
2032 |
status = pthread_mutex_init(_mutex, _mutexAttr); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2033 |
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
|
2034 |
_cur_index = -1; // mark as unused |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2035 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2036 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2037 |
// 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
|
2038 |
// 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
|
2039 |
// 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
|
2040 |
// 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
|
2041 |
// is no need to track notifications. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2042 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2043 |
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
|
2044 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2045 |
// Optional fast-path check: |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2046 |
// 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
|
2047 |
// 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
|
2048 |
// since we are doing a lock-free update to _counter. |
59251
4cbfa5077d68
8234739: Harmonize parameter order in Atomic - xchg
stefank
parents:
59105
diff
changeset
|
2049 |
if (Atomic::xchg(&_counter, 0) > 0) return; |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2050 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2051 |
Thread* thread = Thread::current(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2052 |
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
|
2053 |
JavaThread *jt = (JavaThread *)thread; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2054 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2055 |
// 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
|
2056 |
// an interrupt pending. |
58196
cea6839598e8
8230424: Use platform independent code for Thread.interrupt support
dholmes
parents:
58095
diff
changeset
|
2057 |
if (jt->is_interrupted(false)) { |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2058 |
return; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2059 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2060 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2061 |
// Next, demultiplex/decode time arguments |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2062 |
struct timespec absTime; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2063 |
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
|
2064 |
return; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2065 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2066 |
if (time > 0) { |
53461
08d6edeb3145
8194860: Cleanup Semaphore timed-wait time calculations
dholmes
parents:
53266
diff
changeset
|
2067 |
to_abstime(&absTime, time, isAbsolute, false); |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2068 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2069 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2070 |
// Enter safepoint region |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2071 |
// Beware of deadlocks such as 6317397. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2072 |
// 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
|
2073 |
// 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
|
2074 |
// 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
|
2075 |
// 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
|
2076 |
ThreadBlockInVM tbivm(jt); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2077 |
|
59105
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58744
diff
changeset
|
2078 |
// Can't access interrupt state now that we are _thread_blocked. If we've |
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58744
diff
changeset
|
2079 |
// been interrupted since we checked above then _counter will be > 0. |
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58744
diff
changeset
|
2080 |
|
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2081 |
// Don't wait if cannot get lock since interference arises from |
59105
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58744
diff
changeset
|
2082 |
// unparking. |
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58744
diff
changeset
|
2083 |
if (pthread_mutex_trylock(_mutex) != 0) { |
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2084 |
return; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2085 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2086 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2087 |
int status; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2088 |
if (_counter > 0) { // no wait needed |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2089 |
_counter = 0; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2090 |
status = pthread_mutex_unlock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2091 |
assert_status(status == 0, status, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2092 |
// 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
|
2093 |
// 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
|
2094 |
OrderAccess::fence(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2095 |
return; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2096 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2097 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2098 |
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
|
2099 |
jt->set_suspend_equivalent(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2100 |
// 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
|
2101 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2102 |
assert(_cur_index == -1, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2103 |
if (time == 0) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2104 |
_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
|
2105 |
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
|
2106 |
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
|
2107 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2108 |
else { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2109 |
_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
|
2110 |
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
|
2111 |
assert_status(status == 0 || status == ETIMEDOUT, |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2112 |
status, "cond_timedwait"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2113 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2114 |
_cur_index = -1; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2115 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2116 |
_counter = 0; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2117 |
status = pthread_mutex_unlock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2118 |
assert_status(status == 0, status, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2119 |
// 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
|
2120 |
// 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
|
2121 |
OrderAccess::fence(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2122 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2123 |
// 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
|
2124 |
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
|
2125 |
jt->java_suspend_self(); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2126 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2127 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2128 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2129 |
void Parker::unpark() { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2130 |
int status = pthread_mutex_lock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2131 |
assert_status(status == 0, status, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2132 |
const int s = _counter; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2133 |
_counter = 1; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2134 |
// must capture correct index before unlocking |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2135 |
int index = _cur_index; |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2136 |
status = pthread_mutex_unlock(_mutex); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2137 |
assert_status(status == 0, status, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2138 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2139 |
// 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
|
2140 |
// 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
|
2141 |
// 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
|
2142 |
// 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
|
2143 |
// 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
|
2144 |
// 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
|
2145 |
// provide wait morphing. |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2146 |
|
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2147 |
if (s < 1 && index != -1) { |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2148 |
// thread is definitely parked |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2149 |
status = pthread_cond_signal(&_cond[index]); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2150 |
assert_status(status == 0, status, "invariant"); |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2151 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2152 |
} |
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2153 |
|
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2154 |
// Platform Mutex/Monitor implementation |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2155 |
|
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2156 |
#if PLATFORM_MONITOR_IMPL_INDIRECT |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2157 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2158 |
os::PlatformMutex::Mutex::Mutex() : _next(NULL) { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2159 |
int status = pthread_mutex_init(&_mutex, _mutexAttr); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2160 |
assert_status(status == 0, status, "mutex_init"); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2161 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2162 |
|
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2163 |
os::PlatformMutex::Mutex::~Mutex() { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2164 |
int status = pthread_mutex_destroy(&_mutex); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2165 |
assert_status(status == 0, status, "mutex_destroy"); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2166 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2167 |
|
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2168 |
pthread_mutex_t os::PlatformMutex::_freelist_lock; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2169 |
os::PlatformMutex::Mutex* os::PlatformMutex::_mutex_freelist = NULL; |
54195 | 2170 |
|
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2171 |
void os::PlatformMutex::init() { |
54195 | 2172 |
int status = pthread_mutex_init(&_freelist_lock, _mutexAttr); |
2173 |
assert_status(status == 0, status, "freelist lock init"); |
|
2174 |
} |
|
2175 |
||
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2176 |
struct os::PlatformMutex::WithFreeListLocked : public StackObj { |
54195 | 2177 |
WithFreeListLocked() { |
2178 |
int status = pthread_mutex_lock(&_freelist_lock); |
|
2179 |
assert_status(status == 0, status, "freelist lock"); |
|
2180 |
} |
|
2181 |
||
2182 |
~WithFreeListLocked() { |
|
2183 |
int status = pthread_mutex_unlock(&_freelist_lock); |
|
2184 |
assert_status(status == 0, status, "freelist unlock"); |
|
2185 |
} |
|
2186 |
}; |
|
2187 |
||
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2188 |
os::PlatformMutex::PlatformMutex() { |
54195 | 2189 |
{ |
2190 |
WithFreeListLocked wfl; |
|
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2191 |
_impl = _mutex_freelist; |
54195 | 2192 |
if (_impl != NULL) { |
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2193 |
_mutex_freelist = _impl->_next; |
54195 | 2194 |
_impl->_next = NULL; |
2195 |
return; |
|
2196 |
} |
|
2197 |
} |
|
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2198 |
_impl = new Mutex(); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2199 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2200 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2201 |
os::PlatformMutex::~PlatformMutex() { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2202 |
WithFreeListLocked wfl; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2203 |
assert(_impl->_next == NULL, "invariant"); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2204 |
_impl->_next = _mutex_freelist; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2205 |
_mutex_freelist = _impl; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2206 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2207 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2208 |
os::PlatformMonitor::Cond::Cond() : _next(NULL) { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2209 |
int status = pthread_cond_init(&_cond, _condAttr); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2210 |
assert_status(status == 0, status, "cond_init"); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2211 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2212 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2213 |
os::PlatformMonitor::Cond::~Cond() { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2214 |
int status = pthread_cond_destroy(&_cond); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2215 |
assert_status(status == 0, status, "cond_destroy"); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2216 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2217 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2218 |
os::PlatformMonitor::Cond* os::PlatformMonitor::_cond_freelist = NULL; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2219 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2220 |
os::PlatformMonitor::PlatformMonitor() { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2221 |
{ |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2222 |
WithFreeListLocked wfl; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2223 |
_impl = _cond_freelist; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2224 |
if (_impl != NULL) { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2225 |
_cond_freelist = _impl->_next; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2226 |
_impl->_next = NULL; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2227 |
return; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2228 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2229 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2230 |
_impl = new Cond(); |
54195 | 2231 |
} |
2232 |
||
2233 |
os::PlatformMonitor::~PlatformMonitor() { |
|
2234 |
WithFreeListLocked wfl; |
|
2235 |
assert(_impl->_next == NULL, "invariant"); |
|
57738
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2236 |
_impl->_next = _cond_freelist; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2237 |
_cond_freelist = _impl; |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2238 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2239 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2240 |
#else |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2241 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2242 |
os::PlatformMutex::PlatformMutex() { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2243 |
int status = pthread_mutex_init(&_mutex, _mutexAttr); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2244 |
assert_status(status == 0, status, "mutex_init"); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2245 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2246 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2247 |
os::PlatformMutex::~PlatformMutex() { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2248 |
int status = pthread_mutex_destroy(&_mutex); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2249 |
assert_status(status == 0, status, "mutex_destroy"); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2250 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2251 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2252 |
os::PlatformMonitor::PlatformMonitor() { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2253 |
int status = pthread_cond_init(&_cond, _condAttr); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2254 |
assert_status(status == 0, status, "cond_init"); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2255 |
} |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2256 |
|
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2257 |
os::PlatformMonitor::~PlatformMonitor() { |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2258 |
int status = pthread_cond_destroy(&_cond); |
807d192fb7dd
8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
dholmes
parents:
55524
diff
changeset
|
2259 |
assert_status(status == 0, status, "cond_destroy"); |
54195 | 2260 |
} |
2261 |
||
2262 |
#endif // PLATFORM_MONITOR_IMPL_INDIRECT |
|
2263 |
||
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2264 |
// Must already be locked |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2265 |
int os::PlatformMonitor::wait(jlong millis) { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2266 |
assert(millis >= 0, "negative timeout"); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2267 |
if (millis > 0) { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2268 |
struct timespec abst; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2269 |
// We have to watch for overflow when converting millis to nanos, |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2270 |
// but if millis is that large then we will end up limiting to |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2271 |
// MAX_SECS anyway, so just do that here. |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2272 |
if (millis / MILLIUNITS > MAX_SECS) { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2273 |
millis = jlong(MAX_SECS) * MILLIUNITS; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2274 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2275 |
to_abstime(&abst, millis * (NANOUNITS / MILLIUNITS), false, false); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2276 |
|
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2277 |
int ret = OS_TIMEOUT; |
54195 | 2278 |
int status = pthread_cond_timedwait(cond(), mutex(), &abst); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2279 |
assert_status(status == 0 || status == ETIMEDOUT, |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2280 |
status, "cond_timedwait"); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2281 |
if (status == 0) { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2282 |
ret = OS_OK; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2283 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2284 |
return ret; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2285 |
} else { |
54195 | 2286 |
int status = pthread_cond_wait(cond(), mutex()); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2287 |
assert_status(status == 0, status, "cond_wait"); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2288 |
return OS_OK; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2289 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2290 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53461
diff
changeset
|
2291 |
|
46507
7db40fa6eff7
8174231: Factor out and share PlatformEvent and Parker code for POSIX systems
dholmes
parents:
46451
diff
changeset
|
2292 |
#endif // !SOLARIS |