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