Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/linux/vm/os_linux.inline.hpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef OS_LINUX_VM_OS_LINUX_INLINE_HPP25#define OS_LINUX_VM_OS_LINUX_INLINE_HPP2627#include "runtime/atomic.inline.hpp"28#include "runtime/orderAccess.inline.hpp"29#include "runtime/os.hpp"3031// System includes3233#include <unistd.h>34#include <sys/socket.h>35#include <sys/poll.h>36#include <netdb.h>3738inline void* os::thread_local_storage_at(int index) {39return pthread_getspecific((pthread_key_t)index);40}4142inline const char* os::file_separator() {43return "/";44}4546inline const char* os::line_separator() {47return "\n";48}4950inline const char* os::path_separator() {51return ":";52}5354// File names are case-sensitive on windows only55inline int os::file_name_strcmp(const char* s1, const char* s2) {56return strcmp(s1, s2);57}5859inline bool os::obsolete_option(const JavaVMOption *option) {60return false;61}6263inline bool os::uses_stack_guard_pages() {64return true;65}6667inline bool os::allocate_stack_guard_pages() {68assert(uses_stack_guard_pages(), "sanity check");69return true;70}717273// On Linux, reservations are made on a page by page basis, nothing to do.74inline void os::pd_split_reserved_memory(char *base, size_t size,75size_t split, bool realloc) {76}777879// Bang the shadow pages if they need to be touched to be mapped.80inline void os::bang_stack_shadow_pages() {81}8283inline void os::dll_unload(void *lib) {84::dlclose(lib);85}8687inline const int os::default_file_open_flags() { return 0;}8889inline jlong os::lseek(int fd, jlong offset, int whence) {90return (jlong) ::lseek64(fd, offset, whence);91}9293inline int os::fsync(int fd) {94return ::fsync(fd);95}9697inline char* os::native_path(char *path) {98return path;99}100101inline int os::ftruncate(int fd, jlong length) {102return ::ftruncate64(fd, length);103}104105// macros for restartable system calls106107#define RESTARTABLE(_cmd, _result) do { \108_result = _cmd; \109} while(((int)_result == OS_ERR) && (errno == EINTR))110111#define RESTARTABLE_RETURN_INT(_cmd) do { \112int _result; \113RESTARTABLE(_cmd, _result); \114return _result; \115} while(false)116117inline bool os::numa_has_static_binding() { return true; }118inline bool os::numa_has_group_homing() { return false; }119120inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {121size_t res;122RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);123return res;124}125126inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {127size_t res;128RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);129return res;130}131132inline int os::close(int fd) {133return ::close(fd);134}135136inline int os::socket_close(int fd) {137return ::close(fd);138}139140inline int os::socket(int domain, int type, int protocol) {141return ::socket(domain, type, protocol);142}143144inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {145RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));146}147148inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {149RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));150}151152inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {153return os::send(fd, buf, nBytes, flags);154}155156inline int os::timeout(int fd, long timeout) {157julong prevtime,newtime;158struct timeval t;159160gettimeofday(&t, NULL);161prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;162163for(;;) {164struct pollfd pfd;165166pfd.fd = fd;167pfd.events = POLLIN | POLLERR;168169int res = ::poll(&pfd, 1, timeout);170171if (res == OS_ERR && errno == EINTR) {172173// On Linux any value < 0 means "forever"174175if(timeout >= 0) {176gettimeofday(&t, NULL);177newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;178timeout -= newtime - prevtime;179if(timeout <= 0)180return OS_OK;181prevtime = newtime;182}183} else184return res;185}186}187188inline int os::listen(int fd, int count) {189return ::listen(fd, count);190}191192inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {193RESTARTABLE_RETURN_INT(::connect(fd, him, len));194}195196inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {197// Linux doc says this can't return EINTR, unlike accept() on Solaris.198// But see attachListener_linux.cpp, LinuxAttachListener::dequeue().199return (int)::accept(fd, him, len);200}201202inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,203sockaddr* from, socklen_t* fromlen) {204RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));205}206207inline int os::sendto(int fd, char* buf, size_t len, uint flags,208struct sockaddr* to, socklen_t tolen) {209RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));210}211212inline int os::socket_shutdown(int fd, int howto) {213return ::shutdown(fd, howto);214}215216inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {217return ::bind(fd, him, len);218}219220inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {221return ::getsockname(fd, him, len);222}223224inline int os::get_host_name(char* name, int namelen) {225return ::gethostname(name, namelen);226}227228inline struct hostent* os::get_host_by_name(char* name) {229return ::gethostbyname(name);230}231232inline int os::get_sock_opt(int fd, int level, int optname,233char* optval, socklen_t* optlen) {234return ::getsockopt(fd, level, optname, optval, optlen);235}236237inline int os::set_sock_opt(int fd, int level, int optname,238const char* optval, socklen_t optlen) {239return ::setsockopt(fd, level, optname, optval, optlen);240}241242#endif // OS_LINUX_VM_OS_LINUX_INLINE_HPP243244245