src/os/aix/vm/os_aix.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 7424
c5e86c5cd22e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * Copyright 2013 SAP AG. All rights reserved.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #ifndef OS_AIX_VM_OS_AIX_HPP
aoqi@0 27 #define OS_AIX_VM_OS_AIX_HPP
aoqi@0 28
aoqi@0 29 // Information about the protection of the page at address '0' on this os.
aoqi@0 30 static bool zero_page_read_protected() { return false; }
aoqi@0 31
aoqi@0 32 // Class Aix defines the interface to the Aix operating systems.
aoqi@0 33
aoqi@0 34 class Aix {
aoqi@0 35 friend class os;
aoqi@0 36
aoqi@0 37 // For signal-chaining
aoqi@0 38 // highest so far (AIX 5.2) is SIGSAK (63)
aoqi@0 39 #define MAXSIGNUM 63
aoqi@0 40 // length of strings included in the libperfstat structures
aoqi@0 41 #define IDENTIFIER_LENGTH 64
aoqi@0 42
aoqi@0 43 static struct sigaction sigact[MAXSIGNUM]; // saved preinstalled sigactions
aoqi@0 44 static unsigned int sigs; // mask of signals that have
aoqi@0 45 // preinstalled signal handlers
aoqi@0 46 static bool libjsig_is_loaded; // libjsig that interposes sigaction(),
aoqi@0 47 // __sigaction(), signal() is loaded
aoqi@0 48 static struct sigaction *(*get_signal_action)(int);
aoqi@0 49 static struct sigaction *get_preinstalled_handler(int);
aoqi@0 50 static void save_preinstalled_handler(int, struct sigaction&);
aoqi@0 51
aoqi@0 52 static void check_signal_handler(int sig);
aoqi@0 53
aoqi@0 54 // For signal flags diagnostics
aoqi@0 55 static int sigflags[MAXSIGNUM];
aoqi@0 56
aoqi@0 57 protected:
aoqi@0 58
aoqi@0 59 static julong _physical_memory;
aoqi@0 60 static pthread_t _main_thread;
aoqi@0 61 static Mutex* _createThread_lock;
aoqi@0 62 static int _page_size;
aoqi@0 63 static int _logical_cpus;
aoqi@0 64
aoqi@0 65 // -1 = uninitialized, 0 = AIX, 1 = OS/400 (PASE)
aoqi@0 66 static int _on_pase;
aoqi@0 67
aoqi@0 68 // -1 = uninitialized, otherwise 16 bit number:
aoqi@0 69 // lower 8 bit - minor version
aoqi@0 70 // higher 8 bit - major version
aoqi@0 71 // For AIX, e.g. 0x0601 for AIX 6.1
aoqi@0 72 // for OS/400 e.g. 0x0504 for OS/400 V5R4
aoqi@0 73 static int _os_version;
aoqi@0 74
aoqi@0 75 // -1 = uninitialized,
aoqi@0 76 // 0 - SPEC1170 not requested (XPG_SUS_ENV is OFF or not set)
aoqi@0 77 // 1 - SPEC1170 requested (XPG_SUS_ENV is ON)
aoqi@0 78 static int _xpg_sus_mode;
aoqi@0 79
aoqi@0 80 // -1 = uninitialized,
aoqi@0 81 // 0 - EXTSHM=OFF or not set
aoqi@0 82 // 1 - EXTSHM=ON
aoqi@0 83 static int _extshm;
aoqi@0 84
aoqi@0 85 // page sizes on AIX.
aoqi@0 86 //
aoqi@0 87 // AIX supports four different page sizes - 4K, 64K, 16MB, 16GB. The latter two
aoqi@0 88 // (16M "large" resp. 16G "huge" pages) require special setup and are normally
aoqi@0 89 // not available.
aoqi@0 90 //
aoqi@0 91 // AIX supports multiple page sizes per process, for:
aoqi@0 92 // - Stack (of the primordial thread, so not relevant for us)
aoqi@0 93 // - Data - data, bss, heap, for us also pthread stacks
aoqi@0 94 // - Text - text code
aoqi@0 95 // - shared memory
aoqi@0 96 //
aoqi@0 97 // Default page sizes can be set via linker options (-bdatapsize, -bstacksize, ...)
aoqi@0 98 // and via environment variable LDR_CNTRL (DATAPSIZE, STACKPSIZE, ...)
aoqi@0 99 //
aoqi@0 100 // For shared memory, page size can be set dynamically via shmctl(). Different shared memory
aoqi@0 101 // regions can have different page sizes.
aoqi@0 102 //
aoqi@0 103 // More information can be found at AIBM info center:
aoqi@0 104 // http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/multiple_page_size_app_support.htm
aoqi@0 105 //
aoqi@0 106 // -----
aoqi@0 107 // We want to support 4K and 64K and, if the machine is set up correctly, 16MB pages.
aoqi@0 108 //
aoqi@0 109
aoqi@0 110 // page size of the stack of newly created pthreads
aoqi@0 111 // (should be LDR_CNTRL DATAPSIZE because stack is allocated on heap by pthread lib)
aoqi@0 112 static int _stack_page_size;
aoqi@0 113
aoqi@0 114 // Default shm page size. Read: what page size shared memory will be backed
aoqi@0 115 // with if no page size was set explicitly using shmctl(SHM_PAGESIZE).
aoqi@0 116 // Should be LDR_CNTRL SHMPSIZE.
aoqi@0 117 static size_t _shm_default_page_size;
aoqi@0 118
aoqi@0 119 // True if sys V shm can be used with 64K pages dynamically.
aoqi@0 120 // (via shmctl(.. SHM_PAGESIZE..). Should be true for AIX 53 and
aoqi@0 121 // newer / PASE V6R1 and newer. (0 or 1, -1 if not initialized)
aoqi@0 122 static int _can_use_64K_pages;
aoqi@0 123
aoqi@0 124 // True if sys V shm can be used with 16M pages dynamically.
aoqi@0 125 // (via shmctl(.. SHM_PAGESIZE..). Only true on AIX 5.3 and
aoqi@0 126 // newer, if the system was set up to use 16M pages and the
aoqi@0 127 // jvm has enough user rights. (0 or 1, -1 if not initialized)
aoqi@0 128 static int _can_use_16M_pages;
aoqi@0 129
aoqi@0 130 static julong available_memory();
aoqi@0 131 static julong physical_memory() { return _physical_memory; }
aoqi@0 132 static void initialize_system_info();
aoqi@0 133
aoqi@0 134 // OS recognitions (PASE/AIX, OS level) call this before calling any
aoqi@0 135 // one of Aix::on_pase(), Aix::os_version().
aoqi@0 136 static void initialize_os_info();
aoqi@0 137
aoqi@0 138 static int commit_memory_impl(char* addr, size_t bytes, bool exec);
aoqi@0 139 static int commit_memory_impl(char* addr, size_t bytes,
aoqi@0 140 size_t alignment_hint, bool exec);
aoqi@0 141
aoqi@0 142 // Scan environment for important settings which might effect the
aoqi@0 143 // VM. Trace out settings. Warn about invalid settings and/or
aoqi@0 144 // correct them.
aoqi@0 145 //
aoqi@0 146 // Must run after os::Aix::initialue_os_info().
aoqi@0 147 static void scan_environment();
aoqi@0 148
aoqi@0 149 // Retrieve information about multipage size support. Will initialize
aoqi@0 150 // _page_size, _stack_page_size, _can_use_64K_pages/_can_use_16M_pages
aoqi@0 151 static void query_multipage_support();
aoqi@0 152
aoqi@0 153 // Initialize libo4 (on PASE) and libperfstat (on AIX). Call this
aoqi@0 154 // before relying on functions from either lib, e.g. Aix::get_meminfo().
aoqi@0 155 static void initialize_libo4();
aoqi@0 156 static void initialize_libperfstat();
aoqi@0 157
aoqi@0 158 static bool supports_variable_stack_size();
aoqi@0 159
aoqi@0 160 public:
aoqi@0 161 static void init_thread_fpu_state();
aoqi@0 162 static pthread_t main_thread(void) { return _main_thread; }
aoqi@0 163 // returns kernel thread id (similar to LWP id on Solaris), which can be
aoqi@0 164 // used to access /proc
aoqi@0 165 static pid_t gettid();
aoqi@0 166 static void set_createThread_lock(Mutex* lk) { _createThread_lock = lk; }
aoqi@0 167 static Mutex* createThread_lock(void) { return _createThread_lock; }
aoqi@0 168 static void hotspot_sigmask(Thread* thread);
aoqi@0 169
aoqi@0 170 // Given an address, returns the size of the page backing that address
aoqi@0 171 static size_t query_pagesize(void* p);
aoqi@0 172
aoqi@0 173 // Return `true' if the calling thread is the primordial thread. The
aoqi@0 174 // primordial thread is the thread which contains the main function,
aoqi@0 175 // *not* necessarily the thread which initialized the VM by calling
aoqi@0 176 // JNI_CreateJavaVM.
aoqi@0 177 static bool is_primordial_thread(void);
aoqi@0 178
aoqi@0 179 static int page_size(void) {
aoqi@0 180 assert(_page_size != -1, "not initialized");
aoqi@0 181 return _page_size;
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 // Accessor methods for stack page size which may be different from usual page size.
aoqi@0 185 static int stack_page_size(void) {
aoqi@0 186 assert(_stack_page_size != -1, "not initialized");
aoqi@0 187 return _stack_page_size;
aoqi@0 188 }
aoqi@0 189
aoqi@0 190 // default shm page size. Read: what page size shared memory
aoqi@0 191 // will be backed with if no page size was set explicitly using shmctl(SHM_PAGESIZE).
aoqi@0 192 // Should be LDR_CNTRL SHMPSIZE.
aoqi@0 193 static int shm_default_page_size(void) {
aoqi@0 194 assert(_shm_default_page_size != -1, "not initialized");
aoqi@0 195 return _shm_default_page_size;
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 // Return true if sys V shm can be used with 64K pages dynamically
aoqi@0 199 // (via shmctl(.. SHM_PAGESIZE..).
aoqi@0 200 static bool can_use_64K_pages () {
aoqi@0 201 assert(_can_use_64K_pages != -1, "not initialized");
aoqi@0 202 return _can_use_64K_pages == 1 ? true : false;
aoqi@0 203 }
aoqi@0 204
aoqi@0 205 // Return true if sys V shm can be used with 16M pages dynamically.
aoqi@0 206 // (via shmctl(.. SHM_PAGESIZE..).
aoqi@0 207 static bool can_use_16M_pages () {
aoqi@0 208 assert(_can_use_16M_pages != -1, "not initialized");
aoqi@0 209 return _can_use_16M_pages == 1 ? true : false;
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 static address ucontext_get_pc(ucontext_t* uc);
aoqi@0 213 static intptr_t* ucontext_get_sp(ucontext_t* uc);
aoqi@0 214 static intptr_t* ucontext_get_fp(ucontext_t* uc);
aoqi@0 215 // Set PC into context. Needed for continuation after signal.
aoqi@0 216 static void ucontext_set_pc(ucontext_t* uc, address pc);
aoqi@0 217
aoqi@0 218 // This boolean allows users to forward their own non-matching signals
aoqi@0 219 // to JVM_handle_aix_signal, harmlessly.
aoqi@0 220 static bool signal_handlers_are_installed;
aoqi@0 221
aoqi@0 222 static int get_our_sigflags(int);
aoqi@0 223 static void set_our_sigflags(int, int);
aoqi@0 224 static void signal_sets_init();
aoqi@0 225 static void install_signal_handlers();
aoqi@0 226 static void set_signal_handler(int, bool);
aoqi@0 227 static bool is_sig_ignored(int sig);
aoqi@0 228
aoqi@0 229 static sigset_t* unblocked_signals();
aoqi@0 230 static sigset_t* vm_signals();
aoqi@0 231 static sigset_t* allowdebug_blocked_signals();
aoqi@0 232
aoqi@0 233 // For signal-chaining
aoqi@0 234 static struct sigaction *get_chained_signal_action(int sig);
aoqi@0 235 static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
aoqi@0 236
aoqi@0 237 // libpthread version string
aoqi@0 238 static void libpthread_init();
aoqi@0 239
aoqi@0 240 // Minimum stack size a thread can be created with (allowing
aoqi@0 241 // the VM to completely create the thread and enter user code)
aoqi@0 242 static size_t min_stack_allowed;
aoqi@0 243
aoqi@0 244 // Return default stack size or guard size for the specified thread type
aoqi@0 245 static size_t default_stack_size(os::ThreadType thr_type);
aoqi@0 246 static size_t default_guard_size(os::ThreadType thr_type);
aoqi@0 247
aoqi@0 248 // Function returns true if we run on OS/400 (pase), false if we run
aoqi@0 249 // on AIX.
aoqi@0 250 static bool on_pase() {
aoqi@0 251 assert(_on_pase != -1, "not initialized");
aoqi@0 252 return _on_pase ? true : false;
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 // Function returns true if we run on AIX, false if we run on OS/400
aoqi@0 256 // (pase).
aoqi@0 257 static bool on_aix() {
aoqi@0 258 assert(_on_pase != -1, "not initialized");
aoqi@0 259 return _on_pase ? false : true;
aoqi@0 260 }
aoqi@0 261
aoqi@0 262 // -1 = uninitialized, otherwise 16 bit number:
aoqi@0 263 // lower 8 bit - minor version
aoqi@0 264 // higher 8 bit - major version
aoqi@0 265 // For AIX, e.g. 0x0601 for AIX 6.1
aoqi@0 266 // for OS/400 e.g. 0x0504 for OS/400 V5R4
aoqi@0 267 static int os_version () {
aoqi@0 268 assert(_os_version != -1, "not initialized");
aoqi@0 269 return _os_version;
aoqi@0 270 }
aoqi@0 271
aoqi@0 272 // Convenience method: returns true if running on AIX 5.3 or older.
aoqi@0 273 static bool on_aix_53_or_older() {
aoqi@0 274 return on_aix() && os_version() <= 0x0503;
aoqi@0 275 }
aoqi@0 276
aoqi@0 277 // Returns true if we run in SPEC1170 compliant mode (XPG_SUS_ENV=ON).
aoqi@0 278 static bool xpg_sus_mode() {
aoqi@0 279 assert(_xpg_sus_mode != -1, "not initialized");
aoqi@0 280 return _xpg_sus_mode;
aoqi@0 281 }
aoqi@0 282
aoqi@0 283 // Returns true if EXTSHM=ON.
aoqi@0 284 static bool extshm() {
aoqi@0 285 assert(_extshm != -1, "not initialized");
aoqi@0 286 return _extshm;
aoqi@0 287 }
aoqi@0 288
aoqi@0 289 // result struct for get_meminfo()
aoqi@0 290 struct meminfo_t {
aoqi@0 291
aoqi@0 292 // Amount of virtual memory (in units of 4 KB pages)
aoqi@0 293 unsigned long long virt_total;
aoqi@0 294
aoqi@0 295 // Amount of real memory, in bytes
aoqi@0 296 unsigned long long real_total;
aoqi@0 297
aoqi@0 298 // Amount of free real memory, in bytes
aoqi@0 299 unsigned long long real_free;
aoqi@0 300
aoqi@0 301 // Total amount of paging space, in bytes
aoqi@0 302 unsigned long long pgsp_total;
aoqi@0 303
aoqi@0 304 // Amount of free paging space, in bytes
aoqi@0 305 unsigned long long pgsp_free;
aoqi@0 306
aoqi@0 307 };
aoqi@0 308
aoqi@0 309 // Result struct for get_cpuinfo().
aoqi@0 310 struct cpuinfo_t {
aoqi@0 311 char description[IDENTIFIER_LENGTH]; // processor description (type/official name)
aoqi@0 312 u_longlong_t processorHZ; // processor speed in Hz
aoqi@0 313 int ncpus; // number of active logical processors
aoqi@0 314 double loadavg[3]; // (1<<SBITS) times the average number of runnables processes during the last 1, 5 and 15 minutes.
aoqi@0 315 // To calculate the load average, divide the numbers by (1<<SBITS). SBITS is defined in <sys/proc.h>.
aoqi@0 316 char version[20]; // processor version from _system_configuration (sys/systemcfg.h)
aoqi@0 317 };
aoqi@0 318
aoqi@0 319 // Functions to retrieve memory information on AIX, PASE.
aoqi@0 320 // (on AIX, using libperfstat, on PASE with libo4.so).
aoqi@0 321 // Returns true if ok, false if error.
aoqi@0 322 static bool get_meminfo(meminfo_t* pmi);
aoqi@0 323
aoqi@0 324 // Function to retrieve cpu information on AIX
aoqi@0 325 // (on AIX, using libperfstat)
aoqi@0 326 // Returns true if ok, false if error.
aoqi@0 327 static bool get_cpuinfo(cpuinfo_t* pci);
aoqi@0 328
aoqi@0 329 }; // os::Aix class
aoqi@0 330
aoqi@0 331
aoqi@0 332 class PlatformEvent : public CHeapObj<mtInternal> {
aoqi@0 333 private:
aoqi@0 334 double CachePad [4]; // increase odds that _mutex is sole occupant of cache line
aoqi@0 335 volatile int _Event;
aoqi@0 336 volatile int _nParked;
aoqi@0 337 pthread_mutex_t _mutex [1];
aoqi@0 338 pthread_cond_t _cond [1];
aoqi@0 339 double PostPad [2];
aoqi@0 340 Thread * _Assoc;
aoqi@0 341
aoqi@0 342 public: // TODO-FIXME: make dtor private
aoqi@0 343 ~PlatformEvent() { guarantee (0, "invariant"); }
aoqi@0 344
aoqi@0 345 public:
aoqi@0 346 PlatformEvent() {
aoqi@0 347 int status;
aoqi@0 348 status = pthread_cond_init (_cond, NULL);
aoqi@0 349 assert_status(status == 0, status, "cond_init");
aoqi@0 350 status = pthread_mutex_init (_mutex, NULL);
aoqi@0 351 assert_status(status == 0, status, "mutex_init");
aoqi@0 352 _Event = 0;
aoqi@0 353 _nParked = 0;
aoqi@0 354 _Assoc = NULL;
aoqi@0 355 }
aoqi@0 356
aoqi@0 357 // Use caution with reset() and fired() -- they may require MEMBARs
aoqi@0 358 void reset() { _Event = 0; }
aoqi@0 359 int fired() { return _Event; }
aoqi@0 360 void park ();
aoqi@0 361 void unpark ();
aoqi@0 362 int TryPark ();
aoqi@0 363 int park (jlong millis);
aoqi@0 364 void SetAssociation (Thread * a) { _Assoc = a; }
aoqi@0 365 };
aoqi@0 366
aoqi@0 367 class PlatformParker : public CHeapObj<mtInternal> {
aoqi@0 368 protected:
aoqi@0 369 pthread_mutex_t _mutex [1];
aoqi@0 370 pthread_cond_t _cond [1];
aoqi@0 371
aoqi@0 372 public: // TODO-FIXME: make dtor private
aoqi@0 373 ~PlatformParker() { guarantee (0, "invariant"); }
aoqi@0 374
aoqi@0 375 public:
aoqi@0 376 PlatformParker() {
aoqi@0 377 int status;
aoqi@0 378 status = pthread_cond_init (_cond, NULL);
aoqi@0 379 assert_status(status == 0, status, "cond_init");
aoqi@0 380 status = pthread_mutex_init (_mutex, NULL);
aoqi@0 381 assert_status(status == 0, status, "mutex_init");
aoqi@0 382 }
aoqi@0 383 };
aoqi@0 384
aoqi@0 385 #endif // OS_AIX_VM_OS_AIX_HPP

mercurial