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