< prev index next >

src/hotspot/share/services/threadService.hpp

Print this page
rev 52112 : [mq]: 8021335


  41 class ThreadSnapshot;
  42 class StackFrameInfo;
  43 class ThreadConcurrentLocks;
  44 class DeadlockCycle;
  45 
  46 // VM monitoring and management support for the thread and
  47 // synchronization subsystem
  48 //
  49 // Thread contention monitoring is disabled by default.
  50 // When enabled, the VM will begin measuring the accumulated
  51 // elapsed time a thread blocked on synchronization.
  52 //
  53 class ThreadService : public AllStatic {
  54 private:
  55   // These counters could be moved to Threads class
  56   static PerfCounter*  _total_threads_count;
  57   static PerfVariable* _live_threads_count;
  58   static PerfVariable* _peak_threads_count;
  59   static PerfVariable* _daemon_threads_count;
  60 
  61   // These 2 counters are atomically incremented once the thread is exiting.
  62   // They will be atomically decremented when ThreadService::remove_thread is called.
  63   static volatile int  _exiting_threads_count;
  64   static volatile int  _exiting_daemon_threads_count;
  65 
  66   static bool          _thread_monitoring_contention_enabled;
  67   static bool          _thread_cpu_time_enabled;
  68   static bool          _thread_allocated_memory_enabled;
  69 
  70   // Need to keep the list of thread dump result that
  71   // keep references to Method* since thread dump can be
  72   // requested by multiple threads concurrently.
  73   static ThreadDumpResult* _threaddump_list;
  74 


  75 public:
  76   static void init();
  77   static void add_thread(JavaThread* thread, bool daemon);
  78   static void remove_thread(JavaThread* thread, bool daemon);
  79   static void current_thread_exiting(JavaThread* jt);
  80 
  81   static bool set_thread_monitoring_contention(bool flag);
  82   static bool is_thread_monitoring_contention() { return _thread_monitoring_contention_enabled; }
  83 
  84   static bool set_thread_cpu_time_enabled(bool flag);
  85   static bool is_thread_cpu_time_enabled()    { return _thread_cpu_time_enabled; }
  86 
  87   static bool set_thread_allocated_memory_enabled(bool flag);
  88   static bool is_thread_allocated_memory_enabled() { return _thread_cpu_time_enabled; }
  89 
  90   static jlong get_total_thread_count()       { return _total_threads_count->get_value(); }
  91   static jlong get_peak_thread_count()        { return _peak_threads_count->get_value(); }
  92   static jlong get_live_thread_count()        { return _live_threads_count->get_value() - _exiting_threads_count; }
  93   static jlong get_daemon_thread_count()      { return _daemon_threads_count->get_value() - _exiting_daemon_threads_count; }
  94 
  95   static int   exiting_threads_count()        { return _exiting_threads_count; }
  96   static int   exiting_daemon_threads_count() { return _exiting_daemon_threads_count; }
  97 
  98   // Support for thread dump
  99   static void   add_thread_dump(ThreadDumpResult* dump);
 100   static void   remove_thread_dump(ThreadDumpResult* dump);
 101 
 102   static Handle get_current_contended_monitor(JavaThread* thread);
 103 
 104   // This function is called by JVM_DumpThreads.
 105   static Handle dump_stack_traces(GrowableArray<instanceHandle>* threads,
 106                                   int num_threads, TRAPS);
 107 
 108   static void   reset_peak_thread_count();
 109   static void   reset_contention_count_stat(JavaThread* thread);
 110   static void   reset_contention_time_stat(JavaThread* thread);
 111 
 112   static DeadlockCycle*       find_deadlocks_at_safepoint(ThreadsList * t_list, bool object_monitors_only);
 113 
 114   // GC support
 115   static void   oops_do(OopClosure* f);
 116   static void   metadata_do(void f(Metadata*));




  41 class ThreadSnapshot;
  42 class StackFrameInfo;
  43 class ThreadConcurrentLocks;
  44 class DeadlockCycle;
  45 
  46 // VM monitoring and management support for the thread and
  47 // synchronization subsystem
  48 //
  49 // Thread contention monitoring is disabled by default.
  50 // When enabled, the VM will begin measuring the accumulated
  51 // elapsed time a thread blocked on synchronization.
  52 //
  53 class ThreadService : public AllStatic {
  54 private:
  55   // These counters could be moved to Threads class
  56   static PerfCounter*  _total_threads_count;
  57   static PerfVariable* _live_threads_count;
  58   static PerfVariable* _peak_threads_count;
  59   static PerfVariable* _daemon_threads_count;
  60 





  61   static bool          _thread_monitoring_contention_enabled;
  62   static bool          _thread_cpu_time_enabled;
  63   static bool          _thread_allocated_memory_enabled;
  64 
  65   // Need to keep the list of thread dump result that
  66   // keep references to Method* since thread dump can be
  67   // requested by multiple threads concurrently.
  68   static ThreadDumpResult* _threaddump_list;
  69 
  70   static void decrement_thread_counts(JavaThread* jt, bool daemon);
  71 
  72 public:
  73   static void init();
  74   static void add_thread(JavaThread* thread, bool daemon);
  75   static void remove_thread(JavaThread* thread, bool daemon);
  76   static void current_thread_exiting(JavaThread* jt, bool daemon);
  77 
  78   static bool set_thread_monitoring_contention(bool flag);
  79   static bool is_thread_monitoring_contention() { return _thread_monitoring_contention_enabled; }
  80 
  81   static bool set_thread_cpu_time_enabled(bool flag);
  82   static bool is_thread_cpu_time_enabled()    { return _thread_cpu_time_enabled; }
  83 
  84   static bool set_thread_allocated_memory_enabled(bool flag);
  85   static bool is_thread_allocated_memory_enabled() { return _thread_cpu_time_enabled; }
  86 
  87   static jlong get_total_thread_count()       { return _total_threads_count->get_value(); }
  88   static jlong get_peak_thread_count()        { return _peak_threads_count->get_value(); }
  89   static jlong get_live_thread_count()        { return _live_threads_count->get_value(); }
  90   static jlong get_daemon_thread_count()      { return _daemon_threads_count->get_value(); }



  91 
  92   // Support for thread dump
  93   static void   add_thread_dump(ThreadDumpResult* dump);
  94   static void   remove_thread_dump(ThreadDumpResult* dump);
  95 
  96   static Handle get_current_contended_monitor(JavaThread* thread);
  97 
  98   // This function is called by JVM_DumpThreads.
  99   static Handle dump_stack_traces(GrowableArray<instanceHandle>* threads,
 100                                   int num_threads, TRAPS);
 101 
 102   static void   reset_peak_thread_count();
 103   static void   reset_contention_count_stat(JavaThread* thread);
 104   static void   reset_contention_time_stat(JavaThread* thread);
 105 
 106   static DeadlockCycle*       find_deadlocks_at_safepoint(ThreadsList * t_list, bool object_monitors_only);
 107 
 108   // GC support
 109   static void   oops_do(OopClosure* f);
 110   static void   metadata_do(void f(Metadata*));


< prev index next >