Mercurial > hg > truffle
annotate src/os/bsd/vm/os_bsd.inline.hpp @ 4939:45a1bf98f1bb
7141329: Strange values of stack_size in -XX:+TraceMethodHandles output
Reviewed-by: kvn, never
author | twisti |
---|---|
date | Mon, 13 Feb 2012 02:29:22 -0800 |
parents | 11c26bfcf8c7 |
children | d2a62e0f25eb |
rev | line source |
---|---|
3960 | 1 /* |
2 * Copyright (c) 1999, 2011, 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 */ | |
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" | |
29 #include "runtime/os.hpp" | |
30 #ifdef TARGET_OS_ARCH_bsd_x86 | |
31 # include "atomic_bsd_x86.inline.hpp" | |
32 # include "orderAccess_bsd_x86.inline.hpp" | |
33 #endif | |
34 #ifdef TARGET_OS_ARCH_bsd_zero | |
35 # include "atomic_bsd_zero.inline.hpp" | |
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 inline const char* os::jlong_format_specifier() { | |
63 return "%lld"; | |
64 } | |
65 | |
66 inline const char* os::julong_format_specifier() { | |
67 return "%llu"; | |
68 } | |
69 | |
70 // File names are case-sensitive on windows only | |
71 inline int os::file_name_strcmp(const char* s1, const char* s2) { | |
72 return strcmp(s1, s2); | |
73 } | |
74 | |
75 inline bool os::obsolete_option(const JavaVMOption *option) { | |
76 return false; | |
77 } | |
78 | |
79 inline bool os::uses_stack_guard_pages() { | |
80 return true; | |
81 } | |
82 | |
83 inline bool os::allocate_stack_guard_pages() { | |
84 assert(uses_stack_guard_pages(), "sanity check"); | |
85 #if !defined(__FreeBSD__) || __FreeBSD__ < 5 | |
86 // Since FreeBSD 4 uses malloc() for allocating the thread stack | |
87 // there is no need to do anything extra to allocate the guard pages | |
88 return false; | |
89 #else | |
90 // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks. | |
91 // Must 'allocate' them or guard pages are ignored. | |
92 return true; | |
93 #endif | |
94 } | |
95 | |
96 | |
97 // On Bsd, reservations are made on a page by page basis, nothing to do. | |
98 inline void os::split_reserved_memory(char *base, size_t size, | |
99 size_t split, bool realloc) { | |
100 } | |
101 | |
102 | |
103 // Bang the shadow pages if they need to be touched to be mapped. | |
104 inline void os::bang_stack_shadow_pages() { | |
105 } | |
106 | |
107 inline void os::dll_unload(void *lib) { | |
108 ::dlclose(lib); | |
109 } | |
110 | |
111 inline const int os::default_file_open_flags() { return 0;} | |
112 | |
113 inline DIR* os::opendir(const char* dirname) | |
114 { | |
115 assert(dirname != NULL, "just checking"); | |
116 return ::opendir(dirname); | |
117 } | |
118 | |
119 inline int os::readdir_buf_size(const char *path) | |
120 { | |
121 return NAME_MAX + sizeof(dirent) + 1; | |
122 } | |
123 | |
124 inline jlong os::lseek(int fd, jlong offset, int whence) { | |
125 return (jlong) ::lseek(fd, offset, whence); | |
126 } | |
127 | |
128 inline int os::fsync(int fd) { | |
129 return ::fsync(fd); | |
130 } | |
131 | |
132 inline char* os::native_path(char *path) { | |
133 return path; | |
134 } | |
135 | |
136 inline int os::ftruncate(int fd, jlong length) { | |
137 return ::ftruncate(fd, length); | |
138 } | |
139 | |
140 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) | |
141 { | |
142 dirent* p; | |
143 int status; | |
144 assert(dirp != NULL, "just checking"); | |
145 | |
146 // NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX | |
147 // version. Here is the doc for this function: | |
148 // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html | |
149 | |
150 if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { | |
151 errno = status; | |
152 return NULL; | |
153 } else | |
154 return p; | |
155 } | |
156 | |
157 inline int os::closedir(DIR *dirp) { | |
158 assert(dirp != NULL, "argument is NULL"); | |
159 return ::closedir(dirp); | |
160 } | |
161 | |
162 // macros for restartable system calls | |
163 | |
164 #define RESTARTABLE(_cmd, _result) do { \ | |
165 _result = _cmd; \ | |
166 } while(((int)_result == OS_ERR) && (errno == EINTR)) | |
167 | |
168 #define RESTARTABLE_RETURN_INT(_cmd) do { \ | |
169 int _result; \ | |
170 RESTARTABLE(_cmd, _result); \ | |
171 return _result; \ | |
172 } while(false) | |
173 | |
174 inline bool os::numa_has_static_binding() { return true; } | |
175 inline bool os::numa_has_group_homing() { return false; } | |
176 | |
177 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { | |
178 size_t res; | |
179 RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); | |
180 return res; | |
181 } | |
182 | |
183 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { | |
184 size_t res; | |
185 RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); | |
186 return res; | |
187 } | |
188 | |
189 inline int os::close(int fd) { | |
190 RESTARTABLE_RETURN_INT(::close(fd)); | |
191 } | |
192 | |
193 inline int os::socket_close(int fd) { | |
194 RESTARTABLE_RETURN_INT(::close(fd)); | |
195 } | |
196 | |
197 inline int os::socket(int domain, int type, int protocol) { | |
198 return ::socket(domain, type, protocol); | |
199 } | |
200 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
201 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
|
202 RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags)); |
3960 | 203 } |
204 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
205 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
|
206 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); |
3960 | 207 } |
208 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
209 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { |
3960 | 210 return os::send(fd, buf, nBytes, flags); |
211 } | |
212 | |
213 inline int os::timeout(int fd, long timeout) { | |
214 julong prevtime,newtime; | |
215 struct timeval t; | |
216 | |
217 gettimeofday(&t, NULL); | |
218 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; | |
219 | |
220 for(;;) { | |
221 struct pollfd pfd; | |
222 | |
223 pfd.fd = fd; | |
224 pfd.events = POLLIN | POLLERR; | |
225 | |
226 int res = ::poll(&pfd, 1, timeout); | |
227 | |
228 if (res == OS_ERR && errno == EINTR) { | |
229 | |
230 // On Bsd any value < 0 means "forever" | |
231 | |
232 if(timeout >= 0) { | |
233 gettimeofday(&t, NULL); | |
234 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; | |
235 timeout -= newtime - prevtime; | |
236 if(timeout <= 0) | |
237 return OS_OK; | |
238 prevtime = newtime; | |
239 } | |
240 } else | |
241 return res; | |
242 } | |
243 } | |
244 | |
245 inline int os::listen(int fd, int count) { | |
246 return ::listen(fd, count); | |
247 } | |
248 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
249 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) { |
3960 | 250 RESTARTABLE_RETURN_INT(::connect(fd, him, len)); |
251 } | |
252 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
253 inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) { |
3960 | 254 // 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
|
255 RESTARTABLE_RETURN_INT(::accept(fd, him, len)); |
3960 | 256 } |
257 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
258 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
|
259 sockaddr* from, socklen_t* fromlen) { |
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
260 RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen)); |
3960 | 261 } |
262 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
263 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
|
264 struct sockaddr *to, socklen_t tolen) { |
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
265 RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen)); |
3960 | 266 } |
267 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
268 inline int os::socket_shutdown(int fd, int howto) { |
3960 | 269 return ::shutdown(fd, howto); |
270 } | |
271 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
272 inline int os::bind(int fd, struct sockaddr* him, socklen_t len) { |
3960 | 273 return ::bind(fd, him, len); |
274 } | |
275 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
276 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
|
277 return ::getsockname(fd, him, len); |
3960 | 278 } |
279 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
280 inline int os::get_host_name(char* name, int namelen) { |
3960 | 281 return ::gethostname(name, namelen); |
282 } | |
283 | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
284 inline struct hostent* os::get_host_by_name(char* name) { |
3960 | 285 return ::gethostbyname(name); |
286 } | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
287 |
3960 | 288 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
|
289 char *optval, socklen_t* optlen) { |
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
290 return ::getsockopt(fd, level, optname, optval, optlen); |
3960 | 291 } |
292 | |
293 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
|
294 const char* optval, socklen_t optlen) { |
3960 | 295 return ::setsockopt(fd, level, optname, optval, optlen); |
296 } | |
297 #endif // OS_BSD_VM_OS_BSD_INLINE_HPP |