author | goetz |
Thu, 22 Oct 2015 13:07:10 -0400 | |
changeset 33589 | 7cbd1b2c139b |
parent 30770 | 5ba2d9f2084d |
child 33608 | 7afc768e4d62 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
30613
a7815bb05ae2
8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents:
29464
diff
changeset
|
2 |
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. |
1374 | 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:
5350
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5350
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:
5350
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/g1/concurrentG1Refine.hpp" |
27 |
#include "gc/g1/concurrentG1RefineThread.hpp" |
|
28 |
#include "gc/g1/g1CollectedHeap.inline.hpp" |
|
29 |
#include "gc/g1/g1CollectorPolicy.hpp" |
|
30770
5ba2d9f2084d
8080585: concurrentGCThread.hpp should not include suspendibleThreadSet.hpp
pliden
parents:
30764
diff
changeset
|
30 |
#include "gc/g1/suspendibleThreadSet.hpp" |
7397 | 31 |
#include "memory/resourceArea.hpp" |
32 |
#include "runtime/handles.inline.hpp" |
|
33 |
#include "runtime/mutexLocker.hpp" |
|
1374 | 34 |
|
35 |
ConcurrentG1RefineThread:: |
|
2882
d508a8bac491
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
2881
diff
changeset
|
36 |
ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next, |
24104
febf9363fb68
8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents:
24094
diff
changeset
|
37 |
CardTableEntryClosure* refine_closure, |
23855
c4574075402c
8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents:
22551
diff
changeset
|
38 |
uint worker_id_offset, uint worker_id) : |
1374 | 39 |
ConcurrentGCThread(), |
24104
febf9363fb68
8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents:
24094
diff
changeset
|
40 |
_refine_closure(refine_closure), |
2882
d508a8bac491
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
2881
diff
changeset
|
41 |
_worker_id_offset(worker_id_offset), |
2881 | 42 |
_worker_id(worker_id), |
43 |
_active(false), |
|
44 |
_next(next), |
|
4481 | 45 |
_monitor(NULL), |
1374 | 46 |
_cg1r(cg1r), |
4481 | 47 |
_vtime_accum(0.0) |
1374 | 48 |
{ |
4481 | 49 |
|
22551 | 50 |
// Each thread has its own monitor. The i-th thread is responsible for signaling |
51 |
// to thread i+1 if the number of buffers in the queue exceeds a threshold for this |
|
4481 | 52 |
// thread. Monitors are also used to wake up the threads during termination. |
53 |
// The 0th worker in notified by mutator threads and has a special monitor. |
|
54 |
// The last worker is used for young gen rset size sampling. |
|
55 |
if (worker_id > 0) { |
|
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
24331
diff
changeset
|
56 |
_monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true, |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
24331
diff
changeset
|
57 |
Monitor::_safepoint_check_never); |
4481 | 58 |
} else { |
59 |
_monitor = DirtyCardQ_CBL_mon; |
|
60 |
} |
|
61 |
initialize(); |
|
1374 | 62 |
create_and_start(); |
24331
c0bc7e5653fb
6885993: Named Thread: introduce print() and print_on(outputStream* st) methods
zgu
parents:
24104
diff
changeset
|
63 |
|
c0bc7e5653fb
6885993: Named Thread: introduce print() and print_on(outputStream* st) methods
zgu
parents:
24104
diff
changeset
|
64 |
// set name |
29464
02c245ad3ec9
8073545: Use shorter and more descriptive names for GC worker threads
david
parents:
28163
diff
changeset
|
65 |
set_name("G1 Refine#%d", worker_id); |
1374 | 66 |
} |
67 |
||
4481 | 68 |
void ConcurrentG1RefineThread::initialize() { |
69 |
if (_worker_id < cg1r()->worker_thread_num()) { |
|
70 |
// Current thread activation threshold |
|
71 |
_threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(), |
|
72 |
cg1r()->yellow_zone()); |
|
73 |
// A thread deactivates once the number of buffer reached a deactivation threshold |
|
74 |
_deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone()); |
|
75 |
} else { |
|
76 |
set_active(true); |
|
77 |
} |
|
78 |
} |
|
79 |
||
1374 | 80 |
void ConcurrentG1RefineThread::sample_young_list_rs_lengths() { |
30613
a7815bb05ae2
8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents:
29464
diff
changeset
|
81 |
SuspendibleThreadSetJoiner sts_join; |
1374 | 82 |
G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
83 |
G1CollectorPolicy* g1p = g1h->g1_policy(); |
|
84 |
if (g1p->adaptive_young_list_length()) { |
|
85 |
int regions_visited = 0; |
|
5350
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
5033
diff
changeset
|
86 |
g1h->young_list()->rs_length_sampling_init(); |
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
5033
diff
changeset
|
87 |
while (g1h->young_list()->rs_length_sampling_more()) { |
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
5033
diff
changeset
|
88 |
g1h->young_list()->rs_length_sampling_next(); |
1374 | 89 |
++regions_visited; |
90 |
||
91 |
// we try to yield every time we visit 10 regions |
|
92 |
if (regions_visited == 10) { |
|
30613
a7815bb05ae2
8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents:
29464
diff
changeset
|
93 |
if (sts_join.should_yield()) { |
a7815bb05ae2
8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents:
29464
diff
changeset
|
94 |
sts_join.yield(); |
1374 | 95 |
// we just abandon the iteration |
96 |
break; |
|
97 |
} |
|
98 |
regions_visited = 0; |
|
99 |
} |
|
100 |
} |
|
101 |
||
10528
06fab03478df
7084509: G1: fix inconsistencies and mistakes in the young list target length calculations
tonyp
parents:
7397
diff
changeset
|
102 |
g1p->revise_young_list_target_length_if_necessary(); |
1374 | 103 |
} |
104 |
} |
|
105 |
||
4481 | 106 |
void ConcurrentG1RefineThread::run_young_rs_sampling() { |
107 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
1374 | 108 |
_vtime_start = os::elapsedVTime(); |
4481 | 109 |
while(!_should_terminate) { |
110 |
sample_young_list_rs_lengths(); |
|
1374 | 111 |
|
4481 | 112 |
if (os::supports_vtime()) { |
113 |
_vtime_accum = (os::elapsedVTime() - _vtime_start); |
|
114 |
} else { |
|
115 |
_vtime_accum = 0.0; |
|
2881 | 116 |
} |
117 |
||
4481 | 118 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
119 |
if (_should_terminate) { |
|
120 |
break; |
|
121 |
} |
|
5033 | 122 |
_monitor->wait(Mutex::_no_safepoint_check_flag, G1ConcRefinementServiceIntervalMillis); |
4481 | 123 |
} |
124 |
} |
|
2881 | 125 |
|
4481 | 126 |
void ConcurrentG1RefineThread::wait_for_completed_buffers() { |
127 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
128 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
129 |
while (!_should_terminate && !is_active()) { |
|
130 |
_monitor->wait(Mutex::_no_safepoint_check_flag); |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
bool ConcurrentG1RefineThread::is_active() { |
|
135 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
136 |
return _worker_id > 0 ? _active : dcqs.process_completed_buffers(); |
|
137 |
} |
|
138 |
||
139 |
void ConcurrentG1RefineThread::activate() { |
|
140 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
141 |
if (_worker_id > 0) { |
|
5033 | 142 |
if (G1TraceConcRefinement) { |
4481 | 143 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
144 |
gclog_or_tty->print_cr("G1-Refine-activated worker %d, on threshold %d, current %d", |
|
145 |
_worker_id, _threshold, (int)dcqs.completed_buffers_num()); |
|
1374 | 146 |
} |
4481 | 147 |
set_active(true); |
148 |
} else { |
|
149 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
150 |
dcqs.set_process_completed(true); |
|
151 |
} |
|
152 |
_monitor->notify(); |
|
153 |
} |
|
2881 | 154 |
|
4481 | 155 |
void ConcurrentG1RefineThread::deactivate() { |
156 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
157 |
if (_worker_id > 0) { |
|
5033 | 158 |
if (G1TraceConcRefinement) { |
4481 | 159 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
160 |
gclog_or_tty->print_cr("G1-Refine-deactivated worker %d, off threshold %d, current %d", |
|
161 |
_worker_id, _deactivation_threshold, (int)dcqs.completed_buffers_num()); |
|
162 |
} |
|
163 |
set_active(false); |
|
164 |
} else { |
|
165 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
166 |
dcqs.set_process_completed(false); |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
void ConcurrentG1RefineThread::run() { |
|
171 |
initialize_in_thread(); |
|
172 |
wait_for_universe_init(); |
|
2881 | 173 |
|
4481 | 174 |
if (_worker_id >= cg1r()->worker_thread_num()) { |
175 |
run_young_rs_sampling(); |
|
176 |
terminate(); |
|
5350
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
5033
diff
changeset
|
177 |
return; |
4481 | 178 |
} |
179 |
||
180 |
_vtime_start = os::elapsedVTime(); |
|
181 |
while (!_should_terminate) { |
|
182 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
183 |
||
184 |
// Wait for work |
|
185 |
wait_for_completed_buffers(); |
|
186 |
||
187 |
if (_should_terminate) { |
|
188 |
break; |
|
189 |
} |
|
190 |
||
24094 | 191 |
{ |
30613
a7815bb05ae2
8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents:
29464
diff
changeset
|
192 |
SuspendibleThreadSetJoiner sts_join; |
24094 | 193 |
|
194 |
do { |
|
195 |
int curr_buffer_num = (int)dcqs.completed_buffers_num(); |
|
196 |
// If the number of the buffers falls down into the yellow zone, |
|
197 |
// that means that the transition period after the evacuation pause has ended. |
|
198 |
if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { |
|
199 |
dcqs.set_completed_queue_padding(0); |
|
200 |
} |
|
4481 | 201 |
|
24094 | 202 |
if (_worker_id > 0 && curr_buffer_num <= _deactivation_threshold) { |
203 |
// If the number of the buffer has fallen below our threshold |
|
204 |
// we should deactivate. The predecessor will reactivate this |
|
205 |
// thread should the number of the buffers cross the threshold again. |
|
206 |
deactivate(); |
|
207 |
break; |
|
208 |
} |
|
4481 | 209 |
|
24094 | 210 |
// Check if we need to activate the next thread. |
211 |
if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { |
|
212 |
_next->activate(); |
|
213 |
} |
|
24104
febf9363fb68
8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents:
24094
diff
changeset
|
214 |
} while (dcqs.apply_closure_to_completed_buffer(_refine_closure, _worker_id + _worker_id_offset, cg1r()->green_zone())); |
24094 | 215 |
|
216 |
// We can exit the loop above while being active if there was a yield request. |
|
217 |
if (is_active()) { |
|
2881 | 218 |
deactivate(); |
219 |
} |
|
220 |
} |
|
4481 | 221 |
|
1374 | 222 |
if (os::supports_vtime()) { |
223 |
_vtime_accum = (os::elapsedVTime() - _vtime_start); |
|
224 |
} else { |
|
225 |
_vtime_accum = 0.0; |
|
226 |
} |
|
227 |
} |
|
228 |
assert(_should_terminate, "just checking"); |
|
229 |
terminate(); |
|
230 |
} |
|
231 |
||
232 |
void ConcurrentG1RefineThread::stop() { |
|
233 |
// it is ok to take late safepoints here, if needed |
|
234 |
{ |
|
235 |
MutexLockerEx mu(Terminator_lock); |
|
236 |
_should_terminate = true; |
|
237 |
} |
|
238 |
||
239 |
{ |
|
4481 | 240 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
241 |
_monitor->notify(); |
|
1374 | 242 |
} |
243 |
||
244 |
{ |
|
245 |
MutexLockerEx mu(Terminator_lock); |
|
246 |
while (!_has_terminated) { |
|
247 |
Terminator_lock->wait(); |
|
248 |
} |
|
249 |
} |
|
5033 | 250 |
if (G1TraceConcRefinement) { |
251 |
gclog_or_tty->print_cr("G1-Refine-stop"); |
|
252 |
} |
|
1374 | 253 |
} |
254 |