duke@435: /* hseigel@4465: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef OS_LINUX_VM_OS_LINUX_INLINE_HPP stefank@2314: #define OS_LINUX_VM_OS_LINUX_INLINE_HPP stefank@2314: twisti@4318: #include "runtime/atomic.inline.hpp" stefank@2314: #include "runtime/os.hpp" twisti@4318: stefank@2314: #ifdef TARGET_OS_ARCH_linux_x86 stefank@2314: # include "orderAccess_linux_x86.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_ARCH_linux_sparc stefank@2314: # include "orderAccess_linux_sparc.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_ARCH_linux_zero stefank@2314: # include "orderAccess_linux_zero.inline.hpp" stefank@2314: #endif bobv@2508: #ifdef TARGET_OS_ARCH_linux_arm bobv@2508: # include "orderAccess_linux_arm.inline.hpp" bobv@2508: #endif bobv@2508: #ifdef TARGET_OS_ARCH_linux_ppc bobv@2508: # include "orderAccess_linux_ppc.inline.hpp" bobv@2508: #endif stefank@2314: ikrylov@2322: // System includes ikrylov@2322: ikrylov@2322: #include ikrylov@2322: #include ikrylov@2322: #include ikrylov@2322: #include ikrylov@2322: duke@435: inline void* os::thread_local_storage_at(int index) { duke@435: return pthread_getspecific((pthread_key_t)index); duke@435: } duke@435: duke@435: inline const char* os::file_separator() { duke@435: return "/"; duke@435: } duke@435: duke@435: inline const char* os::line_separator() { duke@435: return "\n"; duke@435: } duke@435: duke@435: inline const char* os::path_separator() { duke@435: return ":"; duke@435: } duke@435: duke@435: // File names are case-sensitive on windows only duke@435: inline int os::file_name_strcmp(const char* s1, const char* s2) { duke@435: return strcmp(s1, s2); duke@435: } duke@435: duke@435: inline bool os::obsolete_option(const JavaVMOption *option) { duke@435: return false; duke@435: } duke@435: duke@435: inline bool os::uses_stack_guard_pages() { duke@435: return true; duke@435: } duke@435: duke@435: inline bool os::allocate_stack_guard_pages() { duke@435: assert(uses_stack_guard_pages(), "sanity check"); duke@435: return true; duke@435: } duke@435: duke@435: duke@435: // On Linux, reservations are made on a page by page basis, nothing to do. zgu@3900: inline void os::pd_split_reserved_memory(char *base, size_t size, duke@435: size_t split, bool realloc) { duke@435: } duke@435: duke@435: duke@435: // Bang the shadow pages if they need to be touched to be mapped. duke@435: inline void os::bang_stack_shadow_pages() { duke@435: } duke@435: ikrylov@2322: inline void os::dll_unload(void *lib) { ikrylov@2322: ::dlclose(lib); ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline const int os::default_file_open_flags() { return 0;} ikrylov@2322: duke@435: inline DIR* os::opendir(const char* dirname) duke@435: { duke@435: assert(dirname != NULL, "just checking"); duke@435: return ::opendir(dirname); duke@435: } duke@435: duke@435: inline int os::readdir_buf_size(const char *path) duke@435: { duke@435: return NAME_MAX + sizeof(dirent) + 1; duke@435: } duke@435: ikrylov@2322: inline jlong os::lseek(int fd, jlong offset, int whence) { ikrylov@2322: return (jlong) ::lseek64(fd, offset, whence); ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline int os::fsync(int fd) { ikrylov@2322: return ::fsync(fd); ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline char* os::native_path(char *path) { ikrylov@2322: return path; ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline int os::ftruncate(int fd, jlong length) { ikrylov@2322: return ::ftruncate64(fd, length); ikrylov@2322: } ikrylov@2322: duke@435: inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) duke@435: { duke@435: dirent* p; duke@435: int status; duke@435: assert(dirp != NULL, "just checking"); duke@435: duke@435: // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX duke@435: // version. Here is the doc for this function: duke@435: // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html duke@435: duke@435: if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { duke@435: errno = status; duke@435: return NULL; duke@435: } else duke@435: return p; duke@435: } duke@435: ikrylov@2322: inline int os::closedir(DIR *dirp) { ikrylov@2322: assert(dirp != NULL, "argument is NULL"); duke@435: return ::closedir(dirp); duke@435: } duke@435: duke@435: // macros for restartable system calls duke@435: duke@435: #define RESTARTABLE(_cmd, _result) do { \ duke@435: _result = _cmd; \ duke@435: } while(((int)_result == OS_ERR) && (errno == EINTR)) duke@435: duke@435: #define RESTARTABLE_RETURN_INT(_cmd) do { \ duke@435: int _result; \ duke@435: RESTARTABLE(_cmd, _result); \ duke@435: return _result; \ duke@435: } while(false) iveresov@576: iveresov@576: inline bool os::numa_has_static_binding() { return true; } iveresov@576: inline bool os::numa_has_group_homing() { return false; } stefank@2314: ikrylov@2322: inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { ikrylov@2322: size_t res; ikrylov@2322: RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); ikrylov@2322: return res; ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { ikrylov@2322: size_t res; ikrylov@2322: RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); ikrylov@2322: return res; ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline int os::close(int fd) { ikrylov@2322: return ::close(fd); ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline int os::socket_close(int fd) { ikrylov@2322: return ::close(fd); ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline int os::socket(int domain, int type, int protocol) { ikrylov@2322: return ::socket(domain, type, protocol); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) { phh@3344: RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags)); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::send(int fd, char* buf, size_t nBytes, uint flags) { phh@3344: RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { ikrylov@2322: return os::send(fd, buf, nBytes, flags); ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline int os::timeout(int fd, long timeout) { ikrylov@2322: julong prevtime,newtime; ikrylov@2322: struct timeval t; ikrylov@2322: ikrylov@2322: gettimeofday(&t, NULL); ikrylov@2322: prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; ikrylov@2322: ikrylov@2322: for(;;) { ikrylov@2322: struct pollfd pfd; ikrylov@2322: ikrylov@2322: pfd.fd = fd; ikrylov@2322: pfd.events = POLLIN | POLLERR; ikrylov@2322: ikrylov@2322: int res = ::poll(&pfd, 1, timeout); ikrylov@2322: ikrylov@2322: if (res == OS_ERR && errno == EINTR) { ikrylov@2322: ikrylov@2322: // On Linux any value < 0 means "forever" ikrylov@2322: ikrylov@2322: if(timeout >= 0) { ikrylov@2322: gettimeofday(&t, NULL); ikrylov@2322: newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; ikrylov@2322: timeout -= newtime - prevtime; ikrylov@2322: if(timeout <= 0) ikrylov@2322: return OS_OK; ikrylov@2322: prevtime = newtime; ikrylov@2322: } ikrylov@2322: } else ikrylov@2322: return res; ikrylov@2322: } ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline int os::listen(int fd, int count) { ikrylov@2322: return ::listen(fd, count); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::connect(int fd, struct sockaddr* him, socklen_t len) { ikrylov@2322: RESTARTABLE_RETURN_INT(::connect(fd, him, len)); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) { phh@3344: // Linux doc says this can't return EINTR, unlike accept() on Solaris. phh@3344: // But see attachListener_linux.cpp, LinuxAttachListener::dequeue(). phh@3344: return (int)::accept(fd, him, len); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags, phh@3344: sockaddr* from, socklen_t* fromlen) { phh@3344: RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen)); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::sendto(int fd, char* buf, size_t len, uint flags, phh@3344: struct sockaddr* to, socklen_t tolen) { phh@3344: RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen)); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::socket_shutdown(int fd, int howto) { ikrylov@2322: return ::shutdown(fd, howto); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::bind(int fd, struct sockaddr* him, socklen_t len) { ikrylov@2322: return ::bind(fd, him, len); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) { phh@3344: return ::getsockname(fd, him, len); ikrylov@2322: } ikrylov@2322: phh@3344: inline int os::get_host_name(char* name, int namelen) { ikrylov@2322: return ::gethostname(name, namelen); ikrylov@2322: } ikrylov@2322: phh@3344: inline struct hostent* os::get_host_by_name(char* name) { ikrylov@2322: return ::gethostbyname(name); ikrylov@2322: } phh@3344: ikrylov@2322: inline int os::get_sock_opt(int fd, int level, int optname, phh@3344: char* optval, socklen_t* optlen) { phh@3344: return ::getsockopt(fd, level, optname, optval, optlen); ikrylov@2322: } ikrylov@2322: ikrylov@2322: inline int os::set_sock_opt(int fd, int level, int optname, phh@3344: const char* optval, socklen_t optlen) { ikrylov@2322: return ::setsockopt(fd, level, optname, optval, optlen); ikrylov@2322: } simonis@4675: stefank@2314: #endif // OS_LINUX_VM_OS_LINUX_INLINE_HPP