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 // These 2 counters are like the above thread counts, but are
62 // atomically decremented in ThreadService::current_thread_exiting instead of
63 // ThreadService::remove_thread, so that the thread count is updated before
64 // Thread.join() returns.
65 static volatile int _atomic_threads_count;
66 static volatile int _atomic_daemon_threads_count;
67
68 static bool _thread_monitoring_contention_enabled;
69 static bool _thread_cpu_time_enabled;
70 static bool _thread_allocated_memory_enabled;
71
72 // Need to keep the list of thread dump result that
73 // keep references to Method* since thread dump can be
74 // requested by multiple threads concurrently.
75 static ThreadDumpResult* _threaddump_list;
76
77 static void decrement_thread_counts(JavaThread* jt);
78
79 public:
80 static void init();
81 static void add_thread(JavaThread* thread, bool daemon);
82 static void remove_thread(JavaThread* thread, bool daemon);
83 static void current_thread_exiting(JavaThread* jt);
84
85 static bool set_thread_monitoring_contention(bool flag);
86 static bool is_thread_monitoring_contention() { return _thread_monitoring_contention_enabled; }
87
88 static bool set_thread_cpu_time_enabled(bool flag);
89 static bool is_thread_cpu_time_enabled() { return _thread_cpu_time_enabled; }
90
91 static bool set_thread_allocated_memory_enabled(bool flag);
92 static bool is_thread_allocated_memory_enabled() { return _thread_cpu_time_enabled; }
93
94 static jlong get_total_thread_count() { return _total_threads_count->get_value(); }
95 static jlong get_peak_thread_count() { return _peak_threads_count->get_value(); }
96 static jlong get_live_thread_count() { return _atomic_threads_count; }
97 static jlong get_daemon_thread_count() { return _atomic_daemon_threads_count; }
98
99 // Support for thread dump
100 static void add_thread_dump(ThreadDumpResult* dump);
101 static void remove_thread_dump(ThreadDumpResult* dump);
102
103 static Handle get_current_contended_monitor(JavaThread* thread);
104
105 // This function is called by JVM_DumpThreads.
106 static Handle dump_stack_traces(GrowableArray<instanceHandle>* threads,
107 int num_threads, TRAPS);
108
109 static void reset_peak_thread_count();
110 static void reset_contention_count_stat(JavaThread* thread);
111 static void reset_contention_time_stat(JavaThread* thread);
112
113 static DeadlockCycle* find_deadlocks_at_safepoint(ThreadsList * t_list, bool object_monitors_only);
114
115 // GC support
116 static void oops_do(OopClosure* f);
117 static void metadata_do(void f(Metadata*));
|