Mercurial > hg > graal-compiler
annotate src/share/vm/services/threadService.cpp @ 19739:6a3832494e24
Check for derived pointers before passing BytecodeFrame into HotSpot
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Mon, 09 Mar 2015 13:07:18 -0700 |
parents | 78bbf4d43a14 |
children | ce8f6bb717c9 |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
13391
diff
changeset
|
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "memory/allocation.hpp" | |
28 #include "memory/heapInspection.hpp" | |
29 #include "memory/oopFactory.hpp" | |
30 #include "oops/instanceKlass.hpp" | |
31 #include "oops/oop.inline.hpp" | |
32 #include "runtime/handles.inline.hpp" | |
33 #include "runtime/init.hpp" | |
34 #include "runtime/thread.hpp" | |
35 #include "runtime/vframe.hpp" | |
36 #include "runtime/vmThread.hpp" | |
37 #include "runtime/vm_operations.hpp" | |
38 #include "services/threadService.hpp" | |
0 | 39 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
13391
diff
changeset
|
40 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
13391
diff
changeset
|
41 |
0 | 42 // TODO: we need to define a naming convention for perf counters |
43 // to distinguish counters for: | |
44 // - standard JSR174 use | |
45 // - Hotspot extension (public and committed) | |
46 // - Hotspot extension (private/internal and uncommitted) | |
47 | |
48 // Default is disabled. | |
49 bool ThreadService::_thread_monitoring_contention_enabled = false; | |
50 bool ThreadService::_thread_cpu_time_enabled = false; | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
51 bool ThreadService::_thread_allocated_memory_enabled = false; |
0 | 52 |
53 PerfCounter* ThreadService::_total_threads_count = NULL; | |
54 PerfVariable* ThreadService::_live_threads_count = NULL; | |
55 PerfVariable* ThreadService::_peak_threads_count = NULL; | |
56 PerfVariable* ThreadService::_daemon_threads_count = NULL; | |
57 volatile int ThreadService::_exiting_threads_count = 0; | |
58 volatile int ThreadService::_exiting_daemon_threads_count = 0; | |
59 | |
60 ThreadDumpResult* ThreadService::_threaddump_list = NULL; | |
61 | |
62 static const int INITIAL_ARRAY_SIZE = 10; | |
63 | |
64 void ThreadService::init() { | |
65 EXCEPTION_MARK; | |
66 | |
67 // These counters are for java.lang.management API support. | |
68 // They are created even if -XX:-UsePerfData is set and in | |
69 // that case, they will be allocated on C heap. | |
70 | |
71 _total_threads_count = | |
72 PerfDataManager::create_counter(JAVA_THREADS, "started", | |
73 PerfData::U_Events, CHECK); | |
74 | |
75 _live_threads_count = | |
76 PerfDataManager::create_variable(JAVA_THREADS, "live", | |
77 PerfData::U_None, CHECK); | |
78 | |
79 _peak_threads_count = | |
80 PerfDataManager::create_variable(JAVA_THREADS, "livePeak", | |
81 PerfData::U_None, CHECK); | |
82 | |
83 _daemon_threads_count = | |
84 PerfDataManager::create_variable(JAVA_THREADS, "daemon", | |
85 PerfData::U_None, CHECK); | |
86 | |
87 if (os::is_thread_cpu_time_supported()) { | |
88 _thread_cpu_time_enabled = true; | |
89 } | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
90 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
91 _thread_allocated_memory_enabled = true; // Always on, so enable it |
0 | 92 } |
93 | |
94 void ThreadService::reset_peak_thread_count() { | |
95 // Acquire the lock to update the peak thread count | |
96 // to synchronize with thread addition and removal. | |
97 MutexLockerEx mu(Threads_lock); | |
98 _peak_threads_count->set_value(get_live_thread_count()); | |
99 } | |
100 | |
101 void ThreadService::add_thread(JavaThread* thread, bool daemon) { | |
102 // Do not count VM internal or JVMTI agent threads | |
103 if (thread->is_hidden_from_external_view() || | |
104 thread->is_jvmti_agent_thread()) { | |
105 return; | |
106 } | |
107 | |
108 _total_threads_count->inc(); | |
109 _live_threads_count->inc(); | |
110 | |
111 if (_live_threads_count->get_value() > _peak_threads_count->get_value()) { | |
112 _peak_threads_count->set_value(_live_threads_count->get_value()); | |
113 } | |
114 | |
115 if (daemon) { | |
116 _daemon_threads_count->inc(); | |
117 } | |
118 } | |
119 | |
120 void ThreadService::remove_thread(JavaThread* thread, bool daemon) { | |
121 Atomic::dec((jint*) &_exiting_threads_count); | |
122 | |
123 if (thread->is_hidden_from_external_view() || | |
124 thread->is_jvmti_agent_thread()) { | |
125 return; | |
126 } | |
127 | |
128 _live_threads_count->set_value(_live_threads_count->get_value() - 1); | |
129 | |
130 if (daemon) { | |
131 _daemon_threads_count->set_value(_daemon_threads_count->get_value() - 1); | |
132 Atomic::dec((jint*) &_exiting_daemon_threads_count); | |
133 } | |
134 } | |
135 | |
136 void ThreadService::current_thread_exiting(JavaThread* jt) { | |
137 assert(jt == JavaThread::current(), "Called by current thread"); | |
138 Atomic::inc((jint*) &_exiting_threads_count); | |
139 | |
140 oop threadObj = jt->threadObj(); | |
141 if (threadObj != NULL && java_lang_Thread::is_daemon(threadObj)) { | |
142 Atomic::inc((jint*) &_exiting_daemon_threads_count); | |
143 } | |
144 } | |
145 | |
146 // FIXME: JVMTI should call this function | |
147 Handle ThreadService::get_current_contended_monitor(JavaThread* thread) { | |
148 assert(thread != NULL, "should be non-NULL"); | |
149 assert(Threads_lock->owned_by_self(), "must grab Threads_lock or be at safepoint"); | |
150 | |
151 ObjectMonitor *wait_obj = thread->current_waiting_monitor(); | |
152 | |
153 oop obj = NULL; | |
154 if (wait_obj != NULL) { | |
155 // thread is doing an Object.wait() call | |
156 obj = (oop) wait_obj->object(); | |
157 assert(obj != NULL, "Object.wait() should have an object"); | |
158 } else { | |
159 ObjectMonitor *enter_obj = thread->current_pending_monitor(); | |
160 if (enter_obj != NULL) { | |
161 // thread is trying to enter() or raw_enter() an ObjectMonitor. | |
162 obj = (oop) enter_obj->object(); | |
163 } | |
164 // If obj == NULL, then ObjectMonitor is raw which doesn't count. | |
165 } | |
166 | |
167 Handle h(obj); | |
168 return h; | |
169 } | |
170 | |
171 bool ThreadService::set_thread_monitoring_contention(bool flag) { | |
172 MutexLocker m(Management_lock); | |
173 | |
174 bool prev = _thread_monitoring_contention_enabled; | |
175 _thread_monitoring_contention_enabled = flag; | |
176 | |
177 return prev; | |
178 } | |
179 | |
180 bool ThreadService::set_thread_cpu_time_enabled(bool flag) { | |
181 MutexLocker m(Management_lock); | |
182 | |
183 bool prev = _thread_cpu_time_enabled; | |
184 _thread_cpu_time_enabled = flag; | |
185 | |
186 return prev; | |
187 } | |
188 | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
189 bool ThreadService::set_thread_allocated_memory_enabled(bool flag) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
190 MutexLocker m(Management_lock); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
191 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
192 bool prev = _thread_allocated_memory_enabled; |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
193 _thread_allocated_memory_enabled = flag; |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
194 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
195 return prev; |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
196 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
197 |
0 | 198 // GC support |
199 void ThreadService::oops_do(OopClosure* f) { | |
200 for (ThreadDumpResult* dump = _threaddump_list; dump != NULL; dump = dump->next()) { | |
201 dump->oops_do(f); | |
202 } | |
203 } | |
204 | |
13391
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
205 void ThreadService::metadata_do(void f(Metadata*)) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
206 for (ThreadDumpResult* dump = _threaddump_list; dump != NULL; dump = dump->next()) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
207 dump->metadata_do(f); |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
208 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
209 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
210 |
0 | 211 void ThreadService::add_thread_dump(ThreadDumpResult* dump) { |
212 MutexLocker ml(Management_lock); | |
213 if (_threaddump_list == NULL) { | |
214 _threaddump_list = dump; | |
215 } else { | |
216 dump->set_next(_threaddump_list); | |
217 _threaddump_list = dump; | |
218 } | |
219 } | |
220 | |
221 void ThreadService::remove_thread_dump(ThreadDumpResult* dump) { | |
222 MutexLocker ml(Management_lock); | |
223 | |
224 ThreadDumpResult* prev = NULL; | |
225 bool found = false; | |
226 for (ThreadDumpResult* d = _threaddump_list; d != NULL; prev = d, d = d->next()) { | |
227 if (d == dump) { | |
228 if (prev == NULL) { | |
229 _threaddump_list = dump->next(); | |
230 } else { | |
231 prev->set_next(dump->next()); | |
232 } | |
233 found = true; | |
234 break; | |
235 } | |
236 } | |
237 assert(found, "The threaddump result to be removed must exist."); | |
238 } | |
239 | |
240 // Dump stack trace of threads specified in the given threads array. | |
241 // Returns StackTraceElement[][] each element is the stack trace of a thread in | |
242 // the corresponding entry in the given threads array | |
243 Handle ThreadService::dump_stack_traces(GrowableArray<instanceHandle>* threads, | |
244 int num_threads, | |
245 TRAPS) { | |
246 assert(num_threads > 0, "just checking"); | |
247 | |
248 ThreadDumpResult dump_result; | |
249 VM_ThreadDump op(&dump_result, | |
250 threads, | |
251 num_threads, | |
252 -1, /* entire stack */ | |
253 false, /* with locked monitors */ | |
254 false /* with locked synchronizers */); | |
255 VMThread::execute(&op); | |
256 | |
257 // Allocate the resulting StackTraceElement[][] object | |
258 | |
259 ResourceMark rm(THREAD); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
260 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackTraceElement_array(), true, CHECK_NH); |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6725
diff
changeset
|
261 ObjArrayKlass* ik = ObjArrayKlass::cast(k); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
262 objArrayOop r = oopFactory::new_objArray(ik, num_threads, CHECK_NH); |
0 | 263 objArrayHandle result_obj(THREAD, r); |
264 | |
265 int num_snapshots = dump_result.num_snapshots(); | |
266 assert(num_snapshots == num_threads, "Must have num_threads thread snapshots"); | |
267 int i = 0; | |
268 for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; i++, ts = ts->next()) { | |
269 ThreadStackTrace* stacktrace = ts->get_stack_trace(); | |
270 if (stacktrace == NULL) { | |
271 // No stack trace | |
272 result_obj->obj_at_put(i, NULL); | |
273 } else { | |
274 // Construct an array of java/lang/StackTraceElement object | |
275 Handle backtrace_h = stacktrace->allocate_fill_stack_trace_element_array(CHECK_NH); | |
276 result_obj->obj_at_put(i, backtrace_h()); | |
277 } | |
278 } | |
279 | |
280 return result_obj; | |
281 } | |
282 | |
283 void ThreadService::reset_contention_count_stat(JavaThread* thread) { | |
284 ThreadStatistics* stat = thread->get_thread_stat(); | |
285 if (stat != NULL) { | |
286 stat->reset_count_stat(); | |
287 } | |
288 } | |
289 | |
290 void ThreadService::reset_contention_time_stat(JavaThread* thread) { | |
291 ThreadStatistics* stat = thread->get_thread_stat(); | |
292 if (stat != NULL) { | |
293 stat->reset_time_stat(); | |
294 } | |
295 } | |
296 | |
297 // Find deadlocks involving object monitors and concurrent locks if concurrent_locks is true | |
298 DeadlockCycle* ThreadService::find_deadlocks_at_safepoint(bool concurrent_locks) { | |
299 // This code was modified from the original Threads::find_deadlocks code. | |
300 int globalDfn = 0, thisDfn; | |
301 ObjectMonitor* waitingToLockMonitor = NULL; | |
302 oop waitingToLockBlocker = NULL; | |
303 bool blocked_on_monitor = false; | |
304 JavaThread *currentThread, *previousThread; | |
305 int num_deadlocks = 0; | |
306 | |
307 for (JavaThread* p = Threads::first(); p != NULL; p = p->next()) { | |
308 // Initialize the depth-first-number | |
309 p->set_depth_first_number(-1); | |
310 } | |
311 | |
312 DeadlockCycle* deadlocks = NULL; | |
313 DeadlockCycle* last = NULL; | |
314 DeadlockCycle* cycle = new DeadlockCycle(); | |
315 for (JavaThread* jt = Threads::first(); jt != NULL; jt = jt->next()) { | |
316 if (jt->depth_first_number() >= 0) { | |
317 // this thread was already visited | |
318 continue; | |
319 } | |
320 | |
321 thisDfn = globalDfn; | |
322 jt->set_depth_first_number(globalDfn++); | |
323 previousThread = jt; | |
324 currentThread = jt; | |
325 | |
326 cycle->reset(); | |
327 | |
328 // When there is a deadlock, all the monitors involved in the dependency | |
329 // cycle must be contended and heavyweight. So we only care about the | |
330 // heavyweight monitor a thread is waiting to lock. | |
331 waitingToLockMonitor = (ObjectMonitor*)jt->current_pending_monitor(); | |
332 if (concurrent_locks) { | |
333 waitingToLockBlocker = jt->current_park_blocker(); | |
334 } | |
335 while (waitingToLockMonitor != NULL || waitingToLockBlocker != NULL) { | |
336 cycle->add_thread(currentThread); | |
337 if (waitingToLockMonitor != NULL) { | |
10985
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
338 address currentOwner = (address)waitingToLockMonitor->owner(); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
339 if (currentOwner != NULL) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
340 currentThread = Threads::owning_thread_from_monitor_owner( |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
341 currentOwner, |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
342 false /* no locking needed */); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
343 if (currentThread == NULL) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
344 // This function is called at a safepoint so the JavaThread |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
345 // that owns waitingToLockMonitor should be findable, but |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
346 // if it is not findable, then the previous currentThread is |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
347 // blocked permanently. We record this as a deadlock. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
348 num_deadlocks++; |
8673
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
349 |
10985
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
350 cycle->set_deadlock(true); |
8673
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
351 |
10985
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
352 // add this cycle to the deadlocks list |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
353 if (deadlocks == NULL) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
354 deadlocks = cycle; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
355 } else { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
356 last->set_next(cycle); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
357 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
358 last = cycle; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
359 cycle = new DeadlockCycle(); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
8673
diff
changeset
|
360 break; |
8673
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
361 } |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
362 } |
0 | 363 } else { |
364 if (concurrent_locks) { | |
365 if (waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) { | |
366 oop threadObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker); | |
367 currentThread = threadObj != NULL ? java_lang_Thread::thread(threadObj) : NULL; | |
368 } else { | |
369 currentThread = NULL; | |
370 } | |
371 } | |
372 } | |
373 | |
374 if (currentThread == NULL) { | |
375 // No dependency on another thread | |
376 break; | |
377 } | |
378 if (currentThread->depth_first_number() < 0) { | |
379 // First visit to this thread | |
380 currentThread->set_depth_first_number(globalDfn++); | |
381 } else if (currentThread->depth_first_number() < thisDfn) { | |
382 // Thread already visited, and not on a (new) cycle | |
383 break; | |
384 } else if (currentThread == previousThread) { | |
385 // Self-loop, ignore | |
386 break; | |
387 } else { | |
388 // We have a (new) cycle | |
389 num_deadlocks++; | |
390 | |
391 cycle->set_deadlock(true); | |
392 | |
393 // add this cycle to the deadlocks list | |
394 if (deadlocks == NULL) { | |
395 deadlocks = cycle; | |
396 } else { | |
397 last->set_next(cycle); | |
398 } | |
399 last = cycle; | |
400 cycle = new DeadlockCycle(); | |
401 break; | |
402 } | |
403 previousThread = currentThread; | |
404 waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor(); | |
405 if (concurrent_locks) { | |
406 waitingToLockBlocker = currentThread->current_park_blocker(); | |
407 } | |
408 } | |
409 | |
410 } | |
4752
8a63c6323842
7125594: C-heap growth issue in ThreadService::find_deadlocks_at_safepoint
fparain
parents:
4006
diff
changeset
|
411 delete cycle; |
0 | 412 return deadlocks; |
413 } | |
414 | |
415 ThreadDumpResult::ThreadDumpResult() : _num_threads(0), _num_snapshots(0), _snapshots(NULL), _next(NULL), _last(NULL) { | |
416 | |
417 // Create a new ThreadDumpResult object and append to the list. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
418 // If GC happens before this function returns, Method* |
0 | 419 // in the stack trace will be visited. |
420 ThreadService::add_thread_dump(this); | |
421 } | |
422 | |
423 ThreadDumpResult::ThreadDumpResult(int num_threads) : _num_threads(num_threads), _num_snapshots(0), _snapshots(NULL), _next(NULL), _last(NULL) { | |
424 // Create a new ThreadDumpResult object and append to the list. | |
425 // If GC happens before this function returns, oops | |
426 // will be visited. | |
427 ThreadService::add_thread_dump(this); | |
428 } | |
429 | |
430 ThreadDumpResult::~ThreadDumpResult() { | |
431 ThreadService::remove_thread_dump(this); | |
432 | |
433 // free all the ThreadSnapshot objects created during | |
434 // the VM_ThreadDump operation | |
435 ThreadSnapshot* ts = _snapshots; | |
436 while (ts != NULL) { | |
437 ThreadSnapshot* p = ts; | |
438 ts = ts->next(); | |
439 delete p; | |
440 } | |
441 } | |
442 | |
443 | |
444 void ThreadDumpResult::add_thread_snapshot(ThreadSnapshot* ts) { | |
445 assert(_num_threads == 0 || _num_snapshots < _num_threads, | |
446 "_num_snapshots must be less than _num_threads"); | |
447 _num_snapshots++; | |
448 if (_snapshots == NULL) { | |
449 _snapshots = ts; | |
450 } else { | |
451 _last->set_next(ts); | |
452 } | |
453 _last = ts; | |
454 } | |
455 | |
456 void ThreadDumpResult::oops_do(OopClosure* f) { | |
457 for (ThreadSnapshot* ts = _snapshots; ts != NULL; ts = ts->next()) { | |
458 ts->oops_do(f); | |
459 } | |
460 } | |
461 | |
13391
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
462 void ThreadDumpResult::metadata_do(void f(Metadata*)) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
463 for (ThreadSnapshot* ts = _snapshots; ts != NULL; ts = ts->next()) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
464 ts->metadata_do(f); |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
465 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
466 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
467 |
0 | 468 StackFrameInfo::StackFrameInfo(javaVFrame* jvf, bool with_lock_info) { |
469 _method = jvf->method(); | |
470 _bci = jvf->bci(); | |
13391
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
471 _class_holder = _method->method_holder()->klass_holder(); |
0 | 472 _locked_monitors = NULL; |
473 if (with_lock_info) { | |
474 ResourceMark rm; | |
475 GrowableArray<MonitorInfo*>* list = jvf->locked_monitors(); | |
476 int length = list->length(); | |
477 if (length > 0) { | |
6197 | 478 _locked_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(length, true); |
0 | 479 for (int i = 0; i < length; i++) { |
480 MonitorInfo* monitor = list->at(i); | |
481 assert(monitor->owner(), "This monitor must have an owning object"); | |
482 _locked_monitors->append(monitor->owner()); | |
483 } | |
484 } | |
485 } | |
486 } | |
487 | |
488 void StackFrameInfo::oops_do(OopClosure* f) { | |
489 if (_locked_monitors != NULL) { | |
490 int length = _locked_monitors->length(); | |
491 for (int i = 0; i < length; i++) { | |
492 f->do_oop((oop*) _locked_monitors->adr_at(i)); | |
493 } | |
494 } | |
13391
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
495 f->do_oop(&_class_holder); |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
496 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
497 |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
498 void StackFrameInfo::metadata_do(void f(Metadata*)) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
499 f(_method); |
0 | 500 } |
501 | |
502 void StackFrameInfo::print_on(outputStream* st) const { | |
503 ResourceMark rm; | |
504 java_lang_Throwable::print_stack_element(st, method(), bci()); | |
505 int len = (_locked_monitors != NULL ? _locked_monitors->length() : 0); | |
506 for (int i = 0; i < len; i++) { | |
507 oop o = _locked_monitors->at(i); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
508 InstanceKlass* ik = InstanceKlass::cast(o->klass()); |
0 | 509 st->print_cr("\t- locked <" INTPTR_FORMAT "> (a %s)", (address)o, ik->external_name()); |
510 } | |
511 | |
512 } | |
513 | |
514 // Iterate through monitor cache to find JNI locked monitors | |
515 class InflatedMonitorsClosure: public MonitorClosure { | |
516 private: | |
517 ThreadStackTrace* _stack_trace; | |
518 Thread* _thread; | |
519 public: | |
520 InflatedMonitorsClosure(Thread* t, ThreadStackTrace* st) { | |
521 _thread = t; | |
522 _stack_trace = st; | |
523 } | |
524 void do_monitor(ObjectMonitor* mid) { | |
525 if (mid->owner() == _thread) { | |
526 oop object = (oop) mid->object(); | |
527 if (!_stack_trace->is_owned_monitor_on_stack(object)) { | |
528 _stack_trace->add_jni_locked_monitor(object); | |
529 } | |
530 } | |
531 } | |
532 }; | |
533 | |
534 ThreadStackTrace::ThreadStackTrace(JavaThread* t, bool with_locked_monitors) { | |
535 _thread = t; | |
6197 | 536 _frames = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<StackFrameInfo*>(INITIAL_ARRAY_SIZE, true); |
0 | 537 _depth = 0; |
538 _with_locked_monitors = with_locked_monitors; | |
539 if (_with_locked_monitors) { | |
6197 | 540 _jni_locked_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(INITIAL_ARRAY_SIZE, true); |
0 | 541 } else { |
542 _jni_locked_monitors = NULL; | |
543 } | |
544 } | |
545 | |
546 ThreadStackTrace::~ThreadStackTrace() { | |
547 for (int i = 0; i < _frames->length(); i++) { | |
548 delete _frames->at(i); | |
549 } | |
550 delete _frames; | |
551 if (_jni_locked_monitors != NULL) { | |
552 delete _jni_locked_monitors; | |
553 } | |
554 } | |
555 | |
556 void ThreadStackTrace::dump_stack_at_safepoint(int maxDepth) { | |
557 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); | |
558 | |
559 if (_thread->has_last_Java_frame()) { | |
560 RegisterMap reg_map(_thread); | |
561 vframe* start_vf = _thread->last_java_vframe(®_map); | |
562 int count = 0; | |
563 for (vframe* f = start_vf; f; f = f->sender() ) { | |
564 if (f->is_java_frame()) { | |
565 javaVFrame* jvf = javaVFrame::cast(f); | |
566 add_stack_frame(jvf); | |
567 count++; | |
568 } else { | |
569 // Ignore non-Java frames | |
570 } | |
571 if (maxDepth > 0 && count == maxDepth) { | |
572 // Skip frames if more than maxDepth | |
573 break; | |
574 } | |
575 } | |
576 } | |
577 | |
578 if (_with_locked_monitors) { | |
579 // Iterate inflated monitors and find monitors locked by this thread | |
580 // not found in the stack | |
581 InflatedMonitorsClosure imc(_thread, this); | |
582 ObjectSynchronizer::monitors_iterate(&imc); | |
583 } | |
584 } | |
585 | |
586 | |
587 bool ThreadStackTrace::is_owned_monitor_on_stack(oop object) { | |
588 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); | |
589 | |
590 bool found = false; | |
591 int num_frames = get_stack_depth(); | |
592 for (int depth = 0; depth < num_frames; depth++) { | |
593 StackFrameInfo* frame = stack_frame_at(depth); | |
594 int len = frame->num_locked_monitors(); | |
595 GrowableArray<oop>* locked_monitors = frame->locked_monitors(); | |
596 for (int j = 0; j < len; j++) { | |
597 oop monitor = locked_monitors->at(j); | |
598 assert(monitor != NULL && monitor->is_instance(), "must be a Java object"); | |
599 if (monitor == object) { | |
600 found = true; | |
601 break; | |
602 } | |
603 } | |
604 } | |
605 return found; | |
606 } | |
607 | |
608 Handle ThreadStackTrace::allocate_fill_stack_trace_element_array(TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
609 Klass* k = SystemDictionary::StackTraceElement_klass(); |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
0
diff
changeset
|
610 assert(k != NULL, "must be loaded in 1.4+"); |
0 | 611 instanceKlassHandle ik(THREAD, k); |
612 | |
613 // Allocate an array of java/lang/StackTraceElement object | |
614 objArrayOop ste = oopFactory::new_objArray(ik(), _depth, CHECK_NH); | |
615 objArrayHandle backtrace(THREAD, ste); | |
616 for (int j = 0; j < _depth; j++) { | |
617 StackFrameInfo* frame = _frames->at(j); | |
618 methodHandle mh(THREAD, frame->method()); | |
619 oop element = java_lang_StackTraceElement::create(mh, frame->bci(), CHECK_NH); | |
620 backtrace->obj_at_put(j, element); | |
621 } | |
622 return backtrace; | |
623 } | |
624 | |
625 void ThreadStackTrace::add_stack_frame(javaVFrame* jvf) { | |
626 StackFrameInfo* frame = new StackFrameInfo(jvf, _with_locked_monitors); | |
627 _frames->append(frame); | |
628 _depth++; | |
629 } | |
630 | |
631 void ThreadStackTrace::oops_do(OopClosure* f) { | |
632 int length = _frames->length(); | |
633 for (int i = 0; i < length; i++) { | |
634 _frames->at(i)->oops_do(f); | |
635 } | |
636 | |
637 length = (_jni_locked_monitors != NULL ? _jni_locked_monitors->length() : 0); | |
638 for (int j = 0; j < length; j++) { | |
639 f->do_oop((oop*) _jni_locked_monitors->adr_at(j)); | |
640 } | |
641 } | |
642 | |
13391
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
643 void ThreadStackTrace::metadata_do(void f(Metadata*)) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
644 int length = _frames->length(); |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
645 for (int i = 0; i < length; i++) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
646 _frames->at(i)->metadata_do(f); |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
647 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
648 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
649 |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
650 |
0 | 651 ConcurrentLocksDump::~ConcurrentLocksDump() { |
652 if (_retain_map_on_free) { | |
653 return; | |
654 } | |
655 | |
656 for (ThreadConcurrentLocks* t = _map; t != NULL;) { | |
657 ThreadConcurrentLocks* tcl = t; | |
658 t = t->next(); | |
659 delete tcl; | |
660 } | |
661 } | |
662 | |
663 void ConcurrentLocksDump::dump_at_safepoint() { | |
664 // dump all locked concurrent locks | |
665 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); | |
666 | |
667 if (JDK_Version::is_gte_jdk16x_version()) { | |
668 ResourceMark rm; | |
669 | |
670 GrowableArray<oop>* aos_objects = new GrowableArray<oop>(INITIAL_ARRAY_SIZE); | |
671 | |
672 // Find all instances of AbstractOwnableSynchronizer | |
673 HeapInspection::find_instances_at_safepoint(SystemDictionary::abstract_ownable_synchronizer_klass(), | |
674 aos_objects); | |
675 // Build a map of thread to its owned AQS locks | |
676 build_map(aos_objects); | |
677 } | |
678 } | |
679 | |
680 | |
681 // build a map of JavaThread to all its owned AbstractOwnableSynchronizer | |
682 void ConcurrentLocksDump::build_map(GrowableArray<oop>* aos_objects) { | |
683 int length = aos_objects->length(); | |
684 for (int i = 0; i < length; i++) { | |
685 oop o = aos_objects->at(i); | |
686 oop owner_thread_obj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(o); | |
687 if (owner_thread_obj != NULL) { | |
688 JavaThread* thread = java_lang_Thread::thread(owner_thread_obj); | |
689 assert(o->is_instance(), "Must be an instanceOop"); | |
690 add_lock(thread, (instanceOop) o); | |
691 } | |
692 } | |
693 } | |
694 | |
695 void ConcurrentLocksDump::add_lock(JavaThread* thread, instanceOop o) { | |
696 ThreadConcurrentLocks* tcl = thread_concurrent_locks(thread); | |
697 if (tcl != NULL) { | |
698 tcl->add_lock(o); | |
699 return; | |
700 } | |
701 | |
702 // First owned lock found for this thread | |
703 tcl = new ThreadConcurrentLocks(thread); | |
704 tcl->add_lock(o); | |
705 if (_map == NULL) { | |
706 _map = tcl; | |
707 } else { | |
708 _last->set_next(tcl); | |
709 } | |
710 _last = tcl; | |
711 } | |
712 | |
713 ThreadConcurrentLocks* ConcurrentLocksDump::thread_concurrent_locks(JavaThread* thread) { | |
714 for (ThreadConcurrentLocks* tcl = _map; tcl != NULL; tcl = tcl->next()) { | |
715 if (tcl->java_thread() == thread) { | |
716 return tcl; | |
717 } | |
718 } | |
719 return NULL; | |
720 } | |
721 | |
722 void ConcurrentLocksDump::print_locks_on(JavaThread* t, outputStream* st) { | |
723 st->print_cr(" Locked ownable synchronizers:"); | |
724 ThreadConcurrentLocks* tcl = thread_concurrent_locks(t); | |
725 GrowableArray<instanceOop>* locks = (tcl != NULL ? tcl->owned_locks() : NULL); | |
726 if (locks == NULL || locks->is_empty()) { | |
727 st->print_cr("\t- None"); | |
728 st->cr(); | |
729 return; | |
730 } | |
731 | |
732 for (int i = 0; i < locks->length(); i++) { | |
733 instanceOop obj = locks->at(i); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
734 InstanceKlass* ik = InstanceKlass::cast(obj->klass()); |
0 | 735 st->print_cr("\t- <" INTPTR_FORMAT "> (a %s)", (address)obj, ik->external_name()); |
736 } | |
737 st->cr(); | |
738 } | |
739 | |
740 ThreadConcurrentLocks::ThreadConcurrentLocks(JavaThread* thread) { | |
741 _thread = thread; | |
6197 | 742 _owned_locks = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceOop>(INITIAL_ARRAY_SIZE, true); |
0 | 743 _next = NULL; |
744 } | |
745 | |
746 ThreadConcurrentLocks::~ThreadConcurrentLocks() { | |
747 delete _owned_locks; | |
748 } | |
749 | |
750 void ThreadConcurrentLocks::add_lock(instanceOop o) { | |
751 _owned_locks->append(o); | |
752 } | |
753 | |
754 void ThreadConcurrentLocks::oops_do(OopClosure* f) { | |
755 int length = _owned_locks->length(); | |
756 for (int i = 0; i < length; i++) { | |
757 f->do_oop((oop*) _owned_locks->adr_at(i)); | |
758 } | |
759 } | |
760 | |
761 ThreadStatistics::ThreadStatistics() { | |
762 _contended_enter_count = 0; | |
763 _monitor_wait_count = 0; | |
764 _sleep_count = 0; | |
765 _count_pending_reset = false; | |
766 _timer_pending_reset = false; | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
242
diff
changeset
|
767 memset((void*) _perf_recursion_counts, 0, sizeof(_perf_recursion_counts)); |
0 | 768 } |
769 | |
770 ThreadSnapshot::ThreadSnapshot(JavaThread* thread) { | |
771 _thread = thread; | |
772 _threadObj = thread->threadObj(); | |
773 _stack_trace = NULL; | |
774 _concurrent_locks = NULL; | |
775 _next = NULL; | |
776 | |
777 ThreadStatistics* stat = thread->get_thread_stat(); | |
778 _contended_enter_ticks = stat->contended_enter_ticks(); | |
779 _contended_enter_count = stat->contended_enter_count(); | |
780 _monitor_wait_ticks = stat->monitor_wait_ticks(); | |
781 _monitor_wait_count = stat->monitor_wait_count(); | |
782 _sleep_ticks = stat->sleep_ticks(); | |
783 _sleep_count = stat->sleep_count(); | |
784 | |
785 _blocker_object = NULL; | |
786 _blocker_object_owner = NULL; | |
787 | |
788 _thread_status = java_lang_Thread::get_thread_status(_threadObj); | |
789 _is_ext_suspended = thread->is_being_ext_suspended(); | |
790 _is_in_native = (thread->thread_state() == _thread_in_native); | |
791 | |
792 if (_thread_status == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER || | |
793 _thread_status == java_lang_Thread::IN_OBJECT_WAIT || | |
794 _thread_status == java_lang_Thread::IN_OBJECT_WAIT_TIMED) { | |
795 | |
796 Handle obj = ThreadService::get_current_contended_monitor(thread); | |
797 if (obj() == NULL) { | |
798 // monitor no longer exists; thread is not blocked | |
799 _thread_status = java_lang_Thread::RUNNABLE; | |
800 } else { | |
801 _blocker_object = obj(); | |
802 JavaThread* owner = ObjectSynchronizer::get_lock_owner(obj, false); | |
803 if ((owner == NULL && _thread_status == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER) | |
4006 | 804 || (owner != NULL && owner->is_attaching_via_jni())) { |
0 | 805 // ownership information of the monitor is not available |
806 // (may no longer be owned or releasing to some other thread) | |
807 // make this thread in RUNNABLE state. | |
808 // And when the owner thread is in attaching state, the java thread | |
809 // is not completely initialized. For example thread name and id | |
810 // and may not be set, so hide the attaching thread. | |
811 _thread_status = java_lang_Thread::RUNNABLE; | |
812 _blocker_object = NULL; | |
813 } else if (owner != NULL) { | |
814 _blocker_object_owner = owner->threadObj(); | |
815 } | |
816 } | |
817 } | |
818 | |
819 // Support for JSR-166 locks | |
242 | 820 if (JDK_Version::current().supports_thread_park_blocker() && |
0 | 821 (_thread_status == java_lang_Thread::PARKED || |
822 _thread_status == java_lang_Thread::PARKED_TIMED)) { | |
823 | |
824 _blocker_object = thread->current_park_blocker(); | |
825 if (_blocker_object != NULL && _blocker_object->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) { | |
826 _blocker_object_owner = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(_blocker_object); | |
827 } | |
828 } | |
829 } | |
830 | |
831 ThreadSnapshot::~ThreadSnapshot() { | |
832 delete _stack_trace; | |
833 delete _concurrent_locks; | |
834 } | |
835 | |
836 void ThreadSnapshot::dump_stack_at_safepoint(int max_depth, bool with_locked_monitors) { | |
837 _stack_trace = new ThreadStackTrace(_thread, with_locked_monitors); | |
838 _stack_trace->dump_stack_at_safepoint(max_depth); | |
839 } | |
840 | |
841 | |
842 void ThreadSnapshot::oops_do(OopClosure* f) { | |
843 f->do_oop(&_threadObj); | |
844 f->do_oop(&_blocker_object); | |
845 f->do_oop(&_blocker_object_owner); | |
846 if (_stack_trace != NULL) { | |
847 _stack_trace->oops_do(f); | |
848 } | |
849 if (_concurrent_locks != NULL) { | |
850 _concurrent_locks->oops_do(f); | |
851 } | |
852 } | |
853 | |
13391
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
854 void ThreadSnapshot::metadata_do(void f(Metadata*)) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
855 if (_stack_trace != NULL) { |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
856 _stack_trace->metadata_do(f); |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
857 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
858 } |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
859 |
0b9ea9a72436
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
10985
diff
changeset
|
860 |
0 | 861 DeadlockCycle::DeadlockCycle() { |
862 _is_deadlock = false; | |
6197 | 863 _threads = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaThread*>(INITIAL_ARRAY_SIZE, true); |
0 | 864 _next = NULL; |
865 } | |
866 | |
867 DeadlockCycle::~DeadlockCycle() { | |
868 delete _threads; | |
869 } | |
870 | |
871 void DeadlockCycle::print_on(outputStream* st) const { | |
872 st->cr(); | |
873 st->print_cr("Found one Java-level deadlock:"); | |
874 st->print("============================="); | |
875 | |
876 JavaThread* currentThread; | |
877 ObjectMonitor* waitingToLockMonitor; | |
878 oop waitingToLockBlocker; | |
879 int len = _threads->length(); | |
880 for (int i = 0; i < len; i++) { | |
881 currentThread = _threads->at(i); | |
882 waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor(); | |
883 waitingToLockBlocker = currentThread->current_park_blocker(); | |
884 st->cr(); | |
885 st->print_cr("\"%s\":", currentThread->get_thread_name()); | |
886 const char* owner_desc = ",\n which is held by"; | |
887 if (waitingToLockMonitor != NULL) { | |
888 st->print(" waiting to lock monitor " INTPTR_FORMAT, waitingToLockMonitor); | |
889 oop obj = (oop)waitingToLockMonitor->object(); | |
890 if (obj != NULL) { | |
891 st->print(" (object "INTPTR_FORMAT ", a %s)", (address)obj, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
892 (InstanceKlass::cast(obj->klass()))->external_name()); |
0 | 893 |
894 if (!currentThread->current_pending_monitor_is_from_java()) { | |
895 owner_desc = "\n in JNI, which is held by"; | |
896 } | |
897 } else { | |
898 // No Java object associated - a JVMTI raw monitor | |
899 owner_desc = " (JVMTI raw monitor),\n which is held by"; | |
900 } | |
901 currentThread = Threads::owning_thread_from_monitor_owner( | |
8673
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
902 (address)waitingToLockMonitor->owner(), |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
903 false /* no locking needed */); |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
904 if (currentThread == NULL) { |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
905 // The deadlock was detected at a safepoint so the JavaThread |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
906 // that owns waitingToLockMonitor should be findable, but |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
907 // if it is not findable, then the previous currentThread is |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
908 // blocked permanently. |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
909 st->print("%s UNKNOWN_owner_addr=" PTR_FORMAT, owner_desc, |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
910 (address)waitingToLockMonitor->owner()); |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
911 continue; |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
6831
diff
changeset
|
912 } |
0 | 913 } else { |
914 st->print(" waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)", | |
915 (address)waitingToLockBlocker, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
916 (InstanceKlass::cast(waitingToLockBlocker->klass()))->external_name()); |
0 | 917 assert(waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass()), |
918 "Must be an AbstractOwnableSynchronizer"); | |
919 oop ownerObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker); | |
920 currentThread = java_lang_Thread::thread(ownerObj); | |
921 } | |
922 st->print("%s \"%s\"", owner_desc, currentThread->get_thread_name()); | |
923 } | |
924 | |
925 st->cr(); | |
926 st->cr(); | |
927 | |
928 // Print stack traces | |
929 bool oldJavaMonitorsInStackTrace = JavaMonitorsInStackTrace; | |
930 JavaMonitorsInStackTrace = true; | |
931 st->print_cr("Java stack information for the threads listed above:"); | |
932 st->print_cr("==================================================="); | |
933 for (int j = 0; j < len; j++) { | |
934 currentThread = _threads->at(j); | |
935 st->print_cr("\"%s\":", currentThread->get_thread_name()); | |
936 currentThread->print_stack_on(st); | |
937 } | |
938 JavaMonitorsInStackTrace = oldJavaMonitorsInStackTrace; | |
939 } | |
940 | |
941 ThreadsListEnumerator::ThreadsListEnumerator(Thread* cur_thread, | |
942 bool include_jvmti_agent_threads, | |
943 bool include_jni_attaching_threads) { | |
944 assert(cur_thread == Thread::current(), "Check current thread"); | |
945 | |
946 int init_size = ThreadService::get_live_thread_count(); | |
947 _threads_array = new GrowableArray<instanceHandle>(init_size); | |
948 | |
949 MutexLockerEx ml(Threads_lock); | |
950 | |
951 for (JavaThread* jt = Threads::first(); jt != NULL; jt = jt->next()) { | |
952 // skips JavaThreads in the process of exiting | |
953 // and also skips VM internal JavaThreads | |
954 // Threads in _thread_new or _thread_new_trans state are included. | |
955 // i.e. threads have been started but not yet running. | |
956 if (jt->threadObj() == NULL || | |
957 jt->is_exiting() || | |
958 !java_lang_Thread::is_alive(jt->threadObj()) || | |
959 jt->is_hidden_from_external_view()) { | |
960 continue; | |
961 } | |
962 | |
963 // skip agent threads | |
964 if (!include_jvmti_agent_threads && jt->is_jvmti_agent_thread()) { | |
965 continue; | |
966 } | |
967 | |
968 // skip jni threads in the process of attaching | |
4006 | 969 if (!include_jni_attaching_threads && jt->is_attaching_via_jni()) { |
0 | 970 continue; |
971 } | |
972 | |
973 instanceHandle h(cur_thread, (instanceOop) jt->threadObj()); | |
974 _threads_array->append(h); | |
975 } | |
976 } |