author | stuefe |
Tue, 24 Apr 2018 18:06:32 +0200 | |
changeset 49980 | 57dd7b4ba338 |
parent 49636 | 6d5bd76650df |
child 50113 | caf115bb98ad |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, 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" |
29071
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
33 |
#include "memory/heapInspection.hpp" |
7397 | 34 |
#include "memory/resourceArea.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
35 |
#include "oops/symbol.hpp" |
7397 | 36 |
#include "runtime/arguments.hpp" |
37 |
#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
|
38 |
#include "runtime/frame.inline.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49389
diff
changeset
|
39 |
#include "runtime/interfaceSupport.inline.hpp" |
7397 | 40 |
#include "runtime/sweeper.hpp" |
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
10565
diff
changeset
|
41 |
#include "runtime/thread.inline.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
42 |
#include "runtime/threadSMR.inline.hpp" |
7397 | 43 |
#include "runtime/vm_operations.hpp" |
44 |
#include "services/threadService.hpp" |
|
18025 | 45 |
#include "trace/tracing.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 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
196 |
void VM_UnlinkSymbols::doit() { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
197 |
JavaThread *thread = (JavaThread *)calling_thread(); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
198 |
assert(thread->is_Java_thread(), "must be a Java thread"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
199 |
SymbolTable::unlink(); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
200 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
201 |
|
1 | 202 |
void VM_Verify::doit() { |
16680
960505df90e7
8011343: Add new flag for verifying the heap during startup
johnc
parents:
14583
diff
changeset
|
203 |
Universe::heap()->prepare_for_verify(); |
35061 | 204 |
Universe::verify(); |
1 | 205 |
} |
206 |
||
207 |
bool VM_PrintThreads::doit_prologue() { |
|
208 |
// Make sure AbstractOwnableSynchronizer is loaded |
|
38708
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
209 |
JavaThread* jt = JavaThread::current(); |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
210 |
java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(jt); |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
211 |
if (jt->has_pending_exception()) { |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
212 |
return false; |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
213 |
} |
1 | 214 |
|
215 |
// Get Heap_lock if concurrent locks will be dumped |
|
216 |
if (_print_concurrent_locks) { |
|
217 |
Heap_lock->lock(); |
|
218 |
} |
|
219 |
return true; |
|
220 |
} |
|
221 |
||
222 |
void VM_PrintThreads::doit() { |
|
223 |
Threads::print_on(_out, true, false, _print_concurrent_locks); |
|
224 |
} |
|
225 |
||
226 |
void VM_PrintThreads::doit_epilogue() { |
|
227 |
if (_print_concurrent_locks) { |
|
228 |
// Release Heap_lock |
|
229 |
Heap_lock->unlock(); |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
void VM_PrintJNI::doit() { |
|
234 |
JNIHandles::print_on(_out); |
|
235 |
} |
|
236 |
||
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
237 |
void VM_PrintMetadata::doit() { |
49980 | 238 |
MetaspaceUtils::print_report(_out, _scale, _flags); |
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
239 |
} |
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
240 |
|
1 | 241 |
VM_FindDeadlocks::~VM_FindDeadlocks() { |
242 |
if (_deadlocks != NULL) { |
|
243 |
DeadlockCycle* cycle = _deadlocks; |
|
244 |
while (cycle != NULL) { |
|
245 |
DeadlockCycle* d = cycle; |
|
246 |
cycle = cycle->next(); |
|
247 |
delete d; |
|
248 |
} |
|
249 |
} |
|
250 |
} |
|
251 |
||
252 |
bool VM_FindDeadlocks::doit_prologue() { |
|
25057 | 253 |
if (_concurrent_locks) { |
38708
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
254 |
// Make sure AbstractOwnableSynchronizer is loaded |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
255 |
JavaThread* jt = JavaThread::current(); |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
256 |
java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(jt); |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
257 |
if (jt->has_pending_exception()) { |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
258 |
return false; |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
259 |
} |
1 | 260 |
} |
261 |
||
262 |
return true; |
|
263 |
} |
|
264 |
||
265 |
void VM_FindDeadlocks::doit() { |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
266 |
// 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
|
267 |
// 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
|
268 |
// 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
|
269 |
// 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
|
270 |
// originating thread. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
271 |
_setter.set(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
272 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
273 |
_deadlocks = ThreadService::find_deadlocks_at_safepoint(_setter.list(), _concurrent_locks); |
1 | 274 |
if (_out != NULL) { |
275 |
int num_deadlocks = 0; |
|
276 |
for (DeadlockCycle* cycle = _deadlocks; cycle != NULL; cycle = cycle->next()) { |
|
277 |
num_deadlocks++; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
278 |
cycle->print_on_with(_setter.list(), _out); |
1 | 279 |
} |
280 |
||
281 |
if (num_deadlocks == 1) { |
|
282 |
_out->print_cr("\nFound 1 deadlock.\n"); |
|
283 |
_out->flush(); |
|
284 |
} else if (num_deadlocks > 1) { |
|
285 |
_out->print_cr("\nFound %d deadlocks.\n", num_deadlocks); |
|
286 |
_out->flush(); |
|
287 |
} |
|
288 |
} |
|
289 |
} |
|
290 |
||
291 |
VM_ThreadDump::VM_ThreadDump(ThreadDumpResult* result, |
|
292 |
int max_depth, |
|
293 |
bool with_locked_monitors, |
|
294 |
bool with_locked_synchronizers) { |
|
295 |
_result = result; |
|
296 |
_num_threads = 0; // 0 indicates all threads |
|
297 |
_threads = NULL; |
|
298 |
_result = result; |
|
299 |
_max_depth = max_depth; |
|
300 |
_with_locked_monitors = with_locked_monitors; |
|
301 |
_with_locked_synchronizers = with_locked_synchronizers; |
|
302 |
} |
|
303 |
||
304 |
VM_ThreadDump::VM_ThreadDump(ThreadDumpResult* result, |
|
305 |
GrowableArray<instanceHandle>* threads, |
|
306 |
int num_threads, |
|
307 |
int max_depth, |
|
308 |
bool with_locked_monitors, |
|
309 |
bool with_locked_synchronizers) { |
|
310 |
_result = result; |
|
311 |
_num_threads = num_threads; |
|
312 |
_threads = threads; |
|
313 |
_result = result; |
|
314 |
_max_depth = max_depth; |
|
315 |
_with_locked_monitors = with_locked_monitors; |
|
316 |
_with_locked_synchronizers = with_locked_synchronizers; |
|
317 |
} |
|
318 |
||
319 |
bool VM_ThreadDump::doit_prologue() { |
|
38708
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
320 |
// Make sure AbstractOwnableSynchronizer is loaded |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
321 |
JavaThread* jt = JavaThread::current(); |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
322 |
java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(jt); |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
323 |
if (jt->has_pending_exception()) { |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
324 |
return false; |
8c27a4f8b242
8154589: assert(k != NULL) failed: preloaded klass not initialized
dholmes
parents:
37296
diff
changeset
|
325 |
} |
1 | 326 |
|
327 |
if (_with_locked_synchronizers) { |
|
328 |
// Acquire Heap_lock to dump concurrent locks |
|
329 |
Heap_lock->lock(); |
|
330 |
} |
|
331 |
||
332 |
return true; |
|
333 |
} |
|
334 |
||
335 |
void VM_ThreadDump::doit_epilogue() { |
|
336 |
if (_with_locked_synchronizers) { |
|
337 |
// Release Heap_lock |
|
338 |
Heap_lock->unlock(); |
|
339 |
} |
|
340 |
} |
|
341 |
||
342 |
void VM_ThreadDump::doit() { |
|
343 |
ResourceMark rm; |
|
344 |
||
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
345 |
// 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
|
346 |
// 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
|
347 |
// 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
|
348 |
// 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
|
349 |
_result->set_t_list(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
350 |
|
1 | 351 |
ConcurrentLocksDump concurrent_locks(true); |
352 |
if (_with_locked_synchronizers) { |
|
353 |
concurrent_locks.dump_at_safepoint(); |
|
354 |
} |
|
355 |
||
356 |
if (_num_threads == 0) { |
|
357 |
// Snapshot all live threads |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
358 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
359 |
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
|
360 |
JavaThread* jt = _result->t_list()->thread_at(i); |
1 | 361 |
if (jt->is_exiting() || |
362 |
jt->is_hidden_from_external_view()) { |
|
363 |
// skip terminating threads and hidden threads |
|
364 |
continue; |
|
365 |
} |
|
366 |
ThreadConcurrentLocks* tcl = NULL; |
|
367 |
if (_with_locked_synchronizers) { |
|
368 |
tcl = concurrent_locks.thread_concurrent_locks(jt); |
|
369 |
} |
|
370 |
ThreadSnapshot* ts = snapshot_thread(jt, tcl); |
|
371 |
_result->add_thread_snapshot(ts); |
|
372 |
} |
|
373 |
} else { |
|
374 |
// Snapshot threads in the given _threads array |
|
375 |
// 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
|
376 |
|
1 | 377 |
for (int i = 0; i < _num_threads; i++) { |
378 |
instanceHandle th = _threads->at(i); |
|
379 |
if (th() == NULL) { |
|
380 |
// skip if the thread doesn't exist |
|
381 |
// Add a dummy snapshot |
|
382 |
_result->add_thread_snapshot(new ThreadSnapshot()); |
|
383 |
continue; |
|
384 |
} |
|
385 |
||
386 |
// Dump thread stack only if the thread is alive and not exiting |
|
387 |
// and not VM internal thread. |
|
388 |
JavaThread* jt = java_lang_Thread::thread(th()); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
389 |
if (jt != NULL && !_result->t_list()->includes(jt)) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
390 |
// _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
|
391 |
// 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
|
392 |
// way to validate the _threads array. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
393 |
jt = NULL; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
394 |
} |
1 | 395 |
if (jt == NULL || /* thread not alive */ |
396 |
jt->is_exiting() || |
|
397 |
jt->is_hidden_from_external_view()) { |
|
398 |
// add a NULL snapshot if skipped |
|
399 |
_result->add_thread_snapshot(new ThreadSnapshot()); |
|
400 |
continue; |
|
401 |
} |
|
402 |
ThreadConcurrentLocks* tcl = NULL; |
|
403 |
if (_with_locked_synchronizers) { |
|
404 |
tcl = concurrent_locks.thread_concurrent_locks(jt); |
|
405 |
} |
|
406 |
ThreadSnapshot* ts = snapshot_thread(jt, tcl); |
|
407 |
_result->add_thread_snapshot(ts); |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
||
412 |
ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) { |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
413 |
ThreadSnapshot* snapshot = new ThreadSnapshot(_result->t_list(), java_thread); |
1 | 414 |
snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors); |
415 |
snapshot->set_concurrent_locks(tcl); |
|
416 |
return snapshot; |
|
417 |
} |
|
418 |
||
419 |
volatile bool VM_Exit::_vm_exited = false; |
|
49636 | 420 |
Thread * volatile VM_Exit::_shutdown_thread = NULL; |
1 | 421 |
|
422 |
int VM_Exit::set_vm_exited() { |
|
31620
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
30764
diff
changeset
|
423 |
|
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
34262
diff
changeset
|
424 |
Thread * thr_cur = Thread::current(); |
1 | 425 |
|
426 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already"); |
|
427 |
||
428 |
int num_active = 0; |
|
429 |
||
430 |
_shutdown_thread = thr_cur; |
|
431 |
_vm_exited = true; // global flag |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
432 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) { |
1 | 433 |
if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { |
434 |
++num_active; |
|
435 |
thr->set_terminated(JavaThread::_vm_exited); // per-thread flag |
|
436 |
} |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
437 |
} |
1 | 438 |
|
439 |
return num_active; |
|
440 |
} |
|
441 |
||
442 |
int VM_Exit::wait_for_threads_in_native_to_block() { |
|
443 |
// VM exits at safepoint. This function must be called at the final safepoint |
|
444 |
// to wait for threads in _thread_in_native state to be quiescent. |
|
445 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already"); |
|
446 |
||
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
34262
diff
changeset
|
447 |
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
|
448 |
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
|
449 |
Monitor::_safepoint_check_never); |
1 | 450 |
|
451 |
// Compiler threads need longer wait because they can access VM data directly |
|
452 |
// while in native. If they are active and some structures being used are |
|
453 |
// deleted by the shutdown sequence, they will crash. On the other hand, user |
|
454 |
// threads must go through native=>Java/VM transitions first to access VM |
|
455 |
// data, and they will be stopped during state transition. In theory, we |
|
456 |
// don't have to wait for user threads to be quiescent, but it's always |
|
457 |
// better to terminate VM when current thread is the only active thread, so |
|
458 |
// wait for user threads too. Numbers are in 10 milliseconds. |
|
459 |
int max_wait_user_thread = 30; // at least 300 milliseconds |
|
460 |
int max_wait_compiler_thread = 1000; // at least 10 seconds |
|
461 |
||
462 |
int max_wait = max_wait_compiler_thread; |
|
463 |
||
464 |
int attempts = 0; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
465 |
JavaThreadIteratorWithHandle jtiwh; |
1 | 466 |
while (true) { |
467 |
int num_active = 0; |
|
468 |
int num_active_compiler_thread = 0; |
|
469 |
||
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
470 |
jtiwh.rewind(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47802
diff
changeset
|
471 |
for (; JavaThread *thr = jtiwh.next(); ) { |
1 | 472 |
if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { |
473 |
num_active++; |
|
474 |
if (thr->is_Compiler_thread()) { |
|
475 |
num_active_compiler_thread++; |
|
476 |
} |
|
477 |
} |
|
478 |
} |
|
479 |
||
480 |
if (num_active == 0) { |
|
481 |
return 0; |
|
482 |
} else if (attempts > max_wait) { |
|
483 |
return num_active; |
|
484 |
} else if (num_active_compiler_thread == 0 && attempts > max_wait_user_thread) { |
|
485 |
return num_active; |
|
486 |
} |
|
487 |
||
488 |
attempts++; |
|
489 |
||
490 |
MutexLockerEx ml(&timer, Mutex::_no_safepoint_check_flag); |
|
491 |
timer.wait(Mutex::_no_safepoint_check_flag, 10); |
|
492 |
} |
|
493 |
} |
|
494 |
||
495 |
void VM_Exit::doit() { |
|
496 |
CompileBroker::set_should_block(); |
|
497 |
||
498 |
// Wait for a short period for threads in native to block. Any thread |
|
499 |
// still executing native code after the wait will be stopped at |
|
500 |
// native==>Java/VM barriers. |
|
501 |
// Among 16276 JCK tests, 94% of them come here without any threads still |
|
502 |
// running in native; the other 6% are quiescent within 250ms (Ultra 80). |
|
503 |
wait_for_threads_in_native_to_block(); |
|
504 |
||
505 |
set_vm_exited(); |
|
506 |
||
507 |
// cleanup globals resources before exiting. exit_globals() currently |
|
508 |
// cleans up outputStream resources and PerfMemory resources. |
|
509 |
exit_globals(); |
|
510 |
||
511 |
// Check for exit hook |
|
512 |
exit_hook_t exit_hook = Arguments::exit_hook(); |
|
513 |
if (exit_hook != NULL) { |
|
514 |
// exit hook should exit. |
|
515 |
exit_hook(_exit_code); |
|
516 |
// ... but if it didn't, we must do it here |
|
517 |
vm_direct_exit(_exit_code); |
|
518 |
} else { |
|
519 |
vm_direct_exit(_exit_code); |
|
520 |
} |
|
521 |
} |
|
522 |
||
523 |
||
524 |
void VM_Exit::wait_if_vm_exited() { |
|
525 |
if (_vm_exited && |
|
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
34262
diff
changeset
|
526 |
Thread::current_or_null() != _shutdown_thread) { |
1 | 527 |
// _vm_exited is set at safepoint, and the Threads_lock is never released |
528 |
// we will block here until the process dies |
|
529 |
Threads_lock->lock_without_safepoint_check(); |
|
530 |
ShouldNotReachHere(); |
|
531 |
} |
|
532 |
} |
|
26587 | 533 |
|
36322 | 534 |
void VM_PrintCompileQueue::doit() { |
535 |
CompileBroker::print_compile_queues(_out); |
|
536 |
} |
|
537 |
||
29071
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
538 |
#if INCLUDE_SERVICES |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
539 |
void VM_PrintClassHierarchy::doit() { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
540 |
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
|
541 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
28163
diff
changeset
|
542 |
#endif |