56 static PerfCounter* _total_threads_count; |
56 static PerfCounter* _total_threads_count; |
57 static PerfVariable* _live_threads_count; |
57 static PerfVariable* _live_threads_count; |
58 static PerfVariable* _peak_threads_count; |
58 static PerfVariable* _peak_threads_count; |
59 static PerfVariable* _daemon_threads_count; |
59 static PerfVariable* _daemon_threads_count; |
60 |
60 |
61 // These 2 counters are atomically incremented once the thread is exiting. |
61 // These 2 counters are like the above thread counts, but are |
62 // They will be atomically decremented when ThreadService::remove_thread is called. |
62 // atomically decremented in ThreadService::current_thread_exiting instead of |
63 static volatile int _exiting_threads_count; |
63 // ThreadService::remove_thread, so that the thread count is updated before |
64 static volatile int _exiting_daemon_threads_count; |
64 // Thread.join() returns. |
|
65 static volatile int _atomic_threads_count; |
|
66 static volatile int _atomic_daemon_threads_count; |
65 |
67 |
66 static bool _thread_monitoring_contention_enabled; |
68 static bool _thread_monitoring_contention_enabled; |
67 static bool _thread_cpu_time_enabled; |
69 static bool _thread_cpu_time_enabled; |
68 static bool _thread_allocated_memory_enabled; |
70 static bool _thread_allocated_memory_enabled; |
69 |
71 |
70 // Need to keep the list of thread dump result that |
72 // Need to keep the list of thread dump result that |
71 // keep references to Method* since thread dump can be |
73 // keep references to Method* since thread dump can be |
72 // requested by multiple threads concurrently. |
74 // requested by multiple threads concurrently. |
73 static ThreadDumpResult* _threaddump_list; |
75 static ThreadDumpResult* _threaddump_list; |
74 |
76 |
|
77 static void decrement_thread_counts(JavaThread* jt, bool daemon); |
|
78 |
75 public: |
79 public: |
76 static void init(); |
80 static void init(); |
77 static void add_thread(JavaThread* thread, bool daemon); |
81 static void add_thread(JavaThread* thread, bool daemon); |
78 static void remove_thread(JavaThread* thread, bool daemon); |
82 static void remove_thread(JavaThread* thread, bool daemon); |
79 static void current_thread_exiting(JavaThread* jt); |
83 static void current_thread_exiting(JavaThread* jt, bool daemon); |
80 |
84 |
81 static bool set_thread_monitoring_contention(bool flag); |
85 static bool set_thread_monitoring_contention(bool flag); |
82 static bool is_thread_monitoring_contention() { return _thread_monitoring_contention_enabled; } |
86 static bool is_thread_monitoring_contention() { return _thread_monitoring_contention_enabled; } |
83 |
87 |
84 static bool set_thread_cpu_time_enabled(bool flag); |
88 static bool set_thread_cpu_time_enabled(bool flag); |
87 static bool set_thread_allocated_memory_enabled(bool flag); |
91 static bool set_thread_allocated_memory_enabled(bool flag); |
88 static bool is_thread_allocated_memory_enabled() { return _thread_cpu_time_enabled; } |
92 static bool is_thread_allocated_memory_enabled() { return _thread_cpu_time_enabled; } |
89 |
93 |
90 static jlong get_total_thread_count() { return _total_threads_count->get_value(); } |
94 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(); } |
95 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; } |
96 static jlong get_live_thread_count() { return _atomic_threads_count; } |
93 static jlong get_daemon_thread_count() { return _daemon_threads_count->get_value() - _exiting_daemon_threads_count; } |
97 static jlong get_daemon_thread_count() { return _atomic_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 |
98 // Support for thread dump |
99 // Support for thread dump |
99 static void add_thread_dump(ThreadDumpResult* dump); |
100 static void add_thread_dump(ThreadDumpResult* dump); |
100 static void remove_thread_dump(ThreadDumpResult* dump); |
101 static void remove_thread_dump(ThreadDumpResult* dump); |
101 |
102 |