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