os_aix.inline.hpp revision 5969:666e6ce3976c
1/*
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2013 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26#ifndef OS_AIX_VM_OS_AIX_INLINE_HPP
27#define OS_AIX_VM_OS_AIX_INLINE_HPP
28
29#include "runtime/atomic.hpp"
30#include "runtime/os.hpp"
31#ifdef TARGET_OS_ARCH_aix_ppc
32# include "atomic_aix_ppc.inline.hpp"
33# include "orderAccess_aix_ppc.inline.hpp"
34#endif
35
36// System includes
37
38#include <unistd.h>
39#include <sys/socket.h>
40#include <sys/poll.h>
41#include <sys/ioctl.h>
42#include <netdb.h>
43
44// Defined in the system headers included above.
45#undef rem_size
46
47inline void* os::thread_local_storage_at(int index) {
48  return pthread_getspecific((pthread_key_t)index);
49}
50
51inline const char* os::file_separator() {
52  return "/";
53}
54
55inline const char* os::line_separator() {
56  return "\n";
57}
58
59inline const char* os::path_separator() {
60  return ":";
61}
62
63// File names are case-sensitive on windows only
64inline int os::file_name_strcmp(const char* s1, const char* s2) {
65  return strcmp(s1, s2);
66}
67
68inline bool os::obsolete_option(const JavaVMOption *option) {
69  return false;
70}
71
72inline bool os::uses_stack_guard_pages() {
73  return true;
74}
75
76inline bool os::allocate_stack_guard_pages() {
77  assert(uses_stack_guard_pages(), "sanity check");
78  return true;
79}
80
81
82// On Aix, reservations are made on a page by page basis, nothing to do.
83inline void os::pd_split_reserved_memory(char *base, size_t size,
84                                         size_t split, bool realloc) {
85}
86
87
88// Bang the shadow pages if they need to be touched to be mapped.
89inline void os::bang_stack_shadow_pages() {
90}
91
92inline void os::dll_unload(void *lib) {
93  ::dlclose(lib);
94}
95
96inline const int os::default_file_open_flags() { return 0;}
97
98inline DIR* os::opendir(const char* dirname)
99{
100  assert(dirname != NULL, "just checking");
101  return ::opendir(dirname);
102}
103
104inline int os::readdir_buf_size(const char *path)
105{
106  // according to aix sys/limits, NAME_MAX must be retrieved at runtime. */
107  const long my_NAME_MAX = pathconf(path, _PC_NAME_MAX);
108  return my_NAME_MAX + sizeof(dirent) + 1;
109}
110
111inline jlong os::lseek(int fd, jlong offset, int whence) {
112  return (jlong) ::lseek64(fd, offset, whence);
113}
114
115inline int os::fsync(int fd) {
116  return ::fsync(fd);
117}
118
119inline char* os::native_path(char *path) {
120  return path;
121}
122
123inline int os::ftruncate(int fd, jlong length) {
124  return ::ftruncate64(fd, length);
125}
126
127inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
128{
129  dirent* p;
130  int status;
131  assert(dirp != NULL, "just checking");
132
133  // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
134  // version. Here is the doc for this function:
135  // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
136
137  if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
138    errno = status;
139    return NULL;
140  } else
141    return p;
142}
143
144inline int os::closedir(DIR *dirp) {
145  assert(dirp != NULL, "argument is NULL");
146  return ::closedir(dirp);
147}
148
149// macros for restartable system calls
150
151#define RESTARTABLE(_cmd, _result) do { \
152    _result = _cmd; \
153  } while(((int)_result == OS_ERR) && (errno == EINTR))
154
155#define RESTARTABLE_RETURN_INT(_cmd) do { \
156  int _result; \
157  RESTARTABLE(_cmd, _result); \
158  return _result; \
159} while(false)
160
161// We don't have NUMA support on Aix, but we need this for compilation.
162inline bool os::numa_has_static_binding()   { ShouldNotReachHere(); return true; }
163inline bool os::numa_has_group_homing()     { ShouldNotReachHere(); return false;  }
164
165inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
166  size_t res;
167  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
168  return res;
169}
170
171inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
172  size_t res;
173  RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
174  return res;
175}
176
177inline int os::close(int fd) {
178  return ::close(fd);
179}
180
181inline int os::socket_close(int fd) {
182  return ::close(fd);
183}
184
185inline int os::socket(int domain, int type, int protocol) {
186  return ::socket(domain, type, protocol);
187}
188
189inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
190  RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
191}
192
193inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
194  RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
195}
196
197inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
198  return os::send(fd, buf, nBytes, flags);
199}
200
201inline int os::timeout(int fd, long timeout) {
202  julong prevtime,newtime;
203  struct timeval t;
204
205  gettimeofday(&t, NULL);
206  prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
207
208  for(;;) {
209    struct pollfd pfd;
210
211    pfd.fd = fd;
212    pfd.events = POLLIN | POLLERR;
213
214    int res = ::poll(&pfd, 1, timeout);
215
216    if (res == OS_ERR && errno == EINTR) {
217
218      // On Linux any value < 0 means "forever"
219
220      if(timeout >= 0) {
221        gettimeofday(&t, NULL);
222        newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
223        timeout -= newtime - prevtime;
224        if(timeout <= 0)
225          return OS_OK;
226        prevtime = newtime;
227      }
228    } else
229      return res;
230  }
231}
232
233inline int os::listen(int fd, int count) {
234  return ::listen(fd, count);
235}
236
237inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
238  RESTARTABLE_RETURN_INT(::connect(fd, him, len));
239}
240
241inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
242  // Linux doc says this can't return EINTR, unlike accept() on Solaris.
243  // But see attachListener_linux.cpp, LinuxAttachListener::dequeue().
244  return (int)::accept(fd, him, len);
245}
246
247inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
248                        sockaddr* from, socklen_t* fromlen) {
249  RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
250}
251
252inline int os::sendto(int fd, char* buf, size_t len, uint flags,
253                      struct sockaddr* to, socklen_t tolen) {
254  RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
255}
256
257inline int os::socket_shutdown(int fd, int howto) {
258  return ::shutdown(fd, howto);
259}
260
261inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
262  return ::bind(fd, him, len);
263}
264
265inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
266  return ::getsockname(fd, him, len);
267}
268
269inline int os::get_host_name(char* name, int namelen) {
270  return ::gethostname(name, namelen);
271}
272
273inline struct hostent* os::get_host_by_name(char* name) {
274  return ::gethostbyname(name);
275}
276
277inline int os::get_sock_opt(int fd, int level, int optname,
278                            char* optval, socklen_t* optlen) {
279  return ::getsockopt(fd, level, optname, optval, optlen);
280}
281
282inline int os::set_sock_opt(int fd, int level, int optname,
283                            const char* optval, socklen_t optlen) {
284  return ::setsockopt(fd, level, optname, optval, optlen);
285}
286#endif // OS_AIX_VM_OS_AIX_INLINE_HPP
287