2649 *priority_ptr = pthread_getprio(thread->osthread()->pthread_id()); 2650 #elif defined(__APPLE__) || defined(__NetBSD__) 2651 int policy; 2652 struct sched_param sp; 2653 2654 pthread_getschedparam(pthread_self(), &policy, &sp); 2655 *priority_ptr = sp.sched_priority; 2656 #else 2657 *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id()); 2658 #endif 2659 return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR); 2660 } 2661 2662 // Hint to the underlying OS that a task switch would not be good. 2663 // Void return because it's a hint and can fail. 2664 void os::hint_no_preempt() {} 2665 2666 //////////////////////////////////////////////////////////////////////////////// 2667 // suspend/resume support 2668 2669 // the low-level signal-based suspend/resume support is a remnant from the 2670 // old VM-suspension that used to be for java-suspension, safepoints etc, 2671 // within hotspot. Now there is a single use-case for this: 2672 // - calling get_thread_pc() on the VMThread by the flat-profiler task 2673 // that runs in the watcher thread. 2674 // The remaining code is greatly simplified from the more general suspension 2675 // code that used to be used. 2676 // 2677 // The protocol is quite simple: 2678 // - suspend: 2679 // - sends a signal to the target thread 2680 // - polls the suspend state of the osthread using a yield loop 2681 // - target thread signal handler (SR_handler) sets suspend state 2682 // and blocks in sigsuspend until continued 2683 // - resume: 2684 // - sets target osthread state to continue 2685 // - sends signal to end the sigsuspend loop in the SR_handler 2686 // 2687 // Note that the SR_lock plays no role in this suspend/resume protocol, 2688 // but is checked for NULL in SR_handler as a thread termination indicator. 2689 2690 static void resume_clear_context(OSThread *osthread) { 2691 osthread->set_ucontext(NULL); 2692 osthread->set_siginfo(NULL); 2693 } 3567 } 3568 3569 bool os::distribute_processes(uint length, uint* distribution) { 3570 // Not yet implemented. 3571 return false; 3572 } 3573 3574 bool os::bind_to_processor(uint processor_id) { 3575 // Not yet implemented. 3576 return false; 3577 } 3578 3579 void os::SuspendedThreadTask::internal_do_task() { 3580 if (do_suspend(_thread->osthread())) { 3581 SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext()); 3582 do_task(context); 3583 do_resume(_thread->osthread()); 3584 } 3585 } 3586 3587 /// 3588 class PcFetcher : public os::SuspendedThreadTask { 3589 public: 3590 PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {} 3591 ExtendedPC result(); 3592 protected: 3593 void do_task(const os::SuspendedThreadTaskContext& context); 3594 private: 3595 ExtendedPC _epc; 3596 }; 3597 3598 ExtendedPC PcFetcher::result() { 3599 guarantee(is_done(), "task is not done yet."); 3600 return _epc; 3601 } 3602 3603 void PcFetcher::do_task(const os::SuspendedThreadTaskContext& context) { 3604 Thread* thread = context.thread(); 3605 OSThread* osthread = thread->osthread(); 3606 if (osthread->ucontext() != NULL) { 3607 _epc = os::Bsd::ucontext_get_pc((const ucontext_t *) context.ucontext()); 3608 } else { 3609 // NULL context is unexpected, double-check this is the VMThread 3610 guarantee(thread->is_VM_thread(), "can only be called for VMThread"); 3611 } 3612 } 3613 3614 // Suspends the target using the signal mechanism and then grabs the PC before 3615 // resuming the target. Used by the flat-profiler only 3616 ExtendedPC os::get_thread_pc(Thread* thread) { 3617 // Make sure that it is called by the watcher for the VMThread 3618 assert(Thread::current()->is_Watcher_thread(), "Must be watcher"); 3619 assert(thread->is_VM_thread(), "Can only be called for VMThread"); 3620 3621 PcFetcher fetcher(thread); 3622 fetcher.run(); 3623 return fetcher.result(); 3624 } 3625 3626 //////////////////////////////////////////////////////////////////////////////// 3627 // debug support 3628 3629 bool os::find(address addr, outputStream* st) { 3630 Dl_info dlinfo; 3631 memset(&dlinfo, 0, sizeof(dlinfo)); 3632 if (dladdr(addr, &dlinfo) != 0) { 3633 st->print(INTPTR_FORMAT ": ", (intptr_t)addr); 3634 if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) { 3635 st->print("%s+%#x", dlinfo.dli_sname, 3636 (uint)((uintptr_t)addr - (uintptr_t)dlinfo.dli_saddr)); 3637 } else if (dlinfo.dli_fbase != NULL) { 3638 st->print("<offset %#x>", (uint)((uintptr_t)addr - (uintptr_t)dlinfo.dli_fbase)); 3639 } else { 3640 st->print("<absolute address>"); 3641 } 3642 if (dlinfo.dli_fname != NULL) { 3643 st->print(" in %s", dlinfo.dli_fname); 3644 } 3645 if (dlinfo.dli_fbase != NULL) { | 2649 *priority_ptr = pthread_getprio(thread->osthread()->pthread_id()); 2650 #elif defined(__APPLE__) || defined(__NetBSD__) 2651 int policy; 2652 struct sched_param sp; 2653 2654 pthread_getschedparam(pthread_self(), &policy, &sp); 2655 *priority_ptr = sp.sched_priority; 2656 #else 2657 *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id()); 2658 #endif 2659 return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR); 2660 } 2661 2662 // Hint to the underlying OS that a task switch would not be good. 2663 // Void return because it's a hint and can fail. 2664 void os::hint_no_preempt() {} 2665 2666 //////////////////////////////////////////////////////////////////////////////// 2667 // suspend/resume support 2668 2669 // The low-level signal-based suspend/resume support is a remnant from the 2670 // old VM-suspension that used to be for java-suspension, safepoints etc, 2671 // within hotspot. Needed for fetch_frame_from_ucontext(), which is used by: 2672 // - Forte Analyzer: AsyncGetCallTrace() 2673 // - StackBanging: get_frame_at_stack_banging_point() 2674 // 2675 // The remaining code is greatly simplified from the more general suspension 2676 // code that used to be used. 2677 // 2678 // The protocol is quite simple: 2679 // - suspend: 2680 // - sends a signal to the target thread 2681 // - polls the suspend state of the osthread using a yield loop 2682 // - target thread signal handler (SR_handler) sets suspend state 2683 // and blocks in sigsuspend until continued 2684 // - resume: 2685 // - sets target osthread state to continue 2686 // - sends signal to end the sigsuspend loop in the SR_handler 2687 // 2688 // Note that the SR_lock plays no role in this suspend/resume protocol, 2689 // but is checked for NULL in SR_handler as a thread termination indicator. 2690 2691 static void resume_clear_context(OSThread *osthread) { 2692 osthread->set_ucontext(NULL); 2693 osthread->set_siginfo(NULL); 2694 } 3568 } 3569 3570 bool os::distribute_processes(uint length, uint* distribution) { 3571 // Not yet implemented. 3572 return false; 3573 } 3574 3575 bool os::bind_to_processor(uint processor_id) { 3576 // Not yet implemented. 3577 return false; 3578 } 3579 3580 void os::SuspendedThreadTask::internal_do_task() { 3581 if (do_suspend(_thread->osthread())) { 3582 SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext()); 3583 do_task(context); 3584 do_resume(_thread->osthread()); 3585 } 3586 } 3587 3588 //////////////////////////////////////////////////////////////////////////////// 3589 // debug support 3590 3591 bool os::find(address addr, outputStream* st) { 3592 Dl_info dlinfo; 3593 memset(&dlinfo, 0, sizeof(dlinfo)); 3594 if (dladdr(addr, &dlinfo) != 0) { 3595 st->print(INTPTR_FORMAT ": ", (intptr_t)addr); 3596 if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) { 3597 st->print("%s+%#x", dlinfo.dli_sname, 3598 (uint)((uintptr_t)addr - (uintptr_t)dlinfo.dli_saddr)); 3599 } else if (dlinfo.dli_fbase != NULL) { 3600 st->print("<offset %#x>", (uint)((uintptr_t)addr - (uintptr_t)dlinfo.dli_fbase)); 3601 } else { 3602 st->print("<absolute address>"); 3603 } 3604 if (dlinfo.dli_fname != NULL) { 3605 st->print(" in %s", dlinfo.dli_fname); 3606 } 3607 if (dlinfo.dli_fbase != NULL) { |