annotate src/os/linux/vm/hpi_linux.hpp @ 1552: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 2a1a77d3458f
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 222
diff changeset
2 * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 222
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 222
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 222
diff changeset
21 * questions.
0
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 // Because the interruptible IO has been dropped for HotSpot/Linux,
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // the following HPI interface is very different from HotSparc.
a61af66fc99e Initial load
duke
parents:
diff changeset
28 //
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #include <unistd.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #include <sys/socket.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #include <sys/poll.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
33 #include <sys/ioctl.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
34 #include <netdb.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // HPI_FileInterface
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 inline int hpi::close(int fd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 return ::close(fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
40 }
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 inline size_t hpi::read(int fd, void *buf, unsigned int nBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 size_t res;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 inline size_t hpi::write(int fd, const void *buf, unsigned int nBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 size_t res;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // HPI_SocketInterface
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 inline int hpi::socket_close(int fd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return ::close(fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 inline int hpi::socket(int domain, int type, int protocol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 return ::socket(domain, type, protocol);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 inline int hpi::recv(int fd, char *buf, int nBytes, int flags) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags));
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 inline int hpi::send(int fd, char *buf, int nBytes, int flags) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags));
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
222
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
73 inline int hpi::raw_send(int fd, char *buf, int nBytes, int flags) {
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
74 return send(fd, buf, nBytes, flags);
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
75 }
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
76
0
a61af66fc99e Initial load
duke
parents:
diff changeset
77 inline int hpi::timeout(int fd, long timeout) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 julong prevtime,newtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 struct timeval t;
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 gettimeofday(&t, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 for(;;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 struct pollfd pfd;
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 pfd.fd = fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 pfd.events = POLLIN | POLLERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int res = ::poll(&pfd, 1, timeout);
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (res == OS_ERR && errno == EINTR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // On Linux any value < 0 means "forever"
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if(timeout >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 gettimeofday(&t, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 timeout -= newtime - prevtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if(timeout <= 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return OS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 prevtime = newtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 inline int hpi::listen(int fd, int count) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return ::listen(fd, count);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 inline int hpi::connect(int fd, struct sockaddr *him, int len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 RESTARTABLE_RETURN_INT(::connect(fd, him, len));
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 inline int hpi::accept(int fd, struct sockaddr *him, int *len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // This cast is from int to unsigned int on linux. Since we
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // only pass the parameter "len" around the vm and don't try to
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // fetch it's value, this cast is safe for now. The java.net group
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // may need and want to change this interface someday if socklen_t goes
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // to 64 bits on some platform that we support.
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Linux doc says this can't return EINTR, unlike accept() on Solaris
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return ::accept(fd, him, (socklen_t *)len);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 inline int hpi::recvfrom(int fd, char *buf, int nBytes, int flags,
a61af66fc99e Initial load
duke
parents:
diff changeset
129 sockaddr *from, int *fromlen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen));
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 inline int hpi::sendto(int fd, char *buf, int len, int flags,
a61af66fc99e Initial load
duke
parents:
diff changeset
134 struct sockaddr *to, int tolen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen));
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 inline int hpi::socket_available(int fd, jint *pbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Linux doc says EINTR not returned, unlike Solaris
a61af66fc99e Initial load
duke
parents:
diff changeset
140 int ret = ::ioctl(fd, FIONREAD, pbytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 //%% note ioctl can return 0 when successful, JVM_SocketAvailable
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // is expected to return 0 on failure and 1 on success to the jdk.
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return (ret < 0) ? 0 : 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // following methods have been updated to avoid problems in
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // hpi's sockets calls based on sys_api_td.c (JDK1.3)
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
152 HPIDECL(socket_shutdown, "socket_shutdown", _socket, SocketShutdown,
a61af66fc99e Initial load
duke
parents:
diff changeset
153 int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
154 (int fd, int howto),
a61af66fc99e Initial load
duke
parents:
diff changeset
155 ("fd = %d, howto = %d", fd, howto),
a61af66fc99e Initial load
duke
parents:
diff changeset
156 (fd, howto));
a61af66fc99e Initial load
duke
parents:
diff changeset
157 */
a61af66fc99e Initial load
duke
parents:
diff changeset
158 inline int hpi::socket_shutdown(int fd, int howto){
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return ::shutdown(fd, howto);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
163 HPIDECL(bind, "bind", _socket, Bind,
a61af66fc99e Initial load
duke
parents:
diff changeset
164 int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
165 (int fd, struct sockaddr *him, int len),
a61af66fc99e Initial load
duke
parents:
diff changeset
166 ("fd = %d, him = %p, len = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
167 fd, him, len),
a61af66fc99e Initial load
duke
parents:
diff changeset
168 (fd, him, len));
a61af66fc99e Initial load
duke
parents:
diff changeset
169 */
a61af66fc99e Initial load
duke
parents:
diff changeset
170 inline int hpi::bind(int fd, struct sockaddr *him, int len){
a61af66fc99e Initial load
duke
parents:
diff changeset
171 return ::bind(fd, him, len);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
175 HPIDECL(get_sock_name, "get_sock_name", _socket, GetSocketName,
a61af66fc99e Initial load
duke
parents:
diff changeset
176 int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
177 (int fd, struct sockaddr *him, int *len),
a61af66fc99e Initial load
duke
parents:
diff changeset
178 ("fd = %d, him = %p, len = %p",
a61af66fc99e Initial load
duke
parents:
diff changeset
179 fd, him, len),
a61af66fc99e Initial load
duke
parents:
diff changeset
180 (fd, him, len));
a61af66fc99e Initial load
duke
parents:
diff changeset
181 */
a61af66fc99e Initial load
duke
parents:
diff changeset
182 inline int hpi::get_sock_name(int fd, struct sockaddr *him, int *len){
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return ::getsockname(fd, him, (socklen_t *)len);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
187 HPIDECL(get_host_name, "get_host_name", _socket, GetHostName, int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
188 (char *hostname, int namelen),
a61af66fc99e Initial load
duke
parents:
diff changeset
189 ("hostname = %p, namelen = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
190 hostname, namelen),
a61af66fc99e Initial load
duke
parents:
diff changeset
191 (hostname, namelen));
a61af66fc99e Initial load
duke
parents:
diff changeset
192 */
a61af66fc99e Initial load
duke
parents:
diff changeset
193 inline int hpi::get_host_name(char* name, int namelen){
a61af66fc99e Initial load
duke
parents:
diff changeset
194 return ::gethostname(name, namelen);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
198 HPIDECL(get_sock_opt, "get_sock_opt", _socket, SocketGetOption, int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
199 (int fd, int level, int optname, char *optval, int* optlen),
a61af66fc99e Initial load
duke
parents:
diff changeset
200 ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %p",
a61af66fc99e Initial load
duke
parents:
diff changeset
201 fd, level, optname, optval, optlen),
a61af66fc99e Initial load
duke
parents:
diff changeset
202 (fd, level, optname, optval, optlen));
a61af66fc99e Initial load
duke
parents:
diff changeset
203 */
a61af66fc99e Initial load
duke
parents:
diff changeset
204 inline int hpi::get_sock_opt(int fd, int level, int optname,
a61af66fc99e Initial load
duke
parents:
diff changeset
205 char *optval, int* optlen){
a61af66fc99e Initial load
duke
parents:
diff changeset
206 return ::getsockopt(fd, level, optname, optval, (socklen_t *)optlen);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
210 HPIDECL(set_sock_opt, "set_sock_opt", _socket, SocketSetOption, int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
211 (int fd, int level, int optname, const char *optval, int optlen),
a61af66fc99e Initial load
duke
parents:
diff changeset
212 ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
213 fd, level, optname, optval, optlen),
a61af66fc99e Initial load
duke
parents:
diff changeset
214 (fd, level, optname, optval, optlen));
a61af66fc99e Initial load
duke
parents:
diff changeset
215 */
a61af66fc99e Initial load
duke
parents:
diff changeset
216 inline int hpi::set_sock_opt(int fd, int level, int optname,
a61af66fc99e Initial load
duke
parents:
diff changeset
217 const char *optval, int optlen){
a61af66fc99e Initial load
duke
parents:
diff changeset
218 return ::setsockopt(fd, level, optname, optval, optlen);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // Reconciliation History
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // hpi_solaris.hpp 1.9 99/08/30 16:31:23
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // End