1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os/bsd/vm/os_bsd.inline.hpp Sun Sep 25 16:03:29 2011 -0700 1.3 @@ -0,0 +1,302 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef OS_BSD_VM_OS_BSD_INLINE_HPP 1.29 +#define OS_BSD_VM_OS_BSD_INLINE_HPP 1.30 + 1.31 +#include "runtime/atomic.hpp" 1.32 +#include "runtime/os.hpp" 1.33 +#ifdef TARGET_OS_ARCH_bsd_x86 1.34 +# include "atomic_bsd_x86.inline.hpp" 1.35 +# include "orderAccess_bsd_x86.inline.hpp" 1.36 +#endif 1.37 +#ifdef TARGET_OS_ARCH_bsd_zero 1.38 +# include "atomic_bsd_zero.inline.hpp" 1.39 +# include "orderAccess_bsd_zero.inline.hpp" 1.40 +#endif 1.41 + 1.42 +// System includes 1.43 + 1.44 +#include <unistd.h> 1.45 +#include <sys/socket.h> 1.46 +#include <sys/poll.h> 1.47 +#include <netdb.h> 1.48 + 1.49 +inline void* os::thread_local_storage_at(int index) { 1.50 + return pthread_getspecific((pthread_key_t)index); 1.51 +} 1.52 + 1.53 +inline const char* os::file_separator() { 1.54 + return "/"; 1.55 +} 1.56 + 1.57 +inline const char* os::line_separator() { 1.58 + return "\n"; 1.59 +} 1.60 + 1.61 +inline const char* os::path_separator() { 1.62 + return ":"; 1.63 +} 1.64 + 1.65 +inline const char* os::jlong_format_specifier() { 1.66 + return "%lld"; 1.67 +} 1.68 + 1.69 +inline const char* os::julong_format_specifier() { 1.70 + return "%llu"; 1.71 +} 1.72 + 1.73 +// File names are case-sensitive on windows only 1.74 +inline int os::file_name_strcmp(const char* s1, const char* s2) { 1.75 + return strcmp(s1, s2); 1.76 +} 1.77 + 1.78 +inline bool os::obsolete_option(const JavaVMOption *option) { 1.79 + return false; 1.80 +} 1.81 + 1.82 +inline bool os::uses_stack_guard_pages() { 1.83 + return true; 1.84 +} 1.85 + 1.86 +inline bool os::allocate_stack_guard_pages() { 1.87 + assert(uses_stack_guard_pages(), "sanity check"); 1.88 +#if !defined(__FreeBSD__) || __FreeBSD__ < 5 1.89 + // Since FreeBSD 4 uses malloc() for allocating the thread stack 1.90 + // there is no need to do anything extra to allocate the guard pages 1.91 + return false; 1.92 +#else 1.93 + // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks. 1.94 + // Must 'allocate' them or guard pages are ignored. 1.95 + return true; 1.96 +#endif 1.97 +} 1.98 + 1.99 + 1.100 +// On Bsd, reservations are made on a page by page basis, nothing to do. 1.101 +inline void os::split_reserved_memory(char *base, size_t size, 1.102 + size_t split, bool realloc) { 1.103 +} 1.104 + 1.105 + 1.106 +// Bang the shadow pages if they need to be touched to be mapped. 1.107 +inline void os::bang_stack_shadow_pages() { 1.108 +} 1.109 + 1.110 +inline void os::dll_unload(void *lib) { 1.111 + ::dlclose(lib); 1.112 +} 1.113 + 1.114 +inline const int os::default_file_open_flags() { return 0;} 1.115 + 1.116 +inline DIR* os::opendir(const char* dirname) 1.117 +{ 1.118 + assert(dirname != NULL, "just checking"); 1.119 + return ::opendir(dirname); 1.120 +} 1.121 + 1.122 +inline int os::readdir_buf_size(const char *path) 1.123 +{ 1.124 + return NAME_MAX + sizeof(dirent) + 1; 1.125 +} 1.126 + 1.127 +inline jlong os::lseek(int fd, jlong offset, int whence) { 1.128 + return (jlong) ::lseek(fd, offset, whence); 1.129 +} 1.130 + 1.131 +inline int os::fsync(int fd) { 1.132 + return ::fsync(fd); 1.133 +} 1.134 + 1.135 +inline char* os::native_path(char *path) { 1.136 + return path; 1.137 +} 1.138 + 1.139 +inline int os::ftruncate(int fd, jlong length) { 1.140 + return ::ftruncate(fd, length); 1.141 +} 1.142 + 1.143 +inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) 1.144 +{ 1.145 + dirent* p; 1.146 + int status; 1.147 + assert(dirp != NULL, "just checking"); 1.148 + 1.149 + // NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX 1.150 + // version. Here is the doc for this function: 1.151 + // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html 1.152 + 1.153 + if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { 1.154 + errno = status; 1.155 + return NULL; 1.156 + } else 1.157 + return p; 1.158 +} 1.159 + 1.160 +inline int os::closedir(DIR *dirp) { 1.161 + assert(dirp != NULL, "argument is NULL"); 1.162 + return ::closedir(dirp); 1.163 +} 1.164 + 1.165 +// macros for restartable system calls 1.166 + 1.167 +#define RESTARTABLE(_cmd, _result) do { \ 1.168 + _result = _cmd; \ 1.169 + } while(((int)_result == OS_ERR) && (errno == EINTR)) 1.170 + 1.171 +#define RESTARTABLE_RETURN_INT(_cmd) do { \ 1.172 + int _result; \ 1.173 + RESTARTABLE(_cmd, _result); \ 1.174 + return _result; \ 1.175 +} while(false) 1.176 + 1.177 +inline bool os::numa_has_static_binding() { return true; } 1.178 +inline bool os::numa_has_group_homing() { return false; } 1.179 + 1.180 +inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { 1.181 + size_t res; 1.182 + RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); 1.183 + return res; 1.184 +} 1.185 + 1.186 +inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { 1.187 + size_t res; 1.188 + RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); 1.189 + return res; 1.190 +} 1.191 + 1.192 +inline int os::close(int fd) { 1.193 + RESTARTABLE_RETURN_INT(::close(fd)); 1.194 +} 1.195 + 1.196 +inline int os::socket_close(int fd) { 1.197 + RESTARTABLE_RETURN_INT(::close(fd)); 1.198 +} 1.199 + 1.200 +inline int os::socket(int domain, int type, int protocol) { 1.201 + return ::socket(domain, type, protocol); 1.202 +} 1.203 + 1.204 +inline int os::recv(int fd, char *buf, int nBytes, int flags) { 1.205 + RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags)); 1.206 +} 1.207 + 1.208 +inline int os::send(int fd, char *buf, int nBytes, int flags) { 1.209 + RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags)); 1.210 +} 1.211 + 1.212 +inline int os::raw_send(int fd, char *buf, int nBytes, int flags) { 1.213 + return os::send(fd, buf, nBytes, flags); 1.214 +} 1.215 + 1.216 +inline int os::timeout(int fd, long timeout) { 1.217 + julong prevtime,newtime; 1.218 + struct timeval t; 1.219 + 1.220 + gettimeofday(&t, NULL); 1.221 + prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; 1.222 + 1.223 + for(;;) { 1.224 + struct pollfd pfd; 1.225 + 1.226 + pfd.fd = fd; 1.227 + pfd.events = POLLIN | POLLERR; 1.228 + 1.229 + int res = ::poll(&pfd, 1, timeout); 1.230 + 1.231 + if (res == OS_ERR && errno == EINTR) { 1.232 + 1.233 + // On Bsd any value < 0 means "forever" 1.234 + 1.235 + if(timeout >= 0) { 1.236 + gettimeofday(&t, NULL); 1.237 + newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; 1.238 + timeout -= newtime - prevtime; 1.239 + if(timeout <= 0) 1.240 + return OS_OK; 1.241 + prevtime = newtime; 1.242 + } 1.243 + } else 1.244 + return res; 1.245 + } 1.246 +} 1.247 + 1.248 +inline int os::listen(int fd, int count) { 1.249 + return ::listen(fd, count); 1.250 +} 1.251 + 1.252 +inline int os::connect(int fd, struct sockaddr *him, int len) { 1.253 + RESTARTABLE_RETURN_INT(::connect(fd, him, len)); 1.254 +} 1.255 + 1.256 +inline int os::accept(int fd, struct sockaddr *him, int *len) { 1.257 + // This cast is from int to unsigned int on bsd. Since we 1.258 + // only pass the parameter "len" around the vm and don't try to 1.259 + // fetch it's value, this cast is safe for now. The java.net group 1.260 + // may need and want to change this interface someday if socklen_t goes 1.261 + // to 64 bits on some platform that we support. 1.262 + 1.263 + // At least OpenBSD and FreeBSD can return EINTR from accept. 1.264 + RESTARTABLE_RETURN_INT(::accept(fd, him, (socklen_t *)len)); 1.265 +} 1.266 + 1.267 +inline int os::recvfrom(int fd, char *buf, int nBytes, int flags, 1.268 + sockaddr *from, int *fromlen) { 1.269 + RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen)); 1.270 +} 1.271 + 1.272 +inline int os::sendto(int fd, char *buf, int len, int flags, 1.273 + struct sockaddr *to, int tolen) { 1.274 + RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen)); 1.275 +} 1.276 + 1.277 +inline int os::socket_shutdown(int fd, int howto){ 1.278 + return ::shutdown(fd, howto); 1.279 +} 1.280 + 1.281 +inline int os::bind(int fd, struct sockaddr *him, int len){ 1.282 + return ::bind(fd, him, len); 1.283 +} 1.284 + 1.285 +inline int os::get_sock_name(int fd, struct sockaddr *him, int *len){ 1.286 + return ::getsockname(fd, him, (socklen_t *)len); 1.287 +} 1.288 + 1.289 +inline int os::get_host_name(char* name, int namelen){ 1.290 + return ::gethostname(name, namelen); 1.291 +} 1.292 + 1.293 +inline struct hostent* os::get_host_by_name(char* name) { 1.294 + return ::gethostbyname(name); 1.295 +} 1.296 +inline int os::get_sock_opt(int fd, int level, int optname, 1.297 + char *optval, int* optlen){ 1.298 + return ::getsockopt(fd, level, optname, optval, (socklen_t *)optlen); 1.299 +} 1.300 + 1.301 +inline int os::set_sock_opt(int fd, int level, int optname, 1.302 + const char *optval, int optlen){ 1.303 + return ::setsockopt(fd, level, optname, optval, optlen); 1.304 +} 1.305 +#endif // OS_BSD_VM_OS_BSD_INLINE_HPP