author | ihse |
Tue, 13 Feb 2018 10:37:33 +0100 | |
branch | ihse-remove-mapfiles-branch |
changeset 56106 | 40e61db323c2 |
parent 47622 | 817f2a7019e4 |
child 49449 | ef5d5d343e2a |
permissions | -rw-r--r-- |
1 | 1 |
/* |
47622
817f2a7019e4
8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2001, 2017, 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" |
|
47622
817f2a7019e4
8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
47216
diff
changeset
|
27 |
#include "gc/cms/cmsHeap.hpp" |
30764 | 28 |
#include "gc/cms/concurrentMarkSweepGeneration.inline.hpp" |
29 |
#include "gc/cms/concurrentMarkSweepThread.hpp" |
|
33107
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
32623
diff
changeset
|
30 |
#include "gc/shared/gcId.hpp" |
7397 | 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 |
||
32623
390a27af5657
8134626: Misc cleanups after generation array removal
jwilhelm
parents:
30764
diff
changeset
|
42 |
ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::_cmst = NULL; |
390a27af5657
8134626: Misc cleanups after generation array removal
jwilhelm
parents:
30764
diff
changeset
|
43 |
CMSCollector* ConcurrentMarkSweepThread::_collector = NULL; |
390a27af5657
8134626: Misc cleanups after generation array removal
jwilhelm
parents:
30764
diff
changeset
|
44 |
int ConcurrentMarkSweepThread::_CMS_flag = CMS_nil; |
1 | 45 |
|
32623
390a27af5657
8134626: Misc cleanups after generation array removal
jwilhelm
parents:
30764
diff
changeset
|
46 |
volatile jint ConcurrentMarkSweepThread::_pending_yields = 0; |
1 | 47 |
|
48 |
ConcurrentMarkSweepThread::ConcurrentMarkSweepThread(CMSCollector* collector) |
|
49 |
: ConcurrentGCThread() { |
|
50 |
assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set"); |
|
51 |
assert(_cmst == NULL, "CMS thread already created"); |
|
52 |
_cmst = this; |
|
53 |
assert(_collector == NULL, "Collector already set"); |
|
54 |
_collector = collector; |
|
55 |
||
29464
02c245ad3ec9
8073545: Use shorter and more descriptive names for GC worker threads
david
parents:
29326
diff
changeset
|
56 |
set_name("CMS Main Thread"); |
1 | 57 |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
58 |
// An old comment here said: "Priority should be just less |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
59 |
// than that of VMThread". Since the VMThread runs at |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
60 |
// NearMaxPriority, the old comment was inaccurate, but |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
61 |
// changing the default priority to NearMaxPriority-1 |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
62 |
// could change current behavior, so the default of |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
63 |
// NearMaxPriority stays in place. |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
64 |
// |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
65 |
// Note that there's a possibility of the VMThread |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
66 |
// starving if UseCriticalCMSThreadPriority is on. |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
67 |
// That won't happen on Solaris for various reasons, |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
68 |
// but may well happen on non-Solaris platforms. |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
69 |
create_and_start(UseCriticalCMSThreadPriority ? CriticalPriority : NearMaxPriority); |
1 | 70 |
} |
71 |
||
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
72 |
void ConcurrentMarkSweepThread::run_service() { |
1 | 73 |
assert(this == cmst(), "just checking"); |
74 |
||
75 |
if (BindCMSThreadToCPU && !os::bind_to_processor(CPUForCMSThread)) { |
|
37073
c39d0903390b
8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents:
34633
diff
changeset
|
76 |
log_warning(gc)("Couldn't bind CMS thread to processor " UINTX_FORMAT, CPUForCMSThread); |
1 | 77 |
} |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
78 |
|
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
79 |
while (!should_terminate()) { |
1 | 80 |
sleepBeforeNextCycle(); |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
81 |
if (should_terminate()) break; |
33107
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
32623
diff
changeset
|
82 |
GCIdMark gc_id_mark; |
18025 | 83 |
GCCause::Cause cause = _collector->_full_gc_requested ? |
84 |
_collector->_full_gc_cause : GCCause::_cms_concurrent_mark; |
|
27686 | 85 |
_collector->collect_in_background(cause); |
1 | 86 |
} |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
87 |
|
1 | 88 |
// Check that the state of any protocol for synchronization |
89 |
// between background (CMS) and foreground collector is "clean" |
|
90 |
// (i.e. will not potentially block the foreground collector, |
|
91 |
// requiring action by us). |
|
92 |
verify_ok_to_terminate(); |
|
93 |
} |
|
94 |
||
95 |
#ifndef PRODUCT |
|
96 |
void ConcurrentMarkSweepThread::verify_ok_to_terminate() const { |
|
97 |
assert(!(CGC_lock->owned_by_self() || cms_thread_has_cms_token() || |
|
98 |
cms_thread_wants_cms_token()), |
|
99 |
"Must renounce all worldly possessions and desires for nirvana"); |
|
100 |
_collector->verify_ok_to_terminate(); |
|
101 |
} |
|
102 |
#endif |
|
103 |
||
104 |
// create and start a new ConcurrentMarkSweep Thread for given CMS generation |
|
105 |
ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::start(CMSCollector* collector) { |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
106 |
guarantee(_cmst == NULL, "start() called twice!"); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
107 |
ConcurrentMarkSweepThread* th = new ConcurrentMarkSweepThread(collector); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
108 |
assert(_cmst == th, "Where did the just-created CMS thread go?"); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
109 |
return th; |
1 | 110 |
} |
111 |
||
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
112 |
void ConcurrentMarkSweepThread::stop_service() { |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
113 |
// Now post a notify on CGC_lock so as to nudge |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
114 |
// CMS thread(s) that might be slumbering in |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
115 |
// sleepBeforeNextCycle. |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
116 |
MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
117 |
CGC_lock->notify_all(); |
1 | 118 |
} |
119 |
||
120 |
void ConcurrentMarkSweepThread::threads_do(ThreadClosure* tc) { |
|
121 |
assert(tc != NULL, "Null ThreadClosure"); |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
122 |
if (cmst() != NULL && !cmst()->has_terminated()) { |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
123 |
tc->do_thread(cmst()); |
1 | 124 |
} |
125 |
assert(Universe::is_fully_initialized(), |
|
126 |
"Called too early, make sure heap is fully initialized"); |
|
127 |
if (_collector != NULL) { |
|
128 |
AbstractWorkGang* gang = _collector->conc_workers(); |
|
129 |
if (gang != NULL) { |
|
130 |
gang->threads_do(tc); |
|
131 |
} |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
void ConcurrentMarkSweepThread::print_all_on(outputStream* st) { |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
136 |
if (cmst() != NULL && !cmst()->has_terminated()) { |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
137 |
cmst()->print_on(st); |
13857 | 138 |
st->cr(); |
1 | 139 |
} |
140 |
if (_collector != NULL) { |
|
141 |
AbstractWorkGang* gang = _collector->conc_workers(); |
|
142 |
if (gang != NULL) { |
|
143 |
gang->print_worker_threads_on(st); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
void ConcurrentMarkSweepThread::synchronize(bool is_cms_thread) { |
|
149 |
assert(UseConcMarkSweepGC, "just checking"); |
|
150 |
||
151 |
MutexLockerEx x(CGC_lock, |
|
152 |
Mutex::_no_safepoint_check_flag); |
|
153 |
if (!is_cms_thread) { |
|
154 |
assert(Thread::current()->is_VM_thread(), "Not a VM thread"); |
|
155 |
CMSSynchronousYieldRequest yr; |
|
156 |
while (CMS_flag_is_set(CMS_cms_has_token)) { |
|
157 |
// indicate that we want to get the token |
|
158 |
set_CMS_flag(CMS_vm_wants_token); |
|
159 |
CGC_lock->wait(true); |
|
160 |
} |
|
161 |
// claim the token and proceed |
|
162 |
clear_CMS_flag(CMS_vm_wants_token); |
|
163 |
set_CMS_flag(CMS_vm_has_token); |
|
164 |
} else { |
|
165 |
assert(Thread::current()->is_ConcurrentGC_thread(), |
|
166 |
"Not a CMS thread"); |
|
167 |
// The following barrier assumes there's only one CMS thread. |
|
168 |
// This will need to be modified is there are more CMS threads than one. |
|
169 |
while (CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token)) { |
|
170 |
set_CMS_flag(CMS_cms_wants_token); |
|
171 |
CGC_lock->wait(true); |
|
172 |
} |
|
173 |
// claim the token |
|
174 |
clear_CMS_flag(CMS_cms_wants_token); |
|
175 |
set_CMS_flag(CMS_cms_has_token); |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
void ConcurrentMarkSweepThread::desynchronize(bool is_cms_thread) { |
|
180 |
assert(UseConcMarkSweepGC, "just checking"); |
|
181 |
||
182 |
MutexLockerEx x(CGC_lock, |
|
183 |
Mutex::_no_safepoint_check_flag); |
|
184 |
if (!is_cms_thread) { |
|
185 |
assert(Thread::current()->is_VM_thread(), "Not a VM thread"); |
|
186 |
assert(CMS_flag_is_set(CMS_vm_has_token), "just checking"); |
|
187 |
clear_CMS_flag(CMS_vm_has_token); |
|
188 |
if (CMS_flag_is_set(CMS_cms_wants_token)) { |
|
189 |
// wake-up a waiting CMS thread |
|
190 |
CGC_lock->notify(); |
|
191 |
} |
|
192 |
assert(!CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token), |
|
193 |
"Should have been cleared"); |
|
194 |
} else { |
|
195 |
assert(Thread::current()->is_ConcurrentGC_thread(), |
|
196 |
"Not a CMS thread"); |
|
197 |
assert(CMS_flag_is_set(CMS_cms_has_token), "just checking"); |
|
198 |
clear_CMS_flag(CMS_cms_has_token); |
|
199 |
if (CMS_flag_is_set(CMS_vm_wants_token)) { |
|
200 |
// wake-up a waiting VM thread |
|
201 |
CGC_lock->notify(); |
|
202 |
} |
|
203 |
assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token), |
|
204 |
"Should have been cleared"); |
|
205 |
} |
|
206 |
} |
|
207 |
||
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
208 |
// Wait until any cms_lock event |
6984
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
209 |
void ConcurrentMarkSweepThread::wait_on_cms_lock(long t_millis) { |
1 | 210 |
MutexLockerEx x(CGC_lock, |
211 |
Mutex::_no_safepoint_check_flag); |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
212 |
if (should_terminate() || _collector->_full_gc_requested) { |
6984
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
213 |
return; |
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
214 |
} |
1 | 215 |
set_CMS_flag(CMS_cms_wants_token); // to provoke notifies |
6984
c6718f921eb6
6992998: CMSWaitDuration=0 causes hangs with +ExplicitGCInvokesConcurrent
ysr
parents:
5547
diff
changeset
|
216 |
CGC_lock->wait(Mutex::_no_safepoint_check_flag, t_millis); |
1 | 217 |
clear_CMS_flag(CMS_cms_wants_token); |
218 |
assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token), |
|
219 |
"Should not be set"); |
|
220 |
} |
|
221 |
||
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
222 |
// 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
|
223 |
// or a timeout, whichever is earlier. |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
224 |
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
|
225 |
// 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
|
226 |
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
|
227 |
|
47622
817f2a7019e4
8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
47216
diff
changeset
|
228 |
CMSHeap* heap = CMSHeap::heap(); |
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
229 |
double start_time_secs = os::elapsedTime(); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
230 |
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
|
231 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
232 |
// Total collections count before waiting loop |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
233 |
unsigned int before_count; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
234 |
{ |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
235 |
MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag); |
47622
817f2a7019e4
8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
47216
diff
changeset
|
236 |
before_count = heap->total_collections(); |
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
237 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
238 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
239 |
unsigned int loop_count = 0; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
240 |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
241 |
while(!should_terminate()) { |
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
242 |
double now_time = os::elapsedTime(); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
243 |
long wait_time_millis; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
244 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
245 |
if(t_millis != 0) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
246 |
// New wait limit |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
247 |
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
|
248 |
if(wait_time_millis <= 0) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
249 |
// Wait time is over |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
250 |
break; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
251 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
252 |
} else { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
253 |
// No wait limit, wait if necessary forever |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
254 |
wait_time_millis = 0; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
255 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
256 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
257 |
// Wait until the next event or the remaining timeout |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
258 |
{ |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
259 |
MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
260 |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
261 |
if (should_terminate() || _collector->_full_gc_requested) { |
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
262 |
return; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
263 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
264 |
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
|
265 |
assert(t_millis == 0 || wait_time_millis > 0, "Sanity"); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
266 |
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
|
267 |
clear_CMS_flag(CMS_cms_wants_token); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
268 |
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
|
269 |
"Should not be set"); |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
270 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
271 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
272 |
// 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
|
273 |
if(t_millis != 0 && os::elapsedTime() >= end_time_secs) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
274 |
// Wait time is over |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
275 |
break; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
276 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
277 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
278 |
// Total collections count after the event |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
279 |
unsigned int after_count; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
280 |
{ |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
281 |
MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag); |
47622
817f2a7019e4
8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
47216
diff
changeset
|
282 |
after_count = heap->total_collections(); |
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
283 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
284 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
285 |
if(before_count != after_count) { |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
286 |
// There was a collection - success |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
287 |
break; |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
288 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
289 |
|
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
290 |
// Too many loops warning |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
291 |
if(++loop_count == 0) { |
37073
c39d0903390b
8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents:
34633
diff
changeset
|
292 |
log_warning(gc)("wait_on_cms_lock_for_scavenge() has looped %u times", loop_count - 1); |
15859
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
293 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
294 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
295 |
} |
b8d7620fb179
7189971: Implement CMSWaitDuration for non-incremental mode of CMS
jmasa
parents:
13857
diff
changeset
|
296 |
|
1 | 297 |
void ConcurrentMarkSweepThread::sleepBeforeNextCycle() { |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
37073
diff
changeset
|
298 |
while (!should_terminate()) { |
27625 | 299 |
if(CMSWaitDuration >= 0) { |
300 |
// Wait until the next synchronous GC, a concurrent full gc |
|
301 |
// request or a timeout, whichever is earlier. |
|
302 |
wait_on_cms_lock_for_scavenge(CMSWaitDuration); |
|
1 | 303 |
} else { |
27625 | 304 |
// Wait until any cms_lock event or check interval not to call shouldConcurrentCollect permanently |
305 |
wait_on_cms_lock(CMSCheckInterval); |
|
1 | 306 |
} |
307 |
// Check if we should start a CMS collection cycle |
|
308 |
if (_collector->shouldConcurrentCollect()) { |
|
309 |
return; |
|
310 |
} |
|
311 |
// .. collection criterion not yet met, let's go back |
|
312 |
// and wait some more |
|
313 |
} |
|
314 |
} |