annotate src/share/vm/runtime/hpi.hpp @ 1563:c18cbe5936b8

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