author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58488 | 165b193b30dd |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "memory/allocation.hpp" |
|
28 |
#include "memory/heapInspection.hpp" |
|
29 |
#include "memory/oopFactory.hpp" |
|
37248 | 30 |
#include "memory/resourceArea.hpp" |
7397 | 31 |
#include "oops/instanceKlass.hpp" |
54786 | 32 |
#include "oops/objArrayKlass.hpp" |
35498
392b50de06c6
8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents:
33602
diff
changeset
|
33 |
#include "oops/objArrayOop.inline.hpp" |
7397 | 34 |
#include "oops/oop.inline.hpp" |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
35 |
#include "prims/jvmtiRawMonitor.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
37248
diff
changeset
|
36 |
#include "runtime/atomic.hpp" |
7397 | 37 |
#include "runtime/handles.inline.hpp" |
38 |
#include "runtime/init.hpp" |
|
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
48955
diff
changeset
|
39 |
#include "runtime/objectMonitor.inline.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
40 |
#include "runtime/thread.inline.hpp" |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
41 |
#include "runtime/threadSMR.inline.hpp" |
7397 | 42 |
#include "runtime/vframe.hpp" |
43 |
#include "runtime/vmThread.hpp" |
|
52877
9e041366c764
8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents:
52297
diff
changeset
|
44 |
#include "runtime/vmOperations.hpp" |
7397 | 45 |
#include "services/threadService.hpp" |
1 | 46 |
|
47 |
// TODO: we need to define a naming convention for perf counters |
|
48 |
// to distinguish counters for: |
|
49 |
// - standard JSR174 use |
|
50 |
// - Hotspot extension (public and committed) |
|
51 |
// - Hotspot extension (private/internal and uncommitted) |
|
52 |
||
53 |
// Default is disabled. |
|
54 |
bool ThreadService::_thread_monitoring_contention_enabled = false; |
|
55 |
bool ThreadService::_thread_cpu_time_enabled = false; |
|
7724
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
56 |
bool ThreadService::_thread_allocated_memory_enabled = false; |
1 | 57 |
|
58 |
PerfCounter* ThreadService::_total_threads_count = NULL; |
|
59 |
PerfVariable* ThreadService::_live_threads_count = NULL; |
|
60 |
PerfVariable* ThreadService::_peak_threads_count = NULL; |
|
61 |
PerfVariable* ThreadService::_daemon_threads_count = NULL; |
|
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
62 |
volatile int ThreadService::_atomic_threads_count = 0; |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
63 |
volatile int ThreadService::_atomic_daemon_threads_count = 0; |
1 | 64 |
|
65 |
ThreadDumpResult* ThreadService::_threaddump_list = NULL; |
|
66 |
||
67 |
static const int INITIAL_ARRAY_SIZE = 10; |
|
68 |
||
69 |
void ThreadService::init() { |
|
70 |
EXCEPTION_MARK; |
|
71 |
||
72 |
// These counters are for java.lang.management API support. |
|
73 |
// They are created even if -XX:-UsePerfData is set and in |
|
74 |
// that case, they will be allocated on C heap. |
|
75 |
||
76 |
_total_threads_count = |
|
77 |
PerfDataManager::create_counter(JAVA_THREADS, "started", |
|
78 |
PerfData::U_Events, CHECK); |
|
79 |
||
80 |
_live_threads_count = |
|
81 |
PerfDataManager::create_variable(JAVA_THREADS, "live", |
|
82 |
PerfData::U_None, CHECK); |
|
83 |
||
84 |
_peak_threads_count = |
|
85 |
PerfDataManager::create_variable(JAVA_THREADS, "livePeak", |
|
86 |
PerfData::U_None, CHECK); |
|
87 |
||
88 |
_daemon_threads_count = |
|
89 |
PerfDataManager::create_variable(JAVA_THREADS, "daemon", |
|
90 |
PerfData::U_None, CHECK); |
|
91 |
||
92 |
if (os::is_thread_cpu_time_supported()) { |
|
93 |
_thread_cpu_time_enabled = true; |
|
94 |
} |
|
7724
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
95 |
|
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
96 |
_thread_allocated_memory_enabled = true; // Always on, so enable it |
1 | 97 |
} |
98 |
||
99 |
void ThreadService::reset_peak_thread_count() { |
|
100 |
// Acquire the lock to update the peak thread count |
|
101 |
// to synchronize with thread addition and removal. |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
53463
diff
changeset
|
102 |
MutexLocker mu(Threads_lock); |
1 | 103 |
_peak_threads_count->set_value(get_live_thread_count()); |
104 |
} |
|
105 |
||
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
106 |
static bool is_hidden_thread(JavaThread *thread) { |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
107 |
// hide VM internal or JVMTI agent threads |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
108 |
return thread->is_hidden_from_external_view() || thread->is_jvmti_agent_thread(); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
109 |
} |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
110 |
|
1 | 111 |
void ThreadService::add_thread(JavaThread* thread, bool daemon) { |
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
112 |
assert(Threads_lock->owned_by_self(), "must have threads lock"); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
113 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
114 |
// Do not count hidden threads |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
115 |
if (is_hidden_thread(thread)) { |
1 | 116 |
return; |
117 |
} |
|
118 |
||
119 |
_total_threads_count->inc(); |
|
120 |
_live_threads_count->inc(); |
|
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
121 |
Atomic::inc(&_atomic_threads_count); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
122 |
int count = _atomic_threads_count; |
1 | 123 |
|
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
124 |
if (count > _peak_threads_count->get_value()) { |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
125 |
_peak_threads_count->set_value(count); |
1 | 126 |
} |
127 |
||
128 |
if (daemon) { |
|
129 |
_daemon_threads_count->inc(); |
|
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
130 |
Atomic::inc(&_atomic_daemon_threads_count); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
131 |
} |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
132 |
} |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
133 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
134 |
void ThreadService::decrement_thread_counts(JavaThread* jt, bool daemon) { |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
135 |
Atomic::dec(&_atomic_threads_count); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
136 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
137 |
if (daemon) { |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
138 |
Atomic::dec(&_atomic_daemon_threads_count); |
1 | 139 |
} |
140 |
} |
|
141 |
||
142 |
void ThreadService::remove_thread(JavaThread* thread, bool daemon) { |
|
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
143 |
assert(Threads_lock->owned_by_self(), "must have threads lock"); |
1 | 144 |
|
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
145 |
// Do not count hidden threads |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
146 |
if (is_hidden_thread(thread)) { |
1 | 147 |
return; |
148 |
} |
|
149 |
||
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
150 |
assert(!thread->is_terminated(), "must not be terminated"); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
151 |
if (!thread->is_exiting()) { |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
152 |
// JavaThread::exit() skipped calling current_thread_exiting() |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
153 |
decrement_thread_counts(thread, daemon); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
154 |
} |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
155 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
156 |
int daemon_count = _atomic_daemon_threads_count; |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
157 |
int count = _atomic_threads_count; |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
158 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
159 |
// Counts are incremented at the same time, but atomic counts are |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
160 |
// decremented earlier than perf counts. |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
161 |
assert(_live_threads_count->get_value() > count, |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
162 |
"thread count mismatch %d : %d", |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
163 |
(int)_live_threads_count->get_value(), count); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
164 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
165 |
_live_threads_count->dec(1); |
1 | 166 |
if (daemon) { |
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
167 |
assert(_daemon_threads_count->get_value() > daemon_count, |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
168 |
"thread count mismatch %d : %d", |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
169 |
(int)_daemon_threads_count->get_value(), daemon_count); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
170 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
171 |
_daemon_threads_count->dec(1); |
1 | 172 |
} |
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
173 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
174 |
// Counts are incremented at the same time, but atomic counts are |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
175 |
// decremented earlier than perf counts. |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
176 |
assert(_daemon_threads_count->get_value() >= daemon_count, |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
177 |
"thread count mismatch %d : %d", |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
178 |
(int)_daemon_threads_count->get_value(), daemon_count); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
179 |
assert(_live_threads_count->get_value() >= count, |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
180 |
"thread count mismatch %d : %d", |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
181 |
(int)_live_threads_count->get_value(), count); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
182 |
assert(_live_threads_count->get_value() > 0 || |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
183 |
(_live_threads_count->get_value() == 0 && count == 0 && |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
184 |
_daemon_threads_count->get_value() == 0 && daemon_count == 0), |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
185 |
"thread counts should reach 0 at the same time, live %d,%d daemon %d,%d", |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
186 |
(int)_live_threads_count->get_value(), count, |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
187 |
(int)_daemon_threads_count->get_value(), daemon_count); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
188 |
assert(_daemon_threads_count->get_value() > 0 || |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
189 |
(_daemon_threads_count->get_value() == 0 && daemon_count == 0), |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
190 |
"thread counts should reach 0 at the same time, daemon %d,%d", |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
191 |
(int)_daemon_threads_count->get_value(), daemon_count); |
1 | 192 |
} |
193 |
||
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
194 |
void ThreadService::current_thread_exiting(JavaThread* jt, bool daemon) { |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
195 |
// Do not count hidden threads |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
196 |
if (is_hidden_thread(jt)) { |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
197 |
return; |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
198 |
} |
1 | 199 |
|
52297
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
200 |
assert(jt == JavaThread::current(), "Called by current thread"); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
201 |
assert(!jt->is_terminated() && jt->is_exiting(), "must be exiting"); |
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
202 |
|
99962c340e73
8021335: Missing synchronization when reading counters for live threads and peak thread count
dlong
parents:
51334
diff
changeset
|
203 |
decrement_thread_counts(jt, daemon); |
1 | 204 |
} |
205 |
||
206 |
// FIXME: JVMTI should call this function |
|
207 |
Handle ThreadService::get_current_contended_monitor(JavaThread* thread) { |
|
208 |
assert(thread != NULL, "should be non-NULL"); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
209 |
debug_only(Thread::check_for_dangling_thread_pointer(thread);) |
1 | 210 |
|
211 |
ObjectMonitor *wait_obj = thread->current_waiting_monitor(); |
|
212 |
||
213 |
oop obj = NULL; |
|
214 |
if (wait_obj != NULL) { |
|
215 |
// thread is doing an Object.wait() call |
|
216 |
obj = (oop) wait_obj->object(); |
|
217 |
assert(obj != NULL, "Object.wait() should have an object"); |
|
218 |
} else { |
|
219 |
ObjectMonitor *enter_obj = thread->current_pending_monitor(); |
|
220 |
if (enter_obj != NULL) { |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
221 |
// thread is trying to enter() an ObjectMonitor. |
1 | 222 |
obj = (oop) enter_obj->object(); |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
223 |
assert(obj != NULL, "ObjectMonitor should have an associated object!"); |
1 | 224 |
} |
225 |
} |
|
226 |
||
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
40655
diff
changeset
|
227 |
Handle h(Thread::current(), obj); |
1 | 228 |
return h; |
229 |
} |
|
230 |
||
231 |
bool ThreadService::set_thread_monitoring_contention(bool flag) { |
|
232 |
MutexLocker m(Management_lock); |
|
233 |
||
234 |
bool prev = _thread_monitoring_contention_enabled; |
|
235 |
_thread_monitoring_contention_enabled = flag; |
|
236 |
||
237 |
return prev; |
|
238 |
} |
|
239 |
||
240 |
bool ThreadService::set_thread_cpu_time_enabled(bool flag) { |
|
241 |
MutexLocker m(Management_lock); |
|
242 |
||
243 |
bool prev = _thread_cpu_time_enabled; |
|
244 |
_thread_cpu_time_enabled = flag; |
|
245 |
||
246 |
return prev; |
|
247 |
} |
|
248 |
||
7724
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
249 |
bool ThreadService::set_thread_allocated_memory_enabled(bool flag) { |
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
250 |
MutexLocker m(Management_lock); |
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
251 |
|
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
252 |
bool prev = _thread_allocated_memory_enabled; |
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
253 |
_thread_allocated_memory_enabled = flag; |
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
254 |
|
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
255 |
return prev; |
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
256 |
} |
a92d706dbdd5
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
7397
diff
changeset
|
257 |
|
1 | 258 |
// GC support |
259 |
void ThreadService::oops_do(OopClosure* f) { |
|
260 |
for (ThreadDumpResult* dump = _threaddump_list; dump != NULL; dump = dump->next()) { |
|
261 |
dump->oops_do(f); |
|
262 |
} |
|
263 |
} |
|
264 |
||
21735
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
265 |
void ThreadService::metadata_do(void f(Metadata*)) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
266 |
for (ThreadDumpResult* dump = _threaddump_list; dump != NULL; dump = dump->next()) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
267 |
dump->metadata_do(f); |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
268 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
269 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
270 |
|
1 | 271 |
void ThreadService::add_thread_dump(ThreadDumpResult* dump) { |
272 |
MutexLocker ml(Management_lock); |
|
273 |
if (_threaddump_list == NULL) { |
|
274 |
_threaddump_list = dump; |
|
275 |
} else { |
|
276 |
dump->set_next(_threaddump_list); |
|
277 |
_threaddump_list = dump; |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
void ThreadService::remove_thread_dump(ThreadDumpResult* dump) { |
|
282 |
MutexLocker ml(Management_lock); |
|
283 |
||
284 |
ThreadDumpResult* prev = NULL; |
|
285 |
bool found = false; |
|
286 |
for (ThreadDumpResult* d = _threaddump_list; d != NULL; prev = d, d = d->next()) { |
|
287 |
if (d == dump) { |
|
288 |
if (prev == NULL) { |
|
289 |
_threaddump_list = dump->next(); |
|
290 |
} else { |
|
291 |
prev->set_next(dump->next()); |
|
292 |
} |
|
293 |
found = true; |
|
294 |
break; |
|
295 |
} |
|
296 |
} |
|
297 |
assert(found, "The threaddump result to be removed must exist."); |
|
298 |
} |
|
299 |
||
300 |
// Dump stack trace of threads specified in the given threads array. |
|
301 |
// Returns StackTraceElement[][] each element is the stack trace of a thread in |
|
302 |
// the corresponding entry in the given threads array |
|
303 |
Handle ThreadService::dump_stack_traces(GrowableArray<instanceHandle>* threads, |
|
304 |
int num_threads, |
|
305 |
TRAPS) { |
|
306 |
assert(num_threads > 0, "just checking"); |
|
307 |
||
308 |
ThreadDumpResult dump_result; |
|
309 |
VM_ThreadDump op(&dump_result, |
|
310 |
threads, |
|
311 |
num_threads, |
|
312 |
-1, /* entire stack */ |
|
313 |
false, /* with locked monitors */ |
|
314 |
false /* with locked synchronizers */); |
|
315 |
VMThread::execute(&op); |
|
316 |
||
317 |
// Allocate the resulting StackTraceElement[][] object |
|
318 |
||
319 |
ResourceMark rm(THREAD); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
320 |
Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackTraceElement_array(), true, CHECK_NH); |
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
321 |
ObjArrayKlass* ik = ObjArrayKlass::cast(k); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
322 |
objArrayOop r = oopFactory::new_objArray(ik, num_threads, CHECK_NH); |
1 | 323 |
objArrayHandle result_obj(THREAD, r); |
324 |
||
325 |
int num_snapshots = dump_result.num_snapshots(); |
|
326 |
assert(num_snapshots == num_threads, "Must have num_threads thread snapshots"); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
327 |
assert(num_snapshots == 0 || dump_result.t_list_has_been_set(), "ThreadsList must have been set if we have a snapshot"); |
1 | 328 |
int i = 0; |
329 |
for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; i++, ts = ts->next()) { |
|
330 |
ThreadStackTrace* stacktrace = ts->get_stack_trace(); |
|
331 |
if (stacktrace == NULL) { |
|
332 |
// No stack trace |
|
333 |
result_obj->obj_at_put(i, NULL); |
|
334 |
} else { |
|
335 |
// Construct an array of java/lang/StackTraceElement object |
|
336 |
Handle backtrace_h = stacktrace->allocate_fill_stack_trace_element_array(CHECK_NH); |
|
337 |
result_obj->obj_at_put(i, backtrace_h()); |
|
338 |
} |
|
339 |
} |
|
340 |
||
341 |
return result_obj; |
|
342 |
} |
|
343 |
||
344 |
void ThreadService::reset_contention_count_stat(JavaThread* thread) { |
|
345 |
ThreadStatistics* stat = thread->get_thread_stat(); |
|
346 |
if (stat != NULL) { |
|
347 |
stat->reset_count_stat(); |
|
348 |
} |
|
349 |
} |
|
350 |
||
351 |
void ThreadService::reset_contention_time_stat(JavaThread* thread) { |
|
352 |
ThreadStatistics* stat = thread->get_thread_stat(); |
|
353 |
if (stat != NULL) { |
|
354 |
stat->reset_time_stat(); |
|
355 |
} |
|
356 |
} |
|
357 |
||
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
358 |
// Find deadlocks involving raw monitors, object monitors and concurrent locks |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
359 |
// if concurrent_locks is true. |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
360 |
DeadlockCycle* ThreadService::find_deadlocks_at_safepoint(ThreadsList * t_list, bool concurrent_locks) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
361 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
362 |
|
1 | 363 |
// This code was modified from the original Threads::find_deadlocks code. |
364 |
int globalDfn = 0, thisDfn; |
|
365 |
ObjectMonitor* waitingToLockMonitor = NULL; |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
366 |
JvmtiRawMonitor* waitingToLockRawMonitor = NULL; |
1 | 367 |
oop waitingToLockBlocker = NULL; |
368 |
bool blocked_on_monitor = false; |
|
369 |
JavaThread *currentThread, *previousThread; |
|
370 |
int num_deadlocks = 0; |
|
371 |
||
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
372 |
// Initialize the depth-first-number for each JavaThread. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
373 |
JavaThreadIterator jti(t_list); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
374 |
for (JavaThread* jt = jti.first(); jt != NULL; jt = jti.next()) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
375 |
jt->set_depth_first_number(-1); |
1 | 376 |
} |
377 |
||
378 |
DeadlockCycle* deadlocks = NULL; |
|
379 |
DeadlockCycle* last = NULL; |
|
380 |
DeadlockCycle* cycle = new DeadlockCycle(); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
381 |
for (JavaThread* jt = jti.first(); jt != NULL; jt = jti.next()) { |
1 | 382 |
if (jt->depth_first_number() >= 0) { |
383 |
// this thread was already visited |
|
384 |
continue; |
|
385 |
} |
|
386 |
||
387 |
thisDfn = globalDfn; |
|
388 |
jt->set_depth_first_number(globalDfn++); |
|
389 |
previousThread = jt; |
|
390 |
currentThread = jt; |
|
391 |
||
392 |
cycle->reset(); |
|
393 |
||
394 |
// When there is a deadlock, all the monitors involved in the dependency |
|
395 |
// cycle must be contended and heavyweight. So we only care about the |
|
396 |
// heavyweight monitor a thread is waiting to lock. |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
397 |
waitingToLockMonitor = jt->current_pending_monitor(); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
398 |
// JVM TI raw monitors can also be involved in deadlocks, and we can be |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
399 |
// waiting to lock both a raw monitor and ObjectMonitor at the same time. |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
400 |
// It isn't clear how to make deadlock detection work correctly if that |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
401 |
// happens. |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
402 |
waitingToLockRawMonitor = jt->current_pending_raw_monitor(); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
403 |
|
1 | 404 |
if (concurrent_locks) { |
405 |
waitingToLockBlocker = jt->current_park_blocker(); |
|
406 |
} |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
407 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
408 |
while (waitingToLockMonitor != NULL || |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
409 |
waitingToLockRawMonitor != NULL || |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
410 |
waitingToLockBlocker != NULL) { |
1 | 411 |
cycle->add_thread(currentThread); |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
412 |
// Give preference to the raw monitor |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
413 |
if (waitingToLockRawMonitor != NULL) { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
414 |
Thread* owner = waitingToLockRawMonitor->owner(); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
415 |
if (owner != NULL && // the raw monitor could be released at any time |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
416 |
owner->is_Java_thread()) { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
417 |
// only JavaThreads can be reported here |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
418 |
currentThread = (JavaThread*) owner; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
419 |
} |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
420 |
} else if (waitingToLockMonitor != NULL) { |
18085
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
421 |
address currentOwner = (address)waitingToLockMonitor->owner(); |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
422 |
if (currentOwner != NULL) { |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
423 |
currentThread = Threads::owning_thread_from_monitor_owner(t_list, |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
424 |
currentOwner); |
18085
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
425 |
if (currentThread == NULL) { |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
426 |
// This function is called at a safepoint so the JavaThread |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
427 |
// that owns waitingToLockMonitor should be findable, but |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
428 |
// if it is not findable, then the previous currentThread is |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
429 |
// blocked permanently. We record this as a deadlock. |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
430 |
num_deadlocks++; |
15853
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
431 |
|
18085
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
432 |
cycle->set_deadlock(true); |
15853
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
433 |
|
18085
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
434 |
// add this cycle to the deadlocks list |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
435 |
if (deadlocks == NULL) { |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
436 |
deadlocks = cycle; |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
437 |
} else { |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
438 |
last->set_next(cycle); |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
439 |
} |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
440 |
last = cycle; |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
441 |
cycle = new DeadlockCycle(); |
fb6d02a9e1c5
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
15853
diff
changeset
|
442 |
break; |
15853
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
443 |
} |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
444 |
} |
1 | 445 |
} else { |
446 |
if (concurrent_locks) { |
|
50419
146c60525d4a
8199882: compiler/uncommontrap/TestDeoptOOM.java failed w/ fatal error: ExceptionMark constructor expects no pending exceptions
dholmes
parents:
50288
diff
changeset
|
447 |
if (waitingToLockBlocker->is_a(SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass())) { |
1 | 448 |
oop threadObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker); |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
449 |
// This JavaThread (if there is one) is protected by the |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
450 |
// ThreadsListSetter in VM_FindDeadlocks::doit(). |
1 | 451 |
currentThread = threadObj != NULL ? java_lang_Thread::thread(threadObj) : NULL; |
452 |
} else { |
|
453 |
currentThread = NULL; |
|
454 |
} |
|
455 |
} |
|
456 |
} |
|
457 |
||
458 |
if (currentThread == NULL) { |
|
459 |
// No dependency on another thread |
|
460 |
break; |
|
461 |
} |
|
462 |
if (currentThread->depth_first_number() < 0) { |
|
463 |
// First visit to this thread |
|
464 |
currentThread->set_depth_first_number(globalDfn++); |
|
465 |
} else if (currentThread->depth_first_number() < thisDfn) { |
|
466 |
// Thread already visited, and not on a (new) cycle |
|
467 |
break; |
|
468 |
} else if (currentThread == previousThread) { |
|
469 |
// Self-loop, ignore |
|
470 |
break; |
|
471 |
} else { |
|
472 |
// We have a (new) cycle |
|
473 |
num_deadlocks++; |
|
474 |
||
475 |
cycle->set_deadlock(true); |
|
476 |
||
477 |
// add this cycle to the deadlocks list |
|
478 |
if (deadlocks == NULL) { |
|
479 |
deadlocks = cycle; |
|
480 |
} else { |
|
481 |
last->set_next(cycle); |
|
482 |
} |
|
483 |
last = cycle; |
|
484 |
cycle = new DeadlockCycle(); |
|
485 |
break; |
|
486 |
} |
|
487 |
previousThread = currentThread; |
|
488 |
waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor(); |
|
489 |
if (concurrent_locks) { |
|
490 |
waitingToLockBlocker = currentThread->current_park_blocker(); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
} |
|
11420
22ec1bad0dce
7125594: C-heap growth issue in ThreadService::find_deadlocks_at_safepoint
fparain
parents:
10739
diff
changeset
|
495 |
delete cycle; |
1 | 496 |
return deadlocks; |
497 |
} |
|
498 |
||
51334
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
50419
diff
changeset
|
499 |
ThreadDumpResult::ThreadDumpResult() : _num_threads(0), _num_snapshots(0), _snapshots(NULL), _last(NULL), _next(NULL), _setter() { |
1 | 500 |
|
501 |
// Create a new ThreadDumpResult object and append to the list. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
502 |
// If GC happens before this function returns, Method* |
1 | 503 |
// in the stack trace will be visited. |
504 |
ThreadService::add_thread_dump(this); |
|
505 |
} |
|
506 |
||
51334
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
50419
diff
changeset
|
507 |
ThreadDumpResult::ThreadDumpResult(int num_threads) : _num_threads(num_threads), _num_snapshots(0), _snapshots(NULL), _last(NULL), _next(NULL), _setter() { |
1 | 508 |
// Create a new ThreadDumpResult object and append to the list. |
509 |
// If GC happens before this function returns, oops |
|
510 |
// will be visited. |
|
511 |
ThreadService::add_thread_dump(this); |
|
512 |
} |
|
513 |
||
514 |
ThreadDumpResult::~ThreadDumpResult() { |
|
515 |
ThreadService::remove_thread_dump(this); |
|
516 |
||
517 |
// free all the ThreadSnapshot objects created during |
|
518 |
// the VM_ThreadDump operation |
|
519 |
ThreadSnapshot* ts = _snapshots; |
|
520 |
while (ts != NULL) { |
|
521 |
ThreadSnapshot* p = ts; |
|
522 |
ts = ts->next(); |
|
523 |
delete p; |
|
524 |
} |
|
525 |
} |
|
526 |
||
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
527 |
ThreadSnapshot* ThreadDumpResult::add_thread_snapshot() { |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
528 |
ThreadSnapshot* ts = new ThreadSnapshot(); |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
529 |
link_thread_snapshot(ts); |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
530 |
return ts; |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
531 |
} |
1 | 532 |
|
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
533 |
ThreadSnapshot* ThreadDumpResult::add_thread_snapshot(JavaThread* thread) { |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
534 |
// Note: it is very important that the ThreadSnapshot* gets linked before |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
535 |
// ThreadSnapshot::initialize gets called. This is to ensure that |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
536 |
// ThreadSnapshot::oops_do can get called prior to the field |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
537 |
// ThreadSnapshot::_threadObj being assigned a value (to prevent a dangling |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
538 |
// oop). |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
539 |
ThreadSnapshot* ts = new ThreadSnapshot(); |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
540 |
link_thread_snapshot(ts); |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
541 |
ts->initialize(t_list(), thread); |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
542 |
return ts; |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
543 |
} |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
544 |
|
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
545 |
void ThreadDumpResult::link_thread_snapshot(ThreadSnapshot* ts) { |
1 | 546 |
assert(_num_threads == 0 || _num_snapshots < _num_threads, |
547 |
"_num_snapshots must be less than _num_threads"); |
|
548 |
_num_snapshots++; |
|
549 |
if (_snapshots == NULL) { |
|
550 |
_snapshots = ts; |
|
551 |
} else { |
|
552 |
_last->set_next(ts); |
|
553 |
} |
|
554 |
_last = ts; |
|
555 |
} |
|
556 |
||
557 |
void ThreadDumpResult::oops_do(OopClosure* f) { |
|
558 |
for (ThreadSnapshot* ts = _snapshots; ts != NULL; ts = ts->next()) { |
|
559 |
ts->oops_do(f); |
|
560 |
} |
|
561 |
} |
|
562 |
||
21735
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
563 |
void ThreadDumpResult::metadata_do(void f(Metadata*)) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
564 |
for (ThreadSnapshot* ts = _snapshots; ts != NULL; ts = ts->next()) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
565 |
ts->metadata_do(f); |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
566 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
567 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
568 |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
569 |
ThreadsList* ThreadDumpResult::t_list() { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
570 |
return _setter.list(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
571 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
572 |
|
1 | 573 |
StackFrameInfo::StackFrameInfo(javaVFrame* jvf, bool with_lock_info) { |
574 |
_method = jvf->method(); |
|
575 |
_bci = jvf->bci(); |
|
21735
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
576 |
_class_holder = _method->method_holder()->klass_holder(); |
1 | 577 |
_locked_monitors = NULL; |
578 |
if (with_lock_info) { |
|
579 |
ResourceMark rm; |
|
580 |
GrowableArray<MonitorInfo*>* list = jvf->locked_monitors(); |
|
581 |
int length = list->length(); |
|
582 |
if (length > 0) { |
|
13195 | 583 |
_locked_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(length, true); |
1 | 584 |
for (int i = 0; i < length; i++) { |
585 |
MonitorInfo* monitor = list->at(i); |
|
48831
05894c073b7e
8196199: Remove miscellaneous oop comparison operators
coleenp
parents:
48105
diff
changeset
|
586 |
assert(monitor->owner() != NULL, "This monitor must have an owning object"); |
1 | 587 |
_locked_monitors->append(monitor->owner()); |
588 |
} |
|
589 |
} |
|
590 |
} |
|
591 |
} |
|
592 |
||
593 |
void StackFrameInfo::oops_do(OopClosure* f) { |
|
594 |
if (_locked_monitors != NULL) { |
|
595 |
int length = _locked_monitors->length(); |
|
596 |
for (int i = 0; i < length; i++) { |
|
597 |
f->do_oop((oop*) _locked_monitors->adr_at(i)); |
|
598 |
} |
|
599 |
} |
|
21735
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
600 |
f->do_oop(&_class_holder); |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
601 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
602 |
|
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
603 |
void StackFrameInfo::metadata_do(void f(Metadata*)) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
604 |
f(_method); |
1 | 605 |
} |
606 |
||
607 |
void StackFrameInfo::print_on(outputStream* st) const { |
|
608 |
ResourceMark rm; |
|
609 |
java_lang_Throwable::print_stack_element(st, method(), bci()); |
|
610 |
int len = (_locked_monitors != NULL ? _locked_monitors->length() : 0); |
|
611 |
for (int i = 0; i < len; i++) { |
|
612 |
oop o = _locked_monitors->at(i); |
|
33602 | 613 |
st->print_cr("\t- locked <" INTPTR_FORMAT "> (a %s)", p2i(o), o->klass()->external_name()); |
1 | 614 |
} |
615 |
||
616 |
} |
|
617 |
||
618 |
// Iterate through monitor cache to find JNI locked monitors |
|
619 |
class InflatedMonitorsClosure: public MonitorClosure { |
|
620 |
private: |
|
621 |
ThreadStackTrace* _stack_trace; |
|
622 |
Thread* _thread; |
|
623 |
public: |
|
624 |
InflatedMonitorsClosure(Thread* t, ThreadStackTrace* st) { |
|
625 |
_thread = t; |
|
626 |
_stack_trace = st; |
|
627 |
} |
|
628 |
void do_monitor(ObjectMonitor* mid) { |
|
629 |
if (mid->owner() == _thread) { |
|
630 |
oop object = (oop) mid->object(); |
|
631 |
if (!_stack_trace->is_owned_monitor_on_stack(object)) { |
|
632 |
_stack_trace->add_jni_locked_monitor(object); |
|
633 |
} |
|
634 |
} |
|
635 |
} |
|
636 |
}; |
|
637 |
||
638 |
ThreadStackTrace::ThreadStackTrace(JavaThread* t, bool with_locked_monitors) { |
|
639 |
_thread = t; |
|
13195 | 640 |
_frames = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<StackFrameInfo*>(INITIAL_ARRAY_SIZE, true); |
1 | 641 |
_depth = 0; |
642 |
_with_locked_monitors = with_locked_monitors; |
|
643 |
if (_with_locked_monitors) { |
|
13195 | 644 |
_jni_locked_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(INITIAL_ARRAY_SIZE, true); |
1 | 645 |
} else { |
646 |
_jni_locked_monitors = NULL; |
|
647 |
} |
|
648 |
} |
|
649 |
||
650 |
ThreadStackTrace::~ThreadStackTrace() { |
|
651 |
for (int i = 0; i < _frames->length(); i++) { |
|
652 |
delete _frames->at(i); |
|
653 |
} |
|
654 |
delete _frames; |
|
655 |
if (_jni_locked_monitors != NULL) { |
|
656 |
delete _jni_locked_monitors; |
|
657 |
} |
|
658 |
} |
|
659 |
||
660 |
void ThreadStackTrace::dump_stack_at_safepoint(int maxDepth) { |
|
661 |
assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); |
|
662 |
||
663 |
if (_thread->has_last_Java_frame()) { |
|
664 |
RegisterMap reg_map(_thread); |
|
665 |
vframe* start_vf = _thread->last_java_vframe(®_map); |
|
666 |
int count = 0; |
|
667 |
for (vframe* f = start_vf; f; f = f->sender() ) { |
|
47592
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
668 |
if (maxDepth >= 0 && count == maxDepth) { |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
669 |
// Skip frames if more than maxDepth |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
670 |
break; |
68d46cb9be45
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
uvangapally
parents:
47216
diff
changeset
|
671 |
} |
1 | 672 |
if (f->is_java_frame()) { |
673 |
javaVFrame* jvf = javaVFrame::cast(f); |
|
674 |
add_stack_frame(jvf); |
|
675 |
count++; |
|
676 |
} else { |
|
677 |
// Ignore non-Java frames |
|
678 |
} |
|
679 |
} |
|
680 |
} |
|
681 |
||
682 |
if (_with_locked_monitors) { |
|
683 |
// Iterate inflated monitors and find monitors locked by this thread |
|
684 |
// not found in the stack |
|
685 |
InflatedMonitorsClosure imc(_thread, this); |
|
686 |
ObjectSynchronizer::monitors_iterate(&imc); |
|
687 |
} |
|
688 |
} |
|
689 |
||
690 |
||
691 |
bool ThreadStackTrace::is_owned_monitor_on_stack(oop object) { |
|
692 |
assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); |
|
693 |
||
694 |
bool found = false; |
|
695 |
int num_frames = get_stack_depth(); |
|
696 |
for (int depth = 0; depth < num_frames; depth++) { |
|
697 |
StackFrameInfo* frame = stack_frame_at(depth); |
|
698 |
int len = frame->num_locked_monitors(); |
|
699 |
GrowableArray<oop>* locked_monitors = frame->locked_monitors(); |
|
700 |
for (int j = 0; j < len; j++) { |
|
701 |
oop monitor = locked_monitors->at(j); |
|
27471 | 702 |
assert(monitor != NULL, "must be a Java object"); |
58177 | 703 |
if (monitor == object) { |
1 | 704 |
found = true; |
705 |
break; |
|
706 |
} |
|
707 |
} |
|
708 |
} |
|
709 |
return found; |
|
710 |
} |
|
711 |
||
712 |
Handle ThreadStackTrace::allocate_fill_stack_trace_element_array(TRAPS) { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
713 |
InstanceKlass* ik = SystemDictionary::StackTraceElement_klass(); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
714 |
assert(ik != NULL, "must be loaded in 1.4+"); |
1 | 715 |
|
716 |
// Allocate an array of java/lang/StackTraceElement object |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
717 |
objArrayOop ste = oopFactory::new_objArray(ik, _depth, CHECK_NH); |
1 | 718 |
objArrayHandle backtrace(THREAD, ste); |
719 |
for (int j = 0; j < _depth; j++) { |
|
720 |
StackFrameInfo* frame = _frames->at(j); |
|
721 |
methodHandle mh(THREAD, frame->method()); |
|
722 |
oop element = java_lang_StackTraceElement::create(mh, frame->bci(), CHECK_NH); |
|
723 |
backtrace->obj_at_put(j, element); |
|
724 |
} |
|
725 |
return backtrace; |
|
726 |
} |
|
727 |
||
728 |
void ThreadStackTrace::add_stack_frame(javaVFrame* jvf) { |
|
729 |
StackFrameInfo* frame = new StackFrameInfo(jvf, _with_locked_monitors); |
|
730 |
_frames->append(frame); |
|
731 |
_depth++; |
|
732 |
} |
|
733 |
||
734 |
void ThreadStackTrace::oops_do(OopClosure* f) { |
|
735 |
int length = _frames->length(); |
|
736 |
for (int i = 0; i < length; i++) { |
|
737 |
_frames->at(i)->oops_do(f); |
|
738 |
} |
|
739 |
||
740 |
length = (_jni_locked_monitors != NULL ? _jni_locked_monitors->length() : 0); |
|
741 |
for (int j = 0; j < length; j++) { |
|
742 |
f->do_oop((oop*) _jni_locked_monitors->adr_at(j)); |
|
743 |
} |
|
744 |
} |
|
745 |
||
21735
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
746 |
void ThreadStackTrace::metadata_do(void f(Metadata*)) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
747 |
int length = _frames->length(); |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
748 |
for (int i = 0; i < length; i++) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
749 |
_frames->at(i)->metadata_do(f); |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
750 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
751 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
752 |
|
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
753 |
|
1 | 754 |
ConcurrentLocksDump::~ConcurrentLocksDump() { |
755 |
if (_retain_map_on_free) { |
|
756 |
return; |
|
757 |
} |
|
758 |
||
759 |
for (ThreadConcurrentLocks* t = _map; t != NULL;) { |
|
760 |
ThreadConcurrentLocks* tcl = t; |
|
761 |
t = t->next(); |
|
762 |
delete tcl; |
|
763 |
} |
|
764 |
} |
|
765 |
||
766 |
void ConcurrentLocksDump::dump_at_safepoint() { |
|
767 |
// dump all locked concurrent locks |
|
768 |
assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); |
|
769 |
||
50288
3831655869bc
8203885: ConcurrentLocksDump::dump_at_safepoint() should not allocate array in resource area
pliden
parents:
50065
diff
changeset
|
770 |
GrowableArray<oop>* aos_objects = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(INITIAL_ARRAY_SIZE, true /* C_heap */); |
1 | 771 |
|
25057 | 772 |
// Find all instances of AbstractOwnableSynchronizer |
50419
146c60525d4a
8199882: compiler/uncommontrap/TestDeoptOOM.java failed w/ fatal error: ExceptionMark constructor expects no pending exceptions
dholmes
parents:
50288
diff
changeset
|
773 |
HeapInspection::find_instances_at_safepoint(SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass(), |
146c60525d4a
8199882: compiler/uncommontrap/TestDeoptOOM.java failed w/ fatal error: ExceptionMark constructor expects no pending exceptions
dholmes
parents:
50288
diff
changeset
|
774 |
aos_objects); |
25057 | 775 |
// Build a map of thread to its owned AQS locks |
776 |
build_map(aos_objects); |
|
50288
3831655869bc
8203885: ConcurrentLocksDump::dump_at_safepoint() should not allocate array in resource area
pliden
parents:
50065
diff
changeset
|
777 |
|
3831655869bc
8203885: ConcurrentLocksDump::dump_at_safepoint() should not allocate array in resource area
pliden
parents:
50065
diff
changeset
|
778 |
delete aos_objects; |
1 | 779 |
} |
780 |
||
781 |
||
782 |
// build a map of JavaThread to all its owned AbstractOwnableSynchronizer |
|
783 |
void ConcurrentLocksDump::build_map(GrowableArray<oop>* aos_objects) { |
|
784 |
int length = aos_objects->length(); |
|
785 |
for (int i = 0; i < length; i++) { |
|
786 |
oop o = aos_objects->at(i); |
|
787 |
oop owner_thread_obj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(o); |
|
788 |
if (owner_thread_obj != NULL) { |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
789 |
// See comments in ThreadConcurrentLocks to see how this |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
790 |
// JavaThread* is protected. |
1 | 791 |
JavaThread* thread = java_lang_Thread::thread(owner_thread_obj); |
792 |
assert(o->is_instance(), "Must be an instanceOop"); |
|
793 |
add_lock(thread, (instanceOop) o); |
|
794 |
} |
|
795 |
} |
|
796 |
} |
|
797 |
||
798 |
void ConcurrentLocksDump::add_lock(JavaThread* thread, instanceOop o) { |
|
799 |
ThreadConcurrentLocks* tcl = thread_concurrent_locks(thread); |
|
800 |
if (tcl != NULL) { |
|
801 |
tcl->add_lock(o); |
|
802 |
return; |
|
803 |
} |
|
804 |
||
805 |
// First owned lock found for this thread |
|
806 |
tcl = new ThreadConcurrentLocks(thread); |
|
807 |
tcl->add_lock(o); |
|
808 |
if (_map == NULL) { |
|
809 |
_map = tcl; |
|
810 |
} else { |
|
811 |
_last->set_next(tcl); |
|
812 |
} |
|
813 |
_last = tcl; |
|
814 |
} |
|
815 |
||
816 |
ThreadConcurrentLocks* ConcurrentLocksDump::thread_concurrent_locks(JavaThread* thread) { |
|
817 |
for (ThreadConcurrentLocks* tcl = _map; tcl != NULL; tcl = tcl->next()) { |
|
818 |
if (tcl->java_thread() == thread) { |
|
819 |
return tcl; |
|
820 |
} |
|
821 |
} |
|
822 |
return NULL; |
|
823 |
} |
|
824 |
||
825 |
void ConcurrentLocksDump::print_locks_on(JavaThread* t, outputStream* st) { |
|
826 |
st->print_cr(" Locked ownable synchronizers:"); |
|
827 |
ThreadConcurrentLocks* tcl = thread_concurrent_locks(t); |
|
828 |
GrowableArray<instanceOop>* locks = (tcl != NULL ? tcl->owned_locks() : NULL); |
|
829 |
if (locks == NULL || locks->is_empty()) { |
|
830 |
st->print_cr("\t- None"); |
|
831 |
st->cr(); |
|
832 |
return; |
|
833 |
} |
|
834 |
||
835 |
for (int i = 0; i < locks->length(); i++) { |
|
836 |
instanceOop obj = locks->at(i); |
|
33602 | 837 |
st->print_cr("\t- <" INTPTR_FORMAT "> (a %s)", p2i(obj), obj->klass()->external_name()); |
1 | 838 |
} |
839 |
st->cr(); |
|
840 |
} |
|
841 |
||
842 |
ThreadConcurrentLocks::ThreadConcurrentLocks(JavaThread* thread) { |
|
843 |
_thread = thread; |
|
13195 | 844 |
_owned_locks = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceOop>(INITIAL_ARRAY_SIZE, true); |
1 | 845 |
_next = NULL; |
846 |
} |
|
847 |
||
848 |
ThreadConcurrentLocks::~ThreadConcurrentLocks() { |
|
849 |
delete _owned_locks; |
|
850 |
} |
|
851 |
||
852 |
void ThreadConcurrentLocks::add_lock(instanceOop o) { |
|
853 |
_owned_locks->append(o); |
|
854 |
} |
|
855 |
||
856 |
void ThreadConcurrentLocks::oops_do(OopClosure* f) { |
|
857 |
int length = _owned_locks->length(); |
|
858 |
for (int i = 0; i < length; i++) { |
|
859 |
f->do_oop((oop*) _owned_locks->adr_at(i)); |
|
860 |
} |
|
861 |
} |
|
862 |
||
863 |
ThreadStatistics::ThreadStatistics() { |
|
864 |
_contended_enter_count = 0; |
|
865 |
_monitor_wait_count = 0; |
|
866 |
_sleep_count = 0; |
|
867 |
_count_pending_reset = false; |
|
868 |
_timer_pending_reset = false; |
|
3575
224791e7ecab
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
950
diff
changeset
|
869 |
memset((void*) _perf_recursion_counts, 0, sizeof(_perf_recursion_counts)); |
1 | 870 |
} |
871 |
||
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
872 |
void ThreadSnapshot::initialize(ThreadsList * t_list, JavaThread* thread) { |
1 | 873 |
_thread = thread; |
874 |
_threadObj = thread->threadObj(); |
|
875 |
||
876 |
ThreadStatistics* stat = thread->get_thread_stat(); |
|
877 |
_contended_enter_ticks = stat->contended_enter_ticks(); |
|
878 |
_contended_enter_count = stat->contended_enter_count(); |
|
879 |
_monitor_wait_ticks = stat->monitor_wait_ticks(); |
|
880 |
_monitor_wait_count = stat->monitor_wait_count(); |
|
881 |
_sleep_ticks = stat->sleep_ticks(); |
|
882 |
_sleep_count = stat->sleep_count(); |
|
883 |
||
884 |
_thread_status = java_lang_Thread::get_thread_status(_threadObj); |
|
885 |
_is_ext_suspended = thread->is_being_ext_suspended(); |
|
886 |
_is_in_native = (thread->thread_state() == _thread_in_native); |
|
887 |
||
888 |
if (_thread_status == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER || |
|
889 |
_thread_status == java_lang_Thread::IN_OBJECT_WAIT || |
|
890 |
_thread_status == java_lang_Thread::IN_OBJECT_WAIT_TIMED) { |
|
891 |
||
892 |
Handle obj = ThreadService::get_current_contended_monitor(thread); |
|
893 |
if (obj() == NULL) { |
|
894 |
// monitor no longer exists; thread is not blocked |
|
895 |
_thread_status = java_lang_Thread::RUNNABLE; |
|
896 |
} else { |
|
897 |
_blocker_object = obj(); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
898 |
JavaThread* owner = ObjectSynchronizer::get_lock_owner(t_list, obj); |
1 | 899 |
if ((owner == NULL && _thread_status == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER) |
10739 | 900 |
|| (owner != NULL && owner->is_attaching_via_jni())) { |
1 | 901 |
// ownership information of the monitor is not available |
902 |
// (may no longer be owned or releasing to some other thread) |
|
903 |
// make this thread in RUNNABLE state. |
|
904 |
// And when the owner thread is in attaching state, the java thread |
|
905 |
// is not completely initialized. For example thread name and id |
|
906 |
// and may not be set, so hide the attaching thread. |
|
907 |
_thread_status = java_lang_Thread::RUNNABLE; |
|
908 |
_blocker_object = NULL; |
|
909 |
} else if (owner != NULL) { |
|
910 |
_blocker_object_owner = owner->threadObj(); |
|
911 |
} |
|
912 |
} |
|
913 |
} |
|
914 |
||
915 |
// Support for JSR-166 locks |
|
54795
fd08f5a976e6
8189208: Cleanup ancient argument processing code
gziemski
parents:
54786
diff
changeset
|
916 |
if (_thread_status == java_lang_Thread::PARKED || _thread_status == java_lang_Thread::PARKED_TIMED) { |
1 | 917 |
_blocker_object = thread->current_park_blocker(); |
50419
146c60525d4a
8199882: compiler/uncommontrap/TestDeoptOOM.java failed w/ fatal error: ExceptionMark constructor expects no pending exceptions
dholmes
parents:
50288
diff
changeset
|
918 |
if (_blocker_object != NULL && _blocker_object->is_a(SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass())) { |
1 | 919 |
_blocker_object_owner = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(_blocker_object); |
920 |
} |
|
921 |
} |
|
922 |
} |
|
923 |
||
924 |
ThreadSnapshot::~ThreadSnapshot() { |
|
925 |
delete _stack_trace; |
|
926 |
delete _concurrent_locks; |
|
927 |
} |
|
928 |
||
929 |
void ThreadSnapshot::dump_stack_at_safepoint(int max_depth, bool with_locked_monitors) { |
|
930 |
_stack_trace = new ThreadStackTrace(_thread, with_locked_monitors); |
|
931 |
_stack_trace->dump_stack_at_safepoint(max_depth); |
|
932 |
} |
|
933 |
||
934 |
||
935 |
void ThreadSnapshot::oops_do(OopClosure* f) { |
|
936 |
f->do_oop(&_threadObj); |
|
937 |
f->do_oop(&_blocker_object); |
|
938 |
f->do_oop(&_blocker_object_owner); |
|
939 |
if (_stack_trace != NULL) { |
|
940 |
_stack_trace->oops_do(f); |
|
941 |
} |
|
942 |
if (_concurrent_locks != NULL) { |
|
943 |
_concurrent_locks->oops_do(f); |
|
944 |
} |
|
945 |
} |
|
946 |
||
21735
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
947 |
void ThreadSnapshot::metadata_do(void f(Metadata*)) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
948 |
if (_stack_trace != NULL) { |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
949 |
_stack_trace->metadata_do(f); |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
950 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
951 |
} |
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
952 |
|
379ba90c3dc4
8027630: SIGSEGV in const char*Klass::external_name()
sla
parents:
18085
diff
changeset
|
953 |
|
1 | 954 |
DeadlockCycle::DeadlockCycle() { |
955 |
_is_deadlock = false; |
|
13195 | 956 |
_threads = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaThread*>(INITIAL_ARRAY_SIZE, true); |
1 | 957 |
_next = NULL; |
958 |
} |
|
959 |
||
960 |
DeadlockCycle::~DeadlockCycle() { |
|
961 |
delete _threads; |
|
962 |
} |
|
963 |
||
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
964 |
void DeadlockCycle::print_on_with(ThreadsList * t_list, outputStream* st) const { |
1 | 965 |
st->cr(); |
966 |
st->print_cr("Found one Java-level deadlock:"); |
|
967 |
st->print("============================="); |
|
968 |
||
969 |
JavaThread* currentThread; |
|
970 |
ObjectMonitor* waitingToLockMonitor; |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
971 |
JvmtiRawMonitor* waitingToLockRawMonitor; |
1 | 972 |
oop waitingToLockBlocker; |
973 |
int len = _threads->length(); |
|
974 |
for (int i = 0; i < len; i++) { |
|
975 |
currentThread = _threads->at(i); |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
976 |
waitingToLockMonitor = currentThread->current_pending_monitor(); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
977 |
waitingToLockRawMonitor = currentThread->current_pending_raw_monitor(); |
1 | 978 |
waitingToLockBlocker = currentThread->current_park_blocker(); |
979 |
st->cr(); |
|
980 |
st->print_cr("\"%s\":", currentThread->get_thread_name()); |
|
981 |
const char* owner_desc = ",\n which is held by"; |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
982 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
983 |
// Note: As the JVM TI "monitor contended enter" event callback is executed after ObjectMonitor |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
984 |
// sets the current pending monitor, it is possible to then see a pending raw monitor as well. |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
985 |
if (waitingToLockRawMonitor != NULL) { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
986 |
st->print(" waiting to lock JVM TI raw monitor " INTPTR_FORMAT, p2i(waitingToLockRawMonitor)); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
987 |
Thread* owner = waitingToLockRawMonitor->owner(); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
988 |
// Could be NULL as the raw monitor could be released at any time if held by non-JavaThread |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
989 |
if (owner != NULL) { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
990 |
if (owner->is_Java_thread()) { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
991 |
currentThread = (JavaThread*) owner; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
992 |
st->print_cr("%s \"%s\"", owner_desc, currentThread->get_thread_name()); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
993 |
} else { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
994 |
st->print_cr(",\n which has now been released"); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
995 |
} |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
996 |
} else { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
997 |
st->print_cr("%s non-Java thread=" PTR_FORMAT, owner_desc, p2i(owner)); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
998 |
} |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
999 |
} |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
1000 |
|
1 | 1001 |
if (waitingToLockMonitor != NULL) { |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
31592
diff
changeset
|
1002 |
st->print(" waiting to lock monitor " INTPTR_FORMAT, p2i(waitingToLockMonitor)); |
1 | 1003 |
oop obj = (oop)waitingToLockMonitor->object(); |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
1004 |
st->print(" (object " INTPTR_FORMAT ", a %s)", p2i(obj), |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
1005 |
obj->klass()->external_name()); |
1 | 1006 |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
1007 |
if (!currentThread->current_pending_monitor_is_from_java()) { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
1008 |
owner_desc = "\n in JNI, which is held by"; |
1 | 1009 |
} |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
1010 |
currentThread = Threads::owning_thread_from_monitor_owner(t_list, |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
1011 |
(address)waitingToLockMonitor->owner()); |
15853
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
1012 |
if (currentThread == NULL) { |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
1013 |
// The deadlock was detected at a safepoint so the JavaThread |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
1014 |
// that owns waitingToLockMonitor should be findable, but |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
1015 |
// if it is not findable, then the previous currentThread is |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
1016 |
// blocked permanently. |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
1017 |
st->print_cr("%s UNKNOWN_owner_addr=" PTR_FORMAT, owner_desc, |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
31592
diff
changeset
|
1018 |
p2i(waitingToLockMonitor->owner())); |
15853
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
1019 |
continue; |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
13952
diff
changeset
|
1020 |
} |
1 | 1021 |
} else { |
1022 |
st->print(" waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)", |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
31592
diff
changeset
|
1023 |
p2i(waitingToLockBlocker), |
33602 | 1024 |
waitingToLockBlocker->klass()->external_name()); |
50419
146c60525d4a
8199882: compiler/uncommontrap/TestDeoptOOM.java failed w/ fatal error: ExceptionMark constructor expects no pending exceptions
dholmes
parents:
50288
diff
changeset
|
1025 |
assert(waitingToLockBlocker->is_a(SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass()), |
1 | 1026 |
"Must be an AbstractOwnableSynchronizer"); |
1027 |
oop ownerObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker); |
|
1028 |
currentThread = java_lang_Thread::thread(ownerObj); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
1029 |
assert(currentThread != NULL, "AbstractOwnableSynchronizer owning thread is unexpectedly NULL"); |
1 | 1030 |
} |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
58177
diff
changeset
|
1031 |
st->print_cr("%s \"%s\"", owner_desc, currentThread->get_thread_name()); |
1 | 1032 |
} |
1033 |
||
1034 |
st->cr(); |
|
1035 |
||
1036 |
// Print stack traces |
|
1037 |
bool oldJavaMonitorsInStackTrace = JavaMonitorsInStackTrace; |
|
1038 |
JavaMonitorsInStackTrace = true; |
|
1039 |
st->print_cr("Java stack information for the threads listed above:"); |
|
1040 |
st->print_cr("==================================================="); |
|
1041 |
for (int j = 0; j < len; j++) { |
|
1042 |
currentThread = _threads->at(j); |
|
1043 |
st->print_cr("\"%s\":", currentThread->get_thread_name()); |
|
1044 |
currentThread->print_stack_on(st); |
|
1045 |
} |
|
1046 |
JavaMonitorsInStackTrace = oldJavaMonitorsInStackTrace; |
|
1047 |
} |
|
1048 |
||
1049 |
ThreadsListEnumerator::ThreadsListEnumerator(Thread* cur_thread, |
|
1050 |
bool include_jvmti_agent_threads, |
|
1051 |
bool include_jni_attaching_threads) { |
|
1052 |
assert(cur_thread == Thread::current(), "Check current thread"); |
|
1053 |
||
1054 |
int init_size = ThreadService::get_live_thread_count(); |
|
1055 |
_threads_array = new GrowableArray<instanceHandle>(init_size); |
|
1056 |
||
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47592
diff
changeset
|
1057 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) { |
1 | 1058 |
// skips JavaThreads in the process of exiting |
1059 |
// and also skips VM internal JavaThreads |
|
1060 |
// Threads in _thread_new or _thread_new_trans state are included. |
|
1061 |
// i.e. threads have been started but not yet running. |
|
1062 |
if (jt->threadObj() == NULL || |
|
1063 |
jt->is_exiting() || |
|
1064 |
!java_lang_Thread::is_alive(jt->threadObj()) || |
|
1065 |
jt->is_hidden_from_external_view()) { |
|
1066 |
continue; |
|
1067 |
} |
|
1068 |
||
1069 |
// skip agent threads |
|
1070 |
if (!include_jvmti_agent_threads && jt->is_jvmti_agent_thread()) { |
|
1071 |
continue; |
|
1072 |
} |
|
1073 |
||
1074 |
// skip jni threads in the process of attaching |
|
10739 | 1075 |
if (!include_jni_attaching_threads && jt->is_attaching_via_jni()) { |
1 | 1076 |
continue; |
1077 |
} |
|
1078 |
||
1079 |
instanceHandle h(cur_thread, (instanceOop) jt->threadObj()); |
|
1080 |
_threads_array->append(h); |
|
1081 |
} |
|
1082 |
} |