author | rehn |
Wed, 06 Mar 2019 11:15:16 +0100 | |
changeset 54009 | 13acb4339895 |
parent 53895 | b22d8ae270a2 |
child 54807 | 33fe50b6d707 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52673
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5042
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5042
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:
5042
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52673
diff
changeset
|
25 |
#ifndef SHARE_RUNTIME_SAFEPOINT_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52673
diff
changeset
|
26 |
#define SHARE_RUNTIME_SAFEPOINT_HPP |
7397 | 27 |
|
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "runtime/os.hpp" |
|
53775 | 30 |
#include "runtime/thread.hpp" |
53895 | 31 |
#include "runtime/vmOperations.hpp" |
7397 | 32 |
#include "utilities/ostream.hpp" |
53775 | 33 |
#include "utilities/waitBarrier.hpp" |
7397 | 34 |
|
1 | 35 |
// |
36 |
// Safepoint synchronization |
|
37 |
//// |
|
53775 | 38 |
// The VMThread uses the SafepointSynchronize::begin/end |
1 | 39 |
// methods to enter/exit a safepoint region. The begin method will roll |
40 |
// all JavaThreads forward to a safepoint. |
|
41 |
// |
|
42 |
// JavaThreads must use the ThreadSafepointState abstraction (defined in |
|
43 |
// thread.hpp) to indicate that that they are at a safepoint. |
|
44 |
// |
|
45 |
// The Mutex/Condition variable and ObjectLocker classes calls the enter/ |
|
46 |
// exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/ |
|
47 |
// exit points *must* be at a safepoint. |
|
48 |
||
49 |
class ThreadSafepointState; |
|
50 |
||
51 |
// |
|
52 |
// Implements roll-forward to safepoint (safepoint synchronization) |
|
53 |
// |
|
54 |
class SafepointSynchronize : AllStatic { |
|
55 |
public: |
|
56 |
enum SynchronizeState { |
|
53775 | 57 |
_not_synchronized = 0, // Threads not synchronized at a safepoint. Keep this value 0. |
1 | 58 |
_synchronizing = 1, // Synchronizing in progress |
53775 | 59 |
_synchronized = 2 // All Java threads are running in native, blocked in OS or stopped at safepoint. |
60 |
// VM thread and any NonJavaThread may be running. |
|
1 | 61 |
}; |
62 |
||
46702 | 63 |
// The enums are listed in the order of the tasks when done serially. |
64 |
enum SafepointCleanupTasks { |
|
65 |
SAFEPOINT_CLEANUP_DEFLATE_MONITORS, |
|
66 |
SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES, |
|
67 |
SAFEPOINT_CLEANUP_COMPILATION_POLICY, |
|
68 |
SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH, |
|
69 |
SAFEPOINT_CLEANUP_STRING_TABLE_REHASH, |
|
70 |
SAFEPOINT_CLEANUP_CLD_PURGE, |
|
47774 | 71 |
SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE, |
46702 | 72 |
// Leave this one last. |
73 |
SAFEPOINT_CLEANUP_NUM_TASKS |
|
74 |
}; |
|
75 |
||
1 | 76 |
private: |
53775 | 77 |
friend class SafepointMechanism; |
78 |
friend class ThreadSafepointState; |
|
79 |
friend class HandshakeState; |
|
80 |
||
81 |
// Threads might read this flag directly, without acquiring the Threads_lock: |
|
82 |
static volatile SynchronizeState _state; |
|
83 |
// Number of threads we are waiting for to block: |
|
84 |
static int _waiting_to_block; |
|
85 |
// Counts the number of active critical natives during the safepoint: |
|
86 |
static int _current_jni_active_count; |
|
1 | 87 |
|
88 |
// This counter is used for fast versions of jni_Get<Primitive>Field. |
|
53775 | 89 |
// An even value means there are no ongoing safepoint operations. |
1 | 90 |
// The counter is incremented ONLY at the beginning and end of each |
53775 | 91 |
// safepoint. |
52672
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
92 |
static volatile uint64_t _safepoint_counter; |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
93 |
|
53775 | 94 |
// JavaThreads that need to block for the safepoint will stop on the |
95 |
// _wait_barrier, where they can quickly be started again. |
|
96 |
static WaitBarrier* _wait_barrier; |
|
97 |
static long _end_of_last_safepoint; // Time of last safepoint in milliseconds |
|
98 |
static julong _coalesced_vmop_count; // coalesced vmop count |
|
1 | 99 |
|
22551 | 100 |
// Statistics |
1 | 101 |
static void begin_statistics(int nof_threads, int nof_running); |
102 |
static void update_statistics_on_spin_end(); |
|
103 |
static void update_statistics_on_sync_end(jlong end_time); |
|
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
104 |
static void update_statistics_on_cleanup_end(jlong end_time); |
1 | 105 |
static void end_statistics(jlong end_time); |
106 |
static void print_statistics(); |
|
107 |
||
108 |
// For debug long safepoint |
|
53895 | 109 |
static void print_safepoint_timeout(); |
1 | 110 |
|
53775 | 111 |
// Helper methods for safepoint procedure: |
112 |
static void arm_safepoint(); |
|
113 |
static int synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running); |
|
114 |
static void disarm_safepoint(); |
|
115 |
static void increment_jni_active_count(); |
|
116 |
static void decrement_waiting_to_block(); |
|
117 |
||
118 |
// Used in safepoint_safe to do a stable load of the thread state. |
|
119 |
static bool try_stable_load_state(JavaThreadState *state, |
|
120 |
JavaThread *thread, |
|
121 |
uint64_t safepoint_count); |
|
122 |
||
123 |
// Called when a thread voluntarily blocks |
|
124 |
static void block(JavaThread *thread); |
|
125 |
||
126 |
// Called from VMThread during handshakes. |
|
127 |
// If true the VMThread may safely process the handshake operation for the JavaThread. |
|
128 |
static bool handshake_safe(JavaThread *thread); |
|
129 |
||
1 | 130 |
public: |
131 |
||
53775 | 132 |
static void init(Thread* vmthread); |
1 | 133 |
|
53775 | 134 |
// Roll all threads forward to safepoint. Must be called by the VMThread. |
1 | 135 |
static void begin(); |
136 |
static void end(); // Start all suspended threads again... |
|
137 |
||
53775 | 138 |
// The value for a not set safepoint id. |
139 |
static const uint64_t InactiveSafepointCounter; |
|
11637
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
140 |
|
1 | 141 |
// Query |
53775 | 142 |
static bool is_at_safepoint() { return _state == _synchronized; } |
143 |
static bool is_synchronizing() { return _state == _synchronizing; } |
|
144 |
static uint64_t safepoint_counter() { return _safepoint_counter; } |
|
145 |
static bool is_same_safepoint(uint64_t counter) { return (SafepointSynchronize::safepoint_counter() - counter) < 2; } |
|
1 | 146 |
// Exception handling for page polling |
147 |
static void handle_polling_page_exception(JavaThread *thread); |
|
148 |
||
149 |
static bool is_cleanup_needed(); |
|
150 |
static void do_cleanup_tasks(); |
|
151 |
||
53775 | 152 |
static void set_is_at_safepoint() { _state = _synchronized; } |
153 |
static void set_is_not_at_safepoint() { _state = _not_synchronized; } |
|
1 | 154 |
|
22551 | 155 |
// Assembly support |
53775 | 156 |
static address address_of_state() { return (address)&_state; } |
1 | 157 |
|
52672
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
158 |
// Only used for making sure that no safepoint has happened in |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
159 |
// JNI_FastGetField. Therefore only the low 32-bits are needed |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
160 |
// even if this is a 64-bit counter. |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
161 |
static address safepoint_counter_addr() { |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
162 |
#ifdef VM_LITTLE_ENDIAN |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
163 |
return (address)&_safepoint_counter; |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
164 |
#else /* BIG */ |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
165 |
// Return pointer to the 32 LSB: |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
166 |
return (address) (((uint32_t*)(&_safepoint_counter)) + 1); |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
167 |
#endif |
bbfa1b3aaf7e
8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents:
52518
diff
changeset
|
168 |
} |
1 | 169 |
}; |
170 |
||
49333
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
171 |
// Some helper assert macros for safepoint checks. |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
172 |
|
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
173 |
#define assert_at_safepoint() \ |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
174 |
assert(SafepointSynchronize::is_at_safepoint(), "should be at a safepoint") |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
175 |
|
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
176 |
#define assert_at_safepoint_msg(...) \ |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
177 |
assert(SafepointSynchronize::is_at_safepoint(), __VA_ARGS__) |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
178 |
|
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
179 |
#define assert_not_at_safepoint() \ |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
180 |
assert(!SafepointSynchronize::is_at_safepoint(), "should not be at a safepoint") |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
181 |
|
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
182 |
#define assert_not_at_safepoint_msg(...) \ |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
183 |
assert(!SafepointSynchronize::is_at_safepoint(), __VA_ARGS__) |
489f1dd40582
8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents:
49169
diff
changeset
|
184 |
|
1 | 185 |
// State class for a thread suspended at a safepoint |
53847
74b616640b00
8219244: NMT: Change ThreadSafepointState's allocation type from mtInternal to mtThread
zgu
parents:
53775
diff
changeset
|
186 |
class ThreadSafepointState: public CHeapObj<mtThread> { |
1 | 187 |
private: |
53775 | 188 |
// At polling page safepoint (NOT a poll return safepoint): |
189 |
volatile bool _at_poll_safepoint; |
|
190 |
JavaThread* _thread; |
|
191 |
bool _safepoint_safe; |
|
192 |
volatile uint64_t _safepoint_id; |
|
193 |
JavaThreadState _orig_thread_state; |
|
1 | 194 |
|
53775 | 195 |
ThreadSafepointState* _next; |
1 | 196 |
|
53775 | 197 |
void account_safe_thread(); |
1 | 198 |
|
199 |
public: |
|
200 |
ThreadSafepointState(JavaThread *thread); |
|
201 |
||
53775 | 202 |
// Linked list support: |
203 |
ThreadSafepointState* get_next() const { return _next; } |
|
204 |
void set_next(ThreadSafepointState* value) { _next = value; } |
|
205 |
ThreadSafepointState** next_ptr() { return &_next; } |
|
206 |
||
207 |
// examine/restart |
|
208 |
void examine_state_of_thread(uint64_t safepoint_count); |
|
1 | 209 |
void restart(); |
210 |
||
211 |
// Query |
|
212 |
JavaThread* thread() const { return _thread; } |
|
53775 | 213 |
bool is_running() const { return !_safepoint_safe; } |
214 |
||
215 |
uint64_t get_safepoint_id() const; |
|
216 |
void reset_safepoint_id(); |
|
217 |
void set_safepoint_id(uint64_t sid); |
|
218 |
||
6269
10e06287c0b0
6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents:
5547
diff
changeset
|
219 |
JavaThreadState orig_thread_state() const { return _orig_thread_state; } |
1 | 220 |
|
221 |
// Support for safepoint timeout (debugging) |
|
53775 | 222 |
bool is_at_poll_safepoint() { return _at_poll_safepoint; } |
223 |
void set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; } |
|
1 | 224 |
|
225 |
void handle_polling_page_exception(); |
|
226 |
||
227 |
// debugging |
|
228 |
void print_on(outputStream* st) const; |
|
229 |
void print() const { print_on(tty); } |
|
230 |
||
231 |
// Initialize |
|
232 |
static void create(JavaThread *thread); |
|
233 |
static void destroy(JavaThread *thread); |
|
234 |
}; |
|
235 |
||
53895 | 236 |
class SafepointTracing : public AllStatic { |
237 |
private: |
|
238 |
// Absolute |
|
239 |
static jlong _last_safepoint_begin_time_ns; |
|
240 |
static jlong _last_safepoint_sync_time_ns; |
|
241 |
static jlong _last_safepoint_cleanup_time_ns; |
|
242 |
static jlong _last_safepoint_end_time_ns; |
|
54009
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
243 |
// amount of ms since epoch |
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
244 |
static jlong _last_safepoint_end_time_epoch_ms; |
53895 | 245 |
// Relative |
246 |
static jlong _last_app_time_ns; |
|
6453 | 247 |
|
53895 | 248 |
static int _nof_threads; |
249 |
static int _nof_running; |
|
250 |
static int _page_trap; |
|
251 |
||
252 |
static VM_Operation::VMOp_Type _current_type; |
|
253 |
static jlong _max_sync_time; |
|
254 |
static jlong _max_vmop_time; |
|
255 |
static uint64_t _op_count[VM_Operation::VMOp_Terminating]; |
|
256 |
||
257 |
static void statistics_log(); |
|
258 |
||
259 |
public: |
|
260 |
static void init(); |
|
261 |
||
262 |
static void begin(VM_Operation::VMOp_Type type); |
|
263 |
static void synchronized(int nof_threads, int nof_running, int traps); |
|
264 |
static void cleanup(); |
|
265 |
static void end(); |
|
266 |
||
267 |
static void statistics_exit_log(); |
|
268 |
||
269 |
static jlong time_since_last_safepoint_ms() { |
|
270 |
return (os::javaTimeNanos() - _last_safepoint_end_time_ns) / (NANOUNITS / MILLIUNITS); |
|
271 |
} |
|
272 |
||
54009
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
273 |
static jlong end_of_last_safepoint_epoch_ms() { |
13acb4339895
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents:
53895
diff
changeset
|
274 |
return _last_safepoint_end_time_epoch_ms; |
53895 | 275 |
} |
276 |
||
277 |
static jlong start_of_safepoint() { |
|
278 |
return _last_safepoint_begin_time_ns; |
|
279 |
} |
|
280 |
}; |
|
7397 | 281 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52673
diff
changeset
|
282 |
#endif // SHARE_RUNTIME_SAFEPOINT_HPP |