annotate src/share/vm/services/threadService.cpp @ 20197:ce8f6bb717c9

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