Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/g1/concurrentG1RefineThread.cpp @ 1779:6eddcbe17c83
6981746: G1: SEGV with -XX:+TraceGen0Time
Summary: Pass correct value for length to NumberSeq constructor. Guard dereferences of "body_summary" pointer with a NULL check.
Reviewed-by: tonyp, ysr
author | johnc |
---|---|
date | Mon, 13 Sep 2010 10:00:24 -0700 |
parents | c18cbe5936b8 |
children | f95d63e2154a |
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 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_concurrentG1RefineThread.cpp.incl" | |
27 | |
28 ConcurrentG1RefineThread:: | |
795
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
29 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next, |
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
30 int worker_id_offset, int worker_id) : |
342 | 31 ConcurrentGCThread(), |
795
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
32 _worker_id_offset(worker_id_offset), |
794 | 33 _worker_id(worker_id), |
34 _active(false), | |
35 _next(next), | |
1111 | 36 _monitor(NULL), |
342 | 37 _cg1r(cg1r), |
1111 | 38 _vtime_accum(0.0) |
342 | 39 { |
1111 | 40 |
41 // Each thread has its own monitor. The i-th thread is responsible for signalling | |
42 // to thread i+1 if the number of buffers in the queue exceeds a threashold for this | |
43 // thread. Monitors are also used to wake up the threads during termination. | |
44 // The 0th worker in notified by mutator threads and has a special monitor. | |
45 // The last worker is used for young gen rset size sampling. | |
46 if (worker_id > 0) { | |
47 _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true); | |
48 } else { | |
49 _monitor = DirtyCardQ_CBL_mon; | |
50 } | |
51 initialize(); | |
342 | 52 create_and_start(); |
53 } | |
54 | |
1111 | 55 void ConcurrentG1RefineThread::initialize() { |
56 if (_worker_id < cg1r()->worker_thread_num()) { | |
57 // Current thread activation threshold | |
58 _threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(), | |
59 cg1r()->yellow_zone()); | |
60 // A thread deactivates once the number of buffer reached a deactivation threshold | |
61 _deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone()); | |
62 } else { | |
63 set_active(true); | |
64 } | |
65 } | |
66 | |
342 | 67 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() { |
68 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
69 G1CollectorPolicy* g1p = g1h->g1_policy(); | |
70 if (g1p->adaptive_young_list_length()) { | |
71 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
|
72 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
|
73 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
|
74 g1h->young_list()->rs_length_sampling_next(); |
342 | 75 ++regions_visited; |
76 | |
77 // we try to yield every time we visit 10 regions | |
78 if (regions_visited == 10) { | |
79 if (_sts.should_yield()) { | |
80 _sts.yield("G1 refine"); | |
81 // we just abandon the iteration | |
82 break; | |
83 } | |
84 regions_visited = 0; | |
85 } | |
86 } | |
87 | |
88 g1p->check_prediction_validity(); | |
89 } | |
90 } | |
91 | |
1111 | 92 void ConcurrentG1RefineThread::run_young_rs_sampling() { |
93 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
342 | 94 _vtime_start = os::elapsedVTime(); |
1111 | 95 while(!_should_terminate) { |
96 _sts.join(); | |
97 sample_young_list_rs_lengths(); | |
98 _sts.leave(); | |
342 | 99 |
1111 | 100 if (os::supports_vtime()) { |
101 _vtime_accum = (os::elapsedVTime() - _vtime_start); | |
102 } else { | |
103 _vtime_accum = 0.0; | |
794 | 104 } |
105 | |
1111 | 106 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
107 if (_should_terminate) { | |
108 break; | |
109 } | |
1282 | 110 _monitor->wait(Mutex::_no_safepoint_check_flag, G1ConcRefinementServiceIntervalMillis); |
1111 | 111 } |
112 } | |
794 | 113 |
1111 | 114 void ConcurrentG1RefineThread::wait_for_completed_buffers() { |
115 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
116 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
117 while (!_should_terminate && !is_active()) { | |
118 _monitor->wait(Mutex::_no_safepoint_check_flag); | |
119 } | |
120 } | |
121 | |
122 bool ConcurrentG1RefineThread::is_active() { | |
123 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
124 return _worker_id > 0 ? _active : dcqs.process_completed_buffers(); | |
125 } | |
126 | |
127 void ConcurrentG1RefineThread::activate() { | |
128 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
129 if (_worker_id > 0) { | |
1282 | 130 if (G1TraceConcRefinement) { |
1111 | 131 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
132 gclog_or_tty->print_cr("G1-Refine-activated worker %d, on threshold %d, current %d", | |
133 _worker_id, _threshold, (int)dcqs.completed_buffers_num()); | |
342 | 134 } |
1111 | 135 set_active(true); |
136 } else { | |
137 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
138 dcqs.set_process_completed(true); | |
139 } | |
140 _monitor->notify(); | |
141 } | |
794 | 142 |
1111 | 143 void ConcurrentG1RefineThread::deactivate() { |
144 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
145 if (_worker_id > 0) { | |
1282 | 146 if (G1TraceConcRefinement) { |
1111 | 147 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
148 gclog_or_tty->print_cr("G1-Refine-deactivated worker %d, off threshold %d, current %d", | |
149 _worker_id, _deactivation_threshold, (int)dcqs.completed_buffers_num()); | |
150 } | |
151 set_active(false); | |
152 } else { | |
153 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
154 dcqs.set_process_completed(false); | |
155 } | |
156 } | |
157 | |
158 void ConcurrentG1RefineThread::run() { | |
159 initialize_in_thread(); | |
160 wait_for_universe_init(); | |
794 | 161 |
1111 | 162 if (_worker_id >= cg1r()->worker_thread_num()) { |
163 run_young_rs_sampling(); | |
164 terminate(); | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1282
diff
changeset
|
165 return; |
1111 | 166 } |
167 | |
168 _vtime_start = os::elapsedVTime(); | |
169 while (!_should_terminate) { | |
170 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
171 | |
172 // Wait for work | |
173 wait_for_completed_buffers(); | |
174 | |
175 if (_should_terminate) { | |
176 break; | |
177 } | |
178 | |
179 _sts.join(); | |
180 | |
181 do { | |
182 int curr_buffer_num = (int)dcqs.completed_buffers_num(); | |
183 // If the number of the buffers falls down into the yellow zone, | |
184 // that means that the transition period after the evacuation pause has ended. | |
185 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { | |
186 dcqs.set_completed_queue_padding(0); | |
794 | 187 } |
1111 | 188 |
189 if (_worker_id > 0 && curr_buffer_num <= _deactivation_threshold) { | |
794 | 190 // If the number of the buffer has fallen below our threshold |
191 // we should deactivate. The predecessor will reactivate this | |
192 // thread should the number of the buffers cross the threshold again. | |
193 deactivate(); | |
194 break; | |
195 } | |
196 | |
197 // Check if we need to activate the next thread. | |
1111 | 198 if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { |
794 | 199 _next->activate(); |
200 } | |
1111 | 201 } while (dcqs.apply_closure_to_completed_buffer(_worker_id + _worker_id_offset, cg1r()->green_zone())); |
794 | 202 |
1111 | 203 // We can exit the loop above while being active if there was a yield request. |
204 if (is_active()) { | |
205 deactivate(); | |
794 | 206 } |
1111 | 207 |
342 | 208 _sts.leave(); |
794 | 209 |
342 | 210 if (os::supports_vtime()) { |
211 _vtime_accum = (os::elapsedVTime() - _vtime_start); | |
212 } else { | |
213 _vtime_accum = 0.0; | |
214 } | |
215 } | |
216 assert(_should_terminate, "just checking"); | |
217 terminate(); | |
218 } | |
219 | |
220 | |
221 void ConcurrentG1RefineThread::yield() { | |
1282 | 222 if (G1TraceConcRefinement) { |
223 gclog_or_tty->print_cr("G1-Refine-yield"); | |
224 } | |
342 | 225 _sts.yield("G1 refine"); |
1282 | 226 if (G1TraceConcRefinement) { |
227 gclog_or_tty->print_cr("G1-Refine-yield-end"); | |
228 } | |
342 | 229 } |
230 | |
231 void ConcurrentG1RefineThread::stop() { | |
232 // it is ok to take late safepoints here, if needed | |
233 { | |
234 MutexLockerEx mu(Terminator_lock); | |
235 _should_terminate = true; | |
236 } | |
237 | |
238 { | |
1111 | 239 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
240 _monitor->notify(); | |
342 | 241 } |
242 | |
243 { | |
244 MutexLockerEx mu(Terminator_lock); | |
245 while (!_has_terminated) { | |
246 Terminator_lock->wait(); | |
247 } | |
248 } | |
1282 | 249 if (G1TraceConcRefinement) { |
250 gclog_or_tty->print_cr("G1-Refine-stop"); | |
251 } | |
342 | 252 } |
253 | |
1019 | 254 void ConcurrentG1RefineThread::print() const { |
255 print_on(tty); | |
342 | 256 } |
1019 | 257 |
258 void ConcurrentG1RefineThread::print_on(outputStream* st) const { | |
259 st->print("\"G1 Concurrent Refinement Thread#%d\" ", _worker_id); | |
260 Thread::print_on(st); | |
261 st->cr(); | |
262 } |