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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 5309
feae15578b2f
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
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"
aoqi@0 29 #include "runtime/os.hpp"
aoqi@0 30
aoqi@0 31 #ifdef TARGET_OS_ARCH_solaris_x86
aoqi@0 32 # include "orderAccess_solaris_x86.inline.hpp"
aoqi@0 33 #endif
aoqi@0 34 #ifdef TARGET_OS_ARCH_solaris_sparc
aoqi@0 35 # include "orderAccess_solaris_sparc.inline.hpp"
aoqi@0 36 #endif
aoqi@0 37
aoqi@0 38 // System includes
aoqi@0 39 #include <sys/param.h>
aoqi@0 40 #include <dlfcn.h>
aoqi@0 41 #include <sys/socket.h>
aoqi@0 42 #include <sys/poll.h>
aoqi@0 43 #include <sys/filio.h>
aoqi@0 44 #include <unistd.h>
aoqi@0 45 #include <netdb.h>
aoqi@0 46 #include <setjmp.h>
aoqi@0 47
aoqi@0 48 inline const char* os::file_separator() { return "/"; }
aoqi@0 49 inline const char* os::line_separator() { return "\n"; }
aoqi@0 50 inline const char* os::path_separator() { return ":"; }
aoqi@0 51
aoqi@0 52 // File names are case-sensitive on windows only
aoqi@0 53 inline int os::file_name_strcmp(const char* s1, const char* s2) {
aoqi@0 54 return strcmp(s1, s2);
aoqi@0 55 }
aoqi@0 56
aoqi@0 57 inline bool os::uses_stack_guard_pages() {
aoqi@0 58 return true;
aoqi@0 59 }
aoqi@0 60
aoqi@0 61 inline bool os::allocate_stack_guard_pages() {
aoqi@0 62 assert(uses_stack_guard_pages(), "sanity check");
aoqi@0 63 int r = thr_main() ;
aoqi@0 64 guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ;
aoqi@0 65 return r;
aoqi@0 66 }
aoqi@0 67
aoqi@0 68
aoqi@0 69 // On Solaris, reservations are made on a page by page basis, nothing to do.
aoqi@0 70 inline void os::pd_split_reserved_memory(char *base, size_t size,
aoqi@0 71 size_t split, bool realloc) {
aoqi@0 72 }
aoqi@0 73
aoqi@0 74
aoqi@0 75 // Bang the shadow pages if they need to be touched to be mapped.
aoqi@0 76 inline void os::bang_stack_shadow_pages() {
aoqi@0 77 }
aoqi@0 78 inline void os::dll_unload(void *lib) { ::dlclose(lib); }
aoqi@0 79
aoqi@0 80 inline DIR* os::opendir(const char* dirname) {
aoqi@0 81 assert(dirname != NULL, "just checking");
aoqi@0 82 return ::opendir(dirname);
aoqi@0 83 }
aoqi@0 84
aoqi@0 85 inline int os::readdir_buf_size(const char *path) {
aoqi@0 86 int size = pathconf(path, _PC_NAME_MAX);
aoqi@0 87 return (size < 0 ? MAXPATHLEN : size) + sizeof(dirent) + 1;
aoqi@0 88 }
aoqi@0 89
aoqi@0 90 inline struct dirent* os::readdir(DIR* dirp, dirent* dbuf) {
aoqi@0 91 assert(dirp != NULL, "just checking");
aoqi@0 92 #if defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64
aoqi@0 93 dirent* p;
aoqi@0 94 int status;
aoqi@0 95
aoqi@0 96 if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
aoqi@0 97 errno = status;
aoqi@0 98 return NULL;
aoqi@0 99 } else
aoqi@0 100 return p;
aoqi@0 101 #else // defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64
aoqi@0 102 return ::readdir_r(dirp, dbuf);
aoqi@0 103 #endif // defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64
aoqi@0 104 }
aoqi@0 105
aoqi@0 106 inline int os::closedir(DIR *dirp) {
aoqi@0 107 assert(dirp != NULL, "argument is NULL");
aoqi@0 108 return ::closedir(dirp);
aoqi@0 109 }
aoqi@0 110
aoqi@0 111 //////////////////////////////////////////////////////////////////////////////
aoqi@0 112 ////////////////////////////////////////////////////////////////////////////////
aoqi@0 113
aoqi@0 114 // macros for interruptible io and system calls and system call restarting
aoqi@0 115
aoqi@0 116 #define _INTERRUPTIBLE(_setup, _cmd, _result, _thread, _clear, _before, _after, _int_enable) \
aoqi@0 117 do { \
aoqi@0 118 _setup; \
aoqi@0 119 _before; \
aoqi@0 120 OSThread* _osthread = _thread->osthread(); \
aoqi@0 121 if (_int_enable && _thread->has_last_Java_frame()) { \
aoqi@0 122 /* this is java interruptible io stuff */ \
aoqi@0 123 if (os::is_interrupted(_thread, _clear)) { \
aoqi@0 124 os::Solaris::bump_interrupted_before_count(); \
aoqi@0 125 _result = OS_INTRPT; \
aoqi@0 126 } else { \
aoqi@0 127 /* _cmd always expands to an assignment to _result */ \
aoqi@0 128 if ((_cmd) < 0 && errno == EINTR \
aoqi@0 129 && os::is_interrupted(_thread, _clear)) { \
aoqi@0 130 os::Solaris::bump_interrupted_during_count(); \
aoqi@0 131 _result = OS_INTRPT; \
aoqi@0 132 } \
aoqi@0 133 } \
aoqi@0 134 } else { \
aoqi@0 135 /* this is normal blocking io stuff */ \
aoqi@0 136 _cmd; \
aoqi@0 137 } \
aoqi@0 138 _after; \
aoqi@0 139 } while(false)
aoqi@0 140
aoqi@0 141 // Interruptible io support + restarting of interrupted system calls
aoqi@0 142
aoqi@0 143 #ifndef ASSERT
aoqi@0 144
aoqi@0 145 #define INTERRUPTIBLE(_cmd, _result, _clear) do { \
aoqi@0 146 _INTERRUPTIBLE( JavaThread* _thread = (JavaThread*)ThreadLocalStorage::thread(),_result = _cmd, _result, _thread, _clear, , , UseVMInterruptibleIO); \
aoqi@0 147 } while((_result == OS_ERR) && (errno == EINTR))
aoqi@0 148
aoqi@0 149 #else
aoqi@0 150
aoqi@0 151 // This adds an assertion that it is only called from thread_in_native
aoqi@0 152 // The call overhead is skipped for performance in product mode
aoqi@0 153 #define INTERRUPTIBLE(_cmd, _result, _clear) do { \
aoqi@0 154 _INTERRUPTIBLE(JavaThread* _thread = os::Solaris::setup_interruptible_native(), _result = _cmd, _result, _thread, _clear, , os::Solaris::cleanup_interruptible_native(_thread), UseVMInterruptibleIO ); \
aoqi@0 155 } while((_result == OS_ERR) && (errno == EINTR))
aoqi@0 156
aoqi@0 157 #endif
aoqi@0 158
aoqi@0 159 // Used for calls from _thread_in_vm, not from _thread_in_native
aoqi@0 160 #define INTERRUPTIBLE_VM(_cmd, _result, _clear) do { \
aoqi@0 161 _INTERRUPTIBLE(JavaThread* _thread = os::Solaris::setup_interruptible(), _result = _cmd, _result, _thread, _clear, , os::Solaris::cleanup_interruptible(_thread), UseVMInterruptibleIO ); \
aoqi@0 162 } while((_result == OS_ERR) && (errno == EINTR))
aoqi@0 163
aoqi@0 164 /* Use NORESTART when the system call cannot return EINTR, when something other
aoqi@0 165 than a system call is being invoked, or when the caller must do EINTR
aoqi@0 166 handling. */
aoqi@0 167
aoqi@0 168 #ifndef ASSERT
aoqi@0 169
aoqi@0 170 #define INTERRUPTIBLE_NORESTART(_cmd, _result, _clear) \
aoqi@0 171 _INTERRUPTIBLE( JavaThread* _thread = (JavaThread*)ThreadLocalStorage::thread(),_result = _cmd, _result, _thread, _clear, , , UseVMInterruptibleIO)
aoqi@0 172
aoqi@0 173 #else
aoqi@0 174
aoqi@0 175 // This adds an assertion that it is only called from thread_in_native
aoqi@0 176 // The call overhead is skipped for performance in product mode
aoqi@0 177 #define INTERRUPTIBLE_NORESTART(_cmd, _result, _clear) \
aoqi@0 178 _INTERRUPTIBLE(JavaThread* _thread = os::Solaris::setup_interruptible_native(), _result = _cmd, _result, _thread, _clear, , os::Solaris::cleanup_interruptible_native(_thread), UseVMInterruptibleIO )
aoqi@0 179
aoqi@0 180 #endif
aoqi@0 181
aoqi@0 182 // Don't attend to UseVMInterruptibleIO. Always allow interruption.
aoqi@0 183 // Also assumes that it is called from the _thread_blocked state.
aoqi@0 184 // Used by os_sleep().
aoqi@0 185
aoqi@0 186 #define INTERRUPTIBLE_NORESTART_VM_ALWAYS(_cmd, _result, _thread, _clear) \
aoqi@0 187 _INTERRUPTIBLE(os::Solaris::setup_interruptible_already_blocked(_thread), _result = _cmd, _result, _thread, _clear, , , true )
aoqi@0 188
aoqi@0 189 #define INTERRUPTIBLE_RETURN_INT(_cmd, _clear) do { \
aoqi@0 190 int _result; \
aoqi@0 191 do { \
aoqi@0 192 INTERRUPTIBLE(_cmd, _result, _clear); \
aoqi@0 193 } while((_result == OS_ERR) && (errno == EINTR)); \
aoqi@0 194 return _result; \
aoqi@0 195 } while(false)
aoqi@0 196
aoqi@0 197 #define INTERRUPTIBLE_RETURN_INT_VM(_cmd, _clear) do { \
aoqi@0 198 int _result; \
aoqi@0 199 do { \
aoqi@0 200 INTERRUPTIBLE_VM(_cmd, _result, _clear); \
aoqi@0 201 } while((_result == OS_ERR) && (errno == EINTR)); \
aoqi@0 202 return _result; \
aoqi@0 203 } while(false)
aoqi@0 204
aoqi@0 205 #define INTERRUPTIBLE_RETURN_INT_NORESTART(_cmd, _clear) do { \
aoqi@0 206 int _result; \
aoqi@0 207 INTERRUPTIBLE_NORESTART(_cmd, _result, _clear); \
aoqi@0 208 return _result; \
aoqi@0 209 } while(false)
aoqi@0 210
aoqi@0 211 /* Use the RESTARTABLE macros when interruptible io is not needed */
aoqi@0 212
aoqi@0 213 #define RESTARTABLE(_cmd, _result) do { \
aoqi@0 214 do { \
aoqi@0 215 _result = _cmd; \
aoqi@0 216 } while((_result == OS_ERR) && (errno == EINTR)); \
aoqi@0 217 } while(false)
aoqi@0 218
aoqi@0 219 #define RESTARTABLE_RETURN_INT(_cmd) do { \
aoqi@0 220 int _result; \
aoqi@0 221 RESTARTABLE(_cmd, _result); \
aoqi@0 222 return _result; \
aoqi@0 223 } while(false)
aoqi@0 224
aoqi@0 225 inline bool os::numa_has_static_binding() { return false; }
aoqi@0 226 inline bool os::numa_has_group_homing() { return true; }
aoqi@0 227
aoqi@0 228 inline int os::socket(int domain, int type, int protocol) {
aoqi@0 229 return ::socket(domain, type, protocol);
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 inline int os::listen(int fd, int count) {
aoqi@0 233 if (fd < 0) return OS_ERR;
aoqi@0 234
aoqi@0 235 return ::listen(fd, count);
aoqi@0 236 }
aoqi@0 237
aoqi@0 238 inline int os::socket_shutdown(int fd, int howto){
aoqi@0 239 return ::shutdown(fd, howto);
aoqi@0 240 }
aoqi@0 241
aoqi@0 242 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len){
aoqi@0 243 return ::getsockname(fd, him, len);
aoqi@0 244 }
aoqi@0 245
aoqi@0 246 inline int os::get_host_name(char* name, int namelen){
aoqi@0 247 return ::gethostname(name, namelen);
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 inline struct hostent* os::get_host_by_name(char* name) {
aoqi@0 251 return ::gethostbyname(name);
aoqi@0 252 }
aoqi@0 253
aoqi@0 254 inline int os::get_sock_opt(int fd, int level, int optname,
aoqi@0 255 char* optval, socklen_t* optlen) {
aoqi@0 256 return ::getsockopt(fd, level, optname, optval, optlen);
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 inline int os::set_sock_opt(int fd, int level, int optname,
aoqi@0 260 const char *optval, socklen_t optlen) {
aoqi@0 261 return ::setsockopt(fd, level, optname, optval, optlen);
aoqi@0 262 }
aoqi@0 263 #endif // OS_SOLARIS_VM_OS_SOLARIS_INLINE_HPP

mercurial