annotate src/os/linux/vm/hpi_linux.hpp @ 79:82db0859acbe

6642862: Code cache allocation fails with large pages after 6588638 Reviewed-by: apetrusenko
author jcoomes
date Fri, 28 Mar 2008 23:35:42 -0700
parents a61af66fc99e
children 2a1a77d3458f
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 1999-2005 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 // 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
a61af66fc99e Initial load
duke
parents:
diff changeset
73 inline int hpi::timeout(int fd, long timeout) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 julong prevtime,newtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 struct timeval t;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 gettimeofday(&t, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 for(;;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 struct pollfd pfd;
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 pfd.fd = fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 pfd.events = POLLIN | POLLERR;
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 int res = ::poll(&pfd, 1, timeout);
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (res == OS_ERR && errno == EINTR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // On Linux any value < 0 means "forever"
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if(timeout >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 gettimeofday(&t, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 timeout -= newtime - prevtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if(timeout <= 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return OS_OK;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 prevtime = newtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 inline int hpi::listen(int fd, int count) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return ::listen(fd, count);
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::connect(int fd, struct sockaddr *him, int len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 RESTARTABLE_RETURN_INT(::connect(fd, him, len));
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::accept(int fd, struct sockaddr *him, int *len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // This cast is from int to unsigned int on linux. Since we
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // only pass the parameter "len" around the vm and don't try to
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // fetch it's value, this cast is safe for now. The java.net group
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // may need and want to change this interface someday if socklen_t goes
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // to 64 bits on some platform that we support.
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Linux doc says this can't return EINTR, unlike accept() on Solaris
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return ::accept(fd, him, (socklen_t *)len);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 inline int hpi::recvfrom(int fd, char *buf, int nBytes, int flags,
a61af66fc99e Initial load
duke
parents:
diff changeset
125 sockaddr *from, int *fromlen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen));
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 inline int hpi::sendto(int fd, char *buf, int len, int flags,
a61af66fc99e Initial load
duke
parents:
diff changeset
130 struct sockaddr *to, int tolen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen));
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 inline int hpi::socket_available(int fd, jint *pbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Linux doc says EINTR not returned, unlike Solaris
a61af66fc99e Initial load
duke
parents:
diff changeset
136 int ret = ::ioctl(fd, FIONREAD, pbytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 //%% note ioctl can return 0 when successful, JVM_SocketAvailable
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // is expected to return 0 on failure and 1 on success to the jdk.
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return (ret < 0) ? 0 : 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // following methods have been updated to avoid problems in
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // hpi's sockets calls based on sys_api_td.c (JDK1.3)
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
148 HPIDECL(socket_shutdown, "socket_shutdown", _socket, SocketShutdown,
a61af66fc99e Initial load
duke
parents:
diff changeset
149 int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
150 (int fd, int howto),
a61af66fc99e Initial load
duke
parents:
diff changeset
151 ("fd = %d, howto = %d", fd, howto),
a61af66fc99e Initial load
duke
parents:
diff changeset
152 (fd, howto));
a61af66fc99e Initial load
duke
parents:
diff changeset
153 */
a61af66fc99e Initial load
duke
parents:
diff changeset
154 inline int hpi::socket_shutdown(int fd, int howto){
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return ::shutdown(fd, howto);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
159 HPIDECL(bind, "bind", _socket, Bind,
a61af66fc99e Initial load
duke
parents:
diff changeset
160 int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
161 (int fd, struct sockaddr *him, int len),
a61af66fc99e Initial load
duke
parents:
diff changeset
162 ("fd = %d, him = %p, len = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
163 fd, him, len),
a61af66fc99e Initial load
duke
parents:
diff changeset
164 (fd, him, len));
a61af66fc99e Initial load
duke
parents:
diff changeset
165 */
a61af66fc99e Initial load
duke
parents:
diff changeset
166 inline int hpi::bind(int fd, struct sockaddr *him, int len){
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return ::bind(fd, him, len);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
171 HPIDECL(get_sock_name, "get_sock_name", _socket, GetSocketName,
a61af66fc99e Initial load
duke
parents:
diff changeset
172 int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
173 (int fd, struct sockaddr *him, int *len),
a61af66fc99e Initial load
duke
parents:
diff changeset
174 ("fd = %d, him = %p, len = %p",
a61af66fc99e Initial load
duke
parents:
diff changeset
175 fd, him, len),
a61af66fc99e Initial load
duke
parents:
diff changeset
176 (fd, him, len));
a61af66fc99e Initial load
duke
parents:
diff changeset
177 */
a61af66fc99e Initial load
duke
parents:
diff changeset
178 inline int hpi::get_sock_name(int fd, struct sockaddr *him, int *len){
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return ::getsockname(fd, him, (socklen_t *)len);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
183 HPIDECL(get_host_name, "get_host_name", _socket, GetHostName, int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
184 (char *hostname, int namelen),
a61af66fc99e Initial load
duke
parents:
diff changeset
185 ("hostname = %p, namelen = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
186 hostname, namelen),
a61af66fc99e Initial load
duke
parents:
diff changeset
187 (hostname, namelen));
a61af66fc99e Initial load
duke
parents:
diff changeset
188 */
a61af66fc99e Initial load
duke
parents:
diff changeset
189 inline int hpi::get_host_name(char* name, int namelen){
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return ::gethostname(name, namelen);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
194 HPIDECL(get_sock_opt, "get_sock_opt", _socket, SocketGetOption, int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
195 (int fd, int level, int optname, char *optval, int* optlen),
a61af66fc99e Initial load
duke
parents:
diff changeset
196 ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %p",
a61af66fc99e Initial load
duke
parents:
diff changeset
197 fd, level, optname, optval, optlen),
a61af66fc99e Initial load
duke
parents:
diff changeset
198 (fd, level, optname, optval, optlen));
a61af66fc99e Initial load
duke
parents:
diff changeset
199 */
a61af66fc99e Initial load
duke
parents:
diff changeset
200 inline int hpi::get_sock_opt(int fd, int level, int optname,
a61af66fc99e Initial load
duke
parents:
diff changeset
201 char *optval, int* optlen){
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return ::getsockopt(fd, level, optname, optval, (socklen_t *)optlen);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
206 HPIDECL(set_sock_opt, "set_sock_opt", _socket, SocketSetOption, int, "%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
207 (int fd, int level, int optname, const char *optval, int optlen),
a61af66fc99e Initial load
duke
parents:
diff changeset
208 ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
209 fd, level, optname, optval, optlen),
a61af66fc99e Initial load
duke
parents:
diff changeset
210 (fd, level, optname, optval, optlen));
a61af66fc99e Initial load
duke
parents:
diff changeset
211 */
a61af66fc99e Initial load
duke
parents:
diff changeset
212 inline int hpi::set_sock_opt(int fd, int level, int optname,
a61af66fc99e Initial load
duke
parents:
diff changeset
213 const char *optval, int optlen){
a61af66fc99e Initial load
duke
parents:
diff changeset
214 return ::setsockopt(fd, level, optname, optval, optlen);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Reconciliation History
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // hpi_solaris.hpp 1.9 99/08/30 16:31:23
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // End