comparison src/os/bsd/vm/os_bsd.cpp @ 14909:4ca6dc0799b6

Backout jdk9 merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 01 Apr 2014 13:57:07 +0200
parents d8041d695d19
children b1911c1e44c8
comparison
equal deleted inserted replaced
14908:8db6e76cb658 14909:4ca6dc0799b6
1 /* 1 /*
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
217 static char cpu_arch[] = "i386"; 217 static char cpu_arch[] = "i386";
218 #elif defined(AMD64) 218 #elif defined(AMD64)
219 static char cpu_arch[] = "amd64"; 219 static char cpu_arch[] = "amd64";
220 #elif defined(ARM) 220 #elif defined(ARM)
221 static char cpu_arch[] = "arm"; 221 static char cpu_arch[] = "arm";
222 #elif defined(PPC32) 222 #elif defined(PPC)
223 static char cpu_arch[] = "ppc"; 223 static char cpu_arch[] = "ppc";
224 #elif defined(SPARC) 224 #elif defined(SPARC)
225 # ifdef _LP64 225 # ifdef _LP64
226 static char cpu_arch[] = "sparcv9"; 226 static char cpu_arch[] = "sparcv9";
227 # else 227 # else
992 } 992 }
993 #endif 993 #endif
994 994
995 995
996 jlong os::javaTimeNanos() { 996 jlong os::javaTimeNanos() {
997 if (os::supports_monotonic_clock()) { 997 if (Bsd::supports_monotonic_clock()) {
998 struct timespec tp; 998 struct timespec tp;
999 int status = Bsd::clock_gettime(CLOCK_MONOTONIC, &tp); 999 int status = Bsd::clock_gettime(CLOCK_MONOTONIC, &tp);
1000 assert(status == 0, "gettime error"); 1000 assert(status == 0, "gettime error");
1001 jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec); 1001 jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec);
1002 return result; 1002 return result;
1008 return 1000 * usecs; 1008 return 1000 * usecs;
1009 } 1009 }
1010 } 1010 }
1011 1011
1012 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { 1012 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
1013 if (os::supports_monotonic_clock()) { 1013 if (Bsd::supports_monotonic_clock()) {
1014 info_ptr->max_value = ALL_64_BITS; 1014 info_ptr->max_value = ALL_64_BITS;
1015 1015
1016 // CLOCK_MONOTONIC - amount of time since some arbitrary point in the past 1016 // CLOCK_MONOTONIC - amount of time since some arbitrary point in the past
1017 info_ptr->may_skip_backward = false; // not subject to resetting or drifting 1017 info_ptr->may_skip_backward = false; // not subject to resetting or drifting
1018 info_ptr->may_skip_forward = false; // not subject to resetting or drifting 1018 info_ptr->may_skip_forward = false; // not subject to resetting or drifting
1555 1555
1556 return NULL; 1556 return NULL;
1557 } 1557 }
1558 #endif /* !__APPLE__ */ 1558 #endif /* !__APPLE__ */
1559 1559
1560 void* os::get_default_process_handle() {
1561 #ifdef __APPLE__
1562 // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY
1563 // to avoid finding unexpected symbols on second (or later)
1564 // loads of a library.
1565 return (void*)::dlopen(NULL, RTLD_FIRST);
1566 #else
1567 return (void*)::dlopen(NULL, RTLD_LAZY);
1568 #endif
1569 }
1570
1571 // XXX: Do we need a lock around this as per Linux? 1560 // XXX: Do we need a lock around this as per Linux?
1572 void* os::dll_lookup(void* handle, const char* name) { 1561 void* os::dll_lookup(void* handle, const char* name) {
1573 return dlsym(handle, name); 1562 return dlsym(handle, name);
1574 } 1563 }
1575 1564
1675 st->print("\n/proc/meminfo:\n"); 1664 st->print("\n/proc/meminfo:\n");
1676 _print_ascii_file("/proc/meminfo", st); 1665 _print_ascii_file("/proc/meminfo", st);
1677 st->cr(); 1666 st->cr();
1678 } 1667 }
1679 1668
1669 // Taken from /usr/include/bits/siginfo.h Supposed to be architecture specific
1670 // but they're the same for all the bsd arch that we support
1671 // and they're the same for solaris but there's no common place to put this.
1672 const char *ill_names[] = { "ILL0", "ILL_ILLOPC", "ILL_ILLOPN", "ILL_ILLADR",
1673 "ILL_ILLTRP", "ILL_PRVOPC", "ILL_PRVREG",
1674 "ILL_COPROC", "ILL_BADSTK" };
1675
1676 const char *fpe_names[] = { "FPE0", "FPE_INTDIV", "FPE_INTOVF", "FPE_FLTDIV",
1677 "FPE_FLTOVF", "FPE_FLTUND", "FPE_FLTRES",
1678 "FPE_FLTINV", "FPE_FLTSUB", "FPE_FLTDEN" };
1679
1680 const char *segv_names[] = { "SEGV0", "SEGV_MAPERR", "SEGV_ACCERR" };
1681
1682 const char *bus_names[] = { "BUS0", "BUS_ADRALN", "BUS_ADRERR", "BUS_OBJERR" };
1683
1680 void os::print_siginfo(outputStream* st, void* siginfo) { 1684 void os::print_siginfo(outputStream* st, void* siginfo) {
1681 const siginfo_t* si = (const siginfo_t*)siginfo; 1685 st->print("siginfo:");
1682 1686
1683 os::Posix::print_siginfo_brief(st, si); 1687 const int buflen = 100;
1684 1688 char buf[buflen];
1685 if (si && (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) && 1689 siginfo_t *si = (siginfo_t*)siginfo;
1690 st->print("si_signo=%s: ", os::exception_name(si->si_signo, buf, buflen));
1691 if (si->si_errno != 0 && strerror_r(si->si_errno, buf, buflen) == 0) {
1692 st->print("si_errno=%s", buf);
1693 } else {
1694 st->print("si_errno=%d", si->si_errno);
1695 }
1696 const int c = si->si_code;
1697 assert(c > 0, "unexpected si_code");
1698 switch (si->si_signo) {
1699 case SIGILL:
1700 st->print(", si_code=%d (%s)", c, c > 8 ? "" : ill_names[c]);
1701 st->print(", si_addr=" PTR_FORMAT, si->si_addr);
1702 break;
1703 case SIGFPE:
1704 st->print(", si_code=%d (%s)", c, c > 9 ? "" : fpe_names[c]);
1705 st->print(", si_addr=" PTR_FORMAT, si->si_addr);
1706 break;
1707 case SIGSEGV:
1708 st->print(", si_code=%d (%s)", c, c > 2 ? "" : segv_names[c]);
1709 st->print(", si_addr=" PTR_FORMAT, si->si_addr);
1710 break;
1711 case SIGBUS:
1712 st->print(", si_code=%d (%s)", c, c > 3 ? "" : bus_names[c]);
1713 st->print(", si_addr=" PTR_FORMAT, si->si_addr);
1714 break;
1715 default:
1716 st->print(", si_code=%d", si->si_code);
1717 // no si_addr
1718 }
1719
1720 if ((si->si_signo == SIGBUS || si->si_signo == SIGSEGV) &&
1686 UseSharedSpaces) { 1721 UseSharedSpaces) {
1687 FileMapInfo* mapinfo = FileMapInfo::current_info(); 1722 FileMapInfo* mapinfo = FileMapInfo::current_info();
1688 if (mapinfo->is_in_shared_space(si->si_addr)) { 1723 if (mapinfo->is_in_shared_space(si->si_addr)) {
1689 st->print("\n\nError accessing class data sharing archive." \ 1724 st->print("\n\nError accessing class data sharing archive." \
1690 " Mapped file inaccessible during execution, " \ 1725 " Mapped file inaccessible during execution, " \
1740 rp = realpath(dli_fname, buf); 1775 rp = realpath(dli_fname, buf);
1741 } 1776 }
1742 if (rp == NULL) 1777 if (rp == NULL)
1743 return; 1778 return;
1744 1779
1745 if (Arguments::sun_java_launcher_is_altjvm()) { 1780 if (Arguments::created_by_gamma_launcher()) {
1746 // Support for the java launcher's '-XXaltjvm=<path>' option. Typical 1781 // Support for the gamma launcher. Typical value for buf is
1747 // value for buf is "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so" 1782 // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm". If "/jre/lib/" appears at
1748 // or "<JAVA_HOME>/jre/lib/<vmtype>/libjvm.dylib". If "/jre/lib/" 1783 // the right place in the string, then assume we are installed in a JDK and
1749 // appears at the right place in the string, then assume we are 1784 // we're done. Otherwise, check for a JAVA_HOME environment variable and
1750 // installed in a JDK and we're done. Otherwise, check for a 1785 // construct a path to the JVM being overridden.
1751 // JAVA_HOME environment variable and construct a path to the JVM
1752 // being overridden.
1753 1786
1754 const char *p = buf + strlen(buf) - 1; 1787 const char *p = buf + strlen(buf) - 1;
1755 for (int count = 0; p > buf && count < 5; ++count) { 1788 for (int count = 0; p > buf && count < 5; ++count) {
1756 for (--p; p > buf && *p != '/'; --p) 1789 for (--p; p > buf && *p != '/'; --p)
1757 /* empty */ ; 1790 /* empty */ ;
1786 // Add the appropriate client or server subdir 1819 // Add the appropriate client or server subdir
1787 len = strlen(buf); 1820 len = strlen(buf);
1788 jrelib_p = buf + len; 1821 jrelib_p = buf + len;
1789 snprintf(jrelib_p, buflen-len, "/%s", COMPILER_VARIANT); 1822 snprintf(jrelib_p, buflen-len, "/%s", COMPILER_VARIANT);
1790 if (0 != access(buf, F_OK)) { 1823 if (0 != access(buf, F_OK)) {
1791 snprintf(jrelib_p, buflen-len, "%s", ""); 1824 snprintf(jrelib_p, buflen-len, "");
1792 } 1825 }
1793 1826
1794 // If the path exists within JAVA_HOME, add the JVM library name 1827 // If the path exists within JAVA_HOME, add the JVM library name
1795 // to complete the path to JVM being overridden. Otherwise fallback 1828 // to complete the path to JVM being overridden. Otherwise fallback
1796 // to the path to the current library. 1829 // to the path to the current library.
2511 2544
2512 size_t os::read(int fd, void *buf, unsigned int nBytes) { 2545 size_t os::read(int fd, void *buf, unsigned int nBytes) {
2513 RESTARTABLE_RETURN_INT(::read(fd, buf, nBytes)); 2546 RESTARTABLE_RETURN_INT(::read(fd, buf, nBytes));
2514 } 2547 }
2515 2548
2516 void os::naked_short_sleep(jlong ms) { 2549 // TODO-FIXME: reconcile Solaris' os::sleep with the bsd variation.
2517 struct timespec req; 2550 // Solaris uses poll(), bsd uses park().
2518 2551 // Poll() is likely a better choice, assuming that Thread.interrupt()
2519 assert(ms < 1000, "Un-interruptable sleep, short time use only"); 2552 // generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
2520 req.tv_sec = 0; 2553 // SIGSEGV, see 4355769.
2521 if (ms > 0) { 2554
2522 req.tv_nsec = (ms % 1000) * 1000000; 2555 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
2523 } 2556 assert(thread == Thread::current(), "thread consistency check");
2524 else { 2557
2525 req.tv_nsec = 1; 2558 ParkEvent * const slp = thread->_SleepEvent ;
2526 } 2559 slp->reset() ;
2527 2560 OrderAccess::fence() ;
2528 nanosleep(&req, NULL); 2561
2529 2562 if (interruptible) {
2530 return; 2563 jlong prevtime = javaTimeNanos();
2564
2565 for (;;) {
2566 if (os::is_interrupted(thread, true)) {
2567 return OS_INTRPT;
2568 }
2569
2570 jlong newtime = javaTimeNanos();
2571
2572 if (newtime - prevtime < 0) {
2573 // time moving backwards, should only happen if no monotonic clock
2574 // not a guarantee() because JVM should not abort on kernel/glibc bugs
2575 assert(!Bsd::supports_monotonic_clock(), "time moving backwards");
2576 } else {
2577 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
2578 }
2579
2580 if(millis <= 0) {
2581 return OS_OK;
2582 }
2583
2584 prevtime = newtime;
2585
2586 {
2587 assert(thread->is_Java_thread(), "sanity check");
2588 JavaThread *jt = (JavaThread *) thread;
2589 ThreadBlockInVM tbivm(jt);
2590 OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */);
2591
2592 jt->set_suspend_equivalent();
2593 // cleared by handle_special_suspend_equivalent_condition() or
2594 // java_suspend_self() via check_and_wait_while_suspended()
2595
2596 slp->park(millis);
2597
2598 // were we externally suspended while we were waiting?
2599 jt->check_and_wait_while_suspended();
2600 }
2601 }
2602 } else {
2603 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
2604 jlong prevtime = javaTimeNanos();
2605
2606 for (;;) {
2607 // It'd be nice to avoid the back-to-back javaTimeNanos() calls on
2608 // the 1st iteration ...
2609 jlong newtime = javaTimeNanos();
2610
2611 if (newtime - prevtime < 0) {
2612 // time moving backwards, should only happen if no monotonic clock
2613 // not a guarantee() because JVM should not abort on kernel/glibc bugs
2614 assert(!Bsd::supports_monotonic_clock(), "time moving backwards");
2615 } else {
2616 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
2617 }
2618
2619 if(millis <= 0) break ;
2620
2621 prevtime = newtime;
2622 slp->park(millis);
2623 }
2624 return OS_OK ;
2625 }
2626 }
2627
2628 int os::naked_sleep() {
2629 // %% make the sleep time an integer flag. for now use 1 millisec.
2630 return os::sleep(Thread::current(), 1, false);
2531 } 2631 }
2532 2632
2533 // Sleep forever; naked call to OS-specific sleep; use with CAUTION 2633 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
2534 void os::infinite_sleep() { 2634 void os::infinite_sleep() {
2535 while (true) { // sleep forever ... 2635 while (true) { // sleep forever ...
2904 ShouldNotReachHere(); 3004 ShouldNotReachHere();
2905 } 3005 }
2906 } 3006 }
2907 3007
2908 guarantee(osthread->sr.is_running(), "Must be running!"); 3008 guarantee(osthread->sr.is_running(), "Must be running!");
3009 }
3010
3011 ////////////////////////////////////////////////////////////////////////////////
3012 // interrupt support
3013
3014 void os::interrupt(Thread* thread) {
3015 assert(Thread::current() == thread || Threads_lock->owned_by_self(),
3016 "possibility of dangling Thread pointer");
3017
3018 OSThread* osthread = thread->osthread();
3019
3020 if (!osthread->interrupted()) {
3021 osthread->set_interrupted(true);
3022 // More than one thread can get here with the same value of osthread,
3023 // resulting in multiple notifications. We do, however, want the store
3024 // to interrupted() to be visible to other threads before we execute unpark().
3025 OrderAccess::fence();
3026 ParkEvent * const slp = thread->_SleepEvent ;
3027 if (slp != NULL) slp->unpark() ;
3028 }
3029
3030 // For JSR166. Unpark even if interrupt status already was set
3031 if (thread->is_Java_thread())
3032 ((JavaThread*)thread)->parker()->unpark();
3033
3034 ParkEvent * ev = thread->_ParkEvent ;
3035 if (ev != NULL) ev->unpark() ;
3036
3037 }
3038
3039 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
3040 assert(Thread::current() == thread || Threads_lock->owned_by_self(),
3041 "possibility of dangling Thread pointer");
3042
3043 OSThread* osthread = thread->osthread();
3044
3045 bool interrupted = osthread->interrupted();
3046
3047 if (interrupted && clear_interrupted) {
3048 osthread->set_interrupted(false);
3049 // consider thread->_SleepEvent->reset() ... optional optimization
3050 }
3051
3052 return interrupted;
2909 } 3053 }
2910 3054
2911 /////////////////////////////////////////////////////////////////////////////////// 3055 ///////////////////////////////////////////////////////////////////////////////////
2912 // signal handling (except suspend/resume) 3056 // signal handling (except suspend/resume)
2913 3057
3246 st->print("SIG_IGN"); 3390 st->print("SIG_IGN");
3247 } else { 3391 } else {
3248 st->print("[%s]", get_signal_handler_name(handler, buf, buflen)); 3392 st->print("[%s]", get_signal_handler_name(handler, buf, buflen));
3249 } 3393 }
3250 3394
3251 st->print(", sa_mask[0]="); 3395 st->print(", sa_mask[0]=" PTR32_FORMAT, *(uint32_t*)&sa.sa_mask);
3252 os::Posix::print_signal_set_short(st, &sa.sa_mask);
3253 3396
3254 address rh = VMError::get_resetted_sighandler(sig); 3397 address rh = VMError::get_resetted_sighandler(sig);
3255 // May be, handler was resetted by VMError? 3398 // May be, handler was resetted by VMError?
3256 if(rh != NULL) { 3399 if(rh != NULL) {
3257 handler = rh; 3400 handler = rh;
3258 sa.sa_flags = VMError::get_resetted_sigflags(sig) & SIGNIFICANT_SIGNAL_MASK; 3401 sa.sa_flags = VMError::get_resetted_sigflags(sig) & SIGNIFICANT_SIGNAL_MASK;
3259 } 3402 }
3260 3403
3261 st->print(", sa_flags="); 3404 st->print(", sa_flags=" PTR32_FORMAT, sa.sa_flags);
3262 os::Posix::print_sa_flags(st, sa.sa_flags);
3263 3405
3264 // Check: is it our handler? 3406 // Check: is it our handler?
3265 if(handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler) || 3407 if(handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler) ||
3266 handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) { 3408 handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
3267 // It is our signal handler 3409 // It is our signal handler