author | goetz |
Thu, 22 Aug 2013 09:39:54 -0700 | |
changeset 22827 | 07d991d45a51 |
parent 22826 | 3ee6886e718d |
child 22828 | 17ecb098bc1e |
permissions | -rw-r--r-- |
8119 | 1 |
/* |
22826 | 2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
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" |
8119 | 28 |
#include "runtime/os.hpp" |
29 |
#include "utilities/vmError.hpp" |
|
30 |
||
22826 | 31 |
#include <signal.h> |
8119 | 32 |
#include <unistd.h> |
33 |
#include <sys/resource.h> |
|
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
34 |
#include <sys/utsname.h> |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
35 |
|
22826 | 36 |
// Todo: provide a os::get_max_process_id() or similar. Number of processes |
37 |
// may have been configured, can be read more accurately from proc fs etc. |
|
38 |
#ifndef MAX_PID |
|
39 |
#define MAX_PID INT_MAX |
|
40 |
#endif |
|
41 |
#define IS_VALID_PID(p) (p > 0 && p < MAX_PID) |
|
8119 | 42 |
|
43 |
// Check core dump limit and report possible place where core can be found |
|
44 |
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
|
45 |
int n; |
8119 | 46 |
struct rlimit rlim; |
47 |
bool success; |
|
48 |
||
13198
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
49 |
n = get_core_path(buffer, bufferSize); |
8119 | 50 |
|
51 |
if (getrlimit(RLIMIT_CORE, &rlim) != 0) { |
|
13198
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
52 |
jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (may not exist)", current_process_id()); |
8119 | 53 |
success = true; |
54 |
} else { |
|
55 |
switch(rlim.rlim_cur) { |
|
56 |
case RLIM_INFINITY: |
|
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", current_process_id()); |
8119 | 58 |
success = true; |
59 |
break; |
|
60 |
case 0: |
|
61 |
jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again"); |
|
62 |
success = false; |
|
63 |
break; |
|
64 |
default: |
|
13198
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
65 |
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 | 66 |
success = true; |
67 |
break; |
|
68 |
} |
|
69 |
} |
|
70 |
VMError::report_coredump_status(buffer, success); |
|
71 |
} |
|
72 |
||
13195 | 73 |
address os::get_caller_pc(int n) { |
74 |
#ifdef _NMT_NOINLINE_ |
|
75 |
n ++; |
|
76 |
#endif |
|
77 |
frame fr = os::current_frame(); |
|
78 |
while (n > 0 && fr.pc() && |
|
79 |
!os::is_first_C_frame(&fr) && fr.sender_pc()) { |
|
80 |
fr = os::get_sender_for_C_frame(&fr); |
|
81 |
n --; |
|
82 |
} |
|
83 |
if (n == 0) { |
|
84 |
return fr.pc(); |
|
85 |
} else { |
|
86 |
return NULL; |
|
87 |
} |
|
88 |
} |
|
89 |
||
11418
66ca80da30e2
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
8476
diff
changeset
|
90 |
int os::get_last_error() { |
66ca80da30e2
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
8476
diff
changeset
|
91 |
return errno; |
66ca80da30e2
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
8476
diff
changeset
|
92 |
} |
66ca80da30e2
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
8476
diff
changeset
|
93 |
|
8476
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
94 |
bool os::is_debugger_attached() { |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
95 |
// not implemented |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
96 |
return false; |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
97 |
} |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
98 |
|
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
99 |
void os::wait_for_keypress_at_exit(void) { |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
100 |
// don't do anything on posix platforms |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
101 |
return; |
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
102 |
} |
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
103 |
|
14840
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
104 |
// 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
|
105 |
// 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
|
106 |
// 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
|
107 |
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
|
108 |
assert((alignment & (os::vm_allocation_granularity() - 1)) == 0, |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
109 |
"Alignment must be a multiple of allocation granularity (page size)"); |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
110 |
assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned"); |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
111 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
112 |
size_t extra_size = size + alignment; |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
113 |
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
|
114 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
115 |
char* extra_base = os::reserve_memory(extra_size, NULL, alignment); |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
116 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
117 |
if (extra_base == NULL) { |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
118 |
return NULL; |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
119 |
} |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
120 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
121 |
// Do manual alignment |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
122 |
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
|
123 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
124 |
// [ | | ] |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
125 |
// ^ extra_base |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
126 |
// ^ extra_base + begin_offset == aligned_base |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
127 |
// extra_base + begin_offset + size ^ |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
128 |
// extra_base + extra_size ^ |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
129 |
// |<>| == begin_offset |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
130 |
// end_offset == |<>| |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
131 |
size_t begin_offset = aligned_base - extra_base; |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
132 |
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
|
133 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
134 |
if (begin_offset > 0) { |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
135 |
os::release_memory(extra_base, begin_offset); |
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 |
|
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
138 |
if (end_offset > 0) { |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
139 |
os::release_memory(extra_base + begin_offset + size, end_offset); |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
140 |
} |
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 |
return aligned_base; |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
143 |
} |
8994c2377547
7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents:
13963
diff
changeset
|
144 |
|
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
145 |
void os::Posix::print_load_average(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
146 |
st->print("load average:"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
147 |
double loadavg[3]; |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
148 |
os::loadavg(loadavg, 3); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
149 |
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
|
150 |
st->cr(); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
151 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
152 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
153 |
void os::Posix::print_rlimit_info(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
154 |
st->print("rlimit:"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
155 |
struct rlimit rlim; |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
156 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
157 |
st->print(" STACK "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
158 |
getrlimit(RLIMIT_STACK, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
159 |
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
|
160 |
else st->print("%uk", rlim.rlim_cur >> 10); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
161 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
162 |
st->print(", CORE "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
163 |
getrlimit(RLIMIT_CORE, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
164 |
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
|
165 |
else st->print("%uk", rlim.rlim_cur >> 10); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
166 |
|
22826 | 167 |
// Isn't there on solaris |
22827 | 168 |
#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
|
169 |
st->print(", NPROC "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
170 |
getrlimit(RLIMIT_NPROC, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
171 |
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
|
172 |
else st->print("%d", rlim.rlim_cur); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
173 |
#endif |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
174 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
175 |
st->print(", NOFILE "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
176 |
getrlimit(RLIMIT_NOFILE, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
177 |
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
|
178 |
else st->print("%d", rlim.rlim_cur); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
179 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
180 |
st->print(", AS "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
181 |
getrlimit(RLIMIT_AS, &rlim); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
182 |
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
|
183 |
else st->print("%uk", rlim.rlim_cur >> 10); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
184 |
st->cr(); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
185 |
} |
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 |
void os::Posix::print_uname_info(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
188 |
// kernel |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
189 |
st->print("uname:"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
190 |
struct utsname name; |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
191 |
uname(&name); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
192 |
st->print(name.sysname); st->print(" "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
193 |
st->print(name.release); st->print(" "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
194 |
st->print(name.version); st->print(" "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
195 |
st->print(name.machine); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
196 |
st->cr(); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
197 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
198 |
|
16605
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
199 |
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
|
200 |
struct rlimit rlim; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
201 |
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
|
202 |
// 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
|
203 |
// on virtual memory. |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
204 |
bool result; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
205 |
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
|
206 |
result = false; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
207 |
} else { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
208 |
*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
|
209 |
result = true; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
210 |
} |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
211 |
#ifdef _LP64 |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
212 |
return result; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
213 |
#else |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
214 |
// 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
|
215 |
// 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
|
216 |
// directly use it. |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
217 |
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
|
218 |
if (result) { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
219 |
*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
|
220 |
} else { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
221 |
*limit = max_virtual_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
222 |
} |
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
11418
diff
changeset
|
223 |
|
16605
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
224 |
// 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
|
225 |
// 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
|
226 |
// 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
|
227 |
// 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
|
228 |
// 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
|
229 |
// 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
|
230 |
// 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
|
231 |
// 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
|
232 |
|
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
233 |
// 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
|
234 |
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
|
235 |
|
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
236 |
julong upper_limit = *limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
237 |
|
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
238 |
// 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
|
239 |
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
|
240 |
*limit = upper_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
241 |
} 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
|
242 |
// 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
|
243 |
// 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
|
244 |
*limit = min_allocation_size; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
245 |
} else { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
246 |
// perform the binary search. |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
lower_limit = temp_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
253 |
} else { |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
254 |
upper_limit = temp_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
255 |
} |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
256 |
} |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
257 |
*limit = lower_limit; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
258 |
} |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
259 |
return true; |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
260 |
#endif |
ba13efd453bc
7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM
tschatzl
parents:
14840
diff
changeset
|
261 |
} |
17121
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
262 |
|
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
263 |
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
|
264 |
return getcwd(buf, buflen); |
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
265 |
} |
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
266 |
|
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
267 |
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
|
268 |
return ::fdopen(fd, mode); |
e40a97c700d9
8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents:
16605
diff
changeset
|
269 |
} |
18943 | 270 |
|
22826 | 271 |
|
272 |
// Returned string is a constant. For unknown signals "UNKNOWN" is returned. |
|
273 |
const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) { |
|
274 |
||
275 |
static const struct { |
|
276 |
int sig; const char* name; |
|
277 |
} |
|
278 |
info[] = |
|
279 |
{ |
|
280 |
{ SIGABRT, "SIGABRT" }, |
|
281 |
#ifdef SIGAIO |
|
282 |
{ SIGAIO, "SIGAIO" }, |
|
283 |
#endif |
|
284 |
{ SIGALRM, "SIGALRM" }, |
|
285 |
#ifdef SIGALRM1 |
|
286 |
{ SIGALRM1, "SIGALRM1" }, |
|
287 |
#endif |
|
288 |
{ SIGBUS, "SIGBUS" }, |
|
289 |
#ifdef SIGCANCEL |
|
290 |
{ SIGCANCEL, "SIGCANCEL" }, |
|
291 |
#endif |
|
292 |
{ SIGCHLD, "SIGCHLD" }, |
|
293 |
#ifdef SIGCLD |
|
294 |
{ SIGCLD, "SIGCLD" }, |
|
295 |
#endif |
|
296 |
{ SIGCONT, "SIGCONT" }, |
|
297 |
#ifdef SIGCPUFAIL |
|
298 |
{ SIGCPUFAIL, "SIGCPUFAIL" }, |
|
299 |
#endif |
|
300 |
#ifdef SIGDANGER |
|
301 |
{ SIGDANGER, "SIGDANGER" }, |
|
302 |
#endif |
|
303 |
#ifdef SIGDIL |
|
304 |
{ SIGDIL, "SIGDIL" }, |
|
305 |
#endif |
|
306 |
#ifdef SIGEMT |
|
307 |
{ SIGEMT, "SIGEMT" }, |
|
308 |
#endif |
|
309 |
{ SIGFPE, "SIGFPE" }, |
|
310 |
#ifdef SIGFREEZE |
|
311 |
{ SIGFREEZE, "SIGFREEZE" }, |
|
312 |
#endif |
|
313 |
#ifdef SIGGFAULT |
|
314 |
{ SIGGFAULT, "SIGGFAULT" }, |
|
315 |
#endif |
|
316 |
#ifdef SIGGRANT |
|
317 |
{ SIGGRANT, "SIGGRANT" }, |
|
318 |
#endif |
|
319 |
{ SIGHUP, "SIGHUP" }, |
|
320 |
{ SIGILL, "SIGILL" }, |
|
321 |
{ SIGINT, "SIGINT" }, |
|
322 |
#ifdef SIGIO |
|
323 |
{ SIGIO, "SIGIO" }, |
|
324 |
#endif |
|
325 |
#ifdef SIGIOINT |
|
326 |
{ SIGIOINT, "SIGIOINT" }, |
|
327 |
#endif |
|
328 |
#ifdef SIGIOT |
|
329 |
// SIGIOT is there for BSD compatibility, but on most Unices just a |
|
330 |
// synonym for SIGABRT. The result should be "SIGABRT", not |
|
331 |
// "SIGIOT". |
|
332 |
#if (SIGIOT != SIGABRT ) |
|
333 |
{ SIGIOT, "SIGIOT" }, |
|
334 |
#endif |
|
335 |
#endif |
|
336 |
#ifdef SIGKAP |
|
337 |
{ SIGKAP, "SIGKAP" }, |
|
338 |
#endif |
|
339 |
{ SIGKILL, "SIGKILL" }, |
|
340 |
#ifdef SIGLOST |
|
341 |
{ SIGLOST, "SIGLOST" }, |
|
342 |
#endif |
|
343 |
#ifdef SIGLWP |
|
344 |
{ SIGLWP, "SIGLWP" }, |
|
345 |
#endif |
|
346 |
#ifdef SIGLWPTIMER |
|
347 |
{ SIGLWPTIMER, "SIGLWPTIMER" }, |
|
348 |
#endif |
|
349 |
#ifdef SIGMIGRATE |
|
350 |
{ SIGMIGRATE, "SIGMIGRATE" }, |
|
351 |
#endif |
|
352 |
#ifdef SIGMSG |
|
353 |
{ SIGMSG, "SIGMSG" }, |
|
354 |
#endif |
|
355 |
{ SIGPIPE, "SIGPIPE" }, |
|
356 |
#ifdef SIGPOLL |
|
357 |
{ SIGPOLL, "SIGPOLL" }, |
|
358 |
#endif |
|
359 |
#ifdef SIGPRE |
|
360 |
{ SIGPRE, "SIGPRE" }, |
|
361 |
#endif |
|
362 |
{ SIGPROF, "SIGPROF" }, |
|
363 |
#ifdef SIGPTY |
|
364 |
{ SIGPTY, "SIGPTY" }, |
|
365 |
#endif |
|
366 |
#ifdef SIGPWR |
|
367 |
{ SIGPWR, "SIGPWR" }, |
|
368 |
#endif |
|
369 |
{ SIGQUIT, "SIGQUIT" }, |
|
370 |
#ifdef SIGRECONFIG |
|
371 |
{ SIGRECONFIG, "SIGRECONFIG" }, |
|
372 |
#endif |
|
373 |
#ifdef SIGRECOVERY |
|
374 |
{ SIGRECOVERY, "SIGRECOVERY" }, |
|
375 |
#endif |
|
376 |
#ifdef SIGRESERVE |
|
377 |
{ SIGRESERVE, "SIGRESERVE" }, |
|
378 |
#endif |
|
379 |
#ifdef SIGRETRACT |
|
380 |
{ SIGRETRACT, "SIGRETRACT" }, |
|
381 |
#endif |
|
382 |
#ifdef SIGSAK |
|
383 |
{ SIGSAK, "SIGSAK" }, |
|
384 |
#endif |
|
385 |
{ SIGSEGV, "SIGSEGV" }, |
|
386 |
#ifdef SIGSOUND |
|
387 |
{ SIGSOUND, "SIGSOUND" }, |
|
388 |
#endif |
|
389 |
{ SIGSTOP, "SIGSTOP" }, |
|
390 |
{ SIGSYS, "SIGSYS" }, |
|
391 |
#ifdef SIGSYSERROR |
|
392 |
{ SIGSYSERROR, "SIGSYSERROR" }, |
|
393 |
#endif |
|
394 |
#ifdef SIGTALRM |
|
395 |
{ SIGTALRM, "SIGTALRM" }, |
|
396 |
#endif |
|
397 |
{ SIGTERM, "SIGTERM" }, |
|
398 |
#ifdef SIGTHAW |
|
399 |
{ SIGTHAW, "SIGTHAW" }, |
|
400 |
#endif |
|
401 |
{ SIGTRAP, "SIGTRAP" }, |
|
402 |
#ifdef SIGTSTP |
|
403 |
{ SIGTSTP, "SIGTSTP" }, |
|
404 |
#endif |
|
405 |
{ SIGTTIN, "SIGTTIN" }, |
|
406 |
{ SIGTTOU, "SIGTTOU" }, |
|
407 |
#ifdef SIGURG |
|
408 |
{ SIGURG, "SIGURG" }, |
|
409 |
#endif |
|
410 |
{ SIGUSR1, "SIGUSR1" }, |
|
411 |
{ SIGUSR2, "SIGUSR2" }, |
|
412 |
#ifdef SIGVIRT |
|
413 |
{ SIGVIRT, "SIGVIRT" }, |
|
414 |
#endif |
|
415 |
{ SIGVTALRM, "SIGVTALRM" }, |
|
416 |
#ifdef SIGWAITING |
|
417 |
{ SIGWAITING, "SIGWAITING" }, |
|
418 |
#endif |
|
419 |
#ifdef SIGWINCH |
|
420 |
{ SIGWINCH, "SIGWINCH" }, |
|
421 |
#endif |
|
422 |
#ifdef SIGWINDOW |
|
423 |
{ SIGWINDOW, "SIGWINDOW" }, |
|
424 |
#endif |
|
425 |
{ SIGXCPU, "SIGXCPU" }, |
|
426 |
{ SIGXFSZ, "SIGXFSZ" }, |
|
427 |
#ifdef SIGXRES |
|
428 |
{ SIGXRES, "SIGXRES" }, |
|
429 |
#endif |
|
430 |
{ -1, NULL } |
|
431 |
}; |
|
432 |
||
433 |
const char* ret = NULL; |
|
434 |
||
435 |
#ifdef SIGRTMIN |
|
436 |
if (sig >= SIGRTMIN && sig <= SIGRTMAX) { |
|
437 |
if (sig == SIGRTMIN) { |
|
438 |
ret = "SIGRTMIN"; |
|
439 |
} else if (sig == SIGRTMAX) { |
|
440 |
ret = "SIGRTMAX"; |
|
441 |
} else { |
|
442 |
jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN); |
|
443 |
return out; |
|
444 |
} |
|
445 |
} |
|
446 |
#endif |
|
447 |
||
448 |
if (sig > 0) { |
|
449 |
for (int idx = 0; info[idx].sig != -1; idx ++) { |
|
450 |
if (info[idx].sig == sig) { |
|
451 |
ret = info[idx].name; |
|
452 |
break; |
|
453 |
} |
|
454 |
} |
|
455 |
} |
|
456 |
||
457 |
if (!ret) { |
|
458 |
if (!is_valid_signal(sig)) { |
|
459 |
ret = "INVALID"; |
|
460 |
} else { |
|
461 |
ret = "UNKNOWN"; |
|
462 |
} |
|
463 |
} |
|
464 |
||
465 |
jio_snprintf(out, outlen, ret); |
|
466 |
return out; |
|
467 |
} |
|
468 |
||
469 |
// Returns true if signal number is valid. |
|
470 |
bool os::Posix::is_valid_signal(int sig) { |
|
471 |
// MacOS not really POSIX compliant: sigaddset does not return |
|
472 |
// an error for invalid signal numbers. However, MacOS does not |
|
473 |
// support real time signals and simply seems to have just 33 |
|
474 |
// signals with no holes in the signal range. |
|
475 |
#ifdef __APPLE__ |
|
476 |
return sig >= 1 && sig < NSIG; |
|
477 |
#else |
|
478 |
// Use sigaddset to check for signal validity. |
|
479 |
sigset_t set; |
|
480 |
if (sigaddset(&set, sig) == -1 && errno == EINVAL) { |
|
481 |
return false; |
|
482 |
} |
|
483 |
return true; |
|
484 |
#endif |
|
485 |
} |
|
486 |
||
487 |
#define NUM_IMPORTANT_SIGS 32 |
|
488 |
// Returns one-line short description of a signal set in a user provided buffer. |
|
489 |
const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) { |
|
22827 | 490 |
assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size"); |
22826 | 491 |
// Note: for shortness, just print out the first 32. That should |
492 |
// cover most of the useful ones, apart from realtime signals. |
|
493 |
for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) { |
|
494 |
const int rc = sigismember(set, sig); |
|
495 |
if (rc == -1 && errno == EINVAL) { |
|
496 |
buffer[sig-1] = '?'; |
|
497 |
} else { |
|
498 |
buffer[sig-1] = rc == 0 ? '0' : '1'; |
|
499 |
} |
|
500 |
} |
|
501 |
buffer[NUM_IMPORTANT_SIGS] = 0; |
|
502 |
return buffer; |
|
503 |
} |
|
504 |
||
505 |
// Prints one-line description of a signal set. |
|
506 |
void os::Posix::print_signal_set_short(outputStream* st, const sigset_t* set) { |
|
507 |
char buf[NUM_IMPORTANT_SIGS + 1]; |
|
508 |
os::Posix::describe_signal_set_short(set, buf, sizeof(buf)); |
|
509 |
st->print(buf); |
|
510 |
} |
|
511 |
||
512 |
// Writes one-line description of a combination of sigaction.sa_flags into a user |
|
513 |
// provided buffer. Returns that buffer. |
|
514 |
const char* os::Posix::describe_sa_flags(int flags, char* buffer, size_t size) { |
|
515 |
char* p = buffer; |
|
516 |
size_t remaining = size; |
|
517 |
bool first = true; |
|
518 |
int idx = 0; |
|
519 |
||
520 |
assert(buffer, "invalid argument"); |
|
521 |
||
522 |
if (size == 0) { |
|
523 |
return buffer; |
|
524 |
} |
|
525 |
||
526 |
strncpy(buffer, "none", size); |
|
527 |
||
528 |
const struct { |
|
529 |
int i; |
|
530 |
const char* s; |
|
531 |
} flaginfo [] = { |
|
532 |
{ SA_NOCLDSTOP, "SA_NOCLDSTOP" }, |
|
533 |
{ SA_ONSTACK, "SA_ONSTACK" }, |
|
534 |
{ SA_RESETHAND, "SA_RESETHAND" }, |
|
535 |
{ SA_RESTART, "SA_RESTART" }, |
|
536 |
{ SA_SIGINFO, "SA_SIGINFO" }, |
|
537 |
{ SA_NOCLDWAIT, "SA_NOCLDWAIT" }, |
|
538 |
{ SA_NODEFER, "SA_NODEFER" }, |
|
539 |
#ifdef AIX |
|
540 |
{ SA_ONSTACK, "SA_ONSTACK" }, |
|
541 |
{ SA_OLDSTYLE, "SA_OLDSTYLE" }, |
|
542 |
#endif |
|
543 |
{ 0, NULL } |
|
544 |
}; |
|
545 |
||
546 |
for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) { |
|
547 |
if (flags & flaginfo[idx].i) { |
|
548 |
if (first) { |
|
549 |
jio_snprintf(p, remaining, "%s", flaginfo[idx].s); |
|
550 |
first = false; |
|
551 |
} else { |
|
552 |
jio_snprintf(p, remaining, "|%s", flaginfo[idx].s); |
|
553 |
} |
|
554 |
const size_t len = strlen(p); |
|
555 |
p += len; |
|
556 |
remaining -= len; |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
buffer[size - 1] = '\0'; |
|
561 |
||
562 |
return buffer; |
|
563 |
} |
|
564 |
||
565 |
// Prints one-line description of a combination of sigaction.sa_flags. |
|
566 |
void os::Posix::print_sa_flags(outputStream* st, int flags) { |
|
567 |
char buffer[0x100]; |
|
568 |
os::Posix::describe_sa_flags(flags, buffer, sizeof(buffer)); |
|
569 |
st->print(buffer); |
|
570 |
} |
|
571 |
||
572 |
// Helper function for os::Posix::print_siginfo_...(): |
|
573 |
// return a textual description for signal code. |
|
574 |
struct enum_sigcode_desc_t { |
|
575 |
const char* s_name; |
|
576 |
const char* s_desc; |
|
577 |
}; |
|
578 |
||
579 |
static bool get_signal_code_description(const siginfo_t* si, enum_sigcode_desc_t* out) { |
|
580 |
||
581 |
const struct { |
|
582 |
int sig; int code; const char* s_code; const char* s_desc; |
|
583 |
} t1 [] = { |
|
584 |
{ SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode." }, |
|
585 |
{ SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand." }, |
|
586 |
{ SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode." }, |
|
587 |
{ SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap." }, |
|
588 |
{ SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode." }, |
|
589 |
{ SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register." }, |
|
590 |
{ SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error." }, |
|
591 |
{ SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error." }, |
|
592 |
#if defined(IA64) && defined(LINUX) |
|
593 |
{ SIGILL, ILL_BADIADDR, "ILL_BADIADDR", "Unimplemented instruction address" }, |
|
594 |
{ SIGILL, ILL_BREAK, "ILL_BREAK", "Application Break instruction" }, |
|
595 |
#endif |
|
596 |
{ SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero." }, |
|
597 |
{ SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow." }, |
|
598 |
{ SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating-point divide by zero." }, |
|
599 |
{ SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating-point overflow." }, |
|
600 |
{ SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating-point underflow." }, |
|
601 |
{ SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating-point inexact result." }, |
|
602 |
{ SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating-point operation." }, |
|
603 |
{ SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range." }, |
|
604 |
{ SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object." }, |
|
605 |
{ SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for mapped object." }, |
|
606 |
#ifdef AIX |
|
607 |
// no explanation found what keyerr would be |
|
608 |
{ SIGSEGV, SEGV_KEYERR, "SEGV_KEYERR", "key error" }, |
|
609 |
#endif |
|
610 |
#if defined(IA64) && !defined(AIX) |
|
611 |
{ SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" }, |
|
612 |
#endif |
|
613 |
{ SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment." }, |
|
614 |
{ SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Nonexistent physical address." }, |
|
615 |
{ SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object-specific hardware error." }, |
|
616 |
{ SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint." }, |
|
617 |
{ SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap." }, |
|
618 |
{ SIGCHLD, CLD_EXITED, "CLD_EXITED", "Child has exited." }, |
|
619 |
{ SIGCHLD, CLD_KILLED, "CLD_KILLED", "Child has terminated abnormally and did not create a core file." }, |
|
620 |
{ SIGCHLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally and created a core file." }, |
|
621 |
{ SIGCHLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped." }, |
|
622 |
{ SIGCHLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped." }, |
|
623 |
{ SIGCHLD, CLD_CONTINUED,"CLD_CONTINUED","Stopped child has continued." }, |
|
624 |
#ifdef SIGPOLL |
|
625 |
{ SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available." }, |
|
626 |
{ SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available." }, |
|
627 |
{ SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error." }, |
|
628 |
{ SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available." }, |
|
629 |
{ SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected. [Option End]" }, |
|
630 |
#endif |
|
631 |
{ -1, -1, NULL, NULL } |
|
632 |
}; |
|
633 |
||
634 |
// Codes valid in any signal context. |
|
635 |
const struct { |
|
636 |
int code; const char* s_code; const char* s_desc; |
|
637 |
} t2 [] = { |
|
638 |
{ SI_USER, "SI_USER", "Signal sent by kill()." }, |
|
639 |
{ SI_QUEUE, "SI_QUEUE", "Signal sent by the sigqueue()." }, |
|
640 |
{ SI_TIMER, "SI_TIMER", "Signal generated by expiration of a timer set by timer_settime()." }, |
|
641 |
{ SI_ASYNCIO, "SI_ASYNCIO", "Signal generated by completion of an asynchronous I/O request." }, |
|
642 |
{ SI_MESGQ, "SI_MESGQ", "Signal generated by arrival of a message on an empty message queue." }, |
|
643 |
// Linux specific |
|
644 |
#ifdef SI_TKILL |
|
645 |
{ SI_TKILL, "SI_TKILL", "Signal sent by tkill (pthread_kill)" }, |
|
646 |
#endif |
|
647 |
#ifdef SI_DETHREAD |
|
648 |
{ SI_DETHREAD, "SI_DETHREAD", "Signal sent by execve() killing subsidiary threads" }, |
|
649 |
#endif |
|
650 |
#ifdef SI_KERNEL |
|
651 |
{ SI_KERNEL, "SI_KERNEL", "Signal sent by kernel." }, |
|
652 |
#endif |
|
653 |
#ifdef SI_SIGIO |
|
654 |
{ SI_SIGIO, "SI_SIGIO", "Signal sent by queued SIGIO" }, |
|
655 |
#endif |
|
656 |
||
657 |
#ifdef AIX |
|
658 |
{ SI_UNDEFINED, "SI_UNDEFINED","siginfo contains partial information" }, |
|
659 |
{ SI_EMPTY, "SI_EMPTY", "siginfo contains no useful information" }, |
|
660 |
#endif |
|
661 |
||
662 |
#ifdef __sun |
|
663 |
{ SI_NOINFO, "SI_NOINFO", "No signal information" }, |
|
664 |
{ SI_RCTL, "SI_RCTL", "kernel generated signal via rctl action" }, |
|
665 |
{ SI_LWP, "SI_LWP", "Signal sent via lwp_kill" }, |
|
666 |
#endif |
|
667 |
||
668 |
{ -1, NULL, NULL } |
|
669 |
}; |
|
670 |
||
671 |
const char* s_code = NULL; |
|
672 |
const char* s_desc = NULL; |
|
673 |
||
674 |
for (int i = 0; t1[i].sig != -1; i ++) { |
|
675 |
if (t1[i].sig == si->si_signo && t1[i].code == si->si_code) { |
|
676 |
s_code = t1[i].s_code; |
|
677 |
s_desc = t1[i].s_desc; |
|
678 |
break; |
|
679 |
} |
|
680 |
} |
|
681 |
||
682 |
if (s_code == NULL) { |
|
683 |
for (int i = 0; t2[i].s_code != NULL; i ++) { |
|
684 |
if (t2[i].code == si->si_code) { |
|
685 |
s_code = t2[i].s_code; |
|
686 |
s_desc = t2[i].s_desc; |
|
687 |
} |
|
688 |
} |
|
689 |
} |
|
690 |
||
691 |
if (s_code == NULL) { |
|
692 |
out->s_name = "unknown"; |
|
693 |
out->s_desc = "unknown"; |
|
694 |
return false; |
|
695 |
} |
|
696 |
||
697 |
out->s_name = s_code; |
|
698 |
out->s_desc = s_desc; |
|
699 |
||
700 |
return true; |
|
701 |
} |
|
702 |
||
703 |
// A POSIX conform, platform-independend siginfo print routine. |
|
704 |
// Short print out on one line. |
|
705 |
void os::Posix::print_siginfo_brief(outputStream* os, const siginfo_t* si) { |
|
706 |
char buf[20]; |
|
707 |
os->print("siginfo: "); |
|
708 |
||
709 |
if (!si) { |
|
710 |
os->print("<null>"); |
|
711 |
return; |
|
712 |
} |
|
713 |
||
714 |
// See print_siginfo_full() for details. |
|
715 |
const int sig = si->si_signo; |
|
716 |
||
717 |
os->print("si_signo: %d (%s)", sig, os::Posix::get_signal_name(sig, buf, sizeof(buf))); |
|
718 |
||
719 |
enum_sigcode_desc_t ed; |
|
720 |
if (get_signal_code_description(si, &ed)) { |
|
721 |
os->print(", si_code: %d (%s)", si->si_code, ed.s_name); |
|
722 |
} else { |
|
723 |
os->print(", si_code: %d (unknown)", si->si_code); |
|
724 |
} |
|
725 |
||
726 |
if (si->si_errno) { |
|
727 |
os->print(", si_errno: %d", si->si_errno); |
|
728 |
} |
|
729 |
||
730 |
const int me = (int) ::getpid(); |
|
731 |
const int pid = (int) si->si_pid; |
|
732 |
||
733 |
if (si->si_code == SI_USER || si->si_code == SI_QUEUE) { |
|
734 |
if (IS_VALID_PID(pid) && pid != me) { |
|
735 |
os->print(", sent from pid: %d (uid: %d)", pid, (int) si->si_uid); |
|
736 |
} |
|
737 |
} else if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || |
|
738 |
sig == SIGTRAP || sig == SIGFPE) { |
|
739 |
os->print(", si_addr: " PTR_FORMAT, si->si_addr); |
|
740 |
#ifdef SIGPOLL |
|
741 |
} else if (sig == SIGPOLL) { |
|
742 |
os->print(", si_band: " PTR64_FORMAT, (uint64_t)si->si_band); |
|
743 |
#endif |
|
744 |
} else if (sig == SIGCHLD) { |
|
745 |
os->print_cr(", si_pid: %d, si_uid: %d, si_status: %d", (int) si->si_pid, si->si_uid, si->si_status); |
|
746 |
} |
|
747 |
} |
|
748 |
||
18943 | 749 |
os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() { |
750 |
assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread"); |
|
751 |
} |
|
752 |
||
753 |
/* |
|
754 |
* See the caveats for this class in os_posix.hpp |
|
755 |
* Protects the callback call so that SIGSEGV / SIGBUS jumps back into this |
|
756 |
* method and returns false. If none of the signals are raised, returns true. |
|
757 |
* The callback is supposed to provide the method that should be protected. |
|
758 |
*/ |
|
759 |
bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) { |
|
760 |
assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread"); |
|
761 |
assert(!WatcherThread::watcher_thread()->has_crash_protection(), |
|
762 |
"crash_protection already set?"); |
|
763 |
||
764 |
if (sigsetjmp(_jmpbuf, 1) == 0) { |
|
765 |
// make sure we can see in the signal handler that we have crash protection |
|
766 |
// installed |
|
767 |
WatcherThread::watcher_thread()->set_crash_protection(this); |
|
768 |
cb.call(); |
|
769 |
// and clear the crash protection |
|
770 |
WatcherThread::watcher_thread()->set_crash_protection(NULL); |
|
771 |
return true; |
|
772 |
} |
|
773 |
// this happens when we siglongjmp() back |
|
774 |
WatcherThread::watcher_thread()->set_crash_protection(NULL); |
|
775 |
return false; |
|
776 |
} |
|
777 |
||
778 |
void os::WatcherThreadCrashProtection::restore() { |
|
779 |
assert(WatcherThread::watcher_thread()->has_crash_protection(), |
|
780 |
"must have crash protection"); |
|
781 |
||
782 |
siglongjmp(_jmpbuf, 1); |
|
783 |
} |
|
784 |
||
785 |
void os::WatcherThreadCrashProtection::check_crash_protection(int sig, |
|
786 |
Thread* thread) { |
|
787 |
||
788 |
if (thread != NULL && |
|
789 |
thread->is_Watcher_thread() && |
|
790 |
WatcherThread::watcher_thread()->has_crash_protection()) { |
|
791 |
||
792 |
if (sig == SIGSEGV || sig == SIGBUS) { |
|
793 |
WatcherThread::watcher_thread()->crash_protection()->restore(); |
|
794 |
} |
|
795 |
} |
|
796 |
} |