478
479 // Change status to parked (timed or indefinite)
480 class JavaThreadParkedState : public JavaThreadStatusChanger {
481 private:
482 ThreadStatistics* _stat;
483 bool _active;
484
485 public:
486 JavaThreadParkedState(JavaThread *java_thread, bool timed) :
487 JavaThreadStatusChanger(java_thread,
488 timed ? java_lang_Thread::PARKED_TIMED : java_lang_Thread::PARKED) {
489 if (is_alive()) {
490 _stat = java_thread->get_thread_stat();
491 _active = ThreadService::is_thread_monitoring_contention();
492 _stat->monitor_wait();
493 if (_active) {
494 _stat->monitor_wait_begin();
495 }
496 } else {
497 _active = false;
498 }
499 }
500
501 ~JavaThreadParkedState() {
502 if (_active) {
503 _stat->monitor_wait_end();
504 }
505 }
506 };
507
508 // Change status to blocked on (re-)entering a synchronization block
509 class JavaThreadBlockedOnMonitorEnterState : public JavaThreadStatusChanger {
510 private:
511 ThreadStatistics* _stat;
512 bool _active;
513
514 static bool contended_enter_begin(JavaThread *java_thread) {
515 set_thread_status(java_thread, java_lang_Thread::BLOCKED_ON_MONITOR_ENTER);
516 ThreadStatistics* stat = java_thread->get_thread_stat();
517 stat->contended_enter();
562 }
563 };
564
565 // Change status to sleeping
566 class JavaThreadSleepState : public JavaThreadStatusChanger {
567 private:
568 ThreadStatistics* _stat;
569 bool _active;
570 public:
571 JavaThreadSleepState(JavaThread *java_thread) :
572 JavaThreadStatusChanger(java_thread, java_lang_Thread::SLEEPING) {
573 if (is_alive()) {
574 _stat = java_thread->get_thread_stat();
575 _active = ThreadService::is_thread_monitoring_contention();
576 _stat->thread_sleep();
577 if (_active) {
578 _stat->thread_sleep_begin();
579 }
580 } else {
581 _active = false;
582 }
583 }
584
585 ~JavaThreadSleepState() {
586 if (_active) {
587 _stat->thread_sleep_end();
588 }
589 }
590 };
591
592 #endif // SHARE_VM_SERVICES_THREADSERVICE_HPP
|
478
479 // Change status to parked (timed or indefinite)
480 class JavaThreadParkedState : public JavaThreadStatusChanger {
481 private:
482 ThreadStatistics* _stat;
483 bool _active;
484
485 public:
486 JavaThreadParkedState(JavaThread *java_thread, bool timed) :
487 JavaThreadStatusChanger(java_thread,
488 timed ? java_lang_Thread::PARKED_TIMED : java_lang_Thread::PARKED) {
489 if (is_alive()) {
490 _stat = java_thread->get_thread_stat();
491 _active = ThreadService::is_thread_monitoring_contention();
492 _stat->monitor_wait();
493 if (_active) {
494 _stat->monitor_wait_begin();
495 }
496 } else {
497 _active = false;
498 _stat = NULL;
499 }
500 }
501
502 ~JavaThreadParkedState() {
503 if (_active) {
504 _stat->monitor_wait_end();
505 }
506 }
507 };
508
509 // Change status to blocked on (re-)entering a synchronization block
510 class JavaThreadBlockedOnMonitorEnterState : public JavaThreadStatusChanger {
511 private:
512 ThreadStatistics* _stat;
513 bool _active;
514
515 static bool contended_enter_begin(JavaThread *java_thread) {
516 set_thread_status(java_thread, java_lang_Thread::BLOCKED_ON_MONITOR_ENTER);
517 ThreadStatistics* stat = java_thread->get_thread_stat();
518 stat->contended_enter();
563 }
564 };
565
566 // Change status to sleeping
567 class JavaThreadSleepState : public JavaThreadStatusChanger {
568 private:
569 ThreadStatistics* _stat;
570 bool _active;
571 public:
572 JavaThreadSleepState(JavaThread *java_thread) :
573 JavaThreadStatusChanger(java_thread, java_lang_Thread::SLEEPING) {
574 if (is_alive()) {
575 _stat = java_thread->get_thread_stat();
576 _active = ThreadService::is_thread_monitoring_contention();
577 _stat->thread_sleep();
578 if (_active) {
579 _stat->thread_sleep_begin();
580 }
581 } else {
582 _active = false;
583 _stat = NULL;
584 }
585 }
586
587 ~JavaThreadSleepState() {
588 if (_active) {
589 _stat->thread_sleep_end();
590 }
591 }
592 };
593
594 #endif // SHARE_VM_SERVICES_THREADSERVICE_HPP
|