author | kvn |
Mon, 06 May 2019 20:05:19 -0700 | |
changeset 54732 | 2d012a75d35c |
parent 54729 | f72402697b2f |
child 54786 | ebf733a324d4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
2 |
* Copyright (c) 1997, 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:
4750
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4750
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:
4750
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
26 |
#include "classfile/symbolTable.hpp" |
7397 | 27 |
#include "classfile/vmSymbols.hpp" |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
25057
diff
changeset
|
28 |
#include "code/codeCache.hpp" |
7397 | 29 |
#include "compiler/compileBroker.hpp" |
30764 | 30 |
#include "gc/shared/isGCActiveMark.hpp" |
34262
43560e879d6d
8143157: Convert TraceVMOperation to Unified Logging
rprotacio
parents:
33451
diff
changeset
|
31 |
#include "logging/log.hpp" |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
32 |
#include "logging/logStream.hpp" |
54729
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
33 |
#include "logging/logConfiguration.hpp" |
29071
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
34 |
#include "memory/heapInspection.hpp" |
7397 | 35 |
#include "memory/resourceArea.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
36 |
#include "oops/symbol.hpp" |
7397 | 37 |
#include "runtime/arguments.hpp" |
38 |
#include "runtime/deoptimization.hpp" |
|
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
39 |
#include "runtime/frame.inline.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49389
diff
changeset
|
40 |
#include "runtime/interfaceSupport.inline.hpp" |
7397 | 41 |
#include "runtime/sweeper.hpp" |
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
10565
diff
changeset
|
42 |
#include "runtime/thread.inline.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
43 |
#include "runtime/threadSMR.inline.hpp" |
52877
9e041366c764
8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents:
50946
diff
changeset
|
44 |
#include "runtime/vmOperations.hpp" |
7397 | 45 |
#include "services/threadService.hpp" |
1 | 46 |
|
47 |
#define VM_OP_NAME_INITIALIZE(name) #name, |
|
48 |
||
49 |
const char* VM_Operation::_names[VM_Operation::VMOp_Terminating] = \ |
|
50 |
{ VM_OPS_DO(VM_OP_NAME_INITIALIZE) }; |
|
51 |
||
52 |
void VM_Operation::set_calling_thread(Thread* thread, ThreadPriority priority) { |
|
53 |
_calling_thread = thread; |
|
54 |
assert(MinPriority <= priority && priority <= MaxPriority, "sanity check"); |
|
55 |
_priority = priority; |
|
56 |
} |
|
57 |
||
58 |
||
59 |
void VM_Operation::evaluate() { |
|
60 |
ResourceMark rm; |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
61 |
LogTarget(Debug, vmoperation) lt; |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
62 |
if (lt.is_enabled()) { |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
63 |
LogStream ls(lt); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
64 |
ls.print("begin "); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
65 |
print_on_error(&ls); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
66 |
ls.cr(); |
1 | 67 |
} |
68 |
doit(); |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
69 |
if (lt.is_enabled()) { |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
70 |
LogStream ls(lt); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
71 |
ls.print("end "); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
72 |
print_on_error(&ls); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
42664
diff
changeset
|
73 |
ls.cr(); |
1 | 74 |
} |
75 |
} |
|
76 |
||
18025 | 77 |
const char* VM_Operation::mode_to_string(Mode mode) { |
78 |
switch(mode) { |
|
79 |
case _safepoint : return "safepoint"; |
|
80 |
case _no_safepoint : return "no safepoint"; |
|
81 |
case _concurrent : return "concurrent"; |
|
82 |
case _async_safepoint: return "async safepoint"; |
|
83 |
default : return "unknown"; |
|
84 |
} |
|
85 |
} |
|
1 | 86 |
// Called by fatal error handler. |
87 |
void VM_Operation::print_on_error(outputStream* st) const { |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
32401
diff
changeset
|
88 |
st->print("VM_Operation (" PTR_FORMAT "): ", p2i(this)); |
1 | 89 |
st->print("%s", name()); |
90 |
||
18025 | 91 |
const char* mode = mode_to_string(evaluation_mode()); |
1 | 92 |
st->print(", mode: %s", mode); |
93 |
||
94 |
if (calling_thread()) { |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
32401
diff
changeset
|
95 |
st->print(", requested by thread " PTR_FORMAT, p2i(calling_thread())); |
1 | 96 |
} |
97 |
} |
|
98 |
||
99 |
void VM_ThreadStop::doit() { |
|
100 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
101 |
ThreadsListHandle tlh; |
1 | 102 |
JavaThread* target = java_lang_Thread::thread(target_thread()); |
103 |
// Note that this now allows multiple ThreadDeath exceptions to be |
|
104 |
// thrown at a thread. |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
105 |
if (target != NULL && (!EnableThreadSMRExtraValidityChecks || tlh.includes(target))) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
106 |
// The target thread has run and has not exited yet. |
1 | 107 |
target->send_thread_stop(throwable()); |
108 |
} |
|
109 |
} |
|
110 |
||
37289
9989add27bf4
8067247: Crash: assert(method_holder->data() == 0 ...) failed: a) MT-unsafe modification of inline cache
jcm
parents:
36322
diff
changeset
|
111 |
void VM_ClearICs::doit() { |
9989add27bf4
8067247: Crash: assert(method_holder->data() == 0 ...) failed: a) MT-unsafe modification of inline cache
jcm
parents:
36322
diff
changeset
|
112 |
if (_preserve_static_stubs) { |
9989add27bf4
8067247: Crash: assert(method_holder->data() == 0 ...) failed: a) MT-unsafe modification of inline cache
jcm
parents:
36322
diff
changeset
|
113 |
CodeCache::cleanup_inline_caches(); |
9989add27bf4
8067247: Crash: assert(method_holder->data() == 0 ...) failed: a) MT-unsafe modification of inline cache
jcm
parents:
36322
diff
changeset
|
114 |
} else { |
9989add27bf4
8067247: Crash: assert(method_holder->data() == 0 ...) failed: a) MT-unsafe modification of inline cache
jcm
parents:
36322
diff
changeset
|
115 |
CodeCache::clear_inline_caches(); |
9989add27bf4
8067247: Crash: assert(method_holder->data() == 0 ...) failed: a) MT-unsafe modification of inline cache
jcm
parents:
36322
diff
changeset
|
116 |
} |
9989add27bf4
8067247: Crash: assert(method_holder->data() == 0 ...) failed: a) MT-unsafe modification of inline cache
jcm
parents:
36322
diff
changeset
|
117 |
} |
9989add27bf4
8067247: Crash: assert(method_holder->data() == 0 ...) failed: a) MT-unsafe modification of inline cache
jcm
parents:
36322
diff
changeset
|
118 |
|
1 | 119 |
void VM_Deoptimize::doit() { |
120 |
// We do not want any GCs to happen while we are in the middle of this VM operation |
|
121 |
ResourceMark rm; |
|
122 |
DeoptimizationMarker dm; |
|
123 |
||
124 |
// Deoptimize all activations depending on marked nmethods |
|
125 |
Deoptimization::deoptimize_dependents(); |
|
126 |
||
32401
cc58aeaec340
8075805: Crash while trying to release CompiledICHolder
thartmann
parents:
31620
diff
changeset
|
127 |
// Make the dependent methods not entrant |
cc58aeaec340
8075805: Crash while trying to release CompiledICHolder
thartmann
parents:
31620
diff
changeset
|
128 |
CodeCache::make_marked_nmethods_not_entrant(); |
1 | 129 |
} |
130 |
||
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26587
diff
changeset
|
131 |
void VM_MarkActiveNMethods::doit() { |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26587
diff
changeset
|
132 |
NMethodSweeper::mark_active_nmethods(); |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26587
diff
changeset
|
133 |
} |
1 | 134 |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32401
diff
changeset
|
135 |
VM_DeoptimizeFrame::VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id, int reason) { |
1 | 136 |
_thread = thread; |
137 |
_id = id; |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32401
diff
changeset
|
138 |
_reason = reason; |
1 | 139 |
} |
140 |
||
141 |
||
142 |
void VM_DeoptimizeFrame::doit() { |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32401
diff
changeset
|
143 |
assert(_reason > Deoptimization::Reason_none && _reason < Deoptimization::Reason_LIMIT, "invalid deopt reason"); |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32401
diff
changeset
|
144 |
Deoptimization::deoptimize_frame_internal(_thread, _id, (Deoptimization::DeoptReason)_reason); |
1 | 145 |
} |
146 |
||
147 |
||
148 |
#ifndef PRODUCT |
|
149 |
||
150 |
void VM_DeoptimizeAll::doit() { |
|
151 |
DeoptimizationMarker dm; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
152 |
JavaThreadIteratorWithHandle jtiwh; |
1 | 153 |
// deoptimize all java threads in the system |
154 |
if (DeoptimizeALot) { |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
155 |
for (; JavaThread *thread = jtiwh.next(); ) { |
1 | 156 |
if (thread->has_last_Java_frame()) { |
157 |
thread->deoptimize(); |
|
158 |
} |
|
159 |
} |
|
160 |
} else if (DeoptimizeRandom) { |
|
161 |
||
162 |
// Deoptimize some selected threads and frames |
|
163 |
int tnum = os::random() & 0x3; |
|
164 |
int fnum = os::random() & 0x3; |
|
165 |
int tcount = 0; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
166 |
for (; JavaThread *thread = jtiwh.next(); ) { |
1 | 167 |
if (thread->has_last_Java_frame()) { |
168 |
if (tcount++ == tnum) { |
|
169 |
tcount = 0; |
|
170 |
int fcount = 0; |
|
171 |
// Deoptimize some selected frames. |
|
172 |
// Biased llocking wants a updated register map |
|
173 |
for(StackFrameStream fst(thread, UseBiasedLocking); !fst.is_done(); fst.next()) { |
|
174 |
if (fst.current()->can_be_deoptimized()) { |
|
175 |
if (fcount++ == fnum) { |
|
176 |
fcount = 0; |
|
177 |
Deoptimization::deoptimize(thread, *fst.current(), fst.register_map()); |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
||
187 |
||
188 |
void VM_ZombieAll::doit() { |
|
189 |
JavaThread *thread = (JavaThread *)calling_thread(); |
|
190 |
assert(thread->is_Java_thread(), "must be a Java thread"); |
|
191 |
thread->make_zombies(); |
|
192 |
} |
|
193 |
||
194 |
#endif // !PRODUCT |
|
195 |
||
196 |
void VM_Verify::doit() { |
|
16680
960505df90e7
8011343: Add new flag for verifying the heap during startup
johnc
parents:
14583
diff
changeset
|
197 |
Universe::heap()->prepare_for_verify(); |
35061 | 198 |
Universe::verify(); |
1 | 199 |
} |
200 |
||
201 |
bool VM_PrintThreads::doit_prologue() { |
|
202 |
// Get Heap_lock if concurrent locks will be dumped |
|
203 |
if (_print_concurrent_locks) { |
|
204 |
Heap_lock->lock(); |
|
205 |
} |
|
206 |
return true; |
|
207 |
} |
|
208 |
||
209 |
void VM_PrintThreads::doit() { |
|
50785
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50419
diff
changeset
|
210 |
Threads::print_on(_out, true, false, _print_concurrent_locks, _print_extended_info); |
1 | 211 |
} |
212 |
||
213 |
void VM_PrintThreads::doit_epilogue() { |
|
214 |
if (_print_concurrent_locks) { |
|
215 |
// Release Heap_lock |
|
216 |
Heap_lock->unlock(); |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
void VM_PrintJNI::doit() { |
|
221 |
JNIHandles::print_on(_out); |
|
222 |
} |
|
223 |
||
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
224 |
void VM_PrintMetadata::doit() { |
49980 | 225 |
MetaspaceUtils::print_report(_out, _scale, _flags); |
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
226 |
} |
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
227 |
|
1 | 228 |
VM_FindDeadlocks::~VM_FindDeadlocks() { |
229 |
if (_deadlocks != NULL) { |
|
230 |
DeadlockCycle* cycle = _deadlocks; |
|
231 |
while (cycle != NULL) { |
|
232 |
DeadlockCycle* d = cycle; |
|
233 |
cycle = cycle->next(); |
|
234 |
delete d; |
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
void VM_FindDeadlocks::doit() { |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
240 |
// Update the hazard ptr in the originating thread to the current |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
241 |
// list of threads. This VM operation needs the current list of |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
242 |
// threads for proper deadlock detection and those are the |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
243 |
// JavaThreads we need to be protected when we return info to the |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
244 |
// originating thread. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
245 |
_setter.set(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
246 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
247 |
_deadlocks = ThreadService::find_deadlocks_at_safepoint(_setter.list(), _concurrent_locks); |
1 | 248 |
if (_out != NULL) { |
249 |
int num_deadlocks = 0; |
|
250 |
for (DeadlockCycle* cycle = _deadlocks; cycle != NULL; cycle = cycle->next()) { |
|
251 |
num_deadlocks++; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
252 |
cycle->print_on_with(_setter.list(), _out); |
1 | 253 |
} |
254 |
||
255 |
if (num_deadlocks == 1) { |
|
256 |
_out->print_cr("\nFound 1 deadlock.\n"); |
|
257 |
_out->flush(); |
|
258 |
} else if (num_deadlocks > 1) { |
|
259 |
_out->print_cr("\nFound %d deadlocks.\n", num_deadlocks); |
|
260 |
_out->flush(); |
|
261 |
} |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
VM_ThreadDump::VM_ThreadDump(ThreadDumpResult* result, |
|
266 |
int max_depth, |
|
267 |
bool with_locked_monitors, |
|
268 |
bool with_locked_synchronizers) { |
|
269 |
_result = result; |
|
270 |
_num_threads = 0; // 0 indicates all threads |
|
271 |
_threads = NULL; |
|
272 |
_result = result; |
|
273 |
_max_depth = max_depth; |
|
274 |
_with_locked_monitors = with_locked_monitors; |
|
275 |
_with_locked_synchronizers = with_locked_synchronizers; |
|
276 |
} |
|
277 |
||
278 |
VM_ThreadDump::VM_ThreadDump(ThreadDumpResult* result, |
|
279 |
GrowableArray<instanceHandle>* threads, |
|
280 |
int num_threads, |
|
281 |
int max_depth, |
|
282 |
bool with_locked_monitors, |
|
283 |
bool with_locked_synchronizers) { |
|
284 |
_result = result; |
|
285 |
_num_threads = num_threads; |
|
286 |
_threads = threads; |
|
287 |
_result = result; |
|
288 |
_max_depth = max_depth; |
|
289 |
_with_locked_monitors = with_locked_monitors; |
|
290 |
_with_locked_synchronizers = with_locked_synchronizers; |
|
291 |
} |
|
292 |
||
293 |
bool VM_ThreadDump::doit_prologue() { |
|
294 |
if (_with_locked_synchronizers) { |
|
295 |
// Acquire Heap_lock to dump concurrent locks |
|
296 |
Heap_lock->lock(); |
|
297 |
} |
|
298 |
||
299 |
return true; |
|
300 |
} |
|
301 |
||
302 |
void VM_ThreadDump::doit_epilogue() { |
|
303 |
if (_with_locked_synchronizers) { |
|
304 |
// Release Heap_lock |
|
305 |
Heap_lock->unlock(); |
|
306 |
} |
|
307 |
} |
|
308 |
||
309 |
void VM_ThreadDump::doit() { |
|
310 |
ResourceMark rm; |
|
311 |
||
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
312 |
// Set the hazard ptr in the originating thread to protect the |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
313 |
// current list of threads. This VM operation needs the current list |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
314 |
// of threads for a proper dump and those are the JavaThreads we need |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
315 |
// to be protected when we return info to the originating thread. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
316 |
_result->set_t_list(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
317 |
|
1 | 318 |
ConcurrentLocksDump concurrent_locks(true); |
319 |
if (_with_locked_synchronizers) { |
|
320 |
concurrent_locks.dump_at_safepoint(); |
|
321 |
} |
|
322 |
||
323 |
if (_num_threads == 0) { |
|
324 |
// Snapshot all live threads |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
325 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
326 |
for (uint i = 0; i < _result->t_list()->length(); i++) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
327 |
JavaThread* jt = _result->t_list()->thread_at(i); |
1 | 328 |
if (jt->is_exiting() || |
329 |
jt->is_hidden_from_external_view()) { |
|
330 |
// skip terminating threads and hidden threads |
|
331 |
continue; |
|
332 |
} |
|
333 |
ThreadConcurrentLocks* tcl = NULL; |
|
334 |
if (_with_locked_synchronizers) { |
|
335 |
tcl = concurrent_locks.thread_concurrent_locks(jt); |
|
336 |
} |
|
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
337 |
snapshot_thread(jt, tcl); |
1 | 338 |
} |
339 |
} else { |
|
340 |
// Snapshot threads in the given _threads array |
|
341 |
// A dummy snapshot is created if a thread doesn't exist |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
342 |
|
1 | 343 |
for (int i = 0; i < _num_threads; i++) { |
344 |
instanceHandle th = _threads->at(i); |
|
345 |
if (th() == NULL) { |
|
346 |
// skip if the thread doesn't exist |
|
347 |
// Add a dummy snapshot |
|
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
348 |
_result->add_thread_snapshot(); |
1 | 349 |
continue; |
350 |
} |
|
351 |
||
352 |
// Dump thread stack only if the thread is alive and not exiting |
|
353 |
// and not VM internal thread. |
|
354 |
JavaThread* jt = java_lang_Thread::thread(th()); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
355 |
if (jt != NULL && !_result->t_list()->includes(jt)) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
356 |
// _threads[i] doesn't refer to a valid JavaThread; this check |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
357 |
// is primarily for JVM_DumpThreads() which doesn't have a good |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
358 |
// way to validate the _threads array. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
359 |
jt = NULL; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
360 |
} |
1 | 361 |
if (jt == NULL || /* thread not alive */ |
362 |
jt->is_exiting() || |
|
363 |
jt->is_hidden_from_external_view()) { |
|
364 |
// add a NULL snapshot if skipped |
|
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
365 |
_result->add_thread_snapshot(); |
1 | 366 |
continue; |
367 |
} |
|
368 |
ThreadConcurrentLocks* tcl = NULL; |
|
369 |
if (_with_locked_synchronizers) { |
|
370 |
tcl = concurrent_locks.thread_concurrent_locks(jt); |
|
371 |
} |
|
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
372 |
snapshot_thread(jt, tcl); |
1 | 373 |
} |
374 |
} |
|
375 |
} |
|
376 |
||
53463
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
377 |
void VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) { |
b2d1c3b0bd31
8213231: ThreadSnapshot::_threadObj can become stale
ehelin
parents:
52877
diff
changeset
|
378 |
ThreadSnapshot* snapshot = _result->add_thread_snapshot(java_thread); |
1 | 379 |
snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors); |
380 |
snapshot->set_concurrent_locks(tcl); |
|
381 |
} |
|
382 |
||
383 |
volatile bool VM_Exit::_vm_exited = false; |
|
49636 | 384 |
Thread * volatile VM_Exit::_shutdown_thread = NULL; |
1 | 385 |
|
386 |
int VM_Exit::set_vm_exited() { |
|
31620
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
30764
diff
changeset
|
387 |
|
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
34262
diff
changeset
|
388 |
Thread * thr_cur = Thread::current(); |
1 | 389 |
|
390 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already"); |
|
391 |
||
392 |
int num_active = 0; |
|
393 |
||
394 |
_shutdown_thread = thr_cur; |
|
395 |
_vm_exited = true; // global flag |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
396 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) { |
1 | 397 |
if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { |
398 |
++num_active; |
|
399 |
thr->set_terminated(JavaThread::_vm_exited); // per-thread flag |
|
400 |
} |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
401 |
} |
1 | 402 |
|
403 |
return num_active; |
|
404 |
} |
|
405 |
||
406 |
int VM_Exit::wait_for_threads_in_native_to_block() { |
|
407 |
// VM exits at safepoint. This function must be called at the final safepoint |
|
408 |
// to wait for threads in _thread_in_native state to be quiescent. |
|
409 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already"); |
|
410 |
||
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
34262
diff
changeset
|
411 |
Thread * thr_cur = Thread::current(); |
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27420
diff
changeset
|
412 |
Monitor timer(Mutex::leaf, "VM_Exit timer", true, |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27420
diff
changeset
|
413 |
Monitor::_safepoint_check_never); |
1 | 414 |
|
415 |
// Compiler threads need longer wait because they can access VM data directly |
|
416 |
// while in native. If they are active and some structures being used are |
|
417 |
// deleted by the shutdown sequence, they will crash. On the other hand, user |
|
418 |
// threads must go through native=>Java/VM transitions first to access VM |
|
419 |
// data, and they will be stopped during state transition. In theory, we |
|
420 |
// don't have to wait for user threads to be quiescent, but it's always |
|
421 |
// better to terminate VM when current thread is the only active thread, so |
|
422 |
// wait for user threads too. Numbers are in 10 milliseconds. |
|
423 |
int max_wait_user_thread = 30; // at least 300 milliseconds |
|
424 |
int max_wait_compiler_thread = 1000; // at least 10 seconds |
|
425 |
||
426 |
int max_wait = max_wait_compiler_thread; |
|
427 |
||
428 |
int attempts = 0; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
429 |
JavaThreadIteratorWithHandle jtiwh; |
1 | 430 |
while (true) { |
431 |
int num_active = 0; |
|
432 |
int num_active_compiler_thread = 0; |
|
433 |
||
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
434 |
jtiwh.rewind(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
435 |
for (; JavaThread *thr = jtiwh.next(); ) { |
1 | 436 |
if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { |
437 |
num_active++; |
|
438 |
if (thr->is_Compiler_thread()) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54645
diff
changeset
|
439 |
#if INCLUDE_JVMCI |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54645
diff
changeset
|
440 |
CompilerThread* ct = (CompilerThread*) thr; |
54732 | 441 |
if (ct->compiler() == NULL || !ct->compiler()->is_jvmci()) { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54645
diff
changeset
|
442 |
num_active_compiler_thread++; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54645
diff
changeset
|
443 |
} else { |
54732 | 444 |
// A JVMCI compiler thread never accesses VM data structures |
445 |
// while in _thread_in_native state so there's no need to wait |
|
446 |
// for it and potentially add a 300 millisecond delay to VM |
|
447 |
// shutdown. |
|
448 |
num_active--; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54645
diff
changeset
|
449 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54645
diff
changeset
|
450 |
#else |
1 | 451 |
num_active_compiler_thread++; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54645
diff
changeset
|
452 |
#endif |
1 | 453 |
} |
454 |
} |
|
455 |
} |
|
456 |
||
457 |
if (num_active == 0) { |
|
458 |
return 0; |
|
459 |
} else if (attempts > max_wait) { |
|
460 |
return num_active; |
|
461 |
} else if (num_active_compiler_thread == 0 && attempts > max_wait_user_thread) { |
|
462 |
return num_active; |
|
463 |
} |
|
464 |
||
465 |
attempts++; |
|
466 |
||
54645
05aaccf7d558
8222988: Use MonitorLocker rather than MutexLocker when wait/notify used
coleenp
parents:
54623
diff
changeset
|
467 |
MonitorLocker ml(&timer, Mutex::_no_safepoint_check_flag); |
05aaccf7d558
8222988: Use MonitorLocker rather than MutexLocker when wait/notify used
coleenp
parents:
54623
diff
changeset
|
468 |
ml.wait(10); |
1 | 469 |
} |
470 |
} |
|
471 |
||
472 |
void VM_Exit::doit() { |
|
54729
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
473 |
|
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
474 |
if (VerifyBeforeExit) { |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
475 |
HandleMark hm(VMThread::vm_thread()); |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
476 |
// Among other things, this ensures that Eden top is correct. |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
477 |
Universe::heap()->prepare_for_verify(); |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
478 |
// Silent verification so as not to pollute normal output, |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
479 |
// unless we really asked for it. |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
480 |
Universe::verify(); |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
481 |
} |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
482 |
|
1 | 483 |
CompileBroker::set_should_block(); |
484 |
||
485 |
// Wait for a short period for threads in native to block. Any thread |
|
486 |
// still executing native code after the wait will be stopped at |
|
487 |
// native==>Java/VM barriers. |
|
488 |
// Among 16276 JCK tests, 94% of them come here without any threads still |
|
489 |
// running in native; the other 6% are quiescent within 250ms (Ultra 80). |
|
490 |
wait_for_threads_in_native_to_block(); |
|
491 |
||
492 |
set_vm_exited(); |
|
493 |
||
54729
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
494 |
// We'd like to call IdealGraphPrinter::clean_up() to finalize the |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
495 |
// XML logging, but we can't safely do that here. The logic to make |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
496 |
// XML termination logging safe is tied to the termination of the |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
497 |
// VMThread, and it doesn't terminate on this exit path. See 8222534. |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
498 |
|
1 | 499 |
// cleanup globals resources before exiting. exit_globals() currently |
500 |
// cleans up outputStream resources and PerfMemory resources. |
|
501 |
exit_globals(); |
|
502 |
||
54729
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
503 |
LogConfiguration::finalize(); |
f72402697b2f
8222534: VerifyBeforeExit is not honored when System.exit is called
dholmes
parents:
54669
diff
changeset
|
504 |
|
1 | 505 |
// Check for exit hook |
506 |
exit_hook_t exit_hook = Arguments::exit_hook(); |
|
507 |
if (exit_hook != NULL) { |
|
508 |
// exit hook should exit. |
|
509 |
exit_hook(_exit_code); |
|
510 |
// ... but if it didn't, we must do it here |
|
511 |
vm_direct_exit(_exit_code); |
|
512 |
} else { |
|
513 |
vm_direct_exit(_exit_code); |
|
514 |
} |
|
515 |
} |
|
516 |
||
517 |
||
518 |
void VM_Exit::wait_if_vm_exited() { |
|
519 |
if (_vm_exited && |
|
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
34262
diff
changeset
|
520 |
Thread::current_or_null() != _shutdown_thread) { |
1 | 521 |
// _vm_exited is set at safepoint, and the Threads_lock is never released |
522 |
// we will block here until the process dies |
|
523 |
Threads_lock->lock_without_safepoint_check(); |
|
524 |
ShouldNotReachHere(); |
|
525 |
} |
|
526 |
} |
|
26587 | 527 |
|
36322 | 528 |
void VM_PrintCompileQueue::doit() { |
529 |
CompileBroker::print_compile_queues(_out); |
|
530 |
} |
|
531 |
||
29071
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
532 |
#if INCLUDE_SERVICES |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
533 |
void VM_PrintClassHierarchy::doit() { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
534 |
KlassHierarchy::print_class_hierarchy(_out, _print_interfaces, _print_subclasses, _classname); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
535 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
536 |
#endif |