Mercurial > hg > graal-compiler
comparison src/os/solaris/vm/os_solaris.hpp @ 0:a61af66fc99e jdk7-b24
Initial load
author | duke |
---|---|
date | Sat, 01 Dec 2007 00:00:00 +0000 |
parents | |
children | 8d84e28e68ba |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a61af66fc99e |
---|---|
1 /* | |
2 * Copyright 1997-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // Solaris_OS defines the interface to Solaris operating systems | |
26 | |
27 class Solaris { | |
28 friend class os; | |
29 | |
30 private: | |
31 | |
32 // Support for "new" libthread APIs for getting & setting thread context (2.8) | |
33 #define TRS_VALID 0 | |
34 #define TRS_NONVOLATILE 1 | |
35 #define TRS_LWPID 2 | |
36 #define TRS_INVALID 3 | |
37 | |
38 // _T2_libthread is true if we believe we are running with the newer | |
39 // SunSoft lib/lwp/libthread: default Solaris 9, available Solaris 8 | |
40 // which is a lightweight libthread that also supports all T1 | |
41 static bool _T2_libthread; | |
42 // These refer to new libthread interface functions | |
43 // They get intialized if we dynamically detect new libthread | |
44 static int_fnP_thread_t_iP_uP_stack_tP_gregset_t _thr_getstate; | |
45 static int_fnP_thread_t_i_gregset_t _thr_setstate; | |
46 static int_fnP_thread_t_i _thr_setmutator; | |
47 static int_fnP_thread_t _thr_suspend_mutator; | |
48 static int_fnP_thread_t _thr_continue_mutator; | |
49 // libthread_init sets the above, if the new functionality is detected | |
50 | |
51 // initialized to libthread or lwp synchronization primitives depending on UseLWPSychronization | |
52 static int_fnP_mutex_tP _mutex_lock; | |
53 static int_fnP_mutex_tP _mutex_trylock; | |
54 static int_fnP_mutex_tP _mutex_unlock; | |
55 static int_fnP_mutex_tP_i_vP _mutex_init; | |
56 static int_fnP_mutex_tP _mutex_destroy; | |
57 static int _mutex_scope; | |
58 | |
59 static int_fnP_cond_tP_mutex_tP_timestruc_tP _cond_timedwait; | |
60 static int_fnP_cond_tP_mutex_tP _cond_wait; | |
61 static int_fnP_cond_tP _cond_signal; | |
62 static int_fnP_cond_tP _cond_broadcast; | |
63 static int_fnP_cond_tP_i_vP _cond_init; | |
64 static int_fnP_cond_tP _cond_destroy; | |
65 static int _cond_scope; | |
66 | |
67 typedef uintptr_t lgrp_cookie_t; | |
68 typedef id_t lgrp_id_t; | |
69 typedef enum lgrp_view { | |
70 LGRP_VIEW_CALLER, /* what's available to the caller */ | |
71 LGRP_VIEW_OS /* what's available to operating system */ | |
72 } lgrp_view_t; | |
73 | |
74 typedef lgrp_id_t (*lgrp_home_func_t)(idtype_t idtype, id_t id); | |
75 typedef lgrp_cookie_t (*lgrp_init_func_t)(lgrp_view_t view); | |
76 typedef int (*lgrp_fini_func_t)(lgrp_cookie_t cookie); | |
77 typedef lgrp_id_t (*lgrp_root_func_t)(lgrp_cookie_t cookie); | |
78 typedef int (*lgrp_children_func_t)(lgrp_cookie_t cookie, lgrp_id_t parent, | |
79 lgrp_id_t *lgrp_array, uint_t lgrp_array_size); | |
80 typedef int (*lgrp_nlgrps_func_t)(lgrp_cookie_t cookie); | |
81 typedef int (*lgrp_cookie_stale_func_t)(lgrp_cookie_t cookie); | |
82 typedef int (*meminfo_func_t)(const uint64_t inaddr[], int addr_count, | |
83 const uint_t info_req[], int info_count, | |
84 uint64_t outdata[], uint_t validity[]); | |
85 | |
86 static lgrp_home_func_t _lgrp_home; | |
87 static lgrp_init_func_t _lgrp_init; | |
88 static lgrp_fini_func_t _lgrp_fini; | |
89 static lgrp_root_func_t _lgrp_root; | |
90 static lgrp_children_func_t _lgrp_children; | |
91 static lgrp_nlgrps_func_t _lgrp_nlgrps; | |
92 static lgrp_cookie_stale_func_t _lgrp_cookie_stale; | |
93 static lgrp_cookie_t _lgrp_cookie; | |
94 | |
95 static meminfo_func_t _meminfo; | |
96 | |
97 // Large Page Support--mpss. | |
98 static bool set_mpss_range(caddr_t start, size_t bytes, size_t align); | |
99 | |
100 static void init_thread_fpu_state(void); | |
101 | |
102 static void try_enable_extended_io(); | |
103 | |
104 // For signal-chaining | |
105 static unsigned long sigs; // mask of signals that have | |
106 // preinstalled signal handlers | |
107 static struct sigaction *(*get_signal_action)(int); | |
108 static struct sigaction *get_preinstalled_handler(int); | |
109 static int (*get_libjsig_version)(); | |
110 static void save_preinstalled_handler(int, struct sigaction&); | |
111 static void check_signal_handler(int sig); | |
112 | |
113 // For overridable signals | |
114 static int _SIGinterrupt; // user-overridable INTERRUPT_SIGNAL | |
115 static int _SIGasync; // user-overridable ASYNC_SIGNAL | |
116 static void set_SIGinterrupt(int newsig) { _SIGinterrupt = newsig; } | |
117 static void set_SIGasync(int newsig) { _SIGasync = newsig; } | |
118 | |
119 | |
120 public: | |
121 // Large Page Support--ISM. | |
122 static bool largepage_range(char* addr, size_t size); | |
123 | |
124 static int SIGinterrupt() { return _SIGinterrupt; } | |
125 static int SIGasync() { return _SIGasync; } | |
126 static address handler_start, handler_end; // start and end pc of thr_sighndlrinfo | |
127 | |
128 static bool valid_stack_address(Thread* thread, address sp); | |
129 static bool valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect); | |
130 static ucontext_t* get_valid_uc_in_signal_handler(Thread* thread, | |
131 ucontext_t* uc); | |
132 | |
133 static ExtendedPC ucontext_get_ExtendedPC(ucontext_t* uc); | |
134 static intptr_t* ucontext_get_sp(ucontext_t* uc); | |
135 // ucontext_get_fp() is only used by Solaris X86 (see note below) | |
136 static intptr_t* ucontext_get_fp(ucontext_t* uc); | |
137 | |
138 // For Analyzer Forte AsyncGetCallTrace profiling support: | |
139 // Parameter ret_fp is only used by Solaris X86. | |
140 // | |
141 // We should have different declarations of this interface in | |
142 // os_solaris_i486.hpp and os_solaris_sparc.hpp, but that file | |
143 // provides extensions to the os class and not the Solaris class. | |
144 static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc, | |
145 intptr_t** ret_sp, intptr_t** ret_fp); | |
146 | |
147 static void hotspot_sigmask(Thread* thread); | |
148 | |
149 protected: | |
150 // Solaris-specific interface goes here | |
151 static julong available_memory(); | |
152 static julong physical_memory() { return _physical_memory; } | |
153 static julong _physical_memory; | |
154 static void initialize_system_info(); | |
155 static int _dev_zero_fd; | |
156 static int get_dev_zero_fd() { return _dev_zero_fd; } | |
157 static void set_dev_zero_fd(int fd) { _dev_zero_fd = fd; } | |
158 static char* mmap_chunk(char *addr, size_t size, int flags, int prot); | |
159 static bool mpss_sanity_check(bool warn, size_t * page_size); | |
160 static bool ism_sanity_check (bool warn, size_t * page_size); | |
161 | |
162 // Workaround for 4352906. thr_stksegment sometimes returns | |
163 // a bad value for the primordial thread's stack base when | |
164 // it is called more than one time. | |
165 // Workaround is to cache the initial value to avoid further | |
166 // calls to thr_stksegment. | |
167 // It appears that someone (Hotspot?) is trashing the user's | |
168 // proc_t structure (note that this is a system struct). | |
169 static address _main_stack_base; | |
170 | |
171 public: | |
172 static void libthread_init(); | |
173 static void synchronization_init(); | |
174 static void liblgrp_init(); | |
175 // Load miscellaneous symbols. | |
176 static void misc_sym_init(); | |
177 // This boolean allows users to forward their own non-matching signals | |
178 // to JVM_handle_solaris_signal, harmlessly. | |
179 static bool signal_handlers_are_installed; | |
180 | |
181 static void signal_sets_init(); | |
182 static void install_signal_handlers(); | |
183 static void set_signal_handler(int sig, bool set_installed, bool oktochain); | |
184 static void init_signal_mem(); | |
185 static bool is_sig_ignored(int sig); | |
186 static void set_our_sigflags(int, int); | |
187 static int get_our_sigflags(int); | |
188 | |
189 // For signal-chaining | |
190 static bool libjsig_is_loaded; // libjsig that interposes sigaction(), | |
191 // signal(), sigset() is loaded | |
192 static struct sigaction *get_chained_signal_action(int sig); | |
193 static bool chained_handler(int sig, siginfo_t *siginfo, void *context); | |
194 | |
195 // The following allow us to link against both the old and new libthread (2.8) | |
196 // and exploit the new libthread functionality if available. | |
197 | |
198 static bool T2_libthread() { return _T2_libthread; } | |
199 static void set_T2_libthread(bool T2_libthread) { _T2_libthread = T2_libthread; } | |
200 | |
201 static int thr_getstate(thread_t tid, int *flag, unsigned *lwp, stack_t *ss, gregset_t rs) | |
202 { return _thr_getstate(tid, flag, lwp, ss, rs); } | |
203 static void set_thr_getstate(int_fnP_thread_t_iP_uP_stack_tP_gregset_t func) | |
204 { _thr_getstate = func; } | |
205 | |
206 static int thr_setstate(thread_t tid, int flag, gregset_t rs) { return _thr_setstate(tid, flag, rs); } | |
207 static void set_thr_setstate(int_fnP_thread_t_i_gregset_t func) { _thr_setstate = func; } | |
208 | |
209 static int thr_setmutator(thread_t tid, int enabled) { return _thr_setmutator(tid, enabled); } | |
210 static void set_thr_setmutator(int_fnP_thread_t_i func) { _thr_setmutator = func; } | |
211 | |
212 static int thr_suspend_mutator(thread_t tid) { return _thr_suspend_mutator(tid); } | |
213 static void set_thr_suspend_mutator(int_fnP_thread_t func) { _thr_suspend_mutator = func; } | |
214 | |
215 static int thr_continue_mutator(thread_t tid) { return _thr_continue_mutator(tid); } | |
216 static void set_thr_continue_mutator(int_fnP_thread_t func) { _thr_continue_mutator = func; } | |
217 | |
218 // Allows us to switch between lwp and thread -based synchronization | |
219 static int mutex_lock(mutex_t *mx) { return _mutex_lock(mx); } | |
220 static int mutex_trylock(mutex_t *mx) { return _mutex_trylock(mx); } | |
221 static int mutex_unlock(mutex_t *mx) { return _mutex_unlock(mx); } | |
222 static int mutex_init(mutex_t *mx) { return _mutex_init(mx, os::Solaris::mutex_scope(), NULL); } | |
223 static int mutex_destroy(mutex_t *mx) { return _mutex_destroy(mx); } | |
224 static int mutex_scope() { return _mutex_scope; } | |
225 | |
226 static void set_mutex_lock(int_fnP_mutex_tP func) { _mutex_lock = func; } | |
227 static void set_mutex_trylock(int_fnP_mutex_tP func) { _mutex_trylock = func; } | |
228 static void set_mutex_unlock(int_fnP_mutex_tP func) { _mutex_unlock = func; } | |
229 static void set_mutex_init(int_fnP_mutex_tP_i_vP func) { _mutex_init = func; } | |
230 static void set_mutex_destroy(int_fnP_mutex_tP func) { _mutex_destroy = func; } | |
231 static void set_mutex_scope(int scope) { _mutex_scope = scope; } | |
232 | |
233 static int cond_timedwait(cond_t *cv, mutex_t *mx, timestruc_t *abst) | |
234 { return _cond_timedwait(cv, mx, abst); } | |
235 static int cond_wait(cond_t *cv, mutex_t *mx) { return _cond_wait(cv, mx); } | |
236 static int cond_signal(cond_t *cv) { return _cond_signal(cv); } | |
237 static int cond_broadcast(cond_t *cv) { return _cond_broadcast(cv); } | |
238 static int cond_init(cond_t *cv) { return _cond_init(cv, os::Solaris::cond_scope(), NULL); } | |
239 static int cond_destroy(cond_t *cv) { return _cond_destroy(cv); } | |
240 static int cond_scope() { return _cond_scope; } | |
241 | |
242 static void set_cond_timedwait(int_fnP_cond_tP_mutex_tP_timestruc_tP func) | |
243 { _cond_timedwait = func; } | |
244 static void set_cond_wait(int_fnP_cond_tP_mutex_tP func) { _cond_wait = func; } | |
245 static void set_cond_signal(int_fnP_cond_tP func) { _cond_signal = func; } | |
246 static void set_cond_broadcast(int_fnP_cond_tP func) { _cond_broadcast = func; } | |
247 static void set_cond_init(int_fnP_cond_tP_i_vP func) { _cond_init = func; } | |
248 static void set_cond_destroy(int_fnP_cond_tP func) { _cond_destroy = func; } | |
249 static void set_cond_scope(int scope) { _cond_scope = scope; } | |
250 | |
251 static void set_lgrp_home(lgrp_home_func_t func) { _lgrp_home = func; } | |
252 static void set_lgrp_init(lgrp_init_func_t func) { _lgrp_init = func; } | |
253 static void set_lgrp_fini(lgrp_fini_func_t func) { _lgrp_fini = func; } | |
254 static void set_lgrp_root(lgrp_root_func_t func) { _lgrp_root = func; } | |
255 static void set_lgrp_children(lgrp_children_func_t func) { _lgrp_children = func; } | |
256 static void set_lgrp_nlgrps(lgrp_nlgrps_func_t func) { _lgrp_nlgrps = func; } | |
257 static void set_lgrp_cookie_stale(lgrp_cookie_stale_func_t func) { _lgrp_cookie_stale = func; } | |
258 static void set_lgrp_cookie(lgrp_cookie_t cookie) { _lgrp_cookie = cookie; } | |
259 | |
260 static id_t lgrp_home(idtype_t type, id_t id) { return _lgrp_home != NULL ? _lgrp_home(type, id) : -1; } | |
261 static lgrp_cookie_t lgrp_init(lgrp_view_t view) { return _lgrp_init != NULL ? _lgrp_init(view) : 0; } | |
262 static int lgrp_fini(lgrp_cookie_t cookie) { return _lgrp_fini != NULL ? _lgrp_fini(cookie) : -1; } | |
263 static lgrp_id_t lgrp_root(lgrp_cookie_t cookie) { return _lgrp_root != NULL ? _lgrp_root(cookie) : -1; }; | |
264 static int lgrp_children(lgrp_cookie_t cookie, lgrp_id_t parent, | |
265 lgrp_id_t *lgrp_array, uint_t lgrp_array_size) { | |
266 return _lgrp_children != NULL ? _lgrp_children(cookie, parent, lgrp_array, lgrp_array_size) : -1; | |
267 } | |
268 static int lgrp_nlgrps(lgrp_cookie_t cookie) { return _lgrp_nlgrps != NULL ? _lgrp_nlgrps(cookie) : -1; } | |
269 static int lgrp_cookie_stale(lgrp_cookie_t cookie) { | |
270 return _lgrp_cookie_stale != NULL ? _lgrp_cookie_stale(cookie) : -1; | |
271 } | |
272 static lgrp_cookie_t lgrp_cookie() { return _lgrp_cookie; } | |
273 | |
274 static void set_meminfo(meminfo_func_t func) { _meminfo = func; } | |
275 static int meminfo (const uint64_t inaddr[], int addr_count, | |
276 const uint_t info_req[], int info_count, | |
277 uint64_t outdata[], uint_t validity[]) { | |
278 return _meminfo != NULL ? _meminfo(inaddr, addr_count, info_req, info_count, | |
279 outdata, validity) : -1; | |
280 } | |
281 | |
282 enum { | |
283 clear_interrupted = true | |
284 }; | |
285 static void setup_interruptible(JavaThread* thread); | |
286 static void setup_interruptible_already_blocked(JavaThread* thread); | |
287 static JavaThread* setup_interruptible(); | |
288 static void cleanup_interruptible(JavaThread* thread); | |
289 | |
290 // perf counter incrementers used by _INTERRUPTIBLE | |
291 | |
292 static void bump_interrupted_before_count(); | |
293 static void bump_interrupted_during_count(); | |
294 | |
295 #ifdef ASSERT | |
296 static JavaThread* setup_interruptible_native(); | |
297 static void cleanup_interruptible_native(JavaThread* thread); | |
298 #endif | |
299 | |
300 static sigset_t* unblocked_signals(); | |
301 static sigset_t* vm_signals(); | |
302 static sigset_t* allowdebug_blocked_signals(); | |
303 | |
304 // %%% Following should be promoted to os.hpp: | |
305 // Trace number of created threads | |
306 static jint _os_thread_limit; | |
307 static volatile jint _os_thread_count; | |
308 | |
309 // Minimum stack size a thread can be created with (allowing | |
310 // the VM to completely create the thread and enter user code) | |
311 | |
312 static size_t min_stack_allowed; | |
313 | |
314 // Stack overflow handling | |
315 | |
316 static int max_register_window_saves_before_flushing(); | |
317 | |
318 // Stack repair handling | |
319 | |
320 // none present | |
321 | |
322 }; | |
323 | |
324 class PlatformEvent : public CHeapObj { | |
325 private: | |
326 double CachePad [4] ; // increase odds that _mutex is sole occupant of cache line | |
327 volatile int _Event ; | |
328 int _nParked ; | |
329 int _pipev [2] ; | |
330 mutex_t _mutex [1] ; | |
331 cond_t _cond [1] ; | |
332 double PostPad [2] ; | |
333 | |
334 protected: | |
335 // Defining a protected ctor effectively gives us an abstract base class. | |
336 // That is, a PlatformEvent can never be instantiated "naked" but only | |
337 // as a part of a ParkEvent (recall that ParkEvent extends PlatformEvent). | |
338 // TODO-FIXME: make dtor private | |
339 ~PlatformEvent() { guarantee (0, "invariant") ; } | |
340 PlatformEvent() { | |
341 int status; | |
342 status = os::Solaris::cond_init(_cond); | |
343 assert_status(status == 0, status, "cond_init"); | |
344 status = os::Solaris::mutex_init(_mutex); | |
345 assert_status(status == 0, status, "mutex_init"); | |
346 _Event = 0 ; | |
347 _nParked = 0 ; | |
348 _pipev[0] = _pipev[1] = -1 ; | |
349 } | |
350 | |
351 public: | |
352 // Exercise caution using reset() and fired() -- they may require MEMBARs | |
353 void reset() { _Event = 0 ; } | |
354 int fired() { return _Event; } | |
355 void park () ; | |
356 int park (jlong millis) ; | |
357 int TryPark () ; | |
358 void unpark () ; | |
359 } ; | |
360 | |
361 class PlatformParker : public CHeapObj { | |
362 protected: | |
363 mutex_t _mutex [1] ; | |
364 cond_t _cond [1] ; | |
365 | |
366 public: // TODO-FIXME: make dtor private | |
367 ~PlatformParker() { guarantee (0, "invariant") ; } | |
368 | |
369 public: | |
370 PlatformParker() { | |
371 int status; | |
372 status = os::Solaris::cond_init(_cond); | |
373 assert_status(status == 0, status, "cond_init"); | |
374 status = os::Solaris::mutex_init(_mutex); | |
375 assert_status(status == 0, status, "mutex_init"); | |
376 } | |
377 } ; |