author | pliden |
Wed, 13 May 2015 15:16:06 +0200 | |
changeset 30764 | fec48bf5a827 |
parent 29464 | hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.cpp@02c245ad3ec9 |
child 32623 | 390a27af5657 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
29326 | 2 |
* Copyright (c) 2001, 2015, 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:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
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:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
30764 | 27 |
#include "gc/cms/concurrentMarkSweepGeneration.inline.hpp" |
28 |
#include "gc/cms/concurrentMarkSweepThread.hpp" |
|
29 |
#include "gc/shared/genCollectedHeap.hpp" |
|
7397 | 30 |
#include "oops/instanceRefKlass.hpp" |
31 |
#include "oops/oop.inline.hpp" |
|
32 |
#include "runtime/init.hpp" |
|
33 |
#include "runtime/interfaceSupport.hpp" |
|
34 |
#include "runtime/java.hpp" |
|
35 |
#include "runtime/javaCalls.hpp" |
|
36 |
#include "runtime/mutexLocker.hpp" |
|
37 |
#include "runtime/os.hpp" |
|
38 |
#include "runtime/vmThread.hpp" |
|
1 | 39 |
|
40 |
// ======= Concurrent Mark Sweep Thread ======== |
|
41 |
||
42 |
// The CMS thread is created when Concurrent Mark Sweep is used in the |
|
43 |
// older of two generations in a generational memory system. |
|
44 |
||
45 |
ConcurrentMarkSweepThread* |
|
46 |
ConcurrentMarkSweepThread::_cmst = NULL; |
|
47 |
CMSCollector* ConcurrentMarkSweepThread::_collector = NULL; |
|
48 |
bool ConcurrentMarkSweepThread::_should_terminate = false; |
|
49 |
int ConcurrentMarkSweepThread::_CMS_flag = CMS_nil; |
|
50 |
||
51 |
volatile jint ConcurrentMarkSweepThread::_pending_yields = 0; |
|
52 |
||
53 |
SurrogateLockerThread* |
|
54 |
ConcurrentMarkSweepThread::_slt = NULL; |
|
55 |
SurrogateLockerThread::SLT_msg_type |
|
56 |
ConcurrentMarkSweepThread::_sltBuffer = SurrogateLockerThread::empty; |
|
57 |
Monitor* |
|
58 |
ConcurrentMarkSweepThread::_sltMonitor = NULL; |
|
59 |
||
60 |
ConcurrentMarkSweepThread::ConcurrentMarkSweepThread(CMSCollector* collector) |
|
61 |
: ConcurrentGCThread() { |
|
62 |
assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set"); |
|
63 |
assert(_cmst == NULL, "CMS thread already created"); |
|
64 |
_cmst = this; |
|
65 |
assert(_collector == NULL, "Collector already set"); |
|
66 |
_collector = collector; |
|
67 |
||
29464
02c245ad3ec9
8073545: Use shorter and more descriptive names for GC worker threads
david
parents:
29326
diff
changeset
|
68 |
set_name("CMS Main Thread"); |
1 | 69 |
|
70 |
if (os::create_thread(this, os::cgc_thread)) { |
|
11601
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
71 |
// An old comment here said: "Priority should be just less |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
72 |
// than that of VMThread". Since the VMThread runs at |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
73 |
// NearMaxPriority, the old comment was inaccurate, but |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
74 |
// changing the default priority to NearMaxPriority-1 |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
75 |
// could change current behavior, so the default of |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
76 |
// NearMaxPriority stays in place. |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
77 |
// |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
78 |
// Note that there's a possibility of the VMThread |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
79 |
// starving if UseCriticalCMSThreadPriority is on. |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
80 |
// That won't happen on Solaris for various reasons, |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
81 |
// but may well happen on non-Solaris platforms. |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
82 |
int native_prio; |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
83 |
if (UseCriticalCMSThreadPriority) { |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
84 |
native_prio = os::java_to_os_priority[CriticalPriority]; |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
85 |
} else { |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
86 |
native_prio = os::java_to_os_priority[NearMaxPriority]; |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
87 |
} |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
88 |
os::set_native_priority(this, native_prio); |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
8684
diff
changeset
|
89 |
|
1 | 90 |
if (!DisableStartThread) { |
91 |
os::start_thread(this); |
|
92 |
} |
|
93 |
} |
|
94 |
_sltMonitor = SLT_lock; |
|
95 |
} |
|
96 |
||
97 |
void ConcurrentMarkSweepThread::run() { |
|
98 |
assert(this == cmst(), "just checking"); |
|
99 |
||
29326 | 100 |
initialize_in_thread(); |
1 | 101 |
// From this time Thread::current() should be working. |
102 |
assert(this == Thread::current(), "just checking"); |
|
103 |
if (BindCMSThreadToCPU && !os::bind_to_processor(CPUForCMSThread)) { |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24331
diff
changeset
|
104 |
warning("Couldn't bind CMS thread to processor " UINTX_FORMAT, CPUForCMSThread); |
1 | 105 |
} |
106 |
// Wait until Universe::is_fully_initialized() |
|
107 |
{ |
|
108 |
CMSLoopCountWarn loopX("CMS::run", "waiting for " |
|
109 |
"Universe::is_fully_initialized()", 2); |
|
110 |
MutexLockerEx x(CGC_lock, true); |
|
111 |
set_CMS_flag(CMS_cms_wants_token); |
|
112 |
// Wait until Universe is initialized and all initialization is completed. |
|
113 |
while (!is_init_completed() && !Universe::is_fully_initialized() && |
|
114 |
!_should_terminate) { |
|
115 |
CGC_lock->wait(true, 200); |
|
116 |
loopX.tick(); |
|
117 |
} |
|
118 |
// Wait until the surrogate locker thread that will do |
|
119 |
// pending list locking on our behalf has been created. |
|
120 |
// We cannot start the SLT thread ourselves since we need |
|
121 |
// to be a JavaThread to do so. |
|
122 |
CMSLoopCountWarn loopY("CMS::run", "waiting for SLT installation", 2); |
|
123 |
while (_slt == NULL && !_should_terminate) { |
|
124 |
CGC_lock->wait(true, 200); |
|
125 |
loopY.tick(); |
|
126 |
} |
|
127 |
clear_CMS_flag(CMS_cms_wants_token); |
|
128 |
} |
|
129 |
||
130 |
while (!_should_terminate) { |
|
131 |
sleepBeforeNextCycle(); |
|
132 |
if (_should_terminate) break; |
|
18025 | 133 |
GCCause::Cause cause = _collector->_full_gc_requested ? |
134 |
_collector->_full_gc_cause : GCCause::_cms_concurrent_mark; |
|
27686 | 135 |
_collector->collect_in_background(cause); |
1 | 136 |
} |
137 |
assert(_should_terminate, "just checking"); |
|
138 |
// Check that the state of any protocol for synchronization |
|
139 |
// between background (CMS) and foreground collector is "clean" |
|
140 |
// (i.e. will not potentially block the foreground collector, |
|
141 |
// requiring action by us). |
|
142 |
verify_ok_to_terminate(); |
|
143 |
// Signal that it is terminated |
|
144 |
{ |
|
145 |
MutexLockerEx mu(Terminator_lock, |
|
146 |
Mutex::_no_safepoint_check_flag); |
|
147 |
assert(_cmst == this, "Weird!"); |
|
148 |
_cmst = NULL; |
|
149 |
Terminator_lock->notify(); |
|
150 |
} |
|
151 |
||
152 |
// Thread destructor usually does this.. |
|
153 |
ThreadLocalStorage::set_thread(NULL); |
|
154 |
} |
|
155 |
||
156 |
#ifndef PRODUCT |
|
157 |
void ConcurrentMarkSweepThread::verify_ok_to_terminate() const { |
|
158 |
assert(!(CGC_lock->owned_by_self() || cms_thread_has_cms_token() || |
|
159 |
cms_thread_wants_cms_token()), |
|
160 |
"Must renounce all worldly possessions and desires for nirvana"); |
|
161 |
_collector->verify_ok_to_terminate(); |
|
162 |
} |
|
163 |
#endif |
|
164 |
||
165 |
// create and start a new ConcurrentMarkSweep Thread for given CMS generation |
|
166 |
ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::start(CMSCollector* collector) { |
|
167 |
if (!_should_terminate) { |
|
168 |
assert(cmst() == NULL, "start() called twice?"); |
|
169 |
ConcurrentMarkSweepThread* th = new ConcurrentMarkSweepThread(collector); |
|
170 |
assert(cmst() == th, "Where did the just-created CMS thread go?"); |
|
171 |
return th; |
|
172 |
} |
|
173 |
return NULL; |
|
174 |
} |
|
175 |
||
176 |
void ConcurrentMarkSweepThread::stop() { |
|
177 |
// it is ok to take late safepoints here, if needed |
|
178 |
{ |
|
179 |
MutexLockerEx x(Terminator_lock); |
|
180 |
_should_terminate = true; |
|
181 |
} |
|
182 |
{ // Now post a notify on CGC_lock so as to nudge |
|
183 |
// CMS thread(s) that might be slumbering in |
|
184 |
// sleepBeforeNextCycle. |
|
185 |
MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
|
186 |
CGC_lock->notify_all(); |
|
187 |
} |
|
188 |
{ // Now wait until (all) CMS thread(s) have exited |
|
189 |
MutexLockerEx x(Terminator_lock); |
|
190 |
while(cmst() != NULL) { |
|
191 |
Terminator_lock->wait(); |
|
192 |
} |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
void ConcurrentMarkSweepThread::threads_do(ThreadClosure* tc) { |
|
197 |
assert(tc != NULL, "Null ThreadClosure"); |
|
198 |
if (_cmst != NULL) { |
|
199 |
tc->do_thread(_cmst); |
|
200 |
} |
|
201 |
assert(Universe::is_fully_initialized(), |
|
202 |
"Called too early, make sure heap is fully initialized"); |
|
203 |
if (_collector != NULL) { |
|
204 |
AbstractWorkGang* gang = _collector->conc_workers(); |
|
205 |
if (gang != NULL) { |
|
206 |
gang->threads_do(tc); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
void ConcurrentMarkSweepThread::print_all_on(outputStream* st) { |
|
212 |
if (_cmst != NULL) { |
|
213 |
_cmst->print_on(st); |
|
13857 | 214 |
st->cr(); |
1 | 215 |
} |
216 |
if (_collector != NULL) { |
|
217 |
AbstractWorkGang* gang = _collector->conc_workers(); |
|
218 |
if (gang != NULL) { |
|
219 |
gang->print_worker_threads_on(st); |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
void ConcurrentMarkSweepThread::synchronize(bool is_cms_thread) { |
|
225 |
assert(UseConcMarkSweepGC, "just checking"); |
|
226 |
||
227 |
MutexLockerEx x(CGC_lock, |
|
228 |
Mutex::_no_safepoint_check_flag); |
|
229 |
if (!is_cms_thread) { |
|
230 |
assert(Thread::current()->is_VM_thread(), "Not a VM thread"); |
|
231 |
CMSSynchronousYieldRequest yr; |
|
232 |
while (CMS_flag_is_set(CMS_cms_has_token)) { |
|
233 |
// indicate that we want to get the token |
|
234 |
set_CMS_flag(CMS_vm_wants_token); |
|
235 |
CGC_lock->wait(true); |
|
236 |
} |
|
237 |
// claim the token and proceed |
|
238 |
clear_CMS_flag(CMS_vm_wants_token); |
|
239 |
set_CMS_flag(CMS_vm_has_token); |
|
240 |
} else { |
|
241 |
assert(Thread::current()->is_ConcurrentGC_thread(), |
|
242 |
"Not a CMS thread"); |
|
243 |
// The following barrier assumes there's only one CMS thread. |
|
244 |
// This will need to be modified is there are more CMS threads than one. |
|
245 |
while (CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token)) { |
|
246 |
set_CMS_flag(CMS_cms_wants_token); |
|
247 |
CGC_lock->wait(true); |
|
248 |
} |
|
249 |
// claim the token |
|
250 |
clear_CMS_flag(CMS_cms_wants_token); |
|
251 |
set_CMS_flag(CMS_cms_has_token); |
|
252 |
} |
|
253 |
} |
|
254 |
||
255 |
void ConcurrentMarkSweepThread::desynchronize(bool is_cms_thread) { |
|
256 |
assert(UseConcMarkSweepGC, "just checking"); |
|
257 |
||
258 |
MutexLockerEx x(CGC_lock, |
|
259 |
Mutex::_no_safepoint_check_flag); |
|
260 |
if (!is_cms_thread) { |
|
261 |
assert(Thread::current()->is_VM_thread(), "Not a VM thread"); |
|
262 |
assert(CMS_flag_is_set(CMS_vm_has_token), "just checking"); |
|
263 |
clear_CMS_flag(CMS_vm_has_token); |
|
264 |
if (CMS_flag_is_set(CMS_cms_wants_token)) { |
|
265 |
// wake-up a waiting CMS thread |
|
266 |
CGC_lock->notify(); |
|
267 |
} |
|
268 |
assert(!CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token), |
|
269 |
"Should have been cleared"); |
|
270 |
} else { |
|
271 |
assert(Thread::current()->is_ConcurrentGC_thread(), |
|
272 |
"Not a CMS thread"); |
|
273 |
assert(CMS_flag_is_set(CMS_cms_has_token), "just checking"); |
|
274 |
clear_CMS_flag(CMS_cms_has_token); |
|
275 |
if (CMS_flag_is_set(CMS_vm_wants_token)) { |
|
276 |
// wake-up a waiting VM thread |
|
277 |
CGC_lock->notify(); |
|
278 |
} |
|
279 |
assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token), |
|
280 |
"Should have been cleared"); |
|
281 |
} |
|
282 |
} |
|
283 |
||
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
284 |
// Wait until any cms_lock event |
6984
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
285 |
void ConcurrentMarkSweepThread::wait_on_cms_lock(long t_millis) { |
1 | 286 |
MutexLockerEx x(CGC_lock, |
287 |
Mutex::_no_safepoint_check_flag); |
|
6984
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
288 |
if (_should_terminate || _collector->_full_gc_requested) { |
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
289 |
return; |
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
290 |
} |
1 | 291 |
set_CMS_flag(CMS_cms_wants_token); // to provoke notifies |
6984
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
292 |
CGC_lock->wait(Mutex::_no_safepoint_check_flag, t_millis); |
1 | 293 |
clear_CMS_flag(CMS_cms_wants_token); |
294 |
assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token), |
|
295 |
"Should not be set"); |
|
296 |
} |
|
297 |
||
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
298 |
// Wait until the next synchronous GC, a concurrent full gc request, |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
299 |
// or a timeout, whichever is earlier. |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
300 |
void ConcurrentMarkSweepThread::wait_on_cms_lock_for_scavenge(long t_millis) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
301 |
// Wait time in millis or 0 value representing infinite wait for a scavenge |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
302 |
assert(t_millis >= 0, "Wait time for scavenge should be 0 or positive"); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
303 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
304 |
GenCollectedHeap* gch = GenCollectedHeap::heap(); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
305 |
double start_time_secs = os::elapsedTime(); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
306 |
double end_time_secs = start_time_secs + (t_millis / ((double) MILLIUNITS)); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
307 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
308 |
// Total collections count before waiting loop |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
309 |
unsigned int before_count; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
310 |
{ |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
311 |
MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
312 |
before_count = gch->total_collections(); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
313 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
314 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
315 |
unsigned int loop_count = 0; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
316 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
317 |
while(!_should_terminate) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
318 |
double now_time = os::elapsedTime(); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
319 |
long wait_time_millis; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
320 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
321 |
if(t_millis != 0) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
322 |
// New wait limit |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
323 |
wait_time_millis = (long) ((end_time_secs - now_time) * MILLIUNITS); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
324 |
if(wait_time_millis <= 0) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
325 |
// Wait time is over |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
326 |
break; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
327 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
328 |
} else { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
329 |
// No wait limit, wait if necessary forever |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
330 |
wait_time_millis = 0; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
331 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
332 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
333 |
// Wait until the next event or the remaining timeout |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
334 |
{ |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
335 |
MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
336 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
337 |
if (_should_terminate || _collector->_full_gc_requested) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
338 |
return; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
339 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
340 |
set_CMS_flag(CMS_cms_wants_token); // to provoke notifies |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
341 |
assert(t_millis == 0 || wait_time_millis > 0, "Sanity"); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
342 |
CGC_lock->wait(Mutex::_no_safepoint_check_flag, wait_time_millis); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
343 |
clear_CMS_flag(CMS_cms_wants_token); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
344 |
assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token), |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
345 |
"Should not be set"); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
346 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
347 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
348 |
// Extra wait time check before entering the heap lock to get the collection count |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
349 |
if(t_millis != 0 && os::elapsedTime() >= end_time_secs) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
350 |
// Wait time is over |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
351 |
break; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
352 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
353 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
354 |
// Total collections count after the event |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
355 |
unsigned int after_count; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
356 |
{ |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
357 |
MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
358 |
after_count = gch->total_collections(); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
359 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
360 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
361 |
if(before_count != after_count) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
362 |
// There was a collection - success |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
363 |
break; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
364 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
365 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
366 |
// Too many loops warning |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
367 |
if(++loop_count == 0) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
368 |
warning("wait_on_cms_lock_for_scavenge() has looped %u times", loop_count - 1); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
369 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
370 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
371 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
372 |
|
1 | 373 |
void ConcurrentMarkSweepThread::sleepBeforeNextCycle() { |
374 |
while (!_should_terminate) { |
|
27625 | 375 |
if(CMSWaitDuration >= 0) { |
376 |
// Wait until the next synchronous GC, a concurrent full gc |
|
377 |
// request or a timeout, whichever is earlier. |
|
378 |
wait_on_cms_lock_for_scavenge(CMSWaitDuration); |
|
1 | 379 |
} else { |
27625 | 380 |
// Wait until any cms_lock event or check interval not to call shouldConcurrentCollect permanently |
381 |
wait_on_cms_lock(CMSCheckInterval); |
|
1 | 382 |
} |
383 |
// Check if we should start a CMS collection cycle |
|
384 |
if (_collector->shouldConcurrentCollect()) { |
|
385 |
return; |
|
386 |
} |
|
387 |
// .. collection criterion not yet met, let's go back |
|
388 |
// and wait some more |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
// Note: this method, although exported by the ConcurrentMarkSweepThread, |
|
393 |
// which is a non-JavaThread, can only be called by a JavaThread. |
|
394 |
// Currently this is done at vm creation time (post-vm-init) by the |
|
395 |
// main/Primordial (Java)Thread. |
|
396 |
// XXX Consider changing this in the future to allow the CMS thread |
|
397 |
// itself to create this thread? |
|
398 |
void ConcurrentMarkSweepThread::makeSurrogateLockerThread(TRAPS) { |
|
399 |
assert(UseConcMarkSweepGC, "SLT thread needed only for CMS GC"); |
|
400 |
assert(_slt == NULL, "SLT already created"); |
|
401 |
_slt = SurrogateLockerThread::make(THREAD); |
|
402 |
} |