Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/bsd/vm/os_bsd.hpp
32285 views
/*1* Copyright (c) 1999, 2018, 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_BSD_VM_OS_BSD_HPP25#define OS_BSD_VM_OS_BSD_HPP2627// Bsd_OS defines the interface to Bsd operating systems2829// Information about the protection of the page at address '0' on this os.30static bool zero_page_read_protected() { return true; }3132/* pthread_getattr_np comes with BsdThreads-0.9-7 on RedHat 7.1 */33typedef int (*pthread_getattr_func_type) (pthread_t, pthread_attr_t *);3435#ifdef __APPLE__36// Mac OS X doesn't support clock_gettime. Stub out the type, it is37// unused38typedef int clockid_t;39#endif4041class Bsd {42friend class os;4344// For signal-chaining45#define MAXSIGNUM 3246static struct sigaction sigact[MAXSIGNUM]; // saved preinstalled sigactions47static unsigned int sigs; // mask of signals that have48// preinstalled signal handlers49static bool libjsig_is_loaded; // libjsig that interposes sigaction(),50// __sigaction(), signal() is loaded51static struct sigaction *(*get_signal_action)(int);52static struct sigaction *get_preinstalled_handler(int);53static void save_preinstalled_handler(int, struct sigaction&);5455static void check_signal_handler(int sig);5657// For signal flags diagnostics58static int sigflags[MAXSIGNUM];5960#ifdef __APPLE__61// mach_absolute_time62static mach_timebase_info_data_t _timebase_info;63static volatile uint64_t _max_abstime;64#else65static int (*_clock_gettime)(clockid_t, struct timespec *);66#endif6768static GrowableArray<int>* _cpu_to_node;6970protected:7172static julong _physical_memory;73static pthread_t _main_thread;74static int _page_size;7576static julong available_memory();77static julong physical_memory() { return _physical_memory; }78static void initialize_system_info();7980static bool supports_variable_stack_size();8182static void rebuild_cpu_to_node_map();83static GrowableArray<int>* cpu_to_node() { return _cpu_to_node; }8485static bool hugetlbfs_sanity_check(bool warn, size_t page_size);8687public:8889static void init_thread_fpu_state();90static pthread_t main_thread(void) { return _main_thread; }9192static void hotspot_sigmask(Thread* thread);9394static pid_t gettid();9596static int page_size(void) { return _page_size; }97static void set_page_size(int val) { _page_size = val; }9899static address ucontext_get_pc(ucontext_t* uc);100static intptr_t* ucontext_get_sp(ucontext_t* uc);101static intptr_t* ucontext_get_fp(ucontext_t* uc);102103// For Analyzer Forte AsyncGetCallTrace profiling support:104//105// This interface should be declared in os_bsd_i486.hpp, but106// that file provides extensions to the os class and not the107// Bsd class.108static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc,109intptr_t** ret_sp, intptr_t** ret_fp);110111// This boolean allows users to forward their own non-matching signals112// to JVM_handle_bsd_signal, harmlessly.113static bool signal_handlers_are_installed;114115static int get_our_sigflags(int);116static void set_our_sigflags(int, int);117static void signal_sets_init();118static void install_signal_handlers();119static void set_signal_handler(int, bool);120static bool is_sig_ignored(int sig);121122static sigset_t* unblocked_signals();123static sigset_t* vm_signals();124static sigset_t* allowdebug_blocked_signals();125126// For signal-chaining127static struct sigaction *get_chained_signal_action(int sig);128static bool chained_handler(int sig, siginfo_t* siginfo, void* context);129130// Minimum stack size a thread can be created with (allowing131// the VM to completely create the thread and enter user code)132static size_t min_stack_allowed;133134// Return default stack size or guard size for the specified thread type135static size_t default_stack_size(os::ThreadType thr_type);136static size_t default_guard_size(os::ThreadType thr_type);137138// Real-time clock functions139static void clock_init(void);140141static inline bool supports_monotonic_clock() {142#ifdef __APPLE__143return true;144#else145return _clock_gettime != NULL;146#endif147}148149// Stack repair handling150151// none present152153// BsdThreads work-around for 6292965154static int safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime);155156private:157typedef int (*sched_getcpu_func_t)(void);158typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);159typedef int (*numa_max_node_func_t)(void);160typedef int (*numa_available_func_t)(void);161typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);162typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);163164static sched_getcpu_func_t _sched_getcpu;165static numa_node_to_cpus_func_t _numa_node_to_cpus;166static numa_max_node_func_t _numa_max_node;167static numa_available_func_t _numa_available;168static numa_tonode_memory_func_t _numa_tonode_memory;169static numa_interleave_memory_func_t _numa_interleave_memory;170static unsigned long* _numa_all_nodes;171172static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }173static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }174static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }175static void set_numa_available(numa_available_func_t func) { _numa_available = func; }176static void set_numa_tonode_memory(numa_tonode_memory_func_t func) { _numa_tonode_memory = func; }177static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; }178static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; }179public:180static int sched_getcpu() { return _sched_getcpu != NULL ? _sched_getcpu() : -1; }181static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) {182return _numa_node_to_cpus != NULL ? _numa_node_to_cpus(node, buffer, bufferlen) : -1;183}184static int numa_max_node() { return _numa_max_node != NULL ? _numa_max_node() : -1; }185static int numa_available() { return _numa_available != NULL ? _numa_available() : -1; }186static int numa_tonode_memory(void *start, size_t size, int node) {187return _numa_tonode_memory != NULL ? _numa_tonode_memory(start, size, node) : -1;188}189static void numa_interleave_memory(void *start, size_t size) {190if (_numa_interleave_memory != NULL && _numa_all_nodes != NULL) {191_numa_interleave_memory(start, size, _numa_all_nodes);192}193}194static int get_node_by_cpu(int cpu_id);195};196197198class PlatformEvent : public CHeapObj<mtInternal> {199private:200double CachePad [4] ; // increase odds that _mutex is sole occupant of cache line201volatile int _Event ;202volatile int _nParked ;203pthread_mutex_t _mutex [1] ;204pthread_cond_t _cond [1] ;205double PostPad [2] ;206Thread * _Assoc ;207208public: // TODO-FIXME: make dtor private209~PlatformEvent() { guarantee (0, "invariant") ; }210211public:212PlatformEvent() {213int status;214status = pthread_cond_init (_cond, NULL);215assert_status(status == 0, status, "cond_init");216status = pthread_mutex_init (_mutex, NULL);217assert_status(status == 0, status, "mutex_init");218_Event = 0 ;219_nParked = 0 ;220_Assoc = NULL ;221}222223// Use caution with reset() and fired() -- they may require MEMBARs224void reset() { _Event = 0 ; }225int fired() { return _Event; }226void park () ;227void unpark () ;228int TryPark () ;229int park (jlong millis) ;230void SetAssociation (Thread * a) { _Assoc = a ; }231};232233class PlatformParker : public CHeapObj<mtInternal> {234protected:235pthread_mutex_t _mutex [1] ;236pthread_cond_t _cond [1] ;237238public: // TODO-FIXME: make dtor private239~PlatformParker() { guarantee (0, "invariant") ; }240241public:242PlatformParker() {243int status;244status = pthread_cond_init (_cond, NULL);245assert_status(status == 0, status, "cond_init");246status = pthread_mutex_init (_mutex, NULL);247assert_status(status == 0, status, "mutex_init");248}249};250251#endif // OS_BSD_VM_OS_BSD_HPP252253254