author | hseigel |
Mon, 26 Feb 2018 11:28:05 -0500 | |
changeset 49169 | af8578e25d17 |
parent 49061 | a6b6a428c915 |
child 49333 | 489f1dd40582 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49061
a6b6a428c915
8198635: Remove unused safepoint message functions and ShowSafepointMsgs
coleenp
parents:
47881
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
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 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_SAFEPOINT_HPP |
26 |
#define SHARE_VM_RUNTIME_SAFEPOINT_HPP |
|
27 |
||
28 |
#include "asm/assembler.hpp" |
|
29 |
#include "code/nmethod.hpp" |
|
30 |
#include "memory/allocation.hpp" |
|
31 |
#include "runtime/extendedPC.hpp" |
|
11631
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
7397
diff
changeset
|
32 |
#include "runtime/mutexLocker.hpp" |
7397 | 33 |
#include "runtime/os.hpp" |
34 |
#include "utilities/ostream.hpp" |
|
35 |
||
1 | 36 |
// |
37 |
// Safepoint synchronization |
|
38 |
//// |
|
39 |
// The VMThread or CMS_thread uses the SafepointSynchronize::begin/end |
|
40 |
// methods to enter/exit a safepoint region. The begin method will roll |
|
41 |
// all JavaThreads forward to a safepoint. |
|
42 |
// |
|
43 |
// JavaThreads must use the ThreadSafepointState abstraction (defined in |
|
44 |
// thread.hpp) to indicate that that they are at a safepoint. |
|
45 |
// |
|
46 |
// The Mutex/Condition variable and ObjectLocker classes calls the enter/ |
|
47 |
// exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/ |
|
48 |
// exit points *must* be at a safepoint. |
|
49 |
||
50 |
||
51 |
class ThreadSafepointState; |
|
52 |
class SnippetCache; |
|
53 |
class nmethod; |
|
54 |
||
55 |
// |
|
56 |
// Implements roll-forward to safepoint (safepoint synchronization) |
|
57 |
// |
|
58 |
class SafepointSynchronize : AllStatic { |
|
59 |
public: |
|
60 |
enum SynchronizeState { |
|
61 |
_not_synchronized = 0, // Threads not synchronized at a safepoint |
|
22551 | 62 |
// Keep this value 0. See the comment in do_call_back() |
1 | 63 |
_synchronizing = 1, // Synchronizing in progress |
64 |
_synchronized = 2 // All Java threads are stopped at a safepoint. Only VM thread is running |
|
65 |
}; |
|
66 |
||
67 |
enum SafepointingThread { |
|
68 |
_null_thread = 0, |
|
69 |
_vm_thread = 1, |
|
70 |
_other_thread = 2 |
|
71 |
}; |
|
72 |
||
73 |
enum SafepointTimeoutReason { |
|
74 |
_spinning_timeout = 0, |
|
75 |
_blocking_timeout = 1 |
|
76 |
}; |
|
77 |
||
46702 | 78 |
// The enums are listed in the order of the tasks when done serially. |
79 |
enum SafepointCleanupTasks { |
|
80 |
SAFEPOINT_CLEANUP_DEFLATE_MONITORS, |
|
81 |
SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES, |
|
82 |
SAFEPOINT_CLEANUP_COMPILATION_POLICY, |
|
83 |
SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH, |
|
84 |
SAFEPOINT_CLEANUP_STRING_TABLE_REHASH, |
|
85 |
SAFEPOINT_CLEANUP_CLD_PURGE, |
|
47774 | 86 |
SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE, |
46702 | 87 |
// Leave this one last. |
88 |
SAFEPOINT_CLEANUP_NUM_TASKS |
|
89 |
}; |
|
90 |
||
1 | 91 |
typedef struct { |
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
92 |
float _time_stamp; // record when the current safepoint occurs in seconds |
1 | 93 |
int _vmop_type; // type of VM operation triggers the safepoint |
94 |
int _nof_total_threads; // total number of Java threads |
|
95 |
int _nof_initial_running_threads; // total number of initially seen running threads |
|
96 |
int _nof_threads_wait_to_block; // total number of threads waiting for to block |
|
97 |
int _nof_threads_hit_page_trap; // total number of threads hitting the page trap |
|
98 |
jlong _time_to_spin; // total time in millis spent in spinning |
|
99 |
jlong _time_to_wait_to_block; // total time in millis spent in waiting for to block |
|
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
100 |
jlong _time_to_do_cleanups; // total time in millis spent in performing cleanups |
1 | 101 |
jlong _time_to_sync; // total time in millis spent in getting to _synchronized |
102 |
jlong _time_to_exec_vmop; // total time in millis spent in vm operation itself |
|
103 |
} SafepointStats; |
|
104 |
||
105 |
private: |
|
22551 | 106 |
static volatile SynchronizeState _state; // Threads might read this flag directly, without acquiring the Threads_lock |
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
107 |
static volatile int _waiting_to_block; // number of threads we are waiting for to block |
11631
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
7397
diff
changeset
|
108 |
static int _current_jni_active_count; // Counts the number of active critical natives during the safepoint |
49169
af8578e25d17
8194085: Obsolete the deprecated SafepointSynchronize flags and remove related code
hseigel
parents:
49061
diff
changeset
|
109 |
static int _defer_thr_suspend_loop_count; // Iterations before blocking VM threads |
1 | 110 |
|
111 |
// This counter is used for fast versions of jni_Get<Primitive>Field. |
|
112 |
// An even value means there is no ongoing safepoint operations. |
|
113 |
// The counter is incremented ONLY at the beginning and end of each |
|
114 |
// safepoint. The fact that Threads_lock is held throughout each pair of |
|
115 |
// increments (at the beginning and end of each safepoint) guarantees |
|
116 |
// race freedom. |
|
117 |
public: |
|
118 |
static volatile int _safepoint_counter; |
|
119 |
private: |
|
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
120 |
static long _end_of_last_safepoint; // Time of last safepoint in milliseconds |
1 | 121 |
|
22551 | 122 |
// Statistics |
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
123 |
static jlong _safepoint_begin_time; // time when safepoint begins |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
124 |
static SafepointStats* _safepoint_stats; // array of SafepointStats struct |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
125 |
static int _cur_stat_index; // current index to the above array |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
126 |
static julong _safepoint_reasons[]; // safepoint count for each VM op |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
127 |
static julong _coalesced_vmop_count; // coalesced vmop count |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
128 |
static jlong _max_sync_time; // maximum sync time in nanos |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
129 |
static jlong _max_vmop_time; // maximum vm operation time in nanos |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
130 |
static float _ts_of_current_safepoint; // time stamp of current safepoint in seconds |
1 | 131 |
|
132 |
static void begin_statistics(int nof_threads, int nof_running); |
|
133 |
static void update_statistics_on_spin_end(); |
|
134 |
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
|
135 |
static void update_statistics_on_cleanup_end(jlong end_time); |
1 | 136 |
static void end_statistics(jlong end_time); |
137 |
static void print_statistics(); |
|
138 |
inline static void inc_page_trap_count() { |
|
139 |
Atomic::inc(&_safepoint_stats[_cur_stat_index]._nof_threads_hit_page_trap); |
|
140 |
} |
|
141 |
||
142 |
// For debug long safepoint |
|
143 |
static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason); |
|
144 |
||
145 |
public: |
|
146 |
||
147 |
// Main entry points |
|
148 |
||
149 |
// Roll all threads forward to safepoint. Must be called by the |
|
150 |
// VMThread or CMS_thread. |
|
151 |
static void begin(); |
|
152 |
static void end(); // Start all suspended threads again... |
|
153 |
||
154 |
static bool safepoint_safe(JavaThread *thread, JavaThreadState state); |
|
155 |
||
11637
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
156 |
static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state); |
030466036615
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
11631
diff
changeset
|
157 |
|
1 | 158 |
// Query |
159 |
inline static bool is_at_safepoint() { return _state == _synchronized; } |
|
160 |
inline static bool is_synchronizing() { return _state == _synchronizing; } |
|
37176
663bdc7d0b86
8149023: Event based tracing should cover safepoint begin and end
dsimms
parents:
24424
diff
changeset
|
161 |
inline static int safepoint_counter() { return _safepoint_counter; } |
1 | 162 |
|
11631
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
7397
diff
changeset
|
163 |
inline static void increment_jni_active_count() { |
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
7397
diff
changeset
|
164 |
assert_locked_or_safepoint(Safepoint_lock); |
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
7397
diff
changeset
|
165 |
_current_jni_active_count++; |
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
7397
diff
changeset
|
166 |
} |
33813f69207b
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents:
7397
diff
changeset
|
167 |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
168 |
private: |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
169 |
inline static bool do_call_back() { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
170 |
return (_state != _not_synchronized); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
171 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
172 |
|
22551 | 173 |
// Called when a thread voluntarily blocks |
1 | 174 |
static void block(JavaThread *thread); |
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
175 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
176 |
friend class SafepointMechanism; |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
177 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47774
diff
changeset
|
178 |
public: |
1 | 179 |
static void signal_thread_at_safepoint() { _waiting_to_block--; } |
180 |
||
181 |
// Exception handling for page polling |
|
182 |
static void handle_polling_page_exception(JavaThread *thread); |
|
183 |
||
184 |
// VM Thread interface for determining safepoint rate |
|
5042
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
185 |
static long last_non_safepoint_interval() { |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
186 |
return os::javaTimeMillis() - _end_of_last_safepoint; |
f86707fd195a
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
1
diff
changeset
|
187 |
} |
6453 | 188 |
static long end_of_last_safepoint() { |
189 |
return _end_of_last_safepoint; |
|
190 |
} |
|
1 | 191 |
static bool is_cleanup_needed(); |
192 |
static void do_cleanup_tasks(); |
|
193 |
||
194 |
static void deferred_initialize_stat(); |
|
195 |
static void print_stat_on_exit(); |
|
196 |
inline static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; } |
|
197 |
||
198 |
static void set_is_at_safepoint() { _state = _synchronized; } |
|
199 |
static void set_is_not_at_safepoint() { _state = _not_synchronized; } |
|
200 |
||
22551 | 201 |
// Assembly support |
1 | 202 |
static address address_of_state() { return (address)&_state; } |
203 |
||
204 |
static address safepoint_counter_addr() { return (address)&_safepoint_counter; } |
|
49169
af8578e25d17
8194085: Obsolete the deprecated SafepointSynchronize flags and remove related code
hseigel
parents:
49061
diff
changeset
|
205 |
|
af8578e25d17
8194085: Obsolete the deprecated SafepointSynchronize flags and remove related code
hseigel
parents:
49061
diff
changeset
|
206 |
// This method is only used for -Xconcurrentio support. |
af8578e25d17
8194085: Obsolete the deprecated SafepointSynchronize flags and remove related code
hseigel
parents:
49061
diff
changeset
|
207 |
static void set_defer_thr_suspend_loop_count() { |
af8578e25d17
8194085: Obsolete the deprecated SafepointSynchronize flags and remove related code
hseigel
parents:
49061
diff
changeset
|
208 |
_defer_thr_suspend_loop_count = 1; |
af8578e25d17
8194085: Obsolete the deprecated SafepointSynchronize flags and remove related code
hseigel
parents:
49061
diff
changeset
|
209 |
} |
1 | 210 |
}; |
211 |
||
212 |
// State class for a thread suspended at a safepoint |
|
13195 | 213 |
class ThreadSafepointState: public CHeapObj<mtInternal> { |
1 | 214 |
public: |
215 |
// These states are maintained by VM thread while threads are being brought |
|
216 |
// to a safepoint. After SafepointSynchronize::end(), they are reset to |
|
217 |
// _running. |
|
218 |
enum suspend_type { |
|
219 |
_running = 0, // Thread state not yet determined (i.e., not at a safepoint yet) |
|
220 |
_at_safepoint = 1, // Thread at a safepoint (f.ex., when blocked on a lock) |
|
221 |
_call_back = 2 // Keep executing and wait for callback (if thread is in interpreted or vm) |
|
222 |
}; |
|
223 |
private: |
|
224 |
volatile bool _at_poll_safepoint; // At polling page safepoint (NOT a poll return safepoint) |
|
225 |
// Thread has called back the safepoint code (for debugging) |
|
226 |
bool _has_called_back; |
|
227 |
||
228 |
JavaThread * _thread; |
|
229 |
volatile suspend_type _type; |
|
6269
10e06287c0b0
6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents:
5547
diff
changeset
|
230 |
JavaThreadState _orig_thread_state; |
1 | 231 |
|
232 |
||
233 |
public: |
|
234 |
ThreadSafepointState(JavaThread *thread); |
|
235 |
||
236 |
// examine/roll-forward/restart |
|
237 |
void examine_state_of_thread(); |
|
238 |
void roll_forward(suspend_type type); |
|
239 |
void restart(); |
|
240 |
||
241 |
// Query |
|
242 |
JavaThread* thread() const { return _thread; } |
|
243 |
suspend_type type() const { return _type; } |
|
244 |
bool is_running() const { return (_type==_running); } |
|
6269
10e06287c0b0
6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents:
5547
diff
changeset
|
245 |
JavaThreadState orig_thread_state() const { return _orig_thread_state; } |
1 | 246 |
|
247 |
// Support for safepoint timeout (debugging) |
|
248 |
bool has_called_back() const { return _has_called_back; } |
|
249 |
void set_has_called_back(bool val) { _has_called_back = val; } |
|
250 |
bool is_at_poll_safepoint() { return _at_poll_safepoint; } |
|
251 |
void set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; } |
|
252 |
||
253 |
void handle_polling_page_exception(); |
|
254 |
||
255 |
// debugging |
|
256 |
void print_on(outputStream* st) const; |
|
257 |
void print() const { print_on(tty); } |
|
258 |
||
259 |
// Initialize |
|
260 |
static void create(JavaThread *thread); |
|
261 |
static void destroy(JavaThread *thread); |
|
262 |
}; |
|
263 |
||
6453 | 264 |
|
7397 | 265 |
|
266 |
#endif // SHARE_VM_RUNTIME_SAFEPOINT_HPP |