1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os/aix/vm/os_aix.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,385 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2013 SAP AG. All rights reserved. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#ifndef OS_AIX_VM_OS_AIX_HPP 1.30 +#define OS_AIX_VM_OS_AIX_HPP 1.31 + 1.32 +// Information about the protection of the page at address '0' on this os. 1.33 +static bool zero_page_read_protected() { return false; } 1.34 + 1.35 +// Class Aix defines the interface to the Aix operating systems. 1.36 + 1.37 +class Aix { 1.38 + friend class os; 1.39 + 1.40 + // For signal-chaining 1.41 + // highest so far (AIX 5.2) is SIGSAK (63) 1.42 +#define MAXSIGNUM 63 1.43 + // length of strings included in the libperfstat structures 1.44 +#define IDENTIFIER_LENGTH 64 1.45 + 1.46 + static struct sigaction sigact[MAXSIGNUM]; // saved preinstalled sigactions 1.47 + static unsigned int sigs; // mask of signals that have 1.48 + // preinstalled signal handlers 1.49 + static bool libjsig_is_loaded; // libjsig that interposes sigaction(), 1.50 + // __sigaction(), signal() is loaded 1.51 + static struct sigaction *(*get_signal_action)(int); 1.52 + static struct sigaction *get_preinstalled_handler(int); 1.53 + static void save_preinstalled_handler(int, struct sigaction&); 1.54 + 1.55 + static void check_signal_handler(int sig); 1.56 + 1.57 + // For signal flags diagnostics 1.58 + static int sigflags[MAXSIGNUM]; 1.59 + 1.60 + protected: 1.61 + 1.62 + static julong _physical_memory; 1.63 + static pthread_t _main_thread; 1.64 + static Mutex* _createThread_lock; 1.65 + static int _page_size; 1.66 + static int _logical_cpus; 1.67 + 1.68 + // -1 = uninitialized, 0 = AIX, 1 = OS/400 (PASE) 1.69 + static int _on_pase; 1.70 + 1.71 + // -1 = uninitialized, otherwise 16 bit number: 1.72 + // lower 8 bit - minor version 1.73 + // higher 8 bit - major version 1.74 + // For AIX, e.g. 0x0601 for AIX 6.1 1.75 + // for OS/400 e.g. 0x0504 for OS/400 V5R4 1.76 + static int _os_version; 1.77 + 1.78 + // -1 = uninitialized, 1.79 + // 0 - SPEC1170 not requested (XPG_SUS_ENV is OFF or not set) 1.80 + // 1 - SPEC1170 requested (XPG_SUS_ENV is ON) 1.81 + static int _xpg_sus_mode; 1.82 + 1.83 + // -1 = uninitialized, 1.84 + // 0 - EXTSHM=OFF or not set 1.85 + // 1 - EXTSHM=ON 1.86 + static int _extshm; 1.87 + 1.88 + // page sizes on AIX. 1.89 + // 1.90 + // AIX supports four different page sizes - 4K, 64K, 16MB, 16GB. The latter two 1.91 + // (16M "large" resp. 16G "huge" pages) require special setup and are normally 1.92 + // not available. 1.93 + // 1.94 + // AIX supports multiple page sizes per process, for: 1.95 + // - Stack (of the primordial thread, so not relevant for us) 1.96 + // - Data - data, bss, heap, for us also pthread stacks 1.97 + // - Text - text code 1.98 + // - shared memory 1.99 + // 1.100 + // Default page sizes can be set via linker options (-bdatapsize, -bstacksize, ...) 1.101 + // and via environment variable LDR_CNTRL (DATAPSIZE, STACKPSIZE, ...) 1.102 + // 1.103 + // For shared memory, page size can be set dynamically via shmctl(). Different shared memory 1.104 + // regions can have different page sizes. 1.105 + // 1.106 + // More information can be found at AIBM info center: 1.107 + // http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/multiple_page_size_app_support.htm 1.108 + // 1.109 + // ----- 1.110 + // We want to support 4K and 64K and, if the machine is set up correctly, 16MB pages. 1.111 + // 1.112 + 1.113 + // page size of the stack of newly created pthreads 1.114 + // (should be LDR_CNTRL DATAPSIZE because stack is allocated on heap by pthread lib) 1.115 + static int _stack_page_size; 1.116 + 1.117 + // Default shm page size. Read: what page size shared memory will be backed 1.118 + // with if no page size was set explicitly using shmctl(SHM_PAGESIZE). 1.119 + // Should be LDR_CNTRL SHMPSIZE. 1.120 + static size_t _shm_default_page_size; 1.121 + 1.122 + // True if sys V shm can be used with 64K pages dynamically. 1.123 + // (via shmctl(.. SHM_PAGESIZE..). Should be true for AIX 53 and 1.124 + // newer / PASE V6R1 and newer. (0 or 1, -1 if not initialized) 1.125 + static int _can_use_64K_pages; 1.126 + 1.127 + // True if sys V shm can be used with 16M pages dynamically. 1.128 + // (via shmctl(.. SHM_PAGESIZE..). Only true on AIX 5.3 and 1.129 + // newer, if the system was set up to use 16M pages and the 1.130 + // jvm has enough user rights. (0 or 1, -1 if not initialized) 1.131 + static int _can_use_16M_pages; 1.132 + 1.133 + static julong available_memory(); 1.134 + static julong physical_memory() { return _physical_memory; } 1.135 + static void initialize_system_info(); 1.136 + 1.137 + // OS recognitions (PASE/AIX, OS level) call this before calling any 1.138 + // one of Aix::on_pase(), Aix::os_version(). 1.139 + static void initialize_os_info(); 1.140 + 1.141 + static int commit_memory_impl(char* addr, size_t bytes, bool exec); 1.142 + static int commit_memory_impl(char* addr, size_t bytes, 1.143 + size_t alignment_hint, bool exec); 1.144 + 1.145 + // Scan environment for important settings which might effect the 1.146 + // VM. Trace out settings. Warn about invalid settings and/or 1.147 + // correct them. 1.148 + // 1.149 + // Must run after os::Aix::initialue_os_info(). 1.150 + static void scan_environment(); 1.151 + 1.152 + // Retrieve information about multipage size support. Will initialize 1.153 + // _page_size, _stack_page_size, _can_use_64K_pages/_can_use_16M_pages 1.154 + static void query_multipage_support(); 1.155 + 1.156 + // Initialize libo4 (on PASE) and libperfstat (on AIX). Call this 1.157 + // before relying on functions from either lib, e.g. Aix::get_meminfo(). 1.158 + static void initialize_libo4(); 1.159 + static void initialize_libperfstat(); 1.160 + 1.161 + static bool supports_variable_stack_size(); 1.162 + 1.163 + public: 1.164 + static void init_thread_fpu_state(); 1.165 + static pthread_t main_thread(void) { return _main_thread; } 1.166 + // returns kernel thread id (similar to LWP id on Solaris), which can be 1.167 + // used to access /proc 1.168 + static pid_t gettid(); 1.169 + static void set_createThread_lock(Mutex* lk) { _createThread_lock = lk; } 1.170 + static Mutex* createThread_lock(void) { return _createThread_lock; } 1.171 + static void hotspot_sigmask(Thread* thread); 1.172 + 1.173 + // Given an address, returns the size of the page backing that address 1.174 + static size_t query_pagesize(void* p); 1.175 + 1.176 + // Return `true' if the calling thread is the primordial thread. The 1.177 + // primordial thread is the thread which contains the main function, 1.178 + // *not* necessarily the thread which initialized the VM by calling 1.179 + // JNI_CreateJavaVM. 1.180 + static bool is_primordial_thread(void); 1.181 + 1.182 + static int page_size(void) { 1.183 + assert(_page_size != -1, "not initialized"); 1.184 + return _page_size; 1.185 + } 1.186 + 1.187 + // Accessor methods for stack page size which may be different from usual page size. 1.188 + static int stack_page_size(void) { 1.189 + assert(_stack_page_size != -1, "not initialized"); 1.190 + return _stack_page_size; 1.191 + } 1.192 + 1.193 + // default shm page size. Read: what page size shared memory 1.194 + // will be backed with if no page size was set explicitly using shmctl(SHM_PAGESIZE). 1.195 + // Should be LDR_CNTRL SHMPSIZE. 1.196 + static int shm_default_page_size(void) { 1.197 + assert(_shm_default_page_size != -1, "not initialized"); 1.198 + return _shm_default_page_size; 1.199 + } 1.200 + 1.201 + // Return true if sys V shm can be used with 64K pages dynamically 1.202 + // (via shmctl(.. SHM_PAGESIZE..). 1.203 + static bool can_use_64K_pages () { 1.204 + assert(_can_use_64K_pages != -1, "not initialized"); 1.205 + return _can_use_64K_pages == 1 ? true : false; 1.206 + } 1.207 + 1.208 + // Return true if sys V shm can be used with 16M pages dynamically. 1.209 + // (via shmctl(.. SHM_PAGESIZE..). 1.210 + static bool can_use_16M_pages () { 1.211 + assert(_can_use_16M_pages != -1, "not initialized"); 1.212 + return _can_use_16M_pages == 1 ? true : false; 1.213 + } 1.214 + 1.215 + static address ucontext_get_pc(ucontext_t* uc); 1.216 + static intptr_t* ucontext_get_sp(ucontext_t* uc); 1.217 + static intptr_t* ucontext_get_fp(ucontext_t* uc); 1.218 + // Set PC into context. Needed for continuation after signal. 1.219 + static void ucontext_set_pc(ucontext_t* uc, address pc); 1.220 + 1.221 + // This boolean allows users to forward their own non-matching signals 1.222 + // to JVM_handle_aix_signal, harmlessly. 1.223 + static bool signal_handlers_are_installed; 1.224 + 1.225 + static int get_our_sigflags(int); 1.226 + static void set_our_sigflags(int, int); 1.227 + static void signal_sets_init(); 1.228 + static void install_signal_handlers(); 1.229 + static void set_signal_handler(int, bool); 1.230 + static bool is_sig_ignored(int sig); 1.231 + 1.232 + static sigset_t* unblocked_signals(); 1.233 + static sigset_t* vm_signals(); 1.234 + static sigset_t* allowdebug_blocked_signals(); 1.235 + 1.236 + // For signal-chaining 1.237 + static struct sigaction *get_chained_signal_action(int sig); 1.238 + static bool chained_handler(int sig, siginfo_t* siginfo, void* context); 1.239 + 1.240 + // libpthread version string 1.241 + static void libpthread_init(); 1.242 + 1.243 + // Minimum stack size a thread can be created with (allowing 1.244 + // the VM to completely create the thread and enter user code) 1.245 + static size_t min_stack_allowed; 1.246 + 1.247 + // Return default stack size or guard size for the specified thread type 1.248 + static size_t default_stack_size(os::ThreadType thr_type); 1.249 + static size_t default_guard_size(os::ThreadType thr_type); 1.250 + 1.251 + // Function returns true if we run on OS/400 (pase), false if we run 1.252 + // on AIX. 1.253 + static bool on_pase() { 1.254 + assert(_on_pase != -1, "not initialized"); 1.255 + return _on_pase ? true : false; 1.256 + } 1.257 + 1.258 + // Function returns true if we run on AIX, false if we run on OS/400 1.259 + // (pase). 1.260 + static bool on_aix() { 1.261 + assert(_on_pase != -1, "not initialized"); 1.262 + return _on_pase ? false : true; 1.263 + } 1.264 + 1.265 + // -1 = uninitialized, otherwise 16 bit number: 1.266 + // lower 8 bit - minor version 1.267 + // higher 8 bit - major version 1.268 + // For AIX, e.g. 0x0601 for AIX 6.1 1.269 + // for OS/400 e.g. 0x0504 for OS/400 V5R4 1.270 + static int os_version () { 1.271 + assert(_os_version != -1, "not initialized"); 1.272 + return _os_version; 1.273 + } 1.274 + 1.275 + // Convenience method: returns true if running on AIX 5.3 or older. 1.276 + static bool on_aix_53_or_older() { 1.277 + return on_aix() && os_version() <= 0x0503; 1.278 + } 1.279 + 1.280 + // Returns true if we run in SPEC1170 compliant mode (XPG_SUS_ENV=ON). 1.281 + static bool xpg_sus_mode() { 1.282 + assert(_xpg_sus_mode != -1, "not initialized"); 1.283 + return _xpg_sus_mode; 1.284 + } 1.285 + 1.286 + // Returns true if EXTSHM=ON. 1.287 + static bool extshm() { 1.288 + assert(_extshm != -1, "not initialized"); 1.289 + return _extshm; 1.290 + } 1.291 + 1.292 + // result struct for get_meminfo() 1.293 + struct meminfo_t { 1.294 + 1.295 + // Amount of virtual memory (in units of 4 KB pages) 1.296 + unsigned long long virt_total; 1.297 + 1.298 + // Amount of real memory, in bytes 1.299 + unsigned long long real_total; 1.300 + 1.301 + // Amount of free real memory, in bytes 1.302 + unsigned long long real_free; 1.303 + 1.304 + // Total amount of paging space, in bytes 1.305 + unsigned long long pgsp_total; 1.306 + 1.307 + // Amount of free paging space, in bytes 1.308 + unsigned long long pgsp_free; 1.309 + 1.310 + }; 1.311 + 1.312 + // Result struct for get_cpuinfo(). 1.313 + struct cpuinfo_t { 1.314 + char description[IDENTIFIER_LENGTH]; // processor description (type/official name) 1.315 + u_longlong_t processorHZ; // processor speed in Hz 1.316 + int ncpus; // number of active logical processors 1.317 + double loadavg[3]; // (1<<SBITS) times the average number of runnables processes during the last 1, 5 and 15 minutes. 1.318 + // To calculate the load average, divide the numbers by (1<<SBITS). SBITS is defined in <sys/proc.h>. 1.319 + char version[20]; // processor version from _system_configuration (sys/systemcfg.h) 1.320 + }; 1.321 + 1.322 + // Functions to retrieve memory information on AIX, PASE. 1.323 + // (on AIX, using libperfstat, on PASE with libo4.so). 1.324 + // Returns true if ok, false if error. 1.325 + static bool get_meminfo(meminfo_t* pmi); 1.326 + 1.327 + // Function to retrieve cpu information on AIX 1.328 + // (on AIX, using libperfstat) 1.329 + // Returns true if ok, false if error. 1.330 + static bool get_cpuinfo(cpuinfo_t* pci); 1.331 + 1.332 +}; // os::Aix class 1.333 + 1.334 + 1.335 +class PlatformEvent : public CHeapObj<mtInternal> { 1.336 + private: 1.337 + double CachePad [4]; // increase odds that _mutex is sole occupant of cache line 1.338 + volatile int _Event; 1.339 + volatile int _nParked; 1.340 + pthread_mutex_t _mutex [1]; 1.341 + pthread_cond_t _cond [1]; 1.342 + double PostPad [2]; 1.343 + Thread * _Assoc; 1.344 + 1.345 + public: // TODO-FIXME: make dtor private 1.346 + ~PlatformEvent() { guarantee (0, "invariant"); } 1.347 + 1.348 + public: 1.349 + PlatformEvent() { 1.350 + int status; 1.351 + status = pthread_cond_init (_cond, NULL); 1.352 + assert_status(status == 0, status, "cond_init"); 1.353 + status = pthread_mutex_init (_mutex, NULL); 1.354 + assert_status(status == 0, status, "mutex_init"); 1.355 + _Event = 0; 1.356 + _nParked = 0; 1.357 + _Assoc = NULL; 1.358 + } 1.359 + 1.360 + // Use caution with reset() and fired() -- they may require MEMBARs 1.361 + void reset() { _Event = 0; } 1.362 + int fired() { return _Event; } 1.363 + void park (); 1.364 + void unpark (); 1.365 + int TryPark (); 1.366 + int park (jlong millis); 1.367 + void SetAssociation (Thread * a) { _Assoc = a; } 1.368 +}; 1.369 + 1.370 +class PlatformParker : public CHeapObj<mtInternal> { 1.371 + protected: 1.372 + pthread_mutex_t _mutex [1]; 1.373 + pthread_cond_t _cond [1]; 1.374 + 1.375 + public: // TODO-FIXME: make dtor private 1.376 + ~PlatformParker() { guarantee (0, "invariant"); } 1.377 + 1.378 + public: 1.379 + PlatformParker() { 1.380 + int status; 1.381 + status = pthread_cond_init (_cond, NULL); 1.382 + assert_status(status == 0, status, "cond_init"); 1.383 + status = pthread_mutex_init (_mutex, NULL); 1.384 + assert_status(status == 0, status, "mutex_init"); 1.385 + } 1.386 +}; 1.387 + 1.388 +#endif // OS_AIX_VM_OS_AIX_HPP