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

Mon, 17 Jun 2019 16:41:38 +0100

author
andrew
date
Mon, 17 Jun 2019 16:41:38 +0100
changeset 9711
0f2fe7d37d8c
parent 6911
ce8f6bb717c9
child 9756
2be326848943
permissions
-rw-r--r--

8202353: os::readdir should use readdir instead of readdir_r
Summary: Summary: os::readdir uses POSIX readdir, drop buffer arg, fix JFR uses.
Reviewed-by: coleenp, tschatzl, bsrbnd, shade, phh

     1 /*
     2  * Copyright (c) 1999, 2013, 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.inline.hpp"
    29 #include "runtime/orderAccess.inline.hpp"
    30 #include "runtime/os.hpp"
    32 // System includes
    34 #include <unistd.h>
    35 #include <sys/socket.h>
    36 #include <sys/poll.h>
    37 #include <netdb.h>
    39 inline void* os::thread_local_storage_at(int index) {
    40   return pthread_getspecific((pthread_key_t)index);
    41 }
    43 inline const char* os::file_separator() {
    44   return "/";
    45 }
    47 inline const char* os::line_separator() {
    48   return "\n";
    49 }
    51 inline const char* os::path_separator() {
    52   return ":";
    53 }
    55 // File names are case-sensitive on windows only
    56 inline int os::file_name_strcmp(const char* s1, const char* s2) {
    57   return strcmp(s1, s2);
    58 }
    60 inline bool os::obsolete_option(const JavaVMOption *option) {
    61   return false;
    62 }
    64 inline bool os::uses_stack_guard_pages() {
    65   return true;
    66 }
    68 inline bool os::allocate_stack_guard_pages() {
    69   assert(uses_stack_guard_pages(), "sanity check");
    70   return true;
    71 }
    74 // On Linux, reservations are made on a page by page basis, nothing to do.
    75 inline void os::pd_split_reserved_memory(char *base, size_t size,
    76                                       size_t split, bool realloc) {
    77 }
    80 // Bang the shadow pages if they need to be touched to be mapped.
    81 inline void os::bang_stack_shadow_pages() {
    82 }
    84 inline void os::dll_unload(void *lib) {
    85   ::dlclose(lib);
    86 }
    88 inline const int os::default_file_open_flags() { return 0;}
    90 inline jlong os::lseek(int fd, jlong offset, int whence) {
    91   return (jlong) ::lseek64(fd, offset, whence);
    92 }
    94 inline int os::fsync(int fd) {
    95   return ::fsync(fd);
    96 }
    98 inline char* os::native_path(char *path) {
    99   return path;
   100 }
   102 inline int os::ftruncate(int fd, jlong length) {
   103   return ::ftruncate64(fd, length);
   104 }
   106 // macros for restartable system calls
   108 #define RESTARTABLE(_cmd, _result) do { \
   109     _result = _cmd; \
   110   } while(((int)_result == OS_ERR) && (errno == EINTR))
   112 #define RESTARTABLE_RETURN_INT(_cmd) do { \
   113   int _result; \
   114   RESTARTABLE(_cmd, _result); \
   115   return _result; \
   116 } while(false)
   118 inline bool os::numa_has_static_binding()   { return true; }
   119 inline bool os::numa_has_group_homing()     { return false;  }
   121 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
   122   size_t res;
   123   RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
   124   return res;
   125 }
   127 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   128   size_t res;
   129   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
   130   return res;
   131 }
   133 inline int os::close(int fd) {
   134   return ::close(fd);
   135 }
   137 inline int os::socket_close(int fd) {
   138   return ::close(fd);
   139 }
   141 inline int os::socket(int domain, int type, int protocol) {
   142   return ::socket(domain, type, protocol);
   143 }
   145 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
   146   RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
   147 }
   149 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
   150   RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
   151 }
   153 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
   154   return os::send(fd, buf, nBytes, flags);
   155 }
   157 inline int os::timeout(int fd, long timeout) {
   158   julong prevtime,newtime;
   159   struct timeval t;
   161   gettimeofday(&t, NULL);
   162   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   164   for(;;) {
   165     struct pollfd pfd;
   167     pfd.fd = fd;
   168     pfd.events = POLLIN | POLLERR;
   170     int res = ::poll(&pfd, 1, timeout);
   172     if (res == OS_ERR && errno == EINTR) {
   174       // On Linux any value < 0 means "forever"
   176       if(timeout >= 0) {
   177         gettimeofday(&t, NULL);
   178         newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   179         timeout -= newtime - prevtime;
   180         if(timeout <= 0)
   181           return OS_OK;
   182         prevtime = newtime;
   183       }
   184     } else
   185       return res;
   186   }
   187 }
   189 inline int os::listen(int fd, int count) {
   190   return ::listen(fd, count);
   191 }
   193 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
   194   RESTARTABLE_RETURN_INT(::connect(fd, him, len));
   195 }
   197 inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
   198   // Linux doc says this can't return EINTR, unlike accept() on Solaris.
   199   // But see attachListener_linux.cpp, LinuxAttachListener::dequeue().
   200   return (int)::accept(fd, him, len);
   201 }
   203 inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
   204                         sockaddr* from, socklen_t* fromlen) {
   205   RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
   206 }
   208 inline int os::sendto(int fd, char* buf, size_t len, uint flags,
   209                       struct sockaddr* to, socklen_t tolen) {
   210   RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
   211 }
   213 inline int os::socket_shutdown(int fd, int howto) {
   214   return ::shutdown(fd, howto);
   215 }
   217 inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
   218   return ::bind(fd, him, len);
   219 }
   221 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
   222   return ::getsockname(fd, him, len);
   223 }
   225 inline int os::get_host_name(char* name, int namelen) {
   226   return ::gethostname(name, namelen);
   227 }
   229 inline struct hostent* os::get_host_by_name(char* name) {
   230   return ::gethostbyname(name);
   231 }
   233 inline int os::get_sock_opt(int fd, int level, int optname,
   234                             char* optval, socklen_t* optlen) {
   235   return ::getsockopt(fd, level, optname, optval, optlen);
   236 }
   238 inline int os::set_sock_opt(int fd, int level, int optname,
   239                             const char* optval, socklen_t optlen) {
   240   return ::setsockopt(fd, level, optname, optval, optlen);
   241 }
   243 #endif // OS_LINUX_VM_OS_LINUX_INLINE_HPP

mercurial