src/os/aix/vm/os_aix.cpp

Thu, 27 Dec 2018 11:43:33 +0800

author
aoqi
date
Thu, 27 Dec 2018 11:43:33 +0800
changeset 9448
73d689add964
parent 9417
65409bcab2ad
parent 7994
04ff2f6cd0eb
child 9637
eef07cd490d4
permissions
-rw-r--r--

Merge

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

mercurial