src/os/linux/vm/os_linux.inline.hpp

Tue, 09 Oct 2012 10:09:34 -0700

author
mikael
date
Tue, 09 Oct 2012 10:09:34 -0700
changeset 4153
b9a9ed0f8eeb
parent 3900
d2a62e0f25eb
child 4318
cd3d6a6b95d9
permissions
-rw-r--r--

7197424: update copyright year to match last edit in jdk8 hotspot repository
Summary: Update copyright year to 2012 for relevant files
Reviewed-by: dholmes, coleenp

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

mercurial