src/os/bsd/vm/os_bsd.inline.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/os/bsd/vm/os_bsd.inline.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,289 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2013, 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.inline.hpp"
    1.32 +#include "runtime/os.hpp"
    1.33 +
    1.34 +#ifdef TARGET_OS_ARCH_bsd_x86
    1.35 +# include "orderAccess_bsd_x86.inline.hpp"
    1.36 +#endif
    1.37 +#ifdef TARGET_OS_ARCH_bsd_zero
    1.38 +# include "orderAccess_bsd_zero.inline.hpp"
    1.39 +#endif
    1.40 +
    1.41 +// System includes
    1.42 +
    1.43 +#include <unistd.h>
    1.44 +#include <sys/socket.h>
    1.45 +#include <sys/poll.h>
    1.46 +#include <netdb.h>
    1.47 +
    1.48 +inline void* os::thread_local_storage_at(int index) {
    1.49 +  return pthread_getspecific((pthread_key_t)index);
    1.50 +}
    1.51 +
    1.52 +inline const char* os::file_separator() {
    1.53 +  return "/";
    1.54 +}
    1.55 +
    1.56 +inline const char* os::line_separator() {
    1.57 +  return "\n";
    1.58 +}
    1.59 +
    1.60 +inline const char* os::path_separator() {
    1.61 +  return ":";
    1.62 +}
    1.63 +
    1.64 +// File names are case-sensitive on windows only
    1.65 +inline int os::file_name_strcmp(const char* s1, const char* s2) {
    1.66 +  return strcmp(s1, s2);
    1.67 +}
    1.68 +
    1.69 +inline bool os::obsolete_option(const JavaVMOption *option) {
    1.70 +  return false;
    1.71 +}
    1.72 +
    1.73 +inline bool os::uses_stack_guard_pages() {
    1.74 +  return true;
    1.75 +}
    1.76 +
    1.77 +inline bool os::allocate_stack_guard_pages() {
    1.78 +  assert(uses_stack_guard_pages(), "sanity check");
    1.79 +#if !defined(__FreeBSD__) || __FreeBSD__ < 5
    1.80 +  // Since FreeBSD 4 uses malloc() for allocating the thread stack
    1.81 +  // there is no need to do anything extra to allocate the guard pages
    1.82 +  return false;
    1.83 +#else
    1.84 +  // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks.
    1.85 +  // Must 'allocate' them or guard pages are ignored.
    1.86 +  return true;
    1.87 +#endif
    1.88 +}
    1.89 +
    1.90 +
    1.91 +// On Bsd, reservations are made on a page by page basis, nothing to do.
    1.92 +inline void os::pd_split_reserved_memory(char *base, size_t size,
    1.93 +                                      size_t split, bool realloc) {
    1.94 +}
    1.95 +
    1.96 +
    1.97 +// Bang the shadow pages if they need to be touched to be mapped.
    1.98 +inline void os::bang_stack_shadow_pages() {
    1.99 +}
   1.100 +
   1.101 +inline void os::dll_unload(void *lib) {
   1.102 +  ::dlclose(lib);
   1.103 +}
   1.104 +
   1.105 +inline const int os::default_file_open_flags() { return 0;}
   1.106 +
   1.107 +inline DIR* os::opendir(const char* dirname)
   1.108 +{
   1.109 +  assert(dirname != NULL, "just checking");
   1.110 +  return ::opendir(dirname);
   1.111 +}
   1.112 +
   1.113 +inline int os::readdir_buf_size(const char *path)
   1.114 +{
   1.115 +  return NAME_MAX + sizeof(dirent) + 1;
   1.116 +}
   1.117 +
   1.118 +inline jlong os::lseek(int fd, jlong offset, int whence) {
   1.119 +  return (jlong) ::lseek(fd, offset, whence);
   1.120 +}
   1.121 +
   1.122 +inline int os::fsync(int fd) {
   1.123 +  return ::fsync(fd);
   1.124 +}
   1.125 +
   1.126 +inline char* os::native_path(char *path) {
   1.127 +  return path;
   1.128 +}
   1.129 +
   1.130 +inline int os::ftruncate(int fd, jlong length) {
   1.131 +  return ::ftruncate(fd, length);
   1.132 +}
   1.133 +
   1.134 +inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
   1.135 +{
   1.136 +  dirent* p;
   1.137 +  int status;
   1.138 +  assert(dirp != NULL, "just checking");
   1.139 +
   1.140 +  // NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
   1.141 +  // version. Here is the doc for this function:
   1.142 +  // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
   1.143 +
   1.144 +  if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
   1.145 +    errno = status;
   1.146 +    return NULL;
   1.147 +  } else
   1.148 +    return p;
   1.149 +}
   1.150 +
   1.151 +inline int os::closedir(DIR *dirp) {
   1.152 +  assert(dirp != NULL, "argument is NULL");
   1.153 +  return ::closedir(dirp);
   1.154 +}
   1.155 +
   1.156 +// macros for restartable system calls
   1.157 +
   1.158 +#define RESTARTABLE(_cmd, _result) do { \
   1.159 +    _result = _cmd; \
   1.160 +  } while(((int)_result == OS_ERR) && (errno == EINTR))
   1.161 +
   1.162 +#define RESTARTABLE_RETURN_INT(_cmd) do { \
   1.163 +  int _result; \
   1.164 +  RESTARTABLE(_cmd, _result); \
   1.165 +  return _result; \
   1.166 +} while(false)
   1.167 +
   1.168 +inline bool os::numa_has_static_binding()   { return true; }
   1.169 +inline bool os::numa_has_group_homing()     { return false;  }
   1.170 +
   1.171 +inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
   1.172 +  size_t res;
   1.173 +  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
   1.174 +  return res;
   1.175 +}
   1.176 +
   1.177 +inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   1.178 +  size_t res;
   1.179 +  RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
   1.180 +  return res;
   1.181 +}
   1.182 +
   1.183 +inline int os::close(int fd) {
   1.184 +  return ::close(fd);
   1.185 +}
   1.186 +
   1.187 +inline int os::socket_close(int fd) {
   1.188 +  return ::close(fd);
   1.189 +}
   1.190 +
   1.191 +inline int os::socket(int domain, int type, int protocol) {
   1.192 +  return ::socket(domain, type, protocol);
   1.193 +}
   1.194 +
   1.195 +inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
   1.196 +  RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
   1.197 +}
   1.198 +
   1.199 +inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
   1.200 +  RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
   1.201 +}
   1.202 +
   1.203 +inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
   1.204 +  return os::send(fd, buf, nBytes, flags);
   1.205 +}
   1.206 +
   1.207 +inline int os::timeout(int fd, long timeout) {
   1.208 +  julong prevtime,newtime;
   1.209 +  struct timeval t;
   1.210 +
   1.211 +  gettimeofday(&t, NULL);
   1.212 +  prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   1.213 +
   1.214 +  for(;;) {
   1.215 +    struct pollfd pfd;
   1.216 +
   1.217 +    pfd.fd = fd;
   1.218 +    pfd.events = POLLIN | POLLERR;
   1.219 +
   1.220 +    int res = ::poll(&pfd, 1, timeout);
   1.221 +
   1.222 +    if (res == OS_ERR && errno == EINTR) {
   1.223 +
   1.224 +      // On Bsd any value < 0 means "forever"
   1.225 +
   1.226 +      if(timeout >= 0) {
   1.227 +        gettimeofday(&t, NULL);
   1.228 +        newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   1.229 +        timeout -= newtime - prevtime;
   1.230 +        if(timeout <= 0)
   1.231 +          return OS_OK;
   1.232 +        prevtime = newtime;
   1.233 +      }
   1.234 +    } else
   1.235 +      return res;
   1.236 +  }
   1.237 +}
   1.238 +
   1.239 +inline int os::listen(int fd, int count) {
   1.240 +  return ::listen(fd, count);
   1.241 +}
   1.242 +
   1.243 +inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
   1.244 +  RESTARTABLE_RETURN_INT(::connect(fd, him, len));
   1.245 +}
   1.246 +
   1.247 +inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
   1.248 +  // At least OpenBSD and FreeBSD can return EINTR from accept.
   1.249 +  RESTARTABLE_RETURN_INT(::accept(fd, him, len));
   1.250 +}
   1.251 +
   1.252 +inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
   1.253 +                         sockaddr* from, socklen_t* fromlen) {
   1.254 +  RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
   1.255 +}
   1.256 +
   1.257 +inline int os::sendto(int fd, char* buf, size_t len, uint flags,
   1.258 +                      struct sockaddr *to, socklen_t tolen) {
   1.259 +  RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
   1.260 +}
   1.261 +
   1.262 +inline int os::socket_shutdown(int fd, int howto) {
   1.263 +  return ::shutdown(fd, howto);
   1.264 +}
   1.265 +
   1.266 +inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
   1.267 +  return ::bind(fd, him, len);
   1.268 +}
   1.269 +
   1.270 +inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
   1.271 +  return ::getsockname(fd, him, len);
   1.272 +}
   1.273 +
   1.274 +inline int os::get_host_name(char* name, int namelen) {
   1.275 +  return ::gethostname(name, namelen);
   1.276 +}
   1.277 +
   1.278 +inline struct hostent* os::get_host_by_name(char* name) {
   1.279 +  return ::gethostbyname(name);
   1.280 +}
   1.281 +
   1.282 +inline int os::get_sock_opt(int fd, int level, int optname,
   1.283 +                            char *optval, socklen_t* optlen) {
   1.284 +  return ::getsockopt(fd, level, optname, optval, optlen);
   1.285 +}
   1.286 +
   1.287 +inline int os::set_sock_opt(int fd, int level, int optname,
   1.288 +                            const char* optval, socklen_t optlen) {
   1.289 +  return ::setsockopt(fd, level, optname, optval, optlen);
   1.290 +}
   1.291 +
   1.292 +#endif // OS_BSD_VM_OS_BSD_INLINE_HPP

mercurial