comparison src/os/linux/vm/os_linux.inline.hpp @ 2044:06f017f7daa7

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Fri, 07 Jan 2011 18:18:08 +0100
parents 03e1b9fce89d
children b92c45f2bc75
comparison
equal deleted inserted replaced
1942:00bc9eaf0e24 2044:06f017f7daa7
1 /* 1 /*
2 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 #ifndef OS_LINUX_VM_OS_LINUX_INLINE_HPP
26 #define OS_LINUX_VM_OS_LINUX_INLINE_HPP
27
28 #include "runtime/atomic.hpp"
29 #include "runtime/os.hpp"
30 #ifdef TARGET_OS_ARCH_linux_x86
31 # include "atomic_linux_x86.inline.hpp"
32 # include "orderAccess_linux_x86.inline.hpp"
33 #endif
34 #ifdef TARGET_OS_ARCH_linux_sparc
35 # include "atomic_linux_sparc.inline.hpp"
36 # include "orderAccess_linux_sparc.inline.hpp"
37 #endif
38 #ifdef TARGET_OS_ARCH_linux_zero
39 # include "atomic_linux_zero.inline.hpp"
40 # include "orderAccess_linux_zero.inline.hpp"
41 #endif
42
43 // System includes
44
45 #include <unistd.h>
46 #include <sys/socket.h>
47 #include <sys/poll.h>
48 #include <netdb.h>
49
25 inline void* os::thread_local_storage_at(int index) { 50 inline void* os::thread_local_storage_at(int index) {
26 return pthread_getspecific((pthread_key_t)index); 51 return pthread_getspecific((pthread_key_t)index);
27 } 52 }
28 53
29 inline const char* os::file_separator() { 54 inline const char* os::file_separator() {
72 97
73 98
74 // Bang the shadow pages if they need to be touched to be mapped. 99 // Bang the shadow pages if they need to be touched to be mapped.
75 inline void os::bang_stack_shadow_pages() { 100 inline void os::bang_stack_shadow_pages() {
76 } 101 }
102
103 inline void os::dll_unload(void *lib) {
104 ::dlclose(lib);
105 }
106
107 inline const int os::default_file_open_flags() { return 0;}
77 108
78 inline DIR* os::opendir(const char* dirname) 109 inline DIR* os::opendir(const char* dirname)
79 { 110 {
80 assert(dirname != NULL, "just checking"); 111 assert(dirname != NULL, "just checking");
81 return ::opendir(dirname); 112 return ::opendir(dirname);
82 } 113 }
83 114
84 inline int os::readdir_buf_size(const char *path) 115 inline int os::readdir_buf_size(const char *path)
85 { 116 {
86 return NAME_MAX + sizeof(dirent) + 1; 117 return NAME_MAX + sizeof(dirent) + 1;
118 }
119
120 inline jlong os::lseek(int fd, jlong offset, int whence) {
121 return (jlong) ::lseek64(fd, offset, whence);
122 }
123
124 inline int os::fsync(int fd) {
125 return ::fsync(fd);
126 }
127
128 inline char* os::native_path(char *path) {
129 return path;
130 }
131
132 inline int os::ftruncate(int fd, jlong length) {
133 return ::ftruncate64(fd, length);
87 } 134 }
88 135
89 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) 136 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
90 { 137 {
91 dirent* p; 138 dirent* p;
101 return NULL; 148 return NULL;
102 } else 149 } else
103 return p; 150 return p;
104 } 151 }
105 152
106 inline int os::closedir(DIR *dirp) 153 inline int os::closedir(DIR *dirp) {
107 { 154 assert(dirp != NULL, "argument is NULL");
108 assert(dirp != NULL, "just checking");
109 return ::closedir(dirp); 155 return ::closedir(dirp);
110 } 156 }
111 157
112 // macros for restartable system calls 158 // macros for restartable system calls
113 159
121 return _result; \ 167 return _result; \
122 } while(false) 168 } while(false)
123 169
124 inline bool os::numa_has_static_binding() { return true; } 170 inline bool os::numa_has_static_binding() { return true; }
125 inline bool os::numa_has_group_homing() { return false; } 171 inline bool os::numa_has_group_homing() { return false; }
172
173 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
174 size_t res;
175 RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
176 return res;
177 }
178
179 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
180 size_t res;
181 RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
182 return res;
183 }
184
185 inline int os::close(int fd) {
186 return ::close(fd);
187 }
188
189 inline int os::socket_close(int fd) {
190 return ::close(fd);
191 }
192
193 inline int os::socket(int domain, int type, int protocol) {
194 return ::socket(domain, type, protocol);
195 }
196
197 inline int os::recv(int fd, char *buf, int nBytes, int flags) {
198 RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags));
199 }
200
201 inline int os::send(int fd, char *buf, int nBytes, int flags) {
202 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags));
203 }
204
205 inline int os::raw_send(int fd, char *buf, int nBytes, int flags) {
206 return os::send(fd, buf, nBytes, flags);
207 }
208
209 inline int os::timeout(int fd, long timeout) {
210 julong prevtime,newtime;
211 struct timeval t;
212
213 gettimeofday(&t, NULL);
214 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
215
216 for(;;) {
217 struct pollfd pfd;
218
219 pfd.fd = fd;
220 pfd.events = POLLIN | POLLERR;
221
222 int res = ::poll(&pfd, 1, timeout);
223
224 if (res == OS_ERR && errno == EINTR) {
225
226 // On Linux any value < 0 means "forever"
227
228 if(timeout >= 0) {
229 gettimeofday(&t, NULL);
230 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
231 timeout -= newtime - prevtime;
232 if(timeout <= 0)
233 return OS_OK;
234 prevtime = newtime;
235 }
236 } else
237 return res;
238 }
239 }
240
241 inline int os::listen(int fd, int count) {
242 return ::listen(fd, count);
243 }
244
245 inline int os::connect(int fd, struct sockaddr *him, int len) {
246 RESTARTABLE_RETURN_INT(::connect(fd, him, len));
247 }
248
249 inline int os::accept(int fd, struct sockaddr *him, int *len) {
250 // This cast is from int to unsigned int on linux. Since we
251 // only pass the parameter "len" around the vm and don't try to
252 // fetch it's value, this cast is safe for now. The java.net group
253 // may need and want to change this interface someday if socklen_t goes
254 // to 64 bits on some platform that we support.
255 // Linux doc says this can't return EINTR, unlike accept() on Solaris
256
257 return ::accept(fd, him, (socklen_t *)len);
258 }
259
260 inline int os::recvfrom(int fd, char *buf, int nBytes, int flags,
261 sockaddr *from, int *fromlen) {
262 RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen));
263 }
264
265 inline int os::sendto(int fd, char *buf, int len, int flags,
266 struct sockaddr *to, int tolen) {
267 RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen));
268 }
269
270 inline int os::socket_shutdown(int fd, int howto){
271 return ::shutdown(fd, howto);
272 }
273
274 inline int os::bind(int fd, struct sockaddr *him, int len){
275 return ::bind(fd, him, len);
276 }
277
278 inline int os::get_sock_name(int fd, struct sockaddr *him, int *len){
279 return ::getsockname(fd, him, (socklen_t *)len);
280 }
281
282 inline int os::get_host_name(char* name, int namelen){
283 return ::gethostname(name, namelen);
284 }
285
286 inline struct hostent* os::get_host_by_name(char* name) {
287 return ::gethostbyname(name);
288 }
289 inline int os::get_sock_opt(int fd, int level, int optname,
290 char *optval, int* optlen){
291 return ::getsockopt(fd, level, optname, optval, (socklen_t *)optlen);
292 }
293
294 inline int os::set_sock_opt(int fd, int level, int optname,
295 const char *optval, int optlen){
296 return ::setsockopt(fd, level, optname, optval, optlen);
297 }
298 #endif // OS_LINUX_VM_OS_LINUX_INLINE_HPP