src/share/vm/runtime/hpi.hpp

Fri, 21 Nov 2008 08:09:11 -0800

author
coleenp
date
Fri, 21 Nov 2008 08:09:11 -0800
changeset 882
2b42b31e7928
parent 657
2a1a77d3458f
child 1126
956304450e80
permissions
-rw-r--r--

6676175: BigApps crash JVM Client VM (build 10.0-b22, mixed mode, sharing) with SIGSEGV (0xb)
Summary: Add test for biased locking epoch before walking own thread stack in case of rare race
Reviewed-by: phh, never

     1 /*
     2  * Copyright 1998-2006 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 // C++ wrapper to HPI.
    27 //
    29 class hpi : AllStatic {
    31 private:
    32   static GetInterfaceFunc       _get_interface;
    33   static HPI_FileInterface*     _file;
    34   static HPI_SocketInterface*   _socket;
    35   static HPI_LibraryInterface*  _library;
    36   static HPI_SystemInterface*   _system;
    38 private:
    39   static void initialize_get_interface(vm_calls_t *callbacks);
    41 public:
    42   // Load and initialize everything except sockets.
    43   static jint initialize();
    45   // Socket library needs to be lazy intialized because eagerly
    46   // loading Winsock is known to cause "connect to your ISP"
    47   // dialog to show up.  Or so goes the legend.
    48   static jint initialize_socket_library();
    50   // HPI_FileInterface
    51   static inline char*  native_path(char *path);
    52   static inline int    file_type(const char *path);
    53   static inline int    open(const char *name, int mode, int perm);
    54   static inline int    close(int fd);
    55   static inline jlong  lseek(int fd, jlong off, int whence);
    56   static inline int    ftruncate(int fd, jlong length);
    57   static inline int    fsync(int fd);
    58   static inline int    available(int fd, jlong *bytes);
    59   static inline size_t read(int fd, void *buf, unsigned int nBytes);
    60   static inline size_t write(int fd, const void *buf, unsigned int nBytes);
    61   static inline int    fsize(int fd, jlong *size);
    63   // HPI_SocketInterface
    64   static inline int    socket(int domain, int type, int protocol);
    65   static inline int    socket_close(int fd);
    66   static inline int    socket_shutdown(int fd, int howto);
    67   static inline int    recv(int fd, char *buf, int nBytes, int flags);
    68   static inline int    send(int fd, char *buf, int nBytes, int flags);
    69   // Variant of send that doesn't support interruptible I/O
    70   static inline int    raw_send(int fd, char *buf, int nBytes, int flags);
    71   static inline int    timeout(int fd, long timeout);
    72   static inline int    listen(int fd, int count);
    73   static inline int    connect(int fd, struct sockaddr *him, int len);
    74   static inline int    bind(int fd, struct sockaddr *him, int len);
    75   static inline int    accept(int fd, struct sockaddr *him, int *len);
    76   static inline int    recvfrom(int fd, char *buf, int nbytes, int flags,
    77                                 struct sockaddr *from, int *fromlen);
    78   static inline int    get_sock_name(int fd, struct sockaddr *him, int *len);
    79   static inline int    sendto(int fd, char *buf, int len, int flags,
    80                               struct sockaddr *to, int tolen);
    81   static inline int    socket_available(int fd, jint *pbytes);
    83   static inline int    get_sock_opt(int fd, int level, int optname,
    84                               char *optval, int* optlen);
    85   static inline int    set_sock_opt(int fd, int level, int optname,
    86                               const char *optval, int optlen);
    87   static inline int    get_host_name(char* name, int namelen);
    88   static inline struct hostent*  get_host_by_addr(const char* name, int len, int type);
    89   static inline struct hostent*  get_host_by_name(char* name);
    90   static inline struct protoent* get_proto_by_name(char* name);
    92   // HPI_LibraryInterface
    93   static inline void   dll_build_name(char *buf, int buf_len, char* path,
    94                                       const char *name);
    95   static inline void*  dll_load(const char *name, char *ebuf, int ebuflen);
    96   static inline void   dll_unload(void *lib);
    97   static inline void*  dll_lookup(void *lib, const char *name);
    99   // HPI_SystemInterface
   100   static inline int    lasterror(char *buf, int len);
   101 };
   103 //
   104 // Macros that provide inline bodies for the functions.
   105 //
   107 #define HPIDECL(name, names, intf, func, ret_type, ret_fmt, arg_type, arg_print, arg)   \
   108   inline ret_type hpi::name arg_type {        \
   109     if (TraceHPI) {                           \
   110       tty->print("hpi::" names "(");          \
   111       tty->print arg_print ;                  \
   112       tty->print(") = ");                     \
   113     }                                         \
   114     ret_type result = (*intf->func) arg ;     \
   115     if (TraceHPI) {                           \
   116       tty->print_cr(ret_fmt, result);         \
   117     }                                         \
   118     return result;                            \
   119   }
   121 // Macro to facilitate moving HPI functionality into the vm.
   122 // See bug 6348631.  The only difference between this macro and
   123 // HPIDECL is that we call a vm method rather than use the HPI
   124 // transfer vector.  Ultimately, we'll replace HPIDECL with
   125 // VM_HPIDECL for all hpi methods.
   126 #define VM_HPIDECL(name, names, func, ret_type, ret_fmt, arg_type,arg_print, arg)   \
   127   inline ret_type hpi::name arg_type {        \
   128     if (TraceHPI) {                           \
   129       tty->print("hpi::" names "(");          \
   130       tty->print arg_print ;                  \
   131       tty->print(") = ");                     \
   132     }                                         \
   133     ret_type result = func arg ;              \
   134     if (TraceHPI) {                           \
   135       tty->print_cr(ret_fmt, result);         \
   136     }                                         \
   137     return result;                            \
   138   }
   142 #define HPIDECL_VOID(name, names, intf, func, arg_type, arg_print, arg) \
   143   inline void hpi::name arg_type {            \
   144     if (TraceHPI) {                           \
   145       tty->print("hpi::" names "(");          \
   146       tty->print arg_print ;                  \
   147       tty->print_cr(") = void");              \
   148     }                                         \
   149     (*intf->func) arg ;                       \
   150   }
   153 // The macro calls below realize into
   154 //          inline char * hpi::native_path(...) {  inlined_body; }
   155 // etc.
   157 // HPI_FileInterface
   159 HPIDECL(native_path, "native_path", _file, NativePath, char *, "%s",
   160         (char *path),
   161         ("path = %s", path),
   162         (path));
   164 HPIDECL(file_type, "file_type", _file, FileType, int, "%d",
   165         (const char *path),
   166         ("path = %s", path),
   167         (path));
   169 HPIDECL(open, "open", _file, Open, int, "%d",
   170         (const char *name, int mode, int perm),
   171         ("name = %s, mode = %d, perm = %d", name, mode, perm),
   172         (name, mode, perm));
   174 HPIDECL(lseek, "seek", _file, Seek, jlong, "(a jlong)",
   175         (int fd, jlong off, int whence),
   176         ("fd = %d, off = (a jlong), whence = %d", fd, /* off, */ whence),
   177         (fd, off, whence));
   179 HPIDECL(ftruncate, "ftruncate", _file, SetLength, int, "%d",
   180         (int fd, jlong length),
   181         ("fd = %d, length = (a jlong)", fd /*, length */),
   182         (fd, length));
   184 HPIDECL(fsync, "fsync", _file, Sync, int, "%d",
   185         (int fd),
   186         ("fd = %d", fd),
   187         (fd));
   189 HPIDECL(available, "available", _file, Available, int, "%d",
   190         (int fd, jlong *bytes),
   191         ("fd = %d, bytes = %p", fd, bytes),
   192         (fd, bytes));
   194 HPIDECL(fsize, "fsize", _file, FileSizeFD, int, "%d",
   195         (int fd, jlong *size),
   196         ("fd = %d, size = %p", fd, size),
   197         (fd, size));
   199 // HPI_LibraryInterface
   200 HPIDECL_VOID(dll_build_name, "dll_build_name", _library, BuildLibName,
   201              (char *buf, int buf_len, char *path, const char *name),
   202              ("buf = %p, buflen = %d, path = %s, name = %s",
   203               buf, buf_len, path, name),
   204              (buf, buf_len, path, name));
   206 VM_HPIDECL(dll_load, "dll_load", os::dll_load,
   207         void *, "(void *)%p",
   208         (const char *name, char *ebuf, int ebuflen),
   209         ("name = %s, ebuf = %p, ebuflen = %d", name, ebuf, ebuflen),
   210         (name, ebuf, ebuflen));
   212 HPIDECL_VOID(dll_unload, "dll_unload", _library, UnloadLibrary,
   213              (void *lib),
   214              ("lib = %p", lib),
   215              (lib));
   217 HPIDECL(dll_lookup, "dll_lookup", _library, FindLibraryEntry, void *, "%p",
   218         (void *lib, const char *name),
   219         ("lib = %p, name = %s", lib, name),
   220         (lib, name));
   222 // HPI_SystemInterface
   223 HPIDECL(lasterror, "lasterror", _system, GetLastErrorString, int, "%d",
   224         (char *buf, int len),
   225         ("buf = %p, len = %d", buf, len),
   226         (buf, len));

mercurial