src/os/linux/vm/os_linux.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File webrev Sdiff src/os/linux/vm

src/os/linux/vm/os_linux.cpp

Print this page




4024 
4025 OSReturn os::get_native_priority(const Thread* const thread,
4026                                  int *priority_ptr) {
4027   if (!UseThreadPriorities || ThreadPriorityPolicy == 0) {
4028     *priority_ptr = java_to_os_priority[NormPriority];
4029     return OS_OK;
4030   }
4031 
4032   errno = 0;
4033   *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id());
4034   return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR);
4035 }
4036 
4037 // Hint to the underlying OS that a task switch would not be good.
4038 // Void return because it's a hint and can fail.
4039 void os::hint_no_preempt() {}
4040 
4041 ////////////////////////////////////////////////////////////////////////////////
4042 // suspend/resume support
4043 
4044 //  the low-level signal-based suspend/resume support is a remnant from the
4045 //  old VM-suspension that used to be for java-suspension, safepoints etc,
4046 //  within hotspot. Now there is a single use-case for this:
4047 //    - calling get_thread_pc() on the VMThread by the flat-profiler task
4048 //      that runs in the watcher thread.
4049 //  The remaining code is greatly simplified from the more general suspension
4050 //  code that used to be used.
4051 //
4052 //  The protocol is quite simple:
4053 //  - suspend:
4054 //      - sends a signal to the target thread
4055 //      - polls the suspend state of the osthread using a yield loop
4056 //      - target thread signal handler (SR_handler) sets suspend state
4057 //        and blocks in sigsuspend until continued
4058 //  - resume:
4059 //      - sets target osthread state to continue
4060 //      - sends signal to end the sigsuspend loop in the SR_handler
4061 //
4062 //  Note that the SR_lock plays no role in this suspend/resume protocol,
4063 //  but is checked for NULL in SR_handler as a thread termination indicator.







4064 
4065 static void resume_clear_context(OSThread *osthread) {
4066   osthread->set_ucontext(NULL);
4067   osthread->set_siginfo(NULL);
4068 }
4069 
4070 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo,
4071                                  ucontext_t* context) {
4072   osthread->set_ucontext(context);
4073   osthread->set_siginfo(siginfo);
4074 }
4075 
4076 // Handler function invoked when a thread's execution is suspended or
4077 // resumed. We have to be careful that only async-safe functions are
4078 // called here (Note: most pthread functions are not async safe and
4079 // should be avoided.)
4080 //
4081 // Note: sigwait() is a more natural fit than sigsuspend() from an
4082 // interface point of view, but sigwait() prevents the signal hander
4083 // from being run. libpthread would get very confused by not having


5084 bool os::distribute_processes(uint length, uint* distribution) {
5085   // Not yet implemented.
5086   return false;
5087 }
5088 
5089 bool os::bind_to_processor(uint processor_id) {
5090   // Not yet implemented.
5091   return false;
5092 }
5093 
5094 ///
5095 
5096 void os::SuspendedThreadTask::internal_do_task() {
5097   if (do_suspend(_thread->osthread())) {
5098     SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext());
5099     do_task(context);
5100     do_resume(_thread->osthread());
5101   }
5102 }
5103 
5104 class PcFetcher : public os::SuspendedThreadTask {
5105  public:
5106   PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {}
5107   ExtendedPC result();
5108  protected:
5109   void do_task(const os::SuspendedThreadTaskContext& context);
5110  private:
5111   ExtendedPC _epc;
5112 };
5113 
5114 ExtendedPC PcFetcher::result() {
5115   guarantee(is_done(), "task is not done yet.");
5116   return _epc;
5117 }
5118 
5119 void PcFetcher::do_task(const os::SuspendedThreadTaskContext& context) {
5120   Thread* thread = context.thread();
5121   OSThread* osthread = thread->osthread();
5122   if (osthread->ucontext() != NULL) {
5123     _epc = os::Linux::ucontext_get_pc((const ucontext_t *) context.ucontext());
5124   } else {
5125     // NULL context is unexpected, double-check this is the VMThread
5126     guarantee(thread->is_VM_thread(), "can only be called for VMThread");
5127   }
5128 }
5129 
5130 // Suspends the target using the signal mechanism and then grabs the PC before
5131 // resuming the target. Used by the flat-profiler only
5132 ExtendedPC os::get_thread_pc(Thread* thread) {
5133   // Make sure that it is called by the watcher for the VMThread
5134   assert(Thread::current()->is_Watcher_thread(), "Must be watcher");
5135   assert(thread->is_VM_thread(), "Can only be called for VMThread");
5136 
5137   PcFetcher fetcher(thread);
5138   fetcher.run();
5139   return fetcher.result();
5140 }
5141 
5142 ////////////////////////////////////////////////////////////////////////////////
5143 // debug support
5144 
5145 bool os::find(address addr, outputStream* st) {
5146   Dl_info dlinfo;
5147   memset(&dlinfo, 0, sizeof(dlinfo));
5148   if (dladdr(addr, &dlinfo) != 0) {
5149     st->print(PTR_FORMAT ": ", p2i(addr));
5150     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
5151       st->print("%s+" PTR_FORMAT, dlinfo.dli_sname,
5152                 p2i(addr) - p2i(dlinfo.dli_saddr));
5153     } else if (dlinfo.dli_fbase != NULL) {
5154       st->print("<offset " PTR_FORMAT ">", p2i(addr) - p2i(dlinfo.dli_fbase));
5155     } else {
5156       st->print("<absolute address>");
5157     }
5158     if (dlinfo.dli_fname != NULL) {
5159       st->print(" in %s", dlinfo.dli_fname);
5160     }
5161     if (dlinfo.dli_fbase != NULL) {




4024 
4025 OSReturn os::get_native_priority(const Thread* const thread,
4026                                  int *priority_ptr) {
4027   if (!UseThreadPriorities || ThreadPriorityPolicy == 0) {
4028     *priority_ptr = java_to_os_priority[NormPriority];
4029     return OS_OK;
4030   }
4031 
4032   errno = 0;
4033   *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id());
4034   return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR);
4035 }
4036 
4037 // Hint to the underlying OS that a task switch would not be good.
4038 // Void return because it's a hint and can fail.
4039 void os::hint_no_preempt() {}
4040 
4041 ////////////////////////////////////////////////////////////////////////////////
4042 // suspend/resume support
4043 
4044 //  The low-level signal-based suspend/resume support is a remnant from the
4045 //  old VM-suspension that used to be for java-suspension, safepoints etc,
4046 //  within hotspot. Currently used by JFR's OSThreadSampler
4047 //

4048 //  The remaining code is greatly simplified from the more general suspension
4049 //  code that used to be used.
4050 //
4051 //  The protocol is quite simple:
4052 //  - suspend:
4053 //      - sends a signal to the target thread
4054 //      - polls the suspend state of the osthread using a yield loop
4055 //      - target thread signal handler (SR_handler) sets suspend state
4056 //        and blocks in sigsuspend until continued
4057 //  - resume:
4058 //      - sets target osthread state to continue
4059 //      - sends signal to end the sigsuspend loop in the SR_handler
4060 //
4061 //  Note that the SR_lock plays no role in this suspend/resume protocol,
4062 //  but is checked for NULL in SR_handler as a thread termination indicator.
4063 //  The SR_lock is, however, used by JavaThread::java_suspend()/java_resume() APIs.
4064 //
4065 //  Note that resume_clear_context() and suspend_save_context() are needed
4066 //  by SR_handler(), so that fetch_frame_from_ucontext() works,
4067 //  which in part is used by:
4068 //    - Forte Analyzer: AsyncGetCallTrace()
4069 //    - StackBanging: get_frame_at_stack_banging_point()
4070 
4071 static void resume_clear_context(OSThread *osthread) {
4072   osthread->set_ucontext(NULL);
4073   osthread->set_siginfo(NULL);
4074 }
4075 
4076 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo,
4077                                  ucontext_t* context) {
4078   osthread->set_ucontext(context);
4079   osthread->set_siginfo(siginfo);
4080 }
4081 
4082 // Handler function invoked when a thread's execution is suspended or
4083 // resumed. We have to be careful that only async-safe functions are
4084 // called here (Note: most pthread functions are not async safe and
4085 // should be avoided.)
4086 //
4087 // Note: sigwait() is a more natural fit than sigsuspend() from an
4088 // interface point of view, but sigwait() prevents the signal hander
4089 // from being run. libpthread would get very confused by not having


5090 bool os::distribute_processes(uint length, uint* distribution) {
5091   // Not yet implemented.
5092   return false;
5093 }
5094 
5095 bool os::bind_to_processor(uint processor_id) {
5096   // Not yet implemented.
5097   return false;
5098 }
5099 
5100 ///
5101 
5102 void os::SuspendedThreadTask::internal_do_task() {
5103   if (do_suspend(_thread->osthread())) {
5104     SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext());
5105     do_task(context);
5106     do_resume(_thread->osthread());
5107   }
5108 }
5109 






































5110 ////////////////////////////////////////////////////////////////////////////////
5111 // debug support
5112 
5113 bool os::find(address addr, outputStream* st) {
5114   Dl_info dlinfo;
5115   memset(&dlinfo, 0, sizeof(dlinfo));
5116   if (dladdr(addr, &dlinfo) != 0) {
5117     st->print(PTR_FORMAT ": ", p2i(addr));
5118     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
5119       st->print("%s+" PTR_FORMAT, dlinfo.dli_sname,
5120                 p2i(addr) - p2i(dlinfo.dli_saddr));
5121     } else if (dlinfo.dli_fbase != NULL) {
5122       st->print("<offset " PTR_FORMAT ">", p2i(addr) - p2i(dlinfo.dli_fbase));
5123     } else {
5124       st->print("<absolute address>");
5125     }
5126     if (dlinfo.dli_fname != NULL) {
5127       st->print(" in %s", dlinfo.dli_fname);
5128     }
5129     if (dlinfo.dli_fbase != NULL) {


src/os/linux/vm/os_linux.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File