Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/bsd/vm/os_bsd.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_BSD_VM_OS_BSD_INLINE_HPP25#define OS_BSD_VM_OS_BSD_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");69#if !defined(__FreeBSD__) || __FreeBSD__ < 570// Since FreeBSD 4 uses malloc() for allocating the thread stack71// there is no need to do anything extra to allocate the guard pages72return false;73#else74// FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks.75// Must 'allocate' them or guard pages are ignored.76return true;77#endif78}798081// On Bsd, reservations are made on a page by page basis, nothing to do.82inline void os::pd_split_reserved_memory(char *base, size_t size,83size_t split, bool realloc) {84}858687// Bang the shadow pages if they need to be touched to be mapped.88inline void os::bang_stack_shadow_pages() {89}9091inline void os::dll_unload(void *lib) {92::dlclose(lib);93}9495inline const int os::default_file_open_flags() { return 0;}9697inline jlong os::lseek(int fd, jlong offset, int whence) {98return (jlong) ::lseek(fd, offset, whence);99}100101inline int os::fsync(int fd) {102return ::fsync(fd);103}104105inline char* os::native_path(char *path) {106return path;107}108109inline int os::ftruncate(int fd, jlong length) {110return ::ftruncate(fd, length);111}112113// macros for restartable system calls114115#define RESTARTABLE(_cmd, _result) do { \116_result = _cmd; \117} while(((int)_result == OS_ERR) && (errno == EINTR))118119#define RESTARTABLE_RETURN_INT(_cmd) do { \120int _result; \121RESTARTABLE(_cmd, _result); \122return _result; \123} while(false)124125inline bool os::numa_has_static_binding() { return true; }126inline bool os::numa_has_group_homing() { return false; }127128inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {129size_t res;130RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);131return res;132}133134inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {135size_t res;136RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);137return res;138}139140inline int os::close(int fd) {141return ::close(fd);142}143144inline int os::socket_close(int fd) {145return ::close(fd);146}147148inline int os::socket(int domain, int type, int protocol) {149return ::socket(domain, type, protocol);150}151152inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {153RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));154}155156inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {157RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));158}159160inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {161return os::send(fd, buf, nBytes, flags);162}163164inline int os::timeout(int fd, long timeout) {165julong prevtime,newtime;166struct timeval t;167168gettimeofday(&t, NULL);169prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;170171for(;;) {172struct pollfd pfd;173174pfd.fd = fd;175pfd.events = POLLIN | POLLERR;176177int res = ::poll(&pfd, 1, timeout);178179if (res == OS_ERR && errno == EINTR) {180181// On Bsd any value < 0 means "forever"182183if(timeout >= 0) {184gettimeofday(&t, NULL);185newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;186timeout -= newtime - prevtime;187if(timeout <= 0)188return OS_OK;189prevtime = newtime;190}191} else192return res;193}194}195196inline int os::listen(int fd, int count) {197return ::listen(fd, count);198}199200inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {201RESTARTABLE_RETURN_INT(::connect(fd, him, len));202}203204inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {205// At least OpenBSD and FreeBSD can return EINTR from accept.206RESTARTABLE_RETURN_INT(::accept(fd, him, len));207}208209inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,210sockaddr* from, socklen_t* fromlen) {211RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));212}213214inline int os::sendto(int fd, char* buf, size_t len, uint flags,215struct sockaddr *to, socklen_t tolen) {216RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));217}218219inline int os::socket_shutdown(int fd, int howto) {220return ::shutdown(fd, howto);221}222223inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {224return ::bind(fd, him, len);225}226227inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {228return ::getsockname(fd, him, len);229}230231inline int os::get_host_name(char* name, int namelen) {232return ::gethostname(name, namelen);233}234235inline struct hostent* os::get_host_by_name(char* name) {236return ::gethostbyname(name);237}238239inline int os::get_sock_opt(int fd, int level, int optname,240char *optval, socklen_t* optlen) {241return ::getsockopt(fd, level, optname, optval, optlen);242}243244inline int os::set_sock_opt(int fd, int level, int optname,245const char* optval, socklen_t optlen) {246return ::setsockopt(fd, level, optname, optval, optlen);247}248249#endif // OS_BSD_VM_OS_BSD_INLINE_HPP250251252