Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/g1/concurrentG1RefineThread.cpp @ 20204:d22136881b85
Merge
author | robm |
---|---|
date | Thu, 17 Jul 2014 18:03:26 +0100 |
parents | 581e70386ec9 |
children | 570cb6369f17 |
rev | line source |
---|---|
342 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1394
diff
changeset
|
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
342 | 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:
1394
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1394
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:
1394
diff
changeset
|
21 * questions. |
342 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "gc_implementation/g1/concurrentG1Refine.hpp" | |
27 #include "gc_implementation/g1/concurrentG1RefineThread.hpp" | |
28 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" | |
29 #include "gc_implementation/g1/g1CollectorPolicy.hpp" | |
30 #include "memory/resourceArea.hpp" | |
31 #include "runtime/handles.inline.hpp" | |
32 #include "runtime/mutexLocker.hpp" | |
342 | 33 |
34 ConcurrentG1RefineThread:: | |
795
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
35 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next, |
17844
8847586c9037
8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents:
3919
diff
changeset
|
36 uint worker_id_offset, uint worker_id) : |
342 | 37 ConcurrentGCThread(), |
795
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
38 _worker_id_offset(worker_id_offset), |
794 | 39 _worker_id(worker_id), |
40 _active(false), | |
41 _next(next), | |
1111 | 42 _monitor(NULL), |
342 | 43 _cg1r(cg1r), |
1111 | 44 _vtime_accum(0.0) |
342 | 45 { |
1111 | 46 |
47 // Each thread has its own monitor. The i-th thread is responsible for signalling | |
48 // to thread i+1 if the number of buffers in the queue exceeds a threashold for this | |
49 // thread. Monitors are also used to wake up the threads during termination. | |
50 // The 0th worker in notified by mutator threads and has a special monitor. | |
51 // The last worker is used for young gen rset size sampling. | |
52 if (worker_id > 0) { | |
53 _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true); | |
54 } else { | |
55 _monitor = DirtyCardQ_CBL_mon; | |
56 } | |
57 initialize(); | |
342 | 58 create_and_start(); |
59 } | |
60 | |
1111 | 61 void ConcurrentG1RefineThread::initialize() { |
62 if (_worker_id < cg1r()->worker_thread_num()) { | |
63 // Current thread activation threshold | |
64 _threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(), | |
65 cg1r()->yellow_zone()); | |
66 // A thread deactivates once the number of buffer reached a deactivation threshold | |
67 _deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone()); | |
68 } else { | |
69 set_active(true); | |
70 } | |
71 } | |
72 | |
342 | 73 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() { |
20192 | 74 SuspendibleThreadSetJoiner sts; |
342 | 75 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
76 G1CollectorPolicy* g1p = g1h->g1_policy(); | |
77 if (g1p->adaptive_young_list_length()) { | |
78 int regions_visited = 0; | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1282
diff
changeset
|
79 g1h->young_list()->rs_length_sampling_init(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1282
diff
changeset
|
80 while (g1h->young_list()->rs_length_sampling_more()) { |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1282
diff
changeset
|
81 g1h->young_list()->rs_length_sampling_next(); |
342 | 82 ++regions_visited; |
83 | |
84 // we try to yield every time we visit 10 regions | |
85 if (regions_visited == 10) { | |
20192 | 86 if (sts.should_yield()) { |
87 sts.yield(); | |
342 | 88 // we just abandon the iteration |
89 break; | |
90 } | |
91 regions_visited = 0; | |
92 } | |
93 } | |
94 | |
3919
4f41766176cf
7084509: G1: fix inconsistencies and mistakes in the young list target length calculations
tonyp
parents:
1972
diff
changeset
|
95 g1p->revise_young_list_target_length_if_necessary(); |
342 | 96 } |
97 } | |
98 | |
1111 | 99 void ConcurrentG1RefineThread::run_young_rs_sampling() { |
100 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
342 | 101 _vtime_start = os::elapsedVTime(); |
1111 | 102 while(!_should_terminate) { |
103 sample_young_list_rs_lengths(); | |
342 | 104 |
1111 | 105 if (os::supports_vtime()) { |
106 _vtime_accum = (os::elapsedVTime() - _vtime_start); | |
107 } else { | |
108 _vtime_accum = 0.0; | |
794 | 109 } |
110 | |
1111 | 111 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
112 if (_should_terminate) { | |
113 break; | |
114 } | |
1282 | 115 _monitor->wait(Mutex::_no_safepoint_check_flag, G1ConcRefinementServiceIntervalMillis); |
1111 | 116 } |
117 } | |
794 | 118 |
1111 | 119 void ConcurrentG1RefineThread::wait_for_completed_buffers() { |
120 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
121 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
122 while (!_should_terminate && !is_active()) { | |
123 _monitor->wait(Mutex::_no_safepoint_check_flag); | |
124 } | |
125 } | |
126 | |
127 bool ConcurrentG1RefineThread::is_active() { | |
128 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
129 return _worker_id > 0 ? _active : dcqs.process_completed_buffers(); | |
130 } | |
131 | |
132 void ConcurrentG1RefineThread::activate() { | |
133 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
134 if (_worker_id > 0) { | |
1282 | 135 if (G1TraceConcRefinement) { |
1111 | 136 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
137 gclog_or_tty->print_cr("G1-Refine-activated worker %d, on threshold %d, current %d", | |
138 _worker_id, _threshold, (int)dcqs.completed_buffers_num()); | |
342 | 139 } |
1111 | 140 set_active(true); |
141 } else { | |
142 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
143 dcqs.set_process_completed(true); | |
144 } | |
145 _monitor->notify(); | |
146 } | |
794 | 147 |
1111 | 148 void ConcurrentG1RefineThread::deactivate() { |
149 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
150 if (_worker_id > 0) { | |
1282 | 151 if (G1TraceConcRefinement) { |
1111 | 152 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
153 gclog_or_tty->print_cr("G1-Refine-deactivated worker %d, off threshold %d, current %d", | |
154 _worker_id, _deactivation_threshold, (int)dcqs.completed_buffers_num()); | |
155 } | |
156 set_active(false); | |
157 } else { | |
158 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
159 dcqs.set_process_completed(false); | |
160 } | |
161 } | |
162 | |
163 void ConcurrentG1RefineThread::run() { | |
164 initialize_in_thread(); | |
165 wait_for_universe_init(); | |
794 | 166 |
1111 | 167 if (_worker_id >= cg1r()->worker_thread_num()) { |
168 run_young_rs_sampling(); | |
169 terminate(); | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1282
diff
changeset
|
170 return; |
1111 | 171 } |
172 | |
173 _vtime_start = os::elapsedVTime(); | |
174 while (!_should_terminate) { | |
175 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
176 | |
177 // Wait for work | |
178 wait_for_completed_buffers(); | |
179 | |
180 if (_should_terminate) { | |
181 break; | |
182 } | |
183 | |
20192 | 184 { |
185 SuspendibleThreadSetJoiner sts; | |
186 | |
187 do { | |
188 int curr_buffer_num = (int)dcqs.completed_buffers_num(); | |
189 // If the number of the buffers falls down into the yellow zone, | |
190 // that means that the transition period after the evacuation pause has ended. | |
191 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { | |
192 dcqs.set_completed_queue_padding(0); | |
193 } | |
1111 | 194 |
20192 | 195 if (_worker_id > 0 && curr_buffer_num <= _deactivation_threshold) { |
196 // If the number of the buffer has fallen below our threshold | |
197 // we should deactivate. The predecessor will reactivate this | |
198 // thread should the number of the buffers cross the threshold again. | |
199 deactivate(); | |
200 break; | |
201 } | |
1111 | 202 |
20192 | 203 // Check if we need to activate the next thread. |
204 if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { | |
205 _next->activate(); | |
206 } | |
207 } while (dcqs.apply_closure_to_completed_buffer(_worker_id + _worker_id_offset, cg1r()->green_zone())); | |
208 | |
209 // We can exit the loop above while being active if there was a yield request. | |
210 if (is_active()) { | |
794 | 211 deactivate(); |
212 } | |
213 } | |
1111 | 214 |
342 | 215 if (os::supports_vtime()) { |
216 _vtime_accum = (os::elapsedVTime() - _vtime_start); | |
217 } else { | |
218 _vtime_accum = 0.0; | |
219 } | |
220 } | |
221 assert(_should_terminate, "just checking"); | |
222 terminate(); | |
223 } | |
224 | |
225 void ConcurrentG1RefineThread::stop() { | |
226 // it is ok to take late safepoints here, if needed | |
227 { | |
228 MutexLockerEx mu(Terminator_lock); | |
229 _should_terminate = true; | |
230 } | |
231 | |
232 { | |
1111 | 233 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
234 _monitor->notify(); | |
342 | 235 } |
236 | |
237 { | |
238 MutexLockerEx mu(Terminator_lock); | |
239 while (!_has_terminated) { | |
240 Terminator_lock->wait(); | |
241 } | |
242 } | |
1282 | 243 if (G1TraceConcRefinement) { |
244 gclog_or_tty->print_cr("G1-Refine-stop"); | |
245 } | |
342 | 246 } |
247 | |
1019 | 248 void ConcurrentG1RefineThread::print() const { |
249 print_on(tty); | |
342 | 250 } |
1019 | 251 |
252 void ConcurrentG1RefineThread::print_on(outputStream* st) const { | |
253 st->print("\"G1 Concurrent Refinement Thread#%d\" ", _worker_id); | |
254 Thread::print_on(st); | |
255 st->cr(); | |
256 } |