src/os/solaris/vm/hpi_solaris.hpp

Fri, 09 May 2008 16:34:08 +0400

author
iveresov
date
Fri, 09 May 2008 16:34:08 +0400
changeset 579
e3729351c946
parent 435
a61af66fc99e
child 657
2a1a77d3458f
permissions
-rw-r--r--

6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
Summary: Don't move tops of the chunks in ensure_parsibility(). Handle the situation with Solaris when a machine has a locality group with no memory.
Reviewed-by: apetrusenko, jcoomes, ysr

     1 /*
     2  * Copyright 1998-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 //
    26 // Parts of the HPI interface for which the HotSparc does not use the
    27 // HPI (because the interruptible IO mechanims used are different).
    28 //
    30 #include <sys/socket.h>
    31 #include <sys/poll.h>
    32 #include <sys/filio.h>
    33 #include <unistd.h>
    34 #include <netdb.h>
    35 #include <setjmp.h>
    37 // HPI_FileInterface
    39 // Many system calls can be interrupted by signals and must be restarted.
    40 // Restart support was added without disturbing the extent of thread
    41 // interruption support.
    43 inline int    hpi::close(int fd) {
    44   RESTARTABLE_RETURN_INT(::close(fd));
    45 }
    47 inline size_t hpi::read(int fd, void *buf, unsigned int nBytes) {
    48   INTERRUPTIBLE_RETURN_INT(::read(fd, buf, nBytes), os::Solaris::clear_interrupted);
    49 }
    51 inline size_t hpi::write(int fd, const void *buf, unsigned int nBytes) {
    52   INTERRUPTIBLE_RETURN_INT(::write(fd, buf, nBytes), os::Solaris::clear_interrupted);
    53 }
    56 // HPI_SocketInterface
    58 inline int    hpi::socket_close(int fd) {
    59   RESTARTABLE_RETURN_INT(::close(fd));
    60 }
    62 inline int    hpi::socket(int domain, int type, int protocol) {
    63   return ::socket(domain, type, protocol);
    64 }
    66 inline int    hpi::recv(int fd, char *buf, int nBytes, int flags) {
    67   INTERRUPTIBLE_RETURN_INT(::recv(fd, buf, nBytes, flags), os::Solaris::clear_interrupted);
    68 }
    70 inline int    hpi::send(int fd, char *buf, int nBytes, int flags) {
    71   INTERRUPTIBLE_RETURN_INT(::send(fd, buf, nBytes, flags), os::Solaris::clear_interrupted);
    72 }
    74 // As both poll and select can be interrupted by signals, we have to be
    75 // prepared to restart the system call after updating the timeout, unless
    76 // a poll() is done with timeout == -1, in which case we repeat with this
    77 // "wait forever" value.
    79 inline int    hpi::timeout(int fd, long timeout) {
    80   int res;
    81   struct timeval t;
    82   julong prevtime, newtime;
    83   static const char* aNull = 0;
    85   struct pollfd pfd;
    86   pfd.fd = fd;
    87   pfd.events = POLLIN;
    89   gettimeofday(&t, &aNull);
    90   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
    92   for(;;) {
    93     INTERRUPTIBLE_NORESTART(::poll(&pfd, 1, timeout), res, os::Solaris::clear_interrupted);
    94     if(res == OS_ERR && errno == EINTR) {
    95         if(timeout != -1) {
    96             gettimeofday(&t, &aNull);
    97             newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec /1000;
    98             timeout -= newtime - prevtime;
    99             if(timeout <= 0)
   100               return OS_OK;
   101             prevtime = newtime;
   102         }
   103     } else
   104       return res;
   105   }
   106 }
   108 inline int    hpi::listen(int fd, int count) {
   109   if (fd < 0)
   110     return OS_ERR;
   112   return ::listen(fd, count);
   113 }
   115 inline int
   116 hpi::connect(int fd, struct sockaddr *him, int len) {
   117   do {
   118     int _result;
   119     INTERRUPTIBLE_NORESTART(::connect(fd, him, len), _result,
   120                             os::Solaris::clear_interrupted);
   122     // Depending on when thread interruption is reset, _result could be
   123     // one of two values when errno == EINTR
   125     if (((_result == OS_INTRPT) || (_result == OS_ERR)) && (errno == EINTR)) {
   126       /* restarting a connect() changes its errno semantics */
   127       INTERRUPTIBLE(::connect(fd, him, len), _result,
   128                       os::Solaris::clear_interrupted);
   129       /* undo these changes */
   130       if (_result == OS_ERR) {
   131         if (errno == EALREADY) errno = EINPROGRESS; /* fall through */
   132         else if (errno == EISCONN) { errno = 0; return OS_OK; }
   133       }
   134     }
   135     return _result;
   136   } while(false);
   137 }
   139 inline int    hpi::accept(int fd, struct sockaddr *him, int *len) {
   140   if (fd < 0)
   141     return OS_ERR;
   142   INTERRUPTIBLE_RETURN_INT((int)::accept(fd, him, (socklen_t*) len), os::Solaris::clear_interrupted);
   143 }
   145 inline int    hpi::recvfrom(int fd, char *buf, int nBytes, int flags,
   146                             sockaddr *from, int *fromlen) {
   147   //%%note jvm_r11
   148   INTERRUPTIBLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen), os::Solaris::clear_interrupted);
   149 }
   151 inline int    hpi::sendto(int fd, char *buf, int len, int flags,
   152                           struct sockaddr *to, int tolen) {
   153   //%%note jvm_r11
   154   INTERRUPTIBLE_RETURN_INT((int)::sendto(fd, buf, len, (unsigned int) flags, to, tolen),os::Solaris::clear_interrupted);
   155 }
   157 inline int    hpi::socket_available(int fd, jint *pbytes) {
   158   if (fd < 0)
   159     return OS_OK;
   161   int ret;
   163   RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret);
   165   //%% note ioctl can return 0 when successful, JVM_SocketAvailable
   166   // is expected to return 0 on failure and 1 on success to the jdk.
   168   return (ret == OS_ERR) ? 0 : 1;
   169 }
   172 /*
   173 HPIDECL(socket_shutdown, "socket_shutdown", _socket, SocketShutdown,
   174         int, "%d",
   175         (int fd, int howto),
   176         ("fd = %d, howto = %d", fd, howto),
   177         (fd, howto));
   178         */
   179 inline int hpi::socket_shutdown(int fd, int howto){
   180   return ::shutdown(fd, howto);
   181 }
   183 /*
   184 HPIDECL(bind, "bind", _socket, Bind,
   185         int, "%d",
   186         (int fd, struct sockaddr *him, int len),
   187         ("fd = %d, him = %p, len = %d",
   188          fd, him, len),
   189         (fd, him, len));
   190 */
   191 inline int hpi::bind(int fd, struct sockaddr *him, int len){
   192   INTERRUPTIBLE_RETURN_INT_NORESTART(::bind(fd, him, len),os::Solaris::clear_interrupted);
   193 }
   195 /*
   196 HPIDECL(get_sock_name, "get_sock_name", _socket, GetSocketName,
   197         int, "%d",
   198         (int fd, struct sockaddr *him, int *len),
   199         ("fd = %d, him = %p, len = %p",
   200          fd, him, len),
   201         (fd, him, len));
   202         */
   203 inline int hpi::get_sock_name(int fd, struct sockaddr *him, int *len){
   204   return ::getsockname(fd, him, (socklen_t*) len);
   205 }
   207 /*
   208 HPIDECL(get_host_name, "get_host_name", _socket, GetHostName, int, "%d",
   209         (char *hostname, int namelen),
   210         ("hostname = %p, namelen = %d",
   211          hostname, namelen),
   212         (hostname, namelen));
   213         */
   214 inline int hpi::get_host_name(char* name, int namelen){
   215   return ::gethostname(name, namelen);
   216 }
   218 /*
   219 HPIDECL(get_sock_opt, "get_sock_opt", _socket, SocketGetOption, int, "%d",
   220         (int fd, int level, int optname, char *optval, int* optlen),
   221         ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %p",
   222          fd, level, optname, optval, optlen),
   223         (fd, level, optname, optval, optlen));
   224         */
   225 inline int hpi::get_sock_opt(int fd, int level, int optname,
   226                              char *optval, int* optlen){
   227   return ::getsockopt(fd, level, optname, optval, (socklen_t*) optlen);
   228 }
   230 /*
   231 HPIDECL(set_sock_opt, "set_sock_opt", _socket, SocketSetOption, int, "%d",
   232         (int fd, int level, int optname, const char *optval, int optlen),
   233         ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %d",
   234          fd, level, optname, optval, optlen),
   235         (fd, level, optname, optval, optlen));
   236         */
   237 inline int hpi::set_sock_opt(int fd, int level, int optname,
   238                              const char *optval, int optlen){
   239   return ::setsockopt(fd, level, optname, optval, optlen);
   240 }
   242 //Reconciliation History
   243 // 1.3 98/10/21 18:17:14 hpi_win32.hpp
   244 // 1.6 99/06/28 11:01:36 hpi_win32.hpp
   245 //End

mercurial