src/share/vm/runtime/hpi.hpp

Thu, 10 Apr 2008 15:49:16 -0400

author
sbohne
date
Thu, 10 Apr 2008 15:49:16 -0400
changeset 528
c6ff24ceec1c
parent 435
a61af66fc99e
child 657
2a1a77d3458f
permissions
-rw-r--r--

6686407: Fix for 6666698 broke -XX:BiasedLockingStartupDelay=0
Summary: Stack allocated VM_EnableBiasedLocking op must be marked as such
Reviewed-by: xlu, acorn, never, dholmes

duke@435 1 /*
duke@435 2 * Copyright 1998-2006 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);
duke@435 69 static inline int timeout(int fd, long timeout);
duke@435 70 static inline int listen(int fd, int count);
duke@435 71 static inline int connect(int fd, struct sockaddr *him, int len);
duke@435 72 static inline int bind(int fd, struct sockaddr *him, int len);
duke@435 73 static inline int accept(int fd, struct sockaddr *him, int *len);
duke@435 74 static inline int recvfrom(int fd, char *buf, int nbytes, int flags,
duke@435 75 struct sockaddr *from, int *fromlen);
duke@435 76 static inline int get_sock_name(int fd, struct sockaddr *him, int *len);
duke@435 77 static inline int sendto(int fd, char *buf, int len, int flags,
duke@435 78 struct sockaddr *to, int tolen);
duke@435 79 static inline int socket_available(int fd, jint *pbytes);
duke@435 80
duke@435 81 static inline int get_sock_opt(int fd, int level, int optname,
duke@435 82 char *optval, int* optlen);
duke@435 83 static inline int set_sock_opt(int fd, int level, int optname,
duke@435 84 const char *optval, int optlen);
duke@435 85 static inline int get_host_name(char* name, int namelen);
duke@435 86 static inline struct hostent* get_host_by_addr(const char* name, int len, int type);
duke@435 87 static inline struct hostent* get_host_by_name(char* name);
duke@435 88 static inline struct protoent* get_proto_by_name(char* name);
duke@435 89
duke@435 90 // HPI_LibraryInterface
duke@435 91 static inline void dll_build_name(char *buf, int buf_len, char* path,
duke@435 92 const char *name);
duke@435 93 static inline void* dll_load(const char *name, char *ebuf, int ebuflen);
duke@435 94 static inline void dll_unload(void *lib);
duke@435 95 static inline void* dll_lookup(void *lib, const char *name);
duke@435 96
duke@435 97 // HPI_SystemInterface
duke@435 98 static inline int lasterror(char *buf, int len);
duke@435 99 };
duke@435 100
duke@435 101 //
duke@435 102 // Macros that provide inline bodies for the functions.
duke@435 103 //
duke@435 104
duke@435 105 #define HPIDECL(name, names, intf, func, ret_type, ret_fmt, arg_type, arg_print, arg) \
duke@435 106 inline ret_type hpi::name arg_type { \
duke@435 107 if (TraceHPI) { \
duke@435 108 tty->print("hpi::" names "("); \
duke@435 109 tty->print arg_print ; \
duke@435 110 tty->print(") = "); \
duke@435 111 } \
duke@435 112 ret_type result = (*intf->func) arg ; \
duke@435 113 if (TraceHPI) { \
duke@435 114 tty->print_cr(ret_fmt, result); \
duke@435 115 } \
duke@435 116 return result; \
duke@435 117 }
duke@435 118
duke@435 119 // Macro to facilitate moving HPI functionality into the vm.
duke@435 120 // See bug 6348631. The only difference between this macro and
duke@435 121 // HPIDECL is that we call a vm method rather than use the HPI
duke@435 122 // transfer vector. Ultimately, we'll replace HPIDECL with
duke@435 123 // VM_HPIDECL for all hpi methods.
duke@435 124 #define VM_HPIDECL(name, names, func, ret_type, ret_fmt, arg_type,arg_print, arg) \
duke@435 125 inline ret_type hpi::name arg_type { \
duke@435 126 if (TraceHPI) { \
duke@435 127 tty->print("hpi::" names "("); \
duke@435 128 tty->print arg_print ; \
duke@435 129 tty->print(") = "); \
duke@435 130 } \
duke@435 131 ret_type result = func arg ; \
duke@435 132 if (TraceHPI) { \
duke@435 133 tty->print_cr(ret_fmt, result); \
duke@435 134 } \
duke@435 135 return result; \
duke@435 136 }
duke@435 137
duke@435 138
duke@435 139
duke@435 140 #define HPIDECL_VOID(name, names, intf, func, arg_type, arg_print, arg) \
duke@435 141 inline void hpi::name arg_type { \
duke@435 142 if (TraceHPI) { \
duke@435 143 tty->print("hpi::" names "("); \
duke@435 144 tty->print arg_print ; \
duke@435 145 tty->print_cr(") = void"); \
duke@435 146 } \
duke@435 147 (*intf->func) arg ; \
duke@435 148 }
duke@435 149
duke@435 150
duke@435 151 // The macro calls below realize into
duke@435 152 // inline char * hpi::native_path(...) { inlined_body; }
duke@435 153 // etc.
duke@435 154
duke@435 155 // HPI_FileInterface
duke@435 156
duke@435 157 HPIDECL(native_path, "native_path", _file, NativePath, char *, "%s",
duke@435 158 (char *path),
duke@435 159 ("path = %s", path),
duke@435 160 (path));
duke@435 161
duke@435 162 HPIDECL(file_type, "file_type", _file, FileType, int, "%d",
duke@435 163 (const char *path),
duke@435 164 ("path = %s", path),
duke@435 165 (path));
duke@435 166
duke@435 167 HPIDECL(open, "open", _file, Open, int, "%d",
duke@435 168 (const char *name, int mode, int perm),
duke@435 169 ("name = %s, mode = %d, perm = %d", name, mode, perm),
duke@435 170 (name, mode, perm));
duke@435 171
duke@435 172 HPIDECL(lseek, "seek", _file, Seek, jlong, "(a jlong)",
duke@435 173 (int fd, jlong off, int whence),
duke@435 174 ("fd = %d, off = (a jlong), whence = %d", fd, /* off, */ whence),
duke@435 175 (fd, off, whence));
duke@435 176
duke@435 177 HPIDECL(ftruncate, "ftruncate", _file, SetLength, int, "%d",
duke@435 178 (int fd, jlong length),
duke@435 179 ("fd = %d, length = (a jlong)", fd /*, length */),
duke@435 180 (fd, length));
duke@435 181
duke@435 182 HPIDECL(fsync, "fsync", _file, Sync, int, "%d",
duke@435 183 (int fd),
duke@435 184 ("fd = %d", fd),
duke@435 185 (fd));
duke@435 186
duke@435 187 HPIDECL(available, "available", _file, Available, int, "%d",
duke@435 188 (int fd, jlong *bytes),
duke@435 189 ("fd = %d, bytes = %p", fd, bytes),
duke@435 190 (fd, bytes));
duke@435 191
duke@435 192 HPIDECL(fsize, "fsize", _file, FileSizeFD, int, "%d",
duke@435 193 (int fd, jlong *size),
duke@435 194 ("fd = %d, size = %p", fd, size),
duke@435 195 (fd, size));
duke@435 196
duke@435 197 // HPI_LibraryInterface
duke@435 198 HPIDECL_VOID(dll_build_name, "dll_build_name", _library, BuildLibName,
duke@435 199 (char *buf, int buf_len, char *path, const char *name),
duke@435 200 ("buf = %p, buflen = %d, path = %s, name = %s",
duke@435 201 buf, buf_len, path, name),
duke@435 202 (buf, buf_len, path, name));
duke@435 203
duke@435 204 VM_HPIDECL(dll_load, "dll_load", os::dll_load,
duke@435 205 void *, "(void *)%p",
duke@435 206 (const char *name, char *ebuf, int ebuflen),
duke@435 207 ("name = %s, ebuf = %p, ebuflen = %d", name, ebuf, ebuflen),
duke@435 208 (name, ebuf, ebuflen));
duke@435 209
duke@435 210 HPIDECL_VOID(dll_unload, "dll_unload", _library, UnloadLibrary,
duke@435 211 (void *lib),
duke@435 212 ("lib = %p", lib),
duke@435 213 (lib));
duke@435 214
duke@435 215 HPIDECL(dll_lookup, "dll_lookup", _library, FindLibraryEntry, void *, "%p",
duke@435 216 (void *lib, const char *name),
duke@435 217 ("lib = %p, name = %s", lib, name),
duke@435 218 (lib, name));
duke@435 219
duke@435 220 // HPI_SystemInterface
duke@435 221 HPIDECL(lasterror, "lasterror", _system, GetLastErrorString, int, "%d",
duke@435 222 (char *buf, int len),
duke@435 223 ("buf = %p, len = %d", buf, len),
duke@435 224 (buf, len));

mercurial