os_aix.hpp revision 9743:d6c6ee9d40b0
1/* 2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 3 * Copyright 2013, 2015 SAP AG. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26#ifndef OS_AIX_VM_OS_AIX_HPP 27#define OS_AIX_VM_OS_AIX_HPP 28 29// Information about the protection of the page at address '0' on this os. 30static bool zero_page_read_protected() { return false; } 31 32// Class Aix defines the interface to the Aix operating systems. 33 34class Aix { 35 friend class os; 36 37 static bool libjsig_is_loaded; // libjsig that interposes sigaction(), 38 // __sigaction(), signal() is loaded 39 static struct sigaction *(*get_signal_action)(int); 40 static struct sigaction *get_preinstalled_handler(int); 41 static void save_preinstalled_handler(int, struct sigaction&); 42 43 static void check_signal_handler(int sig); 44 45 private: 46 47 static julong _physical_memory; 48 static pthread_t _main_thread; 49 static Mutex* _createThread_lock; 50 static int _page_size; 51 52 // Page size of newly created pthreads. 53 static int _stack_page_size; 54 55 // -1 = uninitialized, 0 = AIX, 1 = OS/400 (PASE) 56 static int _on_pase; 57 58 // 0 = uninitialized, otherwise 16 bit number: 59 // lower 8 bit - minor version 60 // higher 8 bit - major version 61 // For AIX, e.g. 0x0601 for AIX 6.1 62 // for OS/400 e.g. 0x0504 for OS/400 V5R4 63 static uint32_t _os_version; 64 65 // -1 = uninitialized, 66 // 0 - SPEC1170 not requested (XPG_SUS_ENV is OFF or not set) 67 // 1 - SPEC1170 requested (XPG_SUS_ENV is ON) 68 static int _xpg_sus_mode; 69 70 // -1 = uninitialized, 71 // 0 - EXTSHM=OFF or not set 72 // 1 - EXTSHM=ON 73 static int _extshm; 74 75 static julong available_memory(); 76 static julong physical_memory() { return _physical_memory; } 77 static void initialize_system_info(); 78 79 // OS recognitions (PASE/AIX, OS level) call this before calling any 80 // one of Aix::on_pase(), Aix::os_version(). 81 static void initialize_os_info(); 82 83 // Scan environment for important settings which might effect the 84 // VM. Trace out settings. Warn about invalid settings and/or 85 // correct them. 86 // 87 // Must run after os::Aix::initialue_os_info(). 88 static void scan_environment(); 89 90 // Initialize libo4 (on PASE) and libperfstat (on AIX). Call this 91 // before relying on functions from either lib, e.g. Aix::get_meminfo(). 92 static void initialize_libo4(); 93 static void initialize_libperfstat(); 94 95 public: 96 static void init_thread_fpu_state(); 97 static pthread_t main_thread(void) { return _main_thread; } 98 static void set_createThread_lock(Mutex* lk) { _createThread_lock = lk; } 99 static Mutex* createThread_lock(void) { return _createThread_lock; } 100 static void hotspot_sigmask(Thread* thread); 101 102 // Given an address, returns the size of the page backing that address 103 static size_t query_pagesize(void* p); 104 105 // Return `true' if the calling thread is the primordial thread. The 106 // primordial thread is the thread which contains the main function, 107 // *not* necessarily the thread which initialized the VM by calling 108 // JNI_CreateJavaVM. 109 static bool is_primordial_thread(void); 110 111 static int page_size(void) { 112 assert(_page_size != -1, "not initialized"); 113 return _page_size; 114 } 115 116 // Accessor methods for stack page size which may be different from usual page size. 117 static int stack_page_size(void) { 118 assert(_stack_page_size != -1, "not initialized"); 119 return _stack_page_size; 120 } 121 122 // This is used to scale stack space (guard pages etc.). The name is somehow misleading. 123 static int vm_default_page_size(void ) { return 8*K; } 124 125 static address ucontext_get_pc(const ucontext_t* uc); 126 static intptr_t* ucontext_get_sp(const ucontext_t* uc); 127 static intptr_t* ucontext_get_fp(const ucontext_t* uc); 128 // Set PC into context. Needed for continuation after signal. 129 static void ucontext_set_pc(ucontext_t* uc, address pc); 130 131 // This boolean allows users to forward their own non-matching signals 132 // to JVM_handle_aix_signal, harmlessly. 133 static bool signal_handlers_are_installed; 134 135 static int get_our_sigflags(int); 136 static void set_our_sigflags(int, int); 137 static void signal_sets_init(); 138 static void install_signal_handlers(); 139 static void set_signal_handler(int, bool); 140 static bool is_sig_ignored(int sig); 141 142 static sigset_t* unblocked_signals(); 143 static sigset_t* vm_signals(); 144 static sigset_t* allowdebug_blocked_signals(); 145 146 // For signal-chaining 147 static struct sigaction *get_chained_signal_action(int sig); 148 static bool chained_handler(int sig, siginfo_t* siginfo, void* context); 149 150 // libpthread version string 151 static void libpthread_init(); 152 153 // Minimum stack size a thread can be created with (allowing 154 // the VM to completely create the thread and enter user code) 155 static size_t min_stack_allowed; 156 157 // Return default stack size or guard size for the specified thread type 158 static size_t default_stack_size(os::ThreadType thr_type); 159 static size_t default_guard_size(os::ThreadType thr_type); 160 161 // Function returns true if we run on OS/400 (pase), false if we run 162 // on AIX. 163 static bool on_pase() { 164 assert(_on_pase != -1, "not initialized"); 165 return _on_pase ? true : false; 166 } 167 168 // Function returns true if we run on AIX, false if we run on OS/400 169 // (pase). 170 static bool on_aix() { 171 assert(_on_pase != -1, "not initialized"); 172 return _on_pase ? false : true; 173 } 174 175 // Get 4 byte AIX kernel version number: 176 // highest 2 bytes: Version, Release 177 // if available: lowest 2 bytes: Tech Level, Service Pack. 178 static uint32_t os_version() { 179 assert(_os_version != 0, "not initialized"); 180 return _os_version; 181 } 182 183 // 0 = uninitialized, otherwise 16 bit number: 184 // lower 8 bit - minor version 185 // higher 8 bit - major version 186 // For AIX, e.g. 0x0601 for AIX 6.1 187 // for OS/400 e.g. 0x0504 for OS/400 V5R4 188 static int os_version_short() { 189 return os_version() >> 16; 190 } 191 192 // Convenience method: returns true if running on PASE V5R4 or older. 193 static bool on_pase_V5R4_or_older() { 194 return on_pase() && os_version_short() <= 0x0504; 195 } 196 197 // Convenience method: returns true if running on AIX 5.3 or older. 198 static bool on_aix_53_or_older() { 199 return on_aix() && os_version_short() <= 0x0503; 200 } 201 202 // Returns true if we run in SPEC1170 compliant mode (XPG_SUS_ENV=ON). 203 static bool xpg_sus_mode() { 204 assert(_xpg_sus_mode != -1, "not initialized"); 205 return _xpg_sus_mode; 206 } 207 208 // Returns true if EXTSHM=ON. 209 static bool extshm() { 210 assert(_extshm != -1, "not initialized"); 211 return _extshm; 212 } 213 214 // result struct for get_meminfo() 215 struct meminfo_t { 216 217 // Amount of virtual memory (in units of 4 KB pages) 218 unsigned long long virt_total; 219 220 // Amount of real memory, in bytes 221 unsigned long long real_total; 222 223 // Amount of free real memory, in bytes 224 unsigned long long real_free; 225 226 // Total amount of paging space, in bytes 227 unsigned long long pgsp_total; 228 229 // Amount of free paging space, in bytes 230 unsigned long long pgsp_free; 231 232 }; 233 234 // Functions to retrieve memory information on AIX, PASE. 235 // (on AIX, using libperfstat, on PASE with libo4.so). 236 // Returns true if ok, false if error. 237 static bool get_meminfo(meminfo_t* pmi); 238 239}; 240 241 242class PlatformEvent : public CHeapObj<mtInternal> { 243 private: 244 double CachePad [4]; // increase odds that _mutex is sole occupant of cache line 245 volatile int _Event; 246 volatile int _nParked; 247 pthread_mutex_t _mutex [1]; 248 pthread_cond_t _cond [1]; 249 double PostPad [2]; 250 Thread * _Assoc; 251 252 public: // TODO-FIXME: make dtor private 253 ~PlatformEvent() { guarantee (0, "invariant"); } 254 255 public: 256 PlatformEvent() { 257 int status; 258 status = pthread_cond_init (_cond, NULL); 259 assert_status(status == 0, status, "cond_init"); 260 status = pthread_mutex_init (_mutex, NULL); 261 assert_status(status == 0, status, "mutex_init"); 262 _Event = 0; 263 _nParked = 0; 264 _Assoc = NULL; 265 } 266 267 // Use caution with reset() and fired() -- they may require MEMBARs 268 void reset() { _Event = 0; } 269 int fired() { return _Event; } 270 void park (); 271 void unpark (); 272 int TryPark (); 273 int park (jlong millis); 274 void SetAssociation (Thread * a) { _Assoc = a; } 275}; 276 277class PlatformParker : public CHeapObj<mtInternal> { 278 protected: 279 pthread_mutex_t _mutex [1]; 280 pthread_cond_t _cond [1]; 281 282 public: // TODO-FIXME: make dtor private 283 ~PlatformParker() { guarantee (0, "invariant"); } 284 285 public: 286 PlatformParker() { 287 int status; 288 status = pthread_cond_init (_cond, NULL); 289 assert_status(status == 0, status, "cond_init"); 290 status = pthread_mutex_init (_mutex, NULL); 291 assert_status(status == 0, status, "mutex_init"); 292 } 293}; 294 295#endif // OS_AIX_VM_OS_AIX_HPP 296