src/os/linux/vm/os_linux.inline.hpp

Fri, 30 Nov 2012 15:23:16 -0800

author
twisti
date
Fri, 30 Nov 2012 15:23:16 -0800
changeset 4318
cd3d6a6b95d9
parent 4153
b9a9ed0f8eeb
child 4465
203f64878aab
permissions
-rw-r--r--

8003240: x86: move MacroAssembler into separate file
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 1999, 2012, 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  */
    25 #ifndef OS_LINUX_VM_OS_LINUX_INLINE_HPP
    26 #define OS_LINUX_VM_OS_LINUX_INLINE_HPP
    28 #include "runtime/atomic.hpp"
    29 #include "runtime/atomic.inline.hpp"
    30 #include "runtime/os.hpp"
    32 #ifdef TARGET_OS_ARCH_linux_x86
    33 # include "orderAccess_linux_x86.inline.hpp"
    34 #endif
    35 #ifdef TARGET_OS_ARCH_linux_sparc
    36 # include "orderAccess_linux_sparc.inline.hpp"
    37 #endif
    38 #ifdef TARGET_OS_ARCH_linux_zero
    39 # include "orderAccess_linux_zero.inline.hpp"
    40 #endif
    41 #ifdef TARGET_OS_ARCH_linux_arm
    42 # include "orderAccess_linux_arm.inline.hpp"
    43 #endif
    44 #ifdef TARGET_OS_ARCH_linux_ppc
    45 # include "orderAccess_linux_ppc.inline.hpp"
    46 #endif
    48 // System includes
    50 #include <unistd.h>
    51 #include <sys/socket.h>
    52 #include <sys/poll.h>
    53 #include <netdb.h>
    55 inline void* os::thread_local_storage_at(int index) {
    56   return pthread_getspecific((pthread_key_t)index);
    57 }
    59 inline const char* os::file_separator() {
    60   return "/";
    61 }
    63 inline const char* os::line_separator() {
    64   return "\n";
    65 }
    67 inline const char* os::path_separator() {
    68   return ":";
    69 }
    71 inline const char* os::jlong_format_specifier() {
    72   return "%lld";
    73 }
    75 inline const char* os::julong_format_specifier() {
    76   return "%llu";
    77 }
    79 // File names are case-sensitive on windows only
    80 inline int os::file_name_strcmp(const char* s1, const char* s2) {
    81   return strcmp(s1, s2);
    82 }
    84 inline bool os::obsolete_option(const JavaVMOption *option) {
    85   return false;
    86 }
    88 inline bool os::uses_stack_guard_pages() {
    89   return true;
    90 }
    92 inline bool os::allocate_stack_guard_pages() {
    93   assert(uses_stack_guard_pages(), "sanity check");
    94   return true;
    95 }
    98 // On Linux, reservations are made on a page by page basis, nothing to do.
    99 inline void os::pd_split_reserved_memory(char *base, size_t size,
   100                                       size_t split, bool realloc) {
   101 }
   104 // Bang the shadow pages if they need to be touched to be mapped.
   105 inline void os::bang_stack_shadow_pages() {
   106 }
   108 inline void os::dll_unload(void *lib) {
   109   ::dlclose(lib);
   110 }
   112 inline const int os::default_file_open_flags() { return 0;}
   114 inline DIR* os::opendir(const char* dirname)
   115 {
   116   assert(dirname != NULL, "just checking");
   117   return ::opendir(dirname);
   118 }
   120 inline int os::readdir_buf_size(const char *path)
   121 {
   122   return NAME_MAX + sizeof(dirent) + 1;
   123 }
   125 inline jlong os::lseek(int fd, jlong offset, int whence) {
   126   return (jlong) ::lseek64(fd, offset, whence);
   127 }
   129 inline int os::fsync(int fd) {
   130   return ::fsync(fd);
   131 }
   133 inline char* os::native_path(char *path) {
   134   return path;
   135 }
   137 inline int os::ftruncate(int fd, jlong length) {
   138   return ::ftruncate64(fd, length);
   139 }
   141 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
   142 {
   143   dirent* p;
   144   int status;
   145   assert(dirp != NULL, "just checking");
   147   // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
   148   // version. Here is the doc for this function:
   149   // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
   151   if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
   152     errno = status;
   153     return NULL;
   154   } else
   155     return p;
   156 }
   158 inline int os::closedir(DIR *dirp) {
   159   assert(dirp != NULL, "argument is NULL");
   160   return ::closedir(dirp);
   161 }
   163 // macros for restartable system calls
   165 #define RESTARTABLE(_cmd, _result) do { \
   166     _result = _cmd; \
   167   } while(((int)_result == OS_ERR) && (errno == EINTR))
   169 #define RESTARTABLE_RETURN_INT(_cmd) do { \
   170   int _result; \
   171   RESTARTABLE(_cmd, _result); \
   172   return _result; \
   173 } while(false)
   175 inline bool os::numa_has_static_binding()   { return true; }
   176 inline bool os::numa_has_group_homing()     { return false;  }
   178 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
   179   size_t res;
   180   RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
   181   return res;
   182 }
   184 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   185   size_t res;
   186   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
   187   return res;
   188 }
   190 inline int os::close(int fd) {
   191   return ::close(fd);
   192 }
   194 inline int os::socket_close(int fd) {
   195   return ::close(fd);
   196 }
   198 inline int os::socket(int domain, int type, int protocol) {
   199   return ::socket(domain, type, protocol);
   200 }
   202 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
   203   RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
   204 }
   206 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
   207   RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
   208 }
   210 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
   211   return os::send(fd, buf, nBytes, flags);
   212 }
   214 inline int os::timeout(int fd, long timeout) {
   215   julong prevtime,newtime;
   216   struct timeval t;
   218   gettimeofday(&t, NULL);
   219   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   221   for(;;) {
   222     struct pollfd pfd;
   224     pfd.fd = fd;
   225     pfd.events = POLLIN | POLLERR;
   227     int res = ::poll(&pfd, 1, timeout);
   229     if (res == OS_ERR && errno == EINTR) {
   231       // On Linux any value < 0 means "forever"
   233       if(timeout >= 0) {
   234         gettimeofday(&t, NULL);
   235         newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   236         timeout -= newtime - prevtime;
   237         if(timeout <= 0)
   238           return OS_OK;
   239         prevtime = newtime;
   240       }
   241     } else
   242       return res;
   243   }
   244 }
   246 inline int os::listen(int fd, int count) {
   247   return ::listen(fd, count);
   248 }
   250 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
   251   RESTARTABLE_RETURN_INT(::connect(fd, him, len));
   252 }
   254 inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
   255   // Linux doc says this can't return EINTR, unlike accept() on Solaris.
   256   // But see attachListener_linux.cpp, LinuxAttachListener::dequeue().
   257   return (int)::accept(fd, him, len);
   258 }
   260 inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
   261                         sockaddr* from, socklen_t* fromlen) {
   262   RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
   263 }
   265 inline int os::sendto(int fd, char* buf, size_t len, uint flags,
   266                       struct sockaddr* to, socklen_t tolen) {
   267   RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
   268 }
   270 inline int os::socket_shutdown(int fd, int howto) {
   271   return ::shutdown(fd, howto);
   272 }
   274 inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
   275   return ::bind(fd, him, len);
   276 }
   278 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
   279   return ::getsockname(fd, him, len);
   280 }
   282 inline int os::get_host_name(char* name, int namelen) {
   283   return ::gethostname(name, namelen);
   284 }
   286 inline struct hostent* os::get_host_by_name(char* name) {
   287   return ::gethostbyname(name);
   288 }
   290 inline int os::get_sock_opt(int fd, int level, int optname,
   291                             char* optval, socklen_t* optlen) {
   292   return ::getsockopt(fd, level, optname, optval, optlen);
   293 }
   295 inline int os::set_sock_opt(int fd, int level, int optname,
   296                             const char* optval, socklen_t optlen) {
   297   return ::setsockopt(fd, level, optname, optval, optlen);
   298 }
   299 #endif // OS_LINUX_VM_OS_LINUX_INLINE_HPP

mercurial