src/share/vm/runtime/hpi.hpp

Tue, 22 Sep 2009 21:12:37 -0600

author
dcubed
date
Tue, 22 Sep 2009 21:12:37 -0600
changeset 1414
87770dcf831b
parent 1279
bd02caa94611
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6876794: 4/4 sp07t002 hangs very intermittently
Summary: remove over locking by VMThread on "is thread suspended?" check
Reviewed-by: dholmes, acorn, andrew

duke@435 1 /*
xdono@1279 2 * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 //
duke@435 26 // C++ wrapper to HPI.
duke@435 27 //
duke@435 28
duke@435 29 class hpi : AllStatic {
duke@435 30
duke@435 31 private:
duke@435 32 static GetInterfaceFunc _get_interface;
duke@435 33 static HPI_FileInterface* _file;
duke@435 34 static HPI_SocketInterface* _socket;
duke@435 35 static HPI_LibraryInterface* _library;
duke@435 36 static HPI_SystemInterface* _system;
duke@435 37
duke@435 38 private:
duke@435 39 static void initialize_get_interface(vm_calls_t *callbacks);
duke@435 40
duke@435 41 public:
duke@435 42 // Load and initialize everything except sockets.
duke@435 43 static jint initialize();
duke@435 44
duke@435 45 // Socket library needs to be lazy intialized because eagerly
duke@435 46 // loading Winsock is known to cause "connect to your ISP"
duke@435 47 // dialog to show up. Or so goes the legend.
duke@435 48 static jint initialize_socket_library();
duke@435 49
duke@435 50 // HPI_FileInterface
duke@435 51 static inline char* native_path(char *path);
duke@435 52 static inline int file_type(const char *path);
duke@435 53 static inline int open(const char *name, int mode, int perm);
duke@435 54 static inline int close(int fd);
duke@435 55 static inline jlong lseek(int fd, jlong off, int whence);
duke@435 56 static inline int ftruncate(int fd, jlong length);
duke@435 57 static inline int fsync(int fd);
duke@435 58 static inline int available(int fd, jlong *bytes);
duke@435 59 static inline size_t read(int fd, void *buf, unsigned int nBytes);
duke@435 60 static inline size_t write(int fd, const void *buf, unsigned int nBytes);
duke@435 61 static inline int fsize(int fd, jlong *size);
duke@435 62
duke@435 63 // HPI_SocketInterface
duke@435 64 static inline int socket(int domain, int type, int protocol);
duke@435 65 static inline int socket_close(int fd);
duke@435 66 static inline int socket_shutdown(int fd, int howto);
duke@435 67 static inline int recv(int fd, char *buf, int nBytes, int flags);
duke@435 68 static inline int send(int fd, char *buf, int nBytes, int flags);
never@657 69 // Variant of send that doesn't support interruptible I/O
never@657 70 static inline int raw_send(int fd, char *buf, int nBytes, int flags);
duke@435 71 static inline int timeout(int fd, long timeout);
duke@435 72 static inline int listen(int fd, int count);
duke@435 73 static inline int connect(int fd, struct sockaddr *him, int len);
duke@435 74 static inline int bind(int fd, struct sockaddr *him, int len);
duke@435 75 static inline int accept(int fd, struct sockaddr *him, int *len);
duke@435 76 static inline int recvfrom(int fd, char *buf, int nbytes, int flags,
duke@435 77 struct sockaddr *from, int *fromlen);
duke@435 78 static inline int get_sock_name(int fd, struct sockaddr *him, int *len);
duke@435 79 static inline int sendto(int fd, char *buf, int len, int flags,
duke@435 80 struct sockaddr *to, int tolen);
duke@435 81 static inline int socket_available(int fd, jint *pbytes);
duke@435 82
duke@435 83 static inline int get_sock_opt(int fd, int level, int optname,
duke@435 84 char *optval, int* optlen);
duke@435 85 static inline int set_sock_opt(int fd, int level, int optname,
duke@435 86 const char *optval, int optlen);
duke@435 87 static inline int get_host_name(char* name, int namelen);
duke@435 88 static inline struct hostent* get_host_by_addr(const char* name, int len, int type);
duke@435 89 static inline struct hostent* get_host_by_name(char* name);
duke@435 90 static inline struct protoent* get_proto_by_name(char* name);
duke@435 91
duke@435 92 // HPI_LibraryInterface
phh@1126 93 static inline void dll_build_name(char *buf, int buf_len, const char* path,
duke@435 94 const char *name);
duke@435 95 static inline void* dll_load(const char *name, char *ebuf, int ebuflen);
duke@435 96 static inline void dll_unload(void *lib);
duke@435 97 static inline void* dll_lookup(void *lib, const char *name);
duke@435 98
duke@435 99 // HPI_SystemInterface
duke@435 100 static inline int lasterror(char *buf, int len);
duke@435 101 };
duke@435 102
duke@435 103 //
duke@435 104 // Macros that provide inline bodies for the functions.
duke@435 105 //
duke@435 106
duke@435 107 #define HPIDECL(name, names, intf, func, ret_type, ret_fmt, arg_type, arg_print, arg) \
duke@435 108 inline ret_type hpi::name arg_type { \
duke@435 109 if (TraceHPI) { \
duke@435 110 tty->print("hpi::" names "("); \
duke@435 111 tty->print arg_print ; \
duke@435 112 tty->print(") = "); \
duke@435 113 } \
duke@435 114 ret_type result = (*intf->func) arg ; \
duke@435 115 if (TraceHPI) { \
duke@435 116 tty->print_cr(ret_fmt, result); \
duke@435 117 } \
duke@435 118 return result; \
duke@435 119 }
duke@435 120
duke@435 121 // Macro to facilitate moving HPI functionality into the vm.
duke@435 122 // See bug 6348631. The only difference between this macro and
duke@435 123 // HPIDECL is that we call a vm method rather than use the HPI
duke@435 124 // transfer vector. Ultimately, we'll replace HPIDECL with
duke@435 125 // VM_HPIDECL for all hpi methods.
duke@435 126 #define VM_HPIDECL(name, names, func, ret_type, ret_fmt, arg_type,arg_print, arg) \
duke@435 127 inline ret_type hpi::name arg_type { \
duke@435 128 if (TraceHPI) { \
duke@435 129 tty->print("hpi::" names "("); \
duke@435 130 tty->print arg_print ; \
duke@435 131 tty->print(") = "); \
duke@435 132 } \
duke@435 133 ret_type result = func arg ; \
duke@435 134 if (TraceHPI) { \
duke@435 135 tty->print_cr(ret_fmt, result); \
duke@435 136 } \
duke@435 137 return result; \
duke@435 138 }
duke@435 139
phh@1126 140 #define VM_HPIDECL_VOID(name, names, func, arg_type, arg_print, arg) \
phh@1126 141 inline void hpi::name arg_type { \
phh@1126 142 if (TraceHPI) { \
phh@1126 143 tty->print("hpi::" names "("); \
phh@1126 144 tty->print arg_print; \
phh@1126 145 tty->print(") = "); \
phh@1126 146 } \
phh@1126 147 func arg; \
phh@1126 148 }
duke@435 149
duke@435 150 #define HPIDECL_VOID(name, names, intf, func, arg_type, arg_print, arg) \
duke@435 151 inline void hpi::name arg_type { \
duke@435 152 if (TraceHPI) { \
duke@435 153 tty->print("hpi::" names "("); \
duke@435 154 tty->print arg_print ; \
duke@435 155 tty->print_cr(") = void"); \
duke@435 156 } \
duke@435 157 (*intf->func) arg ; \
duke@435 158 }
duke@435 159
duke@435 160
duke@435 161 // The macro calls below realize into
duke@435 162 // inline char * hpi::native_path(...) { inlined_body; }
duke@435 163 // etc.
duke@435 164
duke@435 165 // HPI_FileInterface
duke@435 166
duke@435 167 HPIDECL(native_path, "native_path", _file, NativePath, char *, "%s",
duke@435 168 (char *path),
duke@435 169 ("path = %s", path),
duke@435 170 (path));
duke@435 171
duke@435 172 HPIDECL(file_type, "file_type", _file, FileType, int, "%d",
duke@435 173 (const char *path),
duke@435 174 ("path = %s", path),
duke@435 175 (path));
duke@435 176
duke@435 177 HPIDECL(open, "open", _file, Open, int, "%d",
duke@435 178 (const char *name, int mode, int perm),
duke@435 179 ("name = %s, mode = %d, perm = %d", name, mode, perm),
duke@435 180 (name, mode, perm));
duke@435 181
duke@435 182 HPIDECL(lseek, "seek", _file, Seek, jlong, "(a jlong)",
duke@435 183 (int fd, jlong off, int whence),
duke@435 184 ("fd = %d, off = (a jlong), whence = %d", fd, /* off, */ whence),
duke@435 185 (fd, off, whence));
duke@435 186
duke@435 187 HPIDECL(ftruncate, "ftruncate", _file, SetLength, int, "%d",
duke@435 188 (int fd, jlong length),
duke@435 189 ("fd = %d, length = (a jlong)", fd /*, length */),
duke@435 190 (fd, length));
duke@435 191
duke@435 192 HPIDECL(fsync, "fsync", _file, Sync, int, "%d",
duke@435 193 (int fd),
duke@435 194 ("fd = %d", fd),
duke@435 195 (fd));
duke@435 196
duke@435 197 HPIDECL(available, "available", _file, Available, int, "%d",
duke@435 198 (int fd, jlong *bytes),
duke@435 199 ("fd = %d, bytes = %p", fd, bytes),
duke@435 200 (fd, bytes));
duke@435 201
duke@435 202 HPIDECL(fsize, "fsize", _file, FileSizeFD, int, "%d",
duke@435 203 (int fd, jlong *size),
duke@435 204 ("fd = %d, size = %p", fd, size),
duke@435 205 (fd, size));
duke@435 206
duke@435 207 // HPI_LibraryInterface
phh@1126 208 VM_HPIDECL_VOID(dll_build_name, "dll_build_name", os::dll_build_name,
phh@1126 209 (char *buf, int buf_len, const char *path, const char *name),
phh@1126 210 ("buf = %p, buflen = %d, path = %s, name = %s",
phh@1126 211 buf, buf_len, path, name),
phh@1126 212 (buf, buf_len, path, name));
duke@435 213
duke@435 214 VM_HPIDECL(dll_load, "dll_load", os::dll_load,
duke@435 215 void *, "(void *)%p",
duke@435 216 (const char *name, char *ebuf, int ebuflen),
duke@435 217 ("name = %s, ebuf = %p, ebuflen = %d", name, ebuf, ebuflen),
duke@435 218 (name, ebuf, ebuflen));
duke@435 219
duke@435 220 HPIDECL_VOID(dll_unload, "dll_unload", _library, UnloadLibrary,
duke@435 221 (void *lib),
duke@435 222 ("lib = %p", lib),
duke@435 223 (lib));
duke@435 224
duke@435 225 HPIDECL(dll_lookup, "dll_lookup", _library, FindLibraryEntry, void *, "%p",
duke@435 226 (void *lib, const char *name),
duke@435 227 ("lib = %p, name = %s", lib, name),
duke@435 228 (lib, name));
duke@435 229
duke@435 230 // HPI_SystemInterface
duke@435 231 HPIDECL(lasterror, "lasterror", _system, GetLastErrorString, int, "%d",
duke@435 232 (char *buf, int len),
duke@435 233 ("buf = %p, len = %d", buf, len),
duke@435 234 (buf, len));

mercurial