src/os/linux/vm/os_linux.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/linux/vm/os_linux.inline.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,291 @@
     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_LINUX_VM_OS_LINUX_INLINE_HPP
    1.29 +#define OS_LINUX_VM_OS_LINUX_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_linux_x86
    1.35 +# include "orderAccess_linux_x86.inline.hpp"
    1.36 +#endif
    1.37 +#ifdef TARGET_OS_ARCH_linux_sparc
    1.38 +# include "orderAccess_linux_sparc.inline.hpp"
    1.39 +#endif
    1.40 +#ifdef TARGET_OS_ARCH_linux_zero
    1.41 +# include "orderAccess_linux_zero.inline.hpp"
    1.42 +#endif
    1.43 +#ifdef TARGET_OS_ARCH_linux_arm
    1.44 +# include "orderAccess_linux_arm.inline.hpp"
    1.45 +#endif
    1.46 +#ifdef TARGET_OS_ARCH_linux_ppc
    1.47 +# include "orderAccess_linux_ppc.inline.hpp"
    1.48 +#endif
    1.49 +
    1.50 +// System includes
    1.51 +
    1.52 +#include <unistd.h>
    1.53 +#include <sys/socket.h>
    1.54 +#include <sys/poll.h>
    1.55 +#include <netdb.h>
    1.56 +
    1.57 +inline void* os::thread_local_storage_at(int index) {
    1.58 +  return pthread_getspecific((pthread_key_t)index);
    1.59 +}
    1.60 +
    1.61 +inline const char* os::file_separator() {
    1.62 +  return "/";
    1.63 +}
    1.64 +
    1.65 +inline const char* os::line_separator() {
    1.66 +  return "\n";
    1.67 +}
    1.68 +
    1.69 +inline const char* os::path_separator() {
    1.70 +  return ":";
    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 +  return true;
    1.89 +}
    1.90 +
    1.91 +
    1.92 +// On Linux, reservations are made on a page by page basis, nothing to do.
    1.93 +inline void os::pd_split_reserved_memory(char *base, size_t size,
    1.94 +                                      size_t split, bool realloc) {
    1.95 +}
    1.96 +
    1.97 +
    1.98 +// Bang the shadow pages if they need to be touched to be mapped.
    1.99 +inline void os::bang_stack_shadow_pages() {
   1.100 +}
   1.101 +
   1.102 +inline void os::dll_unload(void *lib) {
   1.103 +  ::dlclose(lib);
   1.104 +}
   1.105 +
   1.106 +inline const int os::default_file_open_flags() { return 0;}
   1.107 +
   1.108 +inline DIR* os::opendir(const char* dirname)
   1.109 +{
   1.110 +  assert(dirname != NULL, "just checking");
   1.111 +  return ::opendir(dirname);
   1.112 +}
   1.113 +
   1.114 +inline int os::readdir_buf_size(const char *path)
   1.115 +{
   1.116 +  return NAME_MAX + sizeof(dirent) + 1;
   1.117 +}
   1.118 +
   1.119 +inline jlong os::lseek(int fd, jlong offset, int whence) {
   1.120 +  return (jlong) ::lseek64(fd, offset, whence);
   1.121 +}
   1.122 +
   1.123 +inline int os::fsync(int fd) {
   1.124 +  return ::fsync(fd);
   1.125 +}
   1.126 +
   1.127 +inline char* os::native_path(char *path) {
   1.128 +  return path;
   1.129 +}
   1.130 +
   1.131 +inline int os::ftruncate(int fd, jlong length) {
   1.132 +  return ::ftruncate64(fd, length);
   1.133 +}
   1.134 +
   1.135 +inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
   1.136 +{
   1.137 +  dirent* p;
   1.138 +  int status;
   1.139 +  assert(dirp != NULL, "just checking");
   1.140 +
   1.141 +  // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
   1.142 +  // version. Here is the doc for this function:
   1.143 +  // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
   1.144 +
   1.145 +  if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
   1.146 +    errno = status;
   1.147 +    return NULL;
   1.148 +  } else
   1.149 +    return p;
   1.150 +}
   1.151 +
   1.152 +inline int os::closedir(DIR *dirp) {
   1.153 +  assert(dirp != NULL, "argument is NULL");
   1.154 +  return ::closedir(dirp);
   1.155 +}
   1.156 +
   1.157 +// macros for restartable system calls
   1.158 +
   1.159 +#define RESTARTABLE(_cmd, _result) do { \
   1.160 +    _result = _cmd; \
   1.161 +  } while(((int)_result == OS_ERR) && (errno == EINTR))
   1.162 +
   1.163 +#define RESTARTABLE_RETURN_INT(_cmd) do { \
   1.164 +  int _result; \
   1.165 +  RESTARTABLE(_cmd, _result); \
   1.166 +  return _result; \
   1.167 +} while(false)
   1.168 +
   1.169 +inline bool os::numa_has_static_binding()   { return true; }
   1.170 +inline bool os::numa_has_group_homing()     { return false;  }
   1.171 +
   1.172 +inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
   1.173 +  size_t res;
   1.174 +  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
   1.175 +  return res;
   1.176 +}
   1.177 +
   1.178 +inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   1.179 +  size_t res;
   1.180 +  RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
   1.181 +  return res;
   1.182 +}
   1.183 +
   1.184 +inline int os::close(int fd) {
   1.185 +  return ::close(fd);
   1.186 +}
   1.187 +
   1.188 +inline int os::socket_close(int fd) {
   1.189 +  return ::close(fd);
   1.190 +}
   1.191 +
   1.192 +inline int os::socket(int domain, int type, int protocol) {
   1.193 +  return ::socket(domain, type, protocol);
   1.194 +}
   1.195 +
   1.196 +inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
   1.197 +  RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
   1.198 +}
   1.199 +
   1.200 +inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
   1.201 +  RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
   1.202 +}
   1.203 +
   1.204 +inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
   1.205 +  return os::send(fd, buf, nBytes, flags);
   1.206 +}
   1.207 +
   1.208 +inline int os::timeout(int fd, long timeout) {
   1.209 +  julong prevtime,newtime;
   1.210 +  struct timeval t;
   1.211 +
   1.212 +  gettimeofday(&t, NULL);
   1.213 +  prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   1.214 +
   1.215 +  for(;;) {
   1.216 +    struct pollfd pfd;
   1.217 +
   1.218 +    pfd.fd = fd;
   1.219 +    pfd.events = POLLIN | POLLERR;
   1.220 +
   1.221 +    int res = ::poll(&pfd, 1, timeout);
   1.222 +
   1.223 +    if (res == OS_ERR && errno == EINTR) {
   1.224 +
   1.225 +      // On Linux any value < 0 means "forever"
   1.226 +
   1.227 +      if(timeout >= 0) {
   1.228 +        gettimeofday(&t, NULL);
   1.229 +        newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   1.230 +        timeout -= newtime - prevtime;
   1.231 +        if(timeout <= 0)
   1.232 +          return OS_OK;
   1.233 +        prevtime = newtime;
   1.234 +      }
   1.235 +    } else
   1.236 +      return res;
   1.237 +  }
   1.238 +}
   1.239 +
   1.240 +inline int os::listen(int fd, int count) {
   1.241 +  return ::listen(fd, count);
   1.242 +}
   1.243 +
   1.244 +inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
   1.245 +  RESTARTABLE_RETURN_INT(::connect(fd, him, len));
   1.246 +}
   1.247 +
   1.248 +inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
   1.249 +  // Linux doc says this can't return EINTR, unlike accept() on Solaris.
   1.250 +  // But see attachListener_linux.cpp, LinuxAttachListener::dequeue().
   1.251 +  return (int)::accept(fd, him, len);
   1.252 +}
   1.253 +
   1.254 +inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
   1.255 +                        sockaddr* from, socklen_t* fromlen) {
   1.256 +  RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
   1.257 +}
   1.258 +
   1.259 +inline int os::sendto(int fd, char* buf, size_t len, uint flags,
   1.260 +                      struct sockaddr* to, socklen_t tolen) {
   1.261 +  RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
   1.262 +}
   1.263 +
   1.264 +inline int os::socket_shutdown(int fd, int howto) {
   1.265 +  return ::shutdown(fd, howto);
   1.266 +}
   1.267 +
   1.268 +inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
   1.269 +  return ::bind(fd, him, len);
   1.270 +}
   1.271 +
   1.272 +inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
   1.273 +  return ::getsockname(fd, him, len);
   1.274 +}
   1.275 +
   1.276 +inline int os::get_host_name(char* name, int namelen) {
   1.277 +  return ::gethostname(name, namelen);
   1.278 +}
   1.279 +
   1.280 +inline struct hostent* os::get_host_by_name(char* name) {
   1.281 +  return ::gethostbyname(name);
   1.282 +}
   1.283 +
   1.284 +inline int os::get_sock_opt(int fd, int level, int optname,
   1.285 +                            char* optval, socklen_t* optlen) {
   1.286 +  return ::getsockopt(fd, level, optname, optval, optlen);
   1.287 +}
   1.288 +
   1.289 +inline int os::set_sock_opt(int fd, int level, int optname,
   1.290 +                            const char* optval, socklen_t optlen) {
   1.291 +  return ::setsockopt(fd, level, optname, optval, optlen);
   1.292 +}
   1.293 +
   1.294 +#endif // OS_LINUX_VM_OS_LINUX_INLINE_HPP

mercurial