src/os/solaris/vm/os_solaris.inline.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6911
ce8f6bb717c9
parent 6876
710a3c8b516e
child 9756
2be326848943
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef OS_SOLARIS_VM_OS_SOLARIS_INLINE_HPP
aoqi@0 26 #define OS_SOLARIS_VM_OS_SOLARIS_INLINE_HPP
aoqi@0 27
aoqi@0 28 #include "runtime/atomic.inline.hpp"
goetz@6911 29 #include "runtime/orderAccess.inline.hpp"
aoqi@0 30 #include "runtime/os.hpp"
aoqi@0 31
aoqi@0 32 // System includes
aoqi@0 33 #include <sys/param.h>
aoqi@0 34 #include <dlfcn.h>
aoqi@0 35 #include <sys/socket.h>
aoqi@0 36 #include <sys/poll.h>
aoqi@0 37 #include <sys/filio.h>
aoqi@0 38 #include <unistd.h>
aoqi@0 39 #include <netdb.h>
aoqi@0 40 #include <setjmp.h>
aoqi@0 41
aoqi@0 42 inline const char* os::file_separator() { return "/"; }
aoqi@0 43 inline const char* os::line_separator() { return "\n"; }
aoqi@0 44 inline const char* os::path_separator() { return ":"; }
aoqi@0 45
aoqi@0 46 // File names are case-sensitive on windows only
aoqi@0 47 inline int os::file_name_strcmp(const char* s1, const char* s2) {
aoqi@0 48 return strcmp(s1, s2);
aoqi@0 49 }
aoqi@0 50
aoqi@0 51 inline bool os::uses_stack_guard_pages() {
aoqi@0 52 return true;
aoqi@0 53 }
aoqi@0 54
aoqi@0 55 inline bool os::allocate_stack_guard_pages() {
aoqi@0 56 assert(uses_stack_guard_pages(), "sanity check");
aoqi@0 57 int r = thr_main() ;
aoqi@0 58 guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ;
aoqi@0 59 return r;
aoqi@0 60 }
aoqi@0 61
aoqi@0 62
aoqi@0 63 // On Solaris, reservations are made on a page by page basis, nothing to do.
aoqi@0 64 inline void os::pd_split_reserved_memory(char *base, size_t size,
aoqi@0 65 size_t split, bool realloc) {
aoqi@0 66 }
aoqi@0 67
aoqi@0 68
aoqi@0 69 // Bang the shadow pages if they need to be touched to be mapped.
aoqi@0 70 inline void os::bang_stack_shadow_pages() {
aoqi@0 71 }
aoqi@0 72 inline void os::dll_unload(void *lib) { ::dlclose(lib); }
aoqi@0 73
aoqi@0 74 inline DIR* os::opendir(const char* dirname) {
aoqi@0 75 assert(dirname != NULL, "just checking");
aoqi@0 76 return ::opendir(dirname);
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 inline int os::readdir_buf_size(const char *path) {
aoqi@0 80 int size = pathconf(path, _PC_NAME_MAX);
aoqi@0 81 return (size < 0 ? MAXPATHLEN : size) + sizeof(dirent) + 1;
aoqi@0 82 }
aoqi@0 83
aoqi@0 84 inline struct dirent* os::readdir(DIR* dirp, dirent* dbuf) {
aoqi@0 85 assert(dirp != NULL, "just checking");
aoqi@0 86 #if defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64
aoqi@0 87 dirent* p;
aoqi@0 88 int status;
aoqi@0 89
aoqi@0 90 if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
aoqi@0 91 errno = status;
aoqi@0 92 return NULL;
aoqi@0 93 } else
aoqi@0 94 return p;
aoqi@0 95 #else // defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64
aoqi@0 96 return ::readdir_r(dirp, dbuf);
aoqi@0 97 #endif // defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 inline int os::closedir(DIR *dirp) {
aoqi@0 101 assert(dirp != NULL, "argument is NULL");
aoqi@0 102 return ::closedir(dirp);
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 //////////////////////////////////////////////////////////////////////////////
aoqi@0 106 ////////////////////////////////////////////////////////////////////////////////
aoqi@0 107
aoqi@0 108 // macros for interruptible io and system calls and system call restarting
aoqi@0 109
aoqi@0 110 #define _INTERRUPTIBLE(_setup, _cmd, _result, _thread, _clear, _before, _after, _int_enable) \
aoqi@0 111 do { \
aoqi@0 112 _setup; \
aoqi@0 113 _before; \
aoqi@0 114 OSThread* _osthread = _thread->osthread(); \
aoqi@0 115 if (_int_enable && _thread->has_last_Java_frame()) { \
aoqi@0 116 /* this is java interruptible io stuff */ \
aoqi@0 117 if (os::is_interrupted(_thread, _clear)) { \
aoqi@0 118 os::Solaris::bump_interrupted_before_count(); \
aoqi@0 119 _result = OS_INTRPT; \
aoqi@0 120 } else { \
aoqi@0 121 /* _cmd always expands to an assignment to _result */ \
aoqi@0 122 if ((_cmd) < 0 && errno == EINTR \
aoqi@0 123 && os::is_interrupted(_thread, _clear)) { \
aoqi@0 124 os::Solaris::bump_interrupted_during_count(); \
aoqi@0 125 _result = OS_INTRPT; \
aoqi@0 126 } \
aoqi@0 127 } \
aoqi@0 128 } else { \
aoqi@0 129 /* this is normal blocking io stuff */ \
aoqi@0 130 _cmd; \
aoqi@0 131 } \
aoqi@0 132 _after; \
aoqi@0 133 } while(false)
aoqi@0 134
aoqi@0 135 // Interruptible io support + restarting of interrupted system calls
aoqi@0 136
aoqi@0 137 #ifndef ASSERT
aoqi@0 138
aoqi@0 139 #define INTERRUPTIBLE(_cmd, _result, _clear) do { \
aoqi@0 140 _INTERRUPTIBLE( JavaThread* _thread = (JavaThread*)ThreadLocalStorage::thread(),_result = _cmd, _result, _thread, _clear, , , UseVMInterruptibleIO); \
aoqi@0 141 } while((_result == OS_ERR) && (errno == EINTR))
aoqi@0 142
aoqi@0 143 #else
aoqi@0 144
aoqi@0 145 // This adds an assertion that it is only called from thread_in_native
aoqi@0 146 // The call overhead is skipped for performance in product mode
aoqi@0 147 #define INTERRUPTIBLE(_cmd, _result, _clear) do { \
aoqi@0 148 _INTERRUPTIBLE(JavaThread* _thread = os::Solaris::setup_interruptible_native(), _result = _cmd, _result, _thread, _clear, , os::Solaris::cleanup_interruptible_native(_thread), UseVMInterruptibleIO ); \
aoqi@0 149 } while((_result == OS_ERR) && (errno == EINTR))
aoqi@0 150
aoqi@0 151 #endif
aoqi@0 152
aoqi@0 153 // Used for calls from _thread_in_vm, not from _thread_in_native
aoqi@0 154 #define INTERRUPTIBLE_VM(_cmd, _result, _clear) do { \
aoqi@0 155 _INTERRUPTIBLE(JavaThread* _thread = os::Solaris::setup_interruptible(), _result = _cmd, _result, _thread, _clear, , os::Solaris::cleanup_interruptible(_thread), UseVMInterruptibleIO ); \
aoqi@0 156 } while((_result == OS_ERR) && (errno == EINTR))
aoqi@0 157
aoqi@0 158 /* Use NORESTART when the system call cannot return EINTR, when something other
aoqi@0 159 than a system call is being invoked, or when the caller must do EINTR
aoqi@0 160 handling. */
aoqi@0 161
aoqi@0 162 #ifndef ASSERT
aoqi@0 163
aoqi@0 164 #define INTERRUPTIBLE_NORESTART(_cmd, _result, _clear) \
aoqi@0 165 _INTERRUPTIBLE( JavaThread* _thread = (JavaThread*)ThreadLocalStorage::thread(),_result = _cmd, _result, _thread, _clear, , , UseVMInterruptibleIO)
aoqi@0 166
aoqi@0 167 #else
aoqi@0 168
aoqi@0 169 // This adds an assertion that it is only called from thread_in_native
aoqi@0 170 // The call overhead is skipped for performance in product mode
aoqi@0 171 #define INTERRUPTIBLE_NORESTART(_cmd, _result, _clear) \
aoqi@0 172 _INTERRUPTIBLE(JavaThread* _thread = os::Solaris::setup_interruptible_native(), _result = _cmd, _result, _thread, _clear, , os::Solaris::cleanup_interruptible_native(_thread), UseVMInterruptibleIO )
aoqi@0 173
aoqi@0 174 #endif
aoqi@0 175
aoqi@0 176 // Don't attend to UseVMInterruptibleIO. Always allow interruption.
aoqi@0 177 // Also assumes that it is called from the _thread_blocked state.
aoqi@0 178 // Used by os_sleep().
aoqi@0 179
aoqi@0 180 #define INTERRUPTIBLE_NORESTART_VM_ALWAYS(_cmd, _result, _thread, _clear) \
aoqi@0 181 _INTERRUPTIBLE(os::Solaris::setup_interruptible_already_blocked(_thread), _result = _cmd, _result, _thread, _clear, , , true )
aoqi@0 182
aoqi@0 183 #define INTERRUPTIBLE_RETURN_INT(_cmd, _clear) do { \
aoqi@0 184 int _result; \
aoqi@0 185 do { \
aoqi@0 186 INTERRUPTIBLE(_cmd, _result, _clear); \
aoqi@0 187 } while((_result == OS_ERR) && (errno == EINTR)); \
aoqi@0 188 return _result; \
aoqi@0 189 } while(false)
aoqi@0 190
aoqi@0 191 #define INTERRUPTIBLE_RETURN_INT_VM(_cmd, _clear) do { \
aoqi@0 192 int _result; \
aoqi@0 193 do { \
aoqi@0 194 INTERRUPTIBLE_VM(_cmd, _result, _clear); \
aoqi@0 195 } while((_result == OS_ERR) && (errno == EINTR)); \
aoqi@0 196 return _result; \
aoqi@0 197 } while(false)
aoqi@0 198
aoqi@0 199 #define INTERRUPTIBLE_RETURN_INT_NORESTART(_cmd, _clear) do { \
aoqi@0 200 int _result; \
aoqi@0 201 INTERRUPTIBLE_NORESTART(_cmd, _result, _clear); \
aoqi@0 202 return _result; \
aoqi@0 203 } while(false)
aoqi@0 204
aoqi@0 205 /* Use the RESTARTABLE macros when interruptible io is not needed */
aoqi@0 206
aoqi@0 207 #define RESTARTABLE(_cmd, _result) do { \
aoqi@0 208 do { \
aoqi@0 209 _result = _cmd; \
aoqi@0 210 } while((_result == OS_ERR) && (errno == EINTR)); \
aoqi@0 211 } while(false)
aoqi@0 212
aoqi@0 213 #define RESTARTABLE_RETURN_INT(_cmd) do { \
aoqi@0 214 int _result; \
aoqi@0 215 RESTARTABLE(_cmd, _result); \
aoqi@0 216 return _result; \
aoqi@0 217 } while(false)
aoqi@0 218
aoqi@0 219 inline bool os::numa_has_static_binding() { return false; }
aoqi@0 220 inline bool os::numa_has_group_homing() { return true; }
aoqi@0 221
aoqi@0 222 inline int os::socket(int domain, int type, int protocol) {
aoqi@0 223 return ::socket(domain, type, protocol);
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 inline int os::listen(int fd, int count) {
aoqi@0 227 if (fd < 0) return OS_ERR;
aoqi@0 228
aoqi@0 229 return ::listen(fd, count);
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 inline int os::socket_shutdown(int fd, int howto){
aoqi@0 233 return ::shutdown(fd, howto);
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len){
aoqi@0 237 return ::getsockname(fd, him, len);
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 inline int os::get_host_name(char* name, int namelen){
aoqi@0 241 return ::gethostname(name, namelen);
aoqi@0 242 }
aoqi@0 243
aoqi@0 244 inline struct hostent* os::get_host_by_name(char* name) {
aoqi@0 245 return ::gethostbyname(name);
aoqi@0 246 }
aoqi@0 247
aoqi@0 248 inline int os::get_sock_opt(int fd, int level, int optname,
aoqi@0 249 char* optval, socklen_t* optlen) {
aoqi@0 250 return ::getsockopt(fd, level, optname, optval, optlen);
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 inline int os::set_sock_opt(int fd, int level, int optname,
aoqi@0 254 const char *optval, socklen_t optlen) {
aoqi@0 255 return ::setsockopt(fd, level, optname, optval, optlen);
aoqi@0 256 }
aoqi@0 257 #endif // OS_SOLARIS_VM_OS_SOLARIS_INLINE_HPP

mercurial