Mercurial > hg > graal-jvmci-8
annotate src/share/vm/runtime/safepoint.hpp @ 1778:eeade8e89248
Merge
author | ysr |
---|---|
date | Sat, 11 Sep 2010 11:42:09 -0700 |
parents | da877bdc9000 |
children | d5d065957597 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1291
diff
changeset
|
2 * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1291
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1291
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1291
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 // | |
26 // Safepoint synchronization | |
27 //// | |
28 // The VMThread or CMS_thread uses the SafepointSynchronize::begin/end | |
29 // methods to enter/exit a safepoint region. The begin method will roll | |
30 // all JavaThreads forward to a safepoint. | |
31 // | |
32 // JavaThreads must use the ThreadSafepointState abstraction (defined in | |
33 // thread.hpp) to indicate that that they are at a safepoint. | |
34 // | |
35 // The Mutex/Condition variable and ObjectLocker classes calls the enter/ | |
36 // exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/ | |
37 // exit points *must* be at a safepoint. | |
38 | |
39 | |
40 class ThreadSafepointState; | |
41 class SnippetCache; | |
42 class nmethod; | |
43 | |
44 // | |
45 // Implements roll-forward to safepoint (safepoint synchronization) | |
46 // | |
47 class SafepointSynchronize : AllStatic { | |
48 public: | |
49 enum SynchronizeState { | |
50 _not_synchronized = 0, // Threads not synchronized at a safepoint | |
51 // Keep this value 0. See the coment in do_call_back() | |
52 _synchronizing = 1, // Synchronizing in progress | |
53 _synchronized = 2 // All Java threads are stopped at a safepoint. Only VM thread is running | |
54 }; | |
55 | |
56 enum SafepointingThread { | |
57 _null_thread = 0, | |
58 _vm_thread = 1, | |
59 _other_thread = 2 | |
60 }; | |
61 | |
62 enum SafepointTimeoutReason { | |
63 _spinning_timeout = 0, | |
64 _blocking_timeout = 1 | |
65 }; | |
66 | |
67 typedef struct { | |
1291
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
68 float _time_stamp; // record when the current safepoint occurs in seconds |
0 | 69 int _vmop_type; // type of VM operation triggers the safepoint |
70 int _nof_total_threads; // total number of Java threads | |
71 int _nof_initial_running_threads; // total number of initially seen running threads | |
72 int _nof_threads_wait_to_block; // total number of threads waiting for to block | |
73 bool _page_armed; // true if polling page is armed, false otherwise | |
74 int _nof_threads_hit_page_trap; // total number of threads hitting the page trap | |
75 jlong _time_to_spin; // total time in millis spent in spinning | |
76 jlong _time_to_wait_to_block; // total time in millis spent in waiting for to block | |
1291
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
77 jlong _time_to_do_cleanups; // total time in millis spent in performing cleanups |
0 | 78 jlong _time_to_sync; // total time in millis spent in getting to _synchronized |
79 jlong _time_to_exec_vmop; // total time in millis spent in vm operation itself | |
80 } SafepointStats; | |
81 | |
82 private: | |
83 static volatile SynchronizeState _state; // Threads might read this flag directly, without acquireing the Threads_lock | |
1291
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
84 static volatile int _waiting_to_block; // number of threads we are waiting for to block |
0 | 85 |
86 // This counter is used for fast versions of jni_Get<Primitive>Field. | |
87 // An even value means there is no ongoing safepoint operations. | |
88 // The counter is incremented ONLY at the beginning and end of each | |
89 // safepoint. The fact that Threads_lock is held throughout each pair of | |
90 // increments (at the beginning and end of each safepoint) guarantees | |
91 // race freedom. | |
92 public: | |
93 static volatile int _safepoint_counter; | |
94 private: | |
1291
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
95 static long _end_of_last_safepoint; // Time of last safepoint in milliseconds |
0 | 96 |
97 // statistics | |
1291
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
98 static jlong _safepoint_begin_time; // time when safepoint begins |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
99 static SafepointStats* _safepoint_stats; // array of SafepointStats struct |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
100 static int _cur_stat_index; // current index to the above array |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
101 static julong _safepoint_reasons[]; // safepoint count for each VM op |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
102 static julong _coalesced_vmop_count; // coalesced vmop count |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
103 static jlong _max_sync_time; // maximum sync time in nanos |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
104 static jlong _max_vmop_time; // maximum vm operation time in nanos |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
105 static float _ts_of_current_safepoint; // time stamp of current safepoint in seconds |
0 | 106 |
107 static void begin_statistics(int nof_threads, int nof_running); | |
108 static void update_statistics_on_spin_end(); | |
109 static void update_statistics_on_sync_end(jlong end_time); | |
1291
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
110 static void update_statistics_on_cleanup_end(jlong end_time); |
0 | 111 static void end_statistics(jlong end_time); |
112 static void print_statistics(); | |
113 inline static void inc_page_trap_count() { | |
114 Atomic::inc(&_safepoint_stats[_cur_stat_index]._nof_threads_hit_page_trap); | |
115 } | |
116 | |
117 // For debug long safepoint | |
118 static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason); | |
119 | |
120 public: | |
121 | |
122 // Main entry points | |
123 | |
124 // Roll all threads forward to safepoint. Must be called by the | |
125 // VMThread or CMS_thread. | |
126 static void begin(); | |
127 static void end(); // Start all suspended threads again... | |
128 | |
129 static bool safepoint_safe(JavaThread *thread, JavaThreadState state); | |
130 | |
131 // Query | |
132 inline static bool is_at_safepoint() { return _state == _synchronized; } | |
133 inline static bool is_synchronizing() { return _state == _synchronizing; } | |
134 | |
135 inline static bool do_call_back() { | |
136 return (_state != _not_synchronized); | |
137 } | |
138 | |
139 // Called when a thread volantary blocks | |
140 static void block(JavaThread *thread); | |
141 static void signal_thread_at_safepoint() { _waiting_to_block--; } | |
142 | |
143 // Exception handling for page polling | |
144 static void handle_polling_page_exception(JavaThread *thread); | |
145 | |
146 // VM Thread interface for determining safepoint rate | |
1291
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
147 static long last_non_safepoint_interval() { |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
148 return os::javaTimeMillis() - _end_of_last_safepoint; |
4b0f2f4918ed
6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents:
0
diff
changeset
|
149 } |
0 | 150 static bool is_cleanup_needed(); |
151 static void do_cleanup_tasks(); | |
152 | |
153 // debugging | |
154 static void print_state() PRODUCT_RETURN; | |
155 static void safepoint_msg(const char* format, ...) PRODUCT_RETURN; | |
156 | |
157 static void deferred_initialize_stat(); | |
158 static void print_stat_on_exit(); | |
159 inline static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; } | |
160 | |
161 static void set_is_at_safepoint() { _state = _synchronized; } | |
162 static void set_is_not_at_safepoint() { _state = _not_synchronized; } | |
163 | |
164 // assembly support | |
165 static address address_of_state() { return (address)&_state; } | |
166 | |
167 static address safepoint_counter_addr() { return (address)&_safepoint_counter; } | |
168 }; | |
169 | |
170 // State class for a thread suspended at a safepoint | |
171 class ThreadSafepointState: public CHeapObj { | |
172 public: | |
173 // These states are maintained by VM thread while threads are being brought | |
174 // to a safepoint. After SafepointSynchronize::end(), they are reset to | |
175 // _running. | |
176 enum suspend_type { | |
177 _running = 0, // Thread state not yet determined (i.e., not at a safepoint yet) | |
178 _at_safepoint = 1, // Thread at a safepoint (f.ex., when blocked on a lock) | |
179 _call_back = 2 // Keep executing and wait for callback (if thread is in interpreted or vm) | |
180 }; | |
181 private: | |
182 volatile bool _at_poll_safepoint; // At polling page safepoint (NOT a poll return safepoint) | |
183 // Thread has called back the safepoint code (for debugging) | |
184 bool _has_called_back; | |
185 | |
186 JavaThread * _thread; | |
187 volatile suspend_type _type; | |
1727
da877bdc9000
6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents:
1552
diff
changeset
|
188 JavaThreadState _orig_thread_state; |
0 | 189 |
190 | |
191 public: | |
192 ThreadSafepointState(JavaThread *thread); | |
193 | |
194 // examine/roll-forward/restart | |
195 void examine_state_of_thread(); | |
196 void roll_forward(suspend_type type); | |
197 void restart(); | |
198 | |
199 // Query | |
200 JavaThread* thread() const { return _thread; } | |
201 suspend_type type() const { return _type; } | |
202 bool is_running() const { return (_type==_running); } | |
1727
da877bdc9000
6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents:
1552
diff
changeset
|
203 JavaThreadState orig_thread_state() const { return _orig_thread_state; } |
0 | 204 |
205 // Support for safepoint timeout (debugging) | |
206 bool has_called_back() const { return _has_called_back; } | |
207 void set_has_called_back(bool val) { _has_called_back = val; } | |
208 bool is_at_poll_safepoint() { return _at_poll_safepoint; } | |
209 void set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; } | |
210 | |
211 void handle_polling_page_exception(); | |
212 | |
213 // debugging | |
214 void print_on(outputStream* st) const; | |
215 void print() const { print_on(tty); } | |
216 | |
217 // Initialize | |
218 static void create(JavaThread *thread); | |
219 static void destroy(JavaThread *thread); | |
220 | |
221 void safepoint_msg(const char* format, ...) { | |
222 if (ShowSafepointMsgs) { | |
223 va_list ap; | |
224 va_start(ap, format); | |
225 tty->vprint_cr(format, ap); | |
226 va_end(ap); | |
227 } | |
228 } | |
229 }; | |
230 | |
231 // | |
232 // CounterDecay | |
233 // | |
234 // Interates through invocation counters and decrements them. This | |
235 // is done at each safepoint. | |
236 // | |
237 class CounterDecay : public AllStatic { | |
238 static jlong _last_timestamp; | |
239 public: | |
240 static void decay(); | |
241 static bool is_decay_needed() { return (os::javaTimeMillis() - _last_timestamp) > CounterDecayMinIntervalLength; } | |
242 }; |