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