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

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 9711
0f2fe7d37d8c
child 9756
2be326848943
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

     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_BSD_VM_OS_BSD_INLINE_HPP
    26 #define OS_BSD_VM_OS_BSD_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 #if !defined(__FreeBSD__) || __FreeBSD__ < 5
    71   // Since FreeBSD 4 uses malloc() for allocating the thread stack
    72   // there is no need to do anything extra to allocate the guard pages
    73   return false;
    74 #else
    75   // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks.
    76   // Must 'allocate' them or guard pages are ignored.
    77   return true;
    78 #endif
    79 }
    82 // On Bsd, reservations are made on a page by page basis, nothing to do.
    83 inline void os::pd_split_reserved_memory(char *base, size_t size,
    84                                       size_t split, bool realloc) {
    85 }
    88 // Bang the shadow pages if they need to be touched to be mapped.
    89 inline void os::bang_stack_shadow_pages() {
    90 }
    92 inline void os::dll_unload(void *lib) {
    93   ::dlclose(lib);
    94 }
    96 inline const int os::default_file_open_flags() { return 0;}
    98 inline jlong os::lseek(int fd, jlong offset, int whence) {
    99   return (jlong) ::lseek(fd, offset, whence);
   100 }
   102 inline int os::fsync(int fd) {
   103   return ::fsync(fd);
   104 }
   106 inline char* os::native_path(char *path) {
   107   return path;
   108 }
   110 inline int os::ftruncate(int fd, jlong length) {
   111   return ::ftruncate(fd, length);
   112 }
   114 // macros for restartable system calls
   116 #define RESTARTABLE(_cmd, _result) do { \
   117     _result = _cmd; \
   118   } while(((int)_result == OS_ERR) && (errno == EINTR))
   120 #define RESTARTABLE_RETURN_INT(_cmd) do { \
   121   int _result; \
   122   RESTARTABLE(_cmd, _result); \
   123   return _result; \
   124 } while(false)
   126 inline bool os::numa_has_static_binding()   { return true; }
   127 inline bool os::numa_has_group_homing()     { return false;  }
   129 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
   130   size_t res;
   131   RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
   132   return res;
   133 }
   135 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   136   size_t res;
   137   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
   138   return res;
   139 }
   141 inline int os::close(int fd) {
   142   return ::close(fd);
   143 }
   145 inline int os::socket_close(int fd) {
   146   return ::close(fd);
   147 }
   149 inline int os::socket(int domain, int type, int protocol) {
   150   return ::socket(domain, type, protocol);
   151 }
   153 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
   154   RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
   155 }
   157 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
   158   RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
   159 }
   161 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
   162   return os::send(fd, buf, nBytes, flags);
   163 }
   165 inline int os::timeout(int fd, long timeout) {
   166   julong prevtime,newtime;
   167   struct timeval t;
   169   gettimeofday(&t, NULL);
   170   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   172   for(;;) {
   173     struct pollfd pfd;
   175     pfd.fd = fd;
   176     pfd.events = POLLIN | POLLERR;
   178     int res = ::poll(&pfd, 1, timeout);
   180     if (res == OS_ERR && errno == EINTR) {
   182       // On Bsd any value < 0 means "forever"
   184       if(timeout >= 0) {
   185         gettimeofday(&t, NULL);
   186         newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   187         timeout -= newtime - prevtime;
   188         if(timeout <= 0)
   189           return OS_OK;
   190         prevtime = newtime;
   191       }
   192     } else
   193       return res;
   194   }
   195 }
   197 inline int os::listen(int fd, int count) {
   198   return ::listen(fd, count);
   199 }
   201 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
   202   RESTARTABLE_RETURN_INT(::connect(fd, him, len));
   203 }
   205 inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
   206   // At least OpenBSD and FreeBSD can return EINTR from accept.
   207   RESTARTABLE_RETURN_INT(::accept(fd, him, len));
   208 }
   210 inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
   211                          sockaddr* from, socklen_t* fromlen) {
   212   RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
   213 }
   215 inline int os::sendto(int fd, char* buf, size_t len, uint flags,
   216                       struct sockaddr *to, socklen_t tolen) {
   217   RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
   218 }
   220 inline int os::socket_shutdown(int fd, int howto) {
   221   return ::shutdown(fd, howto);
   222 }
   224 inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
   225   return ::bind(fd, him, len);
   226 }
   228 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
   229   return ::getsockname(fd, him, len);
   230 }
   232 inline int os::get_host_name(char* name, int namelen) {
   233   return ::gethostname(name, namelen);
   234 }
   236 inline struct hostent* os::get_host_by_name(char* name) {
   237   return ::gethostbyname(name);
   238 }
   240 inline int os::get_sock_opt(int fd, int level, int optname,
   241                             char *optval, socklen_t* optlen) {
   242   return ::getsockopt(fd, level, optname, optval, optlen);
   243 }
   245 inline int os::set_sock_opt(int fd, int level, int optname,
   246                             const char* optval, socklen_t optlen) {
   247   return ::setsockopt(fd, level, optname, optval, optlen);
   248 }
   250 #endif // OS_BSD_VM_OS_BSD_INLINE_HPP

mercurial