os_aix.inline.hpp revision 6683:08a2164660fb
1/*
2 * Copyright (c) 1999, 2014, 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/os.hpp"
30
31// System includes
32
33#include <unistd.h>
34#include <sys/socket.h>
35#include <sys/poll.h>
36#include <sys/ioctl.h>
37#include <netdb.h>
38
39// Defined in the system headers included above.
40#undef rem_size
41
42inline void* os::thread_local_storage_at(int index) {
43  return pthread_getspecific((pthread_key_t)index);
44}
45
46// File names are case-sensitive on windows only
47inline int os::file_name_strcmp(const char* s1, const char* s2) {
48  return strcmp(s1, s2);
49}
50
51inline bool os::obsolete_option(const JavaVMOption *option) {
52  return false;
53}
54
55inline bool os::uses_stack_guard_pages() {
56  return true;
57}
58
59inline bool os::allocate_stack_guard_pages() {
60  assert(uses_stack_guard_pages(), "sanity check");
61  return true;
62}
63
64
65// On Aix, reservations are made on a page by page basis, nothing to do.
66inline void os::pd_split_reserved_memory(char *base, size_t size,
67                                         size_t split, bool realloc) {
68}
69
70
71// Bang the shadow pages if they need to be touched to be mapped.
72inline void os::bang_stack_shadow_pages() {
73}
74
75inline void os::dll_unload(void *lib) {
76  ::dlclose(lib);
77}
78
79inline const int os::default_file_open_flags() { return 0;}
80
81inline DIR* os::opendir(const char* dirname)
82{
83  assert(dirname != NULL, "just checking");
84  return ::opendir(dirname);
85}
86
87inline int os::readdir_buf_size(const char *path)
88{
89  // according to aix sys/limits, NAME_MAX must be retrieved at runtime. */
90  const long my_NAME_MAX = pathconf(path, _PC_NAME_MAX);
91  return my_NAME_MAX + sizeof(dirent) + 1;
92}
93
94inline jlong os::lseek(int fd, jlong offset, int whence) {
95  return (jlong) ::lseek64(fd, offset, whence);
96}
97
98inline int os::fsync(int fd) {
99  return ::fsync(fd);
100}
101
102inline char* os::native_path(char *path) {
103  return path;
104}
105
106inline int os::ftruncate(int fd, jlong length) {
107  return ::ftruncate64(fd, length);
108}
109
110inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
111{
112  dirent* p;
113  int status;
114  assert(dirp != NULL, "just checking");
115
116  // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
117  // version. Here is the doc for this function:
118  // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
119
120  if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
121    errno = status;
122    return NULL;
123  } else
124    return p;
125}
126
127inline int os::closedir(DIR *dirp) {
128  assert(dirp != NULL, "argument is NULL");
129  return ::closedir(dirp);
130}
131
132// macros for restartable system calls
133
134#define RESTARTABLE(_cmd, _result) do { \
135    _result = _cmd; \
136  } while(((int)_result == OS_ERR) && (errno == EINTR))
137
138#define RESTARTABLE_RETURN_INT(_cmd) do { \
139  int _result; \
140  RESTARTABLE(_cmd, _result); \
141  return _result; \
142} while(false)
143
144// We don't have NUMA support on Aix, but we need this for compilation.
145inline bool os::numa_has_static_binding()   { ShouldNotReachHere(); return true; }
146inline bool os::numa_has_group_homing()     { ShouldNotReachHere(); return false;  }
147
148inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
149  size_t res;
150  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
151  return res;
152}
153
154inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
155  size_t res;
156  RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
157  return res;
158}
159
160inline int os::close(int fd) {
161  return ::close(fd);
162}
163
164inline int os::socket_close(int fd) {
165  return ::close(fd);
166}
167
168inline int os::socket(int domain, int type, int protocol) {
169  return ::socket(domain, type, protocol);
170}
171
172inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
173  RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
174}
175
176inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
177  RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
178}
179
180inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
181  return os::send(fd, buf, nBytes, flags);
182}
183
184inline int os::timeout(int fd, long timeout) {
185  julong prevtime,newtime;
186  struct timeval t;
187
188  gettimeofday(&t, NULL);
189  prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
190
191  for(;;) {
192    struct pollfd pfd;
193
194    pfd.fd = fd;
195    pfd.events = POLLIN | POLLERR;
196
197    int res = ::poll(&pfd, 1, timeout);
198
199    if (res == OS_ERR && errno == EINTR) {
200
201      // On Linux any value < 0 means "forever"
202
203      if(timeout >= 0) {
204        gettimeofday(&t, NULL);
205        newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
206        timeout -= newtime - prevtime;
207        if(timeout <= 0)
208          return OS_OK;
209        prevtime = newtime;
210      }
211    } else
212      return res;
213  }
214}
215
216inline int os::listen(int fd, int count) {
217  return ::listen(fd, count);
218}
219
220inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
221  RESTARTABLE_RETURN_INT(::connect(fd, him, len));
222}
223
224inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
225  // Linux doc says this can't return EINTR, unlike accept() on Solaris.
226  // But see attachListener_linux.cpp, LinuxAttachListener::dequeue().
227  return (int)::accept(fd, him, len);
228}
229
230inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
231                        sockaddr* from, socklen_t* fromlen) {
232  RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
233}
234
235inline int os::sendto(int fd, char* buf, size_t len, uint flags,
236                      struct sockaddr* to, socklen_t tolen) {
237  RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
238}
239
240inline int os::socket_shutdown(int fd, int howto) {
241  return ::shutdown(fd, howto);
242}
243
244inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
245  return ::bind(fd, him, len);
246}
247
248inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
249  return ::getsockname(fd, him, len);
250}
251
252inline int os::get_host_name(char* name, int namelen) {
253  return ::gethostname(name, namelen);
254}
255
256inline struct hostent* os::get_host_by_name(char* name) {
257  return ::gethostbyname(name);
258}
259
260inline int os::get_sock_opt(int fd, int level, int optname,
261                            char* optval, socklen_t* optlen) {
262  return ::getsockopt(fd, level, optname, optval, optlen);
263}
264
265inline int os::set_sock_opt(int fd, int level, int optname,
266                            const char* optval, socklen_t optlen) {
267  return ::setsockopt(fd, level, optname, optval, optlen);
268}
269
270inline bool os::supports_monotonic_clock() {
271  // mread_real_time() is monotonic on AIX (see os::javaTimeNanos() comments)
272  return true;
273}
274
275#endif // OS_AIX_VM_OS_AIX_INLINE_HPP
276