aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * Copyright 2012, 2013 SAP AG. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef OS_AIX_VM_OS_AIX_INLINE_HPP aoqi@0: #define OS_AIX_VM_OS_AIX_INLINE_HPP aoqi@0: aoqi@0: #include "runtime/atomic.hpp" aoqi@0: #include "runtime/os.hpp" aoqi@0: #ifdef TARGET_OS_ARCH_aix_ppc aoqi@0: # include "atomic_aix_ppc.inline.hpp" aoqi@0: # include "orderAccess_aix_ppc.inline.hpp" aoqi@0: #endif aoqi@0: aoqi@0: // System includes aoqi@0: aoqi@0: #include aoqi@0: #include aoqi@0: #include aoqi@0: #include aoqi@0: #include aoqi@0: aoqi@0: // Defined in the system headers included above. aoqi@0: #undef rem_size aoqi@0: aoqi@0: inline void* os::thread_local_storage_at(int index) { aoqi@0: return pthread_getspecific((pthread_key_t)index); aoqi@0: } aoqi@0: aoqi@0: inline const char* os::file_separator() { aoqi@0: return "/"; aoqi@0: } aoqi@0: aoqi@0: inline const char* os::line_separator() { aoqi@0: return "\n"; aoqi@0: } aoqi@0: aoqi@0: inline const char* os::path_separator() { aoqi@0: return ":"; aoqi@0: } aoqi@0: aoqi@0: // File names are case-sensitive on windows only aoqi@0: inline int os::file_name_strcmp(const char* s1, const char* s2) { aoqi@0: return strcmp(s1, s2); aoqi@0: } aoqi@0: aoqi@0: inline bool os::obsolete_option(const JavaVMOption *option) { aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: inline bool os::uses_stack_guard_pages() { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: inline bool os::allocate_stack_guard_pages() { aoqi@0: assert(uses_stack_guard_pages(), "sanity check"); aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // On Aix, reservations are made on a page by page basis, nothing to do. aoqi@0: inline void os::pd_split_reserved_memory(char *base, size_t size, aoqi@0: size_t split, bool realloc) { aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Bang the shadow pages if they need to be touched to be mapped. aoqi@0: inline void os::bang_stack_shadow_pages() { aoqi@0: } aoqi@0: aoqi@0: inline void os::dll_unload(void *lib) { aoqi@0: ::dlclose(lib); aoqi@0: } aoqi@0: aoqi@0: inline const int os::default_file_open_flags() { return 0;} aoqi@0: aoqi@0: inline DIR* os::opendir(const char* dirname) aoqi@0: { aoqi@0: assert(dirname != NULL, "just checking"); aoqi@0: return ::opendir(dirname); aoqi@0: } aoqi@0: aoqi@0: inline int os::readdir_buf_size(const char *path) aoqi@0: { aoqi@0: // according to aix sys/limits, NAME_MAX must be retrieved at runtime. */ aoqi@0: const long my_NAME_MAX = pathconf(path, _PC_NAME_MAX); aoqi@0: return my_NAME_MAX + sizeof(dirent) + 1; aoqi@0: } aoqi@0: aoqi@0: inline jlong os::lseek(int fd, jlong offset, int whence) { aoqi@0: return (jlong) ::lseek64(fd, offset, whence); aoqi@0: } aoqi@0: aoqi@0: inline int os::fsync(int fd) { aoqi@0: return ::fsync(fd); aoqi@0: } aoqi@0: aoqi@0: inline char* os::native_path(char *path) { aoqi@0: return path; aoqi@0: } aoqi@0: aoqi@0: inline int os::ftruncate(int fd, jlong length) { aoqi@0: return ::ftruncate64(fd, length); aoqi@0: } aoqi@0: aoqi@0: inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) aoqi@0: { aoqi@0: dirent* p; aoqi@0: int status; aoqi@0: assert(dirp != NULL, "just checking"); aoqi@0: aoqi@0: // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX aoqi@0: // version. Here is the doc for this function: aoqi@0: // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html aoqi@0: aoqi@0: if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { aoqi@0: errno = status; aoqi@0: return NULL; aoqi@0: } else aoqi@0: return p; aoqi@0: } aoqi@0: aoqi@0: inline int os::closedir(DIR *dirp) { aoqi@0: assert(dirp != NULL, "argument is NULL"); aoqi@0: return ::closedir(dirp); aoqi@0: } aoqi@0: aoqi@0: // macros for restartable system calls aoqi@0: aoqi@0: #define RESTARTABLE(_cmd, _result) do { \ aoqi@0: _result = _cmd; \ aoqi@0: } while(((int)_result == OS_ERR) && (errno == EINTR)) aoqi@0: aoqi@0: #define RESTARTABLE_RETURN_INT(_cmd) do { \ aoqi@0: int _result; \ aoqi@0: RESTARTABLE(_cmd, _result); \ aoqi@0: return _result; \ aoqi@0: } while(false) aoqi@0: aoqi@0: // We don't have NUMA support on Aix, but we need this for compilation. aoqi@0: inline bool os::numa_has_static_binding() { ShouldNotReachHere(); return true; } aoqi@0: inline bool os::numa_has_group_homing() { ShouldNotReachHere(); return false; } aoqi@0: aoqi@0: inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { aoqi@0: size_t res; aoqi@0: RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { aoqi@0: size_t res; aoqi@0: RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: inline int os::close(int fd) { aoqi@0: return ::close(fd); aoqi@0: } aoqi@0: aoqi@0: inline int os::socket_close(int fd) { aoqi@0: return ::close(fd); aoqi@0: } aoqi@0: aoqi@0: inline int os::socket(int domain, int type, int protocol) { aoqi@0: return ::socket(domain, type, protocol); aoqi@0: } aoqi@0: aoqi@0: inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) { aoqi@0: RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags)); aoqi@0: } aoqi@0: aoqi@0: inline int os::send(int fd, char* buf, size_t nBytes, uint flags) { aoqi@0: RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); aoqi@0: } aoqi@0: aoqi@0: inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { aoqi@0: return os::send(fd, buf, nBytes, flags); aoqi@0: } aoqi@0: aoqi@0: inline int os::timeout(int fd, long timeout) { aoqi@0: julong prevtime,newtime; aoqi@0: struct timeval t; aoqi@0: aoqi@0: gettimeofday(&t, NULL); aoqi@0: prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; aoqi@0: aoqi@0: for(;;) { aoqi@0: struct pollfd pfd; aoqi@0: aoqi@0: pfd.fd = fd; aoqi@0: pfd.events = POLLIN | POLLERR; aoqi@0: aoqi@0: int res = ::poll(&pfd, 1, timeout); aoqi@0: aoqi@0: if (res == OS_ERR && errno == EINTR) { aoqi@0: aoqi@0: // On Linux any value < 0 means "forever" aoqi@0: aoqi@0: if(timeout >= 0) { aoqi@0: gettimeofday(&t, NULL); aoqi@0: newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; aoqi@0: timeout -= newtime - prevtime; aoqi@0: if(timeout <= 0) aoqi@0: return OS_OK; aoqi@0: prevtime = newtime; aoqi@0: } aoqi@0: } else aoqi@0: return res; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: inline int os::listen(int fd, int count) { aoqi@0: return ::listen(fd, count); aoqi@0: } aoqi@0: aoqi@0: inline int os::connect(int fd, struct sockaddr* him, socklen_t len) { aoqi@0: RESTARTABLE_RETURN_INT(::connect(fd, him, len)); aoqi@0: } aoqi@0: aoqi@0: inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) { aoqi@0: // Linux doc says this can't return EINTR, unlike accept() on Solaris. aoqi@0: // But see attachListener_linux.cpp, LinuxAttachListener::dequeue(). aoqi@0: return (int)::accept(fd, him, len); aoqi@0: } aoqi@0: aoqi@0: inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags, aoqi@0: sockaddr* from, socklen_t* fromlen) { aoqi@0: RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen)); aoqi@0: } aoqi@0: aoqi@0: inline int os::sendto(int fd, char* buf, size_t len, uint flags, aoqi@0: struct sockaddr* to, socklen_t tolen) { aoqi@0: RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen)); aoqi@0: } aoqi@0: aoqi@0: inline int os::socket_shutdown(int fd, int howto) { aoqi@0: return ::shutdown(fd, howto); aoqi@0: } aoqi@0: aoqi@0: inline int os::bind(int fd, struct sockaddr* him, socklen_t len) { aoqi@0: return ::bind(fd, him, len); aoqi@0: } aoqi@0: aoqi@0: inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) { aoqi@0: return ::getsockname(fd, him, len); aoqi@0: } aoqi@0: aoqi@0: inline int os::get_host_name(char* name, int namelen) { aoqi@0: return ::gethostname(name, namelen); aoqi@0: } aoqi@0: aoqi@0: inline struct hostent* os::get_host_by_name(char* name) { aoqi@0: return ::gethostbyname(name); aoqi@0: } aoqi@0: aoqi@0: inline int os::get_sock_opt(int fd, int level, int optname, aoqi@0: char* optval, socklen_t* optlen) { aoqi@0: return ::getsockopt(fd, level, optname, optval, optlen); aoqi@0: } aoqi@0: aoqi@0: inline int os::set_sock_opt(int fd, int level, int optname, aoqi@0: const char* optval, socklen_t optlen) { aoqi@0: return ::setsockopt(fd, level, optname, optval, optlen); aoqi@0: } aoqi@0: #endif // OS_AIX_VM_OS_AIX_INLINE_HPP