os_solaris.hpp revision 7050:03835eaaab2d
1125410Sgrehan/* 2125410Sgrehan * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 3125410Sgrehan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4125410Sgrehan * 5125410Sgrehan * This code is free software; you can redistribute it and/or modify it 6125410Sgrehan * under the terms of the GNU General Public License version 2 only, as 7125410Sgrehan * published by the Free Software Foundation. 8125410Sgrehan * 9125410Sgrehan * This code is distributed in the hope that it will be useful, but WITHOUT 10125410Sgrehan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11125410Sgrehan * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12125410Sgrehan * version 2 for more details (a copy is included in the LICENSE file that 13125410Sgrehan * accompanied this code). 14125410Sgrehan * 15125410Sgrehan * You should have received a copy of the GNU General Public License version 16125410Sgrehan * 2 along with this work; if not, write to the Free Software Foundation, 17125410Sgrehan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18199243Sed * 19125410Sgrehan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20125410Sgrehan * or visit www.oracle.com if you need additional information or have any 21125410Sgrehan * questions. 22125410Sgrehan * 23125410Sgrehan */ 24125410Sgrehan 25125410Sgrehan#ifndef OS_SOLARIS_VM_OS_SOLARIS_HPP 26125410Sgrehan#define OS_SOLARIS_VM_OS_SOLARIS_HPP 27125410Sgrehan 28125410Sgrehan// Solaris_OS defines the interface to Solaris operating systems 29125410Sgrehan 30125410Sgrehan// Information about the protection of the page at address '0' on this os. 31125410Sgrehanstatic bool zero_page_read_protected() { return true; } 32125410Sgrehan 33199243Sedclass Solaris { 34125410Sgrehan friend class os; 35199243Sed 36199243Sed private: 37199243Sed 38199243Sed // Support for "new" libthread APIs for getting & setting thread context (2.8) 39199243Sed #define TRS_VALID 0 40199243Sed #define TRS_NONVOLATILE 1 41199243Sed #define TRS_LWPID 2 42170088Sdougb #define TRS_INVALID 3 43125410Sgrehan 44125410Sgrehan // initialized to libthread or lwp synchronization primitives depending on UseLWPSychronization 45166250Smarcel static int_fnP_mutex_tP _mutex_lock; 46166250Smarcel static int_fnP_mutex_tP _mutex_trylock; 47166250Smarcel static int_fnP_mutex_tP _mutex_unlock; 48166250Smarcel static int_fnP_mutex_tP_i_vP _mutex_init; 49125410Sgrehan static int_fnP_mutex_tP _mutex_destroy; 50125410Sgrehan static int _mutex_scope; 51125410Sgrehan 52182104Sed static int_fnP_cond_tP_mutex_tP_timestruc_tP _cond_timedwait; 53182104Sed static int_fnP_cond_tP_mutex_tP _cond_wait; 54182104Sed static int_fnP_cond_tP _cond_signal; 55182104Sed static int_fnP_cond_tP _cond_broadcast; 56182104Sed static int_fnP_cond_tP_i_vP _cond_init; 57182104Sed static int_fnP_cond_tP _cond_destroy; 58182104Sed static int _cond_scope; 59182104Sed 60182104Sed typedef uintptr_t lgrp_cookie_t; 61182104Sed typedef id_t lgrp_id_t; 62182104Sed typedef int lgrp_rsrc_t; 63182104Sed typedef enum lgrp_view { 64182104Sed LGRP_VIEW_CALLER, /* what's available to the caller */ 65182104Sed LGRP_VIEW_OS /* what's available to operating system */ 66182104Sed } lgrp_view_t; 67182104Sed 68182104Sed typedef uint_t (*getisax_func_t)(uint32_t* array, uint_t n); 69182104Sed 70182104Sed typedef lgrp_id_t (*lgrp_home_func_t)(idtype_t idtype, id_t id); 71182104Sed typedef lgrp_cookie_t (*lgrp_init_func_t)(lgrp_view_t view); 72182104Sed typedef int (*lgrp_fini_func_t)(lgrp_cookie_t cookie); 73182104Sed typedef lgrp_id_t (*lgrp_root_func_t)(lgrp_cookie_t cookie); 74182104Sed typedef int (*lgrp_children_func_t)(lgrp_cookie_t cookie, lgrp_id_t parent, 75182104Sed lgrp_id_t *lgrp_array, uint_t lgrp_array_size); 76182104Sed typedef int (*lgrp_resources_func_t)(lgrp_cookie_t cookie, lgrp_id_t lgrp, 77182104Sed lgrp_id_t *lgrp_array, uint_t lgrp_array_size, 78182104Sed lgrp_rsrc_t type); 79182104Sed typedef int (*lgrp_nlgrps_func_t)(lgrp_cookie_t cookie); 80182104Sed typedef int (*lgrp_cookie_stale_func_t)(lgrp_cookie_t cookie); 81182104Sed typedef int (*meminfo_func_t)(const uint64_t inaddr[], int addr_count, 82182104Sed const uint_t info_req[], int info_count, 83182104Sed uint64_t outdata[], uint_t validity[]); 84182104Sed 85182104Sed static getisax_func_t _getisax; 86182104Sed 87182104Sed static lgrp_home_func_t _lgrp_home; 88182104Sed static lgrp_init_func_t _lgrp_init; 89182104Sed static lgrp_fini_func_t _lgrp_fini; 90182104Sed static lgrp_root_func_t _lgrp_root; 91182104Sed static lgrp_children_func_t _lgrp_children; 92182104Sed static lgrp_resources_func_t _lgrp_resources; 93182104Sed static lgrp_nlgrps_func_t _lgrp_nlgrps; 94182104Sed static lgrp_cookie_stale_func_t _lgrp_cookie_stale; 95182104Sed static lgrp_cookie_t _lgrp_cookie; 96182104Sed 97182104Sed static meminfo_func_t _meminfo; 98182104Sed 99182104Sed // Large Page Support 100182104Sed static bool setup_large_pages(caddr_t start, size_t bytes, size_t align); 101182104Sed 102182104Sed static void init_thread_fpu_state(void); 103182104Sed 104182104Sed static void try_enable_extended_io(); 105182104Sed 106182104Sed // For signal-chaining 107182104Sed static unsigned long sigs; // mask of signals that have 108182104Sed // preinstalled signal handlers 109182104Sed static struct sigaction *(*get_signal_action)(int); 110182104Sed static struct sigaction *get_preinstalled_handler(int); 111182104Sed static int (*get_libjsig_version)(); 112182104Sed static void save_preinstalled_handler(int, struct sigaction&); 113182104Sed static void check_signal_handler(int sig); 114182104Sed // For overridable signals 115182104Sed static int _SIGinterrupt; // user-overridable INTERRUPT_SIGNAL 116182104Sed static int _SIGasync; // user-overridable ASYNC_SIGNAL 117182104Sed static void set_SIGinterrupt(int newsig) { _SIGinterrupt = newsig; } 118182104Sed static void set_SIGasync(int newsig) { _SIGasync = newsig; } 119182104Sed 120182104Sed public: 121182104Sed // Large Page Support--ISM. 122182104Sed static bool largepage_range(char* addr, size_t size); 123182104Sed 124182104Sed static int SIGinterrupt() { return _SIGinterrupt; } 125182104Sed static int SIGasync() { return _SIGasync; } 126182104Sed static address handler_start, handler_end; // start and end pc of thr_sighndlrinfo 127182104Sed 128182104Sed static bool valid_stack_address(Thread* thread, address sp); 129182104Sed static bool valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect); 130182104Sed static ucontext_t* get_valid_uc_in_signal_handler(Thread* thread, 131182104Sed ucontext_t* uc); 132182104Sed 133182104Sed static ExtendedPC ucontext_get_ExtendedPC(ucontext_t* uc); 134182104Sed static intptr_t* ucontext_get_sp(ucontext_t* uc); 135182104Sed // ucontext_get_fp() is only used by Solaris X86 (see note below) 136182104Sed static intptr_t* ucontext_get_fp(ucontext_t* uc); 137182104Sed static address ucontext_get_pc(ucontext_t* uc); 138182104Sed 139182104Sed // For Analyzer Forte AsyncGetCallTrace profiling support: 140182104Sed // Parameter ret_fp is only used by Solaris X86. 141182104Sed // 142182104Sed // We should have different declarations of this interface in 143182104Sed // os_solaris_i486.hpp and os_solaris_sparc.hpp, but that file 144182104Sed // provides extensions to the os class and not the Solaris class. 145182104Sed static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc, 146182104Sed intptr_t** ret_sp, intptr_t** ret_fp); 147182104Sed 148182104Sed static void hotspot_sigmask(Thread* thread); 149182104Sed 150182104Sed // SR_handler 151182104Sed static void SR_handler(Thread* thread, ucontext_t* uc); 152182104Sed protected: 153182104Sed // Solaris-specific interface goes here 154182104Sed static julong available_memory(); 155182104Sed static julong physical_memory() { return _physical_memory; } 156182104Sed static julong _physical_memory; 157182104Sed static void initialize_system_info(); 158182104Sed static int _dev_zero_fd; 159182104Sed static int get_dev_zero_fd() { return _dev_zero_fd; } 160182104Sed static void set_dev_zero_fd(int fd) { _dev_zero_fd = fd; } 161182104Sed static int commit_memory_impl(char* addr, size_t bytes, bool exec); 162182104Sed static int commit_memory_impl(char* addr, size_t bytes, 163182104Sed size_t alignment_hint, bool exec); 164182104Sed static char* mmap_chunk(char *addr, size_t size, int flags, int prot); 165182104Sed static char* anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed); 166182104Sed static bool mpss_sanity_check(bool warn, size_t * page_size); 167182104Sed 168182104Sed // Workaround for 4352906. thr_stksegment sometimes returns 169182104Sed // a bad value for the primordial thread's stack base when 170182104Sed // it is called more than one time. 171182104Sed // Workaround is to cache the initial value to avoid further 172182104Sed // calls to thr_stksegment. 173182104Sed // It appears that someone (Hotspot?) is trashing the user's 174182104Sed // proc_t structure (note that this is a system struct). 175182104Sed static address _main_stack_base; 176182104Sed 177182104Sed static void print_distro_info(outputStream* st); 178182104Sed static void print_libversion_info(outputStream* st); 179182104Sed 180182104Sed public: 181182104Sed static void libthread_init(); 182182104Sed static void synchronization_init(); 183182104Sed static bool liblgrp_init(); 184182104Sed // Load miscellaneous symbols. 185182104Sed static void misc_sym_init(); 186182104Sed // This boolean allows users to forward their own non-matching signals 187182104Sed // to JVM_handle_solaris_signal, harmlessly. 188182104Sed static bool signal_handlers_are_installed; 189182104Sed 190182104Sed static void signal_sets_init(); 191182104Sed static void install_signal_handlers(); 192182104Sed static void set_signal_handler(int sig, bool set_installed, bool oktochain); 193182104Sed static void init_signal_mem(); 194182104Sed static bool is_sig_ignored(int sig); 195182104Sed static void set_our_sigflags(int, int); 196182104Sed static int get_our_sigflags(int); 197182104Sed 198182104Sed // For signal-chaining 199182104Sed static bool libjsig_is_loaded; // libjsig that interposes sigaction(), 200182104Sed // signal(), sigset() is loaded 201182104Sed static struct sigaction *get_chained_signal_action(int sig); 202182104Sed static bool chained_handler(int sig, siginfo_t *siginfo, void *context); 203182104Sed 204182104Sed // Allows us to switch between lwp and thread -based synchronization 205182104Sed static int mutex_lock(mutex_t *mx) { return _mutex_lock(mx); } 206182104Sed static int mutex_trylock(mutex_t *mx) { return _mutex_trylock(mx); } 207182104Sed static int mutex_unlock(mutex_t *mx) { return _mutex_unlock(mx); } 208182104Sed static int mutex_init(mutex_t *mx) { return _mutex_init(mx, os::Solaris::mutex_scope(), NULL); } 209182104Sed static int mutex_destroy(mutex_t *mx) { return _mutex_destroy(mx); } 210182104Sed static int mutex_scope() { return _mutex_scope; } 211182104Sed 212182104Sed static void set_mutex_lock(int_fnP_mutex_tP func) { _mutex_lock = func; } 213182104Sed static void set_mutex_trylock(int_fnP_mutex_tP func) { _mutex_trylock = func; } 214182104Sed static void set_mutex_unlock(int_fnP_mutex_tP func) { _mutex_unlock = func; } 215182104Sed static void set_mutex_init(int_fnP_mutex_tP_i_vP func) { _mutex_init = func; } 216182104Sed static void set_mutex_destroy(int_fnP_mutex_tP func) { _mutex_destroy = func; } 217182104Sed static void set_mutex_scope(int scope) { _mutex_scope = scope; } 218182104Sed 219182104Sed static int cond_timedwait(cond_t *cv, mutex_t *mx, timestruc_t *abst) 220182104Sed { return _cond_timedwait(cv, mx, abst); } 221182104Sed static int cond_wait(cond_t *cv, mutex_t *mx) { return _cond_wait(cv, mx); } 222182104Sed static int cond_signal(cond_t *cv) { return _cond_signal(cv); } 223182104Sed static int cond_broadcast(cond_t *cv) { return _cond_broadcast(cv); } 224182104Sed static int cond_init(cond_t *cv) { return _cond_init(cv, os::Solaris::cond_scope(), NULL); } 225182104Sed static int cond_destroy(cond_t *cv) { return _cond_destroy(cv); } 226182104Sed static int cond_scope() { return _cond_scope; } 227182104Sed 228182104Sed static void set_cond_timedwait(int_fnP_cond_tP_mutex_tP_timestruc_tP func) 229182104Sed { _cond_timedwait = func; } 230182104Sed static void set_cond_wait(int_fnP_cond_tP_mutex_tP func) { _cond_wait = func; } 231182104Sed static void set_cond_signal(int_fnP_cond_tP func) { _cond_signal = func; } 232182104Sed static void set_cond_broadcast(int_fnP_cond_tP func) { _cond_broadcast = func; } 233182104Sed static void set_cond_init(int_fnP_cond_tP_i_vP func) { _cond_init = func; } 234182104Sed static void set_cond_destroy(int_fnP_cond_tP func) { _cond_destroy = func; } 235182104Sed static void set_cond_scope(int scope) { _cond_scope = scope; } 236182104Sed 237182104Sed static void set_lgrp_home(lgrp_home_func_t func) { _lgrp_home = func; } 238182104Sed static void set_lgrp_init(lgrp_init_func_t func) { _lgrp_init = func; } 239182104Sed static void set_lgrp_fini(lgrp_fini_func_t func) { _lgrp_fini = func; } 240182104Sed static void set_lgrp_root(lgrp_root_func_t func) { _lgrp_root = func; } 241182104Sed static void set_lgrp_children(lgrp_children_func_t func) { _lgrp_children = func; } 242182104Sed static void set_lgrp_resources(lgrp_resources_func_t func) { _lgrp_resources = func; } 243182104Sed static void set_lgrp_nlgrps(lgrp_nlgrps_func_t func) { _lgrp_nlgrps = func; } 244182104Sed static void set_lgrp_cookie_stale(lgrp_cookie_stale_func_t func) { _lgrp_cookie_stale = func; } 245182104Sed static void set_lgrp_cookie(lgrp_cookie_t cookie) { _lgrp_cookie = cookie; } 246182104Sed 247182104Sed static id_t lgrp_home(idtype_t type, id_t id) { return _lgrp_home != NULL ? _lgrp_home(type, id) : -1; } 248182104Sed static lgrp_cookie_t lgrp_init(lgrp_view_t view) { return _lgrp_init != NULL ? _lgrp_init(view) : 0; } 249182104Sed static int lgrp_fini(lgrp_cookie_t cookie) { return _lgrp_fini != NULL ? _lgrp_fini(cookie) : -1; } 250182104Sed static lgrp_id_t lgrp_root(lgrp_cookie_t cookie) { return _lgrp_root != NULL ? _lgrp_root(cookie) : -1; }; 251182104Sed static int lgrp_children(lgrp_cookie_t cookie, lgrp_id_t parent, 252182104Sed lgrp_id_t *lgrp_array, uint_t lgrp_array_size) { 253182104Sed return _lgrp_children != NULL ? _lgrp_children(cookie, parent, lgrp_array, lgrp_array_size) : -1; 254182104Sed } 255182104Sed static int lgrp_resources(lgrp_cookie_t cookie, lgrp_id_t lgrp, 256182104Sed lgrp_id_t *lgrp_array, uint_t lgrp_array_size, 257182104Sed lgrp_rsrc_t type) { 258182104Sed return _lgrp_resources != NULL ? _lgrp_resources(cookie, lgrp, lgrp_array, lgrp_array_size, type) : -1; 259182104Sed } 260182104Sed 261182104Sed static int lgrp_nlgrps(lgrp_cookie_t cookie) { return _lgrp_nlgrps != NULL ? _lgrp_nlgrps(cookie) : -1; } 262182104Sed static int lgrp_cookie_stale(lgrp_cookie_t cookie) { 263182104Sed return _lgrp_cookie_stale != NULL ? _lgrp_cookie_stale(cookie) : -1; 264182104Sed } 265182104Sed static lgrp_cookie_t lgrp_cookie() { return _lgrp_cookie; } 266182104Sed 267182104Sed static bool supports_getisax() { return _getisax != NULL; } 268182104Sed static uint_t getisax(uint32_t* array, uint_t n); 269182104Sed 270182104Sed static void set_meminfo(meminfo_func_t func) { _meminfo = func; } 271182104Sed static int meminfo (const uint64_t inaddr[], int addr_count, 272182104Sed const uint_t info_req[], int info_count, 273182104Sed uint64_t outdata[], uint_t validity[]) { 274182104Sed return _meminfo != NULL ? _meminfo(inaddr, addr_count, info_req, info_count, 275182104Sed outdata, validity) : -1; 276182104Sed } 277182104Sed 278182104Sed static sigset_t* unblocked_signals(); 279182104Sed static sigset_t* vm_signals(); 280182104Sed static sigset_t* allowdebug_blocked_signals(); 281182104Sed 282182104Sed // %%% Following should be promoted to os.hpp: 283182104Sed // Trace number of created threads 284182104Sed static jint _os_thread_limit; 285182104Sed static volatile jint _os_thread_count; 286182104Sed 287182104Sed // Minimum stack size a thread can be created with (allowing 288182104Sed // the VM to completely create the thread and enter user code) 289182104Sed 290182104Sed static size_t min_stack_allowed; 291182104Sed 292182104Sed // Stack overflow handling 293182104Sed 294182104Sed static int max_register_window_saves_before_flushing(); 295182104Sed 296182104Sed // Stack repair handling 297182104Sed 298182104Sed // none present 299182104Sed 300182104Sed}; 301182104Sed 302182104Sedclass PlatformEvent : public CHeapObj<mtInternal> { 303182104Sed private: 304182104Sed double CachePad[4]; // increase odds that _mutex is sole occupant of cache line 305182104Sed volatile int _Event; 306182104Sed int _nParked; 307182104Sed int _pipev[2]; 308 mutex_t _mutex[1]; 309 cond_t _cond[1]; 310 double PostPad[2]; 311 312 protected: 313 // Defining a protected ctor effectively gives us an abstract base class. 314 // That is, a PlatformEvent can never be instantiated "naked" but only 315 // as a part of a ParkEvent (recall that ParkEvent extends PlatformEvent). 316 // TODO-FIXME: make dtor private 317 ~PlatformEvent() { guarantee(0, "invariant"); } 318 PlatformEvent() { 319 int status; 320 status = os::Solaris::cond_init(_cond); 321 assert_status(status == 0, status, "cond_init"); 322 status = os::Solaris::mutex_init(_mutex); 323 assert_status(status == 0, status, "mutex_init"); 324 _Event = 0; 325 _nParked = 0; 326 _pipev[0] = _pipev[1] = -1; 327 } 328 329 public: 330 // Exercise caution using reset() and fired() -- they may require MEMBARs 331 void reset() { _Event = 0; } 332 int fired() { return _Event; } 333 void park(); 334 int park(jlong millis); 335 void unpark(); 336}; 337 338class PlatformParker : public CHeapObj<mtInternal> { 339 protected: 340 mutex_t _mutex[1]; 341 cond_t _cond[1]; 342 343 public: // TODO-FIXME: make dtor private 344 ~PlatformParker() { guarantee(0, "invariant"); } 345 346 public: 347 PlatformParker() { 348 int status; 349 status = os::Solaris::cond_init(_cond); 350 assert_status(status == 0, status, "cond_init"); 351 status = os::Solaris::mutex_init(_mutex); 352 assert_status(status == 0, status, "mutex_init"); 353 } 354}; 355 356#endif // OS_SOLARIS_VM_OS_SOLARIS_HPP 357