author | rehn |
Fri, 29 Nov 2019 12:09:25 +0100 | |
changeset 59325 | 3636bab5e81e |
parent 59258 | 4c2557ab304e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53582 | 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:
5533
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5533
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:
5533
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
51959
db0c3952de52
8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
51865
diff
changeset
|
26 |
#include "classfile/classLoaderDataGraph.inline.hpp" |
54961
30c8a21ce002
8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents:
54942
diff
changeset
|
27 |
#include "classfile/dictionary.hpp" |
24426
0a69c8cdfca9
8038654: Separate SymbolTable and StringTable code
gziemski
parents:
24096
diff
changeset
|
28 |
#include "classfile/stringTable.hpp" |
34666 | 29 |
#include "classfile/symbolTable.hpp" |
7397 | 30 |
#include "classfile/systemDictionary.hpp" |
31 |
#include "code/codeCache.hpp" |
|
32 |
#include "code/icBuffer.hpp" |
|
33 |
#include "code/nmethod.hpp" |
|
34 |
#include "code/pcDesc.hpp" |
|
35 |
#include "code/scopeDesc.hpp" |
|
58545
725244418646
8165056: move JIT Compiler related files from runtime/ to compiler/ directory
xliu
parents:
58041
diff
changeset
|
36 |
#include "compiler/compilationPolicy.hpp" |
30764 | 37 |
#include "gc/shared/collectedHeap.hpp" |
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
38 |
#include "gc/shared/gcLocker.hpp" |
55569
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
55514
diff
changeset
|
39 |
#include "gc/shared/oopStorage.hpp" |
46702 | 40 |
#include "gc/shared/strongRootsScope.hpp" |
41 |
#include "gc/shared/workgroup.hpp" |
|
7397 | 42 |
#include "interpreter/interpreter.hpp" |
50113 | 43 |
#include "jfr/jfrEvents.hpp" |
33763
cec2333f839c
8140348: Convert TraceSafepoint to Unified Logging
rprotacio
parents:
33589
diff
changeset
|
44 |
#include "logging/log.hpp" |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46630
diff
changeset
|
45 |
#include "logging/logStream.hpp" |
7397 | 46 |
#include "memory/resourceArea.hpp" |
49359
59f6547e151f
8199264: Remove universe.inline.hpp to simplify include dependencies
stefank
parents:
49169
diff
changeset
|
47 |
#include "memory/universe.hpp" |
7397 | 48 |
#include "oops/oop.inline.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
49 |
#include "oops/symbol.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
38151
diff
changeset
|
50 |
#include "runtime/atomic.hpp" |
7397 | 51 |
#include "runtime/deoptimization.hpp" |
52 |
#include "runtime/frame.inline.hpp" |
|
53582 | 53 |
#include "runtime/handles.inline.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49359
diff
changeset
|
54 |
#include "runtime/interfaceSupport.inline.hpp" |
7397 | 55 |
#include "runtime/mutexLocker.hpp" |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
50113
diff
changeset
|
56 |
#include "runtime/orderAccess.hpp" |
7397 | 57 |
#include "runtime/osThread.hpp" |
58 |
#include "runtime/safepoint.hpp" |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
59 |
#include "runtime/safepointMechanism.inline.hpp" |
7397 | 60 |
#include "runtime/signature.hpp" |
61 |
#include "runtime/stubCodeGenerator.hpp" |
|
62 |
#include "runtime/stubRoutines.hpp" |
|
63 |
#include "runtime/sweeper.hpp" |
|
64 |
#include "runtime/synchronizer.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
13195
diff
changeset
|
65 |
#include "runtime/thread.inline.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
66 |
#include "runtime/threadSMR.hpp" |
37161
e881f320966e
8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
37135
diff
changeset
|
67 |
#include "runtime/timerTrace.hpp" |
7397 | 68 |
#include "services/runtimeService.hpp" |
69 |
#include "utilities/events.hpp" |
|
15482
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
14583
diff
changeset
|
70 |
#include "utilities/macros.hpp" |
1 | 71 |
|
53775 | 72 |
static void post_safepoint_begin_event(EventSafepointBegin& event, |
73 |
uint64_t safepoint_id, |
|
50113 | 74 |
int thread_count, |
75 |
int critical_thread_count) { |
|
53775 | 76 |
if (event.should_commit()) { |
77 |
event.set_safepointId(safepoint_id); |
|
78 |
event.set_totalThreadCount(thread_count); |
|
79 |
event.set_jniCriticalThreadCount(critical_thread_count); |
|
80 |
event.commit(); |
|
81 |
} |
|
50113 | 82 |
} |
83 |
||
53775 | 84 |
static void post_safepoint_cleanup_event(EventSafepointCleanup& event, uint64_t safepoint_id) { |
85 |
if (event.should_commit()) { |
|
86 |
event.set_safepointId(safepoint_id); |
|
87 |
event.commit(); |
|
50113 | 88 |
} |
89 |
} |
|
90 |
||
53775 | 91 |
static void post_safepoint_synchronize_event(EventSafepointStateSynchronization& event, |
92 |
uint64_t safepoint_id, |
|
93 |
int initial_number_of_threads, |
|
94 |
int threads_waiting_to_block, |
|
95 |
uint64_t iterations) { |
|
96 |
if (event.should_commit()) { |
|
97 |
event.set_safepointId(safepoint_id); |
|
98 |
event.set_initialThreadCount(initial_number_of_threads); |
|
99 |
event.set_runningThreadCount(threads_waiting_to_block); |
|
100 |
event.set_iterations(iterations); |
|
101 |
event.commit(); |
|
50113 | 102 |
} |
103 |
} |
|
104 |
||
53775 | 105 |
static void post_safepoint_cleanup_task_event(EventSafepointCleanupTask& event, |
106 |
uint64_t safepoint_id, |
|
107 |
const char* name) { |
|
108 |
if (event.should_commit()) { |
|
109 |
event.set_safepointId(safepoint_id); |
|
110 |
event.set_name(name); |
|
111 |
event.commit(); |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
static void post_safepoint_end_event(EventSafepointEnd& event, uint64_t safepoint_id) { |
|
116 |
if (event.should_commit()) { |
|
117 |
event.set_safepointId(safepoint_id); |
|
118 |
event.commit(); |
|
50113 | 119 |
} |
120 |
} |
|
121 |
||
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
122 |
// SafepointCheck |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
123 |
SafepointStateTracker::SafepointStateTracker(uint64_t safepoint_id, bool at_safepoint) |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
124 |
: _safepoint_id(safepoint_id), _at_safepoint(at_safepoint) {} |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
125 |
|
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
126 |
bool SafepointStateTracker::safepoint_state_changed() { |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
127 |
return _safepoint_id != SafepointSynchronize::safepoint_id() || |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
128 |
_at_safepoint != SafepointSynchronize::is_at_safepoint(); |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
129 |
} |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
130 |
|
1 | 131 |
// -------------------------------------------------------------------------------------------------- |
132 |
// Implementation of Safepoint begin/end |
|
133 |
||
134 |
SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized; |
|
53775 | 135 |
int SafepointSynchronize::_waiting_to_block = 0; |
52672
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52628
diff
changeset
|
136 |
volatile uint64_t SafepointSynchronize::_safepoint_counter = 0; |
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
137 |
uint64_t SafepointSynchronize::_safepoint_id = 0; |
53775 | 138 |
const uint64_t SafepointSynchronize::InactiveSafepointCounter = 0; |
11631
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
10565
diff
changeset
|
139 |
int SafepointSynchronize::_current_jni_active_count = 0; |
53775 | 140 |
|
141 |
WaitBarrier* SafepointSynchronize::_wait_barrier; |
|
142 |
||
143 |
static volatile bool PageArmed = false; // safepoint polling page is RO|RW vs PROT_NONE |
|
1 | 144 |
static bool timeout_error_printed = false; |
145 |
||
53775 | 146 |
// Statistic related |
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
147 |
static jlong _safepoint_begin_time = 0; |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
148 |
static volatile int _nof_threads_hit_polling_page = 0; |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
149 |
|
53775 | 150 |
void SafepointSynchronize::init(Thread* vmthread) { |
151 |
// WaitBarrier should never be destroyed since we will have |
|
152 |
// threads waiting on it while exiting. |
|
153 |
_wait_barrier = new WaitBarrier(vmthread); |
|
53895 | 154 |
SafepointTracing::init(); |
53775 | 155 |
} |
156 |
||
157 |
void SafepointSynchronize::increment_jni_active_count() { |
|
158 |
assert(Thread::current()->is_VM_thread(), "Only VM thread may increment"); |
|
159 |
++_current_jni_active_count; |
|
160 |
} |
|
161 |
||
162 |
void SafepointSynchronize::decrement_waiting_to_block() { |
|
163 |
assert(_waiting_to_block > 0, "sanity check"); |
|
164 |
assert(Thread::current()->is_VM_thread(), "Only VM thread may decrement"); |
|
165 |
--_waiting_to_block; |
|
166 |
} |
|
167 |
||
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
168 |
bool SafepointSynchronize::thread_not_running(ThreadSafepointState *cur_state) { |
53775 | 169 |
if (!cur_state->is_running()) { |
170 |
return true; |
|
171 |
} |
|
172 |
cur_state->examine_state_of_thread(SafepointSynchronize::safepoint_counter()); |
|
173 |
if (!cur_state->is_running()) { |
|
174 |
return true; |
|
175 |
} |
|
176 |
LogTarget(Trace, safepoint) lt; |
|
177 |
if (lt.is_enabled()) { |
|
178 |
ResourceMark rm; |
|
179 |
LogStream ls(lt); |
|
180 |
cur_state->print_on(&ls); |
|
181 |
} |
|
182 |
return false; |
|
183 |
} |
|
1 | 184 |
|
53775 | 185 |
#ifdef ASSERT |
186 |
static void assert_list_is_valid(const ThreadSafepointState* tss_head, int still_running) { |
|
187 |
int a = 0; |
|
188 |
const ThreadSafepointState *tmp_tss = tss_head; |
|
189 |
while (tmp_tss != NULL) { |
|
190 |
++a; |
|
191 |
assert(tmp_tss->is_running(), "Illegal initial state"); |
|
192 |
tmp_tss = tmp_tss->get_next(); |
|
193 |
} |
|
194 |
assert(a == still_running, "Must be the same"); |
|
195 |
} |
|
196 |
#endif // ASSERT |
|
197 |
||
54621
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
198 |
static void back_off(int64_t start_time) { |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
199 |
// We start with fine-grained nanosleeping until a millisecond has |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
200 |
// passed, at which point we resort to plain naked_short_sleep. |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
201 |
if (os::javaTimeNanos() - start_time < NANOSECS_PER_MILLISEC) { |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
202 |
os::naked_short_nanosleep(10 * (NANOUNITS / MICROUNITS)); |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
203 |
} else { |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
204 |
os::naked_short_sleep(1); |
53775 | 205 |
} |
206 |
} |
|
207 |
||
208 |
int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running) |
|
209 |
{ |
|
210 |
JavaThreadIteratorWithHandle jtiwh; |
|
211 |
||
212 |
#ifdef ASSERT |
|
213 |
for (; JavaThread *cur = jtiwh.next(); ) { |
|
214 |
assert(cur->safepoint_state()->is_running(), "Illegal initial state"); |
|
215 |
} |
|
216 |
jtiwh.rewind(); |
|
217 |
#endif // ASSERT |
|
218 |
||
219 |
// Iterate through all threads until it has been determined how to stop them all at a safepoint. |
|
220 |
int still_running = nof_threads; |
|
221 |
ThreadSafepointState *tss_head = NULL; |
|
222 |
ThreadSafepointState **p_prev = &tss_head; |
|
223 |
for (; JavaThread *cur = jtiwh.next(); ) { |
|
224 |
ThreadSafepointState *cur_tss = cur->safepoint_state(); |
|
225 |
assert(cur_tss->get_next() == NULL, "Must be NULL"); |
|
226 |
if (thread_not_running(cur_tss)) { |
|
227 |
--still_running; |
|
228 |
} else { |
|
229 |
*p_prev = cur_tss; |
|
230 |
p_prev = cur_tss->next_ptr(); |
|
231 |
} |
|
232 |
} |
|
233 |
*p_prev = NULL; |
|
234 |
||
235 |
DEBUG_ONLY(assert_list_is_valid(tss_head, still_running);) |
|
236 |
||
237 |
*initial_running = still_running; |
|
1 | 238 |
|
54621
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
239 |
// If there is no thread still running, we are already done. |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
240 |
if (still_running <= 0) { |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
241 |
assert(tss_head == NULL, "Must be empty"); |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
242 |
return 1; |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
243 |
} |
1 | 244 |
|
54621
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
245 |
int iterations = 1; // The first iteration is above. |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
246 |
int64_t start_time = os::javaTimeNanos(); |
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
247 |
|
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
248 |
do { |
53775 | 249 |
// Check if this has taken too long: |
250 |
if (SafepointTimeout && safepoint_limit_time < os::javaTimeNanos()) { |
|
53895 | 251 |
print_safepoint_timeout(); |
53775 | 252 |
} |
253 |
if (int(iterations) == -1) { // overflow - something is wrong. |
|
254 |
// We can only overflow here when we are using global |
|
255 |
// polling pages. We keep this guarantee in its original |
|
256 |
// form so that searches of the bug database for this |
|
257 |
// failure mode find the right bugs. |
|
258 |
guarantee (!PageArmed, "invariant"); |
|
259 |
} |
|
1 | 260 |
|
53775 | 261 |
p_prev = &tss_head; |
262 |
ThreadSafepointState *cur_tss = tss_head; |
|
263 |
while (cur_tss != NULL) { |
|
264 |
assert(cur_tss->is_running(), "Illegal initial state"); |
|
265 |
if (thread_not_running(cur_tss)) { |
|
266 |
--still_running; |
|
267 |
*p_prev = NULL; |
|
268 |
ThreadSafepointState *tmp = cur_tss; |
|
269 |
cur_tss = cur_tss->get_next(); |
|
270 |
tmp->set_next(NULL); |
|
271 |
} else { |
|
272 |
*p_prev = cur_tss; |
|
273 |
p_prev = cur_tss->next_ptr(); |
|
274 |
cur_tss = cur_tss->get_next(); |
|
275 |
} |
|
276 |
} |
|
11631
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
10565
diff
changeset
|
277 |
|
53775 | 278 |
DEBUG_ONLY(assert_list_is_valid(tss_head, still_running);) |
279 |
||
280 |
if (still_running > 0) { |
|
54621
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
281 |
back_off(start_time); |
53775 | 282 |
} |
283 |
||
284 |
iterations++; |
|
54621
0b6dc5b93306
8220795: Rework naked_short_nanosleep on Windows to improve time-to-safepoint
rwestberg
parents:
54495
diff
changeset
|
285 |
} while (still_running > 0); |
1 | 286 |
|
53775 | 287 |
assert(tss_head == NULL, "Must be empty"); |
1 | 288 |
|
53775 | 289 |
return iterations; |
290 |
} |
|
291 |
||
292 |
void SafepointSynchronize::arm_safepoint() { |
|
1 | 293 |
// Begin the process of bringing the system to a safepoint. |
294 |
// Java threads can be in several different states and are |
|
295 |
// stopped by different mechanisms: |
|
296 |
// |
|
297 |
// 1. Running interpreted |
|
53895 | 298 |
// When executing branching/returning byte codes interpreter |
299 |
// checks if the poll is armed, if so blocks in SS::block(). |
|
300 |
// When using global polling the interpreter dispatch table |
|
301 |
// is changed to force it to check for a safepoint condition |
|
302 |
// between bytecodes. |
|
1 | 303 |
// 2. Running in native code |
304 |
// When returning from the native code, a Java thread must check |
|
305 |
// the safepoint _state to see if we must block. If the |
|
306 |
// VM thread sees a Java thread in native, it does |
|
307 |
// not wait for this thread to block. The order of the memory |
|
308 |
// writes and reads of both the safepoint state and the Java |
|
309 |
// threads state is critical. In order to guarantee that the |
|
310 |
// memory writes are serialized with respect to each other, |
|
52460 | 311 |
// the VM thread issues a memory barrier instruction. |
1 | 312 |
// 3. Running compiled Code |
53775 | 313 |
// Compiled code reads the local polling page that |
1 | 314 |
// is set to fault if we are trying to get to a safepoint. |
315 |
// 4. Blocked |
|
316 |
// A thread which is blocked will not be allowed to return from the |
|
317 |
// block condition until the safepoint operation is complete. |
|
318 |
// 5. In VM or Transitioning between states |
|
319 |
// If a Java thread is currently running in the VM or transitioning |
|
53895 | 320 |
// between states, the safepointing code will poll the thread state |
321 |
// until the thread blocks itself when it attempts transitions to a |
|
322 |
// new state or locking a safepoint checked monitor. |
|
1 | 323 |
|
53775 | 324 |
// We must never miss a thread with correct safepoint id, so we must make sure we arm |
325 |
// the wait barrier for the next safepoint id/counter. |
|
326 |
// Arming must be done after resetting _current_jni_active_count, _waiting_to_block. |
|
327 |
_wait_barrier->arm(static_cast<int>(_safepoint_counter + 1)); |
|
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
37161
diff
changeset
|
328 |
|
53775 | 329 |
assert((_safepoint_counter & 0x1) == 0, "must be even"); |
330 |
// The store to _safepoint_counter must happen after any stores in arming. |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
58545
diff
changeset
|
331 |
Atomic::release_store(&_safepoint_counter, _safepoint_counter + 1); |
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
37161
diff
changeset
|
332 |
|
53775 | 333 |
// We are synchronizing |
334 |
OrderAccess::storestore(); // Ordered with _safepoint_counter |
|
335 |
_state = _synchronizing; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
336 |
|
53775 | 337 |
if (SafepointMechanism::uses_thread_local_poll()) { |
338 |
// Arming the per thread poll while having _state != _not_synchronized means safepointing |
|
339 |
log_trace(safepoint)("Setting thread local yield flag for threads"); |
|
340 |
OrderAccess::storestore(); // storestore, global state -> local state |
|
341 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) { |
|
342 |
// Make sure the threads start polling, it is time to yield. |
|
343 |
SafepointMechanism::arm_local_poll(cur); |
|
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
37161
diff
changeset
|
344 |
} |
50113 | 345 |
} |
53775 | 346 |
OrderAccess::fence(); // storestore|storeload, global state -> local state |
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
37161
diff
changeset
|
347 |
|
53775 | 348 |
if (SafepointMechanism::uses_global_page_poll()) { |
349 |
// Make interpreter safepoint aware |
|
350 |
Interpreter::notice_safepoints(); |
|
351 |
||
352 |
// Make polling safepoint aware |
|
353 |
guarantee (!PageArmed, "invariant") ; |
|
354 |
PageArmed = true; |
|
355 |
os::make_polling_page_unreadable(); |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
// Roll all threads forward to a safepoint and suspend them all |
|
360 |
void SafepointSynchronize::begin() { |
|
361 |
assert(Thread::current()->is_VM_thread(), "Only VM thread may execute a safepoint"); |
|
362 |
||
53895 | 363 |
EventSafepointBegin begin_event; |
364 |
SafepointTracing::begin(VMThread::vm_op_type()); |
|
53775 | 365 |
|
366 |
Universe::heap()->safepoint_synchronize_begin(); |
|
367 |
||
368 |
// By getting the Threads_lock, we assure that no threads are about to start or |
|
369 |
// exit. It is released again in SafepointSynchronize::end(). |
|
370 |
Threads_lock->lock(); |
|
371 |
||
372 |
assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state"); |
|
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
37161
diff
changeset
|
373 |
|
53775 | 374 |
int nof_threads = Threads::number_of_threads(); |
375 |
||
53895 | 376 |
_nof_threads_hit_polling_page = 0; |
53775 | 377 |
|
53895 | 378 |
log_debug(safepoint)("Safepoint synchronization initiated using %s wait barrier. (%d threads)", _wait_barrier->description(), nof_threads); |
53775 | 379 |
|
380 |
// Reset the count of active JNI critical threads |
|
381 |
_current_jni_active_count = 0; |
|
382 |
||
383 |
// Set number of threads to wait for |
|
384 |
_waiting_to_block = nof_threads; |
|
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
37161
diff
changeset
|
385 |
|
53775 | 386 |
jlong safepoint_limit_time = 0; |
387 |
if (SafepointTimeout) { |
|
388 |
// Set the limit time, so that it can be compared to see if this has taken |
|
389 |
// too long to complete. |
|
53895 | 390 |
safepoint_limit_time = SafepointTracing::start_of_safepoint() + (jlong)SafepointTimeoutDelay * (NANOUNITS / MILLIUNITS); |
391 |
timeout_error_printed = false; |
|
53775 | 392 |
} |
393 |
||
394 |
EventSafepointStateSynchronization sync_event; |
|
395 |
int initial_running = 0; |
|
396 |
||
397 |
// Arms the safepoint, _current_jni_active_count and _waiting_to_block must be set before. |
|
398 |
arm_safepoint(); |
|
399 |
||
400 |
// Will spin until all threads are safe. |
|
401 |
int iterations = synchronize_threads(safepoint_limit_time, nof_threads, &initial_running); |
|
402 |
assert(_waiting_to_block == 0, "No thread should be running"); |
|
403 |
||
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
37161
diff
changeset
|
404 |
#ifndef PRODUCT |
53895 | 405 |
if (safepoint_limit_time != 0) { |
53775 | 406 |
jlong current_time = os::javaTimeNanos(); |
407 |
if (safepoint_limit_time < current_time) { |
|
408 |
log_warning(safepoint)("# SafepointSynchronize: Finished after " |
|
409 |
INT64_FORMAT_W(6) " ms", |
|
53895 | 410 |
(int64_t)(current_time - SafepointTracing::start_of_safepoint()) / (NANOUNITS / MILLIUNITS)); |
1 | 411 |
} |
53775 | 412 |
} |
1 | 413 |
#endif |
414 |
||
53775 | 415 |
assert(Threads_lock->owned_by_self(), "must hold Threads_lock"); |
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
37161
diff
changeset
|
416 |
|
53775 | 417 |
// Record state |
418 |
_state = _synchronized; |
|
1 | 419 |
|
53775 | 420 |
OrderAccess::fence(); |
421 |
||
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
422 |
// Set the new id |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
423 |
++_safepoint_id; |
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
424 |
|
12108
b2ee55606008
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
11637
diff
changeset
|
425 |
#ifdef ASSERT |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
426 |
// Make sure all the threads were visited. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
427 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) { |
53775 | 428 |
assert(cur->was_visited_for_critical_count(_safepoint_counter), "missed a thread"); |
12108
b2ee55606008
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
11637
diff
changeset
|
429 |
} |
b2ee55606008
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
11637
diff
changeset
|
430 |
#endif // ASSERT |
b2ee55606008
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
11637
diff
changeset
|
431 |
|
11631
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
10565
diff
changeset
|
432 |
// Update the count of active JNI critical regions |
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
35061
diff
changeset
|
433 |
GCLocker::set_jni_lock_count(_current_jni_active_count); |
11631
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
10565
diff
changeset
|
434 |
|
53895 | 435 |
post_safepoint_synchronize_event(sync_event, |
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
436 |
_safepoint_id, |
53895 | 437 |
initial_running, |
438 |
_waiting_to_block, iterations); |
|
1 | 439 |
|
53895 | 440 |
SafepointTracing::synchronized(nof_threads, initial_running, _nof_threads_hit_polling_page); |
1 | 441 |
|
53775 | 442 |
// We do the safepoint cleanup first since a GC related safepoint |
443 |
// needs cleanup to be completed before running the GC op. |
|
444 |
EventSafepointCleanup cleanup_event; |
|
445 |
do_cleanup_tasks(); |
|
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
446 |
post_safepoint_cleanup_event(cleanup_event, _safepoint_id); |
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
4006
diff
changeset
|
447 |
|
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
448 |
post_safepoint_begin_event(begin_event, _safepoint_id, nof_threads, _current_jni_active_count); |
53895 | 449 |
SafepointTracing::cleanup(); |
1 | 450 |
} |
451 |
||
53775 | 452 |
void SafepointSynchronize::disarm_safepoint() { |
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
453 |
uint64_t active_safepoint_counter = _safepoint_counter; |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
454 |
{ |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
455 |
JavaThreadIteratorWithHandle jtiwh; |
1 | 456 |
#ifdef ASSERT |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
457 |
// A pending_exception cannot be installed during a safepoint. The threads |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
458 |
// may install an async exception after they come back from a safepoint into |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
459 |
// pending_exception after they unblock. But that should happen later. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
460 |
for (; JavaThread *cur = jtiwh.next(); ) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
461 |
assert (!(cur->has_pending_exception() && |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
462 |
cur->safepoint_state()->is_at_poll_safepoint()), |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
463 |
"safepoint installed a pending exception"); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
464 |
} |
1 | 465 |
#endif // ASSERT |
466 |
||
53775 | 467 |
if (SafepointMechanism::uses_global_page_poll()) { |
468 |
guarantee (PageArmed, "invariant"); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
469 |
// Make polling safepoint aware |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
470 |
os::make_polling_page_readable(); |
53775 | 471 |
PageArmed = false; |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
472 |
// Remove safepoint check from interpreter |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
473 |
Interpreter::ignore_safepoints(); |
1 | 474 |
} |
475 |
||
53775 | 476 |
OrderAccess::fence(); // keep read and write of _state from floating up |
477 |
assert(_state == _synchronized, "must be synchronized before ending safepoint synchronization"); |
|
478 |
||
479 |
// Change state first to _not_synchronized. |
|
480 |
// No threads should see _synchronized when running. |
|
481 |
_state = _not_synchronized; |
|
482 |
||
483 |
// Set the next dormant (even) safepoint id. |
|
484 |
assert((_safepoint_counter & 0x1) == 1, "must be odd"); |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
58545
diff
changeset
|
485 |
Atomic::release_store(&_safepoint_counter, _safepoint_counter + 1); |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
486 |
|
53775 | 487 |
OrderAccess::fence(); // Keep the local state from floating up. |
488 |
||
489 |
jtiwh.rewind(); |
|
490 |
for (; JavaThread *current = jtiwh.next(); ) { |
|
491 |
// Clear the visited flag to ensure that the critical counts are collected properly. |
|
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
492 |
DEBUG_ONLY(current->reset_visited_for_critical_count(active_safepoint_counter);) |
53775 | 493 |
ThreadSafepointState* cur_state = current->safepoint_state(); |
494 |
assert(!cur_state->is_running(), "Thread not suspended at safepoint"); |
|
495 |
cur_state->restart(); // TSS _running |
|
496 |
assert(cur_state->is_running(), "safepoint state has not been reset"); |
|
54323 | 497 |
|
498 |
SafepointMechanism::disarm_if_needed(current, false /* NO release */); |
|
53775 | 499 |
} |
500 |
} // ~JavaThreadIteratorWithHandle |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47881
diff
changeset
|
501 |
|
53775 | 502 |
// Release threads lock, so threads can be created/destroyed again. |
503 |
Threads_lock->unlock(); |
|
504 |
||
505 |
// Wake threads after local state is correctly set. |
|
506 |
_wait_barrier->disarm(); |
|
507 |
} |
|
1 | 508 |
|
53775 | 509 |
// Wake up all threads, so they are ready to resume execution after the safepoint |
510 |
// operation has been carried out |
|
511 |
void SafepointSynchronize::end() { |
|
512 |
assert(Threads_lock->owned_by_self(), "must hold Threads_lock"); |
|
513 |
EventSafepointEnd event; |
|
514 |
assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint"); |
|
1 | 515 |
|
53775 | 516 |
disarm_safepoint(); |
517 |
||
47636
52d46d7e3454
8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents:
47629
diff
changeset
|
518 |
Universe::heap()->safepoint_synchronize_end(); |
53775 | 519 |
|
53895 | 520 |
SafepointTracing::end(); |
53775 | 521 |
|
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
522 |
post_safepoint_end_event(event, safepoint_id()); |
1 | 523 |
} |
524 |
||
525 |
bool SafepointSynchronize::is_cleanup_needed() { |
|
46541
d20828de9e39
8181859: Monitor deflation is not checked in cleanup path
rehn
parents:
46496
diff
changeset
|
526 |
// Need a safepoint if there are many monitors to deflate. |
d20828de9e39
8181859: Monitor deflation is not checked in cleanup path
rehn
parents:
46496
diff
changeset
|
527 |
if (ObjectSynchronizer::is_cleanup_needed()) return true; |
1 | 528 |
// Need a safepoint if some inline cache buffers is non-empty |
529 |
if (!InlineCacheBuffer::is_empty()) return true; |
|
54942 | 530 |
if (StringTable::needs_rehashing()) return true; |
531 |
if (SymbolTable::needs_rehashing()) return true; |
|
1 | 532 |
return false; |
533 |
} |
|
534 |
||
59325 | 535 |
bool SafepointSynchronize::is_forced_cleanup_needed() { |
536 |
return ObjectSynchronizer::needs_monitor_scavenge(); |
|
537 |
} |
|
538 |
||
46702 | 539 |
class ParallelSPCleanupThreadClosure : public ThreadClosure { |
540 |
private: |
|
541 |
CodeBlobClosure* _nmethod_cl; |
|
542 |
DeflateMonitorCounters* _counters; |
|
543 |
||
544 |
public: |
|
545 |
ParallelSPCleanupThreadClosure(DeflateMonitorCounters* counters) : |
|
51865
eb954a4b6083
8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents:
51598
diff
changeset
|
546 |
_nmethod_cl(UseCodeAging ? NMethodSweeper::prepare_reset_hotness_counters() : NULL), |
eb954a4b6083
8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents:
51598
diff
changeset
|
547 |
_counters(counters) {} |
46702 | 548 |
|
549 |
void do_thread(Thread* thread) { |
|
550 |
ObjectSynchronizer::deflate_thread_local_monitors(thread, _counters); |
|
551 |
if (_nmethod_cl != NULL && thread->is_Java_thread() && |
|
552 |
! thread->is_Code_cache_sweeper_thread()) { |
|
553 |
JavaThread* jt = (JavaThread*) thread; |
|
554 |
jt->nmethods_do(_nmethod_cl); |
|
555 |
} |
|
1 | 556 |
} |
46702 | 557 |
}; |
558 |
||
559 |
class ParallelSPCleanupTask : public AbstractGangTask { |
|
560 |
private: |
|
561 |
SubTasksDone _subtasks; |
|
562 |
ParallelSPCleanupThreadClosure _cleanup_threads_cl; |
|
563 |
uint _num_workers; |
|
564 |
DeflateMonitorCounters* _counters; |
|
565 |
public: |
|
566 |
ParallelSPCleanupTask(uint num_workers, DeflateMonitorCounters* counters) : |
|
567 |
AbstractGangTask("Parallel Safepoint Cleanup"), |
|
51334
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
50966
diff
changeset
|
568 |
_subtasks(SubTasksDone(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS)), |
46702 | 569 |
_cleanup_threads_cl(ParallelSPCleanupThreadClosure(counters)), |
570 |
_num_workers(num_workers), |
|
571 |
_counters(counters) {} |
|
572 |
||
573 |
void work(uint worker_id) { |
|
55514
03468b206457
8225702: Safepoint counter can't be used for safepoint detection
rehn
parents:
54982
diff
changeset
|
574 |
uint64_t safepoint_id = SafepointSynchronize::safepoint_id(); |
46702 | 575 |
// All threads deflate monitors and mark nmethods (if necessary). |
47637
87141990dde5
8185580: Refactor Threads::possibly_parallel_oops_do() to use Threads::parallel_java_threads_do()
rkennke
parents:
47636
diff
changeset
|
576 |
Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl); |
46702 | 577 |
|
51598 | 578 |
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) { |
52703
e7fdc9d9c376
8202415: Incorrect time logged for monitor deflation
dcubed
parents:
52672
diff
changeset
|
579 |
const char* name = "deflating global idle monitors"; |
46702 | 580 |
EventSafepointCleanupTask event; |
581 |
TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); |
|
582 |
ObjectSynchronizer::deflate_idle_monitors(_counters); |
|
53775 | 583 |
|
584 |
post_safepoint_cleanup_task_event(event, safepoint_id, name); |
|
46702 | 585 |
} |
586 |
||
51598 | 587 |
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) { |
46702 | 588 |
const char* name = "updating inline caches"; |
589 |
EventSafepointCleanupTask event; |
|
590 |
TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); |
|
591 |
InlineCacheBuffer::update_inline_caches(); |
|
53775 | 592 |
|
593 |
post_safepoint_cleanup_task_event(event, safepoint_id, name); |
|
46702 | 594 |
} |
1 | 595 |
|
51598 | 596 |
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) { |
46702 | 597 |
const char* name = "compilation policy safepoint handler"; |
598 |
EventSafepointCleanupTask event; |
|
599 |
TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); |
|
600 |
CompilationPolicy::policy()->do_safepoint_work(); |
|
53775 | 601 |
|
602 |
post_safepoint_cleanup_task_event(event, safepoint_id, name); |
|
46702 | 603 |
} |
604 |
||
51598 | 605 |
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH)) { |
46702 | 606 |
if (SymbolTable::needs_rehashing()) { |
607 |
const char* name = "rehashing symbol table"; |
|
608 |
EventSafepointCleanupTask event; |
|
609 |
TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); |
|
610 |
SymbolTable::rehash_table(); |
|
53775 | 611 |
|
612 |
post_safepoint_cleanup_task_event(event, safepoint_id, name); |
|
46702 | 613 |
} |
614 |
} |
|
615 |
||
51598 | 616 |
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_STRING_TABLE_REHASH)) { |
46702 | 617 |
if (StringTable::needs_rehashing()) { |
618 |
const char* name = "rehashing string table"; |
|
619 |
EventSafepointCleanupTask event; |
|
620 |
TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); |
|
621 |
StringTable::rehash_table(); |
|
53775 | 622 |
|
623 |
post_safepoint_cleanup_task_event(event, safepoint_id, name); |
|
46702 | 624 |
} |
625 |
} |
|
626 |
||
51598 | 627 |
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE)) { |
54961
30c8a21ce002
8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents:
54942
diff
changeset
|
628 |
if (Dictionary::does_any_dictionary_needs_resizing()) { |
30c8a21ce002
8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents:
54942
diff
changeset
|
629 |
const char* name = "resizing system dictionaries"; |
30c8a21ce002
8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents:
54942
diff
changeset
|
630 |
EventSafepointCleanupTask event; |
30c8a21ce002
8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents:
54942
diff
changeset
|
631 |
TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); |
30c8a21ce002
8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents:
54942
diff
changeset
|
632 |
ClassLoaderDataGraph::resize_dictionaries(); |
53775 | 633 |
|
54961
30c8a21ce002
8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents:
54942
diff
changeset
|
634 |
post_safepoint_cleanup_task_event(event, safepoint_id, name); |
30c8a21ce002
8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents:
54942
diff
changeset
|
635 |
} |
47774 | 636 |
} |
51338
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
637 |
|
55569
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
55514
diff
changeset
|
638 |
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP)) { |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
55514
diff
changeset
|
639 |
// Don't bother reporting event or time for this very short operation. |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
55514
diff
changeset
|
640 |
// To have any utility we'd also want to report whether needed. |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
55514
diff
changeset
|
641 |
OopStorage::trigger_cleanup_if_needed(); |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
55514
diff
changeset
|
642 |
} |
8e3a0ebf3497
8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents:
55514
diff
changeset
|
643 |
|
46702 | 644 |
_subtasks.all_tasks_completed(_num_workers); |
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
4006
diff
changeset
|
645 |
} |
46702 | 646 |
}; |
647 |
||
648 |
// Various cleaning tasks that should be done periodically at safepoints. |
|
649 |
void SafepointSynchronize::do_cleanup_tasks() { |
|
650 |
||
651 |
TraceTime timer("safepoint cleanup tasks", TRACETIME_LOG(Info, safepoint, cleanup)); |
|
652 |
||
653 |
// Prepare for monitor deflation. |
|
654 |
DeflateMonitorCounters deflate_counters; |
|
655 |
ObjectSynchronizer::prepare_deflate_idle_monitors(&deflate_counters); |
|
656 |
||
657 |
CollectedHeap* heap = Universe::heap(); |
|
658 |
assert(heap != NULL, "heap not initialized yet?"); |
|
659 |
WorkGang* cleanup_workers = heap->get_safepoint_workers(); |
|
660 |
if (cleanup_workers != NULL) { |
|
661 |
// Parallel cleanup using GC provided thread pool. |
|
662 |
uint num_cleanup_workers = cleanup_workers->active_workers(); |
|
663 |
ParallelSPCleanupTask cleanup(num_cleanup_workers, &deflate_counters); |
|
664 |
StrongRootsScope srs(num_cleanup_workers); |
|
665 |
cleanup_workers->run_task(&cleanup); |
|
666 |
} else { |
|
667 |
// Serial cleanup using VMThread. |
|
668 |
ParallelSPCleanupTask cleanup(1, &deflate_counters); |
|
669 |
StrongRootsScope srs(1); |
|
670 |
cleanup.work(0); |
|
1 | 671 |
} |
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
4006
diff
changeset
|
672 |
|
51338
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
673 |
// Needs to be done single threaded by the VMThread. This walks |
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
674 |
// the thread stacks looking for references to metadata before |
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
675 |
// deciding to remove it from the metaspaces. |
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
676 |
if (ClassLoaderDataGraph::should_clean_metaspaces_and_reset()) { |
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
677 |
const char* name = "cleanup live ClassLoaderData metaspaces"; |
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
678 |
TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); |
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
679 |
ClassLoaderDataGraph::walk_metadata_and_clean_metaspaces(); |
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
680 |
} |
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
681 |
|
46702 | 682 |
// Finish monitor deflation. |
683 |
ObjectSynchronizer::finish_deflate_idle_monitors(&deflate_counters); |
|
51338
aa3bfacc912c
8208677: Move inner metaspace cleaning out of class unloading
coleenp
parents:
51334
diff
changeset
|
684 |
|
52857
7e268f863ff0
8214338: Move IC stub refilling out of IC cache transitions
eosterlund
parents:
52703
diff
changeset
|
685 |
assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer"); |
1 | 686 |
} |
687 |
||
53775 | 688 |
// Methods for determining if a JavaThread is safepoint safe. |
1 | 689 |
|
53775 | 690 |
// False means unsafe with undetermined state. |
691 |
// True means a determined state, but it may be an unsafe state. |
|
692 |
// If called from a non-safepoint context safepoint_count MUST be InactiveSafepointCounter. |
|
693 |
bool SafepointSynchronize::try_stable_load_state(JavaThreadState *state, JavaThread *thread, uint64_t safepoint_count) { |
|
694 |
assert((safepoint_count != InactiveSafepointCounter && |
|
695 |
Thread::current() == (Thread*)VMThread::vm_thread() && |
|
696 |
SafepointSynchronize::_state != _not_synchronized) |
|
697 |
|| safepoint_count == InactiveSafepointCounter, "Invalid check"); |
|
698 |
||
699 |
// To handle the thread_blocked state on the backedge of the WaitBarrier from |
|
700 |
// previous safepoint and reading the reset value (0/InactiveSafepointCounter) we |
|
701 |
// re-read state after we read thread safepoint id. The JavaThread changes its |
|
702 |
// thread state from thread_blocked before resetting safepoint id to 0. |
|
703 |
// This guarantees the second read will be from an updated thread state. It can |
|
704 |
// either be different state making this an unsafe state or it can see blocked |
|
705 |
// again. When we see blocked twice with a 0 safepoint id, either: |
|
706 |
// - It is normally blocked, e.g. on Mutex, TBIVM. |
|
707 |
// - It was in SS:block(), looped around to SS:block() and is blocked on the WaitBarrier. |
|
708 |
// - It was in SS:block() but now on a Mutex. |
|
709 |
// All of these cases are safe. |
|
710 |
||
711 |
*state = thread->thread_state(); |
|
712 |
OrderAccess::loadload(); |
|
713 |
uint64_t sid = thread->safepoint_state()->get_safepoint_id(); // Load acquire |
|
714 |
if (sid != InactiveSafepointCounter && sid != safepoint_count) { |
|
715 |
// In an old safepoint, state not relevant. |
|
716 |
return false; |
|
717 |
} |
|
718 |
return *state == thread->thread_state(); |
|
719 |
} |
|
720 |
||
721 |
static bool safepoint_safe_with(JavaThread *thread, JavaThreadState state) { |
|
1 | 722 |
switch(state) { |
723 |
case _thread_in_native: |
|
724 |
// native threads are safe if they have no java stack or have walkable stack |
|
725 |
return !thread->has_last_Java_frame() || thread->frame_anchor()->walkable(); |
|
726 |
||
727 |
case _thread_blocked: |
|
53775 | 728 |
// On wait_barrier or blocked. |
729 |
// Blocked threads should already have walkable stack. |
|
1 | 730 |
assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "blocked and not walkable"); |
731 |
return true; |
|
732 |
||
733 |
default: |
|
734 |
return false; |
|
735 |
} |
|
736 |
} |
|
737 |
||
53775 | 738 |
bool SafepointSynchronize::handshake_safe(JavaThread *thread) { |
739 |
// This function must be called with the Threads_lock held so an externally |
|
740 |
// suspended thread cannot be resumed thus it is safe. |
|
741 |
assert(Threads_lock->owned_by_self() && Thread::current()->is_VM_thread(), |
|
742 |
"Must hold Threads_lock and be VMThread"); |
|
743 |
if (thread->is_ext_suspended() || thread->is_terminated()) { |
|
744 |
return true; |
|
745 |
} |
|
746 |
JavaThreadState stable_state; |
|
747 |
if (try_stable_load_state(&stable_state, thread, InactiveSafepointCounter)) { |
|
748 |
return safepoint_safe_with(thread, stable_state); |
|
749 |
} |
|
750 |
return false; |
|
751 |
} |
|
1 | 752 |
|
11637
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
753 |
// See if the thread is running inside a lazy critical native and |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
754 |
// update the thread critical count if so. Also set a suspend flag to |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
755 |
// cause the native wrapper to return into the JVM to do the unlock |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
756 |
// once the native finishes. |
53775 | 757 |
static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state) { |
11637
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
758 |
if (state == _thread_in_native && |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
759 |
thread->has_last_Java_frame() && |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
760 |
thread->frame_anchor()->walkable()) { |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
761 |
// This thread might be in a critical native nmethod so look at |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
762 |
// the top of the stack and increment the critical count if it |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
763 |
// is. |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
764 |
frame wrapper_frame = thread->last_frame(); |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
765 |
CodeBlob* stub_cb = wrapper_frame.cb(); |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
766 |
if (stub_cb != NULL && |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
767 |
stub_cb->is_nmethod() && |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
768 |
stub_cb->as_nmethod_or_null()->is_lazy_critical_native()) { |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
769 |
// A thread could potentially be in a critical native across |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
770 |
// more than one safepoint, so only update the critical state on |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
771 |
// the first one. When it returns it will perform the unlock. |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
772 |
if (!thread->do_critical_native_unlock()) { |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
773 |
#ifdef ASSERT |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
774 |
if (!thread->in_critical()) { |
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
35061
diff
changeset
|
775 |
GCLocker::increment_debug_jni_lock_count(); |
11637
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
776 |
} |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
777 |
#endif |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
778 |
thread->enter_critical(); |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
779 |
// Make sure the native wrapper calls back on return to |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
780 |
// perform the needed critical unlock. |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
781 |
thread->set_critical_native_unlock(); |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
782 |
} |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
783 |
} |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
784 |
} |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
785 |
} |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
786 |
|
53775 | 787 |
// ------------------------------------------------------------------------------------------------------- |
788 |
// Implementation of Safepoint blocking point |
|
11637
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
789 |
|
53775 | 790 |
void SafepointSynchronize::block(JavaThread *thread) { |
1 | 791 |
assert(thread != NULL, "thread must be set"); |
792 |
assert(thread->is_Java_thread(), "not a Java thread"); |
|
793 |
||
794 |
// Threads shouldn't block if they are in the middle of printing, but... |
|
795 |
ttyLocker::break_tty_lock_for_safepoint(os::current_thread_id()); |
|
796 |
||
797 |
// Only bail from the block() call if the thread is gone from the |
|
798 |
// thread list; starting to exit should still block. |
|
799 |
if (thread->is_terminated()) { |
|
800 |
// block current thread if we come here from native code when VM is gone |
|
801 |
thread->block_if_vm_exited(); |
|
802 |
||
803 |
// otherwise do nothing |
|
804 |
return; |
|
805 |
} |
|
806 |
||
807 |
JavaThreadState state = thread->thread_state(); |
|
808 |
thread->frame_anchor()->make_walkable(thread); |
|
809 |
||
53775 | 810 |
uint64_t safepoint_id = SafepointSynchronize::safepoint_counter(); |
1 | 811 |
// Check that we have a valid thread_state at this point |
812 |
switch(state) { |
|
813 |
case _thread_in_vm_trans: |
|
814 |
case _thread_in_Java: // From compiled code |
|
815 |
case _thread_in_native_trans: |
|
816 |
case _thread_blocked_trans: |
|
817 |
case _thread_new_trans: |
|
53775 | 818 |
|
819 |
// We have no idea where the VMThread is, it might even be at next safepoint. |
|
820 |
// So we can miss this poll, but stop at next. |
|
1 | 821 |
|
53775 | 822 |
// Load dependent store, it must not pass loading of safepoint_id. |
823 |
thread->safepoint_state()->set_safepoint_id(safepoint_id); // Release store |
|
824 |
||
825 |
// This part we can skip if we notice we miss or are in a future safepoint. |
|
826 |
OrderAccess::storestore(); |
|
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54323
diff
changeset
|
827 |
// Load in wait barrier should not float up |
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54323
diff
changeset
|
828 |
thread->set_thread_state_fence(_thread_blocked); |
1 | 829 |
|
53775 | 830 |
_wait_barrier->wait(static_cast<int>(safepoint_id)); |
831 |
assert(_state != _synchronized, "Can't be"); |
|
1 | 832 |
|
53775 | 833 |
// If barrier is disarmed stop store from floating above loads in barrier. |
834 |
OrderAccess::loadstore(); |
|
1 | 835 |
thread->set_thread_state(state); |
836 |
||
53775 | 837 |
// Then we reset the safepoint id to inactive. |
838 |
thread->safepoint_state()->reset_safepoint_id(); // Release store |
|
839 |
||
840 |
OrderAccess::fence(); |
|
841 |
||
1 | 842 |
break; |
843 |
||
844 |
default: |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31592
diff
changeset
|
845 |
fatal("Illegal threadstate encountered: %d", state); |
1 | 846 |
} |
53775 | 847 |
guarantee(thread->safepoint_state()->get_safepoint_id() == InactiveSafepointCounter, |
848 |
"The safepoint id should be set only in block path"); |
|
1 | 849 |
|
850 |
// Check for pending. async. exceptions or suspends - except if the |
|
851 |
// thread was blocked inside the VM. has_special_runtime_exit_condition() |
|
852 |
// is called last since it grabs a lock and we only want to do that when |
|
853 |
// we must. |
|
854 |
// |
|
855 |
// Note: we never deliver an async exception at a polling point as the |
|
856 |
// compiler may not have an exception handler for it. The polling |
|
857 |
// code will notice the async and deoptimize and the exception will |
|
858 |
// be delivered. (Polling at a return point is ok though). Sure is |
|
859 |
// a lot of bother for a deprecated feature... |
|
860 |
// |
|
861 |
// We don't deliver an async exception if the thread state is |
|
862 |
// _thread_in_native_trans so JNI functions won't be called with |
|
863 |
// a surprising pending exception. If the thread state is going back to java, |
|
864 |
// async exception is checked in check_special_condition_for_native_trans(). |
|
865 |
||
866 |
if (state != _thread_blocked_trans && |
|
867 |
state != _thread_in_vm_trans && |
|
868 |
thread->has_special_runtime_exit_condition()) { |
|
869 |
thread->handle_special_runtime_exit_condition( |
|
870 |
!thread->is_at_poll_safepoint() && (state != _thread_in_native_trans)); |
|
871 |
} |
|
54323 | 872 |
|
873 |
// cross_modify_fence is done by SafepointMechanism::block_if_requested_slow |
|
874 |
// which is the only caller here. |
|
1 | 875 |
} |
876 |
||
877 |
// ------------------------------------------------------------------------------------------------------ |
|
878 |
// Exception handlers |
|
879 |
||
880 |
||
881 |
void SafepointSynchronize::handle_polling_page_exception(JavaThread *thread) { |
|
882 |
assert(thread->is_Java_thread(), "polling reference encountered by VM thread"); |
|
883 |
assert(thread->thread_state() == _thread_in_Java, "should come from Java code"); |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
884 |
if (!ThreadLocalHandshakes) { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
885 |
assert(SafepointSynchronize::is_synchronizing(), "polling encountered outside safepoint synchronization"); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
886 |
} |
1 | 887 |
|
53895 | 888 |
if (log_is_enabled(Info, safepoint, stats)) { |
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
889 |
Atomic::inc(&_nof_threads_hit_polling_page); |
1 | 890 |
} |
891 |
||
892 |
ThreadSafepointState* state = thread->safepoint_state(); |
|
893 |
||
894 |
state->handle_polling_page_exception(); |
|
895 |
} |
|
896 |
||
897 |
||
53895 | 898 |
void SafepointSynchronize::print_safepoint_timeout() { |
1 | 899 |
if (!timeout_error_printed) { |
900 |
timeout_error_printed = true; |
|
22551 | 901 |
// Print out the thread info which didn't reach the safepoint for debugging |
1 | 902 |
// purposes (useful when there are lots of threads in the debugger). |
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
903 |
LogTarget(Warning, safepoint) lt; |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
904 |
if (lt.is_enabled()) { |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
905 |
ResourceMark rm; |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
906 |
LogStream ls(lt); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
907 |
|
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
908 |
ls.cr(); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
909 |
ls.print_cr("# SafepointSynchronize::begin: Timeout detected:"); |
53895 | 910 |
ls.print_cr("# SafepointSynchronize::begin: Timed out while spinning to reach a safepoint."); |
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
911 |
ls.print_cr("# SafepointSynchronize::begin: Threads which did not reach the safepoint:"); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
912 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur_thread = jtiwh.next(); ) { |
53895 | 913 |
if (cur_thread->safepoint_state()->is_running()) { |
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
914 |
ls.print("# "); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
915 |
cur_thread->print_on(&ls); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
916 |
ls.cr(); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
917 |
} |
1 | 918 |
} |
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
919 |
ls.print_cr("# SafepointSynchronize::begin: (End of list)"); |
1 | 920 |
} |
921 |
} |
|
922 |
||
52628
639a3e43f5b7
8213992: Rename and make DieOnSafepointTimeout the diagnostic option
shade
parents:
52460
diff
changeset
|
923 |
// To debug the long safepoint, specify both AbortVMOnSafepointTimeout & |
1 | 924 |
// ShowMessageBoxOnError. |
52628
639a3e43f5b7
8213992: Rename and make DieOnSafepointTimeout the diagnostic option
shade
parents:
52460
diff
changeset
|
925 |
if (AbortVMOnSafepointTimeout) { |
54031
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
926 |
// Send the blocking thread a signal to terminate and write an error file. |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
927 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur_thread = jtiwh.next(); ) { |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
928 |
if (cur_thread->safepoint_state()->is_running()) { |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
929 |
if (!os::signal_thread(cur_thread, SIGILL, "blocking a safepoint")) { |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
930 |
break; // Could not send signal. Report fatal error. |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
931 |
} |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
932 |
// Give cur_thread a chance to report the error and terminate the VM. |
58041
d8902e9c307c
8230422: Convert uninterruptible os::sleep calls to os::naked_short_sleep
dholmes
parents:
57758
diff
changeset
|
933 |
os::naked_sleep(3000); |
54031
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
934 |
} |
feea57b38a1c
8219584: Try to dump error file by thread which causes safepoint timeout
mdoerr
parents:
54009
diff
changeset
|
935 |
} |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31592
diff
changeset
|
936 |
fatal("Safepoint sync time longer than " INTX_FORMAT "ms detected when executing %s.", |
53895 | 937 |
SafepointTimeoutDelay, VMThread::vm_operation()->name()); |
1 | 938 |
} |
939 |
} |
|
940 |
||
941 |
// ------------------------------------------------------------------------------------------------------- |
|
942 |
// Implementation of ThreadSafepointState |
|
943 |
||
53775 | 944 |
ThreadSafepointState::ThreadSafepointState(JavaThread *thread) |
945 |
: _at_poll_safepoint(false), _thread(thread), _safepoint_safe(false), |
|
57758 | 946 |
_safepoint_id(SafepointSynchronize::InactiveSafepointCounter), _next(NULL) { |
1 | 947 |
} |
948 |
||
949 |
void ThreadSafepointState::create(JavaThread *thread) { |
|
950 |
ThreadSafepointState *state = new ThreadSafepointState(thread); |
|
951 |
thread->set_safepoint_state(state); |
|
952 |
} |
|
953 |
||
954 |
void ThreadSafepointState::destroy(JavaThread *thread) { |
|
955 |
if (thread->safepoint_state()) { |
|
956 |
delete(thread->safepoint_state()); |
|
957 |
thread->set_safepoint_state(NULL); |
|
958 |
} |
|
959 |
} |
|
960 |
||
53775 | 961 |
uint64_t ThreadSafepointState::get_safepoint_id() const { |
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
58545
diff
changeset
|
962 |
return Atomic::load_acquire(&_safepoint_id); |
53775 | 963 |
} |
964 |
||
965 |
void ThreadSafepointState::reset_safepoint_id() { |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
58545
diff
changeset
|
966 |
Atomic::release_store(&_safepoint_id, SafepointSynchronize::InactiveSafepointCounter); |
53775 | 967 |
} |
968 |
||
969 |
void ThreadSafepointState::set_safepoint_id(uint64_t safepoint_id) { |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
58545
diff
changeset
|
970 |
Atomic::release_store(&_safepoint_id, safepoint_id); |
53775 | 971 |
} |
972 |
||
973 |
void ThreadSafepointState::examine_state_of_thread(uint64_t safepoint_count) { |
|
1 | 974 |
assert(is_running(), "better be running or just have hit safepoint poll"); |
975 |
||
53775 | 976 |
JavaThreadState stable_state; |
977 |
if (!SafepointSynchronize::try_stable_load_state(&stable_state, _thread, safepoint_count)) { |
|
978 |
// We could not get stable state of the JavaThread. |
|
979 |
// Consider it running and just return. |
|
980 |
return; |
|
981 |
} |
|
1 | 982 |
|
983 |
// Check for a thread that is suspended. Note that thread resume tries |
|
984 |
// to grab the Threads_lock which we own here, so a thread cannot be |
|
985 |
// resumed during safepoint synchronization. |
|
986 |
||
3826 | 987 |
// We check to see if this thread is suspended without locking to |
988 |
// avoid deadlocking with a third thread that is waiting for this |
|
989 |
// thread to be suspended. The third thread can notice the safepoint |
|
990 |
// that we're trying to start at the beginning of its SR_lock->wait() |
|
991 |
// call. If that happens, then the third thread will block on the |
|
992 |
// safepoint while still holding the underlying SR_lock. We won't be |
|
993 |
// able to get the SR_lock and we'll deadlock. |
|
994 |
// |
|
995 |
// We don't need to grab the SR_lock here for two reasons: |
|
996 |
// 1) The suspend flags are both volatile and are set with an |
|
997 |
// Atomic::cmpxchg() call so we should see the suspended |
|
998 |
// state right away. |
|
999 |
// 2) We're being called from the safepoint polling loop; if |
|
1000 |
// we don't see the suspended state on this iteration, then |
|
1001 |
// we'll come around again. |
|
1002 |
// |
|
1003 |
bool is_suspended = _thread->is_ext_suspended(); |
|
1 | 1004 |
if (is_suspended) { |
53775 | 1005 |
account_safe_thread(); |
1 | 1006 |
return; |
1007 |
} |
|
1008 |
||
53775 | 1009 |
if (safepoint_safe_with(_thread, stable_state)) { |
1010 |
check_for_lazy_critical_native(_thread, stable_state); |
|
1011 |
account_safe_thread(); |
|
1 | 1012 |
return; |
1013 |
} |
|
1014 |
||
1015 |
// All other thread states will continue to run until they |
|
1016 |
// transition and self-block in state _blocked |
|
1017 |
// Safepoint polling in compiled code causes the Java threads to do the same. |
|
1018 |
// Note: new threads may require a malloc so they must be allowed to finish |
|
1019 |
||
1020 |
assert(is_running(), "examine_state_of_thread on non-running thread"); |
|
1021 |
return; |
|
1022 |
} |
|
1023 |
||
53775 | 1024 |
void ThreadSafepointState::account_safe_thread() { |
1025 |
SafepointSynchronize::decrement_waiting_to_block(); |
|
1026 |
if (_thread->in_critical()) { |
|
1027 |
// Notice that this thread is in a critical section |
|
1028 |
SafepointSynchronize::increment_jni_active_count(); |
|
1 | 1029 |
} |
53775 | 1030 |
DEBUG_ONLY(_thread->set_visited_for_critical_count(SafepointSynchronize::safepoint_counter());) |
1031 |
assert(!_safepoint_safe, "Must be unsafe before safe"); |
|
1032 |
_safepoint_safe = true; |
|
1 | 1033 |
} |
1034 |
||
1035 |
void ThreadSafepointState::restart() { |
|
53775 | 1036 |
assert(_safepoint_safe, "Must be safe before unsafe"); |
1037 |
_safepoint_safe = false; |
|
1 | 1038 |
} |
1039 |
||
1040 |
void ThreadSafepointState::print_on(outputStream *st) const { |
|
53775 | 1041 |
const char *s = _safepoint_safe ? "_at_safepoint" : "_running"; |
1 | 1042 |
|
1043 |
st->print_cr("Thread: " INTPTR_FORMAT |
|
53775 | 1044 |
" [0x%2x] State: %s _at_poll_safepoint %d", |
1045 |
p2i(_thread), _thread->osthread()->thread_id(), s, _at_poll_safepoint); |
|
1 | 1046 |
|
1047 |
_thread->print_thread_state_on(st); |
|
1048 |
} |
|
1049 |
||
1050 |
// --------------------------------------------------------------------------------------------------------------------- |
|
1051 |
||
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
1052 |
// Block the thread at poll or poll return for safepoint/handshake. |
1 | 1053 |
void ThreadSafepointState::handle_polling_page_exception() { |
1054 |
||
53775 | 1055 |
// If we're using a global poll, then the thread should not be |
1056 |
// marked as safepoint safe yet. |
|
1057 |
assert(!SafepointMechanism::uses_global_page_poll() || !_safepoint_safe, |
|
1058 |
"polling page exception on thread safepoint safe"); |
|
1 | 1059 |
|
1060 |
// Step 1: Find the nmethod from the return address |
|
1061 |
address real_return_addr = thread()->saved_exception_pc(); |
|
1062 |
||
1063 |
CodeBlob *cb = CodeCache::find_blob(real_return_addr); |
|
38133
78b95467b9f1
8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
37242
diff
changeset
|
1064 |
assert(cb != NULL && cb->is_compiled(), "return address should be in nmethod"); |
78b95467b9f1
8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
37242
diff
changeset
|
1065 |
CompiledMethod* nm = (CompiledMethod*)cb; |
1 | 1066 |
|
1067 |
// Find frame of caller |
|
1068 |
frame stub_fr = thread()->last_frame(); |
|
1069 |
CodeBlob* stub_cb = stub_fr.cb(); |
|
1070 |
assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub"); |
|
1071 |
RegisterMap map(thread(), true); |
|
1072 |
frame caller_fr = stub_fr.sender(&map); |
|
1073 |
||
1074 |
// Should only be poll_return or poll |
|
1075 |
assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" ); |
|
1076 |
||
1077 |
// This is a poll immediately before a return. The exception handling code |
|
1078 |
// has already had the effect of causing the return to occur, so the execution |
|
1079 |
// will continue immediately after the call. In addition, the oopmap at the |
|
1080 |
// return point does not mark the return value as an oop (if it is), so |
|
1081 |
// it needs a handle here to be updated. |
|
1082 |
if( nm->is_at_poll_return(real_return_addr) ) { |
|
1083 |
// See if return type is an oop. |
|
1084 |
bool return_oop = nm->method()->is_returning_oop(); |
|
1085 |
Handle return_value; |
|
1086 |
if (return_oop) { |
|
1087 |
// The oop result has been saved on the stack together with all |
|
1088 |
// the other registers. In order to preserve it over GCs we need |
|
1089 |
// to keep it in a handle. |
|
1090 |
oop result = caller_fr.saved_oop_result(&map); |
|
46968
9119841280f4
8160399: is_oop_or_null involves undefined behavior
coleenp
parents:
46702
diff
changeset
|
1091 |
assert(oopDesc::is_oop_or_null(result), "must be oop"); |
1 | 1092 |
return_value = Handle(thread(), result); |
1093 |
assert(Universe::heap()->is_in_or_null(result), "must be heap pointer"); |
|
1094 |
} |
|
1095 |
||
1096 |
// Block the thread |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
1097 |
SafepointMechanism::block_if_requested(thread()); |
1 | 1098 |
|
1099 |
// restore oop result, if any |
|
1100 |
if (return_oop) { |
|
1101 |
caller_fr.set_saved_oop_result(&map, return_value()); |
|
1102 |
} |
|
1103 |
} |
|
1104 |
||
1105 |
// This is a safepoint poll. Verify the return address and block. |
|
1106 |
else { |
|
1107 |
set_at_poll_safepoint(true); |
|
1108 |
||
1109 |
// verify the blob built the "return address" correctly |
|
1110 |
assert(real_return_addr == caller_fr.pc(), "must match"); |
|
1111 |
||
1112 |
// Block the thread |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
1113 |
SafepointMechanism::block_if_requested(thread()); |
1 | 1114 |
set_at_poll_safepoint(false); |
1115 |
||
1116 |
// If we have a pending async exception deoptimize the frame |
|
1117 |
// as otherwise we may never deliver it. |
|
1118 |
if (thread()->has_async_condition()) { |
|
1119 |
ThreadInVMfromJavaNoAsyncException __tiv(thread()); |
|
7106
867c9d296c6b
6968367: can_post_on_exceptions is still using VM_DeoptimizeFrame in some places
never
parents:
6453
diff
changeset
|
1120 |
Deoptimization::deoptimize_frame(thread(), caller_fr.id()); |
1 | 1121 |
} |
1122 |
||
1123 |
// If an exception has been installed we must check for a pending deoptimization |
|
1124 |
// Deoptimize frame if exception has been thrown. |
|
1125 |
||
1126 |
if (thread()->has_pending_exception() ) { |
|
1127 |
RegisterMap map(thread(), true); |
|
1128 |
frame caller_fr = stub_fr.sender(&map); |
|
1129 |
if (caller_fr.is_deoptimized_frame()) { |
|
1130 |
// The exception patch will destroy registers that are still |
|
1131 |
// live and will be needed during deoptimization. Defer the |
|
22551 | 1132 |
// Async exception should have deferred the exception until the |
1 | 1133 |
// next safepoint which will be detected when we get into |
1134 |
// the interpreter so if we have an exception now things |
|
1135 |
// are messed up. |
|
1136 |
||
1137 |
fatal("Exception installed and deoptimization is pending"); |
|
1138 |
} |
|
1139 |
} |
|
1140 |
} |
|
1141 |
} |
|
1142 |
||
1143 |
||
53895 | 1144 |
// ------------------------------------------------------------------------------------------------------- |
1145 |
// Implementation of SafepointTracing |
|
1 | 1146 |
|
53895 | 1147 |
jlong SafepointTracing::_last_safepoint_begin_time_ns = 0; |
1148 |
jlong SafepointTracing::_last_safepoint_sync_time_ns = 0; |
|
1149 |
jlong SafepointTracing::_last_safepoint_cleanup_time_ns = 0; |
|
1150 |
jlong SafepointTracing::_last_safepoint_end_time_ns = 0; |
|
54009
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
1151 |
jlong SafepointTracing::_last_safepoint_end_time_epoch_ms = 0; |
53895 | 1152 |
jlong SafepointTracing::_last_app_time_ns = 0; |
1153 |
int SafepointTracing::_nof_threads = 0; |
|
1154 |
int SafepointTracing::_nof_running = 0; |
|
1155 |
int SafepointTracing::_page_trap = 0; |
|
1156 |
VM_Operation::VMOp_Type SafepointTracing::_current_type; |
|
1157 |
jlong SafepointTracing::_max_sync_time = 0; |
|
1158 |
jlong SafepointTracing::_max_vmop_time = 0; |
|
1159 |
uint64_t SafepointTracing::_op_count[VM_Operation::VMOp_Terminating] = {0}; |
|
1 | 1160 |
|
53895 | 1161 |
void SafepointTracing::init() { |
1162 |
// Application start |
|
1163 |
_last_safepoint_end_time_ns = os::javaTimeNanos(); |
|
54009
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
1164 |
// amount of time since epoch |
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
1165 |
_last_safepoint_end_time_epoch_ms = os::javaTimeMillis(); |
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1166 |
} |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1167 |
|
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1168 |
// Helper method to print the header. |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1169 |
static void print_header(outputStream* st) { |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1170 |
// The number of spaces is significant here, and should match the format |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1171 |
// specifiers in print_statistics(). |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1172 |
|
53895 | 1173 |
st->print("VM Operation " |
1174 |
"[ threads: total initial_running ]" |
|
1175 |
"[ time: sync cleanup vmop total ]"); |
|
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1176 |
|
53895 | 1177 |
st->print_cr(" page_trap_count"); |
1 | 1178 |
} |
1179 |
||
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1180 |
// This prints a nice table. To get the statistics to not shift due to the logging uptime |
53895 | 1181 |
// decorator, use the option as: -Xlog:safepoint+stats:[outputfile]:none |
1182 |
void SafepointTracing::statistics_log() { |
|
1183 |
LogTarget(Info, safepoint, stats) lt; |
|
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1184 |
assert (lt.is_enabled(), "should only be called when printing statistics is enabled"); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1185 |
LogStream ls(lt); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1186 |
|
53895 | 1187 |
static int _cur_stat_index = 0; |
1188 |
||
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1189 |
// Print header every 30 entries |
53895 | 1190 |
if ((_cur_stat_index % 30) == 0) { |
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1191 |
print_header(&ls); |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1192 |
_cur_stat_index = 1; // wrap |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1193 |
} else { |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1194 |
_cur_stat_index++; |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1195 |
} |
1 | 1196 |
|
53895 | 1197 |
ls.print("%-28s [ " |
1198 |
INT32_FORMAT_W(8) " " INT32_FORMAT_W(8) " " |
|
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1199 |
"]", |
53895 | 1200 |
VM_Operation::name(_current_type), |
1201 |
_nof_threads, |
|
1202 |
_nof_running); |
|
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1203 |
ls.print("[ " |
53895 | 1204 |
INT64_FORMAT_W(10) " " INT64_FORMAT_W(10) " " |
1205 |
INT64_FORMAT_W(10) " " INT64_FORMAT_W(10) " ]", |
|
1206 |
(int64_t)(_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns), |
|
1207 |
(int64_t)(_last_safepoint_cleanup_time_ns - _last_safepoint_sync_time_ns), |
|
1208 |
(int64_t)(_last_safepoint_end_time_ns - _last_safepoint_cleanup_time_ns), |
|
1209 |
(int64_t)(_last_safepoint_end_time_ns - _last_safepoint_begin_time_ns)); |
|
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1210 |
|
53895 | 1211 |
ls.print_cr(INT32_FORMAT_W(16), _page_trap); |
1 | 1212 |
} |
1213 |
||
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1214 |
// This method will be called when VM exits. This tries to summarize the sampling. |
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
50921
diff
changeset
|
1215 |
// Current thread may already be deleted, so don't use ResourceMark. |
53895 | 1216 |
void SafepointTracing::statistics_exit_log() { |
1217 |
if (!log_is_enabled(Info, safepoint, stats)) { |
|
1218 |
return; |
|
1219 |
} |
|
1 | 1220 |
for (int index = 0; index < VM_Operation::VMOp_Terminating; index++) { |
53895 | 1221 |
if (_op_count[index] != 0) { |
1222 |
log_info(safepoint, stats)("%-28s" UINT64_FORMAT_W(10), VM_Operation::name(index), |
|
1223 |
_op_count[index]); |
|
1 | 1224 |
} |
1225 |
} |
|
1226 |
||
53895 | 1227 |
log_info(safepoint, stats)("VM operations coalesced during safepoint " INT64_FORMAT, |
1228 |
VMThread::get_coalesced_count()); |
|
1229 |
log_info(safepoint, stats)("Maximum sync time " INT64_FORMAT" ns", |
|
1230 |
(int64_t)(_max_sync_time)); |
|
1231 |
log_info(safepoint, stats)("Maximum vm operation time (except for Exit VM operation) " |
|
1232 |
INT64_FORMAT " ns", |
|
1233 |
(int64_t)(_max_vmop_time)); |
|
1234 |
} |
|
1235 |
||
1236 |
void SafepointTracing::begin(VM_Operation::VMOp_Type type) { |
|
1237 |
_op_count[type]++; |
|
1238 |
_current_type = type; |
|
1239 |
||
1240 |
// update the time stamp to begin recording safepoint time |
|
1241 |
_last_safepoint_begin_time_ns = os::javaTimeNanos(); |
|
1242 |
_last_safepoint_sync_time_ns = 0; |
|
1243 |
_last_safepoint_cleanup_time_ns = 0; |
|
1244 |
||
1245 |
_last_app_time_ns = _last_safepoint_begin_time_ns - _last_safepoint_end_time_ns; |
|
1246 |
_last_safepoint_end_time_ns = 0; |
|
1247 |
||
1248 |
RuntimeService::record_safepoint_begin(_last_app_time_ns); |
|
1249 |
} |
|
1250 |
||
1251 |
void SafepointTracing::synchronized(int nof_threads, int nof_running, int traps) { |
|
1252 |
_last_safepoint_sync_time_ns = os::javaTimeNanos(); |
|
1253 |
_nof_threads = nof_threads; |
|
1254 |
_nof_running = nof_running; |
|
1255 |
_page_trap = traps; |
|
1256 |
RuntimeService::record_safepoint_synchronized(_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns); |
|
1 | 1257 |
} |
53895 | 1258 |
|
1259 |
void SafepointTracing::cleanup() { |
|
1260 |
_last_safepoint_cleanup_time_ns = os::javaTimeNanos(); |
|
1261 |
} |
|
1262 |
||
1263 |
void SafepointTracing::end() { |
|
1264 |
_last_safepoint_end_time_ns = os::javaTimeNanos(); |
|
54009
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
1265 |
// amount of time since epoch |
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
1266 |
_last_safepoint_end_time_epoch_ms = os::javaTimeMillis(); |
53895 | 1267 |
|
1268 |
if (_max_sync_time < (_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns)) { |
|
1269 |
_max_sync_time = _last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns; |
|
1270 |
} |
|
1271 |
if (_max_vmop_time < (_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns)) { |
|
1272 |
_max_vmop_time = _last_safepoint_end_time_ns - _last_safepoint_sync_time_ns; |
|
1273 |
} |
|
1274 |
if (log_is_enabled(Info, safepoint, stats)) { |
|
1275 |
statistics_log(); |
|
1276 |
} |
|
1277 |
||
1278 |
log_info(safepoint)( |
|
1279 |
"Safepoint \"%s\", " |
|
1280 |
"Time since last: " JLONG_FORMAT " ns, " |
|
1281 |
"Reaching safepoint: " JLONG_FORMAT " ns, " |
|
1282 |
"At safepoint: " JLONG_FORMAT " ns, " |
|
1283 |
"Total: " JLONG_FORMAT " ns", |
|
1284 |
VM_Operation::name(_current_type), |
|
1285 |
_last_app_time_ns, |
|
1286 |
_last_safepoint_cleanup_time_ns - _last_safepoint_begin_time_ns, |
|
1287 |
_last_safepoint_end_time_ns - _last_safepoint_cleanup_time_ns, |
|
1288 |
_last_safepoint_end_time_ns - _last_safepoint_begin_time_ns |
|
1289 |
); |
|
1290 |
||
1291 |
RuntimeService::record_safepoint_end(_last_safepoint_end_time_ns - _last_safepoint_cleanup_time_ns); |
|
1292 |
} |