author | prr |
Mon, 14 Jul 2014 11:11:13 -0700 | |
changeset 25779 | 86b8de4f7d09 |
parent 24351 | 61b33cc6d3cf |
child 25468 | 5331df506290 |
permissions | -rw-r--r-- |
10565 | 1 |
/* |
22891
1f5d1fff23fa
6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents:
18078
diff
changeset
|
2 |
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
10565 | 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 |
*/ |
|
24 |
||
25 |
#ifndef OS_BSD_VM_OS_BSD_INLINE_HPP |
|
26 |
#define OS_BSD_VM_OS_BSD_INLINE_HPP |
|
27 |
||
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
13963
diff
changeset
|
28 |
#include "runtime/atomic.inline.hpp" |
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
24239
diff
changeset
|
29 |
#include "runtime/orderAccess.inline.hpp" |
10565 | 30 |
#include "runtime/os.hpp" |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
13963
diff
changeset
|
31 |
|
10565 | 32 |
// System includes |
33 |
||
34 |
#include <unistd.h> |
|
35 |
#include <sys/socket.h> |
|
36 |
#include <sys/poll.h> |
|
37 |
#include <netdb.h> |
|
38 |
||
39 |
inline void* os::thread_local_storage_at(int index) { |
|
40 |
return pthread_getspecific((pthread_key_t)index); |
|
41 |
} |
|
42 |
||
43 |
inline const char* os::file_separator() { |
|
44 |
return "/"; |
|
45 |
} |
|
46 |
||
47 |
inline const char* os::line_separator() { |
|
48 |
return "\n"; |
|
49 |
} |
|
50 |
||
51 |
inline const char* os::path_separator() { |
|
52 |
return ":"; |
|
53 |
} |
|
54 |
||
55 |
// File names are case-sensitive on windows only |
|
56 |
inline int os::file_name_strcmp(const char* s1, const char* s2) { |
|
57 |
return strcmp(s1, s2); |
|
58 |
} |
|
59 |
||
60 |
inline bool os::obsolete_option(const JavaVMOption *option) { |
|
61 |
return false; |
|
62 |
} |
|
63 |
||
64 |
inline bool os::uses_stack_guard_pages() { |
|
65 |
return true; |
|
66 |
} |
|
67 |
||
68 |
inline bool os::allocate_stack_guard_pages() { |
|
69 |
assert(uses_stack_guard_pages(), "sanity check"); |
|
70 |
#if !defined(__FreeBSD__) || __FreeBSD__ < 5 |
|
71 |
// Since FreeBSD 4 uses malloc() for allocating the thread stack |
|
72 |
// there is no need to do anything extra to allocate the guard pages |
|
73 |
return false; |
|
74 |
#else |
|
75 |
// FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks. |
|
76 |
// Must 'allocate' them or guard pages are ignored. |
|
77 |
return true; |
|
78 |
#endif |
|
79 |
} |
|
80 |
||
81 |
||
82 |
// On Bsd, reservations are made on a page by page basis, nothing to do. |
|
13195 | 83 |
inline void os::pd_split_reserved_memory(char *base, size_t size, |
10565 | 84 |
size_t split, bool realloc) { |
85 |
} |
|
86 |
||
87 |
||
88 |
// Bang the shadow pages if they need to be touched to be mapped. |
|
89 |
inline void os::bang_stack_shadow_pages() { |
|
90 |
} |
|
91 |
||
92 |
inline void os::dll_unload(void *lib) { |
|
93 |
::dlclose(lib); |
|
94 |
} |
|
95 |
||
96 |
inline const int os::default_file_open_flags() { return 0;} |
|
97 |
||
98 |
inline DIR* os::opendir(const char* dirname) |
|
99 |
{ |
|
100 |
assert(dirname != NULL, "just checking"); |
|
101 |
return ::opendir(dirname); |
|
102 |
} |
|
103 |
||
104 |
inline int os::readdir_buf_size(const char *path) |
|
105 |
{ |
|
106 |
return NAME_MAX + sizeof(dirent) + 1; |
|
107 |
} |
|
108 |
||
109 |
inline jlong os::lseek(int fd, jlong offset, int whence) { |
|
110 |
return (jlong) ::lseek(fd, offset, whence); |
|
111 |
} |
|
112 |
||
113 |
inline int os::fsync(int fd) { |
|
114 |
return ::fsync(fd); |
|
115 |
} |
|
116 |
||
117 |
inline char* os::native_path(char *path) { |
|
118 |
return path; |
|
119 |
} |
|
120 |
||
121 |
inline int os::ftruncate(int fd, jlong length) { |
|
122 |
return ::ftruncate(fd, length); |
|
123 |
} |
|
124 |
||
125 |
inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) |
|
126 |
{ |
|
127 |
dirent* p; |
|
128 |
int status; |
|
129 |
assert(dirp != NULL, "just checking"); |
|
130 |
||
131 |
// NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX |
|
132 |
// version. Here is the doc for this function: |
|
133 |
// http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html |
|
134 |
||
135 |
if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { |
|
136 |
errno = status; |
|
137 |
return NULL; |
|
138 |
} else |
|
139 |
return p; |
|
140 |
} |
|
141 |
||
142 |
inline int os::closedir(DIR *dirp) { |
|
143 |
assert(dirp != NULL, "argument is NULL"); |
|
144 |
return ::closedir(dirp); |
|
145 |
} |
|
146 |
||
147 |
// macros for restartable system calls |
|
148 |
||
149 |
#define RESTARTABLE(_cmd, _result) do { \ |
|
150 |
_result = _cmd; \ |
|
151 |
} while(((int)_result == OS_ERR) && (errno == EINTR)) |
|
152 |
||
153 |
#define RESTARTABLE_RETURN_INT(_cmd) do { \ |
|
154 |
int _result; \ |
|
155 |
RESTARTABLE(_cmd, _result); \ |
|
156 |
return _result; \ |
|
157 |
} while(false) |
|
158 |
||
159 |
inline bool os::numa_has_static_binding() { return true; } |
|
160 |
inline bool os::numa_has_group_homing() { return false; } |
|
161 |
||
162 |
inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { |
|
163 |
size_t res; |
|
164 |
RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); |
|
165 |
return res; |
|
166 |
} |
|
167 |
||
168 |
inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { |
|
169 |
size_t res; |
|
170 |
RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); |
|
171 |
return res; |
|
172 |
} |
|
173 |
||
174 |
inline int os::close(int fd) { |
|
18078
10417cf9967d
7178026: os::close can restart ::close but that is not a restartable syscall
rdurbin
parents:
18025
diff
changeset
|
175 |
return ::close(fd); |
10565 | 176 |
} |
177 |
||
178 |
inline int os::socket_close(int fd) { |
|
18078
10417cf9967d
7178026: os::close can restart ::close but that is not a restartable syscall
rdurbin
parents:
18025
diff
changeset
|
179 |
return ::close(fd); |
10565 | 180 |
} |
181 |
||
182 |
inline int os::socket(int domain, int type, int protocol) { |
|
183 |
return ::socket(domain, type, protocol); |
|
184 |
} |
|
185 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
186 |
inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) { |
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
187 |
RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags)); |
10565 | 188 |
} |
189 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
190 |
inline int os::send(int fd, char* buf, size_t nBytes, uint flags) { |
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
191 |
RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); |
10565 | 192 |
} |
193 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
194 |
inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { |
10565 | 195 |
return os::send(fd, buf, nBytes, flags); |
196 |
} |
|
197 |
||
198 |
inline int os::timeout(int fd, long timeout) { |
|
199 |
julong prevtime,newtime; |
|
200 |
struct timeval t; |
|
201 |
||
202 |
gettimeofday(&t, NULL); |
|
203 |
prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; |
|
204 |
||
205 |
for(;;) { |
|
206 |
struct pollfd pfd; |
|
207 |
||
208 |
pfd.fd = fd; |
|
209 |
pfd.events = POLLIN | POLLERR; |
|
210 |
||
211 |
int res = ::poll(&pfd, 1, timeout); |
|
212 |
||
213 |
if (res == OS_ERR && errno == EINTR) { |
|
214 |
||
215 |
// On Bsd any value < 0 means "forever" |
|
216 |
||
217 |
if(timeout >= 0) { |
|
218 |
gettimeofday(&t, NULL); |
|
219 |
newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; |
|
220 |
timeout -= newtime - prevtime; |
|
221 |
if(timeout <= 0) |
|
222 |
return OS_OK; |
|
223 |
prevtime = newtime; |
|
224 |
} |
|
225 |
} else |
|
226 |
return res; |
|
227 |
} |
|
228 |
} |
|
229 |
||
230 |
inline int os::listen(int fd, int count) { |
|
231 |
return ::listen(fd, count); |
|
232 |
} |
|
233 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
234 |
inline int os::connect(int fd, struct sockaddr* him, socklen_t len) { |
10565 | 235 |
RESTARTABLE_RETURN_INT(::connect(fd, him, len)); |
236 |
} |
|
237 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
238 |
inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) { |
10565 | 239 |
// At least OpenBSD and FreeBSD can return EINTR from accept. |
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
240 |
RESTARTABLE_RETURN_INT(::accept(fd, him, len)); |
10565 | 241 |
} |
242 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
243 |
inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags, |
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
244 |
sockaddr* from, socklen_t* fromlen) { |
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
245 |
RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen)); |
10565 | 246 |
} |
247 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
248 |
inline int os::sendto(int fd, char* buf, size_t len, uint flags, |
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
249 |
struct sockaddr *to, socklen_t tolen) { |
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
250 |
RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen)); |
10565 | 251 |
} |
252 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
253 |
inline int os::socket_shutdown(int fd, int howto) { |
10565 | 254 |
return ::shutdown(fd, howto); |
255 |
} |
|
256 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
257 |
inline int os::bind(int fd, struct sockaddr* him, socklen_t len) { |
10565 | 258 |
return ::bind(fd, him, len); |
259 |
} |
|
260 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
261 |
inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) { |
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
262 |
return ::getsockname(fd, him, len); |
10565 | 263 |
} |
264 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
265 |
inline int os::get_host_name(char* name, int namelen) { |
10565 | 266 |
return ::gethostname(name, namelen); |
267 |
} |
|
268 |
||
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
269 |
inline struct hostent* os::get_host_by_name(char* name) { |
10565 | 270 |
return ::gethostbyname(name); |
271 |
} |
|
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
272 |
|
10565 | 273 |
inline int os::get_sock_opt(int fd, int level, int optname, |
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
274 |
char *optval, socklen_t* optlen) { |
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
275 |
return ::getsockopt(fd, level, optname, optval, optlen); |
10565 | 276 |
} |
277 |
||
278 |
inline int os::set_sock_opt(int fd, int level, int optname, |
|
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
279 |
const char* optval, socklen_t optlen) { |
10565 | 280 |
return ::setsockopt(fd, level, optname, optval, optlen); |
281 |
} |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15228
diff
changeset
|
282 |
|
22891
1f5d1fff23fa
6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents:
18078
diff
changeset
|
283 |
inline bool os::supports_monotonic_clock() { |
24239
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22891
diff
changeset
|
284 |
#ifdef __APPLE__ |
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22891
diff
changeset
|
285 |
return true; |
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22891
diff
changeset
|
286 |
#else |
22891
1f5d1fff23fa
6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents:
18078
diff
changeset
|
287 |
return Bsd::_clock_gettime != NULL; |
24239
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22891
diff
changeset
|
288 |
#endif |
22891
1f5d1fff23fa
6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents:
18078
diff
changeset
|
289 |
} |
1f5d1fff23fa
6546236: Thread interrupt() of Thread.sleep() can be lost on Solaris due to race with signal handler
fparain
parents:
18078
diff
changeset
|
290 |
|
10565 | 291 |
#endif // OS_BSD_VM_OS_BSD_INLINE_HPP |