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