annotate src/share/vm/runtime/hpi.hpp @ 222:2a1a77d3458f

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