Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/solaris/vm/os_solaris.hpp
32284 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef OS_SOLARIS_VM_OS_SOLARIS_HPP25#define OS_SOLARIS_VM_OS_SOLARIS_HPP2627// Solaris_OS defines the interface to Solaris operating systems2829// Information about the protection of the page at address '0' on this os.30static bool zero_page_read_protected() { return true; }3132class Solaris {33friend class os;3435private:3637// Support for "new" libthread APIs for getting & setting thread context (2.8)38#define TRS_VALID 039#define TRS_NONVOLATILE 140#define TRS_LWPID 241#define TRS_INVALID 34243// _T2_libthread is true if we believe we are running with the newer44// SunSoft lib/lwp/libthread: default Solaris 9, available Solaris 845// which is a lightweight libthread that also supports all T146static bool _T2_libthread;47// These refer to new libthread interface functions48// They get intialized if we dynamically detect new libthread49static int_fnP_thread_t_iP_uP_stack_tP_gregset_t _thr_getstate;50static int_fnP_thread_t_i_gregset_t _thr_setstate;51static int_fnP_thread_t_i _thr_setmutator;52static int_fnP_thread_t _thr_suspend_mutator;53static int_fnP_thread_t _thr_continue_mutator;54// libthread_init sets the above, if the new functionality is detected5556// initialized to libthread or lwp synchronization primitives depending on UseLWPSychronization57static int_fnP_mutex_tP _mutex_lock;58static int_fnP_mutex_tP _mutex_trylock;59static int_fnP_mutex_tP _mutex_unlock;60static int_fnP_mutex_tP_i_vP _mutex_init;61static int_fnP_mutex_tP _mutex_destroy;62static int _mutex_scope;6364static int_fnP_cond_tP_mutex_tP_timestruc_tP _cond_timedwait;65static int_fnP_cond_tP_mutex_tP _cond_wait;66static int_fnP_cond_tP _cond_signal;67static int_fnP_cond_tP _cond_broadcast;68static int_fnP_cond_tP_i_vP _cond_init;69static int_fnP_cond_tP _cond_destroy;70static int _cond_scope;7172typedef uintptr_t lgrp_cookie_t;73typedef id_t lgrp_id_t;74typedef int lgrp_rsrc_t;75typedef enum lgrp_view {76LGRP_VIEW_CALLER, /* what's available to the caller */77LGRP_VIEW_OS /* what's available to operating system */78} lgrp_view_t;7980typedef uint_t (*getisax_func_t)(uint32_t* array, uint_t n);8182typedef lgrp_id_t (*lgrp_home_func_t)(idtype_t idtype, id_t id);83typedef lgrp_cookie_t (*lgrp_init_func_t)(lgrp_view_t view);84typedef int (*lgrp_fini_func_t)(lgrp_cookie_t cookie);85typedef lgrp_id_t (*lgrp_root_func_t)(lgrp_cookie_t cookie);86typedef int (*lgrp_children_func_t)(lgrp_cookie_t cookie, lgrp_id_t parent,87lgrp_id_t *lgrp_array, uint_t lgrp_array_size);88typedef int (*lgrp_resources_func_t)(lgrp_cookie_t cookie, lgrp_id_t lgrp,89lgrp_id_t *lgrp_array, uint_t lgrp_array_size,90lgrp_rsrc_t type);91typedef int (*lgrp_nlgrps_func_t)(lgrp_cookie_t cookie);92typedef int (*lgrp_cookie_stale_func_t)(lgrp_cookie_t cookie);93typedef int (*meminfo_func_t)(const uint64_t inaddr[], int addr_count,94const uint_t info_req[], int info_count,95uint64_t outdata[], uint_t validity[]);9697static getisax_func_t _getisax;9899static lgrp_home_func_t _lgrp_home;100static lgrp_init_func_t _lgrp_init;101static lgrp_fini_func_t _lgrp_fini;102static lgrp_root_func_t _lgrp_root;103static lgrp_children_func_t _lgrp_children;104static lgrp_resources_func_t _lgrp_resources;105static lgrp_nlgrps_func_t _lgrp_nlgrps;106static lgrp_cookie_stale_func_t _lgrp_cookie_stale;107static lgrp_cookie_t _lgrp_cookie;108109static meminfo_func_t _meminfo;110111// Large Page Support112static bool is_valid_page_size(size_t bytes);113static size_t page_size_for_alignment(size_t alignment);114static bool setup_large_pages(caddr_t start, size_t bytes, size_t align);115116static void init_thread_fpu_state(void);117118static void try_enable_extended_io();119120// For signal-chaining121static unsigned long sigs; // mask of signals that have122// preinstalled signal handlers123static struct sigaction *(*get_signal_action)(int);124static struct sigaction *get_preinstalled_handler(int);125static int (*get_libjsig_version)();126static void save_preinstalled_handler(int, struct sigaction&);127static void check_signal_handler(int sig);128// For overridable signals129static int _SIGinterrupt; // user-overridable INTERRUPT_SIGNAL130static int _SIGasync; // user-overridable ASYNC_SIGNAL131static void set_SIGinterrupt(int newsig) { _SIGinterrupt = newsig; }132static void set_SIGasync(int newsig) { _SIGasync = newsig; }133134typedef int (*pthread_setname_np_func_t)(pthread_t, const char*);135static pthread_setname_np_func_t _pthread_setname_np;136137public:138// Large Page Support--ISM.139static bool largepage_range(char* addr, size_t size);140141static int SIGinterrupt() { return _SIGinterrupt; }142static int SIGasync() { return _SIGasync; }143static address handler_start, handler_end; // start and end pc of thr_sighndlrinfo144145static bool valid_stack_address(Thread* thread, address sp);146static bool valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect);147static ucontext_t* get_valid_uc_in_signal_handler(Thread* thread,148ucontext_t* uc);149150static ExtendedPC ucontext_get_ExtendedPC(ucontext_t* uc);151static intptr_t* ucontext_get_sp(ucontext_t* uc);152// ucontext_get_fp() is only used by Solaris X86 (see note below)153static intptr_t* ucontext_get_fp(ucontext_t* uc);154static address ucontext_get_pc(ucontext_t* uc);155156// For Analyzer Forte AsyncGetCallTrace profiling support:157// Parameter ret_fp is only used by Solaris X86.158//159// We should have different declarations of this interface in160// os_solaris_i486.hpp and os_solaris_sparc.hpp, but that file161// provides extensions to the os class and not the Solaris class.162static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc,163intptr_t** ret_sp, intptr_t** ret_fp);164165static void hotspot_sigmask(Thread* thread);166167// SR_handler168static void SR_handler(Thread* thread, ucontext_t* uc);169protected:170// Solaris-specific interface goes here171static julong available_memory();172static julong physical_memory() { return _physical_memory; }173static julong _physical_memory;174static void initialize_system_info();175static int _dev_zero_fd;176static int get_dev_zero_fd() { return _dev_zero_fd; }177static void set_dev_zero_fd(int fd) { _dev_zero_fd = fd; }178static int commit_memory_impl(char* addr, size_t bytes, bool exec);179static int commit_memory_impl(char* addr, size_t bytes,180size_t alignment_hint, bool exec);181static char* mmap_chunk(char *addr, size_t size, int flags, int prot);182static char* anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed);183static bool mpss_sanity_check(bool warn, size_t * page_size);184185// Workaround for 4352906. thr_stksegment sometimes returns186// a bad value for the primordial thread's stack base when187// it is called more than one time.188// Workaround is to cache the initial value to avoid further189// calls to thr_stksegment.190// It appears that someone (Hotspot?) is trashing the user's191// proc_t structure (note that this is a system struct).192static address _main_stack_base;193194static void print_distro_info(outputStream* st);195static void print_libversion_info(outputStream* st);196197public:198static void libthread_init();199static void synchronization_init();200static bool liblgrp_init();201// Load miscellaneous symbols.202static void misc_sym_init();203// This boolean allows users to forward their own non-matching signals204// to JVM_handle_solaris_signal, harmlessly.205static bool signal_handlers_are_installed;206207static void signal_sets_init();208static void install_signal_handlers();209static void set_signal_handler(int sig, bool set_installed, bool oktochain);210static void init_signal_mem();211static bool is_sig_ignored(int sig);212static void set_our_sigflags(int, int);213static int get_our_sigflags(int);214215// For signal-chaining216static bool libjsig_is_loaded; // libjsig that interposes sigaction(),217// signal(), sigset() is loaded218static struct sigaction *get_chained_signal_action(int sig);219static bool chained_handler(int sig, siginfo_t *siginfo, void *context);220221// The following allow us to link against both the old and new libthread (2.8)222// and exploit the new libthread functionality if available.223224static bool T2_libthread() { return _T2_libthread; }225static void set_T2_libthread(bool T2_libthread) { _T2_libthread = T2_libthread; }226227static int thr_getstate(thread_t tid, int *flag, unsigned *lwp, stack_t *ss, gregset_t rs)228{ return _thr_getstate(tid, flag, lwp, ss, rs); }229static void set_thr_getstate(int_fnP_thread_t_iP_uP_stack_tP_gregset_t func)230{ _thr_getstate = func; }231232static int thr_setstate(thread_t tid, int flag, gregset_t rs) { return _thr_setstate(tid, flag, rs); }233static void set_thr_setstate(int_fnP_thread_t_i_gregset_t func) { _thr_setstate = func; }234235static int thr_setmutator(thread_t tid, int enabled) { return _thr_setmutator(tid, enabled); }236static void set_thr_setmutator(int_fnP_thread_t_i func) { _thr_setmutator = func; }237238static int thr_suspend_mutator(thread_t tid) { return _thr_suspend_mutator(tid); }239static void set_thr_suspend_mutator(int_fnP_thread_t func) { _thr_suspend_mutator = func; }240241static int thr_continue_mutator(thread_t tid) { return _thr_continue_mutator(tid); }242static void set_thr_continue_mutator(int_fnP_thread_t func) { _thr_continue_mutator = func; }243244// Allows us to switch between lwp and thread -based synchronization245static int mutex_lock(mutex_t *mx) { return _mutex_lock(mx); }246static int mutex_trylock(mutex_t *mx) { return _mutex_trylock(mx); }247static int mutex_unlock(mutex_t *mx) { return _mutex_unlock(mx); }248static int mutex_init(mutex_t *mx) { return _mutex_init(mx, os::Solaris::mutex_scope(), NULL); }249static int mutex_destroy(mutex_t *mx) { return _mutex_destroy(mx); }250static int mutex_scope() { return _mutex_scope; }251252static void set_mutex_lock(int_fnP_mutex_tP func) { _mutex_lock = func; }253static void set_mutex_trylock(int_fnP_mutex_tP func) { _mutex_trylock = func; }254static void set_mutex_unlock(int_fnP_mutex_tP func) { _mutex_unlock = func; }255static void set_mutex_init(int_fnP_mutex_tP_i_vP func) { _mutex_init = func; }256static void set_mutex_destroy(int_fnP_mutex_tP func) { _mutex_destroy = func; }257static void set_mutex_scope(int scope) { _mutex_scope = scope; }258259static int cond_timedwait(cond_t *cv, mutex_t *mx, timestruc_t *abst)260{ return _cond_timedwait(cv, mx, abst); }261static int cond_wait(cond_t *cv, mutex_t *mx) { return _cond_wait(cv, mx); }262static int cond_signal(cond_t *cv) { return _cond_signal(cv); }263static int cond_broadcast(cond_t *cv) { return _cond_broadcast(cv); }264static int cond_init(cond_t *cv) { return _cond_init(cv, os::Solaris::cond_scope(), NULL); }265static int cond_destroy(cond_t *cv) { return _cond_destroy(cv); }266static int cond_scope() { return _cond_scope; }267268static void set_cond_timedwait(int_fnP_cond_tP_mutex_tP_timestruc_tP func)269{ _cond_timedwait = func; }270static void set_cond_wait(int_fnP_cond_tP_mutex_tP func) { _cond_wait = func; }271static void set_cond_signal(int_fnP_cond_tP func) { _cond_signal = func; }272static void set_cond_broadcast(int_fnP_cond_tP func) { _cond_broadcast = func; }273static void set_cond_init(int_fnP_cond_tP_i_vP func) { _cond_init = func; }274static void set_cond_destroy(int_fnP_cond_tP func) { _cond_destroy = func; }275static void set_cond_scope(int scope) { _cond_scope = scope; }276277static void set_lgrp_home(lgrp_home_func_t func) { _lgrp_home = func; }278static void set_lgrp_init(lgrp_init_func_t func) { _lgrp_init = func; }279static void set_lgrp_fini(lgrp_fini_func_t func) { _lgrp_fini = func; }280static void set_lgrp_root(lgrp_root_func_t func) { _lgrp_root = func; }281static void set_lgrp_children(lgrp_children_func_t func) { _lgrp_children = func; }282static void set_lgrp_resources(lgrp_resources_func_t func) { _lgrp_resources = func; }283static void set_lgrp_nlgrps(lgrp_nlgrps_func_t func) { _lgrp_nlgrps = func; }284static void set_lgrp_cookie_stale(lgrp_cookie_stale_func_t func) { _lgrp_cookie_stale = func; }285static void set_lgrp_cookie(lgrp_cookie_t cookie) { _lgrp_cookie = cookie; }286287static id_t lgrp_home(idtype_t type, id_t id) { return _lgrp_home != NULL ? _lgrp_home(type, id) : -1; }288static lgrp_cookie_t lgrp_init(lgrp_view_t view) { return _lgrp_init != NULL ? _lgrp_init(view) : 0; }289static int lgrp_fini(lgrp_cookie_t cookie) { return _lgrp_fini != NULL ? _lgrp_fini(cookie) : -1; }290static lgrp_id_t lgrp_root(lgrp_cookie_t cookie) { return _lgrp_root != NULL ? _lgrp_root(cookie) : -1; };291static int lgrp_children(lgrp_cookie_t cookie, lgrp_id_t parent,292lgrp_id_t *lgrp_array, uint_t lgrp_array_size) {293return _lgrp_children != NULL ? _lgrp_children(cookie, parent, lgrp_array, lgrp_array_size) : -1;294}295static int lgrp_resources(lgrp_cookie_t cookie, lgrp_id_t lgrp,296lgrp_id_t *lgrp_array, uint_t lgrp_array_size,297lgrp_rsrc_t type) {298return _lgrp_resources != NULL ? _lgrp_resources(cookie, lgrp, lgrp_array, lgrp_array_size, type) : -1;299}300301static int lgrp_nlgrps(lgrp_cookie_t cookie) { return _lgrp_nlgrps != NULL ? _lgrp_nlgrps(cookie) : -1; }302static int lgrp_cookie_stale(lgrp_cookie_t cookie) {303return _lgrp_cookie_stale != NULL ? _lgrp_cookie_stale(cookie) : -1;304}305static lgrp_cookie_t lgrp_cookie() { return _lgrp_cookie; }306307static bool supports_getisax() { return _getisax != NULL; }308static uint_t getisax(uint32_t* array, uint_t n);309310static void set_meminfo(meminfo_func_t func) { _meminfo = func; }311static int meminfo (const uint64_t inaddr[], int addr_count,312const uint_t info_req[], int info_count,313uint64_t outdata[], uint_t validity[]) {314return _meminfo != NULL ? _meminfo(inaddr, addr_count, info_req, info_count,315outdata, validity) : -1;316}317318enum {319clear_interrupted = true320};321static void setup_interruptible(JavaThread* thread);322static void setup_interruptible_already_blocked(JavaThread* thread);323static JavaThread* setup_interruptible();324static void cleanup_interruptible(JavaThread* thread);325326// perf counter incrementers used by _INTERRUPTIBLE327328static void bump_interrupted_before_count();329static void bump_interrupted_during_count();330331#ifdef ASSERT332static JavaThread* setup_interruptible_native();333static void cleanup_interruptible_native(JavaThread* thread);334#endif335336static sigset_t* unblocked_signals();337static sigset_t* vm_signals();338static sigset_t* allowdebug_blocked_signals();339340// %%% Following should be promoted to os.hpp:341// Trace number of created threads342static jint _os_thread_limit;343static volatile jint _os_thread_count;344345// Minimum stack size a thread can be created with (allowing346// the VM to completely create the thread and enter user code)347348static size_t min_stack_allowed;349350// Stack overflow handling351352static int max_register_window_saves_before_flushing();353354// Stack repair handling355356// none present357358};359360class PlatformEvent : public CHeapObj<mtInternal> {361private:362double CachePad [4] ; // increase odds that _mutex is sole occupant of cache line363volatile int _Event ;364int _nParked ;365int _pipev [2] ;366mutex_t _mutex [1] ;367cond_t _cond [1] ;368double PostPad [2] ;369370protected:371// Defining a protected ctor effectively gives us an abstract base class.372// That is, a PlatformEvent can never be instantiated "naked" but only373// as a part of a ParkEvent (recall that ParkEvent extends PlatformEvent).374// TODO-FIXME: make dtor private375~PlatformEvent() { guarantee (0, "invariant") ; }376PlatformEvent() {377int status;378status = os::Solaris::cond_init(_cond);379assert_status(status == 0, status, "cond_init");380status = os::Solaris::mutex_init(_mutex);381assert_status(status == 0, status, "mutex_init");382_Event = 0 ;383_nParked = 0 ;384_pipev[0] = _pipev[1] = -1 ;385}386387public:388// Exercise caution using reset() and fired() -- they may require MEMBARs389void reset() { _Event = 0 ; }390int fired() { return _Event; }391void park () ;392int park (jlong millis) ;393int TryPark () ;394void unpark () ;395} ;396397class PlatformParker : public CHeapObj<mtInternal> {398protected:399mutex_t _mutex [1] ;400cond_t _cond [1] ;401402public: // TODO-FIXME: make dtor private403~PlatformParker() { guarantee (0, "invariant") ; }404405public:406PlatformParker() {407int status;408status = os::Solaris::cond_init(_cond);409assert_status(status == 0, status, "cond_init");410status = os::Solaris::mutex_init(_mutex);411assert_status(status == 0, status, "mutex_init");412}413} ;414415#endif // OS_SOLARIS_VM_OS_SOLARIS_HPP416417418