annotate src/share/vm/services/threadService.hpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children 4d05b7cb7842
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 class OopClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
26 class ThreadDumpResult;
a61af66fc99e Initial load
duke
parents:
diff changeset
27 class ThreadStackTrace;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 class ThreadSnapshot;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 class StackFrameInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 class ThreadConcurrentLocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 class DeadlockCycle;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // VM monitoring and management support for the thread and
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // synchronization subsystem
a61af66fc99e Initial load
duke
parents:
diff changeset
35 //
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Thread contention monitoring is disabled by default.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // When enabled, the VM will begin measuring the accumulated
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // elapsed time a thread blocked on synchronization.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 //
a61af66fc99e Initial load
duke
parents:
diff changeset
40 class ThreadService : public AllStatic {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // These counters could be moved to Threads class
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static PerfCounter* _total_threads_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 static PerfVariable* _live_threads_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 static PerfVariable* _peak_threads_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 static PerfVariable* _daemon_threads_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // These 2 counters are atomically incremented once the thread is exiting.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // They will be atomically decremented when ThreadService::remove_thread is called.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 static volatile int _exiting_threads_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 static volatile int _exiting_daemon_threads_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 static bool _thread_monitoring_contention_enabled;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 static bool _thread_cpu_time_enabled;
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // Need to keep the list of thread dump result that
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // keep references to methodOop since thread dump can be
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // requested by multiple threads concurrently.
a61af66fc99e Initial load
duke
parents:
diff changeset
59 static ThreadDumpResult* _threaddump_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
62 static void init();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 static void add_thread(JavaThread* thread, bool daemon);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 static void remove_thread(JavaThread* thread, bool daemon);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 static void current_thread_exiting(JavaThread* jt);
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 static bool set_thread_monitoring_contention(bool flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 static bool is_thread_monitoring_contention() { return _thread_monitoring_contention_enabled; }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 static bool set_thread_cpu_time_enabled(bool flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 static bool is_thread_cpu_time_enabled() { return _thread_cpu_time_enabled; }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 static jlong get_total_thread_count() { return _total_threads_count->get_value(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 static jlong get_peak_thread_count() { return _peak_threads_count->get_value(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 static jlong get_live_thread_count() { return _live_threads_count->get_value() - _exiting_threads_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 static jlong get_daemon_thread_count() { return _daemon_threads_count->get_value() - _exiting_daemon_threads_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 static int exiting_threads_count() { return _exiting_threads_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 static int exiting_daemon_threads_count() { return _exiting_daemon_threads_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Support for thread dump
a61af66fc99e Initial load
duke
parents:
diff changeset
82 static void add_thread_dump(ThreadDumpResult* dump);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 static void remove_thread_dump(ThreadDumpResult* dump);
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 static Handle get_current_contended_monitor(JavaThread* thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // This function is called by JVM_DumpThreads.
a61af66fc99e Initial load
duke
parents:
diff changeset
88 static Handle dump_stack_traces(GrowableArray<instanceHandle>* threads,
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int num_threads, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 static void reset_peak_thread_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 static void reset_contention_count_stat(JavaThread* thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 static void reset_contention_time_stat(JavaThread* thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static DeadlockCycle* find_deadlocks_at_safepoint(bool object_monitors_only);
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
98 static void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 };
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Per-thread Statistics for synchronization
a61af66fc99e Initial load
duke
parents:
diff changeset
102 class ThreadStatistics : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // The following contention statistics are only updated by
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // the thread owning these statistics when contention occurs.
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 jlong _contended_enter_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 elapsedTimer _contended_enter_timer;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 jlong _monitor_wait_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 elapsedTimer _monitor_wait_timer;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 jlong _sleep_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 elapsedTimer _sleep_timer;
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // These two reset flags are set to true when another thread
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // requests to reset the statistics. The actual statistics
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // are reset when the thread contention occurs and attempts
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // to update the statistics.
a61af66fc99e Initial load
duke
parents:
diff changeset
119 bool _count_pending_reset;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 bool _timer_pending_reset;
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // Keep accurate times for potentially recursive class operations
a61af66fc99e Initial load
duke
parents:
diff changeset
123 int _class_init_recursion_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 int _class_verify_recursion_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 int _class_link_recursion_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // utility functions
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void check_and_reset_count() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (!_count_pending_reset) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 _contended_enter_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _monitor_wait_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _sleep_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _count_pending_reset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void check_and_reset_timer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if (!_timer_pending_reset) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 _contended_enter_timer.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 _monitor_wait_timer.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 _sleep_timer.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 _timer_pending_reset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
144 ThreadStatistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 jlong contended_enter_count() { return (_count_pending_reset ? 0 : _contended_enter_count); }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 jlong contended_enter_ticks() { return (_timer_pending_reset ? 0 : _contended_enter_timer.active_ticks()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 jlong monitor_wait_count() { return (_count_pending_reset ? 0 : _monitor_wait_count); }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 jlong monitor_wait_ticks() { return (_timer_pending_reset ? 0 : _monitor_wait_timer.active_ticks()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 jlong sleep_count() { return (_count_pending_reset ? 0 : _sleep_count); }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 jlong sleep_ticks() { return (_timer_pending_reset ? 0 : _sleep_timer.active_ticks()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 void monitor_wait() { check_and_reset_count(); _monitor_wait_count++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 void monitor_wait_begin() { check_and_reset_timer(); _monitor_wait_timer.start(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 void monitor_wait_end() { _monitor_wait_timer.stop(); check_and_reset_timer(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void thread_sleep() { check_and_reset_count(); _sleep_count++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 void thread_sleep_begin() { check_and_reset_timer(); _sleep_timer.start(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 void thread_sleep_end() { _sleep_timer.stop(); check_and_reset_timer(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 void contended_enter() { check_and_reset_count(); _contended_enter_count++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 void contended_enter_begin() { check_and_reset_timer(); _contended_enter_timer.start(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 void contended_enter_end() { _contended_enter_timer.stop(); check_and_reset_timer(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 void reset_count_stat() { _count_pending_reset = true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 void reset_time_stat() { _timer_pending_reset = true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 int* class_init_recursion_count_addr() { return &_class_init_recursion_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 int* class_verify_recursion_count_addr() { return &_class_verify_recursion_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 int* class_link_recursion_count_addr() { return &_class_link_recursion_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 };
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Thread snapshot to represent the thread state and statistics
a61af66fc99e Initial load
duke
parents:
diff changeset
174 class ThreadSnapshot : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
176 JavaThread* _thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 oop _threadObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 java_lang_Thread::ThreadStatus _thread_status;
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 bool _is_ext_suspended;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 bool _is_in_native;
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 jlong _contended_enter_ticks;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 jlong _contended_enter_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 jlong _monitor_wait_ticks;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 jlong _monitor_wait_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 jlong _sleep_ticks;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 jlong _sleep_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 oop _blocker_object;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 oop _blocker_object_owner;
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 ThreadStackTrace* _stack_trace;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 ThreadConcurrentLocks* _concurrent_locks;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 ThreadSnapshot* _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // Dummy snapshot
a61af66fc99e Initial load
duke
parents:
diff changeset
198 ThreadSnapshot() : _thread(NULL), _threadObj(NULL), _stack_trace(NULL), _concurrent_locks(NULL), _next(NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
199 _blocker_object(NULL), _blocker_object_owner(NULL) {};
a61af66fc99e Initial load
duke
parents:
diff changeset
200 ThreadSnapshot(JavaThread* thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 ~ThreadSnapshot();
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 java_lang_Thread::ThreadStatus thread_status() { return _thread_status; }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 oop threadObj() const { return _threadObj; }
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 void set_next(ThreadSnapshot* n) { _next = n; }
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 bool is_ext_suspended() { return _is_ext_suspended; }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 bool is_in_native() { return _is_in_native; }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 jlong contended_enter_count() { return _contended_enter_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 jlong contended_enter_ticks() { return _contended_enter_ticks; }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 jlong monitor_wait_count() { return _monitor_wait_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 jlong monitor_wait_ticks() { return _monitor_wait_ticks; }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 jlong sleep_count() { return _sleep_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 jlong sleep_ticks() { return _sleep_ticks; }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 oop blocker_object() { return _blocker_object; }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 oop blocker_object_owner() { return _blocker_object_owner; }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 ThreadSnapshot* next() const { return _next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 ThreadStackTrace* get_stack_trace() { return _stack_trace; }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 ThreadConcurrentLocks* get_concurrent_locks() { return _concurrent_locks; }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 void dump_stack_at_safepoint(int max_depth, bool with_locked_monitors);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 void set_concurrent_locks(ThreadConcurrentLocks* l) { _concurrent_locks = l; }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 };
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 class ThreadStackTrace : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
234 JavaThread* _thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 int _depth; // number of stack frames added
a61af66fc99e Initial load
duke
parents:
diff changeset
236 bool _with_locked_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 GrowableArray<StackFrameInfo*>* _frames;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 GrowableArray<oop>* _jni_locked_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 ThreadStackTrace(JavaThread* thread, bool with_locked_monitors);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 ~ThreadStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 StackFrameInfo* stack_frame_at(int i) { return _frames->at(i); }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 int get_stack_depth() { return _depth; }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 void add_stack_frame(javaVFrame* jvf);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 void dump_stack_at_safepoint(int max_depth);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 Handle allocate_fill_stack_trace_element_array(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
251 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 GrowableArray<oop>* jni_locked_monitors() { return _jni_locked_monitors; }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 int num_jni_locked_monitors() { return (_jni_locked_monitors != NULL ? _jni_locked_monitors->length() : 0); }
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 bool is_owned_monitor_on_stack(oop object);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 void add_jni_locked_monitor(oop object) { _jni_locked_monitors->append(object); }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 };
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // StackFrameInfo for keeping methodOop and bci during
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // stack walking for later construction of StackTraceElement[]
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // Java instances
a61af66fc99e Initial load
duke
parents:
diff changeset
262 class StackFrameInfo : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
264 methodOop _method;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 int _bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
266 GrowableArray<oop>* _locked_monitors; // list of object monitors locked by this frame
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 StackFrameInfo(javaVFrame* jvf, bool with_locked_monitors);
a61af66fc99e Initial load
duke
parents:
diff changeset
271 ~StackFrameInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (_locked_monitors != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 delete _locked_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 };
a61af66fc99e Initial load
duke
parents:
diff changeset
276 methodOop method() const { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 int bci() const { return _bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
278 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 int num_locked_monitors() { return (_locked_monitors != NULL ? _locked_monitors->length() : 0); }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 GrowableArray<oop>* locked_monitors() { return _locked_monitors; }
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 void print_on(outputStream* st) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 };
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 class ThreadConcurrentLocks : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
288 GrowableArray<instanceOop>* _owned_locks;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 ThreadConcurrentLocks* _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 JavaThread* _thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
291 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
292 ThreadConcurrentLocks(JavaThread* thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 ~ThreadConcurrentLocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 void add_lock(instanceOop o);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 void set_next(ThreadConcurrentLocks* n) { _next = n; }
a61af66fc99e Initial load
duke
parents:
diff changeset
297 ThreadConcurrentLocks* next() { return _next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 JavaThread* java_thread() { return _thread; }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 GrowableArray<instanceOop>* owned_locks() { return _owned_locks; }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 };
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 class ConcurrentLocksDump : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
305 ThreadConcurrentLocks* _map;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 ThreadConcurrentLocks* _last; // Last ThreadConcurrentLocks in the map
a61af66fc99e Initial load
duke
parents:
diff changeset
307 bool _retain_map_on_free;
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 void build_map(GrowableArray<oop>* aos_objects);
a61af66fc99e Initial load
duke
parents:
diff changeset
310 void add_lock(JavaThread* thread, instanceOop o);
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
313 ConcurrentLocksDump(bool retain_map_on_free) : _map(NULL), _last(NULL), _retain_map_on_free(retain_map_on_free) {};
a61af66fc99e Initial load
duke
parents:
diff changeset
314 ConcurrentLocksDump() : _map(NULL), _last(NULL), _retain_map_on_free(false) {};
a61af66fc99e Initial load
duke
parents:
diff changeset
315 ~ConcurrentLocksDump();
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 void dump_at_safepoint();
a61af66fc99e Initial load
duke
parents:
diff changeset
318 ThreadConcurrentLocks* thread_concurrent_locks(JavaThread* thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 void print_locks_on(JavaThread* t, outputStream* st);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 };
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 class ThreadDumpResult : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
324 int _num_threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 int _num_snapshots;
a61af66fc99e Initial load
duke
parents:
diff changeset
326 ThreadSnapshot* _snapshots;
a61af66fc99e Initial load
duke
parents:
diff changeset
327 ThreadSnapshot* _last;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 ThreadDumpResult* _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
330 ThreadDumpResult();
a61af66fc99e Initial load
duke
parents:
diff changeset
331 ThreadDumpResult(int num_threads);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 ~ThreadDumpResult();
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 void add_thread_snapshot(ThreadSnapshot* ts);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 void set_next(ThreadDumpResult* next) { _next = next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
336 ThreadDumpResult* next() { return _next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
337 int num_threads() { return _num_threads; }
a61af66fc99e Initial load
duke
parents:
diff changeset
338 int num_snapshots() { return _num_snapshots; }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 ThreadSnapshot* snapshots() { return _snapshots; }
a61af66fc99e Initial load
duke
parents:
diff changeset
340 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
341 };
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 class DeadlockCycle : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
345 bool _is_deadlock;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 GrowableArray<JavaThread*>* _threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 DeadlockCycle* _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
348 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
349 DeadlockCycle();
a61af66fc99e Initial load
duke
parents:
diff changeset
350 ~DeadlockCycle();
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 DeadlockCycle* next() { return _next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 void set_next(DeadlockCycle* d) { _next = d; }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 void add_thread(JavaThread* t) { _threads->append(t); }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 void reset() { _is_deadlock = false; _threads->clear(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
356 void set_deadlock(bool value) { _is_deadlock = value; }
a61af66fc99e Initial load
duke
parents:
diff changeset
357 bool is_deadlock() { return _is_deadlock; }
a61af66fc99e Initial load
duke
parents:
diff changeset
358 int num_threads() { return _threads->length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
359 GrowableArray<JavaThread*>* threads() { return _threads; }
a61af66fc99e Initial load
duke
parents:
diff changeset
360 void print_on(outputStream* st) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 };
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 // Utility class to get list of java threads.
a61af66fc99e Initial load
duke
parents:
diff changeset
364 class ThreadsListEnumerator : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
366 GrowableArray<instanceHandle>* _threads_array;
a61af66fc99e Initial load
duke
parents:
diff changeset
367 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
368 ThreadsListEnumerator(Thread* cur_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
369 bool include_jvmti_agent_threads = false,
a61af66fc99e Initial load
duke
parents:
diff changeset
370 bool include_jni_attaching_threads = true);
a61af66fc99e Initial load
duke
parents:
diff changeset
371 int num_threads() { return _threads_array->length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
372 instanceHandle get_threadObj(int index) { return _threads_array->at(index); }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 };
a61af66fc99e Initial load
duke
parents:
diff changeset
374
a61af66fc99e Initial load
duke
parents:
diff changeset
375
a61af66fc99e Initial load
duke
parents:
diff changeset
376 // abstract utility class to set new thread states, and restore previous after the block exits
a61af66fc99e Initial load
duke
parents:
diff changeset
377 class JavaThreadStatusChanger : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
379 java_lang_Thread::ThreadStatus _old_state;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 JavaThread* _java_thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
381 bool _is_alive;
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 void save_old_state(JavaThread* java_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 _java_thread = java_thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
385 _is_alive = is_alive(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 if (is_alive()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 _old_state = java_lang_Thread::get_thread_status(_java_thread->threadObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
392 static void set_thread_status(JavaThread* java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
393 java_lang_Thread::ThreadStatus state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 java_lang_Thread::set_thread_status(java_thread->threadObj(), state);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397 void set_thread_status(java_lang_Thread::ThreadStatus state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
398 if (is_alive()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 set_thread_status(_java_thread, state);
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 JavaThreadStatusChanger(JavaThread* java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
404 java_lang_Thread::ThreadStatus state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 save_old_state(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 set_thread_status(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 JavaThreadStatusChanger(JavaThread* java_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 save_old_state(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 ~JavaThreadStatusChanger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 set_thread_status(_old_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 static bool is_alive(JavaThread* java_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 return java_thread != NULL && java_thread->threadObj() != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 bool is_alive() {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 return _is_alive;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424 };
a61af66fc99e Initial load
duke
parents:
diff changeset
425
a61af66fc99e Initial load
duke
parents:
diff changeset
426 // Change status to waiting on an object (timed or indefinite)
a61af66fc99e Initial load
duke
parents:
diff changeset
427 class JavaThreadInObjectWaitState : public JavaThreadStatusChanger {
a61af66fc99e Initial load
duke
parents:
diff changeset
428 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
429 ThreadStatistics* _stat;
a61af66fc99e Initial load
duke
parents:
diff changeset
430 bool _active;
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
433 JavaThreadInObjectWaitState(JavaThread *java_thread, bool timed) :
a61af66fc99e Initial load
duke
parents:
diff changeset
434 JavaThreadStatusChanger(java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
435 timed ? java_lang_Thread::IN_OBJECT_WAIT_TIMED : java_lang_Thread::IN_OBJECT_WAIT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 if (is_alive()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 _stat = java_thread->get_thread_stat();
a61af66fc99e Initial load
duke
parents:
diff changeset
438 _active = ThreadService::is_thread_monitoring_contention();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 _stat->monitor_wait();
a61af66fc99e Initial load
duke
parents:
diff changeset
440 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 _stat->monitor_wait_begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 _active = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 ~JavaThreadInObjectWaitState() {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
450 _stat->monitor_wait_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453 };
a61af66fc99e Initial load
duke
parents:
diff changeset
454
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // Change status to parked (timed or indefinite)
a61af66fc99e Initial load
duke
parents:
diff changeset
456 class JavaThreadParkedState : public JavaThreadStatusChanger {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
458 ThreadStatistics* _stat;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 bool _active;
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
462 JavaThreadParkedState(JavaThread *java_thread, bool timed) :
a61af66fc99e Initial load
duke
parents:
diff changeset
463 JavaThreadStatusChanger(java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
464 timed ? java_lang_Thread::PARKED_TIMED : java_lang_Thread::PARKED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 if (is_alive()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 _stat = java_thread->get_thread_stat();
a61af66fc99e Initial load
duke
parents:
diff changeset
467 _active = ThreadService::is_thread_monitoring_contention();
a61af66fc99e Initial load
duke
parents:
diff changeset
468 _stat->monitor_wait();
a61af66fc99e Initial load
duke
parents:
diff changeset
469 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 _stat->monitor_wait_begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
472 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 _active = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 ~JavaThreadParkedState() {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
479 _stat->monitor_wait_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482 };
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // Change status to blocked on (re-)entering a synchronization block
a61af66fc99e Initial load
duke
parents:
diff changeset
485 class JavaThreadBlockedOnMonitorEnterState : public JavaThreadStatusChanger {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
487 ThreadStatistics* _stat;
a61af66fc99e Initial load
duke
parents:
diff changeset
488 bool _active;
a61af66fc99e Initial load
duke
parents:
diff changeset
489
a61af66fc99e Initial load
duke
parents:
diff changeset
490 static bool contended_enter_begin(JavaThread *java_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
491 set_thread_status(java_thread, java_lang_Thread::BLOCKED_ON_MONITOR_ENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
492 ThreadStatistics* stat = java_thread->get_thread_stat();
a61af66fc99e Initial load
duke
parents:
diff changeset
493 stat->contended_enter();
a61af66fc99e Initial load
duke
parents:
diff changeset
494 bool active = ThreadService::is_thread_monitoring_contention();
a61af66fc99e Initial load
duke
parents:
diff changeset
495 if (active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 stat->contended_enter_begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498 return active;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // java_thread is waiting thread being blocked on monitor reenter.
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // Current thread is the notifying thread which holds the monitor.
a61af66fc99e Initial load
duke
parents:
diff changeset
504 static bool wait_reenter_begin(JavaThread *java_thread, ObjectMonitor *obj_m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 assert((java_thread != NULL), "Java thread should not be null here");
a61af66fc99e Initial load
duke
parents:
diff changeset
506 bool active = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (is_alive(java_thread) && ServiceUtil::visible_oop((oop)obj_m->object())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 active = contended_enter_begin(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
509 }
a61af66fc99e Initial load
duke
parents:
diff changeset
510 return active;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 }
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513 static void wait_reenter_end(JavaThread *java_thread, bool active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
514 if (active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 java_thread->get_thread_stat()->contended_enter_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517 set_thread_status(java_thread, java_lang_Thread::RUNNABLE);
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520 JavaThreadBlockedOnMonitorEnterState(JavaThread *java_thread, ObjectMonitor *obj_m) :
a61af66fc99e Initial load
duke
parents:
diff changeset
521 JavaThreadStatusChanger(java_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 assert((java_thread != NULL), "Java thread should not be null here");
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // Change thread status and collect contended enter stats for monitor contended
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // enter done for external java world objects and it is contended. All other cases
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // like for vm internal objects and for external objects which are not contended
a61af66fc99e Initial load
duke
parents:
diff changeset
526 // thread status is not changed and contended enter stat is not collected.
a61af66fc99e Initial load
duke
parents:
diff changeset
527 _active = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
528 if (is_alive() && ServiceUtil::visible_oop((oop)obj_m->object()) && obj_m->contentions() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
529 _stat = java_thread->get_thread_stat();
a61af66fc99e Initial load
duke
parents:
diff changeset
530 _active = contended_enter_begin(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533
a61af66fc99e Initial load
duke
parents:
diff changeset
534 ~JavaThreadBlockedOnMonitorEnterState() {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
536 _stat->contended_enter_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
539 };
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // Change status to sleeping
a61af66fc99e Initial load
duke
parents:
diff changeset
542 class JavaThreadSleepState : public JavaThreadStatusChanger {
a61af66fc99e Initial load
duke
parents:
diff changeset
543 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
544 ThreadStatistics* _stat;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 bool _active;
a61af66fc99e Initial load
duke
parents:
diff changeset
546 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
547 JavaThreadSleepState(JavaThread *java_thread) :
a61af66fc99e Initial load
duke
parents:
diff changeset
548 JavaThreadStatusChanger(java_thread, java_lang_Thread::SLEEPING) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 if (is_alive()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
550 _stat = java_thread->get_thread_stat();
a61af66fc99e Initial load
duke
parents:
diff changeset
551 _active = ThreadService::is_thread_monitoring_contention();
a61af66fc99e Initial load
duke
parents:
diff changeset
552 _stat->thread_sleep();
a61af66fc99e Initial load
duke
parents:
diff changeset
553 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
554 _stat->thread_sleep_begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
556 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
557 _active = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
558 }
a61af66fc99e Initial load
duke
parents:
diff changeset
559 }
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561 ~JavaThreadSleepState() {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
563 _stat->thread_sleep_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
566 };