431 // hard limit
432 st->print("/");
433 if (rlim.rlim_max == RLIM_INFINITY) { st->print("infinity"); }
434 else {
435 if (output_k) { st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_max) / 1024); }
436 else { st->print(UINT64_FORMAT, uint64_t(rlim.rlim_max)); }
437 }
438 }
439 }
440
441 void os::Posix::print_rlimit_info(outputStream* st) {
442 st->print("rlimit (soft/hard):");
443 print_rlimit(st, "STACK", RLIMIT_STACK, true);
444 print_rlimit(st, ", CORE", RLIMIT_CORE, true);
445
446 #if defined(AIX)
447 st->print(", NPROC ");
448 st->print("%d", sysconf(_SC_CHILD_MAX));
449
450 print_rlimit(st, ", THREADS", RLIMIT_THREADS);
451 #elif !defined(SOLARIS)
452 print_rlimit(st, ", NPROC", RLIMIT_NPROC);
453 #endif
454
455 print_rlimit(st, ", NOFILE", RLIMIT_NOFILE);
456 print_rlimit(st, ", AS", RLIMIT_AS, true);
457 print_rlimit(st, ", CPU", RLIMIT_CPU);
458 print_rlimit(st, ", DATA", RLIMIT_DATA, true);
459
460 // maximum size of files that the process may create
461 print_rlimit(st, ", FSIZE", RLIMIT_FSIZE, true);
462
463 #if defined(LINUX) || defined(__APPLE__)
464 // maximum number of bytes of memory that may be locked into RAM
465 // (rounded down to the nearest multiple of system pagesize)
466 print_rlimit(st, ", MEMLOCK", RLIMIT_MEMLOCK, true);
467 #endif
468
469 #if defined(SOLARIS)
470 // maximum size of mapped address space of a process in bytes;
471 // if the limit is exceeded, mmap and brk fail
472 print_rlimit(st, ", VMEM", RLIMIT_VMEM, true);
473 #endif
474
475 // MacOS; The maximum size (in bytes) to which a process's resident set size may grow.
476 #if defined(__APPLE__)
477 print_rlimit(st, ", RSS", RLIMIT_RSS, true);
478 #endif
479
480 st->cr();
481 }
482
483 void os::Posix::print_uname_info(outputStream* st) {
484 // kernel
485 st->print("uname:");
486 struct utsname name;
487 uname(&name);
488 st->print("%s ", name.sysname);
489 #ifdef ASSERT
490 st->print("%s ", name.nodename);
491 #endif
492 st->print("%s ", name.release);
493 st->print("%s ", name.version);
494 st->print("%s", name.machine);
1078 { SIGILL, ILL_BADIADDR, "ILL_BADIADDR", "Unimplemented instruction address" },
1079 { SIGILL, ILL_BREAK, "ILL_BREAK", "Application Break instruction" },
1080 #endif
1081 { SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero." },
1082 { SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow." },
1083 { SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating-point divide by zero." },
1084 { SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating-point overflow." },
1085 { SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating-point underflow." },
1086 { SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating-point inexact result." },
1087 { SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating-point operation." },
1088 { SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range." },
1089 { SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object." },
1090 { SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for mapped object." },
1091 #ifdef AIX
1092 // no explanation found what keyerr would be
1093 { SIGSEGV, SEGV_KEYERR, "SEGV_KEYERR", "key error" },
1094 #endif
1095 #if defined(IA64) && !defined(AIX)
1096 { SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" },
1097 #endif
1098 #if defined(__sparc) && defined(SOLARIS)
1099 // define Solaris Sparc M7 ADI SEGV signals
1100 #if !defined(SEGV_ACCADI)
1101 #define SEGV_ACCADI 3
1102 #endif
1103 { SIGSEGV, SEGV_ACCADI, "SEGV_ACCADI", "ADI not enabled for mapped object." },
1104 #if !defined(SEGV_ACCDERR)
1105 #define SEGV_ACCDERR 4
1106 #endif
1107 { SIGSEGV, SEGV_ACCDERR, "SEGV_ACCDERR", "ADI disrupting exception." },
1108 #if !defined(SEGV_ACCPERR)
1109 #define SEGV_ACCPERR 5
1110 #endif
1111 { SIGSEGV, SEGV_ACCPERR, "SEGV_ACCPERR", "ADI precise exception." },
1112 #endif // defined(__sparc) && defined(SOLARIS)
1113 { SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment." },
1114 { SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Nonexistent physical address." },
1115 { SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object-specific hardware error." },
1116 { SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint." },
1117 { SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap." },
1118 { SIGCHLD, CLD_EXITED, "CLD_EXITED", "Child has exited." },
1119 { SIGCHLD, CLD_KILLED, "CLD_KILLED", "Child has terminated abnormally and did not create a core file." },
1120 { SIGCHLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally and created a core file." },
1121 { SIGCHLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped." },
1122 { SIGCHLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped." },
1123 { SIGCHLD, CLD_CONTINUED,"CLD_CONTINUED","Stopped child has continued." },
1124 #ifdef SIGPOLL
1125 { SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available." },
1126 { SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available." },
1127 { SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error." },
1128 { SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available." },
1129 { SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected. [Option End]" },
1130 #endif
1131 { -1, -1, NULL, NULL }
1132 };
1251 os->print(" (invalid)");
1252 }
1253 os->print(", si_uid: %ld", (long) si->si_uid);
1254 if (sig == SIGCHLD) {
1255 os->print(", si_status: %d", si->si_status);
1256 }
1257 } else if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
1258 sig == SIGTRAP || sig == SIGFPE) {
1259 os->print(", si_addr: " PTR_FORMAT, p2i(si->si_addr));
1260 #ifdef SIGPOLL
1261 } else if (sig == SIGPOLL) {
1262 os->print(", si_band: %ld", si->si_band);
1263 #endif
1264 }
1265
1266 }
1267
1268 bool os::signal_thread(Thread* thread, int sig, const char* reason) {
1269 OSThread* osthread = thread->osthread();
1270 if (osthread) {
1271 #if defined (SOLARIS)
1272 // Note: we cannot use pthread_kill on Solaris - not because
1273 // its missing, but because we do not have the pthread_t id.
1274 int status = thr_kill(osthread->thread_id(), sig);
1275 #else
1276 int status = pthread_kill(osthread->pthread_id(), sig);
1277 #endif
1278 if (status == 0) {
1279 Events::log(Thread::current(), "sent signal %d to Thread " INTPTR_FORMAT " because %s.",
1280 sig, p2i(thread), reason);
1281 return true;
1282 }
1283 }
1284 return false;
1285 }
1286
1287 int os::Posix::unblock_thread_signal_mask(const sigset_t *set) {
1288 return pthread_sigmask(SIG_UNBLOCK, set, NULL);
1289 }
1290
1291 address os::Posix::ucontext_get_pc(const ucontext_t* ctx) {
1292 #if defined(AIX)
1293 return Aix::ucontext_get_pc(ctx);
1294 #elif defined(BSD)
1295 return Bsd::ucontext_get_pc(ctx);
1296 #elif defined(LINUX)
1297 return Linux::ucontext_get_pc(ctx);
1298 #elif defined(SOLARIS)
1299 return Solaris::ucontext_get_pc(ctx);
1300 #else
1301 VMError::report_and_die("unimplemented ucontext_get_pc");
1302 #endif
1303 }
1304
1305 void os::Posix::ucontext_set_pc(ucontext_t* ctx, address pc) {
1306 #if defined(AIX)
1307 Aix::ucontext_set_pc(ctx, pc);
1308 #elif defined(BSD)
1309 Bsd::ucontext_set_pc(ctx, pc);
1310 #elif defined(LINUX)
1311 Linux::ucontext_set_pc(ctx, pc);
1312 #elif defined(SOLARIS)
1313 Solaris::ucontext_set_pc(ctx, pc);
1314 #else
1315 VMError::report_and_die("unimplemented ucontext_get_pc");
1316 #endif
1317 }
1318
1319 char* os::Posix::describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr) {
1320 size_t stack_size = 0;
1321 size_t guard_size = 0;
1322 int detachstate = 0;
1323 pthread_attr_getstacksize(attr, &stack_size);
1324 pthread_attr_getguardsize(attr, &guard_size);
1325 // Work around linux NPTL implementation error, see also os::create_thread() in os_linux.cpp.
1326 LINUX_ONLY(stack_size -= guard_size);
1327 pthread_attr_getdetachstate(attr, &detachstate);
1328 jio_snprintf(buf, buflen, "stacksize: " SIZE_FORMAT "k, guardsize: " SIZE_FORMAT "k, %s",
1329 stack_size / 1024, guard_size / 1024,
1330 (detachstate == PTHREAD_CREATE_DETACHED ? "detached" : "joinable"));
1331 return buf;
1332 }
1333
1398 }
1399
1400 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
1401 // same files
1402 is_same = true;
1403 }
1404 return is_same;
1405 }
1406
1407 // Check minimum allowable stack sizes for thread creation and to initialize
1408 // the java system classes, including StackOverflowError - depends on page
1409 // size.
1410 // The space needed for frames during startup is platform dependent. It
1411 // depends on word size, platform calling conventions, C frame layout and
1412 // interpreter/C1/C2 design decisions. Therefore this is given in a
1413 // platform (os/cpu) dependent constant.
1414 // To this, space for guard mechanisms is added, which depends on the
1415 // page size which again depends on the concrete system the VM is running
1416 // on. Space for libc guard pages is not included in this size.
1417 jint os::Posix::set_minimum_stack_sizes() {
1418 size_t os_min_stack_allowed = SOLARIS_ONLY(thr_min_stack()) NOT_SOLARIS(PTHREAD_STACK_MIN);
1419
1420 _java_thread_min_stack_allowed = _java_thread_min_stack_allowed +
1421 JavaThread::stack_guard_zone_size() +
1422 JavaThread::stack_shadow_zone_size();
1423
1424 _java_thread_min_stack_allowed = align_up(_java_thread_min_stack_allowed, vm_page_size());
1425 _java_thread_min_stack_allowed = MAX2(_java_thread_min_stack_allowed, os_min_stack_allowed);
1426
1427 size_t stack_size_in_bytes = ThreadStackSize * K;
1428 if (stack_size_in_bytes != 0 &&
1429 stack_size_in_bytes < _java_thread_min_stack_allowed) {
1430 // The '-Xss' and '-XX:ThreadStackSize=N' options both set
1431 // ThreadStackSize so we go with "Java thread stack size" instead
1432 // of "ThreadStackSize" to be more friendly.
1433 tty->print_cr("\nThe Java thread stack size specified is too small. "
1434 "Specify at least " SIZE_FORMAT "k",
1435 _java_thread_min_stack_allowed / K);
1436 return JNI_ERR;
1437 }
1438
1608 // but otherwise whatever default is used by the platform - generally the
1609 // time-of-day clock.
1610 static pthread_condattr_t _condAttr[1];
1611
1612 // Shared mutexattr to explicitly set the type to PTHREAD_MUTEX_NORMAL as not
1613 // all systems (e.g. FreeBSD) map the default to "normal".
1614 static pthread_mutexattr_t _mutexAttr[1];
1615
1616 // common basic initialization that is always supported
1617 static void pthread_init_common(void) {
1618 int status;
1619 if ((status = pthread_condattr_init(_condAttr)) != 0) {
1620 fatal("pthread_condattr_init: %s", os::strerror(status));
1621 }
1622 if ((status = pthread_mutexattr_init(_mutexAttr)) != 0) {
1623 fatal("pthread_mutexattr_init: %s", os::strerror(status));
1624 }
1625 if ((status = pthread_mutexattr_settype(_mutexAttr, PTHREAD_MUTEX_NORMAL)) != 0) {
1626 fatal("pthread_mutexattr_settype: %s", os::strerror(status));
1627 }
1628 // Solaris has it's own PlatformMutex, distinct from the one for POSIX.
1629 NOT_SOLARIS(os::PlatformMutex::init();)
1630 }
1631
1632 #ifndef SOLARIS
1633 sigset_t sigs;
1634 struct sigaction sigact[NSIG];
1635
1636 struct sigaction* os::Posix::get_preinstalled_handler(int sig) {
1637 if (sigismember(&sigs, sig)) {
1638 return &sigact[sig];
1639 }
1640 return NULL;
1641 }
1642
1643 void os::Posix::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
1644 assert(sig > 0 && sig < NSIG, "vm signal out of expected range");
1645 sigact[sig] = oldAct;
1646 sigaddset(&sigs, sig);
1647 }
1648 #endif
1649
1650 // Not all POSIX types and API's are available on all notionally "posix"
1651 // platforms. If we have build-time support then we will check for actual
1652 // runtime support via dlopen/dlsym lookup. This allows for running on an
1653 // older OS version compared to the build platform. But if there is no
1654 // build time support then there cannot be any runtime support as we do not
1655 // know what the runtime types would be (for example clockid_t might be an
1656 // int or int64_t).
1657 //
1658 #ifdef SUPPORTS_CLOCK_MONOTONIC
1659
1660 // This means we have clockid_t, clock_gettime et al and CLOCK_MONOTONIC
1661
1662 int (*os::Posix::_clock_gettime)(clockid_t, struct timespec *) = NULL;
1663 int (*os::Posix::_clock_getres)(clockid_t, struct timespec *) = NULL;
1664
1665 static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t) = NULL;
1666
1667 static bool _use_clock_monotonic_condattr = false;
1668
1713 dlclose(handle);
1714 }
1715 #endif
1716 }
1717 }
1718
1719 // 2. Check for pthread_condattr_setclock support.
1720
1721 // libpthread is already loaded.
1722 int (*condattr_setclock_func)(pthread_condattr_t*, clockid_t) =
1723 (int (*)(pthread_condattr_t*, clockid_t))dlsym(RTLD_DEFAULT,
1724 "pthread_condattr_setclock");
1725 if (condattr_setclock_func != NULL) {
1726 _pthread_condattr_setclock = condattr_setclock_func;
1727 }
1728
1729 // Now do general initialization.
1730
1731 pthread_init_common();
1732
1733 #ifndef SOLARIS
1734 int status;
1735 if (_pthread_condattr_setclock != NULL && _clock_gettime != NULL) {
1736 if ((status = _pthread_condattr_setclock(_condAttr, CLOCK_MONOTONIC)) != 0) {
1737 if (status == EINVAL) {
1738 _use_clock_monotonic_condattr = false;
1739 warning("Unable to use monotonic clock with relative timed-waits" \
1740 " - changes to the time-of-day clock may have adverse affects");
1741 } else {
1742 fatal("pthread_condattr_setclock: %s", os::strerror(status));
1743 }
1744 } else {
1745 _use_clock_monotonic_condattr = true;
1746 }
1747 }
1748 #endif // !SOLARIS
1749
1750 }
1751
1752 void os::Posix::init_2(void) {
1753 #ifndef SOLARIS
1754 log_info(os)("Use of CLOCK_MONOTONIC is%s supported",
1755 (_clock_gettime != NULL ? "" : " not"));
1756 log_info(os)("Use of pthread_condattr_setclock is%s supported",
1757 (_pthread_condattr_setclock != NULL ? "" : " not"));
1758 log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with %s",
1759 _use_clock_monotonic_condattr ? "CLOCK_MONOTONIC" : "the default clock");
1760 sigemptyset(&sigs);
1761 #endif // !SOLARIS
1762 }
1763
1764 #else // !SUPPORTS_CLOCK_MONOTONIC
1765
1766 void os::Posix::init(void) {
1767 pthread_init_common();
1768 }
1769
1770 void os::Posix::init_2(void) {
1771 #ifndef SOLARIS
1772 log_info(os)("Use of CLOCK_MONOTONIC is not supported");
1773 log_info(os)("Use of pthread_condattr_setclock is not supported");
1774 log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with the default clock");
1775 sigemptyset(&sigs);
1776 #endif // !SOLARIS
1777 }
1778
1779 #endif // SUPPORTS_CLOCK_MONOTONIC
1780
1781 // Utility to convert the given timeout to an absolute timespec
1782 // (based on the appropriate clock) to use with pthread_cond_timewait,
1783 // and sem_timedwait().
1784 // The clock queried here must be the clock used to manage the
1785 // timeout of the condition variable or semaphore.
1786 //
1787 // The passed in timeout value is either a relative time in nanoseconds
1788 // or an absolute time in milliseconds. A relative timeout will be
1789 // associated with CLOCK_MONOTONIC if available, unless the real-time clock
1790 // is explicitly requested; otherwise, or if absolute,
1791 // the default time-of-day clock will be used.
1792
1793 // Given time is a 64-bit value and the time_t used in the timespec is
1794 // sometimes a signed-32-bit value we have to watch for overflow if times
1795 // way in the future are given. Further on Solaris versions
1796 // prior to 10 there is a restriction (see cond_timedwait) that the specified
1897 DEBUG_ONLY(max_secs += now.tv_sec;)
1898 }
1899
1900 assert(abstime->tv_sec >= 0, "tv_sec < 0");
1901 assert(abstime->tv_sec <= max_secs, "tv_sec > max_secs");
1902 assert(abstime->tv_nsec >= 0, "tv_nsec < 0");
1903 assert(abstime->tv_nsec < NANOUNITS, "tv_nsec >= NANOUNITS");
1904 }
1905
1906 // Create an absolute time 'millis' milliseconds in the future, using the
1907 // real-time (time-of-day) clock. Used by PosixSemaphore.
1908 void os::Posix::to_RTC_abstime(timespec* abstime, int64_t millis) {
1909 to_abstime(abstime, millis_to_nanos_bounded(millis),
1910 false /* not absolute */,
1911 true /* use real-time clock */);
1912 }
1913
1914 // Shared pthread_mutex/cond based PlatformEvent implementation.
1915 // Not currently usable by Solaris.
1916
1917 #ifndef SOLARIS
1918
1919 // PlatformEvent
1920 //
1921 // Assumption:
1922 // Only one parker can exist on an event, which is why we allocate
1923 // them per-thread. Multiple unparkers can coexist.
1924 //
1925 // _event serves as a restricted-range semaphore.
1926 // -1 : thread is blocked, i.e. there is a waiter
1927 // 0 : neutral: thread is running or ready,
1928 // could have been signaled after a wait started
1929 // 1 : signaled - thread is running or ready
1930 //
1931 // Having three states allows for some detection of bad usage - see
1932 // comments on unpark().
1933
1934 os::PlatformEvent::PlatformEvent() {
1935 int status = pthread_cond_init(_cond, _condAttr);
1936 assert_status(status == 0, status, "cond_init");
1937 status = pthread_mutex_init(_mutex, _mutexAttr);
2326 // MAX_SECS anyway, so just do that here.
2327 if (millis / MILLIUNITS > MAX_SECS) {
2328 millis = jlong(MAX_SECS) * MILLIUNITS;
2329 }
2330 to_abstime(&abst, millis_to_nanos(millis), false, false);
2331
2332 int ret = OS_TIMEOUT;
2333 int status = pthread_cond_timedwait(cond(), mutex(), &abst);
2334 assert_status(status == 0 || status == ETIMEDOUT,
2335 status, "cond_timedwait");
2336 if (status == 0) {
2337 ret = OS_OK;
2338 }
2339 return ret;
2340 } else {
2341 int status = pthread_cond_wait(cond(), mutex());
2342 assert_status(status == 0, status, "cond_wait");
2343 return OS_OK;
2344 }
2345 }
2346
2347 #endif // !SOLARIS
|
431 // hard limit
432 st->print("/");
433 if (rlim.rlim_max == RLIM_INFINITY) { st->print("infinity"); }
434 else {
435 if (output_k) { st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_max) / 1024); }
436 else { st->print(UINT64_FORMAT, uint64_t(rlim.rlim_max)); }
437 }
438 }
439 }
440
441 void os::Posix::print_rlimit_info(outputStream* st) {
442 st->print("rlimit (soft/hard):");
443 print_rlimit(st, "STACK", RLIMIT_STACK, true);
444 print_rlimit(st, ", CORE", RLIMIT_CORE, true);
445
446 #if defined(AIX)
447 st->print(", NPROC ");
448 st->print("%d", sysconf(_SC_CHILD_MAX));
449
450 print_rlimit(st, ", THREADS", RLIMIT_THREADS);
451 #else
452 print_rlimit(st, ", NPROC", RLIMIT_NPROC);
453 #endif
454
455 print_rlimit(st, ", NOFILE", RLIMIT_NOFILE);
456 print_rlimit(st, ", AS", RLIMIT_AS, true);
457 print_rlimit(st, ", CPU", RLIMIT_CPU);
458 print_rlimit(st, ", DATA", RLIMIT_DATA, true);
459
460 // maximum size of files that the process may create
461 print_rlimit(st, ", FSIZE", RLIMIT_FSIZE, true);
462
463 #if defined(LINUX) || defined(__APPLE__)
464 // maximum number of bytes of memory that may be locked into RAM
465 // (rounded down to the nearest multiple of system pagesize)
466 print_rlimit(st, ", MEMLOCK", RLIMIT_MEMLOCK, true);
467 #endif
468
469 // MacOS; The maximum size (in bytes) to which a process's resident set size may grow.
470 #if defined(__APPLE__)
471 print_rlimit(st, ", RSS", RLIMIT_RSS, true);
472 #endif
473
474 st->cr();
475 }
476
477 void os::Posix::print_uname_info(outputStream* st) {
478 // kernel
479 st->print("uname:");
480 struct utsname name;
481 uname(&name);
482 st->print("%s ", name.sysname);
483 #ifdef ASSERT
484 st->print("%s ", name.nodename);
485 #endif
486 st->print("%s ", name.release);
487 st->print("%s ", name.version);
488 st->print("%s", name.machine);
1072 { SIGILL, ILL_BADIADDR, "ILL_BADIADDR", "Unimplemented instruction address" },
1073 { SIGILL, ILL_BREAK, "ILL_BREAK", "Application Break instruction" },
1074 #endif
1075 { SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero." },
1076 { SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow." },
1077 { SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating-point divide by zero." },
1078 { SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating-point overflow." },
1079 { SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating-point underflow." },
1080 { SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating-point inexact result." },
1081 { SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating-point operation." },
1082 { SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range." },
1083 { SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object." },
1084 { SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for mapped object." },
1085 #ifdef AIX
1086 // no explanation found what keyerr would be
1087 { SIGSEGV, SEGV_KEYERR, "SEGV_KEYERR", "key error" },
1088 #endif
1089 #if defined(IA64) && !defined(AIX)
1090 { SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" },
1091 #endif
1092 { SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment." },
1093 { SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Nonexistent physical address." },
1094 { SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object-specific hardware error." },
1095 { SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint." },
1096 { SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap." },
1097 { SIGCHLD, CLD_EXITED, "CLD_EXITED", "Child has exited." },
1098 { SIGCHLD, CLD_KILLED, "CLD_KILLED", "Child has terminated abnormally and did not create a core file." },
1099 { SIGCHLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally and created a core file." },
1100 { SIGCHLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped." },
1101 { SIGCHLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped." },
1102 { SIGCHLD, CLD_CONTINUED,"CLD_CONTINUED","Stopped child has continued." },
1103 #ifdef SIGPOLL
1104 { SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available." },
1105 { SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available." },
1106 { SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error." },
1107 { SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available." },
1108 { SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected. [Option End]" },
1109 #endif
1110 { -1, -1, NULL, NULL }
1111 };
1230 os->print(" (invalid)");
1231 }
1232 os->print(", si_uid: %ld", (long) si->si_uid);
1233 if (sig == SIGCHLD) {
1234 os->print(", si_status: %d", si->si_status);
1235 }
1236 } else if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
1237 sig == SIGTRAP || sig == SIGFPE) {
1238 os->print(", si_addr: " PTR_FORMAT, p2i(si->si_addr));
1239 #ifdef SIGPOLL
1240 } else if (sig == SIGPOLL) {
1241 os->print(", si_band: %ld", si->si_band);
1242 #endif
1243 }
1244
1245 }
1246
1247 bool os::signal_thread(Thread* thread, int sig, const char* reason) {
1248 OSThread* osthread = thread->osthread();
1249 if (osthread) {
1250 int status = pthread_kill(osthread->pthread_id(), sig);
1251 if (status == 0) {
1252 Events::log(Thread::current(), "sent signal %d to Thread " INTPTR_FORMAT " because %s.",
1253 sig, p2i(thread), reason);
1254 return true;
1255 }
1256 }
1257 return false;
1258 }
1259
1260 int os::Posix::unblock_thread_signal_mask(const sigset_t *set) {
1261 return pthread_sigmask(SIG_UNBLOCK, set, NULL);
1262 }
1263
1264 address os::Posix::ucontext_get_pc(const ucontext_t* ctx) {
1265 #if defined(AIX)
1266 return Aix::ucontext_get_pc(ctx);
1267 #elif defined(BSD)
1268 return Bsd::ucontext_get_pc(ctx);
1269 #elif defined(LINUX)
1270 return Linux::ucontext_get_pc(ctx);
1271 #else
1272 VMError::report_and_die("unimplemented ucontext_get_pc");
1273 #endif
1274 }
1275
1276 void os::Posix::ucontext_set_pc(ucontext_t* ctx, address pc) {
1277 #if defined(AIX)
1278 Aix::ucontext_set_pc(ctx, pc);
1279 #elif defined(BSD)
1280 Bsd::ucontext_set_pc(ctx, pc);
1281 #elif defined(LINUX)
1282 Linux::ucontext_set_pc(ctx, pc);
1283 #else
1284 VMError::report_and_die("unimplemented ucontext_get_pc");
1285 #endif
1286 }
1287
1288 char* os::Posix::describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr) {
1289 size_t stack_size = 0;
1290 size_t guard_size = 0;
1291 int detachstate = 0;
1292 pthread_attr_getstacksize(attr, &stack_size);
1293 pthread_attr_getguardsize(attr, &guard_size);
1294 // Work around linux NPTL implementation error, see also os::create_thread() in os_linux.cpp.
1295 LINUX_ONLY(stack_size -= guard_size);
1296 pthread_attr_getdetachstate(attr, &detachstate);
1297 jio_snprintf(buf, buflen, "stacksize: " SIZE_FORMAT "k, guardsize: " SIZE_FORMAT "k, %s",
1298 stack_size / 1024, guard_size / 1024,
1299 (detachstate == PTHREAD_CREATE_DETACHED ? "detached" : "joinable"));
1300 return buf;
1301 }
1302
1367 }
1368
1369 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
1370 // same files
1371 is_same = true;
1372 }
1373 return is_same;
1374 }
1375
1376 // Check minimum allowable stack sizes for thread creation and to initialize
1377 // the java system classes, including StackOverflowError - depends on page
1378 // size.
1379 // The space needed for frames during startup is platform dependent. It
1380 // depends on word size, platform calling conventions, C frame layout and
1381 // interpreter/C1/C2 design decisions. Therefore this is given in a
1382 // platform (os/cpu) dependent constant.
1383 // To this, space for guard mechanisms is added, which depends on the
1384 // page size which again depends on the concrete system the VM is running
1385 // on. Space for libc guard pages is not included in this size.
1386 jint os::Posix::set_minimum_stack_sizes() {
1387 size_t os_min_stack_allowed = PTHREAD_STACK_MIN;
1388
1389 _java_thread_min_stack_allowed = _java_thread_min_stack_allowed +
1390 JavaThread::stack_guard_zone_size() +
1391 JavaThread::stack_shadow_zone_size();
1392
1393 _java_thread_min_stack_allowed = align_up(_java_thread_min_stack_allowed, vm_page_size());
1394 _java_thread_min_stack_allowed = MAX2(_java_thread_min_stack_allowed, os_min_stack_allowed);
1395
1396 size_t stack_size_in_bytes = ThreadStackSize * K;
1397 if (stack_size_in_bytes != 0 &&
1398 stack_size_in_bytes < _java_thread_min_stack_allowed) {
1399 // The '-Xss' and '-XX:ThreadStackSize=N' options both set
1400 // ThreadStackSize so we go with "Java thread stack size" instead
1401 // of "ThreadStackSize" to be more friendly.
1402 tty->print_cr("\nThe Java thread stack size specified is too small. "
1403 "Specify at least " SIZE_FORMAT "k",
1404 _java_thread_min_stack_allowed / K);
1405 return JNI_ERR;
1406 }
1407
1577 // but otherwise whatever default is used by the platform - generally the
1578 // time-of-day clock.
1579 static pthread_condattr_t _condAttr[1];
1580
1581 // Shared mutexattr to explicitly set the type to PTHREAD_MUTEX_NORMAL as not
1582 // all systems (e.g. FreeBSD) map the default to "normal".
1583 static pthread_mutexattr_t _mutexAttr[1];
1584
1585 // common basic initialization that is always supported
1586 static void pthread_init_common(void) {
1587 int status;
1588 if ((status = pthread_condattr_init(_condAttr)) != 0) {
1589 fatal("pthread_condattr_init: %s", os::strerror(status));
1590 }
1591 if ((status = pthread_mutexattr_init(_mutexAttr)) != 0) {
1592 fatal("pthread_mutexattr_init: %s", os::strerror(status));
1593 }
1594 if ((status = pthread_mutexattr_settype(_mutexAttr, PTHREAD_MUTEX_NORMAL)) != 0) {
1595 fatal("pthread_mutexattr_settype: %s", os::strerror(status));
1596 }
1597 os::PlatformMutex::init();
1598 }
1599
1600 sigset_t sigs;
1601 struct sigaction sigact[NSIG];
1602
1603 struct sigaction* os::Posix::get_preinstalled_handler(int sig) {
1604 if (sigismember(&sigs, sig)) {
1605 return &sigact[sig];
1606 }
1607 return NULL;
1608 }
1609
1610 void os::Posix::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
1611 assert(sig > 0 && sig < NSIG, "vm signal out of expected range");
1612 sigact[sig] = oldAct;
1613 sigaddset(&sigs, sig);
1614 }
1615
1616 // Not all POSIX types and API's are available on all notionally "posix"
1617 // platforms. If we have build-time support then we will check for actual
1618 // runtime support via dlopen/dlsym lookup. This allows for running on an
1619 // older OS version compared to the build platform. But if there is no
1620 // build time support then there cannot be any runtime support as we do not
1621 // know what the runtime types would be (for example clockid_t might be an
1622 // int or int64_t).
1623 //
1624 #ifdef SUPPORTS_CLOCK_MONOTONIC
1625
1626 // This means we have clockid_t, clock_gettime et al and CLOCK_MONOTONIC
1627
1628 int (*os::Posix::_clock_gettime)(clockid_t, struct timespec *) = NULL;
1629 int (*os::Posix::_clock_getres)(clockid_t, struct timespec *) = NULL;
1630
1631 static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t) = NULL;
1632
1633 static bool _use_clock_monotonic_condattr = false;
1634
1679 dlclose(handle);
1680 }
1681 #endif
1682 }
1683 }
1684
1685 // 2. Check for pthread_condattr_setclock support.
1686
1687 // libpthread is already loaded.
1688 int (*condattr_setclock_func)(pthread_condattr_t*, clockid_t) =
1689 (int (*)(pthread_condattr_t*, clockid_t))dlsym(RTLD_DEFAULT,
1690 "pthread_condattr_setclock");
1691 if (condattr_setclock_func != NULL) {
1692 _pthread_condattr_setclock = condattr_setclock_func;
1693 }
1694
1695 // Now do general initialization.
1696
1697 pthread_init_common();
1698
1699 int status;
1700 if (_pthread_condattr_setclock != NULL && _clock_gettime != NULL) {
1701 if ((status = _pthread_condattr_setclock(_condAttr, CLOCK_MONOTONIC)) != 0) {
1702 if (status == EINVAL) {
1703 _use_clock_monotonic_condattr = false;
1704 warning("Unable to use monotonic clock with relative timed-waits" \
1705 " - changes to the time-of-day clock may have adverse affects");
1706 } else {
1707 fatal("pthread_condattr_setclock: %s", os::strerror(status));
1708 }
1709 } else {
1710 _use_clock_monotonic_condattr = true;
1711 }
1712 }
1713 }
1714
1715 void os::Posix::init_2(void) {
1716 log_info(os)("Use of CLOCK_MONOTONIC is%s supported",
1717 (_clock_gettime != NULL ? "" : " not"));
1718 log_info(os)("Use of pthread_condattr_setclock is%s supported",
1719 (_pthread_condattr_setclock != NULL ? "" : " not"));
1720 log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with %s",
1721 _use_clock_monotonic_condattr ? "CLOCK_MONOTONIC" : "the default clock");
1722 sigemptyset(&sigs);
1723 }
1724
1725 #else // !SUPPORTS_CLOCK_MONOTONIC
1726
1727 void os::Posix::init(void) {
1728 pthread_init_common();
1729 }
1730
1731 void os::Posix::init_2(void) {
1732 log_info(os)("Use of CLOCK_MONOTONIC is not supported");
1733 log_info(os)("Use of pthread_condattr_setclock is not supported");
1734 log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with the default clock");
1735 sigemptyset(&sigs);
1736 }
1737
1738 #endif // SUPPORTS_CLOCK_MONOTONIC
1739
1740 // Utility to convert the given timeout to an absolute timespec
1741 // (based on the appropriate clock) to use with pthread_cond_timewait,
1742 // and sem_timedwait().
1743 // The clock queried here must be the clock used to manage the
1744 // timeout of the condition variable or semaphore.
1745 //
1746 // The passed in timeout value is either a relative time in nanoseconds
1747 // or an absolute time in milliseconds. A relative timeout will be
1748 // associated with CLOCK_MONOTONIC if available, unless the real-time clock
1749 // is explicitly requested; otherwise, or if absolute,
1750 // the default time-of-day clock will be used.
1751
1752 // Given time is a 64-bit value and the time_t used in the timespec is
1753 // sometimes a signed-32-bit value we have to watch for overflow if times
1754 // way in the future are given. Further on Solaris versions
1755 // prior to 10 there is a restriction (see cond_timedwait) that the specified
1856 DEBUG_ONLY(max_secs += now.tv_sec;)
1857 }
1858
1859 assert(abstime->tv_sec >= 0, "tv_sec < 0");
1860 assert(abstime->tv_sec <= max_secs, "tv_sec > max_secs");
1861 assert(abstime->tv_nsec >= 0, "tv_nsec < 0");
1862 assert(abstime->tv_nsec < NANOUNITS, "tv_nsec >= NANOUNITS");
1863 }
1864
1865 // Create an absolute time 'millis' milliseconds in the future, using the
1866 // real-time (time-of-day) clock. Used by PosixSemaphore.
1867 void os::Posix::to_RTC_abstime(timespec* abstime, int64_t millis) {
1868 to_abstime(abstime, millis_to_nanos_bounded(millis),
1869 false /* not absolute */,
1870 true /* use real-time clock */);
1871 }
1872
1873 // Shared pthread_mutex/cond based PlatformEvent implementation.
1874 // Not currently usable by Solaris.
1875
1876
1877 // PlatformEvent
1878 //
1879 // Assumption:
1880 // Only one parker can exist on an event, which is why we allocate
1881 // them per-thread. Multiple unparkers can coexist.
1882 //
1883 // _event serves as a restricted-range semaphore.
1884 // -1 : thread is blocked, i.e. there is a waiter
1885 // 0 : neutral: thread is running or ready,
1886 // could have been signaled after a wait started
1887 // 1 : signaled - thread is running or ready
1888 //
1889 // Having three states allows for some detection of bad usage - see
1890 // comments on unpark().
1891
1892 os::PlatformEvent::PlatformEvent() {
1893 int status = pthread_cond_init(_cond, _condAttr);
1894 assert_status(status == 0, status, "cond_init");
1895 status = pthread_mutex_init(_mutex, _mutexAttr);
2284 // MAX_SECS anyway, so just do that here.
2285 if (millis / MILLIUNITS > MAX_SECS) {
2286 millis = jlong(MAX_SECS) * MILLIUNITS;
2287 }
2288 to_abstime(&abst, millis_to_nanos(millis), false, false);
2289
2290 int ret = OS_TIMEOUT;
2291 int status = pthread_cond_timedwait(cond(), mutex(), &abst);
2292 assert_status(status == 0 || status == ETIMEDOUT,
2293 status, "cond_timedwait");
2294 if (status == 0) {
2295 ret = OS_OK;
2296 }
2297 return ret;
2298 } else {
2299 int status = pthread_cond_wait(cond(), mutex());
2300 assert_status(status == 0, status, "cond_wait");
2301 return OS_OK;
2302 }
2303 }
|