< prev index next >

src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp

Print this page




 318   JavaThread* _last_thread_native;
 319   size_t _interval_java;
 320   size_t _interval_native;
 321   int _cur_index;
 322   const u4 _max_frames;
 323   volatile bool _disenrolled;
 324 
 325   JavaThread* next_thread(ThreadsList* t_list, JavaThread* first_sampled, JavaThread* current);
 326   void task_stacktrace(JfrSampleType type, JavaThread** last_thread);
 327   JfrThreadSampler(size_t interval_java, size_t interval_native, u4 max_frames);
 328   ~JfrThreadSampler();
 329 
 330   void start_thread();
 331 
 332   void enroll();
 333   void disenroll();
 334   void set_java_interval(size_t interval) { _interval_java = interval; };
 335   void set_native_interval(size_t interval) { _interval_native = interval; };
 336   size_t get_java_interval() { return _interval_java; };
 337   size_t get_native_interval() { return _interval_native; };
 338 

 339  public:
 340   void run();
 341   static Monitor* transition_block() { return JfrThreadSampler_lock; }
 342   static void on_javathread_suspend(JavaThread* thread);
 343 };
 344 
 345 static void clear_transition_block(JavaThread* jt) {
 346   jt->clear_trace_flag();
 347   JfrThreadLocal* const tl = jt->jfr_thread_local();
 348   if (tl->is_trace_block()) {
 349     MutexLockerEx ml(JfrThreadSampler::transition_block(), Mutex::_no_safepoint_check_flag);
 350     JfrThreadSampler::transition_block()->notify_all();
 351   }
 352 }
 353 
 354 bool JfrThreadSampleClosure::do_sample_thread(JavaThread* thread, JfrStackFrame* frames, u4 max_frames, JfrSampleType type) {
 355   assert(Threads_lock->owned_by_self(), "Holding the thread table lock.");
 356   if (thread->is_hidden_from_external_view() || thread->in_deopt_handler()) {
 357     return false;
 358   }


 467     jlong now_ms = get_monotonic_ms();
 468 
 469     jlong next_j = java_interval + last_java_ms - now_ms;
 470     jlong next_n = native_interval + last_native_ms - now_ms;
 471 
 472     jlong sleep_to_next = MIN2<jlong>(next_j, next_n);
 473 
 474     if (sleep_to_next > 0) {
 475       os::naked_short_sleep(sleep_to_next);
 476     }
 477 
 478     if ((next_j - sleep_to_next) <= 0) {
 479       task_stacktrace(JAVA_SAMPLE, &_last_thread_java);
 480       last_java_ms = get_monotonic_ms();
 481     }
 482     if ((next_n - sleep_to_next) <= 0) {
 483       task_stacktrace(NATIVE_SAMPLE, &_last_thread_native);
 484       last_native_ms = get_monotonic_ms();
 485     }
 486   }




 487   delete this;
 488 }
 489 
 490 
 491 void JfrThreadSampler::task_stacktrace(JfrSampleType type, JavaThread** last_thread) {
 492   ResourceMark rm;
 493   EventExecutionSample samples[MAX_NR_OF_JAVA_SAMPLES];
 494   EventNativeMethodSample samples_native[MAX_NR_OF_NATIVE_SAMPLES];
 495   JfrThreadSampleClosure sample_task(samples, samples_native);
 496 
 497   const uint sample_limit = JAVA_SAMPLE == type ? MAX_NR_OF_JAVA_SAMPLES : MAX_NR_OF_NATIVE_SAMPLES;
 498   uint num_samples = 0;
 499   JavaThread* start = NULL;
 500 
 501   {
 502     elapsedTimer sample_time;
 503     sample_time.start();
 504     {
 505       MonitorLockerEx tlock(Threads_lock, Mutex::_allow_vm_block_flag);
 506       ThreadsListHandle tlh;




 318   JavaThread* _last_thread_native;
 319   size_t _interval_java;
 320   size_t _interval_native;
 321   int _cur_index;
 322   const u4 _max_frames;
 323   volatile bool _disenrolled;
 324 
 325   JavaThread* next_thread(ThreadsList* t_list, JavaThread* first_sampled, JavaThread* current);
 326   void task_stacktrace(JfrSampleType type, JavaThread** last_thread);
 327   JfrThreadSampler(size_t interval_java, size_t interval_native, u4 max_frames);
 328   ~JfrThreadSampler();
 329 
 330   void start_thread();
 331 
 332   void enroll();
 333   void disenroll();
 334   void set_java_interval(size_t interval) { _interval_java = interval; };
 335   void set_native_interval(size_t interval) { _interval_native = interval; };
 336   size_t get_java_interval() { return _interval_java; };
 337   size_t get_native_interval() { return _interval_native; };
 338  protected:
 339   virtual void post_run();
 340  public:
 341   void run();
 342   static Monitor* transition_block() { return JfrThreadSampler_lock; }
 343   static void on_javathread_suspend(JavaThread* thread);
 344 };
 345 
 346 static void clear_transition_block(JavaThread* jt) {
 347   jt->clear_trace_flag();
 348   JfrThreadLocal* const tl = jt->jfr_thread_local();
 349   if (tl->is_trace_block()) {
 350     MutexLockerEx ml(JfrThreadSampler::transition_block(), Mutex::_no_safepoint_check_flag);
 351     JfrThreadSampler::transition_block()->notify_all();
 352   }
 353 }
 354 
 355 bool JfrThreadSampleClosure::do_sample_thread(JavaThread* thread, JfrStackFrame* frames, u4 max_frames, JfrSampleType type) {
 356   assert(Threads_lock->owned_by_self(), "Holding the thread table lock.");
 357   if (thread->is_hidden_from_external_view() || thread->in_deopt_handler()) {
 358     return false;
 359   }


 468     jlong now_ms = get_monotonic_ms();
 469 
 470     jlong next_j = java_interval + last_java_ms - now_ms;
 471     jlong next_n = native_interval + last_native_ms - now_ms;
 472 
 473     jlong sleep_to_next = MIN2<jlong>(next_j, next_n);
 474 
 475     if (sleep_to_next > 0) {
 476       os::naked_short_sleep(sleep_to_next);
 477     }
 478 
 479     if ((next_j - sleep_to_next) <= 0) {
 480       task_stacktrace(JAVA_SAMPLE, &_last_thread_java);
 481       last_java_ms = get_monotonic_ms();
 482     }
 483     if ((next_n - sleep_to_next) <= 0) {
 484       task_stacktrace(NATIVE_SAMPLE, &_last_thread_native);
 485       last_native_ms = get_monotonic_ms();
 486     }
 487   }
 488 }
 489 
 490 void JfrThreadSampler::post_run() {
 491   this->NonJavaThread::post_run();
 492   delete this;
 493 }
 494 
 495 
 496 void JfrThreadSampler::task_stacktrace(JfrSampleType type, JavaThread** last_thread) {
 497   ResourceMark rm;
 498   EventExecutionSample samples[MAX_NR_OF_JAVA_SAMPLES];
 499   EventNativeMethodSample samples_native[MAX_NR_OF_NATIVE_SAMPLES];
 500   JfrThreadSampleClosure sample_task(samples, samples_native);
 501 
 502   const uint sample_limit = JAVA_SAMPLE == type ? MAX_NR_OF_JAVA_SAMPLES : MAX_NR_OF_NATIVE_SAMPLES;
 503   uint num_samples = 0;
 504   JavaThread* start = NULL;
 505 
 506   {
 507     elapsedTimer sample_time;
 508     sample_time.start();
 509     {
 510       MonitorLockerEx tlock(Threads_lock, Mutex::_allow_vm_block_flag);
 511       ThreadsListHandle tlh;


< prev index next >