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

Sat, 12 Oct 2013 13:09:18 -0400

author
hseigel
date
Sat, 12 Oct 2013 13:09:18 -0400
changeset 5895
3e265ce4d2dd
parent 5264
e95fc50106cf
child 6876
710a3c8b516e
child 6911
ce8f6bb717c9
permissions
-rw-r--r--

8025942: os::Bsd::available_memory() needs implementation
Summary: Implement using the host_statistics64() api.
Reviewed-by: dsamersoff, morris, dholmes, coleenp, hseigel, dcubed
Contributed-by: gerard.ziemski@oracle.com

     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/os.hpp"
    31 #ifdef TARGET_OS_ARCH_bsd_x86
    32 # include "orderAccess_bsd_x86.inline.hpp"
    33 #endif
    34 #ifdef TARGET_OS_ARCH_bsd_zero
    35 # include "orderAccess_bsd_zero.inline.hpp"
    36 #endif
    38 // System includes
    40 #include <unistd.h>
    41 #include <sys/socket.h>
    42 #include <sys/poll.h>
    43 #include <netdb.h>
    45 inline void* os::thread_local_storage_at(int index) {
    46   return pthread_getspecific((pthread_key_t)index);
    47 }
    49 inline const char* os::file_separator() {
    50   return "/";
    51 }
    53 inline const char* os::line_separator() {
    54   return "\n";
    55 }
    57 inline const char* os::path_separator() {
    58   return ":";
    59 }
    61 // File names are case-sensitive on windows only
    62 inline int os::file_name_strcmp(const char* s1, const char* s2) {
    63   return strcmp(s1, s2);
    64 }
    66 inline bool os::obsolete_option(const JavaVMOption *option) {
    67   return false;
    68 }
    70 inline bool os::uses_stack_guard_pages() {
    71   return true;
    72 }
    74 inline bool os::allocate_stack_guard_pages() {
    75   assert(uses_stack_guard_pages(), "sanity check");
    76 #if !defined(__FreeBSD__) || __FreeBSD__ < 5
    77   // Since FreeBSD 4 uses malloc() for allocating the thread stack
    78   // there is no need to do anything extra to allocate the guard pages
    79   return false;
    80 #else
    81   // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks.
    82   // Must 'allocate' them or guard pages are ignored.
    83   return true;
    84 #endif
    85 }
    88 // On Bsd, reservations are made on a page by page basis, nothing to do.
    89 inline void os::pd_split_reserved_memory(char *base, size_t size,
    90                                       size_t split, bool realloc) {
    91 }
    94 // Bang the shadow pages if they need to be touched to be mapped.
    95 inline void os::bang_stack_shadow_pages() {
    96 }
    98 inline void os::dll_unload(void *lib) {
    99   ::dlclose(lib);
   100 }
   102 inline const int os::default_file_open_flags() { return 0;}
   104 inline DIR* os::opendir(const char* dirname)
   105 {
   106   assert(dirname != NULL, "just checking");
   107   return ::opendir(dirname);
   108 }
   110 inline int os::readdir_buf_size(const char *path)
   111 {
   112   return NAME_MAX + sizeof(dirent) + 1;
   113 }
   115 inline jlong os::lseek(int fd, jlong offset, int whence) {
   116   return (jlong) ::lseek(fd, offset, whence);
   117 }
   119 inline int os::fsync(int fd) {
   120   return ::fsync(fd);
   121 }
   123 inline char* os::native_path(char *path) {
   124   return path;
   125 }
   127 inline int os::ftruncate(int fd, jlong length) {
   128   return ::ftruncate(fd, length);
   129 }
   131 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
   132 {
   133   dirent* p;
   134   int status;
   135   assert(dirp != NULL, "just checking");
   137   // NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
   138   // version. Here is the doc for this function:
   139   // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
   141   if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
   142     errno = status;
   143     return NULL;
   144   } else
   145     return p;
   146 }
   148 inline int os::closedir(DIR *dirp) {
   149   assert(dirp != NULL, "argument is NULL");
   150   return ::closedir(dirp);
   151 }
   153 // macros for restartable system calls
   155 #define RESTARTABLE(_cmd, _result) do { \
   156     _result = _cmd; \
   157   } while(((int)_result == OS_ERR) && (errno == EINTR))
   159 #define RESTARTABLE_RETURN_INT(_cmd) do { \
   160   int _result; \
   161   RESTARTABLE(_cmd, _result); \
   162   return _result; \
   163 } while(false)
   165 inline bool os::numa_has_static_binding()   { return true; }
   166 inline bool os::numa_has_group_homing()     { return false;  }
   168 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
   169   size_t res;
   170   RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
   171   return res;
   172 }
   174 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   175   size_t res;
   176   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
   177   return res;
   178 }
   180 inline int os::close(int fd) {
   181   return ::close(fd);
   182 }
   184 inline int os::socket_close(int fd) {
   185   return ::close(fd);
   186 }
   188 inline int os::socket(int domain, int type, int protocol) {
   189   return ::socket(domain, type, protocol);
   190 }
   192 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
   193   RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
   194 }
   196 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
   197   RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
   198 }
   200 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
   201   return os::send(fd, buf, nBytes, flags);
   202 }
   204 inline int os::timeout(int fd, long timeout) {
   205   julong prevtime,newtime;
   206   struct timeval t;
   208   gettimeofday(&t, NULL);
   209   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   211   for(;;) {
   212     struct pollfd pfd;
   214     pfd.fd = fd;
   215     pfd.events = POLLIN | POLLERR;
   217     int res = ::poll(&pfd, 1, timeout);
   219     if (res == OS_ERR && errno == EINTR) {
   221       // On Bsd any value < 0 means "forever"
   223       if(timeout >= 0) {
   224         gettimeofday(&t, NULL);
   225         newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   226         timeout -= newtime - prevtime;
   227         if(timeout <= 0)
   228           return OS_OK;
   229         prevtime = newtime;
   230       }
   231     } else
   232       return res;
   233   }
   234 }
   236 inline int os::listen(int fd, int count) {
   237   return ::listen(fd, count);
   238 }
   240 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
   241   RESTARTABLE_RETURN_INT(::connect(fd, him, len));
   242 }
   244 inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
   245   // At least OpenBSD and FreeBSD can return EINTR from accept.
   246   RESTARTABLE_RETURN_INT(::accept(fd, him, len));
   247 }
   249 inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
   250                          sockaddr* from, socklen_t* fromlen) {
   251   RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
   252 }
   254 inline int os::sendto(int fd, char* buf, size_t len, uint flags,
   255                       struct sockaddr *to, socklen_t tolen) {
   256   RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
   257 }
   259 inline int os::socket_shutdown(int fd, int howto) {
   260   return ::shutdown(fd, howto);
   261 }
   263 inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
   264   return ::bind(fd, him, len);
   265 }
   267 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
   268   return ::getsockname(fd, him, len);
   269 }
   271 inline int os::get_host_name(char* name, int namelen) {
   272   return ::gethostname(name, namelen);
   273 }
   275 inline struct hostent* os::get_host_by_name(char* name) {
   276   return ::gethostbyname(name);
   277 }
   279 inline int os::get_sock_opt(int fd, int level, int optname,
   280                             char *optval, socklen_t* optlen) {
   281   return ::getsockopt(fd, level, optname, optval, optlen);
   282 }
   284 inline int os::set_sock_opt(int fd, int level, int optname,
   285                             const char* optval, socklen_t optlen) {
   286   return ::setsockopt(fd, level, optname, optval, optlen);
   287 }
   289 #endif // OS_BSD_VM_OS_BSD_INLINE_HPP

mercurial