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