src/os/aix/vm/os_aix.cpp

Tue, 07 Jan 2014 17:24:59 +0100

author
goetz
date
Tue, 07 Jan 2014 17:24:59 +0100
changeset 6501
c668f307a4c0
parent 6471
3068270ba476
child 6514
9200402b42d5
permissions
-rw-r--r--

8031319: PPC64: Some fixes in ppc and aix coding.
Reviewed-by: kvn

simonis@6465 1 /*
simonis@6465 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
simonis@6465 3 * Copyright 2012, 2013 SAP AG. All rights reserved.
simonis@6465 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
simonis@6465 5 *
simonis@6465 6 * This code is free software; you can redistribute it and/or modify it
simonis@6465 7 * under the terms of the GNU General Public License version 2 only, as
simonis@6465 8 * published by the Free Software Foundation.
simonis@6465 9 *
simonis@6465 10 * This code is distributed in the hope that it will be useful, but WITHOUT
simonis@6465 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
simonis@6465 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
simonis@6465 13 * version 2 for more details (a copy is included in the LICENSE file that
simonis@6465 14 * accompanied this code).
simonis@6465 15 *
simonis@6465 16 * You should have received a copy of the GNU General Public License version
simonis@6465 17 * 2 along with this work; if not, write to the Free Software Foundation,
simonis@6465 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
simonis@6465 19 *
simonis@6465 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
simonis@6465 21 * or visit www.oracle.com if you need additional information or have any
simonis@6465 22 * questions.
simonis@6465 23 *
simonis@6465 24 */
simonis@6465 25
simonis@6465 26 // According to the AIX OS doc #pragma alloca must be used
simonis@6465 27 // with C++ compiler before referencing the function alloca()
simonis@6465 28 #pragma alloca
simonis@6465 29
simonis@6465 30 // no precompiled headers
simonis@6465 31 #include "classfile/classLoader.hpp"
simonis@6465 32 #include "classfile/systemDictionary.hpp"
simonis@6465 33 #include "classfile/vmSymbols.hpp"
simonis@6465 34 #include "code/icBuffer.hpp"
simonis@6465 35 #include "code/vtableStubs.hpp"
simonis@6465 36 #include "compiler/compileBroker.hpp"
simonis@6465 37 #include "interpreter/interpreter.hpp"
simonis@6465 38 #include "jvm_aix.h"
simonis@6465 39 #include "libperfstat_aix.hpp"
simonis@6465 40 #include "loadlib_aix.hpp"
simonis@6465 41 #include "memory/allocation.inline.hpp"
simonis@6465 42 #include "memory/filemap.hpp"
simonis@6465 43 #include "mutex_aix.inline.hpp"
simonis@6465 44 #include "oops/oop.inline.hpp"
simonis@6465 45 #include "os_share_aix.hpp"
simonis@6465 46 #include "porting_aix.hpp"
simonis@6465 47 #include "prims/jniFastGetField.hpp"
simonis@6465 48 #include "prims/jvm.h"
simonis@6465 49 #include "prims/jvm_misc.hpp"
simonis@6465 50 #include "runtime/arguments.hpp"
simonis@6465 51 #include "runtime/extendedPC.hpp"
simonis@6465 52 #include "runtime/globals.hpp"
simonis@6465 53 #include "runtime/interfaceSupport.hpp"
simonis@6465 54 #include "runtime/java.hpp"
simonis@6465 55 #include "runtime/javaCalls.hpp"
simonis@6465 56 #include "runtime/mutexLocker.hpp"
simonis@6465 57 #include "runtime/objectMonitor.hpp"
simonis@6465 58 #include "runtime/osThread.hpp"
simonis@6465 59 #include "runtime/perfMemory.hpp"
simonis@6465 60 #include "runtime/sharedRuntime.hpp"
simonis@6465 61 #include "runtime/statSampler.hpp"
simonis@6465 62 #include "runtime/stubRoutines.hpp"
simonis@6465 63 #include "runtime/threadCritical.hpp"
simonis@6465 64 #include "runtime/timer.hpp"
simonis@6465 65 #include "services/attachListener.hpp"
simonis@6465 66 #include "services/runtimeService.hpp"
simonis@6465 67 #include "thread_aix.inline.hpp"
simonis@6465 68 #include "utilities/decoder.hpp"
simonis@6465 69 #include "utilities/defaultStream.hpp"
simonis@6465 70 #include "utilities/events.hpp"
simonis@6465 71 #include "utilities/growableArray.hpp"
simonis@6465 72 #include "utilities/vmError.hpp"
simonis@6465 73 #ifdef TARGET_ARCH_ppc
simonis@6465 74 # include "assembler_ppc.inline.hpp"
simonis@6465 75 # include "nativeInst_ppc.hpp"
simonis@6465 76 #endif
simonis@6465 77 #ifdef COMPILER1
simonis@6465 78 #include "c1/c1_Runtime1.hpp"
simonis@6465 79 #endif
simonis@6465 80 #ifdef COMPILER2
simonis@6465 81 #include "opto/runtime.hpp"
simonis@6465 82 #endif
simonis@6465 83
simonis@6465 84 // put OS-includes here (sorted alphabetically)
simonis@6465 85 #include <errno.h>
simonis@6465 86 #include <fcntl.h>
simonis@6465 87 #include <inttypes.h>
simonis@6465 88 #include <poll.h>
simonis@6465 89 #include <procinfo.h>
simonis@6465 90 #include <pthread.h>
simonis@6465 91 #include <pwd.h>
simonis@6465 92 #include <semaphore.h>
simonis@6465 93 #include <signal.h>
simonis@6465 94 #include <stdint.h>
simonis@6465 95 #include <stdio.h>
simonis@6465 96 #include <string.h>
simonis@6465 97 #include <unistd.h>
simonis@6465 98 #include <sys/ioctl.h>
simonis@6465 99 #include <sys/ipc.h>
simonis@6465 100 #include <sys/mman.h>
simonis@6465 101 #include <sys/resource.h>
simonis@6465 102 #include <sys/select.h>
simonis@6465 103 #include <sys/shm.h>
simonis@6465 104 #include <sys/socket.h>
simonis@6465 105 #include <sys/stat.h>
simonis@6465 106 #include <sys/sysinfo.h>
simonis@6465 107 #include <sys/systemcfg.h>
simonis@6465 108 #include <sys/time.h>
simonis@6465 109 #include <sys/times.h>
simonis@6465 110 #include <sys/types.h>
simonis@6465 111 #include <sys/utsname.h>
simonis@6465 112 #include <sys/vminfo.h>
simonis@6465 113 #include <sys/wait.h>
simonis@6465 114
simonis@6465 115 // Add missing declarations (should be in procinfo.h but isn't until AIX 6.1).
simonis@6465 116 #if !defined(_AIXVERSION_610)
simonis@6465 117 extern "C" {
simonis@6465 118 int getthrds64(pid_t ProcessIdentifier,
simonis@6465 119 struct thrdentry64* ThreadBuffer,
simonis@6465 120 int ThreadSize,
simonis@6465 121 tid64_t* IndexPointer,
simonis@6465 122 int Count);
simonis@6465 123 }
simonis@6465 124 #endif
simonis@6465 125
simonis@6465 126 // Excerpts from systemcfg.h definitions newer than AIX 5.3
simonis@6465 127 #ifndef PV_7
simonis@6465 128 # define PV_7 0x200000 // Power PC 7
simonis@6465 129 # define PV_7_Compat 0x208000 // Power PC 7
simonis@6465 130 #endif
simonis@6465 131
simonis@6465 132 #define MAX_PATH (2 * K)
simonis@6465 133
simonis@6465 134 // for timer info max values which include all bits
simonis@6465 135 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
simonis@6465 136 // for multipage initialization error analysis (in 'g_multipage_error')
simonis@6465 137 #define ERROR_MP_OS_TOO_OLD 100
simonis@6465 138 #define ERROR_MP_EXTSHM_ACTIVE 101
simonis@6465 139 #define ERROR_MP_VMGETINFO_FAILED 102
simonis@6465 140 #define ERROR_MP_VMGETINFO_CLAIMS_NO_SUPPORT_FOR_64K 103
simonis@6465 141
simonis@6465 142 // the semantics in this file are thus that codeptr_t is a *real code ptr*
simonis@6465 143 // This means that any function taking codeptr_t as arguments will assume
simonis@6465 144 // a real codeptr and won't handle function descriptors (eg getFuncName),
simonis@6465 145 // whereas functions taking address as args will deal with function
simonis@6465 146 // descriptors (eg os::dll_address_to_library_name)
simonis@6465 147 typedef unsigned int* codeptr_t;
simonis@6465 148
simonis@6465 149 // typedefs for stackslots, stack pointers, pointers to op codes
simonis@6465 150 typedef unsigned long stackslot_t;
simonis@6465 151 typedef stackslot_t* stackptr_t;
simonis@6465 152
simonis@6465 153 // query dimensions of the stack of the calling thread
simonis@6465 154 static void query_stack_dimensions(address* p_stack_base, size_t* p_stack_size);
simonis@6465 155
simonis@6465 156 // function to check a given stack pointer against given stack limits
simonis@6465 157 inline bool is_valid_stackpointer(stackptr_t sp, stackptr_t stack_base, size_t stack_size) {
simonis@6465 158 if (((uintptr_t)sp) & 0x7) {
simonis@6465 159 return false;
simonis@6465 160 }
simonis@6465 161 if (sp > stack_base) {
simonis@6465 162 return false;
simonis@6465 163 }
simonis@6465 164 if (sp < (stackptr_t) ((address)stack_base - stack_size)) {
simonis@6465 165 return false;
simonis@6465 166 }
simonis@6465 167 return true;
simonis@6465 168 }
simonis@6465 169
simonis@6465 170 // returns true if function is a valid codepointer
simonis@6465 171 inline bool is_valid_codepointer(codeptr_t p) {
simonis@6465 172 if (!p) {
simonis@6465 173 return false;
simonis@6465 174 }
simonis@6465 175 if (((uintptr_t)p) & 0x3) {
simonis@6465 176 return false;
simonis@6465 177 }
simonis@6465 178 if (LoadedLibraries::find_for_text_address((address)p) == NULL) {
simonis@6465 179 return false;
simonis@6465 180 }
simonis@6465 181 return true;
simonis@6465 182 }
simonis@6465 183
simonis@6465 184 // macro to check a given stack pointer against given stack limits and to die if test fails
simonis@6465 185 #define CHECK_STACK_PTR(sp, stack_base, stack_size) { \
simonis@6465 186 guarantee(is_valid_stackpointer((stackptr_t)(sp), (stackptr_t)(stack_base), stack_size), "Stack Pointer Invalid"); \
simonis@6465 187 }
simonis@6465 188
simonis@6465 189 // macro to check the current stack pointer against given stacklimits
simonis@6465 190 #define CHECK_CURRENT_STACK_PTR(stack_base, stack_size) { \
simonis@6465 191 address sp; \
simonis@6465 192 sp = os::current_stack_pointer(); \
simonis@6465 193 CHECK_STACK_PTR(sp, stack_base, stack_size); \
simonis@6465 194 }
simonis@6465 195
simonis@6465 196 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 197 // global variables (for a description see os_aix.hpp)
simonis@6465 198
simonis@6465 199 julong os::Aix::_physical_memory = 0;
simonis@6465 200 pthread_t os::Aix::_main_thread = ((pthread_t)0);
simonis@6465 201 int os::Aix::_page_size = -1;
simonis@6465 202 int os::Aix::_on_pase = -1;
simonis@6465 203 int os::Aix::_os_version = -1;
simonis@6465 204 int os::Aix::_stack_page_size = -1;
simonis@6465 205 size_t os::Aix::_shm_default_page_size = -1;
simonis@6465 206 int os::Aix::_can_use_64K_pages = -1;
simonis@6465 207 int os::Aix::_can_use_16M_pages = -1;
simonis@6465 208 int os::Aix::_xpg_sus_mode = -1;
simonis@6465 209 int os::Aix::_extshm = -1;
simonis@6465 210 int os::Aix::_logical_cpus = -1;
simonis@6465 211
simonis@6465 212 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 213 // local variables
simonis@6465 214
simonis@6465 215 static int g_multipage_error = -1; // error analysis for multipage initialization
simonis@6465 216 static jlong initial_time_count = 0;
simonis@6465 217 static int clock_tics_per_sec = 100;
simonis@6465 218 static sigset_t check_signal_done; // For diagnostics to print a message once (see run_periodic_checks)
simonis@6465 219 static bool check_signals = true;
simonis@6465 220 static pid_t _initial_pid = 0;
simonis@6465 221 static int SR_signum = SIGUSR2; // Signal used to suspend/resume a thread (must be > SIGSEGV, see 4355769)
simonis@6465 222 static sigset_t SR_sigset;
simonis@6465 223 static pthread_mutex_t dl_mutex; // Used to protect dlsym() calls */
simonis@6465 224
simonis@6465 225 julong os::available_memory() {
simonis@6465 226 return Aix::available_memory();
simonis@6465 227 }
simonis@6465 228
simonis@6465 229 julong os::Aix::available_memory() {
simonis@6471 230 os::Aix::meminfo_t mi;
simonis@6471 231 if (os::Aix::get_meminfo(&mi)) {
simonis@6471 232 return mi.real_free;
simonis@6471 233 } else {
simonis@6471 234 return 0xFFFFFFFFFFFFFFFFLL;
simonis@6471 235 }
simonis@6465 236 }
simonis@6465 237
simonis@6465 238 julong os::physical_memory() {
simonis@6465 239 return Aix::physical_memory();
simonis@6465 240 }
simonis@6465 241
simonis@6465 242 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 243 // environment support
simonis@6465 244
simonis@6465 245 bool os::getenv(const char* name, char* buf, int len) {
simonis@6465 246 const char* val = ::getenv(name);
simonis@6465 247 if (val != NULL && strlen(val) < (size_t)len) {
simonis@6465 248 strcpy(buf, val);
simonis@6465 249 return true;
simonis@6465 250 }
simonis@6465 251 if (len > 0) buf[0] = 0; // return a null string
simonis@6465 252 return false;
simonis@6465 253 }
simonis@6465 254
simonis@6465 255
simonis@6465 256 // Return true if user is running as root.
simonis@6465 257
simonis@6465 258 bool os::have_special_privileges() {
simonis@6465 259 static bool init = false;
simonis@6465 260 static bool privileges = false;
simonis@6465 261 if (!init) {
simonis@6465 262 privileges = (getuid() != geteuid()) || (getgid() != getegid());
simonis@6465 263 init = true;
simonis@6465 264 }
simonis@6465 265 return privileges;
simonis@6465 266 }
simonis@6465 267
simonis@6465 268 // Helper function, emulates disclaim64 using multiple 32bit disclaims
simonis@6465 269 // because we cannot use disclaim64() on AS/400 and old AIX releases.
simonis@6465 270 static bool my_disclaim64(char* addr, size_t size) {
simonis@6465 271
simonis@6465 272 if (size == 0) {
simonis@6465 273 return true;
simonis@6465 274 }
simonis@6465 275
simonis@6465 276 // Maximum size 32bit disclaim() accepts. (Theoretically 4GB, but I just do not trust that.)
simonis@6465 277 const unsigned int maxDisclaimSize = 0x80000000;
simonis@6465 278
simonis@6465 279 const unsigned int numFullDisclaimsNeeded = (size / maxDisclaimSize);
simonis@6465 280 const unsigned int lastDisclaimSize = (size % maxDisclaimSize);
simonis@6465 281
simonis@6465 282 char* p = addr;
simonis@6465 283
simonis@6465 284 for (int i = 0; i < numFullDisclaimsNeeded; i ++) {
simonis@6465 285 if (::disclaim(p, maxDisclaimSize, DISCLAIM_ZEROMEM) != 0) {
simonis@6465 286 //if (Verbose)
simonis@6465 287 fprintf(stderr, "Cannot disclaim %p - %p (errno %d)\n", p, p + maxDisclaimSize, errno);
simonis@6465 288 return false;
simonis@6465 289 }
simonis@6465 290 p += maxDisclaimSize;
simonis@6465 291 }
simonis@6465 292
simonis@6465 293 if (lastDisclaimSize > 0) {
simonis@6465 294 if (::disclaim(p, lastDisclaimSize, DISCLAIM_ZEROMEM) != 0) {
simonis@6465 295 //if (Verbose)
simonis@6465 296 fprintf(stderr, "Cannot disclaim %p - %p (errno %d)\n", p, p + lastDisclaimSize, errno);
simonis@6465 297 return false;
simonis@6465 298 }
simonis@6465 299 }
simonis@6465 300
simonis@6465 301 return true;
simonis@6465 302 }
simonis@6465 303
simonis@6465 304 // Cpu architecture string
simonis@6465 305 #if defined(PPC32)
simonis@6465 306 static char cpu_arch[] = "ppc";
simonis@6465 307 #elif defined(PPC64)
simonis@6465 308 static char cpu_arch[] = "ppc64";
simonis@6465 309 #else
simonis@6465 310 #error Add appropriate cpu_arch setting
simonis@6465 311 #endif
simonis@6465 312
simonis@6465 313
simonis@6465 314 // Given an address, returns the size of the page backing that address.
simonis@6465 315 size_t os::Aix::query_pagesize(void* addr) {
simonis@6465 316
simonis@6465 317 vm_page_info pi;
simonis@6465 318 pi.addr = (uint64_t)addr;
simonis@6465 319 if (::vmgetinfo(&pi, VM_PAGE_INFO, sizeof(pi)) == 0) {
simonis@6465 320 return pi.pagesize;
simonis@6465 321 } else {
simonis@6465 322 fprintf(stderr, "vmgetinfo failed to retrieve page size for address %p (errno %d).\n", addr, errno);
simonis@6465 323 assert(false, "vmgetinfo failed to retrieve page size");
simonis@6465 324 return SIZE_4K;
simonis@6465 325 }
simonis@6465 326
simonis@6465 327 }
simonis@6465 328
simonis@6465 329 // Returns the kernel thread id of the currently running thread.
simonis@6465 330 pid_t os::Aix::gettid() {
simonis@6465 331 return (pid_t) thread_self();
simonis@6465 332 }
simonis@6465 333
simonis@6465 334 void os::Aix::initialize_system_info() {
simonis@6465 335
simonis@6465 336 // get the number of online(logical) cpus instead of configured
simonis@6465 337 os::_processor_count = sysconf(_SC_NPROCESSORS_ONLN);
simonis@6465 338 assert(_processor_count > 0, "_processor_count must be > 0");
simonis@6465 339
simonis@6465 340 // retrieve total physical storage
simonis@6465 341 os::Aix::meminfo_t mi;
simonis@6465 342 if (!os::Aix::get_meminfo(&mi)) {
simonis@6465 343 fprintf(stderr, "os::Aix::get_meminfo failed.\n"); fflush(stderr);
simonis@6465 344 assert(false, "os::Aix::get_meminfo failed.");
simonis@6465 345 }
simonis@6465 346 _physical_memory = (julong) mi.real_total;
simonis@6465 347 }
simonis@6465 348
simonis@6465 349 // Helper function for tracing page sizes.
simonis@6465 350 static const char* describe_pagesize(size_t pagesize) {
simonis@6465 351 switch (pagesize) {
simonis@6465 352 case SIZE_4K : return "4K";
simonis@6465 353 case SIZE_64K: return "64K";
simonis@6465 354 case SIZE_16M: return "16M";
simonis@6465 355 case SIZE_16G: return "16G";
simonis@6465 356 default:
simonis@6465 357 assert(false, "surprise");
simonis@6465 358 return "??";
simonis@6465 359 }
simonis@6465 360 }
simonis@6465 361
simonis@6465 362 // Retrieve information about multipage size support. Will initialize
simonis@6465 363 // Aix::_page_size, Aix::_stack_page_size, Aix::_can_use_64K_pages,
simonis@6465 364 // Aix::_can_use_16M_pages.
simonis@6465 365 // Must be called before calling os::large_page_init().
simonis@6465 366 void os::Aix::query_multipage_support() {
simonis@6465 367
simonis@6465 368 guarantee(_page_size == -1 &&
simonis@6465 369 _stack_page_size == -1 &&
simonis@6465 370 _can_use_64K_pages == -1 &&
simonis@6465 371 _can_use_16M_pages == -1 &&
simonis@6465 372 g_multipage_error == -1,
simonis@6465 373 "do not call twice");
simonis@6465 374
simonis@6465 375 _page_size = ::sysconf(_SC_PAGESIZE);
simonis@6465 376
simonis@6465 377 // This really would surprise me.
simonis@6465 378 assert(_page_size == SIZE_4K, "surprise!");
simonis@6465 379
simonis@6465 380
simonis@6465 381 // query default data page size (default page size for C-Heap, pthread stacks and .bss).
simonis@6465 382 // Default data page size is influenced either by linker options (-bdatapsize)
simonis@6465 383 // or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given,
simonis@6465 384 // default should be 4K.
simonis@6465 385 size_t data_page_size = SIZE_4K;
simonis@6465 386 {
simonis@6465 387 void* p = ::malloc(SIZE_16M);
simonis@6465 388 data_page_size = os::Aix::query_pagesize(p);
simonis@6465 389 ::free(p);
simonis@6465 390 }
simonis@6465 391
simonis@6465 392 // query default shm page size (LDR_CNTRL SHMPSIZE)
simonis@6465 393 {
simonis@6465 394 const int shmid = ::shmget(IPC_PRIVATE, 1, IPC_CREAT | S_IRUSR | S_IWUSR);
simonis@6465 395 guarantee(shmid != -1, "shmget failed");
simonis@6465 396 void* p = ::shmat(shmid, NULL, 0);
simonis@6465 397 ::shmctl(shmid, IPC_RMID, NULL);
simonis@6465 398 guarantee(p != (void*) -1, "shmat failed");
simonis@6465 399 _shm_default_page_size = os::Aix::query_pagesize(p);
simonis@6465 400 ::shmdt(p);
simonis@6465 401 }
simonis@6465 402
simonis@6465 403 // before querying the stack page size, make sure we are not running as primordial
simonis@6465 404 // thread (because primordial thread's stack may have different page size than
simonis@6465 405 // pthread thread stacks). Running a VM on the primordial thread won't work for a
simonis@6465 406 // number of reasons so we may just as well guarantee it here
simonis@6465 407 guarantee(!os::Aix::is_primordial_thread(), "Must not be called for primordial thread");
simonis@6465 408
simonis@6465 409 // query stack page size
simonis@6465 410 {
simonis@6465 411 int dummy = 0;
simonis@6465 412 _stack_page_size = os::Aix::query_pagesize(&dummy);
simonis@6465 413 // everything else would surprise me and should be looked into
simonis@6465 414 guarantee(_stack_page_size == SIZE_4K || _stack_page_size == SIZE_64K, "Wrong page size");
simonis@6465 415 // also, just for completeness: pthread stacks are allocated from C heap, so
simonis@6465 416 // stack page size should be the same as data page size
simonis@6465 417 guarantee(_stack_page_size == data_page_size, "stack page size should be the same as data page size");
simonis@6465 418 }
simonis@6465 419
simonis@6465 420 // EXTSHM is bad: among other things, it prevents setting pagesize dynamically
simonis@6465 421 // for system V shm.
simonis@6465 422 if (Aix::extshm()) {
simonis@6465 423 if (Verbose) {
simonis@6465 424 fprintf(stderr, "EXTSHM is active - will disable large page support.\n"
simonis@6465 425 "Please make sure EXTSHM is OFF for large page support.\n");
simonis@6465 426 }
simonis@6465 427 g_multipage_error = ERROR_MP_EXTSHM_ACTIVE;
simonis@6465 428 _can_use_64K_pages = _can_use_16M_pages = 0;
simonis@6465 429 goto query_multipage_support_end;
simonis@6465 430 }
simonis@6465 431
simonis@6465 432 // now check which page sizes the OS claims it supports, and of those, which actually can be used.
simonis@6465 433 {
simonis@6465 434 const int MAX_PAGE_SIZES = 4;
simonis@6465 435 psize_t sizes[MAX_PAGE_SIZES];
simonis@6465 436 const int num_psizes = ::vmgetinfo(sizes, VMINFO_GETPSIZES, MAX_PAGE_SIZES);
simonis@6465 437 if (num_psizes == -1) {
simonis@6465 438 if (Verbose) {
simonis@6465 439 fprintf(stderr, "vmgetinfo(VMINFO_GETPSIZES) failed (errno: %d)\n", errno);
simonis@6465 440 fprintf(stderr, "disabling multipage support.\n");
simonis@6465 441 }
simonis@6465 442 g_multipage_error = ERROR_MP_VMGETINFO_FAILED;
simonis@6465 443 _can_use_64K_pages = _can_use_16M_pages = 0;
simonis@6465 444 goto query_multipage_support_end;
simonis@6465 445 }
simonis@6465 446 guarantee(num_psizes > 0, "vmgetinfo(.., VMINFO_GETPSIZES, ...) failed.");
simonis@6465 447 assert(num_psizes <= MAX_PAGE_SIZES, "Surprise! more than 4 page sizes?");
simonis@6465 448 if (Verbose) {
simonis@6465 449 fprintf(stderr, "vmgetinfo(.., VMINFO_GETPSIZES, ...) returns %d supported page sizes: ", num_psizes);
simonis@6465 450 for (int i = 0; i < num_psizes; i ++) {
simonis@6465 451 fprintf(stderr, " %s ", describe_pagesize(sizes[i]));
simonis@6465 452 }
simonis@6465 453 fprintf(stderr, " .\n");
simonis@6465 454 }
simonis@6465 455
simonis@6465 456 // Can we use 64K, 16M pages?
simonis@6465 457 _can_use_64K_pages = 0;
simonis@6465 458 _can_use_16M_pages = 0;
simonis@6465 459 for (int i = 0; i < num_psizes; i ++) {
simonis@6465 460 if (sizes[i] == SIZE_64K) {
simonis@6465 461 _can_use_64K_pages = 1;
simonis@6465 462 } else if (sizes[i] == SIZE_16M) {
simonis@6465 463 _can_use_16M_pages = 1;
simonis@6465 464 }
simonis@6465 465 }
simonis@6465 466
simonis@6465 467 if (!_can_use_64K_pages) {
simonis@6465 468 g_multipage_error = ERROR_MP_VMGETINFO_CLAIMS_NO_SUPPORT_FOR_64K;
simonis@6465 469 }
simonis@6465 470
simonis@6465 471 // Double-check for 16M pages: Even if AIX claims to be able to use 16M pages,
simonis@6465 472 // there must be an actual 16M page pool, and we must run with enough rights.
simonis@6465 473 if (_can_use_16M_pages) {
simonis@6465 474 const int shmid = ::shmget(IPC_PRIVATE, SIZE_16M, IPC_CREAT | S_IRUSR | S_IWUSR);
simonis@6465 475 guarantee(shmid != -1, "shmget failed");
simonis@6465 476 struct shmid_ds shm_buf = { 0 };
simonis@6465 477 shm_buf.shm_pagesize = SIZE_16M;
simonis@6465 478 const bool can_set_pagesize = ::shmctl(shmid, SHM_PAGESIZE, &shm_buf) == 0 ? true : false;
simonis@6465 479 const int en = errno;
simonis@6465 480 ::shmctl(shmid, IPC_RMID, NULL);
simonis@6465 481 if (!can_set_pagesize) {
simonis@6465 482 if (Verbose) {
simonis@6465 483 fprintf(stderr, "Failed to allocate even one misely 16M page. shmctl failed with %d (%s).\n"
simonis@6465 484 "Will deactivate 16M support.\n", en, strerror(en));
simonis@6465 485 }
simonis@6465 486 _can_use_16M_pages = 0;
simonis@6465 487 }
simonis@6465 488 }
simonis@6465 489
simonis@6465 490 } // end: check which pages can be used for shared memory
simonis@6465 491
simonis@6465 492 query_multipage_support_end:
simonis@6465 493
simonis@6465 494 guarantee(_page_size != -1 &&
simonis@6465 495 _stack_page_size != -1 &&
simonis@6465 496 _can_use_64K_pages != -1 &&
simonis@6465 497 _can_use_16M_pages != -1, "Page sizes not properly initialized");
simonis@6465 498
simonis@6465 499 if (_can_use_64K_pages) {
simonis@6465 500 g_multipage_error = 0;
simonis@6465 501 }
simonis@6465 502
simonis@6465 503 if (Verbose) {
simonis@6465 504 fprintf(stderr, "Data page size (C-Heap, bss, etc): %s\n", describe_pagesize(data_page_size));
simonis@6465 505 fprintf(stderr, "Thread stack page size (pthread): %s\n", describe_pagesize(_stack_page_size));
simonis@6465 506 fprintf(stderr, "Default shared memory page size: %s\n", describe_pagesize(_shm_default_page_size));
simonis@6465 507 fprintf(stderr, "Can use 64K pages dynamically with shared meory: %s\n", (_can_use_64K_pages ? "yes" :"no"));
simonis@6465 508 fprintf(stderr, "Can use 16M pages dynamically with shared memory: %s\n", (_can_use_16M_pages ? "yes" :"no"));
simonis@6465 509 fprintf(stderr, "Multipage error details: %d\n", g_multipage_error);
simonis@6465 510 }
simonis@6465 511
simonis@6465 512 } // end os::Aix::query_multipage_support()
simonis@6465 513
simonis@6465 514
simonis@6465 515 // The code for this method was initially derived from the version in os_linux.cpp
simonis@6465 516 void os::init_system_properties_values() {
simonis@6465 517 // The next few definitions allow the code to be verbatim:
simonis@6465 518 #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
simonis@6465 519 #define DEFAULT_LIBPATH "/usr/lib:/lib"
simonis@6465 520 #define EXTENSIONS_DIR "/lib/ext"
simonis@6465 521 #define ENDORSED_DIR "/lib/endorsed"
simonis@6465 522
simonis@6465 523 // sysclasspath, java_home, dll_dir
simonis@6465 524 char *home_path;
simonis@6465 525 char *dll_path;
simonis@6465 526 char *pslash;
simonis@6465 527 char buf[MAXPATHLEN];
simonis@6465 528 os::jvm_path(buf, sizeof(buf));
simonis@6465 529
simonis@6465 530 // Found the full path to libjvm.so.
simonis@6465 531 // Now cut the path to <java_home>/jre if we can.
simonis@6465 532 *(strrchr(buf, '/')) = '\0'; // get rid of /libjvm.so
simonis@6465 533 pslash = strrchr(buf, '/');
simonis@6465 534 if (pslash != NULL) {
simonis@6465 535 *pslash = '\0'; // get rid of /{client|server|hotspot}
simonis@6465 536 }
simonis@6465 537
simonis@6465 538 dll_path = malloc(strlen(buf) + 1);
simonis@6465 539 strcpy(dll_path, buf);
simonis@6465 540 Arguments::set_dll_dir(dll_path);
simonis@6465 541
simonis@6465 542 if (pslash != NULL) {
simonis@6465 543 pslash = strrchr(buf, '/');
simonis@6465 544 if (pslash != NULL) {
simonis@6465 545 *pslash = '\0'; // get rid of /<arch>
simonis@6465 546 pslash = strrchr(buf, '/');
simonis@6465 547 if (pslash != NULL) {
simonis@6465 548 *pslash = '\0'; // get rid of /lib
simonis@6465 549 }
simonis@6465 550 }
simonis@6465 551 }
simonis@6465 552
simonis@6465 553 home_path = malloc(strlen(buf) + 1);
simonis@6465 554 strcpy(home_path, buf);
simonis@6465 555 Arguments::set_java_home(home_path);
simonis@6465 556
simonis@6465 557 if (!set_boot_path('/', ':')) return;
simonis@6465 558
simonis@6465 559 // Where to look for native libraries
simonis@6465 560
simonis@6465 561 // On Aix we get the user setting of LIBPATH
simonis@6465 562 // Eventually, all the library path setting will be done here.
simonis@6465 563 char *ld_library_path;
simonis@6465 564
simonis@6465 565 // Construct the invariant part of ld_library_path.
simonis@6465 566 ld_library_path = (char *) malloc(sizeof(DEFAULT_LIBPATH));
simonis@6465 567 sprintf(ld_library_path, DEFAULT_LIBPATH);
simonis@6465 568
simonis@6465 569 // Get the user setting of LIBPATH, and prepended it.
simonis@6465 570 char *v = ::getenv("LIBPATH");
simonis@6465 571 if (v == NULL) {
simonis@6465 572 v = "";
simonis@6465 573 }
simonis@6465 574
simonis@6465 575 char *t = ld_library_path;
simonis@6465 576 // That's +1 for the colon and +1 for the trailing '\0'
simonis@6465 577 ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1);
simonis@6465 578 sprintf(ld_library_path, "%s:%s", v, t);
simonis@6465 579
simonis@6465 580 Arguments::set_library_path(ld_library_path);
simonis@6465 581
simonis@6465 582 // Extensions directories
simonis@6465 583 char* cbuf = malloc(strlen(Arguments::get_java_home()) + sizeof(EXTENSIONS_DIR));
simonis@6465 584 sprintf(cbuf, "%s" EXTENSIONS_DIR, Arguments::get_java_home());
simonis@6465 585 Arguments::set_ext_dirs(cbuf);
simonis@6465 586
simonis@6465 587 // Endorsed standards default directory.
simonis@6465 588 cbuf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
simonis@6465 589 sprintf(cbuf, "%s" ENDORSED_DIR, Arguments::get_java_home());
simonis@6465 590 Arguments::set_endorsed_dirs(cbuf);
simonis@6465 591
simonis@6465 592 #undef malloc
simonis@6465 593 #undef DEFAULT_LIBPATH
simonis@6465 594 #undef EXTENSIONS_DIR
simonis@6465 595 #undef ENDORSED_DIR
simonis@6465 596 }
simonis@6465 597
simonis@6465 598 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 599 // breakpoint support
simonis@6465 600
simonis@6465 601 void os::breakpoint() {
simonis@6465 602 BREAKPOINT;
simonis@6465 603 }
simonis@6465 604
simonis@6465 605 extern "C" void breakpoint() {
simonis@6465 606 // use debugger to set breakpoint here
simonis@6465 607 }
simonis@6465 608
simonis@6465 609 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 610 // signal support
simonis@6465 611
simonis@6465 612 debug_only(static bool signal_sets_initialized = false);
simonis@6465 613 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
simonis@6465 614
simonis@6465 615 bool os::Aix::is_sig_ignored(int sig) {
simonis@6465 616 struct sigaction oact;
simonis@6465 617 sigaction(sig, (struct sigaction*)NULL, &oact);
simonis@6465 618 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction)
simonis@6465 619 : CAST_FROM_FN_PTR(void*, oact.sa_handler);
simonis@6465 620 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN))
simonis@6465 621 return true;
simonis@6465 622 else
simonis@6465 623 return false;
simonis@6465 624 }
simonis@6465 625
simonis@6465 626 void os::Aix::signal_sets_init() {
simonis@6465 627 // Should also have an assertion stating we are still single-threaded.
simonis@6465 628 assert(!signal_sets_initialized, "Already initialized");
simonis@6465 629 // Fill in signals that are necessarily unblocked for all threads in
simonis@6465 630 // the VM. Currently, we unblock the following signals:
simonis@6465 631 // SHUTDOWN{1,2,3}_SIGNAL: for shutdown hooks support (unless over-ridden
simonis@6465 632 // by -Xrs (=ReduceSignalUsage));
simonis@6465 633 // BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all
simonis@6465 634 // other threads. The "ReduceSignalUsage" boolean tells us not to alter
simonis@6465 635 // the dispositions or masks wrt these signals.
simonis@6465 636 // Programs embedding the VM that want to use the above signals for their
simonis@6465 637 // own purposes must, at this time, use the "-Xrs" option to prevent
simonis@6465 638 // interference with shutdown hooks and BREAK_SIGNAL thread dumping.
simonis@6465 639 // (See bug 4345157, and other related bugs).
simonis@6465 640 // In reality, though, unblocking these signals is really a nop, since
simonis@6465 641 // these signals are not blocked by default.
simonis@6465 642 sigemptyset(&unblocked_sigs);
simonis@6465 643 sigemptyset(&allowdebug_blocked_sigs);
simonis@6465 644 sigaddset(&unblocked_sigs, SIGILL);
simonis@6465 645 sigaddset(&unblocked_sigs, SIGSEGV);
simonis@6465 646 sigaddset(&unblocked_sigs, SIGBUS);
simonis@6465 647 sigaddset(&unblocked_sigs, SIGFPE);
simonis@6465 648 sigaddset(&unblocked_sigs, SIGTRAP);
simonis@6465 649 sigaddset(&unblocked_sigs, SIGDANGER);
simonis@6465 650 sigaddset(&unblocked_sigs, SR_signum);
simonis@6465 651
simonis@6465 652 if (!ReduceSignalUsage) {
simonis@6465 653 if (!os::Aix::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
simonis@6465 654 sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL);
simonis@6465 655 sigaddset(&allowdebug_blocked_sigs, SHUTDOWN1_SIGNAL);
simonis@6465 656 }
simonis@6465 657 if (!os::Aix::is_sig_ignored(SHUTDOWN2_SIGNAL)) {
simonis@6465 658 sigaddset(&unblocked_sigs, SHUTDOWN2_SIGNAL);
simonis@6465 659 sigaddset(&allowdebug_blocked_sigs, SHUTDOWN2_SIGNAL);
simonis@6465 660 }
simonis@6465 661 if (!os::Aix::is_sig_ignored(SHUTDOWN3_SIGNAL)) {
simonis@6465 662 sigaddset(&unblocked_sigs, SHUTDOWN3_SIGNAL);
simonis@6465 663 sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL);
simonis@6465 664 }
simonis@6465 665 }
simonis@6465 666 // Fill in signals that are blocked by all but the VM thread.
simonis@6465 667 sigemptyset(&vm_sigs);
simonis@6465 668 if (!ReduceSignalUsage)
simonis@6465 669 sigaddset(&vm_sigs, BREAK_SIGNAL);
simonis@6465 670 debug_only(signal_sets_initialized = true);
simonis@6465 671 }
simonis@6465 672
simonis@6465 673 // These are signals that are unblocked while a thread is running Java.
simonis@6465 674 // (For some reason, they get blocked by default.)
simonis@6465 675 sigset_t* os::Aix::unblocked_signals() {
simonis@6465 676 assert(signal_sets_initialized, "Not initialized");
simonis@6465 677 return &unblocked_sigs;
simonis@6465 678 }
simonis@6465 679
simonis@6465 680 // These are the signals that are blocked while a (non-VM) thread is
simonis@6465 681 // running Java. Only the VM thread handles these signals.
simonis@6465 682 sigset_t* os::Aix::vm_signals() {
simonis@6465 683 assert(signal_sets_initialized, "Not initialized");
simonis@6465 684 return &vm_sigs;
simonis@6465 685 }
simonis@6465 686
simonis@6465 687 // These are signals that are blocked during cond_wait to allow debugger in
simonis@6465 688 sigset_t* os::Aix::allowdebug_blocked_signals() {
simonis@6465 689 assert(signal_sets_initialized, "Not initialized");
simonis@6465 690 return &allowdebug_blocked_sigs;
simonis@6465 691 }
simonis@6465 692
simonis@6465 693 void os::Aix::hotspot_sigmask(Thread* thread) {
simonis@6465 694
simonis@6465 695 //Save caller's signal mask before setting VM signal mask
simonis@6465 696 sigset_t caller_sigmask;
simonis@6465 697 pthread_sigmask(SIG_BLOCK, NULL, &caller_sigmask);
simonis@6465 698
simonis@6465 699 OSThread* osthread = thread->osthread();
simonis@6465 700 osthread->set_caller_sigmask(caller_sigmask);
simonis@6465 701
simonis@6465 702 pthread_sigmask(SIG_UNBLOCK, os::Aix::unblocked_signals(), NULL);
simonis@6465 703
simonis@6465 704 if (!ReduceSignalUsage) {
simonis@6465 705 if (thread->is_VM_thread()) {
simonis@6465 706 // Only the VM thread handles BREAK_SIGNAL ...
simonis@6465 707 pthread_sigmask(SIG_UNBLOCK, vm_signals(), NULL);
simonis@6465 708 } else {
simonis@6465 709 // ... all other threads block BREAK_SIGNAL
simonis@6465 710 pthread_sigmask(SIG_BLOCK, vm_signals(), NULL);
simonis@6465 711 }
simonis@6465 712 }
simonis@6465 713 }
simonis@6465 714
simonis@6465 715 // retrieve memory information.
simonis@6465 716 // Returns false if something went wrong;
simonis@6465 717 // content of pmi undefined in this case.
simonis@6465 718 bool os::Aix::get_meminfo(meminfo_t* pmi) {
simonis@6465 719
simonis@6465 720 assert(pmi, "get_meminfo: invalid parameter");
simonis@6465 721
simonis@6465 722 memset(pmi, 0, sizeof(meminfo_t));
simonis@6465 723
simonis@6465 724 if (os::Aix::on_pase()) {
simonis@6465 725
simonis@6465 726 Unimplemented();
simonis@6465 727 return false;
simonis@6465 728
simonis@6465 729 } else {
simonis@6465 730
simonis@6465 731 // On AIX, I use the (dynamically loaded) perfstat library to retrieve memory statistics
simonis@6465 732 // See:
simonis@6465 733 // http://publib.boulder.ibm.com/infocenter/systems/index.jsp
simonis@6465 734 // ?topic=/com.ibm.aix.basetechref/doc/basetrf1/perfstat_memtot.htm
simonis@6465 735 // http://publib.boulder.ibm.com/infocenter/systems/index.jsp
simonis@6465 736 // ?topic=/com.ibm.aix.files/doc/aixfiles/libperfstat.h.htm
simonis@6465 737
simonis@6465 738 perfstat_memory_total_t psmt;
simonis@6465 739 memset (&psmt, '\0', sizeof(psmt));
simonis@6465 740 const int rc = libperfstat::perfstat_memory_total(NULL, &psmt, sizeof(psmt), 1);
simonis@6465 741 if (rc == -1) {
simonis@6465 742 fprintf(stderr, "perfstat_memory_total() failed (errno=%d)\n", errno);
simonis@6465 743 assert(0, "perfstat_memory_total() failed");
simonis@6465 744 return false;
simonis@6465 745 }
simonis@6465 746
simonis@6465 747 assert(rc == 1, "perfstat_memory_total() - weird return code");
simonis@6465 748
simonis@6465 749 // excerpt from
simonis@6465 750 // http://publib.boulder.ibm.com/infocenter/systems/index.jsp
simonis@6465 751 // ?topic=/com.ibm.aix.files/doc/aixfiles/libperfstat.h.htm
simonis@6465 752 // The fields of perfstat_memory_total_t:
simonis@6465 753 // u_longlong_t virt_total Total virtual memory (in 4 KB pages).
simonis@6465 754 // u_longlong_t real_total Total real memory (in 4 KB pages).
simonis@6465 755 // u_longlong_t real_free Free real memory (in 4 KB pages).
simonis@6465 756 // u_longlong_t pgsp_total Total paging space (in 4 KB pages).
simonis@6465 757 // u_longlong_t pgsp_free Free paging space (in 4 KB pages).
simonis@6465 758
simonis@6465 759 pmi->virt_total = psmt.virt_total * 4096;
simonis@6465 760 pmi->real_total = psmt.real_total * 4096;
simonis@6465 761 pmi->real_free = psmt.real_free * 4096;
simonis@6465 762 pmi->pgsp_total = psmt.pgsp_total * 4096;
simonis@6465 763 pmi->pgsp_free = psmt.pgsp_free * 4096;
simonis@6465 764
simonis@6465 765 return true;
simonis@6465 766
simonis@6465 767 }
simonis@6465 768 } // end os::Aix::get_meminfo
simonis@6465 769
simonis@6465 770 // Retrieve global cpu information.
simonis@6465 771 // Returns false if something went wrong;
simonis@6465 772 // the content of pci is undefined in this case.
simonis@6465 773 bool os::Aix::get_cpuinfo(cpuinfo_t* pci) {
simonis@6465 774 assert(pci, "get_cpuinfo: invalid parameter");
simonis@6465 775 memset(pci, 0, sizeof(cpuinfo_t));
simonis@6465 776
simonis@6465 777 perfstat_cpu_total_t psct;
simonis@6465 778 memset (&psct, '\0', sizeof(psct));
simonis@6465 779
simonis@6465 780 if (-1 == libperfstat::perfstat_cpu_total(NULL, &psct, sizeof(perfstat_cpu_total_t), 1)) {
simonis@6465 781 fprintf(stderr, "perfstat_cpu_total() failed (errno=%d)\n", errno);
simonis@6465 782 assert(0, "perfstat_cpu_total() failed");
simonis@6465 783 return false;
simonis@6465 784 }
simonis@6465 785
simonis@6465 786 // global cpu information
simonis@6465 787 strcpy (pci->description, psct.description);
simonis@6465 788 pci->processorHZ = psct.processorHZ;
simonis@6465 789 pci->ncpus = psct.ncpus;
simonis@6465 790 os::Aix::_logical_cpus = psct.ncpus;
simonis@6465 791 for (int i = 0; i < 3; i++) {
simonis@6465 792 pci->loadavg[i] = (double) psct.loadavg[i] / (1 << SBITS);
simonis@6465 793 }
simonis@6465 794
simonis@6465 795 // get the processor version from _system_configuration
simonis@6465 796 switch (_system_configuration.version) {
simonis@6465 797 case PV_7:
simonis@6465 798 strcpy(pci->version, "Power PC 7");
simonis@6465 799 break;
simonis@6465 800 case PV_6_1:
simonis@6465 801 strcpy(pci->version, "Power PC 6 DD1.x");
simonis@6465 802 break;
simonis@6465 803 case PV_6:
simonis@6465 804 strcpy(pci->version, "Power PC 6");
simonis@6465 805 break;
simonis@6465 806 case PV_5:
simonis@6465 807 strcpy(pci->version, "Power PC 5");
simonis@6465 808 break;
simonis@6465 809 case PV_5_2:
simonis@6465 810 strcpy(pci->version, "Power PC 5_2");
simonis@6465 811 break;
simonis@6465 812 case PV_5_3:
simonis@6465 813 strcpy(pci->version, "Power PC 5_3");
simonis@6465 814 break;
simonis@6465 815 case PV_5_Compat:
simonis@6465 816 strcpy(pci->version, "PV_5_Compat");
simonis@6465 817 break;
simonis@6465 818 case PV_6_Compat:
simonis@6465 819 strcpy(pci->version, "PV_6_Compat");
simonis@6465 820 break;
simonis@6465 821 case PV_7_Compat:
simonis@6465 822 strcpy(pci->version, "PV_7_Compat");
simonis@6465 823 break;
simonis@6465 824 default:
simonis@6465 825 strcpy(pci->version, "unknown");
simonis@6465 826 }
simonis@6465 827
simonis@6465 828 return true;
simonis@6465 829
simonis@6465 830 } //end os::Aix::get_cpuinfo
simonis@6465 831
simonis@6465 832 //////////////////////////////////////////////////////////////////////////////
simonis@6465 833 // detecting pthread library
simonis@6465 834
simonis@6465 835 void os::Aix::libpthread_init() {
simonis@6465 836 return;
simonis@6465 837 }
simonis@6465 838
simonis@6465 839 //////////////////////////////////////////////////////////////////////////////
simonis@6465 840 // create new thread
simonis@6465 841
simonis@6465 842 // Thread start routine for all newly created threads
simonis@6465 843 static void *java_start(Thread *thread) {
simonis@6465 844
simonis@6465 845 // find out my own stack dimensions
simonis@6465 846 {
simonis@6465 847 // actually, this should do exactly the same as thread->record_stack_base_and_size...
simonis@6465 848 address base = 0;
simonis@6465 849 size_t size = 0;
simonis@6465 850 query_stack_dimensions(&base, &size);
simonis@6465 851 thread->set_stack_base(base);
simonis@6465 852 thread->set_stack_size(size);
simonis@6465 853 }
simonis@6465 854
simonis@6465 855 // Do some sanity checks.
simonis@6465 856 CHECK_CURRENT_STACK_PTR(thread->stack_base(), thread->stack_size());
simonis@6465 857
simonis@6465 858 // Try to randomize the cache line index of hot stack frames.
simonis@6465 859 // This helps when threads of the same stack traces evict each other's
simonis@6465 860 // cache lines. The threads can be either from the same JVM instance, or
simonis@6465 861 // from different JVM instances. The benefit is especially true for
simonis@6465 862 // processors with hyperthreading technology.
simonis@6465 863
simonis@6465 864 static int counter = 0;
simonis@6465 865 int pid = os::current_process_id();
simonis@6465 866 alloca(((pid ^ counter++) & 7) * 128);
simonis@6465 867
simonis@6465 868 ThreadLocalStorage::set_thread(thread);
simonis@6465 869
simonis@6465 870 OSThread* osthread = thread->osthread();
simonis@6465 871
simonis@6465 872 // thread_id is kernel thread id (similar to Solaris LWP id)
simonis@6465 873 osthread->set_thread_id(os::Aix::gettid());
simonis@6465 874
simonis@6465 875 // initialize signal mask for this thread
simonis@6465 876 os::Aix::hotspot_sigmask(thread);
simonis@6465 877
simonis@6465 878 // initialize floating point control register
simonis@6465 879 os::Aix::init_thread_fpu_state();
simonis@6465 880
simonis@6465 881 assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
simonis@6465 882
simonis@6465 883 // call one more level start routine
simonis@6465 884 thread->run();
simonis@6465 885
simonis@6465 886 return 0;
simonis@6465 887 }
simonis@6465 888
simonis@6465 889 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
simonis@6465 890
simonis@6465 891 // We want the whole function to be synchronized.
simonis@6465 892 ThreadCritical cs;
simonis@6465 893
simonis@6465 894 assert(thread->osthread() == NULL, "caller responsible");
simonis@6465 895
simonis@6465 896 // Allocate the OSThread object
simonis@6465 897 OSThread* osthread = new OSThread(NULL, NULL);
simonis@6465 898 if (osthread == NULL) {
simonis@6465 899 return false;
simonis@6465 900 }
simonis@6465 901
simonis@6465 902 // set the correct thread state
simonis@6465 903 osthread->set_thread_type(thr_type);
simonis@6465 904
simonis@6465 905 // Initial state is ALLOCATED but not INITIALIZED
simonis@6465 906 osthread->set_state(ALLOCATED);
simonis@6465 907
simonis@6465 908 thread->set_osthread(osthread);
simonis@6465 909
simonis@6465 910 // init thread attributes
simonis@6465 911 pthread_attr_t attr;
simonis@6465 912 pthread_attr_init(&attr);
simonis@6465 913 guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
simonis@6465 914
simonis@6465 915 // Make sure we run in 1:1 kernel-user-thread mode.
simonis@6465 916 if (os::Aix::on_aix()) {
simonis@6465 917 guarantee(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0, "???");
simonis@6465 918 guarantee(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0, "???");
simonis@6465 919 } // end: aix
simonis@6465 920
simonis@6465 921 // Start in suspended state, and in os::thread_start, wake the thread up.
simonis@6465 922 guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???");
simonis@6465 923
simonis@6465 924 // calculate stack size if it's not specified by caller
simonis@6465 925 if (os::Aix::supports_variable_stack_size()) {
simonis@6465 926 if (stack_size == 0) {
simonis@6465 927 stack_size = os::Aix::default_stack_size(thr_type);
simonis@6465 928
simonis@6465 929 switch (thr_type) {
simonis@6465 930 case os::java_thread:
simonis@6465 931 // Java threads use ThreadStackSize whose default value can be changed with the flag -Xss.
simonis@6465 932 assert(JavaThread::stack_size_at_create() > 0, "this should be set");
simonis@6465 933 stack_size = JavaThread::stack_size_at_create();
simonis@6465 934 break;
simonis@6465 935 case os::compiler_thread:
simonis@6465 936 if (CompilerThreadStackSize > 0) {
simonis@6465 937 stack_size = (size_t)(CompilerThreadStackSize * K);
simonis@6465 938 break;
simonis@6465 939 } // else fall through:
simonis@6465 940 // use VMThreadStackSize if CompilerThreadStackSize is not defined
simonis@6465 941 case os::vm_thread:
simonis@6465 942 case os::pgc_thread:
simonis@6465 943 case os::cgc_thread:
simonis@6465 944 case os::watcher_thread:
simonis@6465 945 if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
simonis@6465 946 break;
simonis@6465 947 }
simonis@6465 948 }
simonis@6465 949
simonis@6465 950 stack_size = MAX2(stack_size, os::Aix::min_stack_allowed);
simonis@6465 951 pthread_attr_setstacksize(&attr, stack_size);
simonis@6465 952 } //else let thread_create() pick the default value (96 K on AIX)
simonis@6465 953
simonis@6465 954 pthread_t tid;
simonis@6465 955 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
simonis@6465 956
simonis@6465 957 pthread_attr_destroy(&attr);
simonis@6465 958
simonis@6465 959 if (ret != 0) {
simonis@6465 960 if (PrintMiscellaneous && (Verbose || WizardMode)) {
simonis@6465 961 perror("pthread_create()");
simonis@6465 962 }
simonis@6465 963 // Need to clean up stuff we've allocated so far
simonis@6465 964 thread->set_osthread(NULL);
simonis@6465 965 delete osthread;
simonis@6465 966 return false;
simonis@6465 967 }
simonis@6465 968
simonis@6465 969 // Store pthread info into the OSThread
simonis@6465 970 osthread->set_pthread_id(tid);
simonis@6465 971
simonis@6465 972 return true;
simonis@6465 973 }
simonis@6465 974
simonis@6465 975 /////////////////////////////////////////////////////////////////////////////
simonis@6465 976 // attach existing thread
simonis@6465 977
simonis@6465 978 // bootstrap the main thread
simonis@6465 979 bool os::create_main_thread(JavaThread* thread) {
simonis@6465 980 assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread");
simonis@6465 981 return create_attached_thread(thread);
simonis@6465 982 }
simonis@6465 983
simonis@6465 984 bool os::create_attached_thread(JavaThread* thread) {
simonis@6465 985 #ifdef ASSERT
simonis@6465 986 thread->verify_not_published();
simonis@6465 987 #endif
simonis@6465 988
simonis@6465 989 // Allocate the OSThread object
simonis@6465 990 OSThread* osthread = new OSThread(NULL, NULL);
simonis@6465 991
simonis@6465 992 if (osthread == NULL) {
simonis@6465 993 return false;
simonis@6465 994 }
simonis@6465 995
simonis@6465 996 // Store pthread info into the OSThread
simonis@6465 997 osthread->set_thread_id(os::Aix::gettid());
simonis@6465 998 osthread->set_pthread_id(::pthread_self());
simonis@6465 999
simonis@6465 1000 // initialize floating point control register
simonis@6465 1001 os::Aix::init_thread_fpu_state();
simonis@6465 1002
simonis@6465 1003 // some sanity checks
simonis@6465 1004 CHECK_CURRENT_STACK_PTR(thread->stack_base(), thread->stack_size());
simonis@6465 1005
simonis@6465 1006 // Initial thread state is RUNNABLE
simonis@6465 1007 osthread->set_state(RUNNABLE);
simonis@6465 1008
simonis@6465 1009 thread->set_osthread(osthread);
simonis@6465 1010
simonis@6465 1011 if (UseNUMA) {
simonis@6465 1012 int lgrp_id = os::numa_get_group_id();
simonis@6465 1013 if (lgrp_id != -1) {
simonis@6465 1014 thread->set_lgrp_id(lgrp_id);
simonis@6465 1015 }
simonis@6465 1016 }
simonis@6465 1017
simonis@6465 1018 // initialize signal mask for this thread
simonis@6465 1019 // and save the caller's signal mask
simonis@6465 1020 os::Aix::hotspot_sigmask(thread);
simonis@6465 1021
simonis@6465 1022 return true;
simonis@6465 1023 }
simonis@6465 1024
simonis@6465 1025 void os::pd_start_thread(Thread* thread) {
simonis@6465 1026 int status = pthread_continue_np(thread->osthread()->pthread_id());
simonis@6465 1027 assert(status == 0, "thr_continue failed");
simonis@6465 1028 }
simonis@6465 1029
simonis@6465 1030 // Free OS resources related to the OSThread
simonis@6465 1031 void os::free_thread(OSThread* osthread) {
simonis@6465 1032 assert(osthread != NULL, "osthread not set");
simonis@6465 1033
simonis@6465 1034 if (Thread::current()->osthread() == osthread) {
simonis@6465 1035 // Restore caller's signal mask
simonis@6465 1036 sigset_t sigmask = osthread->caller_sigmask();
simonis@6465 1037 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
simonis@6465 1038 }
simonis@6465 1039
simonis@6465 1040 delete osthread;
simonis@6465 1041 }
simonis@6465 1042
simonis@6465 1043 //////////////////////////////////////////////////////////////////////////////
simonis@6465 1044 // thread local storage
simonis@6465 1045
simonis@6465 1046 int os::allocate_thread_local_storage() {
simonis@6465 1047 pthread_key_t key;
simonis@6465 1048 int rslt = pthread_key_create(&key, NULL);
simonis@6465 1049 assert(rslt == 0, "cannot allocate thread local storage");
simonis@6465 1050 return (int)key;
simonis@6465 1051 }
simonis@6465 1052
simonis@6465 1053 // Note: This is currently not used by VM, as we don't destroy TLS key
simonis@6465 1054 // on VM exit.
simonis@6465 1055 void os::free_thread_local_storage(int index) {
simonis@6465 1056 int rslt = pthread_key_delete((pthread_key_t)index);
simonis@6465 1057 assert(rslt == 0, "invalid index");
simonis@6465 1058 }
simonis@6465 1059
simonis@6465 1060 void os::thread_local_storage_at_put(int index, void* value) {
simonis@6465 1061 int rslt = pthread_setspecific((pthread_key_t)index, value);
simonis@6465 1062 assert(rslt == 0, "pthread_setspecific failed");
simonis@6465 1063 }
simonis@6465 1064
simonis@6465 1065 extern "C" Thread* get_thread() {
simonis@6465 1066 return ThreadLocalStorage::thread();
simonis@6465 1067 }
simonis@6465 1068
simonis@6465 1069 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 1070 // time support
simonis@6465 1071
simonis@6465 1072 // Time since start-up in seconds to a fine granularity.
simonis@6465 1073 // Used by VMSelfDestructTimer and the MemProfiler.
simonis@6465 1074 double os::elapsedTime() {
simonis@6465 1075 return (double)(os::elapsed_counter()) * 0.000001;
simonis@6465 1076 }
simonis@6465 1077
simonis@6465 1078 jlong os::elapsed_counter() {
simonis@6465 1079 timeval time;
simonis@6465 1080 int status = gettimeofday(&time, NULL);
simonis@6465 1081 return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
simonis@6465 1082 }
simonis@6465 1083
simonis@6465 1084 jlong os::elapsed_frequency() {
simonis@6465 1085 return (1000 * 1000);
simonis@6465 1086 }
simonis@6465 1087
simonis@6465 1088 // For now, we say that linux does not support vtime. I have no idea
simonis@6465 1089 // whether it can actually be made to (DLD, 9/13/05).
simonis@6465 1090
simonis@6465 1091 bool os::supports_vtime() { return false; }
simonis@6465 1092 bool os::enable_vtime() { return false; }
simonis@6465 1093 bool os::vtime_enabled() { return false; }
simonis@6465 1094 double os::elapsedVTime() {
simonis@6465 1095 // better than nothing, but not much
simonis@6465 1096 return elapsedTime();
simonis@6465 1097 }
simonis@6465 1098
simonis@6465 1099 jlong os::javaTimeMillis() {
simonis@6465 1100 timeval time;
simonis@6465 1101 int status = gettimeofday(&time, NULL);
simonis@6465 1102 assert(status != -1, "aix error at gettimeofday()");
simonis@6465 1103 return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
simonis@6465 1104 }
simonis@6465 1105
simonis@6465 1106 // We need to manually declare mread_real_time,
simonis@6465 1107 // because IBM didn't provide a prototype in time.h.
simonis@6465 1108 // (they probably only ever tested in C, not C++)
simonis@6465 1109 extern "C"
simonis@6465 1110 int mread_real_time(timebasestruct_t *t, size_t size_of_timebasestruct_t);
simonis@6465 1111
simonis@6465 1112 jlong os::javaTimeNanos() {
simonis@6465 1113 if (os::Aix::on_pase()) {
simonis@6465 1114 Unimplemented();
simonis@6465 1115 return 0;
simonis@6465 1116 }
simonis@6465 1117 else {
simonis@6465 1118 // On AIX use the precision of processors real time clock
simonis@6465 1119 // or time base registers.
simonis@6465 1120 timebasestruct_t time;
simonis@6465 1121 int rc;
simonis@6465 1122
simonis@6465 1123 // If the CPU has a time register, it will be used and
simonis@6465 1124 // we have to convert to real time first. After convertion we have following data:
simonis@6465 1125 // time.tb_high [seconds since 00:00:00 UTC on 1.1.1970]
simonis@6465 1126 // time.tb_low [nanoseconds after the last full second above]
simonis@6465 1127 // We better use mread_real_time here instead of read_real_time
simonis@6465 1128 // to ensure that we will get a monotonic increasing time.
simonis@6465 1129 if (mread_real_time(&time, TIMEBASE_SZ) != RTC_POWER) {
simonis@6465 1130 rc = time_base_to_time(&time, TIMEBASE_SZ);
simonis@6465 1131 assert(rc != -1, "aix error at time_base_to_time()");
simonis@6465 1132 }
simonis@6465 1133 return jlong(time.tb_high) * (1000 * 1000 * 1000) + jlong(time.tb_low);
simonis@6465 1134 }
simonis@6465 1135 }
simonis@6465 1136
simonis@6465 1137 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
simonis@6465 1138 {
simonis@6465 1139 // gettimeofday - based on time in seconds since the Epoch thus does not wrap
simonis@6465 1140 info_ptr->max_value = ALL_64_BITS;
simonis@6465 1141
simonis@6465 1142 // gettimeofday is a real time clock so it skips
simonis@6465 1143 info_ptr->may_skip_backward = true;
simonis@6465 1144 info_ptr->may_skip_forward = true;
simonis@6465 1145 }
simonis@6465 1146
simonis@6465 1147 info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
simonis@6465 1148 }
simonis@6465 1149
simonis@6465 1150 // Return the real, user, and system times in seconds from an
simonis@6465 1151 // arbitrary fixed point in the past.
simonis@6465 1152 bool os::getTimesSecs(double* process_real_time,
simonis@6465 1153 double* process_user_time,
simonis@6465 1154 double* process_system_time) {
goetz@6501 1155 struct tms ticks;
goetz@6501 1156 clock_t real_ticks = times(&ticks);
goetz@6501 1157
goetz@6501 1158 if (real_ticks == (clock_t) (-1)) {
goetz@6501 1159 return false;
goetz@6501 1160 } else {
goetz@6501 1161 double ticks_per_second = (double) clock_tics_per_sec;
goetz@6501 1162 *process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
goetz@6501 1163 *process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
goetz@6501 1164 *process_real_time = ((double) real_ticks) / ticks_per_second;
goetz@6501 1165
goetz@6501 1166 return true;
goetz@6501 1167 }
simonis@6465 1168 }
simonis@6465 1169
simonis@6465 1170
simonis@6465 1171 char * os::local_time_string(char *buf, size_t buflen) {
simonis@6465 1172 struct tm t;
simonis@6465 1173 time_t long_time;
simonis@6465 1174 time(&long_time);
simonis@6465 1175 localtime_r(&long_time, &t);
simonis@6465 1176 jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
simonis@6465 1177 t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
simonis@6465 1178 t.tm_hour, t.tm_min, t.tm_sec);
simonis@6465 1179 return buf;
simonis@6465 1180 }
simonis@6465 1181
simonis@6465 1182 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
simonis@6465 1183 return localtime_r(clock, res);
simonis@6465 1184 }
simonis@6465 1185
simonis@6465 1186 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 1187 // runtime exit support
simonis@6465 1188
simonis@6465 1189 // Note: os::shutdown() might be called very early during initialization, or
simonis@6465 1190 // called from signal handler. Before adding something to os::shutdown(), make
simonis@6465 1191 // sure it is async-safe and can handle partially initialized VM.
simonis@6465 1192 void os::shutdown() {
simonis@6465 1193
simonis@6465 1194 // allow PerfMemory to attempt cleanup of any persistent resources
simonis@6465 1195 perfMemory_exit();
simonis@6465 1196
simonis@6465 1197 // needs to remove object in file system
simonis@6465 1198 AttachListener::abort();
simonis@6465 1199
simonis@6465 1200 // flush buffered output, finish log files
simonis@6465 1201 ostream_abort();
simonis@6465 1202
simonis@6465 1203 // Check for abort hook
simonis@6465 1204 abort_hook_t abort_hook = Arguments::abort_hook();
simonis@6465 1205 if (abort_hook != NULL) {
simonis@6465 1206 abort_hook();
simonis@6465 1207 }
simonis@6465 1208
simonis@6465 1209 }
simonis@6465 1210
simonis@6465 1211 // Note: os::abort() might be called very early during initialization, or
simonis@6465 1212 // called from signal handler. Before adding something to os::abort(), make
simonis@6465 1213 // sure it is async-safe and can handle partially initialized VM.
simonis@6465 1214 void os::abort(bool dump_core) {
simonis@6465 1215 os::shutdown();
simonis@6465 1216 if (dump_core) {
simonis@6465 1217 #ifndef PRODUCT
simonis@6465 1218 fdStream out(defaultStream::output_fd());
simonis@6465 1219 out.print_raw("Current thread is ");
simonis@6465 1220 char buf[16];
simonis@6465 1221 jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id());
simonis@6465 1222 out.print_raw_cr(buf);
simonis@6465 1223 out.print_raw_cr("Dumping core ...");
simonis@6465 1224 #endif
simonis@6465 1225 ::abort(); // dump core
simonis@6465 1226 }
simonis@6465 1227
simonis@6465 1228 ::exit(1);
simonis@6465 1229 }
simonis@6465 1230
simonis@6465 1231 // Die immediately, no exit hook, no abort hook, no cleanup.
simonis@6465 1232 void os::die() {
simonis@6465 1233 ::abort();
simonis@6465 1234 }
simonis@6465 1235
simonis@6465 1236 // Unused on Aix for now.
simonis@6465 1237 void os::set_error_file(const char *logfile) {}
simonis@6465 1238
simonis@6465 1239
simonis@6465 1240 // This method is a copy of JDK's sysGetLastErrorString
simonis@6465 1241 // from src/solaris/hpi/src/system_md.c
simonis@6465 1242
simonis@6465 1243 size_t os::lasterror(char *buf, size_t len) {
simonis@6465 1244
simonis@6465 1245 if (errno == 0) return 0;
simonis@6465 1246
simonis@6465 1247 const char *s = ::strerror(errno);
simonis@6465 1248 size_t n = ::strlen(s);
simonis@6465 1249 if (n >= len) {
simonis@6465 1250 n = len - 1;
simonis@6465 1251 }
simonis@6465 1252 ::strncpy(buf, s, n);
simonis@6465 1253 buf[n] = '\0';
simonis@6465 1254 return n;
simonis@6465 1255 }
simonis@6465 1256
simonis@6465 1257 intx os::current_thread_id() { return (intx)pthread_self(); }
simonis@6465 1258 int os::current_process_id() {
simonis@6465 1259
simonis@6465 1260 // This implementation returns a unique pid, the pid of the
simonis@6465 1261 // launcher thread that starts the vm 'process'.
simonis@6465 1262
simonis@6465 1263 // Under POSIX, getpid() returns the same pid as the
simonis@6465 1264 // launcher thread rather than a unique pid per thread.
simonis@6465 1265 // Use gettid() if you want the old pre NPTL behaviour.
simonis@6465 1266
simonis@6465 1267 // if you are looking for the result of a call to getpid() that
simonis@6465 1268 // returns a unique pid for the calling thread, then look at the
simonis@6465 1269 // OSThread::thread_id() method in osThread_linux.hpp file
simonis@6465 1270
simonis@6465 1271 return (int)(_initial_pid ? _initial_pid : getpid());
simonis@6465 1272 }
simonis@6465 1273
simonis@6465 1274 // DLL functions
simonis@6465 1275
simonis@6465 1276 const char* os::dll_file_extension() { return ".so"; }
simonis@6465 1277
simonis@6465 1278 // This must be hard coded because it's the system's temporary
simonis@6465 1279 // directory not the java application's temp directory, ala java.io.tmpdir.
simonis@6465 1280 const char* os::get_temp_directory() { return "/tmp"; }
simonis@6465 1281
simonis@6465 1282 static bool file_exists(const char* filename) {
simonis@6465 1283 struct stat statbuf;
simonis@6465 1284 if (filename == NULL || strlen(filename) == 0) {
simonis@6465 1285 return false;
simonis@6465 1286 }
simonis@6465 1287 return os::stat(filename, &statbuf) == 0;
simonis@6465 1288 }
simonis@6465 1289
simonis@6465 1290 bool os::dll_build_name(char* buffer, size_t buflen,
simonis@6465 1291 const char* pname, const char* fname) {
simonis@6465 1292 bool retval = false;
simonis@6465 1293 // Copied from libhpi
simonis@6465 1294 const size_t pnamelen = pname ? strlen(pname) : 0;
simonis@6465 1295
simonis@6465 1296 // Return error on buffer overflow.
simonis@6465 1297 if (pnamelen + strlen(fname) + 10 > (size_t) buflen) {
simonis@6465 1298 *buffer = '\0';
simonis@6465 1299 return retval;
simonis@6465 1300 }
simonis@6465 1301
simonis@6465 1302 if (pnamelen == 0) {
simonis@6465 1303 snprintf(buffer, buflen, "lib%s.so", fname);
simonis@6465 1304 retval = true;
simonis@6465 1305 } else if (strchr(pname, *os::path_separator()) != NULL) {
simonis@6465 1306 int n;
simonis@6465 1307 char** pelements = split_path(pname, &n);
simonis@6465 1308 for (int i = 0; i < n; i++) {
simonis@6465 1309 // Really shouldn't be NULL, but check can't hurt
simonis@6465 1310 if (pelements[i] == NULL || strlen(pelements[i]) == 0) {
simonis@6465 1311 continue; // skip the empty path values
simonis@6465 1312 }
simonis@6465 1313 snprintf(buffer, buflen, "%s/lib%s.so", pelements[i], fname);
simonis@6465 1314 if (file_exists(buffer)) {
simonis@6465 1315 retval = true;
simonis@6465 1316 break;
simonis@6465 1317 }
simonis@6465 1318 }
simonis@6465 1319 // release the storage
simonis@6465 1320 for (int i = 0; i < n; i++) {
simonis@6465 1321 if (pelements[i] != NULL) {
simonis@6465 1322 FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal);
simonis@6465 1323 }
simonis@6465 1324 }
simonis@6465 1325 if (pelements != NULL) {
simonis@6465 1326 FREE_C_HEAP_ARRAY(char*, pelements, mtInternal);
simonis@6465 1327 }
simonis@6465 1328 } else {
simonis@6465 1329 snprintf(buffer, buflen, "%s/lib%s.so", pname, fname);
simonis@6465 1330 retval = true;
simonis@6465 1331 }
simonis@6465 1332 return retval;
simonis@6465 1333 }
simonis@6465 1334
simonis@6465 1335 // Check if addr is inside libjvm.so.
simonis@6465 1336 bool os::address_is_in_vm(address addr) {
simonis@6465 1337
simonis@6465 1338 // Input could be a real pc or a function pointer literal. The latter
simonis@6465 1339 // would be a function descriptor residing in the data segment of a module.
simonis@6465 1340
simonis@6465 1341 const LoadedLibraryModule* lib = LoadedLibraries::find_for_text_address(addr);
simonis@6465 1342 if (lib) {
simonis@6465 1343 if (strcmp(lib->get_shortname(), "libjvm.so") == 0) {
simonis@6465 1344 return true;
simonis@6465 1345 } else {
simonis@6465 1346 return false;
simonis@6465 1347 }
simonis@6465 1348 } else {
simonis@6465 1349 lib = LoadedLibraries::find_for_data_address(addr);
simonis@6465 1350 if (lib) {
simonis@6465 1351 if (strcmp(lib->get_shortname(), "libjvm.so") == 0) {
simonis@6465 1352 return true;
simonis@6465 1353 } else {
simonis@6465 1354 return false;
simonis@6465 1355 }
simonis@6465 1356 } else {
simonis@6465 1357 return false;
simonis@6465 1358 }
simonis@6465 1359 }
simonis@6465 1360 }
simonis@6465 1361
simonis@6465 1362 // Resolve an AIX function descriptor literal to a code pointer.
simonis@6465 1363 // If the input is a valid code pointer to a text segment of a loaded module,
simonis@6465 1364 // it is returned unchanged.
simonis@6465 1365 // If the input is a valid AIX function descriptor, it is resolved to the
simonis@6465 1366 // code entry point.
simonis@6465 1367 // If the input is neither a valid function descriptor nor a valid code pointer,
simonis@6465 1368 // NULL is returned.
simonis@6465 1369 static address resolve_function_descriptor_to_code_pointer(address p) {
simonis@6465 1370
simonis@6465 1371 const LoadedLibraryModule* lib = LoadedLibraries::find_for_text_address(p);
simonis@6465 1372 if (lib) {
simonis@6465 1373 // its a real code pointer
simonis@6465 1374 return p;
simonis@6465 1375 } else {
simonis@6465 1376 lib = LoadedLibraries::find_for_data_address(p);
simonis@6465 1377 if (lib) {
simonis@6465 1378 // pointer to data segment, potential function descriptor
simonis@6465 1379 address code_entry = (address)(((FunctionDescriptor*)p)->entry());
simonis@6465 1380 if (LoadedLibraries::find_for_text_address(code_entry)) {
simonis@6465 1381 // Its a function descriptor
simonis@6465 1382 return code_entry;
simonis@6465 1383 }
simonis@6465 1384 }
simonis@6465 1385 }
simonis@6465 1386 return NULL;
simonis@6465 1387 }
simonis@6465 1388
simonis@6465 1389 bool os::dll_address_to_function_name(address addr, char *buf,
simonis@6465 1390 int buflen, int *offset) {
simonis@6465 1391 if (offset) {
simonis@6465 1392 *offset = -1;
simonis@6465 1393 }
simonis@6465 1394 if (buf) {
simonis@6465 1395 buf[0] = '\0';
simonis@6465 1396 }
simonis@6465 1397
simonis@6465 1398 // Resolve function ptr literals first.
simonis@6465 1399 addr = resolve_function_descriptor_to_code_pointer(addr);
simonis@6465 1400 if (!addr) {
simonis@6465 1401 return false;
simonis@6465 1402 }
simonis@6465 1403
simonis@6465 1404 // Go through Decoder::decode to call getFuncName which reads the name from the traceback table.
simonis@6465 1405 return Decoder::decode(addr, buf, buflen, offset);
simonis@6465 1406 }
simonis@6465 1407
simonis@6465 1408 static int getModuleName(codeptr_t pc, // [in] program counter
simonis@6465 1409 char* p_name, size_t namelen, // [out] optional: function name
simonis@6465 1410 char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages
simonis@6465 1411 ) {
simonis@6465 1412
simonis@6465 1413 // initialize output parameters
simonis@6465 1414 if (p_name && namelen > 0) {
simonis@6465 1415 *p_name = '\0';
simonis@6465 1416 }
simonis@6465 1417 if (p_errmsg && errmsglen > 0) {
simonis@6465 1418 *p_errmsg = '\0';
simonis@6465 1419 }
simonis@6465 1420
simonis@6465 1421 const LoadedLibraryModule* const lib = LoadedLibraries::find_for_text_address((address)pc);
simonis@6465 1422 if (lib) {
simonis@6465 1423 if (p_name && namelen > 0) {
simonis@6465 1424 sprintf(p_name, "%.*s", namelen, lib->get_shortname());
simonis@6465 1425 }
simonis@6465 1426 return 0;
simonis@6465 1427 }
simonis@6465 1428
simonis@6465 1429 if (Verbose) {
simonis@6465 1430 fprintf(stderr, "pc outside any module");
simonis@6465 1431 }
simonis@6465 1432
simonis@6465 1433 return -1;
simonis@6465 1434
simonis@6465 1435 }
simonis@6465 1436
simonis@6465 1437 bool os::dll_address_to_library_name(address addr, char* buf,
simonis@6465 1438 int buflen, int* offset) {
simonis@6465 1439 if (offset) {
simonis@6465 1440 *offset = -1;
simonis@6465 1441 }
simonis@6465 1442 if (buf) {
simonis@6465 1443 buf[0] = '\0';
simonis@6465 1444 }
simonis@6465 1445
simonis@6465 1446 // Resolve function ptr literals first.
simonis@6465 1447 addr = resolve_function_descriptor_to_code_pointer(addr);
simonis@6465 1448 if (!addr) {
simonis@6465 1449 return false;
simonis@6465 1450 }
simonis@6465 1451
simonis@6465 1452 if (::getModuleName((codeptr_t) addr, buf, buflen, 0, 0) == 0) {
simonis@6465 1453 return true;
simonis@6465 1454 }
simonis@6465 1455 return false;
simonis@6465 1456 }
simonis@6465 1457
simonis@6465 1458 // Loads .dll/.so and in case of error it checks if .dll/.so was built
simonis@6465 1459 // for the same architecture as Hotspot is running on
simonis@6465 1460 void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
simonis@6465 1461
simonis@6465 1462 if (ebuf && ebuflen > 0) {
simonis@6465 1463 ebuf[0] = '\0';
simonis@6465 1464 ebuf[ebuflen - 1] = '\0';
simonis@6465 1465 }
simonis@6465 1466
simonis@6465 1467 if (!filename || strlen(filename) == 0) {
simonis@6465 1468 ::strncpy(ebuf, "dll_load: empty filename specified", ebuflen - 1);
simonis@6465 1469 return NULL;
simonis@6465 1470 }
simonis@6465 1471
simonis@6465 1472 // RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants.
simonis@6465 1473 void * result= ::dlopen(filename, RTLD_LAZY);
simonis@6465 1474 if (result != NULL) {
simonis@6465 1475 // Reload dll cache. Don't do this in signal handling.
simonis@6465 1476 LoadedLibraries::reload();
simonis@6465 1477 return result;
simonis@6465 1478 } else {
simonis@6465 1479 // error analysis when dlopen fails
simonis@6465 1480 const char* const error_report = ::dlerror();
simonis@6465 1481 if (error_report && ebuf && ebuflen > 0) {
simonis@6465 1482 snprintf(ebuf, ebuflen - 1, "%s, LIBPATH=%s, LD_LIBRARY_PATH=%s : %s",
simonis@6465 1483 filename, ::getenv("LIBPATH"), ::getenv("LD_LIBRARY_PATH"), error_report);
simonis@6465 1484 }
simonis@6465 1485 }
simonis@6465 1486 return NULL;
simonis@6465 1487 }
simonis@6465 1488
simonis@6465 1489 // Glibc-2.0 libdl is not MT safe. If you are building with any glibc,
simonis@6465 1490 // chances are you might want to run the generated bits against glibc-2.0
simonis@6465 1491 // libdl.so, so always use locking for any version of glibc.
simonis@6465 1492 void* os::dll_lookup(void* handle, const char* name) {
simonis@6465 1493 pthread_mutex_lock(&dl_mutex);
simonis@6465 1494 void* res = dlsym(handle, name);
simonis@6465 1495 pthread_mutex_unlock(&dl_mutex);
simonis@6465 1496 return res;
simonis@6465 1497 }
simonis@6465 1498
simonis@6465 1499 void os::print_dll_info(outputStream *st) {
simonis@6465 1500 st->print_cr("Dynamic libraries:");
simonis@6465 1501 LoadedLibraries::print(st);
simonis@6465 1502 }
simonis@6465 1503
simonis@6465 1504 void os::print_os_info(outputStream* st) {
simonis@6465 1505 st->print("OS:");
simonis@6465 1506
simonis@6465 1507 st->print("uname:");
simonis@6465 1508 struct utsname name;
simonis@6465 1509 uname(&name);
simonis@6465 1510 st->print(name.sysname); st->print(" ");
simonis@6465 1511 st->print(name.nodename); st->print(" ");
simonis@6465 1512 st->print(name.release); st->print(" ");
simonis@6465 1513 st->print(name.version); st->print(" ");
simonis@6465 1514 st->print(name.machine);
simonis@6465 1515 st->cr();
simonis@6465 1516
simonis@6465 1517 // rlimit
simonis@6465 1518 st->print("rlimit:");
simonis@6465 1519 struct rlimit rlim;
simonis@6465 1520
simonis@6465 1521 st->print(" STACK ");
simonis@6465 1522 getrlimit(RLIMIT_STACK, &rlim);
simonis@6465 1523 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
simonis@6465 1524 else st->print("%uk", rlim.rlim_cur >> 10);
simonis@6465 1525
simonis@6465 1526 st->print(", CORE ");
simonis@6465 1527 getrlimit(RLIMIT_CORE, &rlim);
simonis@6465 1528 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
simonis@6465 1529 else st->print("%uk", rlim.rlim_cur >> 10);
simonis@6465 1530
simonis@6465 1531 st->print(", NPROC ");
simonis@6465 1532 st->print("%d", sysconf(_SC_CHILD_MAX));
simonis@6465 1533
simonis@6465 1534 st->print(", NOFILE ");
simonis@6465 1535 getrlimit(RLIMIT_NOFILE, &rlim);
simonis@6465 1536 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
simonis@6465 1537 else st->print("%d", rlim.rlim_cur);
simonis@6465 1538
simonis@6465 1539 st->print(", AS ");
simonis@6465 1540 getrlimit(RLIMIT_AS, &rlim);
simonis@6465 1541 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
simonis@6465 1542 else st->print("%uk", rlim.rlim_cur >> 10);
simonis@6465 1543
simonis@6465 1544 // Print limits on DATA, because it limits the C-heap.
simonis@6465 1545 st->print(", DATA ");
simonis@6465 1546 getrlimit(RLIMIT_DATA, &rlim);
simonis@6465 1547 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
simonis@6465 1548 else st->print("%uk", rlim.rlim_cur >> 10);
simonis@6465 1549 st->cr();
simonis@6465 1550
simonis@6465 1551 // load average
simonis@6465 1552 st->print("load average:");
simonis@6465 1553 double loadavg[3] = {-1.L, -1.L, -1.L};
simonis@6465 1554 os::loadavg(loadavg, 3);
simonis@6465 1555 st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
simonis@6465 1556 st->cr();
simonis@6465 1557 }
simonis@6465 1558
simonis@6465 1559 void os::print_memory_info(outputStream* st) {
simonis@6465 1560
simonis@6465 1561 st->print_cr("Memory:");
simonis@6465 1562
simonis@6465 1563 st->print_cr(" default page size: %s", describe_pagesize(os::vm_page_size()));
simonis@6465 1564 st->print_cr(" default stack page size: %s", describe_pagesize(os::vm_page_size()));
simonis@6465 1565 st->print_cr(" default shm page size: %s", describe_pagesize(os::Aix::shm_default_page_size()));
simonis@6465 1566 st->print_cr(" can use 64K pages dynamically: %s", (os::Aix::can_use_64K_pages() ? "yes" :"no"));
simonis@6465 1567 st->print_cr(" can use 16M pages dynamically: %s", (os::Aix::can_use_16M_pages() ? "yes" :"no"));
simonis@6465 1568 if (g_multipage_error != 0) {
simonis@6465 1569 st->print_cr(" multipage error: %d", g_multipage_error);
simonis@6465 1570 }
simonis@6465 1571
simonis@6465 1572 // print out LDR_CNTRL because it affects the default page sizes
simonis@6465 1573 const char* const ldr_cntrl = ::getenv("LDR_CNTRL");
simonis@6465 1574 st->print_cr(" LDR_CNTRL=%s.", ldr_cntrl ? ldr_cntrl : "<unset>");
simonis@6465 1575
simonis@6465 1576 const char* const extshm = ::getenv("EXTSHM");
simonis@6465 1577 st->print_cr(" EXTSHM=%s.", extshm ? extshm : "<unset>");
simonis@6465 1578
simonis@6465 1579 // Call os::Aix::get_meminfo() to retrieve memory statistics.
simonis@6465 1580 os::Aix::meminfo_t mi;
simonis@6465 1581 if (os::Aix::get_meminfo(&mi)) {
simonis@6465 1582 char buffer[256];
simonis@6465 1583 if (os::Aix::on_aix()) {
simonis@6465 1584 jio_snprintf(buffer, sizeof(buffer),
simonis@6465 1585 " physical total : %llu\n"
simonis@6465 1586 " physical free : %llu\n"
simonis@6465 1587 " swap total : %llu\n"
simonis@6465 1588 " swap free : %llu\n",
simonis@6465 1589 mi.real_total,
simonis@6465 1590 mi.real_free,
simonis@6465 1591 mi.pgsp_total,
simonis@6465 1592 mi.pgsp_free);
simonis@6465 1593 } else {
simonis@6465 1594 Unimplemented();
simonis@6465 1595 }
simonis@6465 1596 st->print_raw(buffer);
simonis@6465 1597 } else {
simonis@6465 1598 st->print_cr(" (no more information available)");
simonis@6465 1599 }
simonis@6465 1600 }
simonis@6465 1601
simonis@6465 1602 void os::pd_print_cpu_info(outputStream* st) {
simonis@6465 1603 // cpu
simonis@6465 1604 st->print("CPU:");
simonis@6465 1605 st->print("total %d", os::processor_count());
simonis@6465 1606 // It's not safe to query number of active processors after crash
simonis@6465 1607 // st->print("(active %d)", os::active_processor_count());
simonis@6465 1608 st->print(" %s", VM_Version::cpu_features());
simonis@6465 1609 st->cr();
simonis@6465 1610 }
simonis@6465 1611
simonis@6465 1612 void os::print_siginfo(outputStream* st, void* siginfo) {
simonis@6465 1613 // Use common posix version.
simonis@6465 1614 os::Posix::print_siginfo_brief(st, (const siginfo_t*) siginfo);
simonis@6465 1615 st->cr();
simonis@6465 1616 }
simonis@6465 1617
simonis@6465 1618
simonis@6465 1619 static void print_signal_handler(outputStream* st, int sig,
simonis@6465 1620 char* buf, size_t buflen);
simonis@6465 1621
simonis@6465 1622 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
simonis@6465 1623 st->print_cr("Signal Handlers:");
simonis@6465 1624 print_signal_handler(st, SIGSEGV, buf, buflen);
simonis@6465 1625 print_signal_handler(st, SIGBUS , buf, buflen);
simonis@6465 1626 print_signal_handler(st, SIGFPE , buf, buflen);
simonis@6465 1627 print_signal_handler(st, SIGPIPE, buf, buflen);
simonis@6465 1628 print_signal_handler(st, SIGXFSZ, buf, buflen);
simonis@6465 1629 print_signal_handler(st, SIGILL , buf, buflen);
simonis@6465 1630 print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen);
simonis@6465 1631 print_signal_handler(st, SR_signum, buf, buflen);
simonis@6465 1632 print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
simonis@6465 1633 print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
simonis@6465 1634 print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
simonis@6465 1635 print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
simonis@6465 1636 print_signal_handler(st, SIGTRAP, buf, buflen);
simonis@6465 1637 print_signal_handler(st, SIGDANGER, buf, buflen);
simonis@6465 1638 }
simonis@6465 1639
simonis@6465 1640 static char saved_jvm_path[MAXPATHLEN] = {0};
simonis@6465 1641
simonis@6465 1642 // Find the full path to the current module, libjvm.so or libjvm_g.so
simonis@6465 1643 void os::jvm_path(char *buf, jint buflen) {
simonis@6465 1644 // Error checking.
simonis@6465 1645 if (buflen < MAXPATHLEN) {
simonis@6465 1646 assert(false, "must use a large-enough buffer");
simonis@6465 1647 buf[0] = '\0';
simonis@6465 1648 return;
simonis@6465 1649 }
simonis@6465 1650 // Lazy resolve the path to current module.
simonis@6465 1651 if (saved_jvm_path[0] != 0) {
simonis@6465 1652 strcpy(buf, saved_jvm_path);
simonis@6465 1653 return;
simonis@6465 1654 }
simonis@6465 1655
simonis@6465 1656 Dl_info dlinfo;
simonis@6465 1657 int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
simonis@6465 1658 assert(ret != 0, "cannot locate libjvm");
simonis@6465 1659 char* rp = realpath((char *)dlinfo.dli_fname, buf);
simonis@6465 1660 assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
simonis@6465 1661
simonis@6465 1662 strcpy(saved_jvm_path, buf);
simonis@6465 1663 }
simonis@6465 1664
simonis@6465 1665 void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
simonis@6465 1666 // no prefix required, not even "_"
simonis@6465 1667 }
simonis@6465 1668
simonis@6465 1669 void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
simonis@6465 1670 // no suffix required
simonis@6465 1671 }
simonis@6465 1672
simonis@6465 1673 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 1674 // sun.misc.Signal support
simonis@6465 1675
simonis@6465 1676 static volatile jint sigint_count = 0;
simonis@6465 1677
simonis@6465 1678 static void
simonis@6465 1679 UserHandler(int sig, void *siginfo, void *context) {
simonis@6465 1680 // 4511530 - sem_post is serialized and handled by the manager thread. When
simonis@6465 1681 // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We
simonis@6465 1682 // don't want to flood the manager thread with sem_post requests.
simonis@6465 1683 if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1)
simonis@6465 1684 return;
simonis@6465 1685
simonis@6465 1686 // Ctrl-C is pressed during error reporting, likely because the error
simonis@6465 1687 // handler fails to abort. Let VM die immediately.
simonis@6465 1688 if (sig == SIGINT && is_error_reported()) {
simonis@6465 1689 os::die();
simonis@6465 1690 }
simonis@6465 1691
simonis@6465 1692 os::signal_notify(sig);
simonis@6465 1693 }
simonis@6465 1694
simonis@6465 1695 void* os::user_handler() {
simonis@6465 1696 return CAST_FROM_FN_PTR(void*, UserHandler);
simonis@6465 1697 }
simonis@6465 1698
simonis@6465 1699 extern "C" {
simonis@6465 1700 typedef void (*sa_handler_t)(int);
simonis@6465 1701 typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
simonis@6465 1702 }
simonis@6465 1703
simonis@6465 1704 void* os::signal(int signal_number, void* handler) {
simonis@6465 1705 struct sigaction sigAct, oldSigAct;
simonis@6465 1706
simonis@6465 1707 sigfillset(&(sigAct.sa_mask));
simonis@6465 1708
simonis@6465 1709 // Do not block out synchronous signals in the signal handler.
simonis@6465 1710 // Blocking synchronous signals only makes sense if you can really
simonis@6465 1711 // be sure that those signals won't happen during signal handling,
simonis@6465 1712 // when the blocking applies. Normal signal handlers are lean and
simonis@6465 1713 // do not cause signals. But our signal handlers tend to be "risky"
simonis@6465 1714 // - secondary SIGSEGV, SIGILL, SIGBUS' may and do happen.
simonis@6465 1715 // On AIX, PASE there was a case where a SIGSEGV happened, followed
simonis@6465 1716 // by a SIGILL, which was blocked due to the signal mask. The process
simonis@6465 1717 // just hung forever. Better to crash from a secondary signal than to hang.
simonis@6465 1718 sigdelset(&(sigAct.sa_mask), SIGSEGV);
simonis@6465 1719 sigdelset(&(sigAct.sa_mask), SIGBUS);
simonis@6465 1720 sigdelset(&(sigAct.sa_mask), SIGILL);
simonis@6465 1721 sigdelset(&(sigAct.sa_mask), SIGFPE);
simonis@6465 1722 sigdelset(&(sigAct.sa_mask), SIGTRAP);
simonis@6465 1723
simonis@6465 1724 sigAct.sa_flags = SA_RESTART|SA_SIGINFO;
simonis@6465 1725
simonis@6465 1726 sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler);
simonis@6465 1727
simonis@6465 1728 if (sigaction(signal_number, &sigAct, &oldSigAct)) {
simonis@6465 1729 // -1 means registration failed
simonis@6465 1730 return (void *)-1;
simonis@6465 1731 }
simonis@6465 1732
simonis@6465 1733 return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
simonis@6465 1734 }
simonis@6465 1735
simonis@6465 1736 void os::signal_raise(int signal_number) {
simonis@6465 1737 ::raise(signal_number);
simonis@6465 1738 }
simonis@6465 1739
simonis@6465 1740 //
simonis@6465 1741 // The following code is moved from os.cpp for making this
simonis@6465 1742 // code platform specific, which it is by its very nature.
simonis@6465 1743 //
simonis@6465 1744
simonis@6465 1745 // Will be modified when max signal is changed to be dynamic
simonis@6465 1746 int os::sigexitnum_pd() {
simonis@6465 1747 return NSIG;
simonis@6465 1748 }
simonis@6465 1749
simonis@6465 1750 // a counter for each possible signal value
simonis@6465 1751 static volatile jint pending_signals[NSIG+1] = { 0 };
simonis@6465 1752
simonis@6465 1753 // Linux(POSIX) specific hand shaking semaphore.
simonis@6465 1754 static sem_t sig_sem;
simonis@6465 1755
simonis@6465 1756 void os::signal_init_pd() {
simonis@6465 1757 // Initialize signal structures
simonis@6465 1758 ::memset((void*)pending_signals, 0, sizeof(pending_signals));
simonis@6465 1759
simonis@6465 1760 // Initialize signal semaphore
simonis@6465 1761 int rc = ::sem_init(&sig_sem, 0, 0);
simonis@6465 1762 guarantee(rc != -1, "sem_init failed");
simonis@6465 1763 }
simonis@6465 1764
simonis@6465 1765 void os::signal_notify(int sig) {
simonis@6465 1766 Atomic::inc(&pending_signals[sig]);
simonis@6465 1767 ::sem_post(&sig_sem);
simonis@6465 1768 }
simonis@6465 1769
simonis@6465 1770 static int check_pending_signals(bool wait) {
simonis@6465 1771 Atomic::store(0, &sigint_count);
simonis@6465 1772 for (;;) {
simonis@6465 1773 for (int i = 0; i < NSIG + 1; i++) {
simonis@6465 1774 jint n = pending_signals[i];
simonis@6465 1775 if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
simonis@6465 1776 return i;
simonis@6465 1777 }
simonis@6465 1778 }
simonis@6465 1779 if (!wait) {
simonis@6465 1780 return -1;
simonis@6465 1781 }
simonis@6465 1782 JavaThread *thread = JavaThread::current();
simonis@6465 1783 ThreadBlockInVM tbivm(thread);
simonis@6465 1784
simonis@6465 1785 bool threadIsSuspended;
simonis@6465 1786 do {
simonis@6465 1787 thread->set_suspend_equivalent();
simonis@6465 1788 // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
simonis@6465 1789
simonis@6465 1790 ::sem_wait(&sig_sem);
simonis@6465 1791
simonis@6465 1792 // were we externally suspended while we were waiting?
simonis@6465 1793 threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
simonis@6465 1794 if (threadIsSuspended) {
simonis@6465 1795 //
simonis@6465 1796 // The semaphore has been incremented, but while we were waiting
simonis@6465 1797 // another thread suspended us. We don't want to continue running
simonis@6465 1798 // while suspended because that would surprise the thread that
simonis@6465 1799 // suspended us.
simonis@6465 1800 //
simonis@6465 1801 ::sem_post(&sig_sem);
simonis@6465 1802
simonis@6465 1803 thread->java_suspend_self();
simonis@6465 1804 }
simonis@6465 1805 } while (threadIsSuspended);
simonis@6465 1806 }
simonis@6465 1807 }
simonis@6465 1808
simonis@6465 1809 int os::signal_lookup() {
simonis@6465 1810 return check_pending_signals(false);
simonis@6465 1811 }
simonis@6465 1812
simonis@6465 1813 int os::signal_wait() {
simonis@6465 1814 return check_pending_signals(true);
simonis@6465 1815 }
simonis@6465 1816
simonis@6465 1817 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 1818 // Virtual Memory
simonis@6465 1819
simonis@6465 1820 // AddrRange describes an immutable address range
simonis@6465 1821 //
simonis@6465 1822 // This is a helper class for the 'shared memory bookkeeping' below.
simonis@6465 1823 class AddrRange {
simonis@6465 1824 friend class ShmBkBlock;
simonis@6465 1825
simonis@6465 1826 char* _start;
simonis@6465 1827 size_t _size;
simonis@6465 1828
simonis@6465 1829 public:
simonis@6465 1830
simonis@6465 1831 AddrRange(char* start, size_t size)
simonis@6465 1832 : _start(start), _size(size)
simonis@6465 1833 {}
simonis@6465 1834
simonis@6465 1835 AddrRange(const AddrRange& r)
simonis@6465 1836 : _start(r.start()), _size(r.size())
simonis@6465 1837 {}
simonis@6465 1838
simonis@6465 1839 char* start() const { return _start; }
simonis@6465 1840 size_t size() const { return _size; }
simonis@6465 1841 char* end() const { return _start + _size; }
simonis@6465 1842 bool is_empty() const { return _size == 0 ? true : false; }
simonis@6465 1843
simonis@6465 1844 static AddrRange empty_range() { return AddrRange(NULL, 0); }
simonis@6465 1845
simonis@6465 1846 bool contains(const char* p) const {
simonis@6465 1847 return start() <= p && end() > p;
simonis@6465 1848 }
simonis@6465 1849
simonis@6465 1850 bool contains(const AddrRange& range) const {
simonis@6465 1851 return start() <= range.start() && end() >= range.end();
simonis@6465 1852 }
simonis@6465 1853
simonis@6465 1854 bool intersects(const AddrRange& range) const {
simonis@6465 1855 return (range.start() <= start() && range.end() > start()) ||
simonis@6465 1856 (range.start() < end() && range.end() >= end()) ||
simonis@6465 1857 contains(range);
simonis@6465 1858 }
simonis@6465 1859
simonis@6465 1860 bool is_same_range(const AddrRange& range) const {
simonis@6465 1861 return start() == range.start() && size() == range.size();
simonis@6465 1862 }
simonis@6465 1863
simonis@6465 1864 // return the closest inside range consisting of whole pages
simonis@6465 1865 AddrRange find_closest_aligned_range(size_t pagesize) const {
simonis@6465 1866 if (pagesize == 0 || is_empty()) {
simonis@6465 1867 return empty_range();
simonis@6465 1868 }
simonis@6465 1869 char* const from = (char*)align_size_up((intptr_t)_start, pagesize);
simonis@6465 1870 char* const to = (char*)align_size_down((intptr_t)end(), pagesize);
simonis@6465 1871 if (from > to) {
simonis@6465 1872 return empty_range();
simonis@6465 1873 }
simonis@6465 1874 return AddrRange(from, to - from);
simonis@6465 1875 }
simonis@6465 1876 };
simonis@6465 1877
simonis@6465 1878 ////////////////////////////////////////////////////////////////////////////
simonis@6465 1879 // shared memory bookkeeping
simonis@6465 1880 //
simonis@6465 1881 // the os::reserve_memory() API and friends hand out different kind of memory, depending
simonis@6465 1882 // on need and circumstances. Memory may be allocated with mmap() or with shmget/shmat.
simonis@6465 1883 //
simonis@6465 1884 // But these memory types have to be treated differently. For example, to uncommit
simonis@6465 1885 // mmap-based memory, msync(MS_INVALIDATE) is needed, to uncommit shmat-based memory,
simonis@6465 1886 // disclaim64() is needed.
simonis@6465 1887 //
simonis@6465 1888 // Therefore we need to keep track of the allocated memory segments and their
simonis@6465 1889 // properties.
simonis@6465 1890
simonis@6465 1891 // ShmBkBlock: base class for all blocks in the shared memory bookkeeping
simonis@6465 1892 class ShmBkBlock {
simonis@6465 1893
simonis@6465 1894 ShmBkBlock* _next;
simonis@6465 1895
simonis@6465 1896 protected:
simonis@6465 1897
simonis@6465 1898 AddrRange _range;
simonis@6465 1899 const size_t _pagesize;
simonis@6465 1900 const bool _pinned;
simonis@6465 1901
simonis@6465 1902 public:
simonis@6465 1903
simonis@6465 1904 ShmBkBlock(AddrRange range, size_t pagesize, bool pinned)
simonis@6465 1905 : _range(range), _pagesize(pagesize), _pinned(pinned) , _next(NULL) {
simonis@6465 1906
simonis@6465 1907 assert(_pagesize == SIZE_4K || _pagesize == SIZE_64K || _pagesize == SIZE_16M, "invalid page size");
simonis@6465 1908 assert(!_range.is_empty(), "invalid range");
simonis@6465 1909 }
simonis@6465 1910
simonis@6465 1911 virtual void print(outputStream* st) const {
simonis@6465 1912 st->print("0x%p ... 0x%p (%llu) - %d %s pages - %s",
simonis@6465 1913 _range.start(), _range.end(), _range.size(),
simonis@6465 1914 _range.size() / _pagesize, describe_pagesize(_pagesize),
simonis@6465 1915 _pinned ? "pinned" : "");
simonis@6465 1916 }
simonis@6465 1917
simonis@6465 1918 enum Type { MMAP, SHMAT };
simonis@6465 1919 virtual Type getType() = 0;
simonis@6465 1920
simonis@6465 1921 char* base() const { return _range.start(); }
simonis@6465 1922 size_t size() const { return _range.size(); }
simonis@6465 1923
simonis@6465 1924 void setAddrRange(AddrRange range) {
simonis@6465 1925 _range = range;
simonis@6465 1926 }
simonis@6465 1927
simonis@6465 1928 bool containsAddress(const char* p) const {
simonis@6465 1929 return _range.contains(p);
simonis@6465 1930 }
simonis@6465 1931
simonis@6465 1932 bool containsRange(const char* p, size_t size) const {
simonis@6465 1933 return _range.contains(AddrRange((char*)p, size));
simonis@6465 1934 }
simonis@6465 1935
simonis@6465 1936 bool isSameRange(const char* p, size_t size) const {
simonis@6465 1937 return _range.is_same_range(AddrRange((char*)p, size));
simonis@6465 1938 }
simonis@6465 1939
simonis@6465 1940 virtual bool disclaim(char* p, size_t size) = 0;
simonis@6465 1941 virtual bool release() = 0;
simonis@6465 1942
simonis@6465 1943 // blocks live in a list.
simonis@6465 1944 ShmBkBlock* next() const { return _next; }
simonis@6465 1945 void set_next(ShmBkBlock* blk) { _next = blk; }
simonis@6465 1946
simonis@6465 1947 }; // end: ShmBkBlock
simonis@6465 1948
simonis@6465 1949
simonis@6465 1950 // ShmBkMappedBlock: describes an block allocated with mmap()
simonis@6465 1951 class ShmBkMappedBlock : public ShmBkBlock {
simonis@6465 1952 public:
simonis@6465 1953
simonis@6465 1954 ShmBkMappedBlock(AddrRange range)
simonis@6465 1955 : ShmBkBlock(range, SIZE_4K, false) {} // mmap: always 4K, never pinned
simonis@6465 1956
simonis@6465 1957 void print(outputStream* st) const {
simonis@6465 1958 ShmBkBlock::print(st);
simonis@6465 1959 st->print_cr(" - mmap'ed");
simonis@6465 1960 }
simonis@6465 1961
simonis@6465 1962 Type getType() {
simonis@6465 1963 return MMAP;
simonis@6465 1964 }
simonis@6465 1965
simonis@6465 1966 bool disclaim(char* p, size_t size) {
simonis@6465 1967
simonis@6465 1968 AddrRange r(p, size);
simonis@6465 1969
simonis@6465 1970 guarantee(_range.contains(r), "invalid disclaim");
simonis@6465 1971
simonis@6465 1972 // only disclaim whole ranges.
simonis@6465 1973 const AddrRange r2 = r.find_closest_aligned_range(_pagesize);
simonis@6465 1974 if (r2.is_empty()) {
simonis@6465 1975 return true;
simonis@6465 1976 }
simonis@6465 1977
simonis@6465 1978 const int rc = ::msync(r2.start(), r2.size(), MS_INVALIDATE);
simonis@6465 1979
simonis@6465 1980 if (rc != 0) {
simonis@6465 1981 warning("msync(0x%p, %llu, MS_INVALIDATE) failed (%d)\n", r2.start(), r2.size(), errno);
simonis@6465 1982 }
simonis@6465 1983
simonis@6465 1984 return rc == 0 ? true : false;
simonis@6465 1985 }
simonis@6465 1986
simonis@6465 1987 bool release() {
simonis@6465 1988 // mmap'ed blocks are released using munmap
simonis@6465 1989 if (::munmap(_range.start(), _range.size()) != 0) {
simonis@6465 1990 warning("munmap(0x%p, %llu) failed (%d)\n", _range.start(), _range.size(), errno);
simonis@6465 1991 return false;
simonis@6465 1992 }
simonis@6465 1993 return true;
simonis@6465 1994 }
simonis@6465 1995 }; // end: ShmBkMappedBlock
simonis@6465 1996
simonis@6465 1997 // ShmBkShmatedBlock: describes an block allocated with shmget/shmat()
simonis@6465 1998 class ShmBkShmatedBlock : public ShmBkBlock {
simonis@6465 1999 public:
simonis@6465 2000
simonis@6465 2001 ShmBkShmatedBlock(AddrRange range, size_t pagesize, bool pinned)
simonis@6465 2002 : ShmBkBlock(range, pagesize, pinned) {}
simonis@6465 2003
simonis@6465 2004 void print(outputStream* st) const {
simonis@6465 2005 ShmBkBlock::print(st);
simonis@6465 2006 st->print_cr(" - shmat'ed");
simonis@6465 2007 }
simonis@6465 2008
simonis@6465 2009 Type getType() {
simonis@6465 2010 return SHMAT;
simonis@6465 2011 }
simonis@6465 2012
simonis@6465 2013 bool disclaim(char* p, size_t size) {
simonis@6465 2014
simonis@6465 2015 AddrRange r(p, size);
simonis@6465 2016
simonis@6465 2017 if (_pinned) {
simonis@6465 2018 return true;
simonis@6465 2019 }
simonis@6465 2020
simonis@6465 2021 // shmat'ed blocks are disclaimed using disclaim64
simonis@6465 2022 guarantee(_range.contains(r), "invalid disclaim");
simonis@6465 2023
simonis@6465 2024 // only disclaim whole ranges.
simonis@6465 2025 const AddrRange r2 = r.find_closest_aligned_range(_pagesize);
simonis@6465 2026 if (r2.is_empty()) {
simonis@6465 2027 return true;
simonis@6465 2028 }
simonis@6465 2029
simonis@6465 2030 const bool rc = my_disclaim64(r2.start(), r2.size());
simonis@6465 2031
simonis@6465 2032 if (Verbose && !rc) {
simonis@6465 2033 warning("failed to disclaim shm %p-%p\n", r2.start(), r2.end());
simonis@6465 2034 }
simonis@6465 2035
simonis@6465 2036 return rc;
simonis@6465 2037 }
simonis@6465 2038
simonis@6465 2039 bool release() {
simonis@6465 2040 bool rc = false;
simonis@6465 2041 if (::shmdt(_range.start()) != 0) {
simonis@6465 2042 warning("shmdt(0x%p) failed (%d)\n", _range.start(), errno);
simonis@6465 2043 } else {
simonis@6465 2044 rc = true;
simonis@6465 2045 }
simonis@6465 2046 return rc;
simonis@6465 2047 }
simonis@6465 2048
simonis@6465 2049 }; // end: ShmBkShmatedBlock
simonis@6465 2050
simonis@6465 2051 static ShmBkBlock* g_shmbk_list = NULL;
simonis@6465 2052 static volatile jint g_shmbk_table_lock = 0;
simonis@6465 2053
simonis@6465 2054 // keep some usage statistics
simonis@6465 2055 static struct {
simonis@6465 2056 int nodes; // number of nodes in list
simonis@6465 2057 size_t bytes; // reserved - not committed - bytes.
simonis@6465 2058 int reserves; // how often reserve was called
simonis@6465 2059 int lookups; // how often a lookup was made
simonis@6465 2060 } g_shmbk_stats = { 0, 0, 0, 0 };
simonis@6465 2061
simonis@6465 2062 // add information about a shared memory segment to the bookkeeping
simonis@6465 2063 static void shmbk_register(ShmBkBlock* p_block) {
simonis@6465 2064 guarantee(p_block, "logic error");
simonis@6465 2065 p_block->set_next(g_shmbk_list);
simonis@6465 2066 g_shmbk_list = p_block;
simonis@6465 2067 g_shmbk_stats.reserves ++;
simonis@6465 2068 g_shmbk_stats.bytes += p_block->size();
simonis@6465 2069 g_shmbk_stats.nodes ++;
simonis@6465 2070 }
simonis@6465 2071
simonis@6465 2072 // remove information about a shared memory segment by its starting address
simonis@6465 2073 static void shmbk_unregister(ShmBkBlock* p_block) {
simonis@6465 2074 ShmBkBlock* p = g_shmbk_list;
simonis@6465 2075 ShmBkBlock* prev = NULL;
simonis@6465 2076 while (p) {
simonis@6465 2077 if (p == p_block) {
simonis@6465 2078 if (prev) {
simonis@6465 2079 prev->set_next(p->next());
simonis@6465 2080 } else {
simonis@6465 2081 g_shmbk_list = p->next();
simonis@6465 2082 }
simonis@6465 2083 g_shmbk_stats.nodes --;
simonis@6465 2084 g_shmbk_stats.bytes -= p->size();
simonis@6465 2085 return;
simonis@6465 2086 }
simonis@6465 2087 prev = p;
simonis@6465 2088 p = p->next();
simonis@6465 2089 }
simonis@6465 2090 assert(false, "should not happen");
simonis@6465 2091 }
simonis@6465 2092
simonis@6465 2093 // given a pointer, return shared memory bookkeeping record for the segment it points into
simonis@6465 2094 // using the returned block info must happen under lock protection
simonis@6465 2095 static ShmBkBlock* shmbk_find_by_containing_address(const char* addr) {
simonis@6465 2096 g_shmbk_stats.lookups ++;
simonis@6465 2097 ShmBkBlock* p = g_shmbk_list;
simonis@6465 2098 while (p) {
simonis@6465 2099 if (p->containsAddress(addr)) {
simonis@6465 2100 return p;
simonis@6465 2101 }
simonis@6465 2102 p = p->next();
simonis@6465 2103 }
simonis@6465 2104 return NULL;
simonis@6465 2105 }
simonis@6465 2106
simonis@6465 2107 // dump all information about all memory segments allocated with os::reserve_memory()
simonis@6465 2108 void shmbk_dump_info() {
simonis@6465 2109 tty->print_cr("-- shared mem bookkeeping (alive: %d segments, %llu bytes, "
simonis@6465 2110 "total reserves: %d total lookups: %d)",
simonis@6465 2111 g_shmbk_stats.nodes, g_shmbk_stats.bytes, g_shmbk_stats.reserves, g_shmbk_stats.lookups);
simonis@6465 2112 const ShmBkBlock* p = g_shmbk_list;
simonis@6465 2113 int i = 0;
simonis@6465 2114 while (p) {
simonis@6465 2115 p->print(tty);
simonis@6465 2116 p = p->next();
simonis@6465 2117 i ++;
simonis@6465 2118 }
simonis@6465 2119 }
simonis@6465 2120
simonis@6465 2121 #define LOCK_SHMBK { ThreadCritical _LOCK_SHMBK;
simonis@6465 2122 #define UNLOCK_SHMBK }
simonis@6465 2123
simonis@6465 2124 // End: shared memory bookkeeping
simonis@6465 2125 ////////////////////////////////////////////////////////////////////////////////////////////////////
simonis@6465 2126
simonis@6465 2127 int os::vm_page_size() {
simonis@6465 2128 // Seems redundant as all get out
simonis@6465 2129 assert(os::Aix::page_size() != -1, "must call os::init");
simonis@6465 2130 return os::Aix::page_size();
simonis@6465 2131 }
simonis@6465 2132
simonis@6465 2133 // Aix allocates memory by pages.
simonis@6465 2134 int os::vm_allocation_granularity() {
simonis@6465 2135 assert(os::Aix::page_size() != -1, "must call os::init");
simonis@6465 2136 return os::Aix::page_size();
simonis@6465 2137 }
simonis@6465 2138
simonis@6465 2139 int os::Aix::commit_memory_impl(char* addr, size_t size, bool exec) {
simonis@6465 2140
simonis@6465 2141 // Commit is a noop. There is no explicit commit
simonis@6465 2142 // needed on AIX. Memory is committed when touched.
simonis@6465 2143 //
simonis@6465 2144 // Debug : check address range for validity
simonis@6465 2145 #ifdef ASSERT
simonis@6465 2146 LOCK_SHMBK
simonis@6465 2147 ShmBkBlock* const block = shmbk_find_by_containing_address(addr);
simonis@6465 2148 if (!block) {
simonis@6465 2149 fprintf(stderr, "invalid pointer: " INTPTR_FORMAT "\n", addr);
simonis@6465 2150 shmbk_dump_info();
simonis@6465 2151 assert(false, "invalid pointer");
simonis@6465 2152 return false;
simonis@6465 2153 } else if (!block->containsRange(addr, size)) {
simonis@6465 2154 fprintf(stderr, "invalid range: " INTPTR_FORMAT " .. " INTPTR_FORMAT "\n", addr, addr + size);
simonis@6465 2155 shmbk_dump_info();
simonis@6465 2156 assert(false, "invalid range");
simonis@6465 2157 return false;
simonis@6465 2158 }
simonis@6465 2159 UNLOCK_SHMBK
simonis@6465 2160 #endif // ASSERT
simonis@6465 2161
simonis@6465 2162 return 0;
simonis@6465 2163 }
simonis@6465 2164
simonis@6465 2165 bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
simonis@6465 2166 return os::Aix::commit_memory_impl(addr, size, exec) == 0;
simonis@6465 2167 }
simonis@6465 2168
simonis@6465 2169 void os::pd_commit_memory_or_exit(char* addr, size_t size, bool exec,
simonis@6465 2170 const char* mesg) {
simonis@6465 2171 assert(mesg != NULL, "mesg must be specified");
simonis@6465 2172 os::Aix::commit_memory_impl(addr, size, exec);
simonis@6465 2173 }
simonis@6465 2174
simonis@6465 2175 int os::Aix::commit_memory_impl(char* addr, size_t size,
simonis@6465 2176 size_t alignment_hint, bool exec) {
simonis@6465 2177 return os::Aix::commit_memory_impl(addr, size, exec);
simonis@6465 2178 }
simonis@6465 2179
simonis@6465 2180 bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
simonis@6465 2181 bool exec) {
simonis@6465 2182 return os::Aix::commit_memory_impl(addr, size, alignment_hint, exec) == 0;
simonis@6465 2183 }
simonis@6465 2184
simonis@6465 2185 void os::pd_commit_memory_or_exit(char* addr, size_t size,
simonis@6465 2186 size_t alignment_hint, bool exec,
simonis@6465 2187 const char* mesg) {
simonis@6465 2188 os::Aix::commit_memory_impl(addr, size, alignment_hint, exec);
simonis@6465 2189 }
simonis@6465 2190
simonis@6465 2191 bool os::pd_uncommit_memory(char* addr, size_t size) {
simonis@6465 2192
simonis@6465 2193 // Delegate to ShmBkBlock class which knows how to uncommit its memory.
simonis@6465 2194
simonis@6465 2195 bool rc = false;
simonis@6465 2196 LOCK_SHMBK
simonis@6465 2197 ShmBkBlock* const block = shmbk_find_by_containing_address(addr);
simonis@6465 2198 if (!block) {
simonis@6465 2199 fprintf(stderr, "invalid pointer: 0x%p.\n", addr);
simonis@6465 2200 shmbk_dump_info();
simonis@6465 2201 assert(false, "invalid pointer");
simonis@6465 2202 return false;
simonis@6465 2203 } else if (!block->containsRange(addr, size)) {
simonis@6465 2204 fprintf(stderr, "invalid range: 0x%p .. 0x%p.\n", addr, addr + size);
simonis@6465 2205 shmbk_dump_info();
simonis@6465 2206 assert(false, "invalid range");
simonis@6465 2207 return false;
simonis@6465 2208 }
simonis@6465 2209 rc = block->disclaim(addr, size);
simonis@6465 2210 UNLOCK_SHMBK
simonis@6465 2211
simonis@6465 2212 if (Verbose && !rc) {
simonis@6465 2213 warning("failed to disclaim 0x%p .. 0x%p (0x%llX bytes).", addr, addr + size, size);
simonis@6465 2214 }
simonis@6465 2215 return rc;
simonis@6465 2216 }
simonis@6465 2217
simonis@6465 2218 bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
simonis@6465 2219 return os::guard_memory(addr, size);
simonis@6465 2220 }
simonis@6465 2221
simonis@6465 2222 bool os::remove_stack_guard_pages(char* addr, size_t size) {
simonis@6465 2223 return os::unguard_memory(addr, size);
simonis@6465 2224 }
simonis@6465 2225
simonis@6465 2226 void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
simonis@6465 2227 }
simonis@6465 2228
simonis@6465 2229 void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
simonis@6465 2230 }
simonis@6465 2231
simonis@6465 2232 void os::numa_make_global(char *addr, size_t bytes) {
simonis@6465 2233 }
simonis@6465 2234
simonis@6465 2235 void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
simonis@6465 2236 }
simonis@6465 2237
simonis@6465 2238 bool os::numa_topology_changed() {
simonis@6465 2239 return false;
simonis@6465 2240 }
simonis@6465 2241
simonis@6465 2242 size_t os::numa_get_groups_num() {
simonis@6465 2243 return 1;
simonis@6465 2244 }
simonis@6465 2245
simonis@6465 2246 int os::numa_get_group_id() {
simonis@6465 2247 return 0;
simonis@6465 2248 }
simonis@6465 2249
simonis@6465 2250 size_t os::numa_get_leaf_groups(int *ids, size_t size) {
simonis@6465 2251 if (size > 0) {
simonis@6465 2252 ids[0] = 0;
simonis@6465 2253 return 1;
simonis@6465 2254 }
simonis@6465 2255 return 0;
simonis@6465 2256 }
simonis@6465 2257
simonis@6465 2258 bool os::get_page_info(char *start, page_info* info) {
simonis@6465 2259 return false;
simonis@6465 2260 }
simonis@6465 2261
simonis@6465 2262 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
simonis@6465 2263 return end;
simonis@6465 2264 }
simonis@6465 2265
simonis@6465 2266 // Flags for reserve_shmatted_memory:
simonis@6465 2267 #define RESSHM_WISHADDR_OR_FAIL 1
simonis@6465 2268 #define RESSHM_TRY_16M_PAGES 2
simonis@6465 2269 #define RESSHM_16M_PAGES_OR_FAIL 4
simonis@6465 2270
simonis@6465 2271 // Result of reserve_shmatted_memory:
simonis@6465 2272 struct shmatted_memory_info_t {
simonis@6465 2273 char* addr;
simonis@6465 2274 size_t pagesize;
simonis@6465 2275 bool pinned;
simonis@6465 2276 };
simonis@6465 2277
simonis@6465 2278 // Reserve a section of shmatted memory.
simonis@6465 2279 // params:
simonis@6465 2280 // bytes [in]: size of memory, in bytes
simonis@6465 2281 // requested_addr [in]: wish address.
simonis@6465 2282 // NULL = no wish.
simonis@6465 2283 // If RESSHM_WISHADDR_OR_FAIL is set in flags and wish address cannot
simonis@6465 2284 // be obtained, function will fail. Otherwise wish address is treated as hint and
simonis@6465 2285 // another pointer is returned.
simonis@6465 2286 // flags [in]: some flags. Valid flags are:
simonis@6465 2287 // RESSHM_WISHADDR_OR_FAIL - fail if wish address is given and cannot be obtained.
simonis@6465 2288 // RESSHM_TRY_16M_PAGES - try to allocate from 16M page pool
simonis@6465 2289 // (requires UseLargePages and Use16MPages)
simonis@6465 2290 // RESSHM_16M_PAGES_OR_FAIL - if you cannot allocate from 16M page pool, fail.
simonis@6465 2291 // Otherwise any other page size will do.
simonis@6465 2292 // p_info [out] : holds information about the created shared memory segment.
simonis@6465 2293 static bool reserve_shmatted_memory(size_t bytes, char* requested_addr, int flags, shmatted_memory_info_t* p_info) {
simonis@6465 2294
simonis@6465 2295 assert(p_info, "parameter error");
simonis@6465 2296
simonis@6465 2297 // init output struct.
simonis@6465 2298 p_info->addr = NULL;
simonis@6465 2299
simonis@6465 2300 // neither should we be here for EXTSHM=ON.
simonis@6465 2301 if (os::Aix::extshm()) {
simonis@6465 2302 ShouldNotReachHere();
simonis@6465 2303 }
simonis@6465 2304
simonis@6465 2305 // extract flags. sanity checks.
simonis@6465 2306 const bool wishaddr_or_fail =
simonis@6465 2307 flags & RESSHM_WISHADDR_OR_FAIL;
simonis@6465 2308 const bool try_16M_pages =
simonis@6465 2309 flags & RESSHM_TRY_16M_PAGES;
simonis@6465 2310 const bool f16M_pages_or_fail =
simonis@6465 2311 flags & RESSHM_16M_PAGES_OR_FAIL;
simonis@6465 2312
simonis@6465 2313 // first check: if a wish address is given and it is mandatory, but not aligned to segment boundary,
simonis@6465 2314 // shmat will fail anyway, so save some cycles by failing right away
simonis@6465 2315 if (requested_addr && ((uintptr_t)requested_addr % SIZE_256M == 0)) {
simonis@6465 2316 if (wishaddr_or_fail) {
simonis@6465 2317 return false;
simonis@6465 2318 } else {
simonis@6465 2319 requested_addr = NULL;
simonis@6465 2320 }
simonis@6465 2321 }
simonis@6465 2322
simonis@6465 2323 char* addr = NULL;
simonis@6465 2324
simonis@6465 2325 // Align size of shm up to the largest possible page size, to avoid errors later on when we try to change
simonis@6465 2326 // pagesize dynamically.
simonis@6465 2327 const size_t size = align_size_up(bytes, SIZE_16M);
simonis@6465 2328
simonis@6465 2329 // reserve the shared segment
simonis@6465 2330 int shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | S_IRUSR | S_IWUSR);
simonis@6465 2331 if (shmid == -1) {
simonis@6465 2332 warning("shmget(.., %lld, ..) failed (errno: %d).", size, errno);
simonis@6465 2333 return false;
simonis@6465 2334 }
simonis@6465 2335
simonis@6465 2336 // Important note:
simonis@6465 2337 // It is very important that we, upon leaving this function, do not leave a shm segment alive.
simonis@6465 2338 // We must right after attaching it remove it from the system. System V shm segments are global and
simonis@6465 2339 // survive the process.
simonis@6465 2340 // So, from here on: Do not assert. Do not return. Always do a "goto cleanup_shm".
simonis@6465 2341
simonis@6465 2342 // try forcing the page size
simonis@6465 2343 size_t pagesize = -1; // unknown so far
simonis@6465 2344
simonis@6465 2345 if (UseLargePages) {
simonis@6465 2346
simonis@6465 2347 struct shmid_ds shmbuf;
simonis@6465 2348 memset(&shmbuf, 0, sizeof(shmbuf));
simonis@6465 2349
simonis@6465 2350 // First, try to take from 16M page pool if...
simonis@6465 2351 if (os::Aix::can_use_16M_pages() // we can ...
simonis@6465 2352 && Use16MPages // we are not explicitly forbidden to do so (-XX:-Use16MPages)..
simonis@6465 2353 && try_16M_pages) { // caller wants us to.
simonis@6465 2354 shmbuf.shm_pagesize = SIZE_16M;
simonis@6465 2355 if (shmctl(shmid, SHM_PAGESIZE, &shmbuf) == 0) {
simonis@6465 2356 pagesize = SIZE_16M;
simonis@6465 2357 } else {
simonis@6465 2358 warning("Failed to allocate %d 16M pages. 16M page pool might be exhausted. (shmctl failed with %d)",
simonis@6465 2359 size / SIZE_16M, errno);
simonis@6465 2360 if (f16M_pages_or_fail) {
simonis@6465 2361 goto cleanup_shm;
simonis@6465 2362 }
simonis@6465 2363 }
simonis@6465 2364 }
simonis@6465 2365
simonis@6465 2366 // Nothing yet? Try setting 64K pages. Note that I never saw this fail, but in theory it might,
simonis@6465 2367 // because the 64K page pool may also be exhausted.
simonis@6465 2368 if (pagesize == -1) {
simonis@6465 2369 shmbuf.shm_pagesize = SIZE_64K;
simonis@6465 2370 if (shmctl(shmid, SHM_PAGESIZE, &shmbuf) == 0) {
simonis@6465 2371 pagesize = SIZE_64K;
simonis@6465 2372 } else {
simonis@6465 2373 warning("Failed to allocate %d 64K pages. (shmctl failed with %d)",
simonis@6465 2374 size / SIZE_64K, errno);
simonis@6465 2375 // here I give up. leave page_size -1 - later, after attaching, we will query the
simonis@6465 2376 // real page size of the attached memory. (in theory, it may be something different
simonis@6465 2377 // from 4K if LDR_CNTRL SHM_PSIZE is set)
simonis@6465 2378 }
simonis@6465 2379 }
simonis@6465 2380 }
simonis@6465 2381
simonis@6465 2382 // sanity point
simonis@6465 2383 assert(pagesize == -1 || pagesize == SIZE_16M || pagesize == SIZE_64K, "wrong page size");
simonis@6465 2384
simonis@6465 2385 // Now attach the shared segment.
simonis@6465 2386 addr = (char*) shmat(shmid, requested_addr, 0);
simonis@6465 2387 if (addr == (char*)-1) {
simonis@6465 2388 // How to handle attach failure:
simonis@6465 2389 // If it failed for a specific wish address, tolerate this: in that case, if wish address was
simonis@6465 2390 // mandatory, fail, if not, retry anywhere.
simonis@6465 2391 // If it failed for any other reason, treat that as fatal error.
simonis@6465 2392 addr = NULL;
simonis@6465 2393 if (requested_addr) {
simonis@6465 2394 if (wishaddr_or_fail) {
simonis@6465 2395 goto cleanup_shm;
simonis@6465 2396 } else {
simonis@6465 2397 addr = (char*) shmat(shmid, NULL, 0);
simonis@6465 2398 if (addr == (char*)-1) { // fatal
simonis@6465 2399 addr = NULL;
simonis@6465 2400 warning("shmat failed (errno: %d)", errno);
simonis@6465 2401 goto cleanup_shm;
simonis@6465 2402 }
simonis@6465 2403 }
simonis@6465 2404 } else { // fatal
simonis@6465 2405 addr = NULL;
simonis@6465 2406 warning("shmat failed (errno: %d)", errno);
simonis@6465 2407 goto cleanup_shm;
simonis@6465 2408 }
simonis@6465 2409 }
simonis@6465 2410
simonis@6465 2411 // sanity point
simonis@6465 2412 assert(addr && addr != (char*) -1, "wrong address");
simonis@6465 2413
simonis@6465 2414 // after successful Attach remove the segment - right away.
simonis@6465 2415 if (::shmctl(shmid, IPC_RMID, NULL) == -1) {
simonis@6465 2416 warning("shmctl(%u, IPC_RMID) failed (%d)\n", shmid, errno);
simonis@6465 2417 guarantee(false, "failed to remove shared memory segment!");
simonis@6465 2418 }
simonis@6465 2419 shmid = -1;
simonis@6465 2420
simonis@6465 2421 // query the real page size. In case setting the page size did not work (see above), the system
simonis@6465 2422 // may have given us something other then 4K (LDR_CNTRL)
simonis@6465 2423 {
simonis@6465 2424 const size_t real_pagesize = os::Aix::query_pagesize(addr);
simonis@6465 2425 if (pagesize != -1) {
simonis@6465 2426 assert(pagesize == real_pagesize, "unexpected pagesize after shmat");
simonis@6465 2427 } else {
simonis@6465 2428 pagesize = real_pagesize;
simonis@6465 2429 }
simonis@6465 2430 }
simonis@6465 2431
simonis@6465 2432 // Now register the reserved block with internal book keeping.
simonis@6465 2433 LOCK_SHMBK
simonis@6465 2434 const bool pinned = pagesize >= SIZE_16M ? true : false;
simonis@6465 2435 ShmBkShmatedBlock* const p_block = new ShmBkShmatedBlock(AddrRange(addr, size), pagesize, pinned);
simonis@6465 2436 assert(p_block, "");
simonis@6465 2437 shmbk_register(p_block);
simonis@6465 2438 UNLOCK_SHMBK
simonis@6465 2439
simonis@6465 2440 cleanup_shm:
simonis@6465 2441
simonis@6465 2442 // if we have not done so yet, remove the shared memory segment. This is very important.
simonis@6465 2443 if (shmid != -1) {
simonis@6465 2444 if (::shmctl(shmid, IPC_RMID, NULL) == -1) {
simonis@6465 2445 warning("shmctl(%u, IPC_RMID) failed (%d)\n", shmid, errno);
simonis@6465 2446 guarantee(false, "failed to remove shared memory segment!");
simonis@6465 2447 }
simonis@6465 2448 shmid = -1;
simonis@6465 2449 }
simonis@6465 2450
simonis@6465 2451 // trace
simonis@6465 2452 if (Verbose && !addr) {
simonis@6465 2453 if (requested_addr != NULL) {
goetz@6501 2454 warning("failed to shm-allocate 0x%llX bytes at wish address 0x%p.", size, requested_addr);
simonis@6465 2455 } else {
simonis@6465 2456 warning("failed to shm-allocate 0x%llX bytes at any address.", size);
simonis@6465 2457 }
simonis@6465 2458 }
simonis@6465 2459
simonis@6465 2460 // hand info to caller
simonis@6465 2461 if (addr) {
simonis@6465 2462 p_info->addr = addr;
simonis@6465 2463 p_info->pagesize = pagesize;
simonis@6465 2464 p_info->pinned = pagesize == SIZE_16M ? true : false;
simonis@6465 2465 }
simonis@6465 2466
simonis@6465 2467 // sanity test:
simonis@6465 2468 if (requested_addr && addr && wishaddr_or_fail) {
simonis@6465 2469 guarantee(addr == requested_addr, "shmat error");
simonis@6465 2470 }
simonis@6465 2471
simonis@6465 2472 // just one more test to really make sure we have no dangling shm segments.
simonis@6465 2473 guarantee(shmid == -1, "dangling shm segments");
simonis@6465 2474
simonis@6465 2475 return addr ? true : false;
simonis@6465 2476
simonis@6465 2477 } // end: reserve_shmatted_memory
simonis@6465 2478
simonis@6465 2479 // Reserve memory using mmap. Behaves the same as reserve_shmatted_memory():
simonis@6465 2480 // will return NULL in case of an error.
simonis@6465 2481 static char* reserve_mmaped_memory(size_t bytes, char* requested_addr) {
simonis@6465 2482
simonis@6465 2483 // if a wish address is given, but not aligned to 4K page boundary, mmap will fail.
simonis@6465 2484 if (requested_addr && ((uintptr_t)requested_addr % os::vm_page_size() != 0)) {
simonis@6465 2485 warning("Wish address 0x%p not aligned to page boundary.", requested_addr);
simonis@6465 2486 return NULL;
simonis@6465 2487 }
simonis@6465 2488
simonis@6465 2489 const size_t size = align_size_up(bytes, SIZE_4K);
simonis@6465 2490
simonis@6465 2491 // Note: MAP_SHARED (instead of MAP_PRIVATE) needed to be able to
simonis@6465 2492 // msync(MS_INVALIDATE) (see os::uncommit_memory)
simonis@6465 2493 int flags = MAP_ANONYMOUS | MAP_SHARED;
simonis@6465 2494
simonis@6465 2495 // MAP_FIXED is needed to enforce requested_addr - manpage is vague about what
simonis@6465 2496 // it means if wishaddress is given but MAP_FIXED is not set.
simonis@6465 2497 //
simonis@6465 2498 // Note however that this changes semantics in SPEC1170 mode insofar as MAP_FIXED
simonis@6465 2499 // clobbers the address range, which is probably not what the caller wants. That's
simonis@6465 2500 // why I assert here (again) that the SPEC1170 compat mode is off.
simonis@6465 2501 // If we want to be able to run under SPEC1170, we have to do some porting and
simonis@6465 2502 // testing.
simonis@6465 2503 if (requested_addr != NULL) {
simonis@6465 2504 assert(!os::Aix::xpg_sus_mode(), "SPEC1170 mode not allowed.");
simonis@6465 2505 flags |= MAP_FIXED;
simonis@6465 2506 }
simonis@6465 2507
simonis@6465 2508 char* addr = (char*)::mmap(requested_addr, size, PROT_READ|PROT_WRITE|PROT_EXEC, flags, -1, 0);
simonis@6465 2509
simonis@6465 2510 if (addr == MAP_FAILED) {
simonis@6465 2511 // attach failed: tolerate for specific wish addresses. Not being able to attach
simonis@6465 2512 // anywhere is a fatal error.
simonis@6465 2513 if (requested_addr == NULL) {
simonis@6465 2514 // It's ok to fail here if the machine has not enough memory.
simonis@6465 2515 warning("mmap(NULL, 0x%llX, ..) failed (%d)", size, errno);
simonis@6465 2516 }
simonis@6465 2517 addr = NULL;
simonis@6465 2518 goto cleanup_mmap;
simonis@6465 2519 }
simonis@6465 2520
simonis@6465 2521 // If we did request a specific address and that address was not available, fail.
simonis@6465 2522 if (addr && requested_addr) {
simonis@6465 2523 guarantee(addr == requested_addr, "unexpected");
simonis@6465 2524 }
simonis@6465 2525
simonis@6465 2526 // register this mmap'ed segment with book keeping
simonis@6465 2527 LOCK_SHMBK
simonis@6465 2528 ShmBkMappedBlock* const p_block = new ShmBkMappedBlock(AddrRange(addr, size));
simonis@6465 2529 assert(p_block, "");
simonis@6465 2530 shmbk_register(p_block);
simonis@6465 2531 UNLOCK_SHMBK
simonis@6465 2532
simonis@6465 2533 cleanup_mmap:
simonis@6465 2534
goetz@6501 2535 // trace
goetz@6501 2536 if (Verbose) {
goetz@6501 2537 if (addr) {
simonis@6465 2538 fprintf(stderr, "mmap-allocated 0x%p .. 0x%p (0x%llX bytes)\n", addr, addr + bytes, bytes);
simonis@6465 2539 }
goetz@6501 2540 else {
goetz@6501 2541 if (requested_addr != NULL) {
goetz@6501 2542 warning("failed to mmap-allocate 0x%llX bytes at wish address 0x%p.", bytes, requested_addr);
goetz@6501 2543 } else {
goetz@6501 2544 warning("failed to mmap-allocate 0x%llX bytes at any address.", bytes);
goetz@6501 2545 }
simonis@6465 2546 }
simonis@6465 2547 }
simonis@6465 2548
simonis@6465 2549 return addr;
simonis@6465 2550
simonis@6465 2551 } // end: reserve_mmaped_memory
simonis@6465 2552
simonis@6465 2553 // Reserves and attaches a shared memory segment.
simonis@6465 2554 // Will assert if a wish address is given and could not be obtained.
simonis@6465 2555 char* os::pd_reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) {
simonis@6465 2556 return os::attempt_reserve_memory_at(bytes, requested_addr);
simonis@6465 2557 }
simonis@6465 2558
simonis@6465 2559 bool os::pd_release_memory(char* addr, size_t size) {
simonis@6465 2560
simonis@6465 2561 // delegate to ShmBkBlock class which knows how to uncommit its memory.
simonis@6465 2562
simonis@6465 2563 bool rc = false;
simonis@6465 2564 LOCK_SHMBK
simonis@6465 2565 ShmBkBlock* const block = shmbk_find_by_containing_address(addr);
simonis@6465 2566 if (!block) {
simonis@6465 2567 fprintf(stderr, "invalid pointer: 0x%p.\n", addr);
simonis@6465 2568 shmbk_dump_info();
simonis@6465 2569 assert(false, "invalid pointer");
simonis@6465 2570 return false;
simonis@6465 2571 }
simonis@6465 2572 else if (!block->isSameRange(addr, size)) {
simonis@6465 2573 if (block->getType() == ShmBkBlock::MMAP) {
simonis@6465 2574 // Release only the same range or a the beginning or the end of a range.
simonis@6465 2575 if (block->base() == addr && size < block->size()) {
simonis@6465 2576 ShmBkMappedBlock* const b = new ShmBkMappedBlock(AddrRange(block->base() + size, block->size() - size));
simonis@6465 2577 assert(b, "");
simonis@6465 2578 shmbk_register(b);
simonis@6465 2579 block->setAddrRange(AddrRange(addr, size));
simonis@6465 2580 }
simonis@6465 2581 else if (addr > block->base() && addr + size == block->base() + block->size()) {
simonis@6465 2582 ShmBkMappedBlock* const b = new ShmBkMappedBlock(AddrRange(block->base(), block->size() - size));
simonis@6465 2583 assert(b, "");
simonis@6465 2584 shmbk_register(b);
simonis@6465 2585 block->setAddrRange(AddrRange(addr, size));
simonis@6465 2586 }
simonis@6465 2587 else {
simonis@6465 2588 fprintf(stderr, "invalid mmap range: 0x%p .. 0x%p.\n", addr, addr + size);
simonis@6465 2589 shmbk_dump_info();
simonis@6465 2590 assert(false, "invalid mmap range");
simonis@6465 2591 return false;
simonis@6465 2592 }
simonis@6465 2593 }
simonis@6465 2594 else {
simonis@6465 2595 // Release only the same range. No partial release allowed.
simonis@6465 2596 // Soften the requirement a bit, because the user may think he owns a smaller size
simonis@6465 2597 // than the block is due to alignment etc.
simonis@6465 2598 if (block->base() != addr || block->size() < size) {
simonis@6465 2599 fprintf(stderr, "invalid shmget range: 0x%p .. 0x%p.\n", addr, addr + size);
simonis@6465 2600 shmbk_dump_info();
simonis@6465 2601 assert(false, "invalid shmget range");
simonis@6465 2602 return false;
simonis@6465 2603 }
simonis@6465 2604 }
simonis@6465 2605 }
simonis@6465 2606 rc = block->release();
simonis@6465 2607 assert(rc, "release failed");
simonis@6465 2608 // remove block from bookkeeping
simonis@6465 2609 shmbk_unregister(block);
simonis@6465 2610 delete block;
simonis@6465 2611 UNLOCK_SHMBK
simonis@6465 2612
simonis@6465 2613 if (!rc) {
simonis@6465 2614 warning("failed to released %lu bytes at 0x%p", size, addr);
simonis@6465 2615 }
simonis@6465 2616
simonis@6465 2617 return rc;
simonis@6465 2618 }
simonis@6465 2619
simonis@6465 2620 static bool checked_mprotect(char* addr, size_t size, int prot) {
simonis@6465 2621
simonis@6465 2622 // Little problem here: if SPEC1170 behaviour is off, mprotect() on AIX will
simonis@6465 2623 // not tell me if protection failed when trying to protect an un-protectable range.
simonis@6465 2624 //
simonis@6465 2625 // This means if the memory was allocated using shmget/shmat, protection wont work
simonis@6465 2626 // but mprotect will still return 0:
simonis@6465 2627 //
simonis@6465 2628 // See http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/mprotect.htm
simonis@6465 2629
simonis@6465 2630 bool rc = ::mprotect(addr, size, prot) == 0 ? true : false;
simonis@6465 2631
simonis@6465 2632 if (!rc) {
simonis@6465 2633 const char* const s_errno = strerror(errno);
simonis@6465 2634 warning("mprotect(" PTR_FORMAT "-" PTR_FORMAT ", 0x%X) failed (%s).", addr, addr + size, prot, s_errno);
simonis@6465 2635 return false;
simonis@6465 2636 }
simonis@6465 2637
simonis@6465 2638 // mprotect success check
simonis@6465 2639 //
simonis@6465 2640 // Mprotect said it changed the protection but can I believe it?
simonis@6465 2641 //
simonis@6465 2642 // To be sure I need to check the protection afterwards. Try to
simonis@6465 2643 // read from protected memory and check whether that causes a segfault.
simonis@6465 2644 //
simonis@6465 2645 if (!os::Aix::xpg_sus_mode()) {
simonis@6465 2646
simonis@6465 2647 if (StubRoutines::SafeFetch32_stub()) {
simonis@6465 2648
simonis@6465 2649 const bool read_protected =
simonis@6465 2650 (SafeFetch32((int*)addr, 0x12345678) == 0x12345678 &&
simonis@6465 2651 SafeFetch32((int*)addr, 0x76543210) == 0x76543210) ? true : false;
simonis@6465 2652
simonis@6465 2653 if (prot & PROT_READ) {
simonis@6465 2654 rc = !read_protected;
simonis@6465 2655 } else {
simonis@6465 2656 rc = read_protected;
simonis@6465 2657 }
simonis@6465 2658 }
simonis@6465 2659 }
simonis@6465 2660 if (!rc) {
simonis@6465 2661 assert(false, "mprotect failed.");
simonis@6465 2662 }
simonis@6465 2663 return rc;
simonis@6465 2664 }
simonis@6465 2665
simonis@6465 2666 // Set protections specified
simonis@6465 2667 bool os::protect_memory(char* addr, size_t size, ProtType prot, bool is_committed) {
simonis@6465 2668 unsigned int p = 0;
simonis@6465 2669 switch (prot) {
simonis@6465 2670 case MEM_PROT_NONE: p = PROT_NONE; break;
simonis@6465 2671 case MEM_PROT_READ: p = PROT_READ; break;
simonis@6465 2672 case MEM_PROT_RW: p = PROT_READ|PROT_WRITE; break;
simonis@6465 2673 case MEM_PROT_RWX: p = PROT_READ|PROT_WRITE|PROT_EXEC; break;
simonis@6465 2674 default:
simonis@6465 2675 ShouldNotReachHere();
simonis@6465 2676 }
simonis@6465 2677 // is_committed is unused.
simonis@6465 2678 return checked_mprotect(addr, size, p);
simonis@6465 2679 }
simonis@6465 2680
simonis@6465 2681 bool os::guard_memory(char* addr, size_t size) {
simonis@6465 2682 return checked_mprotect(addr, size, PROT_NONE);
simonis@6465 2683 }
simonis@6465 2684
simonis@6465 2685 bool os::unguard_memory(char* addr, size_t size) {
simonis@6465 2686 return checked_mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC);
simonis@6465 2687 }
simonis@6465 2688
simonis@6465 2689 // Large page support
simonis@6465 2690
simonis@6465 2691 static size_t _large_page_size = 0;
simonis@6465 2692
simonis@6465 2693 // Enable large page support if OS allows that.
simonis@6465 2694 void os::large_page_init() {
simonis@6465 2695
simonis@6465 2696 // Note: os::Aix::query_multipage_support must run first.
simonis@6465 2697
simonis@6465 2698 if (!UseLargePages) {
simonis@6465 2699 return;
simonis@6465 2700 }
simonis@6465 2701
simonis@6465 2702 if (!Aix::can_use_64K_pages()) {
simonis@6465 2703 assert(!Aix::can_use_16M_pages(), "64K is a precondition for 16M.");
simonis@6465 2704 UseLargePages = false;
simonis@6465 2705 return;
simonis@6465 2706 }
simonis@6465 2707
simonis@6465 2708 if (!Aix::can_use_16M_pages() && Use16MPages) {
simonis@6465 2709 fprintf(stderr, "Cannot use 16M pages. Please ensure that there is a 16M page pool "
simonis@6465 2710 " and that the VM runs with CAP_BYPASS_RAC_VMM and CAP_PROPAGATE capabilities.\n");
simonis@6465 2711 }
simonis@6465 2712
simonis@6465 2713 // Do not report 16M page alignment as part of os::_page_sizes if we are
simonis@6465 2714 // explicitly forbidden from using 16M pages. Doing so would increase the
simonis@6465 2715 // alignment the garbage collector calculates with, slightly increasing
simonis@6465 2716 // heap usage. We should only pay for 16M alignment if we really want to
simonis@6465 2717 // use 16M pages.
simonis@6465 2718 if (Use16MPages && Aix::can_use_16M_pages()) {
simonis@6465 2719 _large_page_size = SIZE_16M;
simonis@6465 2720 _page_sizes[0] = SIZE_16M;
simonis@6465 2721 _page_sizes[1] = SIZE_64K;
simonis@6465 2722 _page_sizes[2] = SIZE_4K;
simonis@6465 2723 _page_sizes[3] = 0;
simonis@6465 2724 } else if (Aix::can_use_64K_pages()) {
simonis@6465 2725 _large_page_size = SIZE_64K;
simonis@6465 2726 _page_sizes[0] = SIZE_64K;
simonis@6465 2727 _page_sizes[1] = SIZE_4K;
simonis@6465 2728 _page_sizes[2] = 0;
simonis@6465 2729 }
simonis@6465 2730
simonis@6465 2731 if (Verbose) {
simonis@6465 2732 ("Default large page size is 0x%llX.", _large_page_size);
simonis@6465 2733 }
simonis@6465 2734 } // end: os::large_page_init()
simonis@6465 2735
simonis@6465 2736 char* os::reserve_memory_special(size_t bytes, size_t alignment, char* req_addr, bool exec) {
simonis@6465 2737 // "exec" is passed in but not used. Creating the shared image for
simonis@6465 2738 // the code cache doesn't have an SHM_X executable permission to check.
simonis@6465 2739 Unimplemented();
simonis@6465 2740 return 0;
simonis@6465 2741 }
simonis@6465 2742
simonis@6465 2743 bool os::release_memory_special(char* base, size_t bytes) {
simonis@6465 2744 // detaching the SHM segment will also delete it, see reserve_memory_special()
simonis@6465 2745 Unimplemented();
simonis@6465 2746 return false;
simonis@6465 2747 }
simonis@6465 2748
simonis@6465 2749 size_t os::large_page_size() {
simonis@6465 2750 return _large_page_size;
simonis@6465 2751 }
simonis@6465 2752
simonis@6465 2753 bool os::can_commit_large_page_memory() {
simonis@6465 2754 // Well, sadly we cannot commit anything at all (see comment in
simonis@6465 2755 // os::commit_memory) but we claim to so we can make use of large pages
simonis@6465 2756 return true;
simonis@6465 2757 }
simonis@6465 2758
simonis@6465 2759 bool os::can_execute_large_page_memory() {
simonis@6465 2760 // We can do that
simonis@6465 2761 return true;
simonis@6465 2762 }
simonis@6465 2763
simonis@6465 2764 // Reserve memory at an arbitrary address, only if that area is
simonis@6465 2765 // available (and not reserved for something else).
simonis@6465 2766 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
simonis@6465 2767
simonis@6465 2768 bool use_mmap = false;
simonis@6465 2769
simonis@6465 2770 // mmap: smaller graining, no large page support
simonis@6465 2771 // shm: large graining (256M), large page support, limited number of shm segments
simonis@6465 2772 //
simonis@6465 2773 // Prefer mmap wherever we either do not need large page support or have OS limits
simonis@6465 2774
simonis@6465 2775 if (!UseLargePages || bytes < SIZE_16M) {
simonis@6465 2776 use_mmap = true;
simonis@6465 2777 }
simonis@6465 2778
simonis@6465 2779 char* addr = NULL;
simonis@6465 2780 if (use_mmap) {
simonis@6465 2781 addr = reserve_mmaped_memory(bytes, requested_addr);
simonis@6465 2782 } else {
simonis@6465 2783 // shmat: wish address is mandatory, and do not try 16M pages here.
simonis@6465 2784 shmatted_memory_info_t info;
simonis@6465 2785 const int flags = RESSHM_WISHADDR_OR_FAIL;
simonis@6465 2786 if (reserve_shmatted_memory(bytes, requested_addr, flags, &info)) {
simonis@6465 2787 addr = info.addr;
simonis@6465 2788 }
simonis@6465 2789 }
simonis@6465 2790
simonis@6465 2791 return addr;
simonis@6465 2792 }
simonis@6465 2793
simonis@6465 2794 size_t os::read(int fd, void *buf, unsigned int nBytes) {
simonis@6465 2795 return ::read(fd, buf, nBytes);
simonis@6465 2796 }
simonis@6465 2797
simonis@6465 2798 #define NANOSECS_PER_MILLISEC 1000000
simonis@6465 2799
simonis@6465 2800 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
simonis@6465 2801 assert(thread == Thread::current(), "thread consistency check");
simonis@6465 2802
simonis@6465 2803 // Prevent nasty overflow in deadline calculation
simonis@6465 2804 // by handling long sleeps similar to solaris or windows.
simonis@6465 2805 const jlong limit = INT_MAX;
simonis@6465 2806 int result;
simonis@6465 2807 while (millis > limit) {
simonis@6465 2808 if ((result = os::sleep(thread, limit, interruptible)) != OS_OK) {
simonis@6465 2809 return result;
simonis@6465 2810 }
simonis@6465 2811 millis -= limit;
simonis@6465 2812 }
simonis@6465 2813
simonis@6465 2814 ParkEvent * const slp = thread->_SleepEvent;
simonis@6465 2815 slp->reset();
simonis@6465 2816 OrderAccess::fence();
simonis@6465 2817
simonis@6465 2818 if (interruptible) {
simonis@6465 2819 jlong prevtime = javaTimeNanos();
simonis@6465 2820
simonis@6465 2821 // Prevent precision loss and too long sleeps
simonis@6465 2822 jlong deadline = prevtime + millis * NANOSECS_PER_MILLISEC;
simonis@6465 2823
simonis@6465 2824 for (;;) {
simonis@6465 2825 if (os::is_interrupted(thread, true)) {
simonis@6465 2826 return OS_INTRPT;
simonis@6465 2827 }
simonis@6465 2828
simonis@6465 2829 jlong newtime = javaTimeNanos();
simonis@6465 2830
simonis@6465 2831 assert(newtime >= prevtime, "time moving backwards");
simonis@6465 2832 // Doing prevtime and newtime in microseconds doesn't help precision,
simonis@6465 2833 // and trying to round up to avoid lost milliseconds can result in a
simonis@6465 2834 // too-short delay.
simonis@6465 2835 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
simonis@6465 2836
simonis@6465 2837 if (millis <= 0) {
simonis@6465 2838 return OS_OK;
simonis@6465 2839 }
simonis@6465 2840
simonis@6465 2841 // Stop sleeping if we passed the deadline
simonis@6465 2842 if (newtime >= deadline) {
simonis@6465 2843 return OS_OK;
simonis@6465 2844 }
simonis@6465 2845
simonis@6465 2846 prevtime = newtime;
simonis@6465 2847
simonis@6465 2848 {
simonis@6465 2849 assert(thread->is_Java_thread(), "sanity check");
simonis@6465 2850 JavaThread *jt = (JavaThread *) thread;
simonis@6465 2851 ThreadBlockInVM tbivm(jt);
simonis@6465 2852 OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */);
simonis@6465 2853
simonis@6465 2854 jt->set_suspend_equivalent();
simonis@6465 2855
simonis@6465 2856 slp->park(millis);
simonis@6465 2857
simonis@6465 2858 // were we externally suspended while we were waiting?
simonis@6465 2859 jt->check_and_wait_while_suspended();
simonis@6465 2860 }
simonis@6465 2861 }
simonis@6465 2862 } else {
simonis@6465 2863 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
simonis@6465 2864 jlong prevtime = javaTimeNanos();
simonis@6465 2865
simonis@6465 2866 // Prevent precision loss and too long sleeps
simonis@6465 2867 jlong deadline = prevtime + millis * NANOSECS_PER_MILLISEC;
simonis@6465 2868
simonis@6465 2869 for (;;) {
simonis@6465 2870 // It'd be nice to avoid the back-to-back javaTimeNanos() calls on
simonis@6465 2871 // the 1st iteration ...
simonis@6465 2872 jlong newtime = javaTimeNanos();
simonis@6465 2873
simonis@6465 2874 if (newtime - prevtime < 0) {
simonis@6465 2875 // time moving backwards, should only happen if no monotonic clock
simonis@6465 2876 // not a guarantee() because JVM should not abort on kernel/glibc bugs
simonis@6465 2877 // - HS14 Commented out as not implemented.
simonis@6465 2878 // - TODO Maybe we should implement it?
simonis@6465 2879 //assert(!Aix::supports_monotonic_clock(), "time moving backwards");
simonis@6465 2880 } else {
simonis@6465 2881 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
simonis@6465 2882 }
simonis@6465 2883
simonis@6465 2884 if (millis <= 0) break;
simonis@6465 2885
simonis@6465 2886 if (newtime >= deadline) {
simonis@6465 2887 break;
simonis@6465 2888 }
simonis@6465 2889
simonis@6465 2890 prevtime = newtime;
simonis@6465 2891 slp->park(millis);
simonis@6465 2892 }
simonis@6465 2893 return OS_OK;
simonis@6465 2894 }
simonis@6465 2895 }
simonis@6465 2896
simonis@6465 2897 int os::naked_sleep() {
simonis@6465 2898 // %% make the sleep time an integer flag. for now use 1 millisec.
simonis@6465 2899 return os::sleep(Thread::current(), 1, false);
simonis@6465 2900 }
simonis@6465 2901
simonis@6465 2902 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
simonis@6465 2903 void os::infinite_sleep() {
simonis@6465 2904 while (true) { // sleep forever ...
simonis@6465 2905 ::sleep(100); // ... 100 seconds at a time
simonis@6465 2906 }
simonis@6465 2907 }
simonis@6465 2908
simonis@6465 2909 // Used to convert frequent JVM_Yield() to nops
simonis@6465 2910 bool os::dont_yield() {
simonis@6465 2911 return DontYieldALot;
simonis@6465 2912 }
simonis@6465 2913
simonis@6465 2914 void os::yield() {
simonis@6465 2915 sched_yield();
simonis@6465 2916 }
simonis@6465 2917
simonis@6465 2918 os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN; }
simonis@6465 2919
simonis@6465 2920 void os::yield_all(int attempts) {
simonis@6465 2921 // Yields to all threads, including threads with lower priorities
simonis@6465 2922 // Threads on Linux are all with same priority. The Solaris style
simonis@6465 2923 // os::yield_all() with nanosleep(1ms) is not necessary.
simonis@6465 2924 sched_yield();
simonis@6465 2925 }
simonis@6465 2926
simonis@6465 2927 // Called from the tight loops to possibly influence time-sharing heuristics
simonis@6465 2928 void os::loop_breaker(int attempts) {
simonis@6465 2929 os::yield_all(attempts);
simonis@6465 2930 }
simonis@6465 2931
simonis@6465 2932 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 2933 // thread priority support
simonis@6465 2934
simonis@6465 2935 // From AIX manpage to pthread_setschedparam
simonis@6465 2936 // (see: http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?
simonis@6465 2937 // topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread_setschedparam.htm):
simonis@6465 2938 //
simonis@6465 2939 // "If schedpolicy is SCHED_OTHER, then sched_priority must be in the
simonis@6465 2940 // range from 40 to 80, where 40 is the least favored priority and 80
simonis@6465 2941 // is the most favored."
simonis@6465 2942 //
simonis@6465 2943 // (Actually, I doubt this even has an impact on AIX, as we do kernel
simonis@6465 2944 // scheduling there; however, this still leaves iSeries.)
simonis@6465 2945 //
simonis@6465 2946 // We use the same values for AIX and PASE.
simonis@6465 2947 int os::java_to_os_priority[CriticalPriority + 1] = {
simonis@6465 2948 54, // 0 Entry should never be used
simonis@6465 2949
simonis@6465 2950 55, // 1 MinPriority
simonis@6465 2951 55, // 2
simonis@6465 2952 56, // 3
simonis@6465 2953
simonis@6465 2954 56, // 4
simonis@6465 2955 57, // 5 NormPriority
simonis@6465 2956 57, // 6
simonis@6465 2957
simonis@6465 2958 58, // 7
simonis@6465 2959 58, // 8
simonis@6465 2960 59, // 9 NearMaxPriority
simonis@6465 2961
simonis@6465 2962 60, // 10 MaxPriority
simonis@6465 2963
simonis@6465 2964 60 // 11 CriticalPriority
simonis@6465 2965 };
simonis@6465 2966
simonis@6465 2967 OSReturn os::set_native_priority(Thread* thread, int newpri) {
simonis@6465 2968 if (!UseThreadPriorities) return OS_OK;
simonis@6465 2969 pthread_t thr = thread->osthread()->pthread_id();
simonis@6465 2970 int policy = SCHED_OTHER;
simonis@6465 2971 struct sched_param param;
simonis@6465 2972 param.sched_priority = newpri;
simonis@6465 2973 int ret = pthread_setschedparam(thr, policy, &param);
simonis@6465 2974
simonis@6465 2975 if (Verbose) {
simonis@6465 2976 if (ret == 0) {
simonis@6465 2977 fprintf(stderr, "changed priority of thread %d to %d\n", (int)thr, newpri);
simonis@6465 2978 } else {
simonis@6465 2979 fprintf(stderr, "Could not changed priority for thread %d to %d (error %d, %s)\n",
simonis@6465 2980 (int)thr, newpri, ret, strerror(ret));
simonis@6465 2981 }
simonis@6465 2982 }
simonis@6465 2983 return (ret == 0) ? OS_OK : OS_ERR;
simonis@6465 2984 }
simonis@6465 2985
simonis@6465 2986 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
simonis@6465 2987 if (!UseThreadPriorities) {
simonis@6465 2988 *priority_ptr = java_to_os_priority[NormPriority];
simonis@6465 2989 return OS_OK;
simonis@6465 2990 }
simonis@6465 2991 pthread_t thr = thread->osthread()->pthread_id();
simonis@6465 2992 int policy = SCHED_OTHER;
simonis@6465 2993 struct sched_param param;
simonis@6465 2994 int ret = pthread_getschedparam(thr, &policy, &param);
simonis@6465 2995 *priority_ptr = param.sched_priority;
simonis@6465 2996
simonis@6465 2997 return (ret == 0) ? OS_OK : OS_ERR;
simonis@6465 2998 }
simonis@6465 2999
simonis@6465 3000 // Hint to the underlying OS that a task switch would not be good.
simonis@6465 3001 // Void return because it's a hint and can fail.
simonis@6465 3002 void os::hint_no_preempt() {}
simonis@6465 3003
simonis@6465 3004 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 3005 // suspend/resume support
simonis@6465 3006
simonis@6465 3007 // the low-level signal-based suspend/resume support is a remnant from the
simonis@6465 3008 // old VM-suspension that used to be for java-suspension, safepoints etc,
simonis@6465 3009 // within hotspot. Now there is a single use-case for this:
simonis@6465 3010 // - calling get_thread_pc() on the VMThread by the flat-profiler task
simonis@6465 3011 // that runs in the watcher thread.
simonis@6465 3012 // The remaining code is greatly simplified from the more general suspension
simonis@6465 3013 // code that used to be used.
simonis@6465 3014 //
simonis@6465 3015 // The protocol is quite simple:
simonis@6465 3016 // - suspend:
simonis@6465 3017 // - sends a signal to the target thread
simonis@6465 3018 // - polls the suspend state of the osthread using a yield loop
simonis@6465 3019 // - target thread signal handler (SR_handler) sets suspend state
simonis@6465 3020 // and blocks in sigsuspend until continued
simonis@6465 3021 // - resume:
simonis@6465 3022 // - sets target osthread state to continue
simonis@6465 3023 // - sends signal to end the sigsuspend loop in the SR_handler
simonis@6465 3024 //
simonis@6465 3025 // Note that the SR_lock plays no role in this suspend/resume protocol.
simonis@6465 3026 //
simonis@6465 3027
simonis@6465 3028 static void resume_clear_context(OSThread *osthread) {
simonis@6465 3029 osthread->set_ucontext(NULL);
simonis@6465 3030 osthread->set_siginfo(NULL);
simonis@6465 3031 }
simonis@6465 3032
simonis@6465 3033 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) {
simonis@6465 3034 osthread->set_ucontext(context);
simonis@6465 3035 osthread->set_siginfo(siginfo);
simonis@6465 3036 }
simonis@6465 3037
simonis@6465 3038 //
simonis@6465 3039 // Handler function invoked when a thread's execution is suspended or
simonis@6465 3040 // resumed. We have to be careful that only async-safe functions are
simonis@6465 3041 // called here (Note: most pthread functions are not async safe and
simonis@6465 3042 // should be avoided.)
simonis@6465 3043 //
simonis@6465 3044 // Note: sigwait() is a more natural fit than sigsuspend() from an
simonis@6465 3045 // interface point of view, but sigwait() prevents the signal hander
simonis@6465 3046 // from being run. libpthread would get very confused by not having
simonis@6465 3047 // its signal handlers run and prevents sigwait()'s use with the
simonis@6465 3048 // mutex granting granting signal.
simonis@6465 3049 //
simonis@6465 3050 // Currently only ever called on the VMThread and JavaThreads (PC sampling).
simonis@6465 3051 //
simonis@6465 3052 static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) {
simonis@6465 3053 // Save and restore errno to avoid confusing native code with EINTR
simonis@6465 3054 // after sigsuspend.
simonis@6465 3055 int old_errno = errno;
simonis@6465 3056
simonis@6465 3057 Thread* thread = Thread::current();
simonis@6465 3058 OSThread* osthread = thread->osthread();
simonis@6465 3059 assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread");
simonis@6465 3060
simonis@6465 3061 os::SuspendResume::State current = osthread->sr.state();
simonis@6465 3062 if (current == os::SuspendResume::SR_SUSPEND_REQUEST) {
simonis@6465 3063 suspend_save_context(osthread, siginfo, context);
simonis@6465 3064
simonis@6465 3065 // attempt to switch the state, we assume we had a SUSPEND_REQUEST
simonis@6465 3066 os::SuspendResume::State state = osthread->sr.suspended();
simonis@6465 3067 if (state == os::SuspendResume::SR_SUSPENDED) {
simonis@6465 3068 sigset_t suspend_set; // signals for sigsuspend()
simonis@6465 3069
simonis@6465 3070 // get current set of blocked signals and unblock resume signal
simonis@6465 3071 pthread_sigmask(SIG_BLOCK, NULL, &suspend_set);
simonis@6465 3072 sigdelset(&suspend_set, SR_signum);
simonis@6465 3073
simonis@6465 3074 // wait here until we are resumed
simonis@6465 3075 while (1) {
simonis@6465 3076 sigsuspend(&suspend_set);
simonis@6465 3077
simonis@6465 3078 os::SuspendResume::State result = osthread->sr.running();
simonis@6465 3079 if (result == os::SuspendResume::SR_RUNNING) {
simonis@6465 3080 break;
simonis@6465 3081 }
simonis@6465 3082 }
simonis@6465 3083
simonis@6465 3084 } else if (state == os::SuspendResume::SR_RUNNING) {
simonis@6465 3085 // request was cancelled, continue
simonis@6465 3086 } else {
simonis@6465 3087 ShouldNotReachHere();
simonis@6465 3088 }
simonis@6465 3089
simonis@6465 3090 resume_clear_context(osthread);
simonis@6465 3091 } else if (current == os::SuspendResume::SR_RUNNING) {
simonis@6465 3092 // request was cancelled, continue
simonis@6465 3093 } else if (current == os::SuspendResume::SR_WAKEUP_REQUEST) {
simonis@6465 3094 // ignore
simonis@6465 3095 } else {
simonis@6465 3096 ShouldNotReachHere();
simonis@6465 3097 }
simonis@6465 3098
simonis@6465 3099 errno = old_errno;
simonis@6465 3100 }
simonis@6465 3101
simonis@6465 3102
simonis@6465 3103 static int SR_initialize() {
simonis@6465 3104 struct sigaction act;
simonis@6465 3105 char *s;
simonis@6465 3106 // Get signal number to use for suspend/resume
simonis@6465 3107 if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
simonis@6465 3108 int sig = ::strtol(s, 0, 10);
simonis@6465 3109 if (sig > 0 || sig < NSIG) {
simonis@6465 3110 SR_signum = sig;
simonis@6465 3111 }
simonis@6465 3112 }
simonis@6465 3113
simonis@6465 3114 assert(SR_signum > SIGSEGV && SR_signum > SIGBUS,
simonis@6465 3115 "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
simonis@6465 3116
simonis@6465 3117 sigemptyset(&SR_sigset);
simonis@6465 3118 sigaddset(&SR_sigset, SR_signum);
simonis@6465 3119
simonis@6465 3120 // Set up signal handler for suspend/resume.
simonis@6465 3121 act.sa_flags = SA_RESTART|SA_SIGINFO;
simonis@6465 3122 act.sa_handler = (void (*)(int)) SR_handler;
simonis@6465 3123
simonis@6465 3124 // SR_signum is blocked by default.
simonis@6465 3125 // 4528190 - We also need to block pthread restart signal (32 on all
simonis@6465 3126 // supported Linux platforms). Note that LinuxThreads need to block
simonis@6465 3127 // this signal for all threads to work properly. So we don't have
simonis@6465 3128 // to use hard-coded signal number when setting up the mask.
simonis@6465 3129 pthread_sigmask(SIG_BLOCK, NULL, &act.sa_mask);
simonis@6465 3130
simonis@6465 3131 if (sigaction(SR_signum, &act, 0) == -1) {
simonis@6465 3132 return -1;
simonis@6465 3133 }
simonis@6465 3134
simonis@6465 3135 // Save signal flag
simonis@6465 3136 os::Aix::set_our_sigflags(SR_signum, act.sa_flags);
simonis@6465 3137 return 0;
simonis@6465 3138 }
simonis@6465 3139
simonis@6465 3140 static int SR_finalize() {
simonis@6465 3141 return 0;
simonis@6465 3142 }
simonis@6465 3143
simonis@6465 3144 static int sr_notify(OSThread* osthread) {
simonis@6465 3145 int status = pthread_kill(osthread->pthread_id(), SR_signum);
simonis@6465 3146 assert_status(status == 0, status, "pthread_kill");
simonis@6465 3147 return status;
simonis@6465 3148 }
simonis@6465 3149
simonis@6465 3150 // "Randomly" selected value for how long we want to spin
simonis@6465 3151 // before bailing out on suspending a thread, also how often
simonis@6465 3152 // we send a signal to a thread we want to resume
simonis@6465 3153 static const int RANDOMLY_LARGE_INTEGER = 1000000;
simonis@6465 3154 static const int RANDOMLY_LARGE_INTEGER2 = 100;
simonis@6465 3155
simonis@6465 3156 // returns true on success and false on error - really an error is fatal
simonis@6465 3157 // but this seems the normal response to library errors
simonis@6465 3158 static bool do_suspend(OSThread* osthread) {
simonis@6465 3159 assert(osthread->sr.is_running(), "thread should be running");
simonis@6465 3160 // mark as suspended and send signal
simonis@6465 3161
simonis@6465 3162 if (osthread->sr.request_suspend() != os::SuspendResume::SR_SUSPEND_REQUEST) {
simonis@6465 3163 // failed to switch, state wasn't running?
simonis@6465 3164 ShouldNotReachHere();
simonis@6465 3165 return false;
simonis@6465 3166 }
simonis@6465 3167
simonis@6465 3168 if (sr_notify(osthread) != 0) {
simonis@6465 3169 // try to cancel, switch to running
simonis@6465 3170
simonis@6465 3171 os::SuspendResume::State result = osthread->sr.cancel_suspend();
simonis@6465 3172 if (result == os::SuspendResume::SR_RUNNING) {
simonis@6465 3173 // cancelled
simonis@6465 3174 return false;
simonis@6465 3175 } else if (result == os::SuspendResume::SR_SUSPENDED) {
simonis@6465 3176 // somehow managed to suspend
simonis@6465 3177 return true;
simonis@6465 3178 } else {
simonis@6465 3179 ShouldNotReachHere();
simonis@6465 3180 return false;
simonis@6465 3181 }
simonis@6465 3182 }
simonis@6465 3183
simonis@6465 3184 // managed to send the signal and switch to SUSPEND_REQUEST, now wait for SUSPENDED
simonis@6465 3185
simonis@6465 3186 for (int n = 0; !osthread->sr.is_suspended(); n++) {
simonis@6465 3187 for (int i = 0; i < RANDOMLY_LARGE_INTEGER2 && !osthread->sr.is_suspended(); i++) {
simonis@6465 3188 os::yield_all(i);
simonis@6465 3189 }
simonis@6465 3190
simonis@6465 3191 // timeout, try to cancel the request
simonis@6465 3192 if (n >= RANDOMLY_LARGE_INTEGER) {
simonis@6465 3193 os::SuspendResume::State cancelled = osthread->sr.cancel_suspend();
simonis@6465 3194 if (cancelled == os::SuspendResume::SR_RUNNING) {
simonis@6465 3195 return false;
simonis@6465 3196 } else if (cancelled == os::SuspendResume::SR_SUSPENDED) {
simonis@6465 3197 return true;
simonis@6465 3198 } else {
simonis@6465 3199 ShouldNotReachHere();
simonis@6465 3200 return false;
simonis@6465 3201 }
simonis@6465 3202 }
simonis@6465 3203 }
simonis@6465 3204
simonis@6465 3205 guarantee(osthread->sr.is_suspended(), "Must be suspended");
simonis@6465 3206 return true;
simonis@6465 3207 }
simonis@6465 3208
simonis@6465 3209 static void do_resume(OSThread* osthread) {
simonis@6465 3210 //assert(osthread->sr.is_suspended(), "thread should be suspended");
simonis@6465 3211
simonis@6465 3212 if (osthread->sr.request_wakeup() != os::SuspendResume::SR_WAKEUP_REQUEST) {
simonis@6465 3213 // failed to switch to WAKEUP_REQUEST
simonis@6465 3214 ShouldNotReachHere();
simonis@6465 3215 return;
simonis@6465 3216 }
simonis@6465 3217
simonis@6465 3218 while (!osthread->sr.is_running()) {
simonis@6465 3219 if (sr_notify(osthread) == 0) {
simonis@6465 3220 for (int n = 0; n < RANDOMLY_LARGE_INTEGER && !osthread->sr.is_running(); n++) {
simonis@6465 3221 for (int i = 0; i < 100 && !osthread->sr.is_running(); i++) {
simonis@6465 3222 os::yield_all(i);
simonis@6465 3223 }
simonis@6465 3224 }
simonis@6465 3225 } else {
simonis@6465 3226 ShouldNotReachHere();
simonis@6465 3227 }
simonis@6465 3228 }
simonis@6465 3229
simonis@6465 3230 guarantee(osthread->sr.is_running(), "Must be running!");
simonis@6465 3231 }
simonis@6465 3232
simonis@6465 3233 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 3234 // interrupt support
simonis@6465 3235
simonis@6465 3236 void os::interrupt(Thread* thread) {
simonis@6465 3237 assert(Thread::current() == thread || Threads_lock->owned_by_self(),
simonis@6465 3238 "possibility of dangling Thread pointer");
simonis@6465 3239
simonis@6465 3240 OSThread* osthread = thread->osthread();
simonis@6465 3241
simonis@6465 3242 if (!osthread->interrupted()) {
simonis@6465 3243 osthread->set_interrupted(true);
simonis@6465 3244 // More than one thread can get here with the same value of osthread,
simonis@6465 3245 // resulting in multiple notifications. We do, however, want the store
simonis@6465 3246 // to interrupted() to be visible to other threads before we execute unpark().
simonis@6465 3247 OrderAccess::fence();
simonis@6465 3248 ParkEvent * const slp = thread->_SleepEvent;
simonis@6465 3249 if (slp != NULL) slp->unpark();
simonis@6465 3250 }
simonis@6465 3251
simonis@6465 3252 // For JSR166. Unpark even if interrupt status already was set
simonis@6465 3253 if (thread->is_Java_thread())
simonis@6465 3254 ((JavaThread*)thread)->parker()->unpark();
simonis@6465 3255
simonis@6465 3256 ParkEvent * ev = thread->_ParkEvent;
simonis@6465 3257 if (ev != NULL) ev->unpark();
simonis@6465 3258
simonis@6465 3259 }
simonis@6465 3260
simonis@6465 3261 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
simonis@6465 3262 assert(Thread::current() == thread || Threads_lock->owned_by_self(),
simonis@6465 3263 "possibility of dangling Thread pointer");
simonis@6465 3264
simonis@6465 3265 OSThread* osthread = thread->osthread();
simonis@6465 3266
simonis@6465 3267 bool interrupted = osthread->interrupted();
simonis@6465 3268
simonis@6465 3269 if (interrupted && clear_interrupted) {
simonis@6465 3270 osthread->set_interrupted(false);
simonis@6465 3271 // consider thread->_SleepEvent->reset() ... optional optimization
simonis@6465 3272 }
simonis@6465 3273
simonis@6465 3274 return interrupted;
simonis@6465 3275 }
simonis@6465 3276
simonis@6465 3277 ///////////////////////////////////////////////////////////////////////////////////
simonis@6465 3278 // signal handling (except suspend/resume)
simonis@6465 3279
simonis@6465 3280 // This routine may be used by user applications as a "hook" to catch signals.
simonis@6465 3281 // The user-defined signal handler must pass unrecognized signals to this
simonis@6465 3282 // routine, and if it returns true (non-zero), then the signal handler must
simonis@6465 3283 // return immediately. If the flag "abort_if_unrecognized" is true, then this
simonis@6465 3284 // routine will never retun false (zero), but instead will execute a VM panic
simonis@6465 3285 // routine kill the process.
simonis@6465 3286 //
simonis@6465 3287 // If this routine returns false, it is OK to call it again. This allows
simonis@6465 3288 // the user-defined signal handler to perform checks either before or after
simonis@6465 3289 // the VM performs its own checks. Naturally, the user code would be making
simonis@6465 3290 // a serious error if it tried to handle an exception (such as a null check
simonis@6465 3291 // or breakpoint) that the VM was generating for its own correct operation.
simonis@6465 3292 //
simonis@6465 3293 // This routine may recognize any of the following kinds of signals:
simonis@6465 3294 // SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
simonis@6465 3295 // It should be consulted by handlers for any of those signals.
simonis@6465 3296 //
simonis@6465 3297 // The caller of this routine must pass in the three arguments supplied
simonis@6465 3298 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
simonis@6465 3299 // field of the structure passed to sigaction(). This routine assumes that
simonis@6465 3300 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
simonis@6465 3301 //
simonis@6465 3302 // Note that the VM will print warnings if it detects conflicting signal
simonis@6465 3303 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
simonis@6465 3304 //
simonis@6465 3305 extern "C" JNIEXPORT int
simonis@6465 3306 JVM_handle_aix_signal(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized);
simonis@6465 3307
simonis@6465 3308 // Set thread signal mask (for some reason on AIX sigthreadmask() seems
simonis@6465 3309 // to be the thing to call; documentation is not terribly clear about whether
simonis@6465 3310 // pthread_sigmask also works, and if it does, whether it does the same.
simonis@6465 3311 bool set_thread_signal_mask(int how, const sigset_t* set, sigset_t* oset) {
simonis@6465 3312 const int rc = ::pthread_sigmask(how, set, oset);
simonis@6465 3313 // return value semantics differ slightly for error case:
simonis@6465 3314 // pthread_sigmask returns error number, sigthreadmask -1 and sets global errno
simonis@6465 3315 // (so, pthread_sigmask is more theadsafe for error handling)
simonis@6465 3316 // But success is always 0.
simonis@6465 3317 return rc == 0 ? true : false;
simonis@6465 3318 }
simonis@6465 3319
simonis@6465 3320 // Function to unblock all signals which are, according
simonis@6465 3321 // to POSIX, typical program error signals. If they happen while being blocked,
simonis@6465 3322 // they typically will bring down the process immediately.
simonis@6465 3323 bool unblock_program_error_signals() {
simonis@6465 3324 sigset_t set;
simonis@6465 3325 ::sigemptyset(&set);
simonis@6465 3326 ::sigaddset(&set, SIGILL);
simonis@6465 3327 ::sigaddset(&set, SIGBUS);
simonis@6465 3328 ::sigaddset(&set, SIGFPE);
simonis@6465 3329 ::sigaddset(&set, SIGSEGV);
simonis@6465 3330 return set_thread_signal_mask(SIG_UNBLOCK, &set, NULL);
simonis@6465 3331 }
simonis@6465 3332
simonis@6465 3333 // Renamed from 'signalHandler' to avoid collision with other shared libs.
simonis@6465 3334 void javaSignalHandler(int sig, siginfo_t* info, void* uc) {
simonis@6465 3335 assert(info != NULL && uc != NULL, "it must be old kernel");
simonis@6465 3336
simonis@6465 3337 // Never leave program error signals blocked;
simonis@6465 3338 // on all our platforms they would bring down the process immediately when
simonis@6465 3339 // getting raised while being blocked.
simonis@6465 3340 unblock_program_error_signals();
simonis@6465 3341
simonis@6465 3342 JVM_handle_aix_signal(sig, info, uc, true);
simonis@6465 3343 }
simonis@6465 3344
simonis@6465 3345
simonis@6465 3346 // This boolean allows users to forward their own non-matching signals
simonis@6465 3347 // to JVM_handle_aix_signal, harmlessly.
simonis@6465 3348 bool os::Aix::signal_handlers_are_installed = false;
simonis@6465 3349
simonis@6465 3350 // For signal-chaining
simonis@6465 3351 struct sigaction os::Aix::sigact[MAXSIGNUM];
simonis@6465 3352 unsigned int os::Aix::sigs = 0;
simonis@6465 3353 bool os::Aix::libjsig_is_loaded = false;
simonis@6465 3354 typedef struct sigaction *(*get_signal_t)(int);
simonis@6465 3355 get_signal_t os::Aix::get_signal_action = NULL;
simonis@6465 3356
simonis@6465 3357 struct sigaction* os::Aix::get_chained_signal_action(int sig) {
simonis@6465 3358 struct sigaction *actp = NULL;
simonis@6465 3359
simonis@6465 3360 if (libjsig_is_loaded) {
simonis@6465 3361 // Retrieve the old signal handler from libjsig
simonis@6465 3362 actp = (*get_signal_action)(sig);
simonis@6465 3363 }
simonis@6465 3364 if (actp == NULL) {
simonis@6465 3365 // Retrieve the preinstalled signal handler from jvm
simonis@6465 3366 actp = get_preinstalled_handler(sig);
simonis@6465 3367 }
simonis@6465 3368
simonis@6465 3369 return actp;
simonis@6465 3370 }
simonis@6465 3371
simonis@6465 3372 static bool call_chained_handler(struct sigaction *actp, int sig,
simonis@6465 3373 siginfo_t *siginfo, void *context) {
goetz@6501 3374 // Call the old signal handler
goetz@6501 3375 if (actp->sa_handler == SIG_DFL) {
goetz@6501 3376 // It's more reasonable to let jvm treat it as an unexpected exception
goetz@6501 3377 // instead of taking the default action.
goetz@6501 3378 return false;
goetz@6501 3379 } else if (actp->sa_handler != SIG_IGN) {
goetz@6501 3380 if ((actp->sa_flags & SA_NODEFER) == 0) {
goetz@6501 3381 // automaticlly block the signal
goetz@6501 3382 sigaddset(&(actp->sa_mask), sig);
goetz@6501 3383 }
goetz@6501 3384
goetz@6501 3385 sa_handler_t hand = NULL;
goetz@6501 3386 sa_sigaction_t sa = NULL;
goetz@6501 3387 bool siginfo_flag_set = (actp->sa_flags & SA_SIGINFO) != 0;
goetz@6501 3388 // retrieve the chained handler
goetz@6501 3389 if (siginfo_flag_set) {
goetz@6501 3390 sa = actp->sa_sigaction;
goetz@6501 3391 } else {
goetz@6501 3392 hand = actp->sa_handler;
goetz@6501 3393 }
goetz@6501 3394
goetz@6501 3395 if ((actp->sa_flags & SA_RESETHAND) != 0) {
goetz@6501 3396 actp->sa_handler = SIG_DFL;
goetz@6501 3397 }
goetz@6501 3398
goetz@6501 3399 // try to honor the signal mask
goetz@6501 3400 sigset_t oset;
goetz@6501 3401 pthread_sigmask(SIG_SETMASK, &(actp->sa_mask), &oset);
goetz@6501 3402
goetz@6501 3403 // call into the chained handler
goetz@6501 3404 if (siginfo_flag_set) {
goetz@6501 3405 (*sa)(sig, siginfo, context);
goetz@6501 3406 } else {
goetz@6501 3407 (*hand)(sig);
goetz@6501 3408 }
goetz@6501 3409
goetz@6501 3410 // restore the signal mask
goetz@6501 3411 pthread_sigmask(SIG_SETMASK, &oset, 0);
goetz@6501 3412 }
goetz@6501 3413 // Tell jvm's signal handler the signal is taken care of.
simonis@6465 3414 return true;
simonis@6465 3415 }
simonis@6465 3416
simonis@6465 3417 bool os::Aix::chained_handler(int sig, siginfo_t* siginfo, void* context) {
simonis@6465 3418 bool chained = false;
simonis@6465 3419 // signal-chaining
simonis@6465 3420 if (UseSignalChaining) {
simonis@6465 3421 struct sigaction *actp = get_chained_signal_action(sig);
simonis@6465 3422 if (actp != NULL) {
simonis@6465 3423 chained = call_chained_handler(actp, sig, siginfo, context);
simonis@6465 3424 }
simonis@6465 3425 }
simonis@6465 3426 return chained;
simonis@6465 3427 }
simonis@6465 3428
simonis@6465 3429 struct sigaction* os::Aix::get_preinstalled_handler(int sig) {
simonis@6465 3430 if ((((unsigned int)1 << sig) & sigs) != 0) {
simonis@6465 3431 return &sigact[sig];
simonis@6465 3432 }
simonis@6465 3433 return NULL;
simonis@6465 3434 }
simonis@6465 3435
simonis@6465 3436 void os::Aix::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
simonis@6465 3437 assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
simonis@6465 3438 sigact[sig] = oldAct;
simonis@6465 3439 sigs |= (unsigned int)1 << sig;
simonis@6465 3440 }
simonis@6465 3441
simonis@6465 3442 // for diagnostic
simonis@6465 3443 int os::Aix::sigflags[MAXSIGNUM];
simonis@6465 3444
simonis@6465 3445 int os::Aix::get_our_sigflags(int sig) {
simonis@6465 3446 assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
simonis@6465 3447 return sigflags[sig];
simonis@6465 3448 }
simonis@6465 3449
simonis@6465 3450 void os::Aix::set_our_sigflags(int sig, int flags) {
simonis@6465 3451 assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
simonis@6465 3452 sigflags[sig] = flags;
simonis@6465 3453 }
simonis@6465 3454
simonis@6465 3455 void os::Aix::set_signal_handler(int sig, bool set_installed) {
simonis@6465 3456 // Check for overwrite.
simonis@6465 3457 struct sigaction oldAct;
simonis@6465 3458 sigaction(sig, (struct sigaction*)NULL, &oldAct);
simonis@6465 3459
simonis@6465 3460 void* oldhand = oldAct.sa_sigaction
simonis@6465 3461 ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
simonis@6465 3462 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
simonis@6465 3463 // Renamed 'signalHandler' to avoid collision with other shared libs.
simonis@6465 3464 if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) &&
simonis@6465 3465 oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) &&
simonis@6465 3466 oldhand != CAST_FROM_FN_PTR(void*, (sa_sigaction_t)javaSignalHandler)) {
simonis@6465 3467 if (AllowUserSignalHandlers || !set_installed) {
simonis@6465 3468 // Do not overwrite; user takes responsibility to forward to us.
simonis@6465 3469 return;
simonis@6465 3470 } else if (UseSignalChaining) {
simonis@6465 3471 // save the old handler in jvm
simonis@6465 3472 save_preinstalled_handler(sig, oldAct);
simonis@6465 3473 // libjsig also interposes the sigaction() call below and saves the
simonis@6465 3474 // old sigaction on it own.
simonis@6465 3475 } else {
simonis@6465 3476 fatal(err_msg("Encountered unexpected pre-existing sigaction handler "
simonis@6465 3477 "%#lx for signal %d.", (long)oldhand, sig));
simonis@6465 3478 }
simonis@6465 3479 }
simonis@6465 3480
simonis@6465 3481 struct sigaction sigAct;
simonis@6465 3482 sigfillset(&(sigAct.sa_mask));
simonis@6465 3483 if (!set_installed) {
simonis@6465 3484 sigAct.sa_handler = SIG_DFL;
simonis@6465 3485 sigAct.sa_flags = SA_RESTART;
simonis@6465 3486 } else {
simonis@6465 3487 // Renamed 'signalHandler' to avoid collision with other shared libs.
simonis@6465 3488 sigAct.sa_sigaction = javaSignalHandler;
simonis@6465 3489 sigAct.sa_flags = SA_SIGINFO|SA_RESTART;
simonis@6465 3490 }
simonis@6465 3491 // Save flags, which are set by ours
simonis@6465 3492 assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
simonis@6465 3493 sigflags[sig] = sigAct.sa_flags;
simonis@6465 3494
simonis@6465 3495 int ret = sigaction(sig, &sigAct, &oldAct);
simonis@6465 3496 assert(ret == 0, "check");
simonis@6465 3497
simonis@6465 3498 void* oldhand2 = oldAct.sa_sigaction
simonis@6465 3499 ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
simonis@6465 3500 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
simonis@6465 3501 assert(oldhand2 == oldhand, "no concurrent signal handler installation");
simonis@6465 3502 }
simonis@6465 3503
simonis@6465 3504 // install signal handlers for signals that HotSpot needs to
simonis@6465 3505 // handle in order to support Java-level exception handling.
simonis@6465 3506 void os::Aix::install_signal_handlers() {
simonis@6465 3507 if (!signal_handlers_are_installed) {
simonis@6465 3508 signal_handlers_are_installed = true;
simonis@6465 3509
simonis@6465 3510 // signal-chaining
simonis@6465 3511 typedef void (*signal_setting_t)();
simonis@6465 3512 signal_setting_t begin_signal_setting = NULL;
simonis@6465 3513 signal_setting_t end_signal_setting = NULL;
simonis@6465 3514 begin_signal_setting = CAST_TO_FN_PTR(signal_setting_t,
simonis@6465 3515 dlsym(RTLD_DEFAULT, "JVM_begin_signal_setting"));
simonis@6465 3516 if (begin_signal_setting != NULL) {
simonis@6465 3517 end_signal_setting = CAST_TO_FN_PTR(signal_setting_t,
simonis@6465 3518 dlsym(RTLD_DEFAULT, "JVM_end_signal_setting"));
simonis@6465 3519 get_signal_action = CAST_TO_FN_PTR(get_signal_t,
simonis@6465 3520 dlsym(RTLD_DEFAULT, "JVM_get_signal_action"));
simonis@6465 3521 libjsig_is_loaded = true;
simonis@6465 3522 assert(UseSignalChaining, "should enable signal-chaining");
simonis@6465 3523 }
simonis@6465 3524 if (libjsig_is_loaded) {
simonis@6465 3525 // Tell libjsig jvm is setting signal handlers
simonis@6465 3526 (*begin_signal_setting)();
simonis@6465 3527 }
simonis@6465 3528
simonis@6465 3529 set_signal_handler(SIGSEGV, true);
simonis@6465 3530 set_signal_handler(SIGPIPE, true);
simonis@6465 3531 set_signal_handler(SIGBUS, true);
simonis@6465 3532 set_signal_handler(SIGILL, true);
simonis@6465 3533 set_signal_handler(SIGFPE, true);
simonis@6465 3534 set_signal_handler(SIGTRAP, true);
simonis@6465 3535 set_signal_handler(SIGXFSZ, true);
simonis@6465 3536 set_signal_handler(SIGDANGER, true);
simonis@6465 3537
simonis@6465 3538 if (libjsig_is_loaded) {
simonis@6465 3539 // Tell libjsig jvm finishes setting signal handlers
simonis@6465 3540 (*end_signal_setting)();
simonis@6465 3541 }
simonis@6465 3542
simonis@6465 3543 // We don't activate signal checker if libjsig is in place, we trust ourselves
simonis@6465 3544 // and if UserSignalHandler is installed all bets are off.
simonis@6465 3545 // Log that signal checking is off only if -verbose:jni is specified.
simonis@6465 3546 if (CheckJNICalls) {
simonis@6465 3547 if (libjsig_is_loaded) {
simonis@6465 3548 tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
simonis@6465 3549 check_signals = false;
simonis@6465 3550 }
simonis@6465 3551 if (AllowUserSignalHandlers) {
simonis@6465 3552 tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
simonis@6465 3553 check_signals = false;
simonis@6465 3554 }
simonis@6465 3555 // need to initialize check_signal_done
simonis@6465 3556 ::sigemptyset(&check_signal_done);
simonis@6465 3557 }
simonis@6465 3558 }
simonis@6465 3559 }
simonis@6465 3560
simonis@6465 3561 static const char* get_signal_handler_name(address handler,
simonis@6465 3562 char* buf, int buflen) {
simonis@6465 3563 int offset;
simonis@6465 3564 bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
simonis@6465 3565 if (found) {
simonis@6465 3566 // skip directory names
simonis@6465 3567 const char *p1, *p2;
simonis@6465 3568 p1 = buf;
simonis@6465 3569 size_t len = strlen(os::file_separator());
simonis@6465 3570 while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
simonis@6465 3571 // The way os::dll_address_to_library_name is implemented on Aix
simonis@6465 3572 // right now, it always returns -1 for the offset which is not
simonis@6465 3573 // terribly informative.
simonis@6465 3574 // Will fix that. For now, omit the offset.
simonis@6465 3575 jio_snprintf(buf, buflen, "%s", p1);
simonis@6465 3576 } else {
simonis@6465 3577 jio_snprintf(buf, buflen, PTR_FORMAT, handler);
simonis@6465 3578 }
simonis@6465 3579 return buf;
simonis@6465 3580 }
simonis@6465 3581
simonis@6465 3582 static void print_signal_handler(outputStream* st, int sig,
simonis@6465 3583 char* buf, size_t buflen) {
simonis@6465 3584 struct sigaction sa;
simonis@6465 3585 sigaction(sig, NULL, &sa);
simonis@6465 3586
simonis@6465 3587 st->print("%s: ", os::exception_name(sig, buf, buflen));
simonis@6465 3588
simonis@6465 3589 address handler = (sa.sa_flags & SA_SIGINFO)
simonis@6465 3590 ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
simonis@6465 3591 : CAST_FROM_FN_PTR(address, sa.sa_handler);
simonis@6465 3592
simonis@6465 3593 if (handler == CAST_FROM_FN_PTR(address, SIG_DFL)) {
simonis@6465 3594 st->print("SIG_DFL");
simonis@6465 3595 } else if (handler == CAST_FROM_FN_PTR(address, SIG_IGN)) {
simonis@6465 3596 st->print("SIG_IGN");
simonis@6465 3597 } else {
simonis@6465 3598 st->print("[%s]", get_signal_handler_name(handler, buf, buflen));
simonis@6465 3599 }
simonis@6465 3600
simonis@6465 3601 // Print readable mask.
simonis@6465 3602 st->print(", sa_mask[0]=");
simonis@6465 3603 os::Posix::print_signal_set_short(st, &sa.sa_mask);
simonis@6465 3604
simonis@6465 3605 address rh = VMError::get_resetted_sighandler(sig);
simonis@6465 3606 // May be, handler was resetted by VMError?
simonis@6465 3607 if (rh != NULL) {
simonis@6465 3608 handler = rh;
simonis@6465 3609 sa.sa_flags = VMError::get_resetted_sigflags(sig);
simonis@6465 3610 }
simonis@6465 3611
simonis@6465 3612 // Print textual representation of sa_flags.
simonis@6465 3613 st->print(", sa_flags=");
simonis@6465 3614 os::Posix::print_sa_flags(st, sa.sa_flags);
simonis@6465 3615
simonis@6465 3616 // Check: is it our handler?
simonis@6465 3617 if (handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)javaSignalHandler) ||
simonis@6465 3618 handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
simonis@6465 3619 // It is our signal handler.
simonis@6465 3620 // Check for flags, reset system-used one!
simonis@6465 3621 if ((int)sa.sa_flags != os::Aix::get_our_sigflags(sig)) {
simonis@6465 3622 st->print(", flags was changed from " PTR32_FORMAT ", consider using jsig library",
simonis@6465 3623 os::Aix::get_our_sigflags(sig));
simonis@6465 3624 }
simonis@6465 3625 }
simonis@6465 3626 st->cr();
simonis@6465 3627 }
simonis@6465 3628
simonis@6465 3629
simonis@6465 3630 #define DO_SIGNAL_CHECK(sig) \
simonis@6465 3631 if (!sigismember(&check_signal_done, sig)) \
simonis@6465 3632 os::Aix::check_signal_handler(sig)
simonis@6465 3633
simonis@6465 3634 // This method is a periodic task to check for misbehaving JNI applications
simonis@6465 3635 // under CheckJNI, we can add any periodic checks here
simonis@6465 3636
simonis@6465 3637 void os::run_periodic_checks() {
simonis@6465 3638
simonis@6465 3639 if (check_signals == false) return;
simonis@6465 3640
simonis@6465 3641 // SEGV and BUS if overridden could potentially prevent
simonis@6465 3642 // generation of hs*.log in the event of a crash, debugging
simonis@6465 3643 // such a case can be very challenging, so we absolutely
simonis@6465 3644 // check the following for a good measure:
simonis@6465 3645 DO_SIGNAL_CHECK(SIGSEGV);
simonis@6465 3646 DO_SIGNAL_CHECK(SIGILL);
simonis@6465 3647 DO_SIGNAL_CHECK(SIGFPE);
simonis@6465 3648 DO_SIGNAL_CHECK(SIGBUS);
simonis@6465 3649 DO_SIGNAL_CHECK(SIGPIPE);
simonis@6465 3650 DO_SIGNAL_CHECK(SIGXFSZ);
simonis@6465 3651 if (UseSIGTRAP) {
simonis@6465 3652 DO_SIGNAL_CHECK(SIGTRAP);
simonis@6465 3653 }
simonis@6465 3654 DO_SIGNAL_CHECK(SIGDANGER);
simonis@6465 3655
simonis@6465 3656 // ReduceSignalUsage allows the user to override these handlers
simonis@6465 3657 // see comments at the very top and jvm_solaris.h
simonis@6465 3658 if (!ReduceSignalUsage) {
simonis@6465 3659 DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL);
simonis@6465 3660 DO_SIGNAL_CHECK(SHUTDOWN2_SIGNAL);
simonis@6465 3661 DO_SIGNAL_CHECK(SHUTDOWN3_SIGNAL);
simonis@6465 3662 DO_SIGNAL_CHECK(BREAK_SIGNAL);
simonis@6465 3663 }
simonis@6465 3664
simonis@6465 3665 DO_SIGNAL_CHECK(SR_signum);
simonis@6465 3666 DO_SIGNAL_CHECK(INTERRUPT_SIGNAL);
simonis@6465 3667 }
simonis@6465 3668
simonis@6465 3669 typedef int (*os_sigaction_t)(int, const struct sigaction *, struct sigaction *);
simonis@6465 3670
simonis@6465 3671 static os_sigaction_t os_sigaction = NULL;
simonis@6465 3672
simonis@6465 3673 void os::Aix::check_signal_handler(int sig) {
simonis@6465 3674 char buf[O_BUFLEN];
simonis@6465 3675 address jvmHandler = NULL;
simonis@6465 3676
simonis@6465 3677 struct sigaction act;
simonis@6465 3678 if (os_sigaction == NULL) {
simonis@6465 3679 // only trust the default sigaction, in case it has been interposed
simonis@6465 3680 os_sigaction = (os_sigaction_t)dlsym(RTLD_DEFAULT, "sigaction");
simonis@6465 3681 if (os_sigaction == NULL) return;
simonis@6465 3682 }
simonis@6465 3683
simonis@6465 3684 os_sigaction(sig, (struct sigaction*)NULL, &act);
simonis@6465 3685
simonis@6465 3686 address thisHandler = (act.sa_flags & SA_SIGINFO)
simonis@6465 3687 ? CAST_FROM_FN_PTR(address, act.sa_sigaction)
simonis@6465 3688 : CAST_FROM_FN_PTR(address, act.sa_handler);
simonis@6465 3689
simonis@6465 3690
simonis@6465 3691 switch(sig) {
simonis@6465 3692 case SIGSEGV:
simonis@6465 3693 case SIGBUS:
simonis@6465 3694 case SIGFPE:
simonis@6465 3695 case SIGPIPE:
simonis@6465 3696 case SIGILL:
simonis@6465 3697 case SIGXFSZ:
simonis@6465 3698 // Renamed 'signalHandler' to avoid collision with other shared libs.
simonis@6465 3699 jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)javaSignalHandler);
simonis@6465 3700 break;
simonis@6465 3701
simonis@6465 3702 case SHUTDOWN1_SIGNAL:
simonis@6465 3703 case SHUTDOWN2_SIGNAL:
simonis@6465 3704 case SHUTDOWN3_SIGNAL:
simonis@6465 3705 case BREAK_SIGNAL:
simonis@6465 3706 jvmHandler = (address)user_handler();
simonis@6465 3707 break;
simonis@6465 3708
simonis@6465 3709 case INTERRUPT_SIGNAL:
simonis@6465 3710 jvmHandler = CAST_FROM_FN_PTR(address, SIG_DFL);
simonis@6465 3711 break;
simonis@6465 3712
simonis@6465 3713 default:
simonis@6465 3714 if (sig == SR_signum) {
simonis@6465 3715 jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler);
simonis@6465 3716 } else {
simonis@6465 3717 return;
simonis@6465 3718 }
simonis@6465 3719 break;
simonis@6465 3720 }
simonis@6465 3721
simonis@6465 3722 if (thisHandler != jvmHandler) {
simonis@6465 3723 tty->print("Warning: %s handler ", exception_name(sig, buf, O_BUFLEN));
simonis@6465 3724 tty->print("expected:%s", get_signal_handler_name(jvmHandler, buf, O_BUFLEN));
simonis@6465 3725 tty->print_cr(" found:%s", get_signal_handler_name(thisHandler, buf, O_BUFLEN));
simonis@6465 3726 // No need to check this sig any longer
simonis@6465 3727 sigaddset(&check_signal_done, sig);
simonis@6465 3728 } else if (os::Aix::get_our_sigflags(sig) != 0 && (int)act.sa_flags != os::Aix::get_our_sigflags(sig)) {
simonis@6465 3729 tty->print("Warning: %s handler flags ", exception_name(sig, buf, O_BUFLEN));
simonis@6465 3730 tty->print("expected:" PTR32_FORMAT, os::Aix::get_our_sigflags(sig));
simonis@6465 3731 tty->print_cr(" found:" PTR32_FORMAT, act.sa_flags);
simonis@6465 3732 // No need to check this sig any longer
simonis@6465 3733 sigaddset(&check_signal_done, sig);
simonis@6465 3734 }
simonis@6465 3735
simonis@6465 3736 // Dump all the signal
simonis@6465 3737 if (sigismember(&check_signal_done, sig)) {
simonis@6465 3738 print_signal_handlers(tty, buf, O_BUFLEN);
simonis@6465 3739 }
simonis@6465 3740 }
simonis@6465 3741
simonis@6465 3742 extern bool signal_name(int signo, char* buf, size_t len);
simonis@6465 3743
simonis@6465 3744 const char* os::exception_name(int exception_code, char* buf, size_t size) {
simonis@6465 3745 if (0 < exception_code && exception_code <= SIGRTMAX) {
simonis@6465 3746 // signal
simonis@6465 3747 if (!signal_name(exception_code, buf, size)) {
simonis@6465 3748 jio_snprintf(buf, size, "SIG%d", exception_code);
simonis@6465 3749 }
simonis@6465 3750 return buf;
simonis@6465 3751 } else {
simonis@6465 3752 return NULL;
simonis@6465 3753 }
simonis@6465 3754 }
simonis@6465 3755
simonis@6465 3756 // To install functions for atexit system call
simonis@6465 3757 extern "C" {
simonis@6465 3758 static void perfMemory_exit_helper() {
simonis@6465 3759 perfMemory_exit();
simonis@6465 3760 }
simonis@6465 3761 }
simonis@6465 3762
simonis@6465 3763 // This is called _before_ the most of global arguments have been parsed.
simonis@6465 3764 void os::init(void) {
simonis@6465 3765 // This is basic, we want to know if that ever changes.
simonis@6465 3766 // (shared memory boundary is supposed to be a 256M aligned)
simonis@6465 3767 assert(SHMLBA == ((uint64_t)0x10000000ULL)/*256M*/, "unexpected");
simonis@6465 3768
simonis@6465 3769 // First off, we need to know whether we run on AIX or PASE, and
simonis@6465 3770 // the OS level we run on.
simonis@6465 3771 os::Aix::initialize_os_info();
simonis@6465 3772
simonis@6465 3773 // Scan environment (SPEC1170 behaviour, etc)
simonis@6465 3774 os::Aix::scan_environment();
simonis@6465 3775
simonis@6465 3776 // Check which pages are supported by AIX.
simonis@6465 3777 os::Aix::query_multipage_support();
simonis@6465 3778
simonis@6465 3779 // Next, we need to initialize libo4 and libperfstat libraries.
simonis@6465 3780 if (os::Aix::on_pase()) {
simonis@6465 3781 os::Aix::initialize_libo4();
simonis@6465 3782 } else {
simonis@6465 3783 os::Aix::initialize_libperfstat();
simonis@6465 3784 }
simonis@6465 3785
simonis@6465 3786 // Reset the perfstat information provided by ODM.
simonis@6465 3787 if (os::Aix::on_aix()) {
simonis@6465 3788 libperfstat::perfstat_reset();
simonis@6465 3789 }
simonis@6465 3790
simonis@6465 3791 // Now initialze basic system properties. Note that for some of the values we
simonis@6465 3792 // need libperfstat etc.
simonis@6465 3793 os::Aix::initialize_system_info();
simonis@6465 3794
simonis@6465 3795 // Initialize large page support.
simonis@6465 3796 if (UseLargePages) {
simonis@6465 3797 os::large_page_init();
simonis@6465 3798 if (!UseLargePages) {
simonis@6465 3799 // initialize os::_page_sizes
simonis@6465 3800 _page_sizes[0] = Aix::page_size();
simonis@6465 3801 _page_sizes[1] = 0;
simonis@6465 3802 if (Verbose) {
simonis@6465 3803 fprintf(stderr, "Large Page initialization failed: setting UseLargePages=0.\n");
simonis@6465 3804 }
simonis@6465 3805 }
simonis@6465 3806 } else {
simonis@6465 3807 // initialize os::_page_sizes
simonis@6465 3808 _page_sizes[0] = Aix::page_size();
simonis@6465 3809 _page_sizes[1] = 0;
simonis@6465 3810 }
simonis@6465 3811
simonis@6465 3812 // debug trace
simonis@6465 3813 if (Verbose) {
simonis@6465 3814 fprintf(stderr, "os::vm_page_size 0x%llX\n", os::vm_page_size());
simonis@6465 3815 fprintf(stderr, "os::large_page_size 0x%llX\n", os::large_page_size());
simonis@6465 3816 fprintf(stderr, "os::_page_sizes = ( ");
simonis@6465 3817 for (int i = 0; _page_sizes[i]; i ++) {
simonis@6465 3818 fprintf(stderr, " %s ", describe_pagesize(_page_sizes[i]));
simonis@6465 3819 }
simonis@6465 3820 fprintf(stderr, ")\n");
simonis@6465 3821 }
simonis@6465 3822
simonis@6465 3823 _initial_pid = getpid();
simonis@6465 3824
simonis@6465 3825 clock_tics_per_sec = sysconf(_SC_CLK_TCK);
simonis@6465 3826
simonis@6465 3827 init_random(1234567);
simonis@6465 3828
simonis@6465 3829 ThreadCritical::initialize();
simonis@6465 3830
simonis@6465 3831 // Main_thread points to the aboriginal thread.
simonis@6465 3832 Aix::_main_thread = pthread_self();
simonis@6465 3833
simonis@6465 3834 initial_time_count = os::elapsed_counter();
simonis@6465 3835 pthread_mutex_init(&dl_mutex, NULL);
simonis@6465 3836 }
simonis@6465 3837
simonis@6465 3838 // this is called _after_ the global arguments have been parsed
simonis@6465 3839 jint os::init_2(void) {
simonis@6465 3840
simonis@6465 3841 if (Verbose) {
simonis@6465 3842 fprintf(stderr, "processor count: %d\n", os::_processor_count);
simonis@6465 3843 fprintf(stderr, "physical memory: %lu\n", Aix::_physical_memory);
simonis@6465 3844 }
simonis@6465 3845
simonis@6465 3846 // initially build up the loaded dll map
simonis@6465 3847 LoadedLibraries::reload();
simonis@6465 3848
simonis@6465 3849 const int page_size = Aix::page_size();
simonis@6465 3850 const int map_size = page_size;
simonis@6465 3851
simonis@6465 3852 address map_address = (address) MAP_FAILED;
simonis@6465 3853 const int prot = PROT_READ;
simonis@6465 3854 const int flags = MAP_PRIVATE|MAP_ANONYMOUS;
simonis@6465 3855
simonis@6465 3856 // use optimized addresses for the polling page,
simonis@6465 3857 // e.g. map it to a special 32-bit address.
simonis@6465 3858 if (OptimizePollingPageLocation) {
simonis@6465 3859 // architecture-specific list of address wishes:
simonis@6465 3860 address address_wishes[] = {
simonis@6465 3861 // AIX: addresses lower than 0x30000000 don't seem to work on AIX.
simonis@6465 3862 // PPC64: all address wishes are non-negative 32 bit values where
simonis@6465 3863 // the lower 16 bits are all zero. we can load these addresses
simonis@6465 3864 // with a single ppc_lis instruction.
simonis@6465 3865 (address) 0x30000000, (address) 0x31000000,
simonis@6465 3866 (address) 0x32000000, (address) 0x33000000,
simonis@6465 3867 (address) 0x40000000, (address) 0x41000000,
simonis@6465 3868 (address) 0x42000000, (address) 0x43000000,
simonis@6465 3869 (address) 0x50000000, (address) 0x51000000,
simonis@6465 3870 (address) 0x52000000, (address) 0x53000000,
simonis@6465 3871 (address) 0x60000000, (address) 0x61000000,
simonis@6465 3872 (address) 0x62000000, (address) 0x63000000
simonis@6465 3873 };
simonis@6465 3874 int address_wishes_length = sizeof(address_wishes)/sizeof(address);
simonis@6465 3875
simonis@6465 3876 // iterate over the list of address wishes:
simonis@6465 3877 for (int i=0; i<address_wishes_length; i++) {
simonis@6465 3878 // try to map with current address wish.
simonis@6465 3879 // AIX: AIX needs MAP_FIXED if we provide an address and mmap will
simonis@6465 3880 // fail if the address is already mapped.
simonis@6465 3881 map_address = (address) ::mmap(address_wishes[i] - (ssize_t)page_size,
simonis@6465 3882 map_size, prot,
simonis@6465 3883 flags | MAP_FIXED,
simonis@6465 3884 -1, 0);
simonis@6465 3885 if (Verbose) {
simonis@6465 3886 fprintf(stderr, "SafePoint Polling Page address: %p (wish) => %p\n",
simonis@6465 3887 address_wishes[i], map_address + (ssize_t)page_size);
simonis@6465 3888 }
simonis@6465 3889
simonis@6465 3890 if (map_address + (ssize_t)page_size == address_wishes[i]) {
simonis@6465 3891 // map succeeded and map_address is at wished address, exit loop.
simonis@6465 3892 break;
simonis@6465 3893 }
simonis@6465 3894
simonis@6465 3895 if (map_address != (address) MAP_FAILED) {
simonis@6465 3896 // map succeeded, but polling_page is not at wished address, unmap and continue.
simonis@6465 3897 ::munmap(map_address, map_size);
simonis@6465 3898 map_address = (address) MAP_FAILED;
simonis@6465 3899 }
simonis@6465 3900 // map failed, continue loop.
simonis@6465 3901 }
simonis@6465 3902 } // end OptimizePollingPageLocation
simonis@6465 3903
simonis@6465 3904 if (map_address == (address) MAP_FAILED) {
simonis@6465 3905 map_address = (address) ::mmap(NULL, map_size, prot, flags, -1, 0);
simonis@6465 3906 }
simonis@6465 3907 guarantee(map_address != MAP_FAILED, "os::init_2: failed to allocate polling page");
simonis@6465 3908 os::set_polling_page(map_address);
simonis@6465 3909
simonis@6465 3910 if (!UseMembar) {
simonis@6465 3911 address mem_serialize_page = (address) ::mmap(NULL, Aix::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
simonis@6465 3912 guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
simonis@6465 3913 os::set_memory_serialize_page(mem_serialize_page);
simonis@6465 3914
simonis@6465 3915 #ifndef PRODUCT
simonis@6465 3916 if (Verbose && PrintMiscellaneous)
simonis@6465 3917 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page);
simonis@6465 3918 #endif
simonis@6465 3919 }
simonis@6465 3920
simonis@6465 3921 // initialize suspend/resume support - must do this before signal_sets_init()
simonis@6465 3922 if (SR_initialize() != 0) {
simonis@6465 3923 perror("SR_initialize failed");
simonis@6465 3924 return JNI_ERR;
simonis@6465 3925 }
simonis@6465 3926
simonis@6465 3927 Aix::signal_sets_init();
simonis@6465 3928 Aix::install_signal_handlers();
simonis@6465 3929
simonis@6465 3930 // Check minimum allowable stack size for thread creation and to initialize
simonis@6465 3931 // the java system classes, including StackOverflowError - depends on page
simonis@6465 3932 // size. Add a page for compiler2 recursion in main thread.
simonis@6465 3933 // Add in 2*BytesPerWord times page size to account for VM stack during
simonis@6465 3934 // class initialization depending on 32 or 64 bit VM.
simonis@6465 3935 os::Aix::min_stack_allowed = MAX2(os::Aix::min_stack_allowed,
simonis@6465 3936 (size_t)(StackYellowPages+StackRedPages+StackShadowPages +
simonis@6465 3937 2*BytesPerWord COMPILER2_PRESENT(+1)) * Aix::page_size());
simonis@6465 3938
simonis@6465 3939 size_t threadStackSizeInBytes = ThreadStackSize * K;
simonis@6465 3940 if (threadStackSizeInBytes != 0 &&
simonis@6465 3941 threadStackSizeInBytes < os::Aix::min_stack_allowed) {
simonis@6465 3942 tty->print_cr("\nThe stack size specified is too small, "
simonis@6465 3943 "Specify at least %dk",
simonis@6465 3944 os::Aix::min_stack_allowed / K);
simonis@6465 3945 return JNI_ERR;
simonis@6465 3946 }
simonis@6465 3947
simonis@6465 3948 // Make the stack size a multiple of the page size so that
simonis@6465 3949 // the yellow/red zones can be guarded.
simonis@6465 3950 // note that this can be 0, if no default stacksize was set
simonis@6465 3951 JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes, vm_page_size()));
simonis@6465 3952
simonis@6465 3953 Aix::libpthread_init();
simonis@6465 3954
simonis@6465 3955 if (MaxFDLimit) {
simonis@6465 3956 // set the number of file descriptors to max. print out error
simonis@6465 3957 // if getrlimit/setrlimit fails but continue regardless.
simonis@6465 3958 struct rlimit nbr_files;
simonis@6465 3959 int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
simonis@6465 3960 if (status != 0) {
simonis@6465 3961 if (PrintMiscellaneous && (Verbose || WizardMode))
simonis@6465 3962 perror("os::init_2 getrlimit failed");
simonis@6465 3963 } else {
simonis@6465 3964 nbr_files.rlim_cur = nbr_files.rlim_max;
simonis@6465 3965 status = setrlimit(RLIMIT_NOFILE, &nbr_files);
simonis@6465 3966 if (status != 0) {
simonis@6465 3967 if (PrintMiscellaneous && (Verbose || WizardMode))
simonis@6465 3968 perror("os::init_2 setrlimit failed");
simonis@6465 3969 }
simonis@6465 3970 }
simonis@6465 3971 }
simonis@6465 3972
simonis@6465 3973 if (PerfAllowAtExitRegistration) {
simonis@6465 3974 // only register atexit functions if PerfAllowAtExitRegistration is set.
simonis@6465 3975 // atexit functions can be delayed until process exit time, which
simonis@6465 3976 // can be problematic for embedded VM situations. Embedded VMs should
simonis@6465 3977 // call DestroyJavaVM() to assure that VM resources are released.
simonis@6465 3978
simonis@6465 3979 // note: perfMemory_exit_helper atexit function may be removed in
simonis@6465 3980 // the future if the appropriate cleanup code can be added to the
simonis@6465 3981 // VM_Exit VMOperation's doit method.
simonis@6465 3982 if (atexit(perfMemory_exit_helper) != 0) {
simonis@6465 3983 warning("os::init_2 atexit(perfMemory_exit_helper) failed");
simonis@6465 3984 }
simonis@6465 3985 }
simonis@6465 3986
simonis@6465 3987 return JNI_OK;
simonis@6465 3988 }
simonis@6465 3989
simonis@6465 3990 // this is called at the end of vm_initialization
simonis@6465 3991 void os::init_3(void) {
simonis@6465 3992 return;
simonis@6465 3993 }
simonis@6465 3994
simonis@6465 3995 // Mark the polling page as unreadable
simonis@6465 3996 void os::make_polling_page_unreadable(void) {
simonis@6465 3997 if (!guard_memory((char*)_polling_page, Aix::page_size())) {
simonis@6465 3998 fatal("Could not disable polling page");
simonis@6465 3999 }
simonis@6465 4000 };
simonis@6465 4001
simonis@6465 4002 // Mark the polling page as readable
simonis@6465 4003 void os::make_polling_page_readable(void) {
simonis@6465 4004 // Changed according to os_linux.cpp.
simonis@6465 4005 if (!checked_mprotect((char *)_polling_page, Aix::page_size(), PROT_READ)) {
simonis@6465 4006 fatal(err_msg("Could not enable polling page at " PTR_FORMAT, _polling_page));
simonis@6465 4007 }
simonis@6465 4008 };
simonis@6465 4009
simonis@6465 4010 int os::active_processor_count() {
simonis@6465 4011 int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
simonis@6465 4012 assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
simonis@6465 4013 return online_cpus;
simonis@6465 4014 }
simonis@6465 4015
simonis@6465 4016 void os::set_native_thread_name(const char *name) {
simonis@6465 4017 // Not yet implemented.
simonis@6465 4018 return;
simonis@6465 4019 }
simonis@6465 4020
simonis@6465 4021 bool os::distribute_processes(uint length, uint* distribution) {
simonis@6465 4022 // Not yet implemented.
simonis@6465 4023 return false;
simonis@6465 4024 }
simonis@6465 4025
simonis@6465 4026 bool os::bind_to_processor(uint processor_id) {
simonis@6465 4027 // Not yet implemented.
simonis@6465 4028 return false;
simonis@6465 4029 }
simonis@6465 4030
simonis@6465 4031 void os::SuspendedThreadTask::internal_do_task() {
simonis@6465 4032 if (do_suspend(_thread->osthread())) {
simonis@6465 4033 SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext());
simonis@6465 4034 do_task(context);
simonis@6465 4035 do_resume(_thread->osthread());
simonis@6465 4036 }
simonis@6465 4037 }
simonis@6465 4038
simonis@6465 4039 class PcFetcher : public os::SuspendedThreadTask {
simonis@6465 4040 public:
simonis@6465 4041 PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {}
simonis@6465 4042 ExtendedPC result();
simonis@6465 4043 protected:
simonis@6465 4044 void do_task(const os::SuspendedThreadTaskContext& context);
simonis@6465 4045 private:
simonis@6465 4046 ExtendedPC _epc;
simonis@6465 4047 };
simonis@6465 4048
simonis@6465 4049 ExtendedPC PcFetcher::result() {
simonis@6465 4050 guarantee(is_done(), "task is not done yet.");
simonis@6465 4051 return _epc;
simonis@6465 4052 }
simonis@6465 4053
simonis@6465 4054 void PcFetcher::do_task(const os::SuspendedThreadTaskContext& context) {
simonis@6465 4055 Thread* thread = context.thread();
simonis@6465 4056 OSThread* osthread = thread->osthread();
simonis@6465 4057 if (osthread->ucontext() != NULL) {
simonis@6465 4058 _epc = os::Aix::ucontext_get_pc((ucontext_t *) context.ucontext());
simonis@6465 4059 } else {
simonis@6465 4060 // NULL context is unexpected, double-check this is the VMThread.
simonis@6465 4061 guarantee(thread->is_VM_thread(), "can only be called for VMThread");
simonis@6465 4062 }
simonis@6465 4063 }
simonis@6465 4064
simonis@6465 4065 // Suspends the target using the signal mechanism and then grabs the PC before
simonis@6465 4066 // resuming the target. Used by the flat-profiler only
simonis@6465 4067 ExtendedPC os::get_thread_pc(Thread* thread) {
simonis@6465 4068 // Make sure that it is called by the watcher for the VMThread.
simonis@6465 4069 assert(Thread::current()->is_Watcher_thread(), "Must be watcher");
simonis@6465 4070 assert(thread->is_VM_thread(), "Can only be called for VMThread");
simonis@6465 4071
simonis@6465 4072 PcFetcher fetcher(thread);
simonis@6465 4073 fetcher.run();
simonis@6465 4074 return fetcher.result();
simonis@6465 4075 }
simonis@6465 4076
simonis@6465 4077 // Not neede on Aix.
simonis@6465 4078 // int os::Aix::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime) {
simonis@6465 4079 // }
simonis@6465 4080
simonis@6465 4081 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 4082 // debug support
simonis@6465 4083
simonis@6465 4084 static address same_page(address x, address y) {
simonis@6465 4085 intptr_t page_bits = -os::vm_page_size();
simonis@6465 4086 if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits))
simonis@6465 4087 return x;
simonis@6465 4088 else if (x > y)
simonis@6465 4089 return (address)(intptr_t(y) | ~page_bits) + 1;
simonis@6465 4090 else
simonis@6465 4091 return (address)(intptr_t(y) & page_bits);
simonis@6465 4092 }
simonis@6465 4093
simonis@6465 4094 bool os::find(address addr, outputStream* st) {
goetz@6501 4095
goetz@6501 4096 st->print(PTR_FORMAT ": ", addr);
goetz@6501 4097
goetz@6501 4098 const LoadedLibraryModule* lib = LoadedLibraries::find_for_text_address(addr);
goetz@6501 4099 if (lib) {
goetz@6501 4100 lib->print(st);
goetz@6501 4101 return true;
goetz@6501 4102 } else {
goetz@6501 4103 lib = LoadedLibraries::find_for_data_address(addr);
goetz@6501 4104 if (lib) {
goetz@6501 4105 lib->print(st);
goetz@6501 4106 return true;
goetz@6501 4107 } else {
goetz@6501 4108 st->print_cr("(outside any module)");
goetz@6501 4109 }
goetz@6501 4110 }
goetz@6501 4111
simonis@6465 4112 return false;
simonis@6465 4113 }
simonis@6465 4114
simonis@6465 4115 ////////////////////////////////////////////////////////////////////////////////
simonis@6465 4116 // misc
simonis@6465 4117
simonis@6465 4118 // This does not do anything on Aix. This is basically a hook for being
simonis@6465 4119 // able to use structured exception handling (thread-local exception filters)
simonis@6465 4120 // on, e.g., Win32.
simonis@6465 4121 void
simonis@6465 4122 os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method,
simonis@6465 4123 JavaCallArguments* args, Thread* thread) {
simonis@6465 4124 f(value, method, args, thread);
simonis@6465 4125 }
simonis@6465 4126
simonis@6465 4127 void os::print_statistics() {
simonis@6465 4128 }
simonis@6465 4129
simonis@6465 4130 int os::message_box(const char* title, const char* message) {
simonis@6465 4131 int i;
simonis@6465 4132 fdStream err(defaultStream::error_fd());
simonis@6465 4133 for (i = 0; i < 78; i++) err.print_raw("=");
simonis@6465 4134 err.cr();
simonis@6465 4135 err.print_raw_cr(title);
simonis@6465 4136 for (i = 0; i < 78; i++) err.print_raw("-");
simonis@6465 4137 err.cr();
simonis@6465 4138 err.print_raw_cr(message);
simonis@6465 4139 for (i = 0; i < 78; i++) err.print_raw("=");
simonis@6465 4140 err.cr();
simonis@6465 4141
simonis@6465 4142 char buf[16];
simonis@6465 4143 // Prevent process from exiting upon "read error" without consuming all CPU
simonis@6465 4144 while (::read(0, buf, sizeof(buf)) <= 0) { ::sleep(100); }
simonis@6465 4145
simonis@6465 4146 return buf[0] == 'y' || buf[0] == 'Y';
simonis@6465 4147 }
simonis@6465 4148
simonis@6465 4149 int os::stat(const char *path, struct stat *sbuf) {
simonis@6465 4150 char pathbuf[MAX_PATH];
simonis@6465 4151 if (strlen(path) > MAX_PATH - 1) {
simonis@6465 4152 errno = ENAMETOOLONG;
simonis@6465 4153 return -1;
simonis@6465 4154 }
simonis@6465 4155 os::native_path(strcpy(pathbuf, path));
simonis@6465 4156 return ::stat(pathbuf, sbuf);
simonis@6465 4157 }
simonis@6465 4158
simonis@6465 4159 bool os::check_heap(bool force) {
simonis@6465 4160 return true;
simonis@6465 4161 }
simonis@6465 4162
simonis@6465 4163 // int local_vsnprintf(char* buf, size_t count, const char* format, va_list args) {
simonis@6465 4164 // return ::vsnprintf(buf, count, format, args);
simonis@6465 4165 // }
simonis@6465 4166
simonis@6465 4167 // Is a (classpath) directory empty?
simonis@6465 4168 bool os::dir_is_empty(const char* path) {
goetz@6501 4169 DIR *dir = NULL;
goetz@6501 4170 struct dirent *ptr;
goetz@6501 4171
goetz@6501 4172 dir = opendir(path);
goetz@6501 4173 if (dir == NULL) return true;
goetz@6501 4174
goetz@6501 4175 /* Scan the directory */
goetz@6501 4176 bool result = true;
goetz@6501 4177 char buf[sizeof(struct dirent) + MAX_PATH];
goetz@6501 4178 while (result && (ptr = ::readdir(dir)) != NULL) {
goetz@6501 4179 if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
goetz@6501 4180 result = false;
goetz@6501 4181 }
goetz@6501 4182 }
goetz@6501 4183 closedir(dir);
goetz@6501 4184 return result;
simonis@6465 4185 }
simonis@6465 4186
simonis@6465 4187 // This code originates from JDK's sysOpen and open64_w
simonis@6465 4188 // from src/solaris/hpi/src/system_md.c
simonis@6465 4189
simonis@6465 4190 #ifndef O_DELETE
simonis@6465 4191 #define O_DELETE 0x10000
simonis@6465 4192 #endif
simonis@6465 4193
simonis@6465 4194 // Open a file. Unlink the file immediately after open returns
simonis@6465 4195 // if the specified oflag has the O_DELETE flag set.
simonis@6465 4196 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
simonis@6465 4197
simonis@6465 4198 int os::open(const char *path, int oflag, int mode) {
simonis@6465 4199
simonis@6465 4200 if (strlen(path) > MAX_PATH - 1) {
simonis@6465 4201 errno = ENAMETOOLONG;
simonis@6465 4202 return -1;
simonis@6465 4203 }
simonis@6465 4204 int fd;
simonis@6465 4205 int o_delete = (oflag & O_DELETE);
simonis@6465 4206 oflag = oflag & ~O_DELETE;
simonis@6465 4207
simonis@6465 4208 fd = ::open64(path, oflag, mode);
simonis@6465 4209 if (fd == -1) return -1;
simonis@6465 4210
goetz@6501 4211 // If the open succeeded, the file might still be a directory.
simonis@6465 4212 {
simonis@6465 4213 struct stat64 buf64;
simonis@6465 4214 int ret = ::fstat64(fd, &buf64);
simonis@6465 4215 int st_mode = buf64.st_mode;
simonis@6465 4216
simonis@6465 4217 if (ret != -1) {
simonis@6465 4218 if ((st_mode & S_IFMT) == S_IFDIR) {
simonis@6465 4219 errno = EISDIR;
simonis@6465 4220 ::close(fd);
simonis@6465 4221 return -1;
simonis@6465 4222 }
simonis@6465 4223 } else {
simonis@6465 4224 ::close(fd);
simonis@6465 4225 return -1;
simonis@6465 4226 }
simonis@6465 4227 }
simonis@6465 4228
simonis@6465 4229 // All file descriptors that are opened in the JVM and not
simonis@6465 4230 // specifically destined for a subprocess should have the
simonis@6465 4231 // close-on-exec flag set. If we don't set it, then careless 3rd
simonis@6465 4232 // party native code might fork and exec without closing all
simonis@6465 4233 // appropriate file descriptors (e.g. as we do in closeDescriptors in
simonis@6465 4234 // UNIXProcess.c), and this in turn might:
simonis@6465 4235 //
simonis@6465 4236 // - cause end-of-file to fail to be detected on some file
simonis@6465 4237 // descriptors, resulting in mysterious hangs, or
simonis@6465 4238 //
simonis@6465 4239 // - might cause an fopen in the subprocess to fail on a system
simonis@6465 4240 // suffering from bug 1085341.
simonis@6465 4241 //
simonis@6465 4242 // (Yes, the default setting of the close-on-exec flag is a Unix
simonis@6465 4243 // design flaw.)
simonis@6465 4244 //
simonis@6465 4245 // See:
simonis@6465 4246 // 1085341: 32-bit stdio routines should support file descriptors >255
simonis@6465 4247 // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
simonis@6465 4248 // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
simonis@6465 4249 #ifdef FD_CLOEXEC
simonis@6465 4250 {
simonis@6465 4251 int flags = ::fcntl(fd, F_GETFD);
simonis@6465 4252 if (flags != -1)
simonis@6465 4253 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
simonis@6465 4254 }
simonis@6465 4255 #endif
simonis@6465 4256
simonis@6465 4257 if (o_delete != 0) {
simonis@6465 4258 ::unlink(path);
simonis@6465 4259 }
simonis@6465 4260 return fd;
simonis@6465 4261 }
simonis@6465 4262
simonis@6465 4263
simonis@6465 4264 // create binary file, rewriting existing file if required
simonis@6465 4265 int os::create_binary_file(const char* path, bool rewrite_existing) {
goetz@6501 4266 int oflags = O_WRONLY | O_CREAT;
goetz@6501 4267 if (!rewrite_existing) {
goetz@6501 4268 oflags |= O_EXCL;
goetz@6501 4269 }
goetz@6501 4270 return ::open64(path, oflags, S_IREAD | S_IWRITE);
simonis@6465 4271 }
simonis@6465 4272
simonis@6465 4273 // return current position of file pointer
simonis@6465 4274 jlong os::current_file_offset(int fd) {
simonis@6465 4275 return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
simonis@6465 4276 }
simonis@6465 4277
simonis@6465 4278 // move file pointer to the specified offset
simonis@6465 4279 jlong os::seek_to_file_offset(int fd, jlong offset) {
simonis@6465 4280 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
simonis@6465 4281 }
simonis@6465 4282
simonis@6465 4283 // This code originates from JDK's sysAvailable
simonis@6465 4284 // from src/solaris/hpi/src/native_threads/src/sys_api_td.c
simonis@6465 4285
simonis@6465 4286 int os::available(int fd, jlong *bytes) {
simonis@6465 4287 jlong cur, end;
simonis@6465 4288 int mode;
simonis@6465 4289 struct stat64 buf64;
simonis@6465 4290
simonis@6465 4291 if (::fstat64(fd, &buf64) >= 0) {
simonis@6465 4292 mode = buf64.st_mode;
simonis@6465 4293 if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
simonis@6465 4294 // XXX: is the following call interruptible? If so, this might
simonis@6465 4295 // need to go through the INTERRUPT_IO() wrapper as for other
simonis@6465 4296 // blocking, interruptible calls in this file.
simonis@6465 4297 int n;
simonis@6465 4298 if (::ioctl(fd, FIONREAD, &n) >= 0) {
simonis@6465 4299 *bytes = n;
simonis@6465 4300 return 1;
simonis@6465 4301 }
simonis@6465 4302 }
simonis@6465 4303 }
simonis@6465 4304 if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
simonis@6465 4305 return 0;
simonis@6465 4306 } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
simonis@6465 4307 return 0;
simonis@6465 4308 } else if (::lseek64(fd, cur, SEEK_SET) == -1) {
simonis@6465 4309 return 0;
simonis@6465 4310 }
simonis@6465 4311 *bytes = end - cur;
simonis@6465 4312 return 1;
simonis@6465 4313 }
simonis@6465 4314
simonis@6465 4315 int os::socket_available(int fd, jint *pbytes) {
simonis@6465 4316 // Linux doc says EINTR not returned, unlike Solaris
simonis@6465 4317 int ret = ::ioctl(fd, FIONREAD, pbytes);
simonis@6465 4318
simonis@6465 4319 //%% note ioctl can return 0 when successful, JVM_SocketAvailable
simonis@6465 4320 // is expected to return 0 on failure and 1 on success to the jdk.
simonis@6465 4321 return (ret < 0) ? 0 : 1;
simonis@6465 4322 }
simonis@6465 4323
simonis@6465 4324 // Map a block of memory.
simonis@6465 4325 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
simonis@6465 4326 char *addr, size_t bytes, bool read_only,
simonis@6465 4327 bool allow_exec) {
simonis@6465 4328 Unimplemented();
simonis@6465 4329 return NULL;
simonis@6465 4330 }
simonis@6465 4331
simonis@6465 4332
simonis@6465 4333 // Remap a block of memory.
simonis@6465 4334 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
simonis@6465 4335 char *addr, size_t bytes, bool read_only,
simonis@6465 4336 bool allow_exec) {
simonis@6465 4337 // same as map_memory() on this OS
simonis@6465 4338 return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
simonis@6465 4339 allow_exec);
simonis@6465 4340 }
simonis@6465 4341
simonis@6465 4342 // Unmap a block of memory.
simonis@6465 4343 bool os::pd_unmap_memory(char* addr, size_t bytes) {
simonis@6465 4344 return munmap(addr, bytes) == 0;
simonis@6465 4345 }
simonis@6465 4346
simonis@6465 4347 // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
simonis@6465 4348 // are used by JVM M&M and JVMTI to get user+sys or user CPU time
simonis@6465 4349 // of a thread.
simonis@6465 4350 //
simonis@6465 4351 // current_thread_cpu_time() and thread_cpu_time(Thread*) returns
simonis@6465 4352 // the fast estimate available on the platform.
simonis@6465 4353
simonis@6465 4354 jlong os::current_thread_cpu_time() {
simonis@6465 4355 // return user + sys since the cost is the same
simonis@6465 4356 const jlong n = os::thread_cpu_time(Thread::current(), true /* user + sys */);
simonis@6465 4357 assert(n >= 0, "negative CPU time");
simonis@6465 4358 return n;
simonis@6465 4359 }
simonis@6465 4360
simonis@6465 4361 jlong os::thread_cpu_time(Thread* thread) {
simonis@6465 4362 // consistent with what current_thread_cpu_time() returns
simonis@6465 4363 const jlong n = os::thread_cpu_time(thread, true /* user + sys */);
simonis@6465 4364 assert(n >= 0, "negative CPU time");
simonis@6465 4365 return n;
simonis@6465 4366 }
simonis@6465 4367
simonis@6465 4368 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
simonis@6465 4369 const jlong n = os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
simonis@6465 4370 assert(n >= 0, "negative CPU time");
simonis@6465 4371 return n;
simonis@6465 4372 }
simonis@6465 4373
simonis@6465 4374 static bool thread_cpu_time_unchecked(Thread* thread, jlong* p_sys_time, jlong* p_user_time) {
simonis@6465 4375 bool error = false;
simonis@6465 4376
simonis@6465 4377 jlong sys_time = 0;
simonis@6465 4378 jlong user_time = 0;
simonis@6465 4379
simonis@6465 4380 // reimplemented using getthrds64().
simonis@6465 4381 //
simonis@6465 4382 // goes like this:
simonis@6465 4383 // For the thread in question, get the kernel thread id. Then get the
simonis@6465 4384 // kernel thread statistics using that id.
simonis@6465 4385 //
simonis@6465 4386 // This only works of course when no pthread scheduling is used,
simonis@6465 4387 // ie there is a 1:1 relationship to kernel threads.
simonis@6465 4388 // On AIX, see AIXTHREAD_SCOPE variable.
simonis@6465 4389
simonis@6465 4390 pthread_t pthtid = thread->osthread()->pthread_id();
simonis@6465 4391
simonis@6465 4392 // retrieve kernel thread id for the pthread:
simonis@6465 4393 tid64_t tid = 0;
simonis@6465 4394 struct __pthrdsinfo pinfo;
simonis@6465 4395 // I just love those otherworldly IBM APIs which force me to hand down
simonis@6465 4396 // dummy buffers for stuff I dont care for...
simonis@6465 4397 char dummy[1];
simonis@6465 4398 int dummy_size = sizeof(dummy);
simonis@6465 4399 if (pthread_getthrds_np(&pthtid, PTHRDSINFO_QUERY_TID, &pinfo, sizeof(pinfo),
simonis@6465 4400 dummy, &dummy_size) == 0) {
simonis@6465 4401 tid = pinfo.__pi_tid;
simonis@6465 4402 } else {
simonis@6465 4403 tty->print_cr("pthread_getthrds_np failed.");
simonis@6465 4404 error = true;
simonis@6465 4405 }
simonis@6465 4406
simonis@6465 4407 // retrieve kernel timing info for that kernel thread
simonis@6465 4408 if (!error) {
simonis@6465 4409 struct thrdentry64 thrdentry;
simonis@6465 4410 if (getthrds64(getpid(), &thrdentry, sizeof(thrdentry), &tid, 1) == 1) {
simonis@6465 4411 sys_time = thrdentry.ti_ru.ru_stime.tv_sec * 1000000000LL + thrdentry.ti_ru.ru_stime.tv_usec * 1000LL;
simonis@6465 4412 user_time = thrdentry.ti_ru.ru_utime.tv_sec * 1000000000LL + thrdentry.ti_ru.ru_utime.tv_usec * 1000LL;
simonis@6465 4413 } else {
simonis@6465 4414 tty->print_cr("pthread_getthrds_np failed.");
simonis@6465 4415 error = true;
simonis@6465 4416 }
simonis@6465 4417 }
simonis@6465 4418
simonis@6465 4419 if (p_sys_time) {
simonis@6465 4420 *p_sys_time = sys_time;
simonis@6465 4421 }
simonis@6465 4422
simonis@6465 4423 if (p_user_time) {
simonis@6465 4424 *p_user_time = user_time;
simonis@6465 4425 }
simonis@6465 4426
simonis@6465 4427 if (error) {
simonis@6465 4428 return false;
simonis@6465 4429 }
simonis@6465 4430
simonis@6465 4431 return true;
simonis@6465 4432 }
simonis@6465 4433
simonis@6465 4434 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
simonis@6465 4435 jlong sys_time;
simonis@6465 4436 jlong user_time;
simonis@6465 4437
simonis@6465 4438 if (!thread_cpu_time_unchecked(thread, &sys_time, &user_time)) {
simonis@6465 4439 return -1;
simonis@6465 4440 }
simonis@6465 4441
simonis@6465 4442 return user_sys_cpu_time ? sys_time + user_time : user_time;
simonis@6465 4443 }
simonis@6465 4444
simonis@6465 4445 void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
simonis@6465 4446 info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits
simonis@6465 4447 info_ptr->may_skip_backward = false; // elapsed time not wall time
simonis@6465 4448 info_ptr->may_skip_forward = false; // elapsed time not wall time
simonis@6465 4449 info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned
simonis@6465 4450 }
simonis@6465 4451
simonis@6465 4452 void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
simonis@6465 4453 info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits
simonis@6465 4454 info_ptr->may_skip_backward = false; // elapsed time not wall time
simonis@6465 4455 info_ptr->may_skip_forward = false; // elapsed time not wall time
simonis@6465 4456 info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned
simonis@6465 4457 }
simonis@6465 4458
simonis@6465 4459 bool os::is_thread_cpu_time_supported() {
simonis@6465 4460 return true;
simonis@6465 4461 }
simonis@6465 4462
simonis@6465 4463 // System loadavg support. Returns -1 if load average cannot be obtained.
simonis@6465 4464 // For now just return the system wide load average (no processor sets).
simonis@6465 4465 int os::loadavg(double values[], int nelem) {
simonis@6465 4466
simonis@6465 4467 // Implemented using libperfstat on AIX.
simonis@6465 4468
simonis@6465 4469 guarantee(nelem >= 0 && nelem <= 3, "argument error");
simonis@6465 4470 guarantee(values, "argument error");
simonis@6465 4471
simonis@6465 4472 if (os::Aix::on_pase()) {
simonis@6465 4473 Unimplemented();
simonis@6465 4474 return -1;
simonis@6465 4475 } else {
simonis@6465 4476 // AIX: use libperfstat
simonis@6465 4477 //
simonis@6465 4478 // See also:
simonis@6465 4479 // http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/perfstat_cputot.htm
simonis@6465 4480 // /usr/include/libperfstat.h:
simonis@6465 4481
simonis@6465 4482 // Use the already AIX version independent get_cpuinfo.
simonis@6465 4483 os::Aix::cpuinfo_t ci;
simonis@6465 4484 if (os::Aix::get_cpuinfo(&ci)) {
simonis@6465 4485 for (int i = 0; i < nelem; i++) {
simonis@6465 4486 values[i] = ci.loadavg[i];
simonis@6465 4487 }
simonis@6465 4488 } else {
simonis@6465 4489 return -1;
simonis@6465 4490 }
simonis@6465 4491 return nelem;
simonis@6465 4492 }
simonis@6465 4493 }
simonis@6465 4494
simonis@6465 4495 void os::pause() {
simonis@6465 4496 char filename[MAX_PATH];
simonis@6465 4497 if (PauseAtStartupFile && PauseAtStartupFile[0]) {
simonis@6465 4498 jio_snprintf(filename, MAX_PATH, PauseAtStartupFile);
simonis@6465 4499 } else {
simonis@6465 4500 jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
simonis@6465 4501 }
simonis@6465 4502
simonis@6465 4503 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
simonis@6465 4504 if (fd != -1) {
simonis@6465 4505 struct stat buf;
simonis@6465 4506 ::close(fd);
simonis@6465 4507 while (::stat(filename, &buf) == 0) {
simonis@6465 4508 (void)::poll(NULL, 0, 100);
simonis@6465 4509 }
simonis@6465 4510 } else {
simonis@6465 4511 jio_fprintf(stderr,
simonis@6465 4512 "Could not open pause file '%s', continuing immediately.\n", filename);
simonis@6465 4513 }
simonis@6465 4514 }
simonis@6465 4515
simonis@6465 4516 bool os::Aix::is_primordial_thread() {
simonis@6465 4517 if (pthread_self() == (pthread_t)1) {
simonis@6465 4518 return true;
simonis@6465 4519 } else {
simonis@6465 4520 return false;
simonis@6465 4521 }
simonis@6465 4522 }
simonis@6465 4523
simonis@6465 4524 // OS recognitions (PASE/AIX, OS level) call this before calling any
simonis@6465 4525 // one of Aix::on_pase(), Aix::os_version() static
simonis@6465 4526 void os::Aix::initialize_os_info() {
simonis@6465 4527
simonis@6465 4528 assert(_on_pase == -1 && _os_version == -1, "already called.");
simonis@6465 4529
simonis@6465 4530 struct utsname uts;
simonis@6465 4531 memset(&uts, 0, sizeof(uts));
simonis@6465 4532 strcpy(uts.sysname, "?");
simonis@6465 4533 if (::uname(&uts) == -1) {
simonis@6465 4534 fprintf(stderr, "uname failed (%d)\n", errno);
simonis@6465 4535 guarantee(0, "Could not determine whether we run on AIX or PASE");
simonis@6465 4536 } else {
simonis@6465 4537 if (Verbose) {
simonis@6465 4538 fprintf(stderr,"uname says: sysname \"%s\" version \"%s\" release \"%s\" "
simonis@6465 4539 "node \"%s\" machine \"%s\"\n",
simonis@6465 4540 uts.sysname, uts.version, uts.release, uts.nodename, uts.machine);
simonis@6465 4541 }
simonis@6465 4542 const int major = atoi(uts.version);
simonis@6465 4543 assert(major > 0, "invalid OS version");
simonis@6465 4544 const int minor = atoi(uts.release);
simonis@6465 4545 assert(minor > 0, "invalid OS release");
simonis@6465 4546 _os_version = (major << 8) | minor;
simonis@6465 4547 if (strcmp(uts.sysname, "OS400") == 0) {
simonis@6465 4548 Unimplemented();
simonis@6465 4549 } else if (strcmp(uts.sysname, "AIX") == 0) {
simonis@6465 4550 // We run on AIX. We do not support versions older than AIX 5.3.
simonis@6465 4551 _on_pase = 0;
simonis@6465 4552 if (_os_version < 0x0503) {
simonis@6465 4553 fprintf(stderr, "AIX release older than AIX 5.3 not supported.\n");
simonis@6465 4554 assert(false, "AIX release too old.");
simonis@6465 4555 } else {
simonis@6465 4556 if (Verbose) {
simonis@6465 4557 fprintf(stderr, "We run on AIX %d.%d\n", major, minor);
simonis@6465 4558 }
simonis@6465 4559 }
simonis@6465 4560 } else {
simonis@6465 4561 assert(false, "unknown OS");
simonis@6465 4562 }
simonis@6465 4563 }
simonis@6465 4564
simonis@6465 4565 guarantee(_on_pase != -1 && _os_version, "Could not determine AIX/OS400 release");
simonis@6465 4566
simonis@6465 4567 } // end: os::Aix::initialize_os_info()
simonis@6465 4568
simonis@6465 4569 // Scan environment for important settings which might effect the VM.
simonis@6465 4570 // Trace out settings. Warn about invalid settings and/or correct them.
simonis@6465 4571 //
simonis@6465 4572 // Must run after os::Aix::initialue_os_info().
simonis@6465 4573 void os::Aix::scan_environment() {
simonis@6465 4574
simonis@6465 4575 char* p;
simonis@6465 4576 int rc;
simonis@6465 4577
simonis@6465 4578 // Warn explicity if EXTSHM=ON is used. That switch changes how
simonis@6465 4579 // System V shared memory behaves. One effect is that page size of
simonis@6465 4580 // shared memory cannot be change dynamically, effectivly preventing
simonis@6465 4581 // large pages from working.
simonis@6465 4582 // This switch was needed on AIX 32bit, but on AIX 64bit the general
simonis@6465 4583 // recommendation is (in OSS notes) to switch it off.
simonis@6465 4584 p = ::getenv("EXTSHM");
simonis@6465 4585 if (Verbose) {
simonis@6465 4586 fprintf(stderr, "EXTSHM=%s.\n", p ? p : "<unset>");
simonis@6465 4587 }
simonis@6465 4588 if (p && strcmp(p, "ON") == 0) {
simonis@6465 4589 fprintf(stderr, "Unsupported setting: EXTSHM=ON. Large Page support will be disabled.\n");
simonis@6465 4590 _extshm = 1;
simonis@6465 4591 } else {
simonis@6465 4592 _extshm = 0;
simonis@6465 4593 }
simonis@6465 4594
simonis@6465 4595 // SPEC1170 behaviour: will change the behaviour of a number of POSIX APIs.
simonis@6465 4596 // Not tested, not supported.
simonis@6465 4597 //
simonis@6465 4598 // Note that it might be worth the trouble to test and to require it, if only to
simonis@6465 4599 // get useful return codes for mprotect.
simonis@6465 4600 //
simonis@6465 4601 // Note: Setting XPG_SUS_ENV in the process is too late. Must be set earlier (before
simonis@6465 4602 // exec() ? before loading the libjvm ? ....)
simonis@6465 4603 p = ::getenv("XPG_SUS_ENV");
simonis@6465 4604 if (Verbose) {
simonis@6465 4605 fprintf(stderr, "XPG_SUS_ENV=%s.\n", p ? p : "<unset>");
simonis@6465 4606 }
simonis@6465 4607 if (p && strcmp(p, "ON") == 0) {
simonis@6465 4608 _xpg_sus_mode = 1;
simonis@6465 4609 fprintf(stderr, "Unsupported setting: XPG_SUS_ENV=ON\n");
simonis@6465 4610 // This is not supported. Worst of all, it changes behaviour of mmap MAP_FIXED to
simonis@6465 4611 // clobber address ranges. If we ever want to support that, we have to do some
simonis@6465 4612 // testing first.
simonis@6465 4613 guarantee(false, "XPG_SUS_ENV=ON not supported");
simonis@6465 4614 } else {
simonis@6465 4615 _xpg_sus_mode = 0;
simonis@6465 4616 }
simonis@6465 4617
simonis@6465 4618 // Switch off AIX internal (pthread) guard pages. This has
simonis@6465 4619 // immediate effect for any pthread_create calls which follow.
simonis@6465 4620 p = ::getenv("AIXTHREAD_GUARDPAGES");
simonis@6465 4621 if (Verbose) {
simonis@6465 4622 fprintf(stderr, "AIXTHREAD_GUARDPAGES=%s.\n", p ? p : "<unset>");
simonis@6465 4623 fprintf(stderr, "setting AIXTHREAD_GUARDPAGES=0.\n");
simonis@6465 4624 }
simonis@6465 4625 rc = ::putenv("AIXTHREAD_GUARDPAGES=0");
simonis@6465 4626 guarantee(rc == 0, "");
simonis@6465 4627
simonis@6465 4628 } // end: os::Aix::scan_environment()
simonis@6465 4629
simonis@6465 4630 // PASE: initialize the libo4 library (AS400 PASE porting library).
simonis@6465 4631 void os::Aix::initialize_libo4() {
simonis@6465 4632 Unimplemented();
simonis@6465 4633 }
simonis@6465 4634
simonis@6465 4635 // AIX: initialize the libperfstat library (we load this dynamically
simonis@6465 4636 // because it is only available on AIX.
simonis@6465 4637 void os::Aix::initialize_libperfstat() {
simonis@6465 4638
simonis@6465 4639 assert(os::Aix::on_aix(), "AIX only");
simonis@6465 4640
simonis@6465 4641 if (!libperfstat::init()) {
simonis@6465 4642 fprintf(stderr, "libperfstat initialization failed.\n");
simonis@6465 4643 assert(false, "libperfstat initialization failed");
simonis@6465 4644 } else {
simonis@6465 4645 if (Verbose) {
simonis@6465 4646 fprintf(stderr, "libperfstat initialized.\n");
simonis@6465 4647 }
simonis@6465 4648 }
simonis@6465 4649 } // end: os::Aix::initialize_libperfstat
simonis@6465 4650
simonis@6465 4651 /////////////////////////////////////////////////////////////////////////////
simonis@6465 4652 // thread stack
simonis@6465 4653
simonis@6465 4654 // function to query the current stack size using pthread_getthrds_np
simonis@6465 4655 //
simonis@6465 4656 // ! do not change anything here unless you know what you are doing !
simonis@6465 4657 static void query_stack_dimensions(address* p_stack_base, size_t* p_stack_size) {
simonis@6465 4658
simonis@6465 4659 // This only works when invoked on a pthread. As we agreed not to use
simonis@6465 4660 // primordial threads anyway, I assert here
simonis@6465 4661 guarantee(!os::Aix::is_primordial_thread(), "not allowed on the primordial thread");
simonis@6465 4662
simonis@6465 4663 // information about this api can be found (a) in the pthread.h header and
simonis@6465 4664 // (b) in http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread_getthrds_np.htm
simonis@6465 4665 //
simonis@6465 4666 // The use of this API to find out the current stack is kind of undefined.
simonis@6465 4667 // But after a lot of tries and asking IBM about it, I concluded that it is safe
simonis@6465 4668 // enough for cases where I let the pthread library create its stacks. For cases
simonis@6465 4669 // where I create an own stack and pass this to pthread_create, it seems not to
simonis@6465 4670 // work (the returned stack size in that case is 0).
simonis@6465 4671
simonis@6465 4672 pthread_t tid = pthread_self();
simonis@6465 4673 struct __pthrdsinfo pinfo;
simonis@6465 4674 char dummy[1]; // we only need this to satisfy the api and to not get E
simonis@6465 4675 int dummy_size = sizeof(dummy);
simonis@6465 4676
simonis@6465 4677 memset(&pinfo, 0, sizeof(pinfo));
simonis@6465 4678
simonis@6465 4679 const int rc = pthread_getthrds_np (&tid, PTHRDSINFO_QUERY_ALL, &pinfo,
simonis@6465 4680 sizeof(pinfo), dummy, &dummy_size);
simonis@6465 4681
simonis@6465 4682 if (rc != 0) {
simonis@6465 4683 fprintf(stderr, "pthread_getthrds_np failed (%d)\n", rc);
simonis@6465 4684 guarantee(0, "pthread_getthrds_np failed");
simonis@6465 4685 }
simonis@6465 4686
simonis@6465 4687 guarantee(pinfo.__pi_stackend, "returned stack base invalid");
simonis@6465 4688
simonis@6465 4689 // the following can happen when invoking pthread_getthrds_np on a pthread running on a user provided stack
simonis@6465 4690 // (when handing down a stack to pthread create, see pthread_attr_setstackaddr).
simonis@6465 4691 // Not sure what to do here - I feel inclined to forbid this use case completely.
simonis@6465 4692 guarantee(pinfo.__pi_stacksize, "returned stack size invalid");
simonis@6465 4693
simonis@6465 4694 // On AIX, stacks are not necessarily page aligned so round the base and size accordingly
simonis@6465 4695 if (p_stack_base) {
simonis@6465 4696 (*p_stack_base) = (address) align_size_up((intptr_t)pinfo.__pi_stackend, os::Aix::stack_page_size());
simonis@6465 4697 }
simonis@6465 4698
simonis@6465 4699 if (p_stack_size) {
simonis@6465 4700 (*p_stack_size) = pinfo.__pi_stacksize - os::Aix::stack_page_size();
simonis@6465 4701 }
simonis@6465 4702
simonis@6465 4703 #ifndef PRODUCT
simonis@6465 4704 if (Verbose) {
simonis@6465 4705 fprintf(stderr,
simonis@6465 4706 "query_stack_dimensions() -> real stack_base=" INTPTR_FORMAT ", real stack_addr=" INTPTR_FORMAT
simonis@6465 4707 ", real stack_size=" INTPTR_FORMAT
simonis@6465 4708 ", stack_base=" INTPTR_FORMAT ", stack_size=" INTPTR_FORMAT "\n",
simonis@6465 4709 (intptr_t)pinfo.__pi_stackend, (intptr_t)pinfo.__pi_stackaddr, pinfo.__pi_stacksize,
simonis@6465 4710 (intptr_t)align_size_up((intptr_t)pinfo.__pi_stackend, os::Aix::stack_page_size()),
simonis@6465 4711 pinfo.__pi_stacksize - os::Aix::stack_page_size());
simonis@6465 4712 }
simonis@6465 4713 #endif
simonis@6465 4714
simonis@6465 4715 } // end query_stack_dimensions
simonis@6465 4716
simonis@6465 4717 // get the current stack base from the OS (actually, the pthread library)
simonis@6465 4718 address os::current_stack_base() {
simonis@6465 4719 address p;
simonis@6465 4720 query_stack_dimensions(&p, 0);
simonis@6465 4721 return p;
simonis@6465 4722 }
simonis@6465 4723
simonis@6465 4724 // get the current stack size from the OS (actually, the pthread library)
simonis@6465 4725 size_t os::current_stack_size() {
simonis@6465 4726 size_t s;
simonis@6465 4727 query_stack_dimensions(0, &s);
simonis@6465 4728 return s;
simonis@6465 4729 }
simonis@6465 4730
simonis@6465 4731 // Refer to the comments in os_solaris.cpp park-unpark.
simonis@6465 4732 //
simonis@6465 4733 // Beware -- Some versions of NPTL embody a flaw where pthread_cond_timedwait() can
simonis@6465 4734 // hang indefinitely. For instance NPTL 0.60 on 2.4.21-4ELsmp is vulnerable.
simonis@6465 4735 // For specifics regarding the bug see GLIBC BUGID 261237 :
simonis@6465 4736 // http://www.mail-archive.com/debian-glibc@lists.debian.org/msg10837.html.
simonis@6465 4737 // Briefly, pthread_cond_timedwait() calls with an expiry time that's not in the future
simonis@6465 4738 // will either hang or corrupt the condvar, resulting in subsequent hangs if the condvar
simonis@6465 4739 // is used. (The simple C test-case provided in the GLIBC bug report manifests the
simonis@6465 4740 // hang). The JVM is vulernable via sleep(), Object.wait(timo), LockSupport.parkNanos()
simonis@6465 4741 // and monitorenter when we're using 1-0 locking. All those operations may result in
simonis@6465 4742 // calls to pthread_cond_timedwait(). Using LD_ASSUME_KERNEL to use an older version
simonis@6465 4743 // of libpthread avoids the problem, but isn't practical.
simonis@6465 4744 //
simonis@6465 4745 // Possible remedies:
simonis@6465 4746 //
simonis@6465 4747 // 1. Establish a minimum relative wait time. 50 to 100 msecs seems to work.
simonis@6465 4748 // This is palliative and probabilistic, however. If the thread is preempted
simonis@6465 4749 // between the call to compute_abstime() and pthread_cond_timedwait(), more
simonis@6465 4750 // than the minimum period may have passed, and the abstime may be stale (in the
simonis@6465 4751 // past) resultin in a hang. Using this technique reduces the odds of a hang
simonis@6465 4752 // but the JVM is still vulnerable, particularly on heavily loaded systems.
simonis@6465 4753 //
simonis@6465 4754 // 2. Modify park-unpark to use per-thread (per ParkEvent) pipe-pairs instead
simonis@6465 4755 // of the usual flag-condvar-mutex idiom. The write side of the pipe is set
simonis@6465 4756 // NDELAY. unpark() reduces to write(), park() reduces to read() and park(timo)
simonis@6465 4757 // reduces to poll()+read(). This works well, but consumes 2 FDs per extant
simonis@6465 4758 // thread.
simonis@6465 4759 //
simonis@6465 4760 // 3. Embargo pthread_cond_timedwait() and implement a native "chron" thread
simonis@6465 4761 // that manages timeouts. We'd emulate pthread_cond_timedwait() by enqueuing
simonis@6465 4762 // a timeout request to the chron thread and then blocking via pthread_cond_wait().
simonis@6465 4763 // This also works well. In fact it avoids kernel-level scalability impediments
simonis@6465 4764 // on certain platforms that don't handle lots of active pthread_cond_timedwait()
simonis@6465 4765 // timers in a graceful fashion.
simonis@6465 4766 //
simonis@6465 4767 // 4. When the abstime value is in the past it appears that control returns
simonis@6465 4768 // correctly from pthread_cond_timedwait(), but the condvar is left corrupt.
simonis@6465 4769 // Subsequent timedwait/wait calls may hang indefinitely. Given that, we
simonis@6465 4770 // can avoid the problem by reinitializing the condvar -- by cond_destroy()
simonis@6465 4771 // followed by cond_init() -- after all calls to pthread_cond_timedwait().
simonis@6465 4772 // It may be possible to avoid reinitialization by checking the return
simonis@6465 4773 // value from pthread_cond_timedwait(). In addition to reinitializing the
simonis@6465 4774 // condvar we must establish the invariant that cond_signal() is only called
simonis@6465 4775 // within critical sections protected by the adjunct mutex. This prevents
simonis@6465 4776 // cond_signal() from "seeing" a condvar that's in the midst of being
simonis@6465 4777 // reinitialized or that is corrupt. Sadly, this invariant obviates the
simonis@6465 4778 // desirable signal-after-unlock optimization that avoids futile context switching.
simonis@6465 4779 //
simonis@6465 4780 // I'm also concerned that some versions of NTPL might allocate an auxilliary
simonis@6465 4781 // structure when a condvar is used or initialized. cond_destroy() would
simonis@6465 4782 // release the helper structure. Our reinitialize-after-timedwait fix
simonis@6465 4783 // put excessive stress on malloc/free and locks protecting the c-heap.
simonis@6465 4784 //
simonis@6465 4785 // We currently use (4). See the WorkAroundNTPLTimedWaitHang flag.
simonis@6465 4786 // It may be possible to refine (4) by checking the kernel and NTPL verisons
simonis@6465 4787 // and only enabling the work-around for vulnerable environments.
simonis@6465 4788
simonis@6465 4789 // utility to compute the abstime argument to timedwait:
simonis@6465 4790 // millis is the relative timeout time
simonis@6465 4791 // abstime will be the absolute timeout time
simonis@6465 4792 // TODO: replace compute_abstime() with unpackTime()
simonis@6465 4793
simonis@6465 4794 static struct timespec* compute_abstime(timespec* abstime, jlong millis) {
simonis@6465 4795 if (millis < 0) millis = 0;
simonis@6465 4796 struct timeval now;
simonis@6465 4797 int status = gettimeofday(&now, NULL);
simonis@6465 4798 assert(status == 0, "gettimeofday");
simonis@6465 4799 jlong seconds = millis / 1000;
simonis@6465 4800 millis %= 1000;
simonis@6465 4801 if (seconds > 50000000) { // see man cond_timedwait(3T)
simonis@6465 4802 seconds = 50000000;
simonis@6465 4803 }
simonis@6465 4804 abstime->tv_sec = now.tv_sec + seconds;
simonis@6465 4805 long usec = now.tv_usec + millis * 1000;
simonis@6465 4806 if (usec >= 1000000) {
simonis@6465 4807 abstime->tv_sec += 1;
simonis@6465 4808 usec -= 1000000;
simonis@6465 4809 }
simonis@6465 4810 abstime->tv_nsec = usec * 1000;
simonis@6465 4811 return abstime;
simonis@6465 4812 }
simonis@6465 4813
simonis@6465 4814
simonis@6465 4815 // Test-and-clear _Event, always leaves _Event set to 0, returns immediately.
simonis@6465 4816 // Conceptually TryPark() should be equivalent to park(0).
simonis@6465 4817
simonis@6465 4818 int os::PlatformEvent::TryPark() {
simonis@6465 4819 for (;;) {
simonis@6465 4820 const int v = _Event;
simonis@6465 4821 guarantee ((v == 0) || (v == 1), "invariant");
simonis@6465 4822 if (Atomic::cmpxchg (0, &_Event, v) == v) return v;
simonis@6465 4823 }
simonis@6465 4824 }
simonis@6465 4825
simonis@6465 4826 void os::PlatformEvent::park() { // AKA "down()"
simonis@6465 4827 // Invariant: Only the thread associated with the Event/PlatformEvent
simonis@6465 4828 // may call park().
simonis@6465 4829 // TODO: assert that _Assoc != NULL or _Assoc == Self
simonis@6465 4830 int v;
simonis@6465 4831 for (;;) {
simonis@6465 4832 v = _Event;
simonis@6465 4833 if (Atomic::cmpxchg (v-1, &_Event, v) == v) break;
simonis@6465 4834 }
simonis@6465 4835 guarantee (v >= 0, "invariant");
simonis@6465 4836 if (v == 0) {
simonis@6465 4837 // Do this the hard way by blocking ...
simonis@6465 4838 int status = pthread_mutex_lock(_mutex);
simonis@6465 4839 assert_status(status == 0, status, "mutex_lock");
simonis@6465 4840 guarantee (_nParked == 0, "invariant");
simonis@6465 4841 ++ _nParked;
simonis@6465 4842 while (_Event < 0) {
simonis@6465 4843 status = pthread_cond_wait(_cond, _mutex);
simonis@6465 4844 assert_status(status == 0 || status == ETIMEDOUT, status, "cond_timedwait");
simonis@6465 4845 }
simonis@6465 4846 -- _nParked;
simonis@6465 4847
simonis@6465 4848 // In theory we could move the ST of 0 into _Event past the unlock(),
simonis@6465 4849 // but then we'd need a MEMBAR after the ST.
simonis@6465 4850 _Event = 0;
simonis@6465 4851 status = pthread_mutex_unlock(_mutex);
simonis@6465 4852 assert_status(status == 0, status, "mutex_unlock");
simonis@6465 4853 }
simonis@6465 4854 guarantee (_Event >= 0, "invariant");
simonis@6465 4855 }
simonis@6465 4856
simonis@6465 4857 int os::PlatformEvent::park(jlong millis) {
simonis@6465 4858 guarantee (_nParked == 0, "invariant");
simonis@6465 4859
simonis@6465 4860 int v;
simonis@6465 4861 for (;;) {
simonis@6465 4862 v = _Event;
simonis@6465 4863 if (Atomic::cmpxchg (v-1, &_Event, v) == v) break;
simonis@6465 4864 }
simonis@6465 4865 guarantee (v >= 0, "invariant");
simonis@6465 4866 if (v != 0) return OS_OK;
simonis@6465 4867
simonis@6465 4868 // We do this the hard way, by blocking the thread.
simonis@6465 4869 // Consider enforcing a minimum timeout value.
simonis@6465 4870 struct timespec abst;
simonis@6465 4871 compute_abstime(&abst, millis);
simonis@6465 4872
simonis@6465 4873 int ret = OS_TIMEOUT;
simonis@6465 4874 int status = pthread_mutex_lock(_mutex);
simonis@6465 4875 assert_status(status == 0, status, "mutex_lock");
simonis@6465 4876 guarantee (_nParked == 0, "invariant");
simonis@6465 4877 ++_nParked;
simonis@6465 4878
simonis@6465 4879 // Object.wait(timo) will return because of
simonis@6465 4880 // (a) notification
simonis@6465 4881 // (b) timeout
simonis@6465 4882 // (c) thread.interrupt
simonis@6465 4883 //
simonis@6465 4884 // Thread.interrupt and object.notify{All} both call Event::set.
simonis@6465 4885 // That is, we treat thread.interrupt as a special case of notification.
simonis@6465 4886 // The underlying Solaris implementation, cond_timedwait, admits
simonis@6465 4887 // spurious/premature wakeups, but the JLS/JVM spec prevents the
simonis@6465 4888 // JVM from making those visible to Java code. As such, we must
simonis@6465 4889 // filter out spurious wakeups. We assume all ETIME returns are valid.
simonis@6465 4890 //
simonis@6465 4891 // TODO: properly differentiate simultaneous notify+interrupt.
simonis@6465 4892 // In that case, we should propagate the notify to another waiter.
simonis@6465 4893
simonis@6465 4894 while (_Event < 0) {
simonis@6465 4895 status = pthread_cond_timedwait(_cond, _mutex, &abst);
simonis@6465 4896 assert_status(status == 0 || status == ETIMEDOUT,
simonis@6465 4897 status, "cond_timedwait");
simonis@6465 4898 if (!FilterSpuriousWakeups) break; // previous semantics
simonis@6465 4899 if (status == ETIMEDOUT) break;
simonis@6465 4900 // We consume and ignore EINTR and spurious wakeups.
simonis@6465 4901 }
simonis@6465 4902 --_nParked;
simonis@6465 4903 if (_Event >= 0) {
simonis@6465 4904 ret = OS_OK;
simonis@6465 4905 }
simonis@6465 4906 _Event = 0;
simonis@6465 4907 status = pthread_mutex_unlock(_mutex);
simonis@6465 4908 assert_status(status == 0, status, "mutex_unlock");
simonis@6465 4909 assert (_nParked == 0, "invariant");
simonis@6465 4910 return ret;
simonis@6465 4911 }
simonis@6465 4912
simonis@6465 4913 void os::PlatformEvent::unpark() {
simonis@6465 4914 int v, AnyWaiters;
simonis@6465 4915 for (;;) {
simonis@6465 4916 v = _Event;
simonis@6465 4917 if (v > 0) {
simonis@6465 4918 // The LD of _Event could have reordered or be satisfied
simonis@6465 4919 // by a read-aside from this processor's write buffer.
simonis@6465 4920 // To avoid problems execute a barrier and then
simonis@6465 4921 // ratify the value.
simonis@6465 4922 OrderAccess::fence();
simonis@6465 4923 if (_Event == v) return;
simonis@6465 4924 continue;
simonis@6465 4925 }
simonis@6465 4926 if (Atomic::cmpxchg (v+1, &_Event, v) == v) break;
simonis@6465 4927 }
simonis@6465 4928 if (v < 0) {
simonis@6465 4929 // Wait for the thread associated with the event to vacate
simonis@6465 4930 int status = pthread_mutex_lock(_mutex);
simonis@6465 4931 assert_status(status == 0, status, "mutex_lock");
simonis@6465 4932 AnyWaiters = _nParked;
simonis@6465 4933
simonis@6465 4934 if (AnyWaiters != 0) {
simonis@6465 4935 // We intentional signal *after* dropping the lock
simonis@6465 4936 // to avoid a common class of futile wakeups.
simonis@6465 4937 status = pthread_cond_signal(_cond);
simonis@6465 4938 assert_status(status == 0, status, "cond_signal");
simonis@6465 4939 }
simonis@6465 4940 // Mutex should be locked for pthread_cond_signal(_cond).
simonis@6465 4941 status = pthread_mutex_unlock(_mutex);
simonis@6465 4942 assert_status(status == 0, status, "mutex_unlock");
simonis@6465 4943 }
simonis@6465 4944
simonis@6465 4945 // Note that we signal() _after dropping the lock for "immortal" Events.
simonis@6465 4946 // This is safe and avoids a common class of futile wakeups. In rare
simonis@6465 4947 // circumstances this can cause a thread to return prematurely from
simonis@6465 4948 // cond_{timed}wait() but the spurious wakeup is benign and the victim will
simonis@6465 4949 // simply re-test the condition and re-park itself.
simonis@6465 4950 }
simonis@6465 4951
simonis@6465 4952
simonis@6465 4953 // JSR166
simonis@6465 4954 // -------------------------------------------------------
simonis@6465 4955
simonis@6465 4956 //
simonis@6465 4957 // The solaris and linux implementations of park/unpark are fairly
simonis@6465 4958 // conservative for now, but can be improved. They currently use a
simonis@6465 4959 // mutex/condvar pair, plus a a count.
simonis@6465 4960 // Park decrements count if > 0, else does a condvar wait. Unpark
simonis@6465 4961 // sets count to 1 and signals condvar. Only one thread ever waits
simonis@6465 4962 // on the condvar. Contention seen when trying to park implies that someone
simonis@6465 4963 // is unparking you, so don't wait. And spurious returns are fine, so there
simonis@6465 4964 // is no need to track notifications.
simonis@6465 4965 //
simonis@6465 4966
simonis@6465 4967 #define MAX_SECS 100000000
simonis@6465 4968 //
simonis@6465 4969 // This code is common to linux and solaris and will be moved to a
simonis@6465 4970 // common place in dolphin.
simonis@6465 4971 //
simonis@6465 4972 // The passed in time value is either a relative time in nanoseconds
simonis@6465 4973 // or an absolute time in milliseconds. Either way it has to be unpacked
simonis@6465 4974 // into suitable seconds and nanoseconds components and stored in the
simonis@6465 4975 // given timespec structure.
simonis@6465 4976 // Given time is a 64-bit value and the time_t used in the timespec is only
simonis@6465 4977 // a signed-32-bit value (except on 64-bit Linux) we have to watch for
simonis@6465 4978 // overflow if times way in the future are given. Further on Solaris versions
simonis@6465 4979 // prior to 10 there is a restriction (see cond_timedwait) that the specified
simonis@6465 4980 // number of seconds, in abstime, is less than current_time + 100,000,000.
simonis@6465 4981 // As it will be 28 years before "now + 100000000" will overflow we can
simonis@6465 4982 // ignore overflow and just impose a hard-limit on seconds using the value
simonis@6465 4983 // of "now + 100,000,000". This places a limit on the timeout of about 3.17
simonis@6465 4984 // years from "now".
simonis@6465 4985 //
simonis@6465 4986
simonis@6465 4987 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
simonis@6465 4988 assert (time > 0, "convertTime");
simonis@6465 4989
simonis@6465 4990 struct timeval now;
simonis@6465 4991 int status = gettimeofday(&now, NULL);
simonis@6465 4992 assert(status == 0, "gettimeofday");
simonis@6465 4993
simonis@6465 4994 time_t max_secs = now.tv_sec + MAX_SECS;
simonis@6465 4995
simonis@6465 4996 if (isAbsolute) {
simonis@6465 4997 jlong secs = time / 1000;
simonis@6465 4998 if (secs > max_secs) {
simonis@6465 4999 absTime->tv_sec = max_secs;
simonis@6465 5000 }
simonis@6465 5001 else {
simonis@6465 5002 absTime->tv_sec = secs;
simonis@6465 5003 }
simonis@6465 5004 absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC;
simonis@6465 5005 }
simonis@6465 5006 else {
simonis@6465 5007 jlong secs = time / NANOSECS_PER_SEC;
simonis@6465 5008 if (secs >= MAX_SECS) {
simonis@6465 5009 absTime->tv_sec = max_secs;
simonis@6465 5010 absTime->tv_nsec = 0;
simonis@6465 5011 }
simonis@6465 5012 else {
simonis@6465 5013 absTime->tv_sec = now.tv_sec + secs;
simonis@6465 5014 absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000;
simonis@6465 5015 if (absTime->tv_nsec >= NANOSECS_PER_SEC) {
simonis@6465 5016 absTime->tv_nsec -= NANOSECS_PER_SEC;
simonis@6465 5017 ++absTime->tv_sec; // note: this must be <= max_secs
simonis@6465 5018 }
simonis@6465 5019 }
simonis@6465 5020 }
simonis@6465 5021 assert(absTime->tv_sec >= 0, "tv_sec < 0");
simonis@6465 5022 assert(absTime->tv_sec <= max_secs, "tv_sec > max_secs");
simonis@6465 5023 assert(absTime->tv_nsec >= 0, "tv_nsec < 0");
simonis@6465 5024 assert(absTime->tv_nsec < NANOSECS_PER_SEC, "tv_nsec >= nanos_per_sec");
simonis@6465 5025 }
simonis@6465 5026
simonis@6465 5027 void Parker::park(bool isAbsolute, jlong time) {
simonis@6465 5028 // Optional fast-path check:
simonis@6465 5029 // Return immediately if a permit is available.
simonis@6465 5030 if (_counter > 0) {
simonis@6465 5031 _counter = 0;
simonis@6465 5032 OrderAccess::fence();
simonis@6465 5033 return;
simonis@6465 5034 }
simonis@6465 5035
simonis@6465 5036 Thread* thread = Thread::current();
simonis@6465 5037 assert(thread->is_Java_thread(), "Must be JavaThread");
simonis@6465 5038 JavaThread *jt = (JavaThread *)thread;
simonis@6465 5039
simonis@6465 5040 // Optional optimization -- avoid state transitions if there's an interrupt pending.
simonis@6465 5041 // Check interrupt before trying to wait
simonis@6465 5042 if (Thread::is_interrupted(thread, false)) {
simonis@6465 5043 return;
simonis@6465 5044 }
simonis@6465 5045
simonis@6465 5046 // Next, demultiplex/decode time arguments
simonis@6465 5047 timespec absTime;
simonis@6465 5048 if (time < 0 || (isAbsolute && time == 0)) { // don't wait at all
simonis@6465 5049 return;
simonis@6465 5050 }
simonis@6465 5051 if (time > 0) {
simonis@6465 5052 unpackTime(&absTime, isAbsolute, time);
simonis@6465 5053 }
simonis@6465 5054
simonis@6465 5055
simonis@6465 5056 // Enter safepoint region
simonis@6465 5057 // Beware of deadlocks such as 6317397.
simonis@6465 5058 // The per-thread Parker:: mutex is a classic leaf-lock.
simonis@6465 5059 // In particular a thread must never block on the Threads_lock while
simonis@6465 5060 // holding the Parker:: mutex. If safepoints are pending both the
simonis@6465 5061 // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
simonis@6465 5062 ThreadBlockInVM tbivm(jt);
simonis@6465 5063
simonis@6465 5064 // Don't wait if cannot get lock since interference arises from
simonis@6465 5065 // unblocking. Also. check interrupt before trying wait
simonis@6465 5066 if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) {
simonis@6465 5067 return;
simonis@6465 5068 }
simonis@6465 5069
simonis@6465 5070 int status;
simonis@6465 5071 if (_counter > 0) { // no wait needed
simonis@6465 5072 _counter = 0;
simonis@6465 5073 status = pthread_mutex_unlock(_mutex);
simonis@6465 5074 assert (status == 0, "invariant");
simonis@6465 5075 OrderAccess::fence();
simonis@6465 5076 return;
simonis@6465 5077 }
simonis@6465 5078
simonis@6465 5079 #ifdef ASSERT
simonis@6465 5080 // Don't catch signals while blocked; let the running threads have the signals.
simonis@6465 5081 // (This allows a debugger to break into the running thread.)
simonis@6465 5082 sigset_t oldsigs;
simonis@6465 5083 sigset_t* allowdebug_blocked = os::Aix::allowdebug_blocked_signals();
simonis@6465 5084 pthread_sigmask(SIG_BLOCK, allowdebug_blocked, &oldsigs);
simonis@6465 5085 #endif
simonis@6465 5086
simonis@6465 5087 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
simonis@6465 5088 jt->set_suspend_equivalent();
simonis@6465 5089 // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
simonis@6465 5090
simonis@6465 5091 if (time == 0) {
simonis@6465 5092 status = pthread_cond_wait (_cond, _mutex);
simonis@6465 5093 } else {
simonis@6465 5094 status = pthread_cond_timedwait (_cond, _mutex, &absTime);
simonis@6465 5095 if (status != 0 && WorkAroundNPTLTimedWaitHang) {
simonis@6465 5096 pthread_cond_destroy (_cond);
simonis@6465 5097 pthread_cond_init (_cond, NULL);
simonis@6465 5098 }
simonis@6465 5099 }
simonis@6465 5100 assert_status(status == 0 || status == EINTR ||
simonis@6465 5101 status == ETIME || status == ETIMEDOUT,
simonis@6465 5102 status, "cond_timedwait");
simonis@6465 5103
simonis@6465 5104 #ifdef ASSERT
simonis@6465 5105 pthread_sigmask(SIG_SETMASK, &oldsigs, NULL);
simonis@6465 5106 #endif
simonis@6465 5107
simonis@6465 5108 _counter = 0;
simonis@6465 5109 status = pthread_mutex_unlock(_mutex);
simonis@6465 5110 assert_status(status == 0, status, "invariant");
simonis@6465 5111 // If externally suspended while waiting, re-suspend
simonis@6465 5112 if (jt->handle_special_suspend_equivalent_condition()) {
simonis@6465 5113 jt->java_suspend_self();
simonis@6465 5114 }
simonis@6465 5115
simonis@6465 5116 OrderAccess::fence();
simonis@6465 5117 }
simonis@6465 5118
simonis@6465 5119 void Parker::unpark() {
simonis@6465 5120 int s, status;
simonis@6465 5121 status = pthread_mutex_lock(_mutex);
simonis@6465 5122 assert (status == 0, "invariant");
simonis@6465 5123 s = _counter;
simonis@6465 5124 _counter = 1;
simonis@6465 5125 if (s < 1) {
simonis@6465 5126 if (WorkAroundNPTLTimedWaitHang) {
simonis@6465 5127 status = pthread_cond_signal (_cond);
simonis@6465 5128 assert (status == 0, "invariant");
simonis@6465 5129 status = pthread_mutex_unlock(_mutex);
simonis@6465 5130 assert (status == 0, "invariant");
simonis@6465 5131 } else {
simonis@6465 5132 status = pthread_mutex_unlock(_mutex);
simonis@6465 5133 assert (status == 0, "invariant");
simonis@6465 5134 status = pthread_cond_signal (_cond);
simonis@6465 5135 assert (status == 0, "invariant");
simonis@6465 5136 }
simonis@6465 5137 } else {
simonis@6465 5138 pthread_mutex_unlock(_mutex);
simonis@6465 5139 assert (status == 0, "invariant");
simonis@6465 5140 }
simonis@6465 5141 }
simonis@6465 5142
simonis@6465 5143
simonis@6465 5144 extern char** environ;
simonis@6465 5145
simonis@6465 5146 // Run the specified command in a separate process. Return its exit value,
simonis@6465 5147 // or -1 on failure (e.g. can't fork a new process).
simonis@6465 5148 // Unlike system(), this function can be called from signal handler. It
simonis@6465 5149 // doesn't block SIGINT et al.
simonis@6465 5150 int os::fork_and_exec(char* cmd) {
simonis@6471 5151 char * argv[4] = {"sh", "-c", cmd, NULL};
simonis@6471 5152
simonis@6471 5153 pid_t pid = fork();
simonis@6471 5154
simonis@6471 5155 if (pid < 0) {
simonis@6471 5156 // fork failed
simonis@6471 5157 return -1;
simonis@6471 5158
simonis@6471 5159 } else if (pid == 0) {
simonis@6471 5160 // child process
simonis@6471 5161
simonis@6471 5162 // try to be consistent with system(), which uses "/usr/bin/sh" on AIX
simonis@6471 5163 execve("/usr/bin/sh", argv, environ);
simonis@6471 5164
simonis@6471 5165 // execve failed
simonis@6471 5166 _exit(-1);
simonis@6471 5167
simonis@6471 5168 } else {
simonis@6471 5169 // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
simonis@6471 5170 // care about the actual exit code, for now.
simonis@6471 5171
simonis@6471 5172 int status;
simonis@6471 5173
simonis@6471 5174 // Wait for the child process to exit. This returns immediately if
simonis@6471 5175 // the child has already exited. */
simonis@6471 5176 while (waitpid(pid, &status, 0) < 0) {
simonis@6471 5177 switch (errno) {
simonis@6471 5178 case ECHILD: return 0;
simonis@6471 5179 case EINTR: break;
simonis@6471 5180 default: return -1;
simonis@6471 5181 }
simonis@6471 5182 }
simonis@6471 5183
simonis@6471 5184 if (WIFEXITED(status)) {
simonis@6471 5185 // The child exited normally; get its exit code.
simonis@6471 5186 return WEXITSTATUS(status);
simonis@6471 5187 } else if (WIFSIGNALED(status)) {
simonis@6471 5188 // The child exited because of a signal
simonis@6471 5189 // The best value to return is 0x80 + signal number,
simonis@6471 5190 // because that is what all Unix shells do, and because
simonis@6471 5191 // it allows callers to distinguish between process exit and
simonis@6471 5192 // process death by signal.
simonis@6471 5193 return 0x80 + WTERMSIG(status);
simonis@6471 5194 } else {
simonis@6471 5195 // Unknown exit code; pass it through
simonis@6471 5196 return status;
simonis@6471 5197 }
simonis@6471 5198 }
simonis@6471 5199 // Remove warning.
simonis@6471 5200 return -1;
simonis@6465 5201 }
simonis@6465 5202
simonis@6465 5203 // is_headless_jre()
simonis@6465 5204 //
simonis@6465 5205 // Test for the existence of xawt/libmawt.so or libawt_xawt.so
simonis@6465 5206 // in order to report if we are running in a headless jre.
simonis@6465 5207 //
simonis@6465 5208 // Since JDK8 xawt/libmawt.so is moved into the same directory
simonis@6465 5209 // as libawt.so, and renamed libawt_xawt.so
simonis@6465 5210 bool os::is_headless_jre() {
simonis@6465 5211 struct stat statbuf;
simonis@6465 5212 char buf[MAXPATHLEN];
simonis@6465 5213 char libmawtpath[MAXPATHLEN];
simonis@6465 5214 const char *xawtstr = "/xawt/libmawt.so";
simonis@6465 5215 const char *new_xawtstr = "/libawt_xawt.so";
simonis@6465 5216
simonis@6465 5217 char *p;
simonis@6465 5218
simonis@6465 5219 // Get path to libjvm.so
simonis@6465 5220 os::jvm_path(buf, sizeof(buf));
simonis@6465 5221
simonis@6465 5222 // Get rid of libjvm.so
simonis@6465 5223 p = strrchr(buf, '/');
simonis@6465 5224 if (p == NULL) return false;
simonis@6465 5225 else *p = '\0';
simonis@6465 5226
simonis@6465 5227 // Get rid of client or server
simonis@6465 5228 p = strrchr(buf, '/');
simonis@6465 5229 if (p == NULL) return false;
simonis@6465 5230 else *p = '\0';
simonis@6465 5231
simonis@6465 5232 // check xawt/libmawt.so
simonis@6465 5233 strcpy(libmawtpath, buf);
simonis@6465 5234 strcat(libmawtpath, xawtstr);
simonis@6465 5235 if (::stat(libmawtpath, &statbuf) == 0) return false;
simonis@6465 5236
simonis@6465 5237 // check libawt_xawt.so
simonis@6465 5238 strcpy(libmawtpath, buf);
simonis@6465 5239 strcat(libmawtpath, new_xawtstr);
simonis@6465 5240 if (::stat(libmawtpath, &statbuf) == 0) return false;
simonis@6465 5241
simonis@6465 5242 return true;
simonis@6465 5243 }
simonis@6465 5244
simonis@6465 5245 // Get the default path to the core file
simonis@6465 5246 // Returns the length of the string
simonis@6465 5247 int os::get_core_path(char* buffer, size_t bufferSize) {
simonis@6465 5248 const char* p = get_current_directory(buffer, bufferSize);
simonis@6465 5249
simonis@6465 5250 if (p == NULL) {
simonis@6465 5251 assert(p != NULL, "failed to get current directory");
simonis@6465 5252 return 0;
simonis@6465 5253 }
simonis@6465 5254
simonis@6465 5255 return strlen(buffer);
simonis@6465 5256 }
simonis@6465 5257
simonis@6465 5258 #ifndef PRODUCT
simonis@6465 5259 void TestReserveMemorySpecial_test() {
simonis@6465 5260 // No tests available for this platform
simonis@6465 5261 }
simonis@6465 5262 #endif

mercurial