os_aix.inline.hpp revision 6402:2377269bd73d
113546Sjulian/*
235509Sjb * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
313546Sjulian * Copyright 2012, 2013 SAP AG. All rights reserved.
413546Sjulian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
513546Sjulian *
613546Sjulian * This code is free software; you can redistribute it and/or modify it
713546Sjulian * under the terms of the GNU General Public License version 2 only, as
813546Sjulian * published by the Free Software Foundation.
913546Sjulian *
1013546Sjulian * This code is distributed in the hope that it will be useful, but WITHOUT
1113546Sjulian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1213546Sjulian * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1313546Sjulian * version 2 for more details (a copy is included in the LICENSE file that
1413546Sjulian * accompanied this code).
1513546Sjulian *
1613546Sjulian * You should have received a copy of the GNU General Public License version
1713546Sjulian * 2 along with this work; if not, write to the Free Software Foundation,
1813546Sjulian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1913546Sjulian *
2013546Sjulian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2113546Sjulian * or visit www.oracle.com if you need additional information or have any
2213546Sjulian * questions.
2349439Sdeischen *
2413546Sjulian */
2513546Sjulian
2613546Sjulian#ifndef OS_AIX_VM_OS_AIX_INLINE_HPP
2713546Sjulian#define OS_AIX_VM_OS_AIX_INLINE_HPP
2813546Sjulian
2913546Sjulian#include "runtime/atomic.inline.hpp"
3013546Sjulian#include "runtime/orderAccess.inline.hpp"
3113546Sjulian#include "runtime/os.hpp"
3250476Speter
3313546Sjulian// System includes
3451794Smarcel
3551794Smarcel#include <unistd.h>
3651794Smarcel#include <sys/socket.h>
3713546Sjulian#include <sys/poll.h>
3817706Sjulian#include <sys/ioctl.h>
3917706Sjulian#include <netdb.h>
4013546Sjulian
4113546Sjulian// Defined in the system headers included above.
4213546Sjulian#undef rem_size
4313546Sjulian
4413546Sjulianinline void* os::thread_local_storage_at(int index) {
4554138Sdeischen  return pthread_getspecific((pthread_key_t)index);
4654138Sdeischen}
4754138Sdeischen
4835509Sjbinline const char* os::file_separator() {
4948046Sjb  return "/";
5048046Sjb}
5148046Sjb
5248046Sjbinline const char* os::line_separator() {
5335509Sjb  return "\n";
5448046Sjb}
5513546Sjulian
5648046Sjbinline const char* os::path_separator() {
5735509Sjb  return ":";
5848046Sjb}
5935509Sjb
6048046Sjb// File names are case-sensitive on windows only
6148046Sjbinline int os::file_name_strcmp(const char* s1, const char* s2) {
6248046Sjb  return strcmp(s1, s2);
6348046Sjb}
6448046Sjb
6535509Sjbinline bool os::obsolete_option(const JavaVMOption *option) {
6648046Sjb  return false;
6748046Sjb}
6854138Sdeischen
6954138Sdeischeninline bool os::uses_stack_guard_pages() {
7054138Sdeischen  return true;
7135509Sjb}
7235509Sjb
7335509Sjbinline bool os::allocate_stack_guard_pages() {
7451794Smarcel  assert(uses_stack_guard_pages(), "sanity check");
7513546Sjulian  return true;
7648046Sjb}
7748046Sjb
7813546Sjulian
7935509Sjb// On Aix, reservations are made on a page by page basis, nothing to do.
8048046Sjbinline void os::pd_split_reserved_memory(char *base, size_t size,
8148046Sjb                                         size_t split, bool realloc) {
8213546Sjulian}
8348046Sjb
8448046Sjb
8513546Sjulian// Bang the shadow pages if they need to be touched to be mapped.
8648046Sjbinline void os::bang_stack_shadow_pages() {
8735509Sjb}
8844963Sjb
8944963Sjbinline void os::dll_unload(void *lib) {
9048046Sjb  ::dlclose(lib);
9144963Sjb}
9248046Sjb
9348046Sjbinline const int os::default_file_open_flags() { return 0;}
9444963Sjb
9548046Sjbinline DIR* os::opendir(const char* dirname)
9635509Sjb{
9735509Sjb  assert(dirname != NULL, "just checking");
9835509Sjb  return ::opendir(dirname);
9935509Sjb}
10035509Sjb
10135509Sjbinline int os::readdir_buf_size(const char *path)
10217706Sjulian{
10317706Sjulian  // according to aix sys/limits, NAME_MAX must be retrieved at runtime. */
10435509Sjb  const long my_NAME_MAX = pathconf(path, _PC_NAME_MAX);
10535509Sjb  return my_NAME_MAX + sizeof(dirent) + 1;
10635509Sjb}
10735509Sjb
10835509Sjbinline jlong os::lseek(int fd, jlong offset, int whence) {
10948046Sjb  return (jlong) ::lseek64(fd, offset, whence);
11048046Sjb}
11148046Sjb
11248046Sjbinline int os::fsync(int fd) {
11348046Sjb  return ::fsync(fd);
11448046Sjb}
11548046Sjb
11648046Sjbinline char* os::native_path(char *path) {
11748046Sjb  return path;
11848046Sjb}
11948046Sjb
12048046Sjbinline int os::ftruncate(int fd, jlong length) {
12148046Sjb  return ::ftruncate64(fd, length);
12248046Sjb}
12348046Sjb
12448046Sjbinline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
12548046Sjb{
12648046Sjb  dirent* p;
12748046Sjb  int status;
12848046Sjb  assert(dirp != NULL, "just checking");
12948046Sjb
13048046Sjb  // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
13148046Sjb  // version. Here is the doc for this function:
13248046Sjb  // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
13348046Sjb
13448046Sjb  if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
13548046Sjb    errno = status;
13648046Sjb    return NULL;
13748046Sjb  } else
13848046Sjb    return p;
13948046Sjb}
14048046Sjb
14148046Sjbinline int os::closedir(DIR *dirp) {
14248046Sjb  assert(dirp != NULL, "argument is NULL");
14348046Sjb  return ::closedir(dirp);
14448046Sjb}
14548046Sjb
14648046Sjb// macros for restartable system calls
14748046Sjb
14848046Sjb#define RESTARTABLE(_cmd, _result) do { \
14948046Sjb    _result = _cmd; \
15048046Sjb  } while(((int)_result == OS_ERR) && (errno == EINTR))
15148046Sjb
15248046Sjb#define RESTARTABLE_RETURN_INT(_cmd) do { \
15348046Sjb  int _result; \
15448046Sjb  RESTARTABLE(_cmd, _result); \
15548046Sjb  return _result; \
15648046Sjb} while(false)
15748046Sjb
15848046Sjb// We don't have NUMA support on Aix, but we need this for compilation.
15948046Sjbinline bool os::numa_has_static_binding()   { ShouldNotReachHere(); return true; }
16051794Smarcelinline bool os::numa_has_group_homing()     { ShouldNotReachHere(); return false;  }
16148046Sjb
16248046Sjbinline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
16348046Sjb  size_t res;
16454138Sdeischen  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
16548046Sjb  return res;
16648046Sjb}
16748046Sjb
16848046Sjbinline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
16948046Sjb  size_t res;
17048046Sjb  RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
17148046Sjb  return res;
17248046Sjb}
17348046Sjb
17448046Sjbinline int os::close(int fd) {
17548046Sjb  return ::close(fd);
17635509Sjb}
17735509Sjb
17835509Sjbinline int os::socket_close(int fd) {
17935509Sjb  return ::close(fd);
18017706Sjulian}
18117706Sjulian
18217706Sjulianinline int os::socket(int domain, int type, int protocol) {
18317706Sjulian  return ::socket(domain, type, protocol);
18417706Sjulian}
18517706Sjulian
18617706Sjulianinline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
18735509Sjb  RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
18835509Sjb}
18935509Sjb
19035509Sjbinline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
19135509Sjb  RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
19235509Sjb}
19335509Sjb
19417706Sjulianinline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
19517706Sjulian  return os::send(fd, buf, nBytes, flags);
19635509Sjb}
19717706Sjulian
19835509Sjbinline int os::timeout(int fd, long timeout) {
19935509Sjb  julong prevtime,newtime;
20039805Sjb  struct timeval t;
20135509Sjb
20235509Sjb  gettimeofday(&t, NULL);
20335509Sjb  prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
20435509Sjb
20535509Sjb  for(;;) {
20635509Sjb    struct pollfd pfd;
20748046Sjb
20835509Sjb    pfd.fd = fd;
20948046Sjb    pfd.events = POLLIN | POLLERR;
21035509Sjb
21113546Sjulian    int res = ::poll(&pfd, 1, timeout);
21239805Sjb
21354138Sdeischen    if (res == OS_ERR && errno == EINTR) {
21454138Sdeischen
21554138Sdeischen      // On Linux any value < 0 means "forever"
21654138Sdeischen
21754138Sdeischen      if(timeout >= 0) {
21854138Sdeischen        gettimeofday(&t, NULL);
21939805Sjb        newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
22054138Sdeischen        timeout -= newtime - prevtime;
22154138Sdeischen        if(timeout <= 0)
22248046Sjb          return OS_OK;
22348046Sjb        prevtime = newtime;
22448046Sjb      }
22548046Sjb    } else
22648046Sjb      return res;
22748046Sjb  }
22848046Sjb}
22948046Sjb
23039805Sjbinline int os::listen(int fd, int count) {
23139805Sjb  return ::listen(fd, count);
23239805Sjb}
23348046Sjb
23439805Sjbinline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
23539805Sjb  RESTARTABLE_RETURN_INT(::connect(fd, him, len));
23639805Sjb}
23739805Sjb
23839805Sjbinline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
23954138Sdeischen  // Linux doc says this can't return EINTR, unlike accept() on Solaris.
24054138Sdeischen  // But see attachListener_linux.cpp, LinuxAttachListener::dequeue().
24154138Sdeischen  return (int)::accept(fd, him, len);
24254138Sdeischen}
24354138Sdeischen
24439805Sjbinline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
24539805Sjb                        sockaddr* from, socklen_t* fromlen) {
24639805Sjb  RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
24739805Sjb}
24839805Sjb
24954138Sdeischeninline int os::sendto(int fd, char* buf, size_t len, uint flags,
25054138Sdeischen                      struct sockaddr* to, socklen_t tolen) {
25154138Sdeischen  RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
25254138Sdeischen}
25354138Sdeischen
25454138Sdeischeninline int os::socket_shutdown(int fd, int howto) {
25554138Sdeischen  return ::shutdown(fd, howto);
25639805Sjb}
25739805Sjb
25835509Sjbinline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
25954138Sdeischen  return ::bind(fd, him, len);
26054138Sdeischen}
26154138Sdeischen
26254138Sdeischeninline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
26354138Sdeischen  return ::getsockname(fd, him, len);
26454138Sdeischen}
26554138Sdeischen
26654138Sdeischeninline int os::get_host_name(char* name, int namelen) {
26754138Sdeischen  return ::gethostname(name, namelen);
26844963Sjb}
26944963Sjb
27054138Sdeischeninline struct hostent* os::get_host_by_name(char* name) {
27154138Sdeischen  return ::gethostbyname(name);
27254138Sdeischen}
27354138Sdeischen
27454138Sdeischeninline int os::get_sock_opt(int fd, int level, int optname,
27554138Sdeischen                            char* optval, socklen_t* optlen) {
27654138Sdeischen  return ::getsockopt(fd, level, optname, optval, optlen);
27754138Sdeischen}
27854138Sdeischen
27948046Sjbinline int os::set_sock_opt(int fd, int level, int optname,
28048046Sjb                            const char* optval, socklen_t optlen) {
28148046Sjb  return ::setsockopt(fd, level, optname, optval, optlen);
28248046Sjb}
28344963Sjb
28435509Sjbinline bool os::supports_monotonic_clock() {
28535509Sjb  // mread_real_time() is monotonic on AIX (see os::javaTimeNanos() comments)
28644963Sjb  return true;
28744963Sjb}
28844963Sjb
28944963Sjb#endif // OS_AIX_VM_OS_AIX_INLINE_HPP
29044963Sjb