Wed, 31 Jan 2018 19:24:57 -0500
8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * Copyright 2012, 2013 SAP AG. All rights reserved. |
aoqi@0 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 5 | * |
aoqi@0 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 8 | * published by the Free Software Foundation. |
aoqi@0 | 9 | * |
aoqi@0 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 14 | * accompanied this code). |
aoqi@0 | 15 | * |
aoqi@0 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 19 | * |
aoqi@0 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 22 | * questions. |
aoqi@0 | 23 | * |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | #ifndef OS_AIX_VM_OS_AIX_INLINE_HPP |
aoqi@0 | 27 | #define OS_AIX_VM_OS_AIX_INLINE_HPP |
aoqi@0 | 28 | |
goetz@6911 | 29 | #include "runtime/atomic.inline.hpp" |
goetz@6911 | 30 | #include "runtime/orderAccess.inline.hpp" |
aoqi@0 | 31 | #include "runtime/os.hpp" |
aoqi@0 | 32 | |
aoqi@0 | 33 | // System includes |
aoqi@0 | 34 | |
aoqi@0 | 35 | #include <unistd.h> |
aoqi@0 | 36 | #include <sys/socket.h> |
aoqi@0 | 37 | #include <sys/poll.h> |
aoqi@0 | 38 | #include <sys/ioctl.h> |
aoqi@0 | 39 | #include <netdb.h> |
aoqi@0 | 40 | |
aoqi@0 | 41 | // Defined in the system headers included above. |
aoqi@0 | 42 | #undef rem_size |
aoqi@0 | 43 | |
aoqi@0 | 44 | inline void* os::thread_local_storage_at(int index) { |
aoqi@0 | 45 | return pthread_getspecific((pthread_key_t)index); |
aoqi@0 | 46 | } |
aoqi@0 | 47 | |
aoqi@0 | 48 | inline const char* os::file_separator() { |
aoqi@0 | 49 | return "/"; |
aoqi@0 | 50 | } |
aoqi@0 | 51 | |
aoqi@0 | 52 | inline const char* os::line_separator() { |
aoqi@0 | 53 | return "\n"; |
aoqi@0 | 54 | } |
aoqi@0 | 55 | |
aoqi@0 | 56 | inline const char* os::path_separator() { |
aoqi@0 | 57 | return ":"; |
aoqi@0 | 58 | } |
aoqi@0 | 59 | |
aoqi@0 | 60 | // File names are case-sensitive on windows only |
aoqi@0 | 61 | inline int os::file_name_strcmp(const char* s1, const char* s2) { |
aoqi@0 | 62 | return strcmp(s1, s2); |
aoqi@0 | 63 | } |
aoqi@0 | 64 | |
aoqi@0 | 65 | inline bool os::obsolete_option(const JavaVMOption *option) { |
aoqi@0 | 66 | return false; |
aoqi@0 | 67 | } |
aoqi@0 | 68 | |
aoqi@0 | 69 | inline bool os::uses_stack_guard_pages() { |
aoqi@0 | 70 | return true; |
aoqi@0 | 71 | } |
aoqi@0 | 72 | |
aoqi@0 | 73 | inline bool os::allocate_stack_guard_pages() { |
aoqi@0 | 74 | assert(uses_stack_guard_pages(), "sanity check"); |
aoqi@0 | 75 | return true; |
aoqi@0 | 76 | } |
aoqi@0 | 77 | |
aoqi@0 | 78 | |
aoqi@0 | 79 | // On Aix, reservations are made on a page by page basis, nothing to do. |
aoqi@0 | 80 | inline void os::pd_split_reserved_memory(char *base, size_t size, |
aoqi@0 | 81 | size_t split, bool realloc) { |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | |
aoqi@0 | 85 | // Bang the shadow pages if they need to be touched to be mapped. |
aoqi@0 | 86 | inline void os::bang_stack_shadow_pages() { |
aoqi@0 | 87 | } |
aoqi@0 | 88 | |
aoqi@0 | 89 | inline void os::dll_unload(void *lib) { |
aoqi@0 | 90 | ::dlclose(lib); |
aoqi@0 | 91 | } |
aoqi@0 | 92 | |
aoqi@0 | 93 | inline const int os::default_file_open_flags() { return 0;} |
aoqi@0 | 94 | |
aoqi@0 | 95 | inline DIR* os::opendir(const char* dirname) |
aoqi@0 | 96 | { |
aoqi@0 | 97 | assert(dirname != NULL, "just checking"); |
aoqi@0 | 98 | return ::opendir(dirname); |
aoqi@0 | 99 | } |
aoqi@0 | 100 | |
aoqi@0 | 101 | inline int os::readdir_buf_size(const char *path) |
aoqi@0 | 102 | { |
aoqi@0 | 103 | // according to aix sys/limits, NAME_MAX must be retrieved at runtime. */ |
aoqi@0 | 104 | const long my_NAME_MAX = pathconf(path, _PC_NAME_MAX); |
aoqi@0 | 105 | return my_NAME_MAX + sizeof(dirent) + 1; |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | inline jlong os::lseek(int fd, jlong offset, int whence) { |
aoqi@0 | 109 | return (jlong) ::lseek64(fd, offset, whence); |
aoqi@0 | 110 | } |
aoqi@0 | 111 | |
aoqi@0 | 112 | inline int os::fsync(int fd) { |
aoqi@0 | 113 | return ::fsync(fd); |
aoqi@0 | 114 | } |
aoqi@0 | 115 | |
aoqi@0 | 116 | inline char* os::native_path(char *path) { |
aoqi@0 | 117 | return path; |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | inline int os::ftruncate(int fd, jlong length) { |
aoqi@0 | 121 | return ::ftruncate64(fd, length); |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) |
aoqi@0 | 125 | { |
aoqi@0 | 126 | dirent* p; |
aoqi@0 | 127 | int status; |
aoqi@0 | 128 | assert(dirp != NULL, "just checking"); |
aoqi@0 | 129 | |
aoqi@0 | 130 | // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX |
aoqi@0 | 131 | // version. Here is the doc for this function: |
aoqi@0 | 132 | // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html |
aoqi@0 | 133 | |
aoqi@0 | 134 | if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { |
aoqi@0 | 135 | errno = status; |
aoqi@0 | 136 | return NULL; |
aoqi@0 | 137 | } else |
aoqi@0 | 138 | return p; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | inline int os::closedir(DIR *dirp) { |
aoqi@0 | 142 | assert(dirp != NULL, "argument is NULL"); |
aoqi@0 | 143 | return ::closedir(dirp); |
aoqi@0 | 144 | } |
aoqi@0 | 145 | |
aoqi@0 | 146 | // macros for restartable system calls |
aoqi@0 | 147 | |
aoqi@0 | 148 | #define RESTARTABLE(_cmd, _result) do { \ |
aoqi@0 | 149 | _result = _cmd; \ |
aoqi@0 | 150 | } while(((int)_result == OS_ERR) && (errno == EINTR)) |
aoqi@0 | 151 | |
aoqi@0 | 152 | #define RESTARTABLE_RETURN_INT(_cmd) do { \ |
aoqi@0 | 153 | int _result; \ |
aoqi@0 | 154 | RESTARTABLE(_cmd, _result); \ |
aoqi@0 | 155 | return _result; \ |
aoqi@0 | 156 | } while(false) |
aoqi@0 | 157 | |
aoqi@0 | 158 | // We don't have NUMA support on Aix, but we need this for compilation. |
aoqi@0 | 159 | inline bool os::numa_has_static_binding() { ShouldNotReachHere(); return true; } |
aoqi@0 | 160 | inline bool os::numa_has_group_homing() { ShouldNotReachHere(); return false; } |
aoqi@0 | 161 | |
aoqi@0 | 162 | inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { |
aoqi@0 | 163 | size_t res; |
aoqi@0 | 164 | RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); |
aoqi@0 | 165 | return res; |
aoqi@0 | 166 | } |
aoqi@0 | 167 | |
aoqi@0 | 168 | inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { |
aoqi@0 | 169 | size_t res; |
aoqi@0 | 170 | RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); |
aoqi@0 | 171 | return res; |
aoqi@0 | 172 | } |
aoqi@0 | 173 | |
aoqi@0 | 174 | inline int os::close(int fd) { |
aoqi@0 | 175 | return ::close(fd); |
aoqi@0 | 176 | } |
aoqi@0 | 177 | |
aoqi@0 | 178 | inline int os::socket_close(int fd) { |
aoqi@0 | 179 | return ::close(fd); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | inline int os::socket(int domain, int type, int protocol) { |
aoqi@0 | 183 | return ::socket(domain, type, protocol); |
aoqi@0 | 184 | } |
aoqi@0 | 185 | |
aoqi@0 | 186 | inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) { |
aoqi@0 | 187 | RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags)); |
aoqi@0 | 188 | } |
aoqi@0 | 189 | |
aoqi@0 | 190 | inline int os::send(int fd, char* buf, size_t nBytes, uint flags) { |
aoqi@0 | 191 | RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); |
aoqi@0 | 192 | } |
aoqi@0 | 193 | |
aoqi@0 | 194 | inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { |
aoqi@0 | 195 | return os::send(fd, buf, nBytes, flags); |
aoqi@0 | 196 | } |
aoqi@0 | 197 | |
aoqi@0 | 198 | inline int os::timeout(int fd, long timeout) { |
aoqi@0 | 199 | julong prevtime,newtime; |
aoqi@0 | 200 | struct timeval t; |
aoqi@0 | 201 | |
aoqi@0 | 202 | gettimeofday(&t, NULL); |
aoqi@0 | 203 | prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; |
aoqi@0 | 204 | |
aoqi@0 | 205 | for(;;) { |
aoqi@0 | 206 | struct pollfd pfd; |
aoqi@0 | 207 | |
aoqi@0 | 208 | pfd.fd = fd; |
aoqi@0 | 209 | pfd.events = POLLIN | POLLERR; |
aoqi@0 | 210 | |
aoqi@0 | 211 | int res = ::poll(&pfd, 1, timeout); |
aoqi@0 | 212 | |
aoqi@0 | 213 | if (res == OS_ERR && errno == EINTR) { |
aoqi@0 | 214 | |
aoqi@0 | 215 | // On Linux any value < 0 means "forever" |
aoqi@0 | 216 | |
aoqi@0 | 217 | if(timeout >= 0) { |
aoqi@0 | 218 | gettimeofday(&t, NULL); |
aoqi@0 | 219 | newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; |
aoqi@0 | 220 | timeout -= newtime - prevtime; |
aoqi@0 | 221 | if(timeout <= 0) |
aoqi@0 | 222 | return OS_OK; |
aoqi@0 | 223 | prevtime = newtime; |
aoqi@0 | 224 | } |
aoqi@0 | 225 | } else |
aoqi@0 | 226 | return res; |
aoqi@0 | 227 | } |
aoqi@0 | 228 | } |
aoqi@0 | 229 | |
aoqi@0 | 230 | inline int os::listen(int fd, int count) { |
aoqi@0 | 231 | return ::listen(fd, count); |
aoqi@0 | 232 | } |
aoqi@0 | 233 | |
aoqi@0 | 234 | inline int os::connect(int fd, struct sockaddr* him, socklen_t len) { |
aoqi@0 | 235 | RESTARTABLE_RETURN_INT(::connect(fd, him, len)); |
aoqi@0 | 236 | } |
aoqi@0 | 237 | |
aoqi@0 | 238 | inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) { |
aoqi@0 | 239 | // Linux doc says this can't return EINTR, unlike accept() on Solaris. |
aoqi@0 | 240 | // But see attachListener_linux.cpp, LinuxAttachListener::dequeue(). |
aoqi@0 | 241 | return (int)::accept(fd, him, len); |
aoqi@0 | 242 | } |
aoqi@0 | 243 | |
aoqi@0 | 244 | inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags, |
aoqi@0 | 245 | sockaddr* from, socklen_t* fromlen) { |
aoqi@0 | 246 | RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen)); |
aoqi@0 | 247 | } |
aoqi@0 | 248 | |
aoqi@0 | 249 | inline int os::sendto(int fd, char* buf, size_t len, uint flags, |
aoqi@0 | 250 | struct sockaddr* to, socklen_t tolen) { |
aoqi@0 | 251 | RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen)); |
aoqi@0 | 252 | } |
aoqi@0 | 253 | |
aoqi@0 | 254 | inline int os::socket_shutdown(int fd, int howto) { |
aoqi@0 | 255 | return ::shutdown(fd, howto); |
aoqi@0 | 256 | } |
aoqi@0 | 257 | |
aoqi@0 | 258 | inline int os::bind(int fd, struct sockaddr* him, socklen_t len) { |
aoqi@0 | 259 | return ::bind(fd, him, len); |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) { |
aoqi@0 | 263 | return ::getsockname(fd, him, len); |
aoqi@0 | 264 | } |
aoqi@0 | 265 | |
aoqi@0 | 266 | inline int os::get_host_name(char* name, int namelen) { |
aoqi@0 | 267 | return ::gethostname(name, namelen); |
aoqi@0 | 268 | } |
aoqi@0 | 269 | |
aoqi@0 | 270 | inline struct hostent* os::get_host_by_name(char* name) { |
aoqi@0 | 271 | return ::gethostbyname(name); |
aoqi@0 | 272 | } |
aoqi@0 | 273 | |
aoqi@0 | 274 | inline int os::get_sock_opt(int fd, int level, int optname, |
aoqi@0 | 275 | char* optval, socklen_t* optlen) { |
aoqi@0 | 276 | return ::getsockopt(fd, level, optname, optval, optlen); |
aoqi@0 | 277 | } |
aoqi@0 | 278 | |
aoqi@0 | 279 | inline int os::set_sock_opt(int fd, int level, int optname, |
aoqi@0 | 280 | const char* optval, socklen_t optlen) { |
aoqi@0 | 281 | return ::setsockopt(fd, level, optname, optval, optlen); |
aoqi@0 | 282 | } |
aoqi@0 | 283 | #endif // OS_AIX_VM_OS_AIX_INLINE_HPP |