1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os/solaris/vm/os_solaris.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,377 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// Solaris_OS defines the interface to Solaris operating systems 1.29 + 1.30 +class Solaris { 1.31 + friend class os; 1.32 + 1.33 + private: 1.34 + 1.35 + // Support for "new" libthread APIs for getting & setting thread context (2.8) 1.36 + #define TRS_VALID 0 1.37 + #define TRS_NONVOLATILE 1 1.38 + #define TRS_LWPID 2 1.39 + #define TRS_INVALID 3 1.40 + 1.41 + // _T2_libthread is true if we believe we are running with the newer 1.42 + // SunSoft lib/lwp/libthread: default Solaris 9, available Solaris 8 1.43 + // which is a lightweight libthread that also supports all T1 1.44 + static bool _T2_libthread; 1.45 + // These refer to new libthread interface functions 1.46 + // They get intialized if we dynamically detect new libthread 1.47 + static int_fnP_thread_t_iP_uP_stack_tP_gregset_t _thr_getstate; 1.48 + static int_fnP_thread_t_i_gregset_t _thr_setstate; 1.49 + static int_fnP_thread_t_i _thr_setmutator; 1.50 + static int_fnP_thread_t _thr_suspend_mutator; 1.51 + static int_fnP_thread_t _thr_continue_mutator; 1.52 + // libthread_init sets the above, if the new functionality is detected 1.53 + 1.54 + // initialized to libthread or lwp synchronization primitives depending on UseLWPSychronization 1.55 + static int_fnP_mutex_tP _mutex_lock; 1.56 + static int_fnP_mutex_tP _mutex_trylock; 1.57 + static int_fnP_mutex_tP _mutex_unlock; 1.58 + static int_fnP_mutex_tP_i_vP _mutex_init; 1.59 + static int_fnP_mutex_tP _mutex_destroy; 1.60 + static int _mutex_scope; 1.61 + 1.62 + static int_fnP_cond_tP_mutex_tP_timestruc_tP _cond_timedwait; 1.63 + static int_fnP_cond_tP_mutex_tP _cond_wait; 1.64 + static int_fnP_cond_tP _cond_signal; 1.65 + static int_fnP_cond_tP _cond_broadcast; 1.66 + static int_fnP_cond_tP_i_vP _cond_init; 1.67 + static int_fnP_cond_tP _cond_destroy; 1.68 + static int _cond_scope; 1.69 + 1.70 + typedef uintptr_t lgrp_cookie_t; 1.71 + typedef id_t lgrp_id_t; 1.72 + typedef enum lgrp_view { 1.73 + LGRP_VIEW_CALLER, /* what's available to the caller */ 1.74 + LGRP_VIEW_OS /* what's available to operating system */ 1.75 + } lgrp_view_t; 1.76 + 1.77 + typedef lgrp_id_t (*lgrp_home_func_t)(idtype_t idtype, id_t id); 1.78 + typedef lgrp_cookie_t (*lgrp_init_func_t)(lgrp_view_t view); 1.79 + typedef int (*lgrp_fini_func_t)(lgrp_cookie_t cookie); 1.80 + typedef lgrp_id_t (*lgrp_root_func_t)(lgrp_cookie_t cookie); 1.81 + typedef int (*lgrp_children_func_t)(lgrp_cookie_t cookie, lgrp_id_t parent, 1.82 + lgrp_id_t *lgrp_array, uint_t lgrp_array_size); 1.83 + typedef int (*lgrp_nlgrps_func_t)(lgrp_cookie_t cookie); 1.84 + typedef int (*lgrp_cookie_stale_func_t)(lgrp_cookie_t cookie); 1.85 + typedef int (*meminfo_func_t)(const uint64_t inaddr[], int addr_count, 1.86 + const uint_t info_req[], int info_count, 1.87 + uint64_t outdata[], uint_t validity[]); 1.88 + 1.89 + static lgrp_home_func_t _lgrp_home; 1.90 + static lgrp_init_func_t _lgrp_init; 1.91 + static lgrp_fini_func_t _lgrp_fini; 1.92 + static lgrp_root_func_t _lgrp_root; 1.93 + static lgrp_children_func_t _lgrp_children; 1.94 + static lgrp_nlgrps_func_t _lgrp_nlgrps; 1.95 + static lgrp_cookie_stale_func_t _lgrp_cookie_stale; 1.96 + static lgrp_cookie_t _lgrp_cookie; 1.97 + 1.98 + static meminfo_func_t _meminfo; 1.99 + 1.100 + // Large Page Support--mpss. 1.101 + static bool set_mpss_range(caddr_t start, size_t bytes, size_t align); 1.102 + 1.103 + static void init_thread_fpu_state(void); 1.104 + 1.105 + static void try_enable_extended_io(); 1.106 + 1.107 + // For signal-chaining 1.108 + static unsigned long sigs; // mask of signals that have 1.109 + // preinstalled signal handlers 1.110 + static struct sigaction *(*get_signal_action)(int); 1.111 + static struct sigaction *get_preinstalled_handler(int); 1.112 + static int (*get_libjsig_version)(); 1.113 + static void save_preinstalled_handler(int, struct sigaction&); 1.114 + static void check_signal_handler(int sig); 1.115 + 1.116 + // For overridable signals 1.117 + static int _SIGinterrupt; // user-overridable INTERRUPT_SIGNAL 1.118 + static int _SIGasync; // user-overridable ASYNC_SIGNAL 1.119 + static void set_SIGinterrupt(int newsig) { _SIGinterrupt = newsig; } 1.120 + static void set_SIGasync(int newsig) { _SIGasync = newsig; } 1.121 + 1.122 + 1.123 + public: 1.124 + // Large Page Support--ISM. 1.125 + static bool largepage_range(char* addr, size_t size); 1.126 + 1.127 + static int SIGinterrupt() { return _SIGinterrupt; } 1.128 + static int SIGasync() { return _SIGasync; } 1.129 + static address handler_start, handler_end; // start and end pc of thr_sighndlrinfo 1.130 + 1.131 + static bool valid_stack_address(Thread* thread, address sp); 1.132 + static bool valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect); 1.133 + static ucontext_t* get_valid_uc_in_signal_handler(Thread* thread, 1.134 + ucontext_t* uc); 1.135 + 1.136 + static ExtendedPC ucontext_get_ExtendedPC(ucontext_t* uc); 1.137 + static intptr_t* ucontext_get_sp(ucontext_t* uc); 1.138 + // ucontext_get_fp() is only used by Solaris X86 (see note below) 1.139 + static intptr_t* ucontext_get_fp(ucontext_t* uc); 1.140 + 1.141 + // For Analyzer Forte AsyncGetCallTrace profiling support: 1.142 + // Parameter ret_fp is only used by Solaris X86. 1.143 + // 1.144 + // We should have different declarations of this interface in 1.145 + // os_solaris_i486.hpp and os_solaris_sparc.hpp, but that file 1.146 + // provides extensions to the os class and not the Solaris class. 1.147 + static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc, 1.148 + intptr_t** ret_sp, intptr_t** ret_fp); 1.149 + 1.150 + static void hotspot_sigmask(Thread* thread); 1.151 + 1.152 + protected: 1.153 + // Solaris-specific interface goes here 1.154 + static julong available_memory(); 1.155 + static julong physical_memory() { return _physical_memory; } 1.156 + static julong _physical_memory; 1.157 + static void initialize_system_info(); 1.158 + static int _dev_zero_fd; 1.159 + static int get_dev_zero_fd() { return _dev_zero_fd; } 1.160 + static void set_dev_zero_fd(int fd) { _dev_zero_fd = fd; } 1.161 + static char* mmap_chunk(char *addr, size_t size, int flags, int prot); 1.162 + static bool mpss_sanity_check(bool warn, size_t * page_size); 1.163 + static bool ism_sanity_check (bool warn, size_t * page_size); 1.164 + 1.165 + // Workaround for 4352906. thr_stksegment sometimes returns 1.166 + // a bad value for the primordial thread's stack base when 1.167 + // it is called more than one time. 1.168 + // Workaround is to cache the initial value to avoid further 1.169 + // calls to thr_stksegment. 1.170 + // It appears that someone (Hotspot?) is trashing the user's 1.171 + // proc_t structure (note that this is a system struct). 1.172 + static address _main_stack_base; 1.173 + 1.174 + public: 1.175 + static void libthread_init(); 1.176 + static void synchronization_init(); 1.177 + static void liblgrp_init(); 1.178 + // Load miscellaneous symbols. 1.179 + static void misc_sym_init(); 1.180 + // This boolean allows users to forward their own non-matching signals 1.181 + // to JVM_handle_solaris_signal, harmlessly. 1.182 + static bool signal_handlers_are_installed; 1.183 + 1.184 + static void signal_sets_init(); 1.185 + static void install_signal_handlers(); 1.186 + static void set_signal_handler(int sig, bool set_installed, bool oktochain); 1.187 + static void init_signal_mem(); 1.188 + static bool is_sig_ignored(int sig); 1.189 + static void set_our_sigflags(int, int); 1.190 + static int get_our_sigflags(int); 1.191 + 1.192 + // For signal-chaining 1.193 + static bool libjsig_is_loaded; // libjsig that interposes sigaction(), 1.194 + // signal(), sigset() is loaded 1.195 + static struct sigaction *get_chained_signal_action(int sig); 1.196 + static bool chained_handler(int sig, siginfo_t *siginfo, void *context); 1.197 + 1.198 + // The following allow us to link against both the old and new libthread (2.8) 1.199 + // and exploit the new libthread functionality if available. 1.200 + 1.201 + static bool T2_libthread() { return _T2_libthread; } 1.202 + static void set_T2_libthread(bool T2_libthread) { _T2_libthread = T2_libthread; } 1.203 + 1.204 + static int thr_getstate(thread_t tid, int *flag, unsigned *lwp, stack_t *ss, gregset_t rs) 1.205 + { return _thr_getstate(tid, flag, lwp, ss, rs); } 1.206 + static void set_thr_getstate(int_fnP_thread_t_iP_uP_stack_tP_gregset_t func) 1.207 + { _thr_getstate = func; } 1.208 + 1.209 + static int thr_setstate(thread_t tid, int flag, gregset_t rs) { return _thr_setstate(tid, flag, rs); } 1.210 + static void set_thr_setstate(int_fnP_thread_t_i_gregset_t func) { _thr_setstate = func; } 1.211 + 1.212 + static int thr_setmutator(thread_t tid, int enabled) { return _thr_setmutator(tid, enabled); } 1.213 + static void set_thr_setmutator(int_fnP_thread_t_i func) { _thr_setmutator = func; } 1.214 + 1.215 + static int thr_suspend_mutator(thread_t tid) { return _thr_suspend_mutator(tid); } 1.216 + static void set_thr_suspend_mutator(int_fnP_thread_t func) { _thr_suspend_mutator = func; } 1.217 + 1.218 + static int thr_continue_mutator(thread_t tid) { return _thr_continue_mutator(tid); } 1.219 + static void set_thr_continue_mutator(int_fnP_thread_t func) { _thr_continue_mutator = func; } 1.220 + 1.221 + // Allows us to switch between lwp and thread -based synchronization 1.222 + static int mutex_lock(mutex_t *mx) { return _mutex_lock(mx); } 1.223 + static int mutex_trylock(mutex_t *mx) { return _mutex_trylock(mx); } 1.224 + static int mutex_unlock(mutex_t *mx) { return _mutex_unlock(mx); } 1.225 + static int mutex_init(mutex_t *mx) { return _mutex_init(mx, os::Solaris::mutex_scope(), NULL); } 1.226 + static int mutex_destroy(mutex_t *mx) { return _mutex_destroy(mx); } 1.227 + static int mutex_scope() { return _mutex_scope; } 1.228 + 1.229 + static void set_mutex_lock(int_fnP_mutex_tP func) { _mutex_lock = func; } 1.230 + static void set_mutex_trylock(int_fnP_mutex_tP func) { _mutex_trylock = func; } 1.231 + static void set_mutex_unlock(int_fnP_mutex_tP func) { _mutex_unlock = func; } 1.232 + static void set_mutex_init(int_fnP_mutex_tP_i_vP func) { _mutex_init = func; } 1.233 + static void set_mutex_destroy(int_fnP_mutex_tP func) { _mutex_destroy = func; } 1.234 + static void set_mutex_scope(int scope) { _mutex_scope = scope; } 1.235 + 1.236 + static int cond_timedwait(cond_t *cv, mutex_t *mx, timestruc_t *abst) 1.237 + { return _cond_timedwait(cv, mx, abst); } 1.238 + static int cond_wait(cond_t *cv, mutex_t *mx) { return _cond_wait(cv, mx); } 1.239 + static int cond_signal(cond_t *cv) { return _cond_signal(cv); } 1.240 + static int cond_broadcast(cond_t *cv) { return _cond_broadcast(cv); } 1.241 + static int cond_init(cond_t *cv) { return _cond_init(cv, os::Solaris::cond_scope(), NULL); } 1.242 + static int cond_destroy(cond_t *cv) { return _cond_destroy(cv); } 1.243 + static int cond_scope() { return _cond_scope; } 1.244 + 1.245 + static void set_cond_timedwait(int_fnP_cond_tP_mutex_tP_timestruc_tP func) 1.246 + { _cond_timedwait = func; } 1.247 + static void set_cond_wait(int_fnP_cond_tP_mutex_tP func) { _cond_wait = func; } 1.248 + static void set_cond_signal(int_fnP_cond_tP func) { _cond_signal = func; } 1.249 + static void set_cond_broadcast(int_fnP_cond_tP func) { _cond_broadcast = func; } 1.250 + static void set_cond_init(int_fnP_cond_tP_i_vP func) { _cond_init = func; } 1.251 + static void set_cond_destroy(int_fnP_cond_tP func) { _cond_destroy = func; } 1.252 + static void set_cond_scope(int scope) { _cond_scope = scope; } 1.253 + 1.254 + static void set_lgrp_home(lgrp_home_func_t func) { _lgrp_home = func; } 1.255 + static void set_lgrp_init(lgrp_init_func_t func) { _lgrp_init = func; } 1.256 + static void set_lgrp_fini(lgrp_fini_func_t func) { _lgrp_fini = func; } 1.257 + static void set_lgrp_root(lgrp_root_func_t func) { _lgrp_root = func; } 1.258 + static void set_lgrp_children(lgrp_children_func_t func) { _lgrp_children = func; } 1.259 + static void set_lgrp_nlgrps(lgrp_nlgrps_func_t func) { _lgrp_nlgrps = func; } 1.260 + static void set_lgrp_cookie_stale(lgrp_cookie_stale_func_t func) { _lgrp_cookie_stale = func; } 1.261 + static void set_lgrp_cookie(lgrp_cookie_t cookie) { _lgrp_cookie = cookie; } 1.262 + 1.263 + static id_t lgrp_home(idtype_t type, id_t id) { return _lgrp_home != NULL ? _lgrp_home(type, id) : -1; } 1.264 + static lgrp_cookie_t lgrp_init(lgrp_view_t view) { return _lgrp_init != NULL ? _lgrp_init(view) : 0; } 1.265 + static int lgrp_fini(lgrp_cookie_t cookie) { return _lgrp_fini != NULL ? _lgrp_fini(cookie) : -1; } 1.266 + static lgrp_id_t lgrp_root(lgrp_cookie_t cookie) { return _lgrp_root != NULL ? _lgrp_root(cookie) : -1; }; 1.267 + static int lgrp_children(lgrp_cookie_t cookie, lgrp_id_t parent, 1.268 + lgrp_id_t *lgrp_array, uint_t lgrp_array_size) { 1.269 + return _lgrp_children != NULL ? _lgrp_children(cookie, parent, lgrp_array, lgrp_array_size) : -1; 1.270 + } 1.271 + static int lgrp_nlgrps(lgrp_cookie_t cookie) { return _lgrp_nlgrps != NULL ? _lgrp_nlgrps(cookie) : -1; } 1.272 + static int lgrp_cookie_stale(lgrp_cookie_t cookie) { 1.273 + return _lgrp_cookie_stale != NULL ? _lgrp_cookie_stale(cookie) : -1; 1.274 + } 1.275 + static lgrp_cookie_t lgrp_cookie() { return _lgrp_cookie; } 1.276 + 1.277 + static void set_meminfo(meminfo_func_t func) { _meminfo = func; } 1.278 + static int meminfo (const uint64_t inaddr[], int addr_count, 1.279 + const uint_t info_req[], int info_count, 1.280 + uint64_t outdata[], uint_t validity[]) { 1.281 + return _meminfo != NULL ? _meminfo(inaddr, addr_count, info_req, info_count, 1.282 + outdata, validity) : -1; 1.283 + } 1.284 + 1.285 + enum { 1.286 + clear_interrupted = true 1.287 + }; 1.288 + static void setup_interruptible(JavaThread* thread); 1.289 + static void setup_interruptible_already_blocked(JavaThread* thread); 1.290 + static JavaThread* setup_interruptible(); 1.291 + static void cleanup_interruptible(JavaThread* thread); 1.292 + 1.293 + // perf counter incrementers used by _INTERRUPTIBLE 1.294 + 1.295 + static void bump_interrupted_before_count(); 1.296 + static void bump_interrupted_during_count(); 1.297 + 1.298 +#ifdef ASSERT 1.299 + static JavaThread* setup_interruptible_native(); 1.300 + static void cleanup_interruptible_native(JavaThread* thread); 1.301 +#endif 1.302 + 1.303 + static sigset_t* unblocked_signals(); 1.304 + static sigset_t* vm_signals(); 1.305 + static sigset_t* allowdebug_blocked_signals(); 1.306 + 1.307 + // %%% Following should be promoted to os.hpp: 1.308 + // Trace number of created threads 1.309 + static jint _os_thread_limit; 1.310 + static volatile jint _os_thread_count; 1.311 + 1.312 + // Minimum stack size a thread can be created with (allowing 1.313 + // the VM to completely create the thread and enter user code) 1.314 + 1.315 + static size_t min_stack_allowed; 1.316 + 1.317 + // Stack overflow handling 1.318 + 1.319 + static int max_register_window_saves_before_flushing(); 1.320 + 1.321 + // Stack repair handling 1.322 + 1.323 + // none present 1.324 + 1.325 +}; 1.326 + 1.327 +class PlatformEvent : public CHeapObj { 1.328 + private: 1.329 + double CachePad [4] ; // increase odds that _mutex is sole occupant of cache line 1.330 + volatile int _Event ; 1.331 + int _nParked ; 1.332 + int _pipev [2] ; 1.333 + mutex_t _mutex [1] ; 1.334 + cond_t _cond [1] ; 1.335 + double PostPad [2] ; 1.336 + 1.337 + protected: 1.338 + // Defining a protected ctor effectively gives us an abstract base class. 1.339 + // That is, a PlatformEvent can never be instantiated "naked" but only 1.340 + // as a part of a ParkEvent (recall that ParkEvent extends PlatformEvent). 1.341 + // TODO-FIXME: make dtor private 1.342 + ~PlatformEvent() { guarantee (0, "invariant") ; } 1.343 + PlatformEvent() { 1.344 + int status; 1.345 + status = os::Solaris::cond_init(_cond); 1.346 + assert_status(status == 0, status, "cond_init"); 1.347 + status = os::Solaris::mutex_init(_mutex); 1.348 + assert_status(status == 0, status, "mutex_init"); 1.349 + _Event = 0 ; 1.350 + _nParked = 0 ; 1.351 + _pipev[0] = _pipev[1] = -1 ; 1.352 + } 1.353 + 1.354 + public: 1.355 + // Exercise caution using reset() and fired() -- they may require MEMBARs 1.356 + void reset() { _Event = 0 ; } 1.357 + int fired() { return _Event; } 1.358 + void park () ; 1.359 + int park (jlong millis) ; 1.360 + int TryPark () ; 1.361 + void unpark () ; 1.362 +} ; 1.363 + 1.364 +class PlatformParker : public CHeapObj { 1.365 + protected: 1.366 + mutex_t _mutex [1] ; 1.367 + cond_t _cond [1] ; 1.368 + 1.369 + public: // TODO-FIXME: make dtor private 1.370 + ~PlatformParker() { guarantee (0, "invariant") ; } 1.371 + 1.372 + public: 1.373 + PlatformParker() { 1.374 + int status; 1.375 + status = os::Solaris::cond_init(_cond); 1.376 + assert_status(status == 0, status, "cond_init"); 1.377 + status = os::Solaris::mutex_init(_mutex); 1.378 + assert_status(status == 0, status, "mutex_init"); 1.379 + } 1.380 +} ;