author | johnc |
Thu, 30 Apr 2009 15:07:53 -0700 | |
changeset 2741 | 34e2a243d69a |
parent 2142 | 032f4652700c |
child 2881 | 74a1337e4acc |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
2 |
* Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. |
|
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 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "incls/_precompiled.incl" |
|
26 |
#include "incls/_concurrentG1RefineThread.cpp.incl" |
|
27 |
||
28 |
// ======= Concurrent Mark Thread ======== |
|
29 |
||
30 |
// The CM thread is created when the G1 garbage collector is used |
|
31 |
||
32 |
ConcurrentG1RefineThread:: |
|
33 |
ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r) : |
|
34 |
ConcurrentGCThread(), |
|
35 |
_cg1r(cg1r), |
|
36 |
_started(false), |
|
37 |
_in_progress(false), |
|
38 |
_do_traversal(false), |
|
39 |
_vtime_accum(0.0), |
|
40 |
_co_tracker(G1CRGroup), |
|
41 |
_interval_ms(5.0) |
|
42 |
{ |
|
43 |
create_and_start(); |
|
44 |
} |
|
45 |
||
46 |
const long timeout = 200; // ms. |
|
47 |
||
48 |
void ConcurrentG1RefineThread::traversalBasedRefinement() { |
|
49 |
_cg1r->wait_for_ConcurrentG1Refine_enabled(); |
|
50 |
MutexLocker x(G1ConcRefine_mon); |
|
51 |
while (_cg1r->enabled()) { |
|
52 |
MutexUnlocker ux(G1ConcRefine_mon); |
|
53 |
ResourceMark rm; |
|
54 |
HandleMark hm; |
|
55 |
||
2741 | 56 |
if (G1TraceConcurrentRefinement) { |
57 |
gclog_or_tty->print_cr("G1-Refine starting pass"); |
|
58 |
} |
|
1374 | 59 |
_sts.join(); |
60 |
bool no_sleep = _cg1r->refine(); |
|
61 |
_sts.leave(); |
|
62 |
if (!no_sleep) { |
|
63 |
MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
|
64 |
// We do this only for the timeout; we don't expect this to be signalled. |
|
65 |
CGC_lock->wait(Mutex::_no_safepoint_check_flag, timeout); |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
void ConcurrentG1RefineThread::queueBasedRefinement() { |
|
71 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
72 |
// Wait for completed log buffers to exist. |
|
73 |
{ |
|
74 |
MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag); |
|
75 |
while (!_do_traversal && !dcqs.process_completed_buffers() && |
|
76 |
!_should_terminate) { |
|
77 |
DirtyCardQ_CBL_mon->wait(Mutex::_no_safepoint_check_flag); |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
if (_should_terminate) { |
|
82 |
return; |
|
83 |
} |
|
84 |
||
85 |
// Now we take them off (this doesn't hold locks while it applies |
|
86 |
// closures.) (If we did a full collection, then we'll do a full |
|
87 |
// traversal. |
|
88 |
_sts.join(); |
|
89 |
if (_do_traversal) { |
|
90 |
(void)_cg1r->refine(); |
|
91 |
switch (_cg1r->get_last_pya()) { |
|
92 |
case PYA_cancel: case PYA_continue: |
|
93 |
// Continue was caught and handled inside "refine". If it's still |
|
94 |
// "continue" when we get here, we're done. |
|
95 |
_do_traversal = false; |
|
96 |
break; |
|
97 |
case PYA_restart: |
|
98 |
assert(_do_traversal, "Because of Full GC."); |
|
99 |
break; |
|
100 |
} |
|
101 |
} else { |
|
102 |
int n_logs = 0; |
|
103 |
int lower_limit = 0; |
|
104 |
double start_vtime_sec; // only used when G1SmoothConcRefine is on |
|
105 |
int prev_buffer_num; // only used when G1SmoothConcRefine is on |
|
106 |
||
107 |
if (G1SmoothConcRefine) { |
|
108 |
lower_limit = 0; |
|
109 |
start_vtime_sec = os::elapsedVTime(); |
|
110 |
prev_buffer_num = (int) dcqs.completed_buffers_num(); |
|
111 |
} else { |
|
112 |
lower_limit = DCQBarrierProcessCompletedThreshold / 4; // For now. |
|
113 |
} |
|
114 |
while (dcqs.apply_closure_to_completed_buffer(0, lower_limit)) { |
|
115 |
double end_vtime_sec; |
|
116 |
double elapsed_vtime_sec; |
|
117 |
int elapsed_vtime_ms; |
|
118 |
int curr_buffer_num; |
|
119 |
||
120 |
if (G1SmoothConcRefine) { |
|
121 |
end_vtime_sec = os::elapsedVTime(); |
|
122 |
elapsed_vtime_sec = end_vtime_sec - start_vtime_sec; |
|
123 |
elapsed_vtime_ms = (int) (elapsed_vtime_sec * 1000.0); |
|
124 |
curr_buffer_num = (int) dcqs.completed_buffers_num(); |
|
125 |
||
126 |
if (curr_buffer_num > prev_buffer_num || |
|
127 |
curr_buffer_num > DCQBarrierProcessCompletedThreshold) { |
|
128 |
decreaseInterval(elapsed_vtime_ms); |
|
129 |
} else if (curr_buffer_num < prev_buffer_num) { |
|
130 |
increaseInterval(elapsed_vtime_ms); |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
sample_young_list_rs_lengths(); |
|
135 |
_co_tracker.update(false); |
|
136 |
||
137 |
if (G1SmoothConcRefine) { |
|
138 |
prev_buffer_num = curr_buffer_num; |
|
139 |
_sts.leave(); |
|
140 |
os::sleep(Thread::current(), (jlong) _interval_ms, false); |
|
141 |
_sts.join(); |
|
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1374
diff
changeset
|
142 |
start_vtime_sec = os::elapsedVTime(); |
1374 | 143 |
} |
144 |
n_logs++; |
|
145 |
} |
|
146 |
// Make sure we harvest the PYA, if any. |
|
147 |
(void)_cg1r->get_pya(); |
|
148 |
} |
|
149 |
_sts.leave(); |
|
150 |
} |
|
151 |
||
152 |
void ConcurrentG1RefineThread::sample_young_list_rs_lengths() { |
|
153 |
G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
|
154 |
G1CollectorPolicy* g1p = g1h->g1_policy(); |
|
155 |
if (g1p->adaptive_young_list_length()) { |
|
156 |
int regions_visited = 0; |
|
157 |
||
158 |
g1h->young_list_rs_length_sampling_init(); |
|
159 |
while (g1h->young_list_rs_length_sampling_more()) { |
|
160 |
g1h->young_list_rs_length_sampling_next(); |
|
161 |
++regions_visited; |
|
162 |
||
163 |
// we try to yield every time we visit 10 regions |
|
164 |
if (regions_visited == 10) { |
|
165 |
if (_sts.should_yield()) { |
|
166 |
_sts.yield("G1 refine"); |
|
167 |
// we just abandon the iteration |
|
168 |
break; |
|
169 |
} |
|
170 |
regions_visited = 0; |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
g1p->check_prediction_validity(); |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
void ConcurrentG1RefineThread::run() { |
|
179 |
initialize_in_thread(); |
|
180 |
_vtime_start = os::elapsedVTime(); |
|
181 |
wait_for_universe_init(); |
|
182 |
||
183 |
_co_tracker.enable(); |
|
184 |
_co_tracker.start(); |
|
185 |
||
186 |
while (!_should_terminate) { |
|
187 |
// wait until started is set. |
|
188 |
if (G1RSBarrierUseQueue) { |
|
189 |
queueBasedRefinement(); |
|
190 |
} else { |
|
191 |
traversalBasedRefinement(); |
|
192 |
} |
|
193 |
_sts.join(); |
|
194 |
_co_tracker.update(); |
|
195 |
_sts.leave(); |
|
196 |
if (os::supports_vtime()) { |
|
197 |
_vtime_accum = (os::elapsedVTime() - _vtime_start); |
|
198 |
} else { |
|
199 |
_vtime_accum = 0.0; |
|
200 |
} |
|
201 |
} |
|
202 |
_sts.join(); |
|
203 |
_co_tracker.update(true); |
|
204 |
_sts.leave(); |
|
205 |
assert(_should_terminate, "just checking"); |
|
206 |
||
207 |
terminate(); |
|
208 |
} |
|
209 |
||
210 |
||
211 |
void ConcurrentG1RefineThread::yield() { |
|
2741 | 212 |
if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield"); |
1374 | 213 |
_sts.yield("G1 refine"); |
2741 | 214 |
if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield-end"); |
1374 | 215 |
} |
216 |
||
217 |
void ConcurrentG1RefineThread::stop() { |
|
218 |
// it is ok to take late safepoints here, if needed |
|
219 |
{ |
|
220 |
MutexLockerEx mu(Terminator_lock); |
|
221 |
_should_terminate = true; |
|
222 |
} |
|
223 |
||
224 |
{ |
|
225 |
MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag); |
|
226 |
DirtyCardQ_CBL_mon->notify_all(); |
|
227 |
} |
|
228 |
||
229 |
{ |
|
230 |
MutexLockerEx mu(Terminator_lock); |
|
231 |
while (!_has_terminated) { |
|
232 |
Terminator_lock->wait(); |
|
233 |
} |
|
234 |
} |
|
2741 | 235 |
if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-stop"); |
1374 | 236 |
} |
237 |
||
238 |
void ConcurrentG1RefineThread::print() { |
|
239 |
gclog_or_tty->print("\"Concurrent G1 Refinement Thread\" "); |
|
240 |
Thread::print(); |
|
241 |
gclog_or_tty->cr(); |
|
242 |
} |
|
243 |
||
244 |
void ConcurrentG1RefineThread::set_do_traversal(bool b) { |
|
245 |
_do_traversal = b; |
|
246 |
} |