Mercurial > hg > truffle
comparison src/os/linux/vm/os_linux.cpp @ 10408:836a62f43af9
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 19 Jun 2013 10:45:56 +0200 |
parents | 89e4d67fdd2a f2110083203d |
children | 6b0fd0964b87 |
comparison
equal
deleted
inserted
replaced
10086:e0fb8a213650 | 10408:836a62f43af9 |
---|---|
99 # include <link.h> | 99 # include <link.h> |
100 # include <stdint.h> | 100 # include <stdint.h> |
101 # include <inttypes.h> | 101 # include <inttypes.h> |
102 # include <sys/ioctl.h> | 102 # include <sys/ioctl.h> |
103 | 103 |
104 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling | |
105 // getrusage() is prepared to handle the associated failure. | |
106 #ifndef RUSAGE_THREAD | |
107 #define RUSAGE_THREAD (1) /* only the calling thread */ | |
108 #endif | |
109 | |
104 #define MAX_PATH (2 * K) | 110 #define MAX_PATH (2 * K) |
105 | 111 |
106 // for timer info max values which include all bits | 112 // for timer info max values which include all bits |
107 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) | 113 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) |
108 | 114 |
117 int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL; | 123 int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL; |
118 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL; | 124 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL; |
119 Mutex* os::Linux::_createThread_lock = NULL; | 125 Mutex* os::Linux::_createThread_lock = NULL; |
120 pthread_t os::Linux::_main_thread; | 126 pthread_t os::Linux::_main_thread; |
121 int os::Linux::_page_size = -1; | 127 int os::Linux::_page_size = -1; |
128 const int os::Linux::_vm_default_page_size = (8 * K); | |
122 bool os::Linux::_is_floating_stack = false; | 129 bool os::Linux::_is_floating_stack = false; |
123 bool os::Linux::_is_NPTL = false; | 130 bool os::Linux::_is_NPTL = false; |
124 bool os::Linux::_supports_fast_thread_cpu_time = false; | 131 bool os::Linux::_supports_fast_thread_cpu_time = false; |
125 const char * os::Linux::_glibc_version = NULL; | 132 const char * os::Linux::_glibc_version = NULL; |
126 const char * os::Linux::_libpthread_version = NULL; | 133 const char * os::Linux::_libpthread_version = NULL; |
141 static int SR_signum = SIGUSR2; | 148 static int SR_signum = SIGUSR2; |
142 sigset_t SR_sigset; | 149 sigset_t SR_sigset; |
143 | 150 |
144 /* Used to protect dlsym() calls */ | 151 /* Used to protect dlsym() calls */ |
145 static pthread_mutex_t dl_mutex; | 152 static pthread_mutex_t dl_mutex; |
153 | |
154 // Declarations | |
155 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time); | |
146 | 156 |
147 #ifdef JAVASE_EMBEDDED | 157 #ifdef JAVASE_EMBEDDED |
148 class MemNotifyThread: public Thread { | 158 class MemNotifyThread: public Thread { |
149 friend class VMStructs; | 159 friend class VMStructs; |
150 public: | 160 public: |
1333 | 1343 |
1334 jlong os::elapsed_frequency() { | 1344 jlong os::elapsed_frequency() { |
1335 return (1000 * 1000); | 1345 return (1000 * 1000); |
1336 } | 1346 } |
1337 | 1347 |
1338 // For now, we say that linux does not support vtime. I have no idea | 1348 bool os::supports_vtime() { return true; } |
1339 // whether it can actually be made to (DLD, 9/13/05). | |
1340 | |
1341 bool os::supports_vtime() { return false; } | |
1342 bool os::enable_vtime() { return false; } | 1349 bool os::enable_vtime() { return false; } |
1343 bool os::vtime_enabled() { return false; } | 1350 bool os::vtime_enabled() { return false; } |
1351 | |
1344 double os::elapsedVTime() { | 1352 double os::elapsedVTime() { |
1345 // better than nothing, but not much | 1353 struct rusage usage; |
1346 return elapsedTime(); | 1354 int retval = getrusage(RUSAGE_THREAD, &usage); |
1355 if (retval == 0) { | |
1356 return (double) (usage.ru_utime.tv_sec + usage.ru_stime.tv_sec) + (double) (usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) / (1000 * 1000); | |
1357 } else { | |
1358 // better than nothing, but not much | |
1359 return elapsedTime(); | |
1360 } | |
1347 } | 1361 } |
1348 | 1362 |
1349 jlong os::javaTimeMillis() { | 1363 jlong os::javaTimeMillis() { |
1350 timeval time; | 1364 timeval time; |
1351 int status = gettimeofday(&time, NULL); | 1365 int status = gettimeofday(&time, NULL); |
1658 } else { | 1672 } else { |
1659 snprintf(buffer, buflen, "%s/lib%s.so", pname, fname); | 1673 snprintf(buffer, buflen, "%s/lib%s.so", pname, fname); |
1660 retval = true; | 1674 retval = true; |
1661 } | 1675 } |
1662 return retval; | 1676 return retval; |
1663 } | |
1664 | |
1665 const char* os::get_current_directory(char *buf, int buflen) { | |
1666 return getcwd(buf, buflen); | |
1667 } | 1677 } |
1668 | 1678 |
1669 // check if addr is inside libjvm.so | 1679 // check if addr is inside libjvm.so |
1670 bool os::address_is_in_vm(address addr) { | 1680 bool os::address_is_in_vm(address addr) { |
1671 static address libjvm_base_addr; | 1681 static address libjvm_base_addr; |
2398 | 2408 |
2399 void* os::user_handler() { | 2409 void* os::user_handler() { |
2400 return CAST_FROM_FN_PTR(void*, UserHandler); | 2410 return CAST_FROM_FN_PTR(void*, UserHandler); |
2401 } | 2411 } |
2402 | 2412 |
2413 class Semaphore : public StackObj { | |
2414 public: | |
2415 Semaphore(); | |
2416 ~Semaphore(); | |
2417 void signal(); | |
2418 void wait(); | |
2419 bool trywait(); | |
2420 bool timedwait(unsigned int sec, int nsec); | |
2421 private: | |
2422 sem_t _semaphore; | |
2423 }; | |
2424 | |
2425 | |
2426 Semaphore::Semaphore() { | |
2427 sem_init(&_semaphore, 0, 0); | |
2428 } | |
2429 | |
2430 Semaphore::~Semaphore() { | |
2431 sem_destroy(&_semaphore); | |
2432 } | |
2433 | |
2434 void Semaphore::signal() { | |
2435 sem_post(&_semaphore); | |
2436 } | |
2437 | |
2438 void Semaphore::wait() { | |
2439 sem_wait(&_semaphore); | |
2440 } | |
2441 | |
2442 bool Semaphore::trywait() { | |
2443 return sem_trywait(&_semaphore) == 0; | |
2444 } | |
2445 | |
2446 bool Semaphore::timedwait(unsigned int sec, int nsec) { | |
2447 struct timespec ts; | |
2448 unpackTime(&ts, false, (sec * NANOSECS_PER_SEC) + nsec); | |
2449 | |
2450 while (1) { | |
2451 int result = sem_timedwait(&_semaphore, &ts); | |
2452 if (result == 0) { | |
2453 return true; | |
2454 } else if (errno == EINTR) { | |
2455 continue; | |
2456 } else if (errno == ETIMEDOUT) { | |
2457 return false; | |
2458 } else { | |
2459 return false; | |
2460 } | |
2461 } | |
2462 } | |
2463 | |
2403 extern "C" { | 2464 extern "C" { |
2404 typedef void (*sa_handler_t)(int); | 2465 typedef void (*sa_handler_t)(int); |
2405 typedef void (*sa_sigaction_t)(int, siginfo_t *, void *); | 2466 typedef void (*sa_sigaction_t)(int, siginfo_t *, void *); |
2406 } | 2467 } |
2407 | 2468 |
2437 // a counter for each possible signal value | 2498 // a counter for each possible signal value |
2438 static volatile jint pending_signals[NSIG+1] = { 0 }; | 2499 static volatile jint pending_signals[NSIG+1] = { 0 }; |
2439 | 2500 |
2440 // Linux(POSIX) specific hand shaking semaphore. | 2501 // Linux(POSIX) specific hand shaking semaphore. |
2441 static sem_t sig_sem; | 2502 static sem_t sig_sem; |
2503 static Semaphore sr_semaphore; | |
2442 | 2504 |
2443 void os::signal_init_pd() { | 2505 void os::signal_init_pd() { |
2444 // Initialize signal structures | 2506 // Initialize signal structures |
2445 ::memset((void*)pending_signals, 0, sizeof(pending_signals)); | 2507 ::memset((void*)pending_signals, 0, sizeof(pending_signals)); |
2446 | 2508 |
2904 if (fixed) { | 2966 if (fixed) { |
2905 assert((uintptr_t)requested_addr % os::Linux::page_size() == 0, "unaligned address"); | 2967 assert((uintptr_t)requested_addr % os::Linux::page_size() == 0, "unaligned address"); |
2906 flags |= MAP_FIXED; | 2968 flags |= MAP_FIXED; |
2907 } | 2969 } |
2908 | 2970 |
2909 // Map uncommitted pages PROT_READ and PROT_WRITE, change access | 2971 // Map reserved/uncommitted pages PROT_NONE so we fail early if we |
2910 // to PROT_EXEC if executable when we commit the page. | 2972 // touch an uncommitted page. Otherwise, the read/write might |
2911 addr = (char*)::mmap(requested_addr, bytes, PROT_READ|PROT_WRITE, | 2973 // succeed if we have enough swap space to back the physical page. |
2974 addr = (char*)::mmap(requested_addr, bytes, PROT_NONE, | |
2912 flags, -1, 0); | 2975 flags, -1, 0); |
2913 | 2976 |
2914 if (addr != MAP_FAILED) { | 2977 if (addr != MAP_FAILED) { |
2915 // anon_mmap() should only get called during VM initialization, | 2978 // anon_mmap() should only get called during VM initialization, |
2916 // don't need lock (actually we can skip locking even it can be called | 2979 // don't need lock (actually we can skip locking even it can be called |
3549 // | 3612 // |
3550 | 3613 |
3551 static void resume_clear_context(OSThread *osthread) { | 3614 static void resume_clear_context(OSThread *osthread) { |
3552 osthread->set_ucontext(NULL); | 3615 osthread->set_ucontext(NULL); |
3553 osthread->set_siginfo(NULL); | 3616 osthread->set_siginfo(NULL); |
3554 | |
3555 // notify the suspend action is completed, we have now resumed | |
3556 osthread->sr.clear_suspended(); | |
3557 } | 3617 } |
3558 | 3618 |
3559 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) { | 3619 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) { |
3560 osthread->set_ucontext(context); | 3620 osthread->set_ucontext(context); |
3561 osthread->set_siginfo(siginfo); | 3621 osthread->set_siginfo(siginfo); |
3571 // interface point of view, but sigwait() prevents the signal hander | 3631 // interface point of view, but sigwait() prevents the signal hander |
3572 // from being run. libpthread would get very confused by not having | 3632 // from being run. libpthread would get very confused by not having |
3573 // its signal handlers run and prevents sigwait()'s use with the | 3633 // its signal handlers run and prevents sigwait()'s use with the |
3574 // mutex granting granting signal. | 3634 // mutex granting granting signal. |
3575 // | 3635 // |
3576 // Currently only ever called on the VMThread | 3636 // Currently only ever called on the VMThread and JavaThreads (PC sampling) |
3577 // | 3637 // |
3578 static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) { | 3638 static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) { |
3579 // Save and restore errno to avoid confusing native code with EINTR | 3639 // Save and restore errno to avoid confusing native code with EINTR |
3580 // after sigsuspend. | 3640 // after sigsuspend. |
3581 int old_errno = errno; | 3641 int old_errno = errno; |
3582 | 3642 |
3583 Thread* thread = Thread::current(); | 3643 Thread* thread = Thread::current(); |
3584 OSThread* osthread = thread->osthread(); | 3644 OSThread* osthread = thread->osthread(); |
3585 assert(thread->is_VM_thread(), "Must be VMThread"); | 3645 assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread"); |
3586 // read current suspend action | 3646 |
3587 int action = osthread->sr.suspend_action(); | 3647 os::SuspendResume::State current = osthread->sr.state(); |
3588 if (action == os::Linux::SuspendResume::SR_SUSPEND) { | 3648 if (current == os::SuspendResume::SR_SUSPEND_REQUEST) { |
3589 suspend_save_context(osthread, siginfo, context); | 3649 suspend_save_context(osthread, siginfo, context); |
3590 | 3650 |
3591 // Notify the suspend action is about to be completed. do_suspend() | 3651 // attempt to switch the state, we assume we had a SUSPEND_REQUEST |
3592 // waits until SR_SUSPENDED is set and then returns. We will wait | 3652 os::SuspendResume::State state = osthread->sr.suspended(); |
3593 // here for a resume signal and that completes the suspend-other | 3653 if (state == os::SuspendResume::SR_SUSPENDED) { |
3594 // action. do_suspend/do_resume is always called as a pair from | 3654 sigset_t suspend_set; // signals for sigsuspend() |
3595 // the same thread - so there are no races | 3655 |
3596 | 3656 // get current set of blocked signals and unblock resume signal |
3597 // notify the caller | 3657 pthread_sigmask(SIG_BLOCK, NULL, &suspend_set); |
3598 osthread->sr.set_suspended(); | 3658 sigdelset(&suspend_set, SR_signum); |
3599 | 3659 |
3600 sigset_t suspend_set; // signals for sigsuspend() | 3660 sr_semaphore.signal(); |
3601 | 3661 // wait here until we are resumed |
3602 // get current set of blocked signals and unblock resume signal | 3662 while (1) { |
3603 pthread_sigmask(SIG_BLOCK, NULL, &suspend_set); | 3663 sigsuspend(&suspend_set); |
3604 sigdelset(&suspend_set, SR_signum); | 3664 |
3605 | 3665 os::SuspendResume::State result = osthread->sr.running(); |
3606 // wait here until we are resumed | 3666 if (result == os::SuspendResume::SR_RUNNING) { |
3607 do { | 3667 sr_semaphore.signal(); |
3608 sigsuspend(&suspend_set); | 3668 break; |
3609 // ignore all returns until we get a resume signal | 3669 } |
3610 } while (osthread->sr.suspend_action() != os::Linux::SuspendResume::SR_CONTINUE); | 3670 } |
3671 | |
3672 } else if (state == os::SuspendResume::SR_RUNNING) { | |
3673 // request was cancelled, continue | |
3674 } else { | |
3675 ShouldNotReachHere(); | |
3676 } | |
3611 | 3677 |
3612 resume_clear_context(osthread); | 3678 resume_clear_context(osthread); |
3613 | 3679 } else if (current == os::SuspendResume::SR_RUNNING) { |
3680 // request was cancelled, continue | |
3681 } else if (current == os::SuspendResume::SR_WAKEUP_REQUEST) { | |
3682 // ignore | |
3614 } else { | 3683 } else { |
3615 assert(action == os::Linux::SuspendResume::SR_CONTINUE, "unexpected sr action"); | 3684 // ignore |
3616 // nothing special to do - just leave the handler | |
3617 } | 3685 } |
3618 | 3686 |
3619 errno = old_errno; | 3687 errno = old_errno; |
3620 } | 3688 } |
3621 | 3689 |
3655 // Save signal flag | 3723 // Save signal flag |
3656 os::Linux::set_our_sigflags(SR_signum, act.sa_flags); | 3724 os::Linux::set_our_sigflags(SR_signum, act.sa_flags); |
3657 return 0; | 3725 return 0; |
3658 } | 3726 } |
3659 | 3727 |
3728 static int sr_notify(OSThread* osthread) { | |
3729 int status = pthread_kill(osthread->pthread_id(), SR_signum); | |
3730 assert_status(status == 0, status, "pthread_kill"); | |
3731 return status; | |
3732 } | |
3733 | |
3734 // "Randomly" selected value for how long we want to spin | |
3735 // before bailing out on suspending a thread, also how often | |
3736 // we send a signal to a thread we want to resume | |
3737 static const int RANDOMLY_LARGE_INTEGER = 1000000; | |
3738 static const int RANDOMLY_LARGE_INTEGER2 = 100; | |
3660 | 3739 |
3661 // returns true on success and false on error - really an error is fatal | 3740 // returns true on success and false on error - really an error is fatal |
3662 // but this seems the normal response to library errors | 3741 // but this seems the normal response to library errors |
3663 static bool do_suspend(OSThread* osthread) { | 3742 static bool do_suspend(OSThread* osthread) { |
3743 assert(osthread->sr.is_running(), "thread should be running"); | |
3744 assert(!sr_semaphore.trywait(), "semaphore has invalid state"); | |
3745 | |
3664 // mark as suspended and send signal | 3746 // mark as suspended and send signal |
3665 osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_SUSPEND); | 3747 if (osthread->sr.request_suspend() != os::SuspendResume::SR_SUSPEND_REQUEST) { |
3666 int status = pthread_kill(osthread->pthread_id(), SR_signum); | 3748 // failed to switch, state wasn't running? |
3667 assert_status(status == 0, status, "pthread_kill"); | 3749 ShouldNotReachHere(); |
3668 | |
3669 // check status and wait until notified of suspension | |
3670 if (status == 0) { | |
3671 for (int i = 0; !osthread->sr.is_suspended(); i++) { | |
3672 os::yield_all(i); | |
3673 } | |
3674 osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_NONE); | |
3675 return true; | |
3676 } | |
3677 else { | |
3678 osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_NONE); | |
3679 return false; | 3750 return false; |
3680 } | 3751 } |
3752 | |
3753 if (sr_notify(osthread) != 0) { | |
3754 ShouldNotReachHere(); | |
3755 } | |
3756 | |
3757 // managed to send the signal and switch to SUSPEND_REQUEST, now wait for SUSPENDED | |
3758 while (true) { | |
3759 if (sr_semaphore.timedwait(0, 2 * NANOSECS_PER_MILLISEC)) { | |
3760 break; | |
3761 } else { | |
3762 // timeout | |
3763 os::SuspendResume::State cancelled = osthread->sr.cancel_suspend(); | |
3764 if (cancelled == os::SuspendResume::SR_RUNNING) { | |
3765 return false; | |
3766 } else if (cancelled == os::SuspendResume::SR_SUSPENDED) { | |
3767 // make sure that we consume the signal on the semaphore as well | |
3768 sr_semaphore.wait(); | |
3769 break; | |
3770 } else { | |
3771 ShouldNotReachHere(); | |
3772 return false; | |
3773 } | |
3774 } | |
3775 } | |
3776 | |
3777 guarantee(osthread->sr.is_suspended(), "Must be suspended"); | |
3778 return true; | |
3681 } | 3779 } |
3682 | 3780 |
3683 static void do_resume(OSThread* osthread) { | 3781 static void do_resume(OSThread* osthread) { |
3684 assert(osthread->sr.is_suspended(), "thread should be suspended"); | 3782 assert(osthread->sr.is_suspended(), "thread should be suspended"); |
3685 osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_CONTINUE); | 3783 assert(!sr_semaphore.trywait(), "invalid semaphore state"); |
3686 | 3784 |
3687 int status = pthread_kill(osthread->pthread_id(), SR_signum); | 3785 if (osthread->sr.request_wakeup() != os::SuspendResume::SR_WAKEUP_REQUEST) { |
3688 assert_status(status == 0, status, "pthread_kill"); | 3786 // failed to switch to WAKEUP_REQUEST |
3689 // check status and wait unit notified of resumption | 3787 ShouldNotReachHere(); |
3690 if (status == 0) { | 3788 return; |
3691 for (int i = 0; osthread->sr.is_suspended(); i++) { | 3789 } |
3692 os::yield_all(i); | 3790 |
3693 } | 3791 while (true) { |
3694 } | 3792 if (sr_notify(osthread) == 0) { |
3695 osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_NONE); | 3793 if (sr_semaphore.timedwait(0, 2 * NANOSECS_PER_MILLISEC)) { |
3794 if (osthread->sr.is_running()) { | |
3795 return; | |
3796 } | |
3797 } | |
3798 } else { | |
3799 ShouldNotReachHere(); | |
3800 } | |
3801 } | |
3802 | |
3803 guarantee(osthread->sr.is_running(), "Must be running!"); | |
3696 } | 3804 } |
3697 | 3805 |
3698 //////////////////////////////////////////////////////////////////////////////// | 3806 //////////////////////////////////////////////////////////////////////////////// |
3699 // interrupt support | 3807 // interrupt support |
3700 | 3808 |
4247 Linux::_main_thread = pthread_self(); | 4355 Linux::_main_thread = pthread_self(); |
4248 | 4356 |
4249 Linux::clock_init(); | 4357 Linux::clock_init(); |
4250 initial_time_count = os::elapsed_counter(); | 4358 initial_time_count = os::elapsed_counter(); |
4251 pthread_mutex_init(&dl_mutex, NULL); | 4359 pthread_mutex_init(&dl_mutex, NULL); |
4360 | |
4361 // If the pagesize of the VM is greater than 8K determine the appropriate | |
4362 // number of initial guard pages. The user can change this with the | |
4363 // command line arguments, if needed. | |
4364 if (vm_page_size() > (int)Linux::vm_default_page_size()) { | |
4365 StackYellowPages = 1; | |
4366 StackRedPages = 1; | |
4367 StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size(); | |
4368 } | |
4252 } | 4369 } |
4253 | 4370 |
4254 // To install functions for atexit system call | 4371 // To install functions for atexit system call |
4255 extern "C" { | 4372 extern "C" { |
4256 static void perfMemory_exit_helper() { | 4373 static void perfMemory_exit_helper() { |
4300 // the java system classes, including StackOverflowError - depends on page | 4417 // the java system classes, including StackOverflowError - depends on page |
4301 // size. Add a page for compiler2 recursion in main thread. | 4418 // size. Add a page for compiler2 recursion in main thread. |
4302 // Add in 2*BytesPerWord times page size to account for VM stack during | 4419 // Add in 2*BytesPerWord times page size to account for VM stack during |
4303 // class initialization depending on 32 or 64 bit VM. | 4420 // class initialization depending on 32 or 64 bit VM. |
4304 os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed, | 4421 os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed, |
4305 (size_t)(StackYellowPages+StackRedPages+StackShadowPages+ | 4422 (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() + |
4306 2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::page_size()); | 4423 (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size()); |
4307 | 4424 |
4308 size_t threadStackSizeInBytes = ThreadStackSize * K; | 4425 size_t threadStackSizeInBytes = ThreadStackSize * K; |
4309 if (threadStackSizeInBytes != 0 && | 4426 if (threadStackSizeInBytes != 0 && |
4310 threadStackSizeInBytes < os::Linux::min_stack_allowed) { | 4427 threadStackSizeInBytes < os::Linux::min_stack_allowed) { |
4311 tty->print_cr("\nThe stack size specified is too small, " | 4428 tty->print_cr("\nThe stack size specified is too small, " |
4453 return false; | 4570 return false; |
4454 } | 4571 } |
4455 | 4572 |
4456 /// | 4573 /// |
4457 | 4574 |
4575 void os::SuspendedThreadTask::internal_do_task() { | |
4576 if (do_suspend(_thread->osthread())) { | |
4577 SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext()); | |
4578 do_task(context); | |
4579 do_resume(_thread->osthread()); | |
4580 } | |
4581 } | |
4582 | |
4583 class PcFetcher : public os::SuspendedThreadTask { | |
4584 public: | |
4585 PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {} | |
4586 ExtendedPC result(); | |
4587 protected: | |
4588 void do_task(const os::SuspendedThreadTaskContext& context); | |
4589 private: | |
4590 ExtendedPC _epc; | |
4591 }; | |
4592 | |
4593 ExtendedPC PcFetcher::result() { | |
4594 guarantee(is_done(), "task is not done yet."); | |
4595 return _epc; | |
4596 } | |
4597 | |
4598 void PcFetcher::do_task(const os::SuspendedThreadTaskContext& context) { | |
4599 Thread* thread = context.thread(); | |
4600 OSThread* osthread = thread->osthread(); | |
4601 if (osthread->ucontext() != NULL) { | |
4602 _epc = os::Linux::ucontext_get_pc((ucontext_t *) context.ucontext()); | |
4603 } else { | |
4604 // NULL context is unexpected, double-check this is the VMThread | |
4605 guarantee(thread->is_VM_thread(), "can only be called for VMThread"); | |
4606 } | |
4607 } | |
4608 | |
4458 // Suspends the target using the signal mechanism and then grabs the PC before | 4609 // Suspends the target using the signal mechanism and then grabs the PC before |
4459 // resuming the target. Used by the flat-profiler only | 4610 // resuming the target. Used by the flat-profiler only |
4460 ExtendedPC os::get_thread_pc(Thread* thread) { | 4611 ExtendedPC os::get_thread_pc(Thread* thread) { |
4461 // Make sure that it is called by the watcher for the VMThread | 4612 // Make sure that it is called by the watcher for the VMThread |
4462 assert(Thread::current()->is_Watcher_thread(), "Must be watcher"); | 4613 assert(Thread::current()->is_Watcher_thread(), "Must be watcher"); |
4463 assert(thread->is_VM_thread(), "Can only be called for VMThread"); | 4614 assert(thread->is_VM_thread(), "Can only be called for VMThread"); |
4464 | 4615 |
4465 ExtendedPC epc; | 4616 PcFetcher fetcher(thread); |
4466 | 4617 fetcher.run(); |
4467 OSThread* osthread = thread->osthread(); | 4618 return fetcher.result(); |
4468 if (do_suspend(osthread)) { | |
4469 if (osthread->ucontext() != NULL) { | |
4470 epc = os::Linux::ucontext_get_pc(osthread->ucontext()); | |
4471 } else { | |
4472 // NULL context is unexpected, double-check this is the VMThread | |
4473 guarantee(thread->is_VM_thread(), "can only be called for VMThread"); | |
4474 } | |
4475 do_resume(osthread); | |
4476 } | |
4477 // failure means pthread_kill failed for some reason - arguably this is | |
4478 // a fatal problem, but such problems are ignored elsewhere | |
4479 | |
4480 return epc; | |
4481 } | 4619 } |
4482 | 4620 |
4483 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime) | 4621 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime) |
4484 { | 4622 { |
4485 if (is_NPTL()) { | 4623 if (is_NPTL()) { |
5597 | 5735 |
5598 if (memnotify_thread() == NULL) { | 5736 if (memnotify_thread() == NULL) { |
5599 new MemNotifyThread(fd); | 5737 new MemNotifyThread(fd); |
5600 } | 5738 } |
5601 } | 5739 } |
5740 | |
5602 #endif // JAVASE_EMBEDDED | 5741 #endif // JAVASE_EMBEDDED |