annotate src/os/solaris/vm/os_solaris.hpp @ 0:a61af66fc99e

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