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