Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/g1/concurrentMark.cpp @ 1030:dfdaf65c3423
6858886: G1: guarantee(_next_marked_bytes <= used(),"invariant") at heapRegion.hpp:359
Reviewed-by: tonyp, ysr
author | apetrusenko |
---|---|
date | Thu, 22 Oct 2009 07:43:49 -0700 |
parents | 11d4857fe5e1 |
children | 6270f80a7331 |
rev | line source |
---|---|
342 | 1 /* |
844 | 2 * Copyright 2001-2009 Sun Microsystems, Inc. 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 * | |
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/_concurrentMark.cpp.incl" | |
27 | |
28 // | |
29 // CMS Bit Map Wrapper | |
30 | |
31 CMBitMapRO::CMBitMapRO(ReservedSpace rs, int shifter): | |
32 _bm((uintptr_t*)NULL,0), | |
33 _shifter(shifter) { | |
34 _bmStartWord = (HeapWord*)(rs.base()); | |
35 _bmWordSize = rs.size()/HeapWordSize; // rs.size() is in bytes | |
36 ReservedSpace brs(ReservedSpace::allocation_align_size_up( | |
37 (_bmWordSize >> (_shifter + LogBitsPerByte)) + 1)); | |
38 | |
39 guarantee(brs.is_reserved(), "couldn't allocate CMS bit map"); | |
40 // For now we'll just commit all of the bit map up fromt. | |
41 // Later on we'll try to be more parsimonious with swap. | |
42 guarantee(_virtual_space.initialize(brs, brs.size()), | |
43 "couldn't reseve backing store for CMS bit map"); | |
44 assert(_virtual_space.committed_size() == brs.size(), | |
45 "didn't reserve backing store for all of CMS bit map?"); | |
46 _bm.set_map((uintptr_t*)_virtual_space.low()); | |
47 assert(_virtual_space.committed_size() << (_shifter + LogBitsPerByte) >= | |
48 _bmWordSize, "inconsistency in bit map sizing"); | |
49 _bm.set_size(_bmWordSize >> _shifter); | |
50 } | |
51 | |
52 HeapWord* CMBitMapRO::getNextMarkedWordAddress(HeapWord* addr, | |
53 HeapWord* limit) const { | |
54 // First we must round addr *up* to a possible object boundary. | |
55 addr = (HeapWord*)align_size_up((intptr_t)addr, | |
56 HeapWordSize << _shifter); | |
57 size_t addrOffset = heapWordToOffset(addr); | |
58 if (limit == NULL) limit = _bmStartWord + _bmWordSize; | |
59 size_t limitOffset = heapWordToOffset(limit); | |
60 size_t nextOffset = _bm.get_next_one_offset(addrOffset, limitOffset); | |
61 HeapWord* nextAddr = offsetToHeapWord(nextOffset); | |
62 assert(nextAddr >= addr, "get_next_one postcondition"); | |
63 assert(nextAddr == limit || isMarked(nextAddr), | |
64 "get_next_one postcondition"); | |
65 return nextAddr; | |
66 } | |
67 | |
68 HeapWord* CMBitMapRO::getNextUnmarkedWordAddress(HeapWord* addr, | |
69 HeapWord* limit) const { | |
70 size_t addrOffset = heapWordToOffset(addr); | |
71 if (limit == NULL) limit = _bmStartWord + _bmWordSize; | |
72 size_t limitOffset = heapWordToOffset(limit); | |
73 size_t nextOffset = _bm.get_next_zero_offset(addrOffset, limitOffset); | |
74 HeapWord* nextAddr = offsetToHeapWord(nextOffset); | |
75 assert(nextAddr >= addr, "get_next_one postcondition"); | |
76 assert(nextAddr == limit || !isMarked(nextAddr), | |
77 "get_next_one postcondition"); | |
78 return nextAddr; | |
79 } | |
80 | |
81 int CMBitMapRO::heapWordDiffToOffsetDiff(size_t diff) const { | |
82 assert((diff & ((1 << _shifter) - 1)) == 0, "argument check"); | |
83 return (int) (diff >> _shifter); | |
84 } | |
85 | |
86 bool CMBitMapRO::iterate(BitMapClosure* cl, MemRegion mr) { | |
87 HeapWord* left = MAX2(_bmStartWord, mr.start()); | |
88 HeapWord* right = MIN2(_bmStartWord + _bmWordSize, mr.end()); | |
89 if (right > left) { | |
90 // Right-open interval [leftOffset, rightOffset). | |
91 return _bm.iterate(cl, heapWordToOffset(left), heapWordToOffset(right)); | |
92 } else { | |
93 return true; | |
94 } | |
95 } | |
96 | |
97 void CMBitMapRO::mostly_disjoint_range_union(BitMap* from_bitmap, | |
98 size_t from_start_index, | |
99 HeapWord* to_start_word, | |
100 size_t word_num) { | |
101 _bm.mostly_disjoint_range_union(from_bitmap, | |
102 from_start_index, | |
103 heapWordToOffset(to_start_word), | |
104 word_num); | |
105 } | |
106 | |
107 #ifndef PRODUCT | |
108 bool CMBitMapRO::covers(ReservedSpace rs) const { | |
109 // assert(_bm.map() == _virtual_space.low(), "map inconsistency"); | |
645
c3a720eefe82
6816308: Changes to allow builds with latest Windows SDK 6.1 on 64bit Windows 2003
kvn
parents:
619
diff
changeset
|
110 assert(((size_t)_bm.size() * (size_t)(1 << _shifter)) == _bmWordSize, |
342 | 111 "size inconsistency"); |
112 return _bmStartWord == (HeapWord*)(rs.base()) && | |
113 _bmWordSize == rs.size()>>LogHeapWordSize; | |
114 } | |
115 #endif | |
116 | |
117 void CMBitMap::clearAll() { | |
118 _bm.clear(); | |
119 return; | |
120 } | |
121 | |
122 void CMBitMap::markRange(MemRegion mr) { | |
123 mr.intersection(MemRegion(_bmStartWord, _bmWordSize)); | |
124 assert(!mr.is_empty(), "unexpected empty region"); | |
125 assert((offsetToHeapWord(heapWordToOffset(mr.end())) == | |
126 ((HeapWord *) mr.end())), | |
127 "markRange memory region end is not card aligned"); | |
128 // convert address range into offset range | |
129 _bm.at_put_range(heapWordToOffset(mr.start()), | |
130 heapWordToOffset(mr.end()), true); | |
131 } | |
132 | |
133 void CMBitMap::clearRange(MemRegion mr) { | |
134 mr.intersection(MemRegion(_bmStartWord, _bmWordSize)); | |
135 assert(!mr.is_empty(), "unexpected empty region"); | |
136 // convert address range into offset range | |
137 _bm.at_put_range(heapWordToOffset(mr.start()), | |
138 heapWordToOffset(mr.end()), false); | |
139 } | |
140 | |
141 MemRegion CMBitMap::getAndClearMarkedRegion(HeapWord* addr, | |
142 HeapWord* end_addr) { | |
143 HeapWord* start = getNextMarkedWordAddress(addr); | |
144 start = MIN2(start, end_addr); | |
145 HeapWord* end = getNextUnmarkedWordAddress(start); | |
146 end = MIN2(end, end_addr); | |
147 assert(start <= end, "Consistency check"); | |
148 MemRegion mr(start, end); | |
149 if (!mr.is_empty()) { | |
150 clearRange(mr); | |
151 } | |
152 return mr; | |
153 } | |
154 | |
155 CMMarkStack::CMMarkStack(ConcurrentMark* cm) : | |
156 _base(NULL), _cm(cm) | |
157 #ifdef ASSERT | |
158 , _drain_in_progress(false) | |
159 , _drain_in_progress_yields(false) | |
160 #endif | |
161 {} | |
162 | |
163 void CMMarkStack::allocate(size_t size) { | |
164 _base = NEW_C_HEAP_ARRAY(oop, size); | |
165 if (_base == NULL) | |
166 vm_exit_during_initialization("Failed to allocate " | |
167 "CM region mark stack"); | |
168 _index = 0; | |
169 // QQQQ cast ... | |
170 _capacity = (jint) size; | |
171 _oops_do_bound = -1; | |
172 NOT_PRODUCT(_max_depth = 0); | |
173 } | |
174 | |
175 CMMarkStack::~CMMarkStack() { | |
176 if (_base != NULL) FREE_C_HEAP_ARRAY(oop, _base); | |
177 } | |
178 | |
179 void CMMarkStack::par_push(oop ptr) { | |
180 while (true) { | |
181 if (isFull()) { | |
182 _overflow = true; | |
183 return; | |
184 } | |
185 // Otherwise... | |
186 jint index = _index; | |
187 jint next_index = index+1; | |
188 jint res = Atomic::cmpxchg(next_index, &_index, index); | |
189 if (res == index) { | |
190 _base[index] = ptr; | |
191 // Note that we don't maintain this atomically. We could, but it | |
192 // doesn't seem necessary. | |
193 NOT_PRODUCT(_max_depth = MAX2(_max_depth, next_index)); | |
194 return; | |
195 } | |
196 // Otherwise, we need to try again. | |
197 } | |
198 } | |
199 | |
200 void CMMarkStack::par_adjoin_arr(oop* ptr_arr, int n) { | |
201 while (true) { | |
202 if (isFull()) { | |
203 _overflow = true; | |
204 return; | |
205 } | |
206 // Otherwise... | |
207 jint index = _index; | |
208 jint next_index = index + n; | |
209 if (next_index > _capacity) { | |
210 _overflow = true; | |
211 return; | |
212 } | |
213 jint res = Atomic::cmpxchg(next_index, &_index, index); | |
214 if (res == index) { | |
215 for (int i = 0; i < n; i++) { | |
216 int ind = index + i; | |
217 assert(ind < _capacity, "By overflow test above."); | |
218 _base[ind] = ptr_arr[i]; | |
219 } | |
220 NOT_PRODUCT(_max_depth = MAX2(_max_depth, next_index)); | |
221 return; | |
222 } | |
223 // Otherwise, we need to try again. | |
224 } | |
225 } | |
226 | |
227 | |
228 void CMMarkStack::par_push_arr(oop* ptr_arr, int n) { | |
229 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
230 jint start = _index; | |
231 jint next_index = start + n; | |
232 if (next_index > _capacity) { | |
233 _overflow = true; | |
234 return; | |
235 } | |
236 // Otherwise. | |
237 _index = next_index; | |
238 for (int i = 0; i < n; i++) { | |
239 int ind = start + i; | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
240 assert(ind < _capacity, "By overflow test above."); |
342 | 241 _base[ind] = ptr_arr[i]; |
242 } | |
243 } | |
244 | |
245 | |
246 bool CMMarkStack::par_pop_arr(oop* ptr_arr, int max, int* n) { | |
247 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
248 jint index = _index; | |
249 if (index == 0) { | |
250 *n = 0; | |
251 return false; | |
252 } else { | |
253 int k = MIN2(max, index); | |
254 jint new_ind = index - k; | |
255 for (int j = 0; j < k; j++) { | |
256 ptr_arr[j] = _base[new_ind + j]; | |
257 } | |
258 _index = new_ind; | |
259 *n = k; | |
260 return true; | |
261 } | |
262 } | |
263 | |
264 | |
265 CMRegionStack::CMRegionStack() : _base(NULL) {} | |
266 | |
267 void CMRegionStack::allocate(size_t size) { | |
268 _base = NEW_C_HEAP_ARRAY(MemRegion, size); | |
269 if (_base == NULL) | |
270 vm_exit_during_initialization("Failed to allocate " | |
271 "CM region mark stack"); | |
272 _index = 0; | |
273 // QQQQ cast ... | |
274 _capacity = (jint) size; | |
275 } | |
276 | |
277 CMRegionStack::~CMRegionStack() { | |
278 if (_base != NULL) FREE_C_HEAP_ARRAY(oop, _base); | |
279 } | |
280 | |
281 void CMRegionStack::push(MemRegion mr) { | |
282 assert(mr.word_size() > 0, "Precondition"); | |
283 while (true) { | |
284 if (isFull()) { | |
285 _overflow = true; | |
286 return; | |
287 } | |
288 // Otherwise... | |
289 jint index = _index; | |
290 jint next_index = index+1; | |
291 jint res = Atomic::cmpxchg(next_index, &_index, index); | |
292 if (res == index) { | |
293 _base[index] = mr; | |
294 return; | |
295 } | |
296 // Otherwise, we need to try again. | |
297 } | |
298 } | |
299 | |
300 MemRegion CMRegionStack::pop() { | |
301 while (true) { | |
302 // Otherwise... | |
303 jint index = _index; | |
304 | |
305 if (index == 0) { | |
306 return MemRegion(); | |
307 } | |
308 jint next_index = index-1; | |
309 jint res = Atomic::cmpxchg(next_index, &_index, index); | |
310 if (res == index) { | |
311 MemRegion mr = _base[next_index]; | |
312 if (mr.start() != NULL) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
313 assert(mr.end() != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
314 assert(mr.word_size() > 0, "invariant"); |
342 | 315 return mr; |
316 } else { | |
317 // that entry was invalidated... let's skip it | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
318 assert(mr.end() == NULL, "invariant"); |
342 | 319 } |
320 } | |
321 // Otherwise, we need to try again. | |
322 } | |
323 } | |
324 | |
325 bool CMRegionStack::invalidate_entries_into_cset() { | |
326 bool result = false; | |
327 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
328 for (int i = 0; i < _oops_do_bound; ++i) { | |
329 MemRegion mr = _base[i]; | |
330 if (mr.start() != NULL) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
331 assert(mr.end() != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
332 assert(mr.word_size() > 0, "invariant"); |
342 | 333 HeapRegion* hr = g1h->heap_region_containing(mr.start()); |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
334 assert(hr != NULL, "invariant"); |
342 | 335 if (hr->in_collection_set()) { |
336 // The region points into the collection set | |
337 _base[i] = MemRegion(); | |
338 result = true; | |
339 } | |
340 } else { | |
341 // that entry was invalidated... let's skip it | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
342 assert(mr.end() == NULL, "invariant"); |
342 | 343 } |
344 } | |
345 return result; | |
346 } | |
347 | |
348 template<class OopClosureClass> | |
349 bool CMMarkStack::drain(OopClosureClass* cl, CMBitMap* bm, bool yield_after) { | |
350 assert(!_drain_in_progress || !_drain_in_progress_yields || yield_after | |
351 || SafepointSynchronize::is_at_safepoint(), | |
352 "Drain recursion must be yield-safe."); | |
353 bool res = true; | |
354 debug_only(_drain_in_progress = true); | |
355 debug_only(_drain_in_progress_yields = yield_after); | |
356 while (!isEmpty()) { | |
357 oop newOop = pop(); | |
358 assert(G1CollectedHeap::heap()->is_in_reserved(newOop), "Bad pop"); | |
359 assert(newOop->is_oop(), "Expected an oop"); | |
360 assert(bm == NULL || bm->isMarked((HeapWord*)newOop), | |
361 "only grey objects on this stack"); | |
362 // iterate over the oops in this oop, marking and pushing | |
363 // the ones in CMS generation. | |
364 newOop->oop_iterate(cl); | |
365 if (yield_after && _cm->do_yield_check()) { | |
366 res = false; break; | |
367 } | |
368 } | |
369 debug_only(_drain_in_progress = false); | |
370 return res; | |
371 } | |
372 | |
373 void CMMarkStack::oops_do(OopClosure* f) { | |
374 if (_index == 0) return; | |
375 assert(_oops_do_bound != -1 && _oops_do_bound <= _index, | |
376 "Bound must be set."); | |
377 for (int i = 0; i < _oops_do_bound; i++) { | |
378 f->do_oop(&_base[i]); | |
379 } | |
380 _oops_do_bound = -1; | |
381 } | |
382 | |
383 bool ConcurrentMark::not_yet_marked(oop obj) const { | |
384 return (_g1h->is_obj_ill(obj) | |
385 || (_g1h->is_in_permanent(obj) | |
386 && !nextMarkBitMap()->isMarked((HeapWord*)obj))); | |
387 } | |
388 | |
389 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away | |
390 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list | |
391 #endif // _MSC_VER | |
392 | |
393 ConcurrentMark::ConcurrentMark(ReservedSpace rs, | |
394 int max_regions) : | |
395 _markBitMap1(rs, MinObjAlignment - 1), | |
396 _markBitMap2(rs, MinObjAlignment - 1), | |
397 | |
398 _parallel_marking_threads(0), | |
399 _sleep_factor(0.0), | |
400 _marking_task_overhead(1.0), | |
401 _cleanup_sleep_factor(0.0), | |
402 _cleanup_task_overhead(1.0), | |
403 _region_bm(max_regions, false /* in_resource_area*/), | |
404 _card_bm((rs.size() + CardTableModRefBS::card_size - 1) >> | |
405 CardTableModRefBS::card_shift, | |
406 false /* in_resource_area*/), | |
407 _prevMarkBitMap(&_markBitMap1), | |
408 _nextMarkBitMap(&_markBitMap2), | |
409 _at_least_one_mark_complete(false), | |
410 | |
411 _markStack(this), | |
412 _regionStack(), | |
413 // _finger set in set_non_marking_state | |
414 | |
415 _max_task_num(MAX2(ParallelGCThreads, (size_t)1)), | |
416 // _active_tasks set in set_non_marking_state | |
417 // _tasks set inside the constructor | |
418 _task_queues(new CMTaskQueueSet((int) _max_task_num)), | |
419 _terminator(ParallelTaskTerminator((int) _max_task_num, _task_queues)), | |
420 | |
421 _has_overflown(false), | |
422 _concurrent(false), | |
619
7ea5ca260b28
6814467: G1: small fixes related to concurrent marking verboseness
tonyp
parents:
470
diff
changeset
|
423 _has_aborted(false), |
7ea5ca260b28
6814467: G1: small fixes related to concurrent marking verboseness
tonyp
parents:
470
diff
changeset
|
424 _restart_for_overflow(false), |
7ea5ca260b28
6814467: G1: small fixes related to concurrent marking verboseness
tonyp
parents:
470
diff
changeset
|
425 _concurrent_marking_in_progress(false), |
7ea5ca260b28
6814467: G1: small fixes related to concurrent marking verboseness
tonyp
parents:
470
diff
changeset
|
426 _should_gray_objects(false), |
342 | 427 |
428 // _verbose_level set below | |
429 | |
430 _init_times(), | |
431 _remark_times(), _remark_mark_times(), _remark_weak_ref_times(), | |
432 _cleanup_times(), | |
433 _total_counting_time(0.0), | |
434 _total_rs_scrub_time(0.0), | |
435 | |
936 | 436 _parallel_workers(NULL) |
342 | 437 { |
438 CMVerboseLevel verbose_level = | |
439 (CMVerboseLevel) G1MarkingVerboseLevel; | |
440 if (verbose_level < no_verbose) | |
441 verbose_level = no_verbose; | |
442 if (verbose_level > high_verbose) | |
443 verbose_level = high_verbose; | |
444 _verbose_level = verbose_level; | |
445 | |
446 if (verbose_low()) | |
447 gclog_or_tty->print_cr("[global] init, heap start = "PTR_FORMAT", " | |
448 "heap end = "PTR_FORMAT, _heap_start, _heap_end); | |
449 | |
751 | 450 _markStack.allocate(G1MarkStackSize); |
451 _regionStack.allocate(G1MarkRegionStackSize); | |
342 | 452 |
453 // Create & start a ConcurrentMark thread. | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
454 _cmThread = new ConcurrentMarkThread(this); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
455 assert(cmThread() != NULL, "CM Thread should have been created"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
456 assert(cmThread()->cm() != NULL, "CM Thread should refer to this cm"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
457 |
342 | 458 _g1h = G1CollectedHeap::heap(); |
459 assert(CGC_lock != NULL, "Where's the CGC_lock?"); | |
460 assert(_markBitMap1.covers(rs), "_markBitMap1 inconsistency"); | |
461 assert(_markBitMap2.covers(rs), "_markBitMap2 inconsistency"); | |
462 | |
463 SATBMarkQueueSet& satb_qs = JavaThread::satb_mark_queue_set(); | |
464 satb_qs.set_buffer_size(G1SATBLogBufferSize); | |
465 | |
466 int size = (int) MAX2(ParallelGCThreads, (size_t)1); | |
467 _par_cleanup_thread_state = NEW_C_HEAP_ARRAY(ParCleanupThreadState*, size); | |
468 for (int i = 0 ; i < size; i++) { | |
469 _par_cleanup_thread_state[i] = new ParCleanupThreadState; | |
470 } | |
471 | |
472 _tasks = NEW_C_HEAP_ARRAY(CMTask*, _max_task_num); | |
473 _accum_task_vtime = NEW_C_HEAP_ARRAY(double, _max_task_num); | |
474 | |
475 // so that the assertion in MarkingTaskQueue::task_queue doesn't fail | |
476 _active_tasks = _max_task_num; | |
477 for (int i = 0; i < (int) _max_task_num; ++i) { | |
478 CMTaskQueue* task_queue = new CMTaskQueue(); | |
479 task_queue->initialize(); | |
480 _task_queues->register_queue(i, task_queue); | |
481 | |
482 _tasks[i] = new CMTask(i, this, task_queue, _task_queues); | |
483 _accum_task_vtime[i] = 0.0; | |
484 } | |
485 | |
486 if (ParallelMarkingThreads > ParallelGCThreads) { | |
487 vm_exit_during_initialization("Can't have more ParallelMarkingThreads " | |
488 "than ParallelGCThreads."); | |
489 } | |
490 if (ParallelGCThreads == 0) { | |
491 // if we are not running with any parallel GC threads we will not | |
492 // spawn any marking threads either | |
493 _parallel_marking_threads = 0; | |
494 _sleep_factor = 0.0; | |
495 _marking_task_overhead = 1.0; | |
496 } else { | |
497 if (ParallelMarkingThreads > 0) { | |
751 | 498 // notice that ParallelMarkingThreads overwrites G1MarkingOverheadPercent |
342 | 499 // if both are set |
500 | |
501 _parallel_marking_threads = ParallelMarkingThreads; | |
502 _sleep_factor = 0.0; | |
503 _marking_task_overhead = 1.0; | |
751 | 504 } else if (G1MarkingOverheadPercent > 0) { |
342 | 505 // we will calculate the number of parallel marking threads |
506 // based on a target overhead with respect to the soft real-time | |
507 // goal | |
508 | |
751 | 509 double marking_overhead = (double) G1MarkingOverheadPercent / 100.0; |
342 | 510 double overall_cm_overhead = |
751 | 511 (double) MaxGCPauseMillis * marking_overhead / |
512 (double) GCPauseIntervalMillis; | |
342 | 513 double cpu_ratio = 1.0 / (double) os::processor_count(); |
514 double marking_thread_num = ceil(overall_cm_overhead / cpu_ratio); | |
515 double marking_task_overhead = | |
516 overall_cm_overhead / marking_thread_num * | |
517 (double) os::processor_count(); | |
518 double sleep_factor = | |
519 (1.0 - marking_task_overhead) / marking_task_overhead; | |
520 | |
521 _parallel_marking_threads = (size_t) marking_thread_num; | |
522 _sleep_factor = sleep_factor; | |
523 _marking_task_overhead = marking_task_overhead; | |
524 } else { | |
525 _parallel_marking_threads = MAX2((ParallelGCThreads + 2) / 4, (size_t)1); | |
526 _sleep_factor = 0.0; | |
527 _marking_task_overhead = 1.0; | |
528 } | |
529 | |
530 if (parallel_marking_threads() > 1) | |
531 _cleanup_task_overhead = 1.0; | |
532 else | |
533 _cleanup_task_overhead = marking_task_overhead(); | |
534 _cleanup_sleep_factor = | |
535 (1.0 - cleanup_task_overhead()) / cleanup_task_overhead(); | |
536 | |
537 #if 0 | |
538 gclog_or_tty->print_cr("Marking Threads %d", parallel_marking_threads()); | |
539 gclog_or_tty->print_cr("CM Marking Task Overhead %1.4lf", marking_task_overhead()); | |
540 gclog_or_tty->print_cr("CM Sleep Factor %1.4lf", sleep_factor()); | |
541 gclog_or_tty->print_cr("CL Marking Task Overhead %1.4lf", cleanup_task_overhead()); | |
542 gclog_or_tty->print_cr("CL Sleep Factor %1.4lf", cleanup_sleep_factor()); | |
543 #endif | |
544 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
545 guarantee(parallel_marking_threads() > 0, "peace of mind"); |
1019 | 546 _parallel_workers = new WorkGang("G1 Parallel Marking Threads", |
342 | 547 (int) parallel_marking_threads(), false, true); |
548 if (_parallel_workers == NULL) | |
549 vm_exit_during_initialization("Failed necessary allocation."); | |
550 } | |
551 | |
552 // so that the call below can read a sensible value | |
553 _heap_start = (HeapWord*) rs.base(); | |
554 set_non_marking_state(); | |
555 } | |
556 | |
557 void ConcurrentMark::update_g1_committed(bool force) { | |
558 // If concurrent marking is not in progress, then we do not need to | |
559 // update _heap_end. This has a subtle and important | |
560 // side-effect. Imagine that two evacuation pauses happen between | |
561 // marking completion and remark. The first one can grow the | |
562 // heap (hence now the finger is below the heap end). Then, the | |
563 // second one could unnecessarily push regions on the region | |
564 // stack. This causes the invariant that the region stack is empty | |
565 // at the beginning of remark to be false. By ensuring that we do | |
566 // not observe heap expansions after marking is complete, then we do | |
567 // not have this problem. | |
568 if (!concurrent_marking_in_progress() && !force) | |
569 return; | |
570 | |
571 MemRegion committed = _g1h->g1_committed(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
572 assert(committed.start() == _heap_start, "start shouldn't change"); |
342 | 573 HeapWord* new_end = committed.end(); |
574 if (new_end > _heap_end) { | |
575 // The heap has been expanded. | |
576 | |
577 _heap_end = new_end; | |
578 } | |
579 // Notice that the heap can also shrink. However, this only happens | |
580 // during a Full GC (at least currently) and the entire marking | |
581 // phase will bail out and the task will not be restarted. So, let's | |
582 // do nothing. | |
583 } | |
584 | |
585 void ConcurrentMark::reset() { | |
586 // Starting values for these two. This should be called in a STW | |
587 // phase. CM will be notified of any future g1_committed expansions | |
588 // will be at the end of evacuation pauses, when tasks are | |
589 // inactive. | |
590 MemRegion committed = _g1h->g1_committed(); | |
591 _heap_start = committed.start(); | |
592 _heap_end = committed.end(); | |
593 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
594 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
595 assert(_heap_start != NULL, "heap bounds should look ok"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
596 assert(_heap_end != NULL, "heap bounds should look ok"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
597 assert(_heap_start < _heap_end, "heap bounds should look ok"); |
342 | 598 |
599 // reset all the marking data structures and any necessary flags | |
600 clear_marking_state(); | |
601 | |
602 if (verbose_low()) | |
603 gclog_or_tty->print_cr("[global] resetting"); | |
604 | |
605 // We do reset all of them, since different phases will use | |
606 // different number of active threads. So, it's easiest to have all | |
607 // of them ready. | |
608 for (int i = 0; i < (int) _max_task_num; ++i) | |
609 _tasks[i]->reset(_nextMarkBitMap); | |
610 | |
611 // we need this to make sure that the flag is on during the evac | |
612 // pause with initial mark piggy-backed | |
613 set_concurrent_marking_in_progress(); | |
614 } | |
615 | |
616 void ConcurrentMark::set_phase(size_t active_tasks, bool concurrent) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
617 assert(active_tasks <= _max_task_num, "we should not have more"); |
342 | 618 |
619 _active_tasks = active_tasks; | |
620 // Need to update the three data structures below according to the | |
621 // number of active threads for this phase. | |
622 _terminator = ParallelTaskTerminator((int) active_tasks, _task_queues); | |
623 _first_overflow_barrier_sync.set_n_workers((int) active_tasks); | |
624 _second_overflow_barrier_sync.set_n_workers((int) active_tasks); | |
625 | |
626 _concurrent = concurrent; | |
627 // We propagate this to all tasks, not just the active ones. | |
628 for (int i = 0; i < (int) _max_task_num; ++i) | |
629 _tasks[i]->set_concurrent(concurrent); | |
630 | |
631 if (concurrent) { | |
632 set_concurrent_marking_in_progress(); | |
633 } else { | |
634 // We currently assume that the concurrent flag has been set to | |
635 // false before we start remark. At this point we should also be | |
636 // in a STW phase. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
637 assert(!concurrent_marking_in_progress(), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
638 assert(_finger == _heap_end, "only way to get here"); |
342 | 639 update_g1_committed(true); |
640 } | |
641 } | |
642 | |
643 void ConcurrentMark::set_non_marking_state() { | |
644 // We set the global marking state to some default values when we're | |
645 // not doing marking. | |
646 clear_marking_state(); | |
647 _active_tasks = 0; | |
648 clear_concurrent_marking_in_progress(); | |
649 } | |
650 | |
651 ConcurrentMark::~ConcurrentMark() { | |
652 int size = (int) MAX2(ParallelGCThreads, (size_t)1); | |
653 for (int i = 0; i < size; i++) delete _par_cleanup_thread_state[i]; | |
654 FREE_C_HEAP_ARRAY(ParCleanupThreadState*, | |
655 _par_cleanup_thread_state); | |
656 | |
657 for (int i = 0; i < (int) _max_task_num; ++i) { | |
658 delete _task_queues->queue(i); | |
659 delete _tasks[i]; | |
660 } | |
661 delete _task_queues; | |
662 FREE_C_HEAP_ARRAY(CMTask*, _max_task_num); | |
663 } | |
664 | |
665 // This closure is used to mark refs into the g1 generation | |
666 // from external roots in the CMS bit map. | |
667 // Called at the first checkpoint. | |
668 // | |
669 | |
670 #define PRINT_REACHABLE_AT_INITIAL_MARK 0 | |
671 #if PRINT_REACHABLE_AT_INITIAL_MARK | |
672 static FILE* reachable_file = NULL; | |
673 | |
674 class PrintReachableClosure: public OopsInGenClosure { | |
675 CMBitMap* _bm; | |
676 int _level; | |
677 public: | |
678 PrintReachableClosure(CMBitMap* bm) : | |
679 _bm(bm), _level(0) { | |
680 guarantee(reachable_file != NULL, "pre-condition"); | |
681 } | |
682 void do_oop(oop* p) { | |
683 oop obj = *p; | |
684 HeapWord* obj_addr = (HeapWord*)obj; | |
685 if (obj == NULL) return; | |
686 fprintf(reachable_file, "%d: "PTR_FORMAT" -> "PTR_FORMAT" (%d)\n", | |
687 _level, p, (void*) obj, _bm->isMarked(obj_addr)); | |
688 if (!_bm->isMarked(obj_addr)) { | |
689 _bm->mark(obj_addr); | |
690 _level++; | |
691 obj->oop_iterate(this); | |
692 _level--; | |
693 } | |
694 } | |
695 }; | |
696 #endif // PRINT_REACHABLE_AT_INITIAL_MARK | |
697 | |
698 #define SEND_HEAP_DUMP_TO_FILE 0 | |
699 #if SEND_HEAP_DUMP_TO_FILE | |
700 static FILE* heap_dump_file = NULL; | |
701 #endif // SEND_HEAP_DUMP_TO_FILE | |
702 | |
703 void ConcurrentMark::clearNextBitmap() { | |
704 guarantee(!G1CollectedHeap::heap()->mark_in_progress(), "Precondition."); | |
705 | |
706 // clear the mark bitmap (no grey objects to start with). | |
707 // We need to do this in chunks and offer to yield in between | |
708 // each chunk. | |
709 HeapWord* start = _nextMarkBitMap->startWord(); | |
710 HeapWord* end = _nextMarkBitMap->endWord(); | |
711 HeapWord* cur = start; | |
712 size_t chunkSize = M; | |
713 while (cur < end) { | |
714 HeapWord* next = cur + chunkSize; | |
715 if (next > end) | |
716 next = end; | |
717 MemRegion mr(cur,next); | |
718 _nextMarkBitMap->clearRange(mr); | |
719 cur = next; | |
720 do_yield_check(); | |
721 } | |
722 } | |
723 | |
724 class NoteStartOfMarkHRClosure: public HeapRegionClosure { | |
725 public: | |
726 bool doHeapRegion(HeapRegion* r) { | |
727 if (!r->continuesHumongous()) { | |
728 r->note_start_of_marking(true); | |
729 } | |
730 return false; | |
731 } | |
732 }; | |
733 | |
734 void ConcurrentMark::checkpointRootsInitialPre() { | |
735 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
736 G1CollectorPolicy* g1p = g1h->g1_policy(); | |
737 | |
738 _has_aborted = false; | |
739 | |
740 // Find all the reachable objects... | |
741 #if PRINT_REACHABLE_AT_INITIAL_MARK | |
742 guarantee(reachable_file == NULL, "Protocol"); | |
743 char fn_buf[100]; | |
744 sprintf(fn_buf, "/tmp/reachable.txt.%d", os::current_process_id()); | |
745 reachable_file = fopen(fn_buf, "w"); | |
746 // clear the mark bitmap (no grey objects to start with) | |
747 _nextMarkBitMap->clearAll(); | |
748 PrintReachableClosure prcl(_nextMarkBitMap); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
749 g1h->process_strong_roots(true, // activate StrongRootsScope |
342 | 750 false, // fake perm gen collection |
751 SharedHeap::SO_AllClasses, | |
752 &prcl, // Regular roots | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
753 NULL, // do not visit active blobs |
342 | 754 &prcl // Perm Gen Roots |
755 ); | |
756 // The root iteration above "consumed" dirty cards in the perm gen. | |
757 // Therefore, as a shortcut, we dirty all such cards. | |
758 g1h->rem_set()->invalidate(g1h->perm_gen()->used_region(), false); | |
759 fclose(reachable_file); | |
760 reachable_file = NULL; | |
761 // clear the mark bitmap again. | |
762 _nextMarkBitMap->clearAll(); | |
763 COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); | |
764 COMPILER2_PRESENT(DerivedPointerTable::clear()); | |
765 #endif // PRINT_REACHABLE_AT_INITIAL_MARK | |
766 | |
767 // Initialise marking structures. This has to be done in a STW phase. | |
768 reset(); | |
769 } | |
770 | |
771 class CMMarkRootsClosure: public OopsInGenClosure { | |
772 private: | |
773 ConcurrentMark* _cm; | |
774 G1CollectedHeap* _g1h; | |
775 bool _do_barrier; | |
776 | |
777 public: | |
778 CMMarkRootsClosure(ConcurrentMark* cm, | |
779 G1CollectedHeap* g1h, | |
780 bool do_barrier) : _cm(cm), _g1h(g1h), | |
781 _do_barrier(do_barrier) { } | |
782 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
783 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
784 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
785 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
786 template <class T> void do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
787 T heap_oop = oopDesc::load_heap_oop(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
788 if (!oopDesc::is_null(heap_oop)) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
789 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
790 assert(obj->is_oop() || obj->mark() == NULL, |
342 | 791 "expected an oop, possibly with mark word displaced"); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
792 HeapWord* addr = (HeapWord*)obj; |
342 | 793 if (_g1h->is_in_g1_reserved(addr)) { |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
794 _cm->grayRoot(obj); |
342 | 795 } |
796 } | |
797 if (_do_barrier) { | |
798 assert(!_g1h->is_in_g1_reserved(p), | |
799 "Should be called on external roots"); | |
800 do_barrier(p); | |
801 } | |
802 } | |
803 }; | |
804 | |
805 void ConcurrentMark::checkpointRootsInitialPost() { | |
806 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
807 | |
808 // For each region note start of marking. | |
809 NoteStartOfMarkHRClosure startcl; | |
810 g1h->heap_region_iterate(&startcl); | |
811 | |
812 // Start weak-reference discovery. | |
813 ReferenceProcessor* rp = g1h->ref_processor(); | |
814 rp->verify_no_references_recorded(); | |
815 rp->enable_discovery(); // enable ("weak") refs discovery | |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
816 rp->setup_policy(false); // snapshot the soft ref policy to be used in this cycle |
342 | 817 |
818 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
819 satb_mq_set.set_process_completed_threshold(G1SATBProcessCompletedThreshold); | |
820 satb_mq_set.set_active_all_threads(true); | |
821 | |
822 // update_g1_committed() will be called at the end of an evac pause | |
823 // when marking is on. So, it's also called at the end of the | |
824 // initial-mark pause to update the heap end, if the heap expands | |
825 // during it. No need to call it here. | |
826 } | |
827 | |
828 // Checkpoint the roots into this generation from outside | |
829 // this generation. [Note this initial checkpoint need only | |
830 // be approximate -- we'll do a catch up phase subsequently.] | |
831 void ConcurrentMark::checkpointRootsInitial() { | |
832 assert(SafepointSynchronize::is_at_safepoint(), "world should be stopped"); | |
833 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
834 | |
835 double start = os::elapsedTime(); | |
836 | |
837 G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy(); | |
838 g1p->record_concurrent_mark_init_start(); | |
839 checkpointRootsInitialPre(); | |
840 | |
841 // YSR: when concurrent precleaning is in place, we'll | |
842 // need to clear the cached card table here | |
843 | |
844 ResourceMark rm; | |
845 HandleMark hm; | |
846 | |
847 g1h->ensure_parsability(false); | |
848 g1h->perm_gen()->save_marks(); | |
849 | |
850 CMMarkRootsClosure notOlder(this, g1h, false); | |
851 CMMarkRootsClosure older(this, g1h, true); | |
852 | |
853 g1h->set_marking_started(); | |
854 g1h->rem_set()->prepare_for_younger_refs_iterate(false); | |
855 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
856 g1h->process_strong_roots(true, // activate StrongRootsScope |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
857 false, // fake perm gen collection |
342 | 858 SharedHeap::SO_AllClasses, |
859 ¬Older, // Regular roots | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
860 NULL, // do not visit active blobs |
342 | 861 &older // Perm Gen Roots |
862 ); | |
863 checkpointRootsInitialPost(); | |
864 | |
865 // Statistics. | |
866 double end = os::elapsedTime(); | |
867 _init_times.add((end - start) * 1000.0); | |
868 | |
869 g1p->record_concurrent_mark_init_end(); | |
870 } | |
871 | |
872 /* | |
873 Notice that in the next two methods, we actually leave the STS | |
874 during the barrier sync and join it immediately afterwards. If we | |
875 do not do this, this then the following deadlock can occur: one | |
876 thread could be in the barrier sync code, waiting for the other | |
877 thread to also sync up, whereas another one could be trying to | |
878 yield, while also waiting for the other threads to sync up too. | |
879 | |
880 Because the thread that does the sync barrier has left the STS, it | |
881 is possible to be suspended for a Full GC or an evacuation pause | |
882 could occur. This is actually safe, since the entering the sync | |
883 barrier is one of the last things do_marking_step() does, and it | |
884 doesn't manipulate any data structures afterwards. | |
885 */ | |
886 | |
887 void ConcurrentMark::enter_first_sync_barrier(int task_num) { | |
888 if (verbose_low()) | |
889 gclog_or_tty->print_cr("[%d] entering first barrier", task_num); | |
890 | |
891 ConcurrentGCThread::stsLeave(); | |
892 _first_overflow_barrier_sync.enter(); | |
893 ConcurrentGCThread::stsJoin(); | |
894 // at this point everyone should have synced up and not be doing any | |
895 // more work | |
896 | |
897 if (verbose_low()) | |
898 gclog_or_tty->print_cr("[%d] leaving first barrier", task_num); | |
899 | |
900 // let task 0 do this | |
901 if (task_num == 0) { | |
902 // task 0 is responsible for clearing the global data structures | |
903 clear_marking_state(); | |
904 | |
905 if (PrintGC) { | |
906 gclog_or_tty->date_stamp(PrintGCDateStamps); | |
907 gclog_or_tty->stamp(PrintGCTimeStamps); | |
908 gclog_or_tty->print_cr("[GC concurrent-mark-reset-for-overflow]"); | |
909 } | |
910 } | |
911 | |
912 // after this, each task should reset its own data structures then | |
913 // then go into the second barrier | |
914 } | |
915 | |
916 void ConcurrentMark::enter_second_sync_barrier(int task_num) { | |
917 if (verbose_low()) | |
918 gclog_or_tty->print_cr("[%d] entering second barrier", task_num); | |
919 | |
920 ConcurrentGCThread::stsLeave(); | |
921 _second_overflow_barrier_sync.enter(); | |
922 ConcurrentGCThread::stsJoin(); | |
923 // at this point everything should be re-initialised and ready to go | |
924 | |
925 if (verbose_low()) | |
926 gclog_or_tty->print_cr("[%d] leaving second barrier", task_num); | |
927 } | |
928 | |
929 void ConcurrentMark::grayRoot(oop p) { | |
930 HeapWord* addr = (HeapWord*) p; | |
931 // We can't really check against _heap_start and _heap_end, since it | |
932 // is possible during an evacuation pause with piggy-backed | |
933 // initial-mark that the committed space is expanded during the | |
934 // pause without CM observing this change. So the assertions below | |
935 // is a bit conservative; but better than nothing. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
936 assert(_g1h->g1_committed().contains(addr), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
937 "address should be within the heap bounds"); |
342 | 938 |
939 if (!_nextMarkBitMap->isMarked(addr)) | |
940 _nextMarkBitMap->parMark(addr); | |
941 } | |
942 | |
943 void ConcurrentMark::grayRegionIfNecessary(MemRegion mr) { | |
944 // The objects on the region have already been marked "in bulk" by | |
945 // the caller. We only need to decide whether to push the region on | |
946 // the region stack or not. | |
947 | |
948 if (!concurrent_marking_in_progress() || !_should_gray_objects) | |
949 // We're done with marking and waiting for remark. We do not need to | |
950 // push anything else on the region stack. | |
951 return; | |
952 | |
953 HeapWord* finger = _finger; | |
954 | |
955 if (verbose_low()) | |
956 gclog_or_tty->print_cr("[global] attempting to push " | |
957 "region ["PTR_FORMAT", "PTR_FORMAT"), finger is at " | |
958 PTR_FORMAT, mr.start(), mr.end(), finger); | |
959 | |
960 if (mr.start() < finger) { | |
961 // The finger is always heap region aligned and it is not possible | |
962 // for mr to span heap regions. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
963 assert(mr.end() <= finger, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
964 |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
965 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
966 assert(mr.start() <= mr.end(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
967 "region boundaries should fall within the committed space"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
968 assert(_heap_start <= mr.start(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
969 "region boundaries should fall within the committed space"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
970 assert(mr.end() <= _heap_end, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
971 "region boundaries should fall within the committed space"); |
342 | 972 if (verbose_low()) |
973 gclog_or_tty->print_cr("[global] region ["PTR_FORMAT", "PTR_FORMAT") " | |
974 "below the finger, pushing it", | |
975 mr.start(), mr.end()); | |
976 | |
977 if (!region_stack_push(mr)) { | |
978 if (verbose_low()) | |
979 gclog_or_tty->print_cr("[global] region stack has overflown."); | |
980 } | |
981 } | |
982 } | |
983 | |
984 void ConcurrentMark::markAndGrayObjectIfNecessary(oop p) { | |
985 // The object is not marked by the caller. We need to at least mark | |
986 // it and maybe push in on the stack. | |
987 | |
988 HeapWord* addr = (HeapWord*)p; | |
989 if (!_nextMarkBitMap->isMarked(addr)) { | |
990 // We definitely need to mark it, irrespective whether we bail out | |
991 // because we're done with marking. | |
992 if (_nextMarkBitMap->parMark(addr)) { | |
993 if (!concurrent_marking_in_progress() || !_should_gray_objects) | |
994 // If we're done with concurrent marking and we're waiting for | |
995 // remark, then we're not pushing anything on the stack. | |
996 return; | |
997 | |
998 // No OrderAccess:store_load() is needed. It is implicit in the | |
999 // CAS done in parMark(addr) above | |
1000 HeapWord* finger = _finger; | |
1001 | |
1002 if (addr < finger) { | |
1003 if (!mark_stack_push(oop(addr))) { | |
1004 if (verbose_low()) | |
1005 gclog_or_tty->print_cr("[global] global stack overflow " | |
1006 "during parMark"); | |
1007 } | |
1008 } | |
1009 } | |
1010 } | |
1011 } | |
1012 | |
1013 class CMConcurrentMarkingTask: public AbstractGangTask { | |
1014 private: | |
1015 ConcurrentMark* _cm; | |
1016 ConcurrentMarkThread* _cmt; | |
1017 | |
1018 public: | |
1019 void work(int worker_i) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1020 assert(Thread::current()->is_ConcurrentGC_thread(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1021 "this should only be done by a conc GC thread"); |
342 | 1022 |
1023 double start_vtime = os::elapsedVTime(); | |
1024 | |
1025 ConcurrentGCThread::stsJoin(); | |
1026 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1027 assert((size_t) worker_i < _cm->active_tasks(), "invariant"); |
342 | 1028 CMTask* the_task = _cm->task(worker_i); |
1029 the_task->record_start_time(); | |
1030 if (!_cm->has_aborted()) { | |
1031 do { | |
1032 double start_vtime_sec = os::elapsedVTime(); | |
1033 double start_time_sec = os::elapsedTime(); | |
1034 the_task->do_marking_step(10.0); | |
1035 double end_time_sec = os::elapsedTime(); | |
1036 double end_vtime_sec = os::elapsedVTime(); | |
1037 double elapsed_vtime_sec = end_vtime_sec - start_vtime_sec; | |
1038 double elapsed_time_sec = end_time_sec - start_time_sec; | |
1039 _cm->clear_has_overflown(); | |
1040 | |
1041 bool ret = _cm->do_yield_check(worker_i); | |
1042 | |
1043 jlong sleep_time_ms; | |
1044 if (!_cm->has_aborted() && the_task->has_aborted()) { | |
1045 sleep_time_ms = | |
1046 (jlong) (elapsed_vtime_sec * _cm->sleep_factor() * 1000.0); | |
1047 ConcurrentGCThread::stsLeave(); | |
1048 os::sleep(Thread::current(), sleep_time_ms, false); | |
1049 ConcurrentGCThread::stsJoin(); | |
1050 } | |
1051 double end_time2_sec = os::elapsedTime(); | |
1052 double elapsed_time2_sec = end_time2_sec - start_time_sec; | |
1053 | |
1054 #if 0 | |
1055 gclog_or_tty->print_cr("CM: elapsed %1.4lf ms, sleep %1.4lf ms, " | |
1056 "overhead %1.4lf", | |
1057 elapsed_vtime_sec * 1000.0, (double) sleep_time_ms, | |
1058 the_task->conc_overhead(os::elapsedTime()) * 8.0); | |
1059 gclog_or_tty->print_cr("elapsed time %1.4lf ms, time 2: %1.4lf ms", | |
1060 elapsed_time_sec * 1000.0, elapsed_time2_sec * 1000.0); | |
1061 #endif | |
1062 } while (!_cm->has_aborted() && the_task->has_aborted()); | |
1063 } | |
1064 the_task->record_end_time(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1065 guarantee(!the_task->has_aborted() || _cm->has_aborted(), "invariant"); |
342 | 1066 |
1067 ConcurrentGCThread::stsLeave(); | |
1068 | |
1069 double end_vtime = os::elapsedVTime(); | |
1070 _cm->update_accum_task_vtime(worker_i, end_vtime - start_vtime); | |
1071 } | |
1072 | |
1073 CMConcurrentMarkingTask(ConcurrentMark* cm, | |
1074 ConcurrentMarkThread* cmt) : | |
1075 AbstractGangTask("Concurrent Mark"), _cm(cm), _cmt(cmt) { } | |
1076 | |
1077 ~CMConcurrentMarkingTask() { } | |
1078 }; | |
1079 | |
1080 void ConcurrentMark::markFromRoots() { | |
1081 // we might be tempted to assert that: | |
1082 // assert(asynch == !SafepointSynchronize::is_at_safepoint(), | |
1083 // "inconsistent argument?"); | |
1084 // However that wouldn't be right, because it's possible that | |
1085 // a safepoint is indeed in progress as a younger generation | |
1086 // stop-the-world GC happens even as we mark in this generation. | |
1087 | |
1088 _restart_for_overflow = false; | |
1089 | |
1090 set_phase(MAX2((size_t) 1, parallel_marking_threads()), true); | |
1091 | |
1092 CMConcurrentMarkingTask markingTask(this, cmThread()); | |
1093 if (parallel_marking_threads() > 0) | |
1094 _parallel_workers->run_task(&markingTask); | |
1095 else | |
1096 markingTask.work(0); | |
1097 print_stats(); | |
1098 } | |
1099 | |
1100 void ConcurrentMark::checkpointRootsFinal(bool clear_all_soft_refs) { | |
1101 // world is stopped at this checkpoint | |
1102 assert(SafepointSynchronize::is_at_safepoint(), | |
1103 "world should be stopped"); | |
1104 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1105 | |
1106 // If a full collection has happened, we shouldn't do this. | |
1107 if (has_aborted()) { | |
1108 g1h->set_marking_complete(); // So bitmap clearing isn't confused | |
1109 return; | |
1110 } | |
1111 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1112 if (VerifyDuringGC) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1113 HandleMark hm; // handle scope |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1114 gclog_or_tty->print(" VerifyDuringGC:(before)"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1115 Universe::heap()->prepare_for_verify(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1116 Universe::verify(true, false, true); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1117 } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1118 |
342 | 1119 G1CollectorPolicy* g1p = g1h->g1_policy(); |
1120 g1p->record_concurrent_mark_remark_start(); | |
1121 | |
1122 double start = os::elapsedTime(); | |
1123 | |
1124 checkpointRootsFinalWork(); | |
1125 | |
1126 double mark_work_end = os::elapsedTime(); | |
1127 | |
1128 weakRefsWork(clear_all_soft_refs); | |
1129 | |
1130 if (has_overflown()) { | |
1131 // Oops. We overflowed. Restart concurrent marking. | |
1132 _restart_for_overflow = true; | |
1133 // Clear the flag. We do not need it any more. | |
1134 clear_has_overflown(); | |
1135 if (G1TraceMarkStackOverflow) | |
1136 gclog_or_tty->print_cr("\nRemark led to restart for overflow."); | |
1137 } else { | |
1138 // We're done with marking. | |
1139 JavaThread::satb_mark_queue_set().set_active_all_threads(false); | |
811 | 1140 |
1141 if (VerifyDuringGC) { | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1142 HandleMark hm; // handle scope |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1143 gclog_or_tty->print(" VerifyDuringGC:(after)"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1144 Universe::heap()->prepare_for_verify(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1145 Universe::heap()->verify(/* allow_dirty */ true, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1146 /* silent */ false, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1147 /* use_prev_marking */ false); |
811 | 1148 } |
342 | 1149 } |
1150 | |
1151 #if VERIFY_OBJS_PROCESSED | |
1152 _scan_obj_cl.objs_processed = 0; | |
1153 ThreadLocalObjQueue::objs_enqueued = 0; | |
1154 #endif | |
1155 | |
1156 // Statistics | |
1157 double now = os::elapsedTime(); | |
1158 _remark_mark_times.add((mark_work_end - start) * 1000.0); | |
1159 _remark_weak_ref_times.add((now - mark_work_end) * 1000.0); | |
1160 _remark_times.add((now - start) * 1000.0); | |
1161 | |
1162 g1p->record_concurrent_mark_remark_end(); | |
1163 } | |
1164 | |
1165 | |
1166 #define CARD_BM_TEST_MODE 0 | |
1167 | |
1168 class CalcLiveObjectsClosure: public HeapRegionClosure { | |
1169 | |
1170 CMBitMapRO* _bm; | |
1171 ConcurrentMark* _cm; | |
1172 bool _changed; | |
1173 bool _yield; | |
1174 size_t _words_done; | |
1175 size_t _tot_live; | |
1176 size_t _tot_used; | |
1177 size_t _regions_done; | |
1178 double _start_vtime_sec; | |
1179 | |
1180 BitMap* _region_bm; | |
1181 BitMap* _card_bm; | |
1182 intptr_t _bottom_card_num; | |
1183 bool _final; | |
1184 | |
1185 void mark_card_num_range(intptr_t start_card_num, intptr_t last_card_num) { | |
1186 for (intptr_t i = start_card_num; i <= last_card_num; i++) { | |
1187 #if CARD_BM_TEST_MODE | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1188 guarantee(_card_bm->at(i - _bottom_card_num), "Should already be set."); |
342 | 1189 #else |
1190 _card_bm->par_at_put(i - _bottom_card_num, 1); | |
1191 #endif | |
1192 } | |
1193 } | |
1194 | |
1195 public: | |
1196 CalcLiveObjectsClosure(bool final, | |
1197 CMBitMapRO *bm, ConcurrentMark *cm, | |
936 | 1198 BitMap* region_bm, BitMap* card_bm) : |
342 | 1199 _bm(bm), _cm(cm), _changed(false), _yield(true), |
1200 _words_done(0), _tot_live(0), _tot_used(0), | |
936 | 1201 _region_bm(region_bm), _card_bm(card_bm),_final(final), |
342 | 1202 _regions_done(0), _start_vtime_sec(0.0) |
1203 { | |
1204 _bottom_card_num = | |
1205 intptr_t(uintptr_t(G1CollectedHeap::heap()->reserved_region().start()) >> | |
1206 CardTableModRefBS::card_shift); | |
1207 } | |
1208 | |
829 | 1209 // It takes a region that's not empty (i.e., it has at least one |
1210 // live object in it and sets its corresponding bit on the region | |
1211 // bitmap to 1. If the region is "starts humongous" it will also set | |
1212 // to 1 the bits on the region bitmap that correspond to its | |
1213 // associated "continues humongous" regions. | |
1214 void set_bit_for_region(HeapRegion* hr) { | |
1215 assert(!hr->continuesHumongous(), "should have filtered those out"); | |
1216 | |
1217 size_t index = hr->hrs_index(); | |
1218 if (!hr->startsHumongous()) { | |
1219 // Normal (non-humongous) case: just set the bit. | |
1220 _region_bm->par_at_put((BitMap::idx_t) index, true); | |
1221 } else { | |
1222 // Starts humongous case: calculate how many regions are part of | |
1223 // this humongous region and then set the bit range. It might | |
1224 // have been a bit more efficient to look at the object that | |
1225 // spans these humongous regions to calculate their number from | |
1226 // the object's size. However, it's a good idea to calculate | |
1227 // this based on the metadata itself, and not the region | |
1228 // contents, so that this code is not aware of what goes into | |
1229 // the humongous regions (in case this changes in the future). | |
1230 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1231 size_t end_index = index + 1; | |
831 | 1232 while (end_index < g1h->n_regions()) { |
1233 HeapRegion* chr = g1h->region_at(end_index); | |
829 | 1234 if (!chr->continuesHumongous()) { |
1235 break; | |
1236 } | |
1237 end_index += 1; | |
1238 } | |
1239 _region_bm->par_at_put_range((BitMap::idx_t) index, | |
1240 (BitMap::idx_t) end_index, true); | |
1241 } | |
1242 } | |
1243 | |
342 | 1244 bool doHeapRegion(HeapRegion* hr) { |
1245 if (!_final && _regions_done == 0) | |
1246 _start_vtime_sec = os::elapsedVTime(); | |
1247 | |
639 | 1248 if (hr->continuesHumongous()) { |
829 | 1249 // We will ignore these here and process them when their |
1250 // associated "starts humongous" region is processed (see | |
1251 // set_bit_for_heap_region()). Note that we cannot rely on their | |
1252 // associated "starts humongous" region to have their bit set to | |
1253 // 1 since, due to the region chunking in the parallel region | |
1254 // iteration, a "continues humongous" region might be visited | |
1255 // before its associated "starts humongous". | |
639 | 1256 return false; |
1257 } | |
342 | 1258 |
1259 HeapWord* nextTop = hr->next_top_at_mark_start(); | |
1260 HeapWord* start = hr->top_at_conc_mark_count(); | |
1261 assert(hr->bottom() <= start && start <= hr->end() && | |
1262 hr->bottom() <= nextTop && nextTop <= hr->end() && | |
1263 start <= nextTop, | |
1264 "Preconditions."); | |
1265 // Otherwise, record the number of word's we'll examine. | |
1266 size_t words_done = (nextTop - start); | |
1267 // Find the first marked object at or after "start". | |
1268 start = _bm->getNextMarkedWordAddress(start, nextTop); | |
1269 size_t marked_bytes = 0; | |
1270 | |
1271 // Below, the term "card num" means the result of shifting an address | |
1272 // by the card shift -- address 0 corresponds to card number 0. One | |
1273 // must subtract the card num of the bottom of the heap to obtain a | |
1274 // card table index. | |
1275 // The first card num of the sequence of live cards currently being | |
1276 // constructed. -1 ==> no sequence. | |
1277 intptr_t start_card_num = -1; | |
1278 // The last card num of the sequence of live cards currently being | |
1279 // constructed. -1 ==> no sequence. | |
1280 intptr_t last_card_num = -1; | |
1281 | |
1282 while (start < nextTop) { | |
1283 if (_yield && _cm->do_yield_check()) { | |
1284 // We yielded. It might be for a full collection, in which case | |
1285 // all bets are off; terminate the traversal. | |
1286 if (_cm->has_aborted()) { | |
1287 _changed = false; | |
1288 return true; | |
1289 } else { | |
1290 // Otherwise, it might be a collection pause, and the region | |
1291 // we're looking at might be in the collection set. We'll | |
1292 // abandon this region. | |
1293 return false; | |
1294 } | |
1295 } | |
1296 oop obj = oop(start); | |
1297 int obj_sz = obj->size(); | |
1298 // The card num of the start of the current object. | |
1299 intptr_t obj_card_num = | |
1300 intptr_t(uintptr_t(start) >> CardTableModRefBS::card_shift); | |
1301 | |
1302 HeapWord* obj_last = start + obj_sz - 1; | |
1303 intptr_t obj_last_card_num = | |
1304 intptr_t(uintptr_t(obj_last) >> CardTableModRefBS::card_shift); | |
1305 | |
1306 if (obj_card_num != last_card_num) { | |
1307 if (start_card_num == -1) { | |
1308 assert(last_card_num == -1, "Both or neither."); | |
1309 start_card_num = obj_card_num; | |
1310 } else { | |
1311 assert(last_card_num != -1, "Both or neither."); | |
1312 assert(obj_card_num >= last_card_num, "Inv"); | |
1313 if ((obj_card_num - last_card_num) > 1) { | |
1314 // Mark the last run, and start a new one. | |
1315 mark_card_num_range(start_card_num, last_card_num); | |
1316 start_card_num = obj_card_num; | |
1317 } | |
1318 } | |
1319 #if CARD_BM_TEST_MODE | |
1320 /* | |
1321 gclog_or_tty->print_cr("Setting bits from %d/%d.", | |
1322 obj_card_num - _bottom_card_num, | |
1323 obj_last_card_num - _bottom_card_num); | |
1324 */ | |
1325 for (intptr_t j = obj_card_num; j <= obj_last_card_num; j++) { | |
1326 _card_bm->par_at_put(j - _bottom_card_num, 1); | |
1327 } | |
1328 #endif | |
1329 } | |
1330 // In any case, we set the last card num. | |
1331 last_card_num = obj_last_card_num; | |
1332 | |
1030
dfdaf65c3423
6858886: G1: guarantee(_next_marked_bytes <= used(),"invariant") at heapRegion.hpp:359
apetrusenko
parents:
1023
diff
changeset
|
1333 marked_bytes += (size_t)obj_sz * HeapWordSize; |
342 | 1334 // Find the next marked object after this one. |
1335 start = _bm->getNextMarkedWordAddress(start + 1, nextTop); | |
1336 _changed = true; | |
1337 } | |
1338 // Handle the last range, if any. | |
1339 if (start_card_num != -1) | |
1340 mark_card_num_range(start_card_num, last_card_num); | |
1341 if (_final) { | |
1342 // Mark the allocated-since-marking portion... | |
1343 HeapWord* tp = hr->top(); | |
1344 if (nextTop < tp) { | |
1345 start_card_num = | |
1346 intptr_t(uintptr_t(nextTop) >> CardTableModRefBS::card_shift); | |
1347 last_card_num = | |
1348 intptr_t(uintptr_t(tp) >> CardTableModRefBS::card_shift); | |
1349 mark_card_num_range(start_card_num, last_card_num); | |
1350 // This definitely means the region has live objects. | |
829 | 1351 set_bit_for_region(hr); |
342 | 1352 } |
1353 } | |
1354 | |
1355 hr->add_to_marked_bytes(marked_bytes); | |
1356 // Update the live region bitmap. | |
1357 if (marked_bytes > 0) { | |
829 | 1358 set_bit_for_region(hr); |
342 | 1359 } |
1360 hr->set_top_at_conc_mark_count(nextTop); | |
1361 _tot_live += hr->next_live_bytes(); | |
1362 _tot_used += hr->used(); | |
1363 _words_done = words_done; | |
1364 | |
1365 if (!_final) { | |
1366 ++_regions_done; | |
1367 if (_regions_done % 10 == 0) { | |
1368 double end_vtime_sec = os::elapsedVTime(); | |
1369 double elapsed_vtime_sec = end_vtime_sec - _start_vtime_sec; | |
1370 if (elapsed_vtime_sec > (10.0 / 1000.0)) { | |
1371 jlong sleep_time_ms = | |
1372 (jlong) (elapsed_vtime_sec * _cm->cleanup_sleep_factor() * 1000.0); | |
1373 os::sleep(Thread::current(), sleep_time_ms, false); | |
1374 _start_vtime_sec = end_vtime_sec; | |
1375 } | |
1376 } | |
1377 } | |
1378 | |
1379 return false; | |
1380 } | |
1381 | |
1382 bool changed() { return _changed; } | |
1383 void reset() { _changed = false; _words_done = 0; } | |
1384 void no_yield() { _yield = false; } | |
1385 size_t words_done() { return _words_done; } | |
1386 size_t tot_live() { return _tot_live; } | |
1387 size_t tot_used() { return _tot_used; } | |
1388 }; | |
1389 | |
1390 | |
1391 void ConcurrentMark::calcDesiredRegions() { | |
1392 _region_bm.clear(); | |
1393 _card_bm.clear(); | |
1394 CalcLiveObjectsClosure calccl(false /*final*/, | |
1395 nextMarkBitMap(), this, | |
936 | 1396 &_region_bm, &_card_bm); |
342 | 1397 G1CollectedHeap *g1h = G1CollectedHeap::heap(); |
1398 g1h->heap_region_iterate(&calccl); | |
1399 | |
1400 do { | |
1401 calccl.reset(); | |
1402 g1h->heap_region_iterate(&calccl); | |
1403 } while (calccl.changed()); | |
1404 } | |
1405 | |
1406 class G1ParFinalCountTask: public AbstractGangTask { | |
1407 protected: | |
1408 G1CollectedHeap* _g1h; | |
1409 CMBitMap* _bm; | |
1410 size_t _n_workers; | |
1411 size_t *_live_bytes; | |
1412 size_t *_used_bytes; | |
1413 BitMap* _region_bm; | |
1414 BitMap* _card_bm; | |
1415 public: | |
1416 G1ParFinalCountTask(G1CollectedHeap* g1h, CMBitMap* bm, | |
1417 BitMap* region_bm, BitMap* card_bm) : | |
1418 AbstractGangTask("G1 final counting"), _g1h(g1h), | |
1419 _bm(bm), _region_bm(region_bm), _card_bm(card_bm) | |
1420 { | |
1421 if (ParallelGCThreads > 0) | |
1422 _n_workers = _g1h->workers()->total_workers(); | |
1423 else | |
1424 _n_workers = 1; | |
1425 _live_bytes = NEW_C_HEAP_ARRAY(size_t, _n_workers); | |
1426 _used_bytes = NEW_C_HEAP_ARRAY(size_t, _n_workers); | |
1427 } | |
1428 | |
1429 ~G1ParFinalCountTask() { | |
1430 FREE_C_HEAP_ARRAY(size_t, _live_bytes); | |
1431 FREE_C_HEAP_ARRAY(size_t, _used_bytes); | |
1432 } | |
1433 | |
1434 void work(int i) { | |
1435 CalcLiveObjectsClosure calccl(true /*final*/, | |
1436 _bm, _g1h->concurrent_mark(), | |
936 | 1437 _region_bm, _card_bm); |
342 | 1438 calccl.no_yield(); |
1439 if (ParallelGCThreads > 0) { | |
355 | 1440 _g1h->heap_region_par_iterate_chunked(&calccl, i, |
1441 HeapRegion::FinalCountClaimValue); | |
342 | 1442 } else { |
1443 _g1h->heap_region_iterate(&calccl); | |
1444 } | |
1445 assert(calccl.complete(), "Shouldn't have yielded!"); | |
1446 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1447 assert((size_t) i < _n_workers, "invariant"); |
342 | 1448 _live_bytes[i] = calccl.tot_live(); |
1449 _used_bytes[i] = calccl.tot_used(); | |
1450 } | |
1451 size_t live_bytes() { | |
1452 size_t live_bytes = 0; | |
1453 for (size_t i = 0; i < _n_workers; ++i) | |
1454 live_bytes += _live_bytes[i]; | |
1455 return live_bytes; | |
1456 } | |
1457 size_t used_bytes() { | |
1458 size_t used_bytes = 0; | |
1459 for (size_t i = 0; i < _n_workers; ++i) | |
1460 used_bytes += _used_bytes[i]; | |
1461 return used_bytes; | |
1462 } | |
1463 }; | |
1464 | |
1465 class G1ParNoteEndTask; | |
1466 | |
1467 class G1NoteEndOfConcMarkClosure : public HeapRegionClosure { | |
1468 G1CollectedHeap* _g1; | |
1469 int _worker_num; | |
1470 size_t _max_live_bytes; | |
1471 size_t _regions_claimed; | |
1472 size_t _freed_bytes; | |
1473 size_t _cleared_h_regions; | |
1474 size_t _freed_regions; | |
1475 UncleanRegionList* _unclean_region_list; | |
1476 double _claimed_region_time; | |
1477 double _max_region_time; | |
1478 | |
1479 public: | |
1480 G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1, | |
1481 UncleanRegionList* list, | |
1482 int worker_num); | |
1483 size_t freed_bytes() { return _freed_bytes; } | |
1484 size_t cleared_h_regions() { return _cleared_h_regions; } | |
1485 size_t freed_regions() { return _freed_regions; } | |
1486 UncleanRegionList* unclean_region_list() { | |
1487 return _unclean_region_list; | |
1488 } | |
1489 | |
1490 bool doHeapRegion(HeapRegion *r); | |
1491 | |
1492 size_t max_live_bytes() { return _max_live_bytes; } | |
1493 size_t regions_claimed() { return _regions_claimed; } | |
1494 double claimed_region_time_sec() { return _claimed_region_time; } | |
1495 double max_region_time_sec() { return _max_region_time; } | |
1496 }; | |
1497 | |
1498 class G1ParNoteEndTask: public AbstractGangTask { | |
1499 friend class G1NoteEndOfConcMarkClosure; | |
1500 protected: | |
1501 G1CollectedHeap* _g1h; | |
1502 size_t _max_live_bytes; | |
1503 size_t _freed_bytes; | |
1504 ConcurrentMark::ParCleanupThreadState** _par_cleanup_thread_state; | |
1505 public: | |
1506 G1ParNoteEndTask(G1CollectedHeap* g1h, | |
1507 ConcurrentMark::ParCleanupThreadState** | |
1508 par_cleanup_thread_state) : | |
1509 AbstractGangTask("G1 note end"), _g1h(g1h), | |
1510 _max_live_bytes(0), _freed_bytes(0), | |
1511 _par_cleanup_thread_state(par_cleanup_thread_state) | |
1512 {} | |
1513 | |
1514 void work(int i) { | |
1515 double start = os::elapsedTime(); | |
1516 G1NoteEndOfConcMarkClosure g1_note_end(_g1h, | |
1517 &_par_cleanup_thread_state[i]->list, | |
1518 i); | |
1519 if (ParallelGCThreads > 0) { | |
355 | 1520 _g1h->heap_region_par_iterate_chunked(&g1_note_end, i, |
1521 HeapRegion::NoteEndClaimValue); | |
342 | 1522 } else { |
1523 _g1h->heap_region_iterate(&g1_note_end); | |
1524 } | |
1525 assert(g1_note_end.complete(), "Shouldn't have yielded!"); | |
1526 | |
1527 // Now finish up freeing the current thread's regions. | |
1528 _g1h->finish_free_region_work(g1_note_end.freed_bytes(), | |
1529 g1_note_end.cleared_h_regions(), | |
1530 0, NULL); | |
1531 { | |
1532 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
1533 _max_live_bytes += g1_note_end.max_live_bytes(); | |
1534 _freed_bytes += g1_note_end.freed_bytes(); | |
1535 } | |
1536 double end = os::elapsedTime(); | |
1537 if (G1PrintParCleanupStats) { | |
1538 gclog_or_tty->print(" Worker thread %d [%8.3f..%8.3f = %8.3f ms] " | |
1539 "claimed %d regions (tot = %8.3f ms, max = %8.3f ms).\n", | |
1540 i, start, end, (end-start)*1000.0, | |
1541 g1_note_end.regions_claimed(), | |
1542 g1_note_end.claimed_region_time_sec()*1000.0, | |
1543 g1_note_end.max_region_time_sec()*1000.0); | |
1544 } | |
1545 } | |
1546 size_t max_live_bytes() { return _max_live_bytes; } | |
1547 size_t freed_bytes() { return _freed_bytes; } | |
1548 }; | |
1549 | |
1550 class G1ParScrubRemSetTask: public AbstractGangTask { | |
1551 protected: | |
1552 G1RemSet* _g1rs; | |
1553 BitMap* _region_bm; | |
1554 BitMap* _card_bm; | |
1555 public: | |
1556 G1ParScrubRemSetTask(G1CollectedHeap* g1h, | |
1557 BitMap* region_bm, BitMap* card_bm) : | |
1558 AbstractGangTask("G1 ScrubRS"), _g1rs(g1h->g1_rem_set()), | |
1559 _region_bm(region_bm), _card_bm(card_bm) | |
1560 {} | |
1561 | |
1562 void work(int i) { | |
1563 if (ParallelGCThreads > 0) { | |
355 | 1564 _g1rs->scrub_par(_region_bm, _card_bm, i, |
1565 HeapRegion::ScrubRemSetClaimValue); | |
342 | 1566 } else { |
1567 _g1rs->scrub(_region_bm, _card_bm); | |
1568 } | |
1569 } | |
1570 | |
1571 }; | |
1572 | |
1573 G1NoteEndOfConcMarkClosure:: | |
1574 G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1, | |
1575 UncleanRegionList* list, | |
1576 int worker_num) | |
1577 : _g1(g1), _worker_num(worker_num), | |
1578 _max_live_bytes(0), _regions_claimed(0), | |
1579 _freed_bytes(0), _cleared_h_regions(0), _freed_regions(0), | |
1580 _claimed_region_time(0.0), _max_region_time(0.0), | |
1581 _unclean_region_list(list) | |
1582 {} | |
1583 | |
1584 bool G1NoteEndOfConcMarkClosure::doHeapRegion(HeapRegion *r) { | |
1585 // We use a claim value of zero here because all regions | |
1586 // were claimed with value 1 in the FinalCount task. | |
1587 r->reset_gc_time_stamp(); | |
1588 if (!r->continuesHumongous()) { | |
1589 double start = os::elapsedTime(); | |
1590 _regions_claimed++; | |
1591 r->note_end_of_marking(); | |
1592 _max_live_bytes += r->max_live_bytes(); | |
1593 _g1->free_region_if_totally_empty_work(r, | |
1594 _freed_bytes, | |
1595 _cleared_h_regions, | |
1596 _freed_regions, | |
1597 _unclean_region_list, | |
1598 true /*par*/); | |
1599 double region_time = (os::elapsedTime() - start); | |
1600 _claimed_region_time += region_time; | |
1601 if (region_time > _max_region_time) _max_region_time = region_time; | |
1602 } | |
1603 return false; | |
1604 } | |
1605 | |
1606 void ConcurrentMark::cleanup() { | |
1607 // world is stopped at this checkpoint | |
1608 assert(SafepointSynchronize::is_at_safepoint(), | |
1609 "world should be stopped"); | |
1610 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1611 | |
1612 // If a full collection has happened, we shouldn't do this. | |
1613 if (has_aborted()) { | |
1614 g1h->set_marking_complete(); // So bitmap clearing isn't confused | |
1615 return; | |
1616 } | |
1617 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1618 if (VerifyDuringGC) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1619 HandleMark hm; // handle scope |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1620 gclog_or_tty->print(" VerifyDuringGC:(before)"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1621 Universe::heap()->prepare_for_verify(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1622 Universe::verify(/* allow dirty */ true, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1623 /* silent */ false, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1624 /* prev marking */ true); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1625 } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1626 |
342 | 1627 G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy(); |
1628 g1p->record_concurrent_mark_cleanup_start(); | |
1629 | |
1630 double start = os::elapsedTime(); | |
1631 | |
1632 // Do counting once more with the world stopped for good measure. | |
1633 G1ParFinalCountTask g1_par_count_task(g1h, nextMarkBitMap(), | |
1634 &_region_bm, &_card_bm); | |
1635 if (ParallelGCThreads > 0) { | |
355 | 1636 assert(g1h->check_heap_region_claim_values( |
1637 HeapRegion::InitialClaimValue), | |
1638 "sanity check"); | |
1639 | |
342 | 1640 int n_workers = g1h->workers()->total_workers(); |
1641 g1h->set_par_threads(n_workers); | |
1642 g1h->workers()->run_task(&g1_par_count_task); | |
1643 g1h->set_par_threads(0); | |
355 | 1644 |
1645 assert(g1h->check_heap_region_claim_values( | |
1646 HeapRegion::FinalCountClaimValue), | |
1647 "sanity check"); | |
342 | 1648 } else { |
1649 g1_par_count_task.work(0); | |
1650 } | |
1651 | |
1652 size_t known_garbage_bytes = | |
1653 g1_par_count_task.used_bytes() - g1_par_count_task.live_bytes(); | |
1654 #if 0 | |
1655 gclog_or_tty->print_cr("used %1.2lf, live %1.2lf, garbage %1.2lf", | |
1656 (double) g1_par_count_task.used_bytes() / (double) (1024 * 1024), | |
1657 (double) g1_par_count_task.live_bytes() / (double) (1024 * 1024), | |
1658 (double) known_garbage_bytes / (double) (1024 * 1024)); | |
1659 #endif // 0 | |
1660 g1p->set_known_garbage_bytes(known_garbage_bytes); | |
1661 | |
1662 size_t start_used_bytes = g1h->used(); | |
1663 _at_least_one_mark_complete = true; | |
1664 g1h->set_marking_complete(); | |
1665 | |
1666 double count_end = os::elapsedTime(); | |
1667 double this_final_counting_time = (count_end - start); | |
1668 if (G1PrintParCleanupStats) { | |
1669 gclog_or_tty->print_cr("Cleanup:"); | |
1670 gclog_or_tty->print_cr(" Finalize counting: %8.3f ms", | |
1671 this_final_counting_time*1000.0); | |
1672 } | |
1673 _total_counting_time += this_final_counting_time; | |
1674 | |
1675 // Install newly created mark bitMap as "prev". | |
1676 swapMarkBitMaps(); | |
1677 | |
1678 g1h->reset_gc_time_stamp(); | |
1679 | |
1680 // Note end of marking in all heap regions. | |
1681 double note_end_start = os::elapsedTime(); | |
1682 G1ParNoteEndTask g1_par_note_end_task(g1h, _par_cleanup_thread_state); | |
1683 if (ParallelGCThreads > 0) { | |
1684 int n_workers = g1h->workers()->total_workers(); | |
1685 g1h->set_par_threads(n_workers); | |
1686 g1h->workers()->run_task(&g1_par_note_end_task); | |
1687 g1h->set_par_threads(0); | |
355 | 1688 |
1689 assert(g1h->check_heap_region_claim_values(HeapRegion::NoteEndClaimValue), | |
1690 "sanity check"); | |
342 | 1691 } else { |
1692 g1_par_note_end_task.work(0); | |
1693 } | |
1694 g1h->set_unclean_regions_coming(true); | |
1695 double note_end_end = os::elapsedTime(); | |
1696 // Tell the mutators that there might be unclean regions coming... | |
1697 if (G1PrintParCleanupStats) { | |
1698 gclog_or_tty->print_cr(" note end of marking: %8.3f ms.", | |
1699 (note_end_end - note_end_start)*1000.0); | |
1700 } | |
1701 | |
355 | 1702 |
342 | 1703 // call below, since it affects the metric by which we sort the heap |
1704 // regions. | |
1705 if (G1ScrubRemSets) { | |
1706 double rs_scrub_start = os::elapsedTime(); | |
1707 G1ParScrubRemSetTask g1_par_scrub_rs_task(g1h, &_region_bm, &_card_bm); | |
1708 if (ParallelGCThreads > 0) { | |
1709 int n_workers = g1h->workers()->total_workers(); | |
1710 g1h->set_par_threads(n_workers); | |
1711 g1h->workers()->run_task(&g1_par_scrub_rs_task); | |
1712 g1h->set_par_threads(0); | |
355 | 1713 |
1714 assert(g1h->check_heap_region_claim_values( | |
1715 HeapRegion::ScrubRemSetClaimValue), | |
1716 "sanity check"); | |
342 | 1717 } else { |
1718 g1_par_scrub_rs_task.work(0); | |
1719 } | |
1720 | |
1721 double rs_scrub_end = os::elapsedTime(); | |
1722 double this_rs_scrub_time = (rs_scrub_end - rs_scrub_start); | |
1723 _total_rs_scrub_time += this_rs_scrub_time; | |
1724 } | |
1725 | |
1726 // this will also free any regions totally full of garbage objects, | |
1727 // and sort the regions. | |
1728 g1h->g1_policy()->record_concurrent_mark_cleanup_end( | |
1729 g1_par_note_end_task.freed_bytes(), | |
1730 g1_par_note_end_task.max_live_bytes()); | |
1731 | |
1732 // Statistics. | |
1733 double end = os::elapsedTime(); | |
1734 _cleanup_times.add((end - start) * 1000.0); | |
1735 | |
1736 // G1CollectedHeap::heap()->print(); | |
1737 // gclog_or_tty->print_cr("HEAP GC TIME STAMP : %d", | |
1738 // G1CollectedHeap::heap()->get_gc_time_stamp()); | |
1739 | |
1740 if (PrintGC || PrintGCDetails) { | |
1741 g1h->print_size_transition(gclog_or_tty, | |
1742 start_used_bytes, | |
1743 g1h->used(), | |
1744 g1h->capacity()); | |
1745 } | |
1746 | |
1747 size_t cleaned_up_bytes = start_used_bytes - g1h->used(); | |
1748 g1p->decrease_known_garbage_bytes(cleaned_up_bytes); | |
1749 | |
1750 // We need to make this be a "collection" so any collection pause that | |
1751 // races with it goes around and waits for completeCleanup to finish. | |
1752 g1h->increment_total_collections(); | |
1753 | |
751 | 1754 if (VerifyDuringGC) { |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1755 HandleMark hm; // handle scope |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1756 gclog_or_tty->print(" VerifyDuringGC:(after)"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1757 Universe::heap()->prepare_for_verify(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1758 Universe::verify(/* allow dirty */ true, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1759 /* silent */ false, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1760 /* prev marking */ true); |
342 | 1761 } |
1762 } | |
1763 | |
1764 void ConcurrentMark::completeCleanup() { | |
1765 // A full collection intervened. | |
1766 if (has_aborted()) return; | |
1767 | |
1768 int first = 0; | |
1769 int last = (int)MAX2(ParallelGCThreads, (size_t)1); | |
1770 for (int t = 0; t < last; t++) { | |
1771 UncleanRegionList* list = &_par_cleanup_thread_state[t]->list; | |
1772 assert(list->well_formed(), "Inv"); | |
1773 HeapRegion* hd = list->hd(); | |
1774 while (hd != NULL) { | |
1775 // Now finish up the other stuff. | |
1776 hd->rem_set()->clear(); | |
1777 HeapRegion* next_hd = hd->next_from_unclean_list(); | |
1778 (void)list->pop(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1779 assert(list->hd() == next_hd, "how not?"); |
342 | 1780 _g1h->put_region_on_unclean_list(hd); |
1781 if (!hd->isHumongous()) { | |
1782 // Add this to the _free_regions count by 1. | |
1783 _g1h->finish_free_region_work(0, 0, 1, NULL); | |
1784 } | |
1785 hd = list->hd(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1786 assert(hd == next_hd, "how not?"); |
342 | 1787 } |
1788 } | |
1789 } | |
1790 | |
1791 | |
1792 class G1CMIsAliveClosure: public BoolObjectClosure { | |
1793 G1CollectedHeap* _g1; | |
1794 public: | |
1795 G1CMIsAliveClosure(G1CollectedHeap* g1) : | |
1796 _g1(g1) | |
1797 {} | |
1798 | |
1799 void do_object(oop obj) { | |
1800 assert(false, "not to be invoked"); | |
1801 } | |
1802 bool do_object_b(oop obj) { | |
1803 HeapWord* addr = (HeapWord*)obj; | |
1804 return addr != NULL && | |
1805 (!_g1->is_in_g1_reserved(addr) || !_g1->is_obj_ill(obj)); | |
1806 } | |
1807 }; | |
1808 | |
1809 class G1CMKeepAliveClosure: public OopClosure { | |
1810 G1CollectedHeap* _g1; | |
1811 ConcurrentMark* _cm; | |
1812 CMBitMap* _bitMap; | |
1813 public: | |
1814 G1CMKeepAliveClosure(G1CollectedHeap* g1, ConcurrentMark* cm, | |
1815 CMBitMap* bitMap) : | |
1816 _g1(g1), _cm(cm), | |
1817 _bitMap(bitMap) {} | |
1818 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1819 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1820 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1821 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1822 template <class T> void do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1823 oop thisOop = oopDesc::load_decode_heap_oop(p); |
342 | 1824 HeapWord* addr = (HeapWord*)thisOop; |
1825 if (_g1->is_in_g1_reserved(addr) && _g1->is_obj_ill(thisOop)) { | |
1826 _bitMap->mark(addr); | |
1827 _cm->mark_stack_push(thisOop); | |
1828 } | |
1829 } | |
1830 }; | |
1831 | |
1832 class G1CMDrainMarkingStackClosure: public VoidClosure { | |
1833 CMMarkStack* _markStack; | |
1834 CMBitMap* _bitMap; | |
1835 G1CMKeepAliveClosure* _oopClosure; | |
1836 public: | |
1837 G1CMDrainMarkingStackClosure(CMBitMap* bitMap, CMMarkStack* markStack, | |
1838 G1CMKeepAliveClosure* oopClosure) : | |
1839 _bitMap(bitMap), | |
1840 _markStack(markStack), | |
1841 _oopClosure(oopClosure) | |
1842 {} | |
1843 | |
1844 void do_void() { | |
1845 _markStack->drain((OopClosure*)_oopClosure, _bitMap, false); | |
1846 } | |
1847 }; | |
1848 | |
1849 void ConcurrentMark::weakRefsWork(bool clear_all_soft_refs) { | |
1850 ResourceMark rm; | |
1851 HandleMark hm; | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1852 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1853 ReferenceProcessor* rp = g1h->ref_processor(); |
342 | 1854 |
1855 // Process weak references. | |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
1856 rp->setup_policy(clear_all_soft_refs); |
342 | 1857 assert(_markStack.isEmpty(), "mark stack should be empty"); |
1858 | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1859 G1CMIsAliveClosure g1IsAliveClosure (g1h); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1860 G1CMKeepAliveClosure g1KeepAliveClosure(g1h, this, nextMarkBitMap()); |
342 | 1861 G1CMDrainMarkingStackClosure |
1862 g1DrainMarkingStackClosure(nextMarkBitMap(), &_markStack, | |
1863 &g1KeepAliveClosure); | |
1864 | |
1865 // XXXYYY Also: copy the parallel ref processing code from CMS. | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1866 rp->process_discovered_references(&g1IsAliveClosure, |
342 | 1867 &g1KeepAliveClosure, |
1868 &g1DrainMarkingStackClosure, | |
1869 NULL); | |
1870 assert(_markStack.overflow() || _markStack.isEmpty(), | |
1871 "mark stack should be empty (unless it overflowed)"); | |
1872 if (_markStack.overflow()) { | |
1873 set_has_overflown(); | |
1874 } | |
1875 | |
1876 rp->enqueue_discovered_references(); | |
1877 rp->verify_no_references_recorded(); | |
1878 assert(!rp->discovery_enabled(), "should have been disabled"); | |
1879 | |
1880 // Now clean up stale oops in SymbolTable and StringTable | |
1881 SymbolTable::unlink(&g1IsAliveClosure); | |
1882 StringTable::unlink(&g1IsAliveClosure); | |
1883 } | |
1884 | |
1885 void ConcurrentMark::swapMarkBitMaps() { | |
1886 CMBitMapRO* temp = _prevMarkBitMap; | |
1887 _prevMarkBitMap = (CMBitMapRO*)_nextMarkBitMap; | |
1888 _nextMarkBitMap = (CMBitMap*) temp; | |
1889 } | |
1890 | |
1891 class CMRemarkTask: public AbstractGangTask { | |
1892 private: | |
1893 ConcurrentMark *_cm; | |
1894 | |
1895 public: | |
1896 void work(int worker_i) { | |
1897 // Since all available tasks are actually started, we should | |
1898 // only proceed if we're supposed to be actived. | |
1899 if ((size_t)worker_i < _cm->active_tasks()) { | |
1900 CMTask* task = _cm->task(worker_i); | |
1901 task->record_start_time(); | |
1902 do { | |
1903 task->do_marking_step(1000000000.0 /* something very large */); | |
1904 } while (task->has_aborted() && !_cm->has_overflown()); | |
1905 // If we overflow, then we do not want to restart. We instead | |
1906 // want to abort remark and do concurrent marking again. | |
1907 task->record_end_time(); | |
1908 } | |
1909 } | |
1910 | |
1911 CMRemarkTask(ConcurrentMark* cm) : | |
1912 AbstractGangTask("Par Remark"), _cm(cm) { } | |
1913 }; | |
1914 | |
1915 void ConcurrentMark::checkpointRootsFinalWork() { | |
1916 ResourceMark rm; | |
1917 HandleMark hm; | |
1918 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1919 | |
1920 g1h->ensure_parsability(false); | |
1921 | |
1922 if (ParallelGCThreads > 0) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
1923 G1CollectedHeap::StrongRootsScope srs(g1h); |
342 | 1924 // this is remark, so we'll use up all available threads |
1925 int active_workers = ParallelGCThreads; | |
1926 set_phase(active_workers, false); | |
1927 | |
1928 CMRemarkTask remarkTask(this); | |
1929 // We will start all available threads, even if we decide that the | |
1930 // active_workers will be fewer. The extra ones will just bail out | |
1931 // immediately. | |
1932 int n_workers = g1h->workers()->total_workers(); | |
1933 g1h->set_par_threads(n_workers); | |
1934 g1h->workers()->run_task(&remarkTask); | |
1935 g1h->set_par_threads(0); | |
1936 } else { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
1937 G1CollectedHeap::StrongRootsScope srs(g1h); |
342 | 1938 // this is remark, so we'll use up all available threads |
1939 int active_workers = 1; | |
1940 set_phase(active_workers, false); | |
1941 | |
1942 CMRemarkTask remarkTask(this); | |
1943 // We will start all available threads, even if we decide that the | |
1944 // active_workers will be fewer. The extra ones will just bail out | |
1945 // immediately. | |
1946 remarkTask.work(0); | |
1947 } | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1948 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1949 guarantee(satb_mq_set.completed_buffers_num() == 0, "invariant"); |
342 | 1950 |
1951 print_stats(); | |
1952 | |
1953 if (!restart_for_overflow()) | |
1954 set_non_marking_state(); | |
1955 | |
1956 #if VERIFY_OBJS_PROCESSED | |
1957 if (_scan_obj_cl.objs_processed != ThreadLocalObjQueue::objs_enqueued) { | |
1958 gclog_or_tty->print_cr("Processed = %d, enqueued = %d.", | |
1959 _scan_obj_cl.objs_processed, | |
1960 ThreadLocalObjQueue::objs_enqueued); | |
1961 guarantee(_scan_obj_cl.objs_processed == | |
1962 ThreadLocalObjQueue::objs_enqueued, | |
1963 "Different number of objs processed and enqueued."); | |
1964 } | |
1965 #endif | |
1966 } | |
1967 | |
1968 class ReachablePrinterOopClosure: public OopClosure { | |
1969 private: | |
1970 G1CollectedHeap* _g1h; | |
1971 CMBitMapRO* _bitmap; | |
1972 outputStream* _out; | |
1973 | |
1974 public: | |
1975 ReachablePrinterOopClosure(CMBitMapRO* bitmap, outputStream* out) : | |
1976 _bitmap(bitmap), _g1h(G1CollectedHeap::heap()), _out(out) { } | |
1977 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1978 void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1979 void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1980 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1981 template <class T> void do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1982 oop obj = oopDesc::load_decode_heap_oop(p); |
342 | 1983 const char* str = NULL; |
1984 const char* str2 = ""; | |
1985 | |
1986 if (!_g1h->is_in_g1_reserved(obj)) | |
1987 str = "outside G1 reserved"; | |
1988 else { | |
1989 HeapRegion* hr = _g1h->heap_region_containing(obj); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1990 guarantee(hr != NULL, "invariant"); |
342 | 1991 if (hr->obj_allocated_since_prev_marking(obj)) { |
1992 str = "over TAMS"; | |
1993 if (_bitmap->isMarked((HeapWord*) obj)) | |
1994 str2 = " AND MARKED"; | |
1995 } else if (_bitmap->isMarked((HeapWord*) obj)) | |
1996 str = "marked"; | |
1997 else | |
1998 str = "#### NOT MARKED ####"; | |
1999 } | |
2000 | |
2001 _out->print_cr(" "PTR_FORMAT" contains "PTR_FORMAT" %s%s", | |
2002 p, (void*) obj, str, str2); | |
2003 } | |
2004 }; | |
2005 | |
2006 class ReachablePrinterClosure: public BitMapClosure { | |
2007 private: | |
2008 CMBitMapRO* _bitmap; | |
2009 outputStream* _out; | |
2010 | |
2011 public: | |
2012 ReachablePrinterClosure(CMBitMapRO* bitmap, outputStream* out) : | |
2013 _bitmap(bitmap), _out(out) { } | |
2014 | |
2015 bool do_bit(size_t offset) { | |
2016 HeapWord* addr = _bitmap->offsetToHeapWord(offset); | |
2017 ReachablePrinterOopClosure oopCl(_bitmap, _out); | |
2018 | |
2019 _out->print_cr(" obj "PTR_FORMAT", offset %10d (marked)", addr, offset); | |
2020 oop(addr)->oop_iterate(&oopCl); | |
2021 _out->print_cr(""); | |
2022 | |
2023 return true; | |
2024 } | |
2025 }; | |
2026 | |
2027 class ObjInRegionReachablePrinterClosure : public ObjectClosure { | |
2028 private: | |
2029 CMBitMapRO* _bitmap; | |
2030 outputStream* _out; | |
2031 | |
2032 public: | |
2033 void do_object(oop o) { | |
2034 ReachablePrinterOopClosure oopCl(_bitmap, _out); | |
2035 | |
2036 _out->print_cr(" obj "PTR_FORMAT" (over TAMS)", (void*) o); | |
2037 o->oop_iterate(&oopCl); | |
2038 _out->print_cr(""); | |
2039 } | |
2040 | |
2041 ObjInRegionReachablePrinterClosure(CMBitMapRO* bitmap, outputStream* out) : | |
2042 _bitmap(bitmap), _out(out) { } | |
2043 }; | |
2044 | |
2045 class RegionReachablePrinterClosure : public HeapRegionClosure { | |
2046 private: | |
2047 CMBitMapRO* _bitmap; | |
2048 outputStream* _out; | |
2049 | |
2050 public: | |
2051 bool doHeapRegion(HeapRegion* hr) { | |
2052 HeapWord* b = hr->bottom(); | |
2053 HeapWord* e = hr->end(); | |
2054 HeapWord* t = hr->top(); | |
2055 HeapWord* p = hr->prev_top_at_mark_start(); | |
2056 _out->print_cr("** ["PTR_FORMAT", "PTR_FORMAT"] top: "PTR_FORMAT" " | |
2057 "PTAMS: "PTR_FORMAT, b, e, t, p); | |
2058 _out->print_cr(""); | |
2059 | |
2060 ObjInRegionReachablePrinterClosure ocl(_bitmap, _out); | |
2061 hr->object_iterate_mem_careful(MemRegion(p, t), &ocl); | |
2062 | |
2063 return false; | |
2064 } | |
2065 | |
2066 RegionReachablePrinterClosure(CMBitMapRO* bitmap, | |
2067 outputStream* out) : | |
2068 _bitmap(bitmap), _out(out) { } | |
2069 }; | |
2070 | |
2071 void ConcurrentMark::print_prev_bitmap_reachable() { | |
2072 outputStream* out = gclog_or_tty; | |
2073 | |
2074 #if SEND_HEAP_DUMP_TO_FILE | |
2075 guarantee(heap_dump_file == NULL, "Protocol"); | |
2076 char fn_buf[100]; | |
2077 sprintf(fn_buf, "/tmp/dump.txt.%d", os::current_process_id()); | |
2078 heap_dump_file = fopen(fn_buf, "w"); | |
2079 fileStream fstream(heap_dump_file); | |
2080 out = &fstream; | |
2081 #endif // SEND_HEAP_DUMP_TO_FILE | |
2082 | |
2083 RegionReachablePrinterClosure rcl(_prevMarkBitMap, out); | |
2084 out->print_cr("--- ITERATING OVER REGIONS WITH PTAMS < TOP"); | |
2085 _g1h->heap_region_iterate(&rcl); | |
2086 out->print_cr(""); | |
2087 | |
2088 ReachablePrinterClosure cl(_prevMarkBitMap, out); | |
2089 out->print_cr("--- REACHABLE OBJECTS ON THE BITMAP"); | |
2090 _prevMarkBitMap->iterate(&cl); | |
2091 out->print_cr(""); | |
2092 | |
2093 #if SEND_HEAP_DUMP_TO_FILE | |
2094 fclose(heap_dump_file); | |
2095 heap_dump_file = NULL; | |
2096 #endif // SEND_HEAP_DUMP_TO_FILE | |
2097 } | |
2098 | |
2099 // This note is for drainAllSATBBuffers and the code in between. | |
2100 // In the future we could reuse a task to do this work during an | |
2101 // evacuation pause (since now tasks are not active and can be claimed | |
2102 // during an evacuation pause). This was a late change to the code and | |
2103 // is currently not being taken advantage of. | |
2104 | |
2105 class CMGlobalObjectClosure : public ObjectClosure { | |
2106 private: | |
2107 ConcurrentMark* _cm; | |
2108 | |
2109 public: | |
2110 void do_object(oop obj) { | |
2111 _cm->deal_with_reference(obj); | |
2112 } | |
2113 | |
2114 CMGlobalObjectClosure(ConcurrentMark* cm) : _cm(cm) { } | |
2115 }; | |
2116 | |
2117 void ConcurrentMark::deal_with_reference(oop obj) { | |
2118 if (verbose_high()) | |
2119 gclog_or_tty->print_cr("[global] we're dealing with reference "PTR_FORMAT, | |
2120 (void*) obj); | |
2121 | |
2122 | |
2123 HeapWord* objAddr = (HeapWord*) obj; | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2124 assert(obj->is_oop_or_null(true /* ignore mark word */), "Error"); |
342 | 2125 if (_g1h->is_in_g1_reserved(objAddr)) { |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2126 assert(obj != NULL, "is_in_g1_reserved should ensure this"); |
342 | 2127 HeapRegion* hr = _g1h->heap_region_containing(obj); |
2128 if (_g1h->is_obj_ill(obj, hr)) { | |
2129 if (verbose_high()) | |
2130 gclog_or_tty->print_cr("[global] "PTR_FORMAT" is not considered " | |
2131 "marked", (void*) obj); | |
2132 | |
2133 // we need to mark it first | |
2134 if (_nextMarkBitMap->parMark(objAddr)) { | |
2135 // No OrderAccess:store_load() is needed. It is implicit in the | |
2136 // CAS done in parMark(objAddr) above | |
2137 HeapWord* finger = _finger; | |
2138 if (objAddr < finger) { | |
2139 if (verbose_high()) | |
2140 gclog_or_tty->print_cr("[global] below the global finger " | |
2141 "("PTR_FORMAT"), pushing it", finger); | |
2142 if (!mark_stack_push(obj)) { | |
2143 if (verbose_low()) | |
2144 gclog_or_tty->print_cr("[global] global stack overflow during " | |
2145 "deal_with_reference"); | |
2146 } | |
2147 } | |
2148 } | |
2149 } | |
2150 } | |
2151 } | |
2152 | |
2153 void ConcurrentMark::drainAllSATBBuffers() { | |
2154 CMGlobalObjectClosure oc(this); | |
2155 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
2156 satb_mq_set.set_closure(&oc); | |
2157 | |
2158 while (satb_mq_set.apply_closure_to_completed_buffer()) { | |
2159 if (verbose_medium()) | |
2160 gclog_or_tty->print_cr("[global] processed an SATB buffer"); | |
2161 } | |
2162 | |
2163 // no need to check whether we should do this, as this is only | |
2164 // called during an evacuation pause | |
2165 satb_mq_set.iterate_closure_all_threads(); | |
2166 | |
2167 satb_mq_set.set_closure(NULL); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2168 assert(satb_mq_set.completed_buffers_num() == 0, "invariant"); |
342 | 2169 } |
2170 | |
2171 void ConcurrentMark::markPrev(oop p) { | |
2172 // Note we are overriding the read-only view of the prev map here, via | |
2173 // the cast. | |
2174 ((CMBitMap*)_prevMarkBitMap)->mark((HeapWord*)p); | |
2175 } | |
2176 | |
2177 void ConcurrentMark::clear(oop p) { | |
2178 assert(p != NULL && p->is_oop(), "expected an oop"); | |
2179 HeapWord* addr = (HeapWord*)p; | |
2180 assert(addr >= _nextMarkBitMap->startWord() || | |
2181 addr < _nextMarkBitMap->endWord(), "in a region"); | |
2182 | |
2183 _nextMarkBitMap->clear(addr); | |
2184 } | |
2185 | |
2186 void ConcurrentMark::clearRangeBothMaps(MemRegion mr) { | |
2187 // Note we are overriding the read-only view of the prev map here, via | |
2188 // the cast. | |
2189 ((CMBitMap*)_prevMarkBitMap)->clearRange(mr); | |
2190 _nextMarkBitMap->clearRange(mr); | |
2191 } | |
2192 | |
2193 HeapRegion* | |
2194 ConcurrentMark::claim_region(int task_num) { | |
2195 // "checkpoint" the finger | |
2196 HeapWord* finger = _finger; | |
2197 | |
2198 // _heap_end will not change underneath our feet; it only changes at | |
2199 // yield points. | |
2200 while (finger < _heap_end) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2201 assert(_g1h->is_in_g1_reserved(finger), "invariant"); |
342 | 2202 |
2203 // is the gap between reading the finger and doing the CAS too long? | |
2204 | |
2205 HeapRegion* curr_region = _g1h->heap_region_containing(finger); | |
2206 HeapWord* bottom = curr_region->bottom(); | |
2207 HeapWord* end = curr_region->end(); | |
2208 HeapWord* limit = curr_region->next_top_at_mark_start(); | |
2209 | |
2210 if (verbose_low()) | |
2211 gclog_or_tty->print_cr("[%d] curr_region = "PTR_FORMAT" " | |
2212 "["PTR_FORMAT", "PTR_FORMAT"), " | |
2213 "limit = "PTR_FORMAT, | |
2214 task_num, curr_region, bottom, end, limit); | |
2215 | |
2216 HeapWord* res = | |
2217 (HeapWord*) Atomic::cmpxchg_ptr(end, &_finger, finger); | |
2218 if (res == finger) { | |
2219 // we succeeded | |
2220 | |
2221 // notice that _finger == end cannot be guaranteed here since, | |
2222 // someone else might have moved the finger even further | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2223 assert(_finger >= end, "the finger should have moved forward"); |
342 | 2224 |
2225 if (verbose_low()) | |
2226 gclog_or_tty->print_cr("[%d] we were successful with region = " | |
2227 PTR_FORMAT, task_num, curr_region); | |
2228 | |
2229 if (limit > bottom) { | |
2230 if (verbose_low()) | |
2231 gclog_or_tty->print_cr("[%d] region "PTR_FORMAT" is not empty, " | |
2232 "returning it ", task_num, curr_region); | |
2233 return curr_region; | |
2234 } else { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2235 assert(limit == bottom, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2236 "the region limit should be at bottom"); |
342 | 2237 if (verbose_low()) |
2238 gclog_or_tty->print_cr("[%d] region "PTR_FORMAT" is empty, " | |
2239 "returning NULL", task_num, curr_region); | |
2240 // we return NULL and the caller should try calling | |
2241 // claim_region() again. | |
2242 return NULL; | |
2243 } | |
2244 } else { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2245 assert(_finger > finger, "the finger should have moved forward"); |
342 | 2246 if (verbose_low()) |
2247 gclog_or_tty->print_cr("[%d] somebody else moved the finger, " | |
2248 "global finger = "PTR_FORMAT", " | |
2249 "our finger = "PTR_FORMAT, | |
2250 task_num, _finger, finger); | |
2251 | |
2252 // read it again | |
2253 finger = _finger; | |
2254 } | |
2255 } | |
2256 | |
2257 return NULL; | |
2258 } | |
2259 | |
2260 void ConcurrentMark::oops_do(OopClosure* cl) { | |
2261 if (_markStack.size() > 0 && verbose_low()) | |
2262 gclog_or_tty->print_cr("[global] scanning the global marking stack, " | |
2263 "size = %d", _markStack.size()); | |
2264 // we first iterate over the contents of the mark stack... | |
2265 _markStack.oops_do(cl); | |
2266 | |
2267 for (int i = 0; i < (int)_max_task_num; ++i) { | |
2268 OopTaskQueue* queue = _task_queues->queue((int)i); | |
2269 | |
2270 if (queue->size() > 0 && verbose_low()) | |
2271 gclog_or_tty->print_cr("[global] scanning task queue of task %d, " | |
2272 "size = %d", i, queue->size()); | |
2273 | |
2274 // ...then over the contents of the all the task queues. | |
2275 queue->oops_do(cl); | |
2276 } | |
2277 | |
2278 // finally, invalidate any entries that in the region stack that | |
2279 // point into the collection set | |
2280 if (_regionStack.invalidate_entries_into_cset()) { | |
2281 // otherwise, any gray objects copied during the evacuation pause | |
2282 // might not be visited. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2283 assert(_should_gray_objects, "invariant"); |
342 | 2284 } |
2285 } | |
2286 | |
2287 void ConcurrentMark::clear_marking_state() { | |
2288 _markStack.setEmpty(); | |
2289 _markStack.clear_overflow(); | |
2290 _regionStack.setEmpty(); | |
2291 _regionStack.clear_overflow(); | |
2292 clear_has_overflown(); | |
2293 _finger = _heap_start; | |
2294 | |
2295 for (int i = 0; i < (int)_max_task_num; ++i) { | |
2296 OopTaskQueue* queue = _task_queues->queue(i); | |
2297 queue->set_empty(); | |
2298 } | |
2299 } | |
2300 | |
2301 void ConcurrentMark::print_stats() { | |
2302 if (verbose_stats()) { | |
2303 gclog_or_tty->print_cr("---------------------------------------------------------------------"); | |
2304 for (size_t i = 0; i < _active_tasks; ++i) { | |
2305 _tasks[i]->print_stats(); | |
2306 gclog_or_tty->print_cr("---------------------------------------------------------------------"); | |
2307 } | |
2308 } | |
2309 } | |
2310 | |
2311 class CSMarkOopClosure: public OopClosure { | |
2312 friend class CSMarkBitMapClosure; | |
2313 | |
2314 G1CollectedHeap* _g1h; | |
2315 CMBitMap* _bm; | |
2316 ConcurrentMark* _cm; | |
2317 oop* _ms; | |
2318 jint* _array_ind_stack; | |
2319 int _ms_size; | |
2320 int _ms_ind; | |
2321 int _array_increment; | |
2322 | |
2323 bool push(oop obj, int arr_ind = 0) { | |
2324 if (_ms_ind == _ms_size) { | |
2325 gclog_or_tty->print_cr("Mark stack is full."); | |
2326 return false; | |
2327 } | |
2328 _ms[_ms_ind] = obj; | |
2329 if (obj->is_objArray()) _array_ind_stack[_ms_ind] = arr_ind; | |
2330 _ms_ind++; | |
2331 return true; | |
2332 } | |
2333 | |
2334 oop pop() { | |
2335 if (_ms_ind == 0) return NULL; | |
2336 else { | |
2337 _ms_ind--; | |
2338 return _ms[_ms_ind]; | |
2339 } | |
2340 } | |
2341 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2342 template <class T> bool drain() { |
342 | 2343 while (_ms_ind > 0) { |
2344 oop obj = pop(); | |
2345 assert(obj != NULL, "Since index was non-zero."); | |
2346 if (obj->is_objArray()) { | |
2347 jint arr_ind = _array_ind_stack[_ms_ind]; | |
2348 objArrayOop aobj = objArrayOop(obj); | |
2349 jint len = aobj->length(); | |
2350 jint next_arr_ind = arr_ind + _array_increment; | |
2351 if (next_arr_ind < len) { | |
2352 push(obj, next_arr_ind); | |
2353 } | |
2354 // Now process this portion of this one. | |
2355 int lim = MIN2(next_arr_ind, len); | |
2356 for (int j = arr_ind; j < lim; j++) { | |
912
308762b2bf14
6872000: G1: compilation fails on linux/older gcc
apetrusenko
parents:
866
diff
changeset
|
2357 do_oop(aobj->objArrayOopDesc::obj_at_addr<T>(j)); |
342 | 2358 } |
2359 | |
2360 } else { | |
2361 obj->oop_iterate(this); | |
2362 } | |
2363 if (abort()) return false; | |
2364 } | |
2365 return true; | |
2366 } | |
2367 | |
2368 public: | |
2369 CSMarkOopClosure(ConcurrentMark* cm, int ms_size) : | |
2370 _g1h(G1CollectedHeap::heap()), | |
2371 _cm(cm), | |
2372 _bm(cm->nextMarkBitMap()), | |
2373 _ms_size(ms_size), _ms_ind(0), | |
2374 _ms(NEW_C_HEAP_ARRAY(oop, ms_size)), | |
2375 _array_ind_stack(NEW_C_HEAP_ARRAY(jint, ms_size)), | |
2376 _array_increment(MAX2(ms_size/8, 16)) | |
2377 {} | |
2378 | |
2379 ~CSMarkOopClosure() { | |
2380 FREE_C_HEAP_ARRAY(oop, _ms); | |
2381 FREE_C_HEAP_ARRAY(jint, _array_ind_stack); | |
2382 } | |
2383 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2384 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2385 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2386 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2387 template <class T> void do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2388 T heap_oop = oopDesc::load_heap_oop(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2389 if (oopDesc::is_null(heap_oop)) return; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2390 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
342 | 2391 if (obj->is_forwarded()) { |
2392 // If the object has already been forwarded, we have to make sure | |
2393 // that it's marked. So follow the forwarding pointer. Note that | |
2394 // this does the right thing for self-forwarding pointers in the | |
2395 // evacuation failure case. | |
2396 obj = obj->forwardee(); | |
2397 } | |
2398 HeapRegion* hr = _g1h->heap_region_containing(obj); | |
2399 if (hr != NULL) { | |
2400 if (hr->in_collection_set()) { | |
2401 if (_g1h->is_obj_ill(obj)) { | |
2402 _bm->mark((HeapWord*)obj); | |
2403 if (!push(obj)) { | |
2404 gclog_or_tty->print_cr("Setting abort in CSMarkOopClosure because push failed."); | |
2405 set_abort(); | |
2406 } | |
2407 } | |
2408 } else { | |
2409 // Outside the collection set; we need to gray it | |
2410 _cm->deal_with_reference(obj); | |
2411 } | |
2412 } | |
2413 } | |
2414 }; | |
2415 | |
2416 class CSMarkBitMapClosure: public BitMapClosure { | |
2417 G1CollectedHeap* _g1h; | |
2418 CMBitMap* _bitMap; | |
2419 ConcurrentMark* _cm; | |
2420 CSMarkOopClosure _oop_cl; | |
2421 public: | |
2422 CSMarkBitMapClosure(ConcurrentMark* cm, int ms_size) : | |
2423 _g1h(G1CollectedHeap::heap()), | |
2424 _bitMap(cm->nextMarkBitMap()), | |
2425 _oop_cl(cm, ms_size) | |
2426 {} | |
2427 | |
2428 ~CSMarkBitMapClosure() {} | |
2429 | |
2430 bool do_bit(size_t offset) { | |
2431 // convert offset into a HeapWord* | |
2432 HeapWord* addr = _bitMap->offsetToHeapWord(offset); | |
2433 assert(_bitMap->endWord() && addr < _bitMap->endWord(), | |
2434 "address out of range"); | |
2435 assert(_bitMap->isMarked(addr), "tautology"); | |
2436 oop obj = oop(addr); | |
2437 if (!obj->is_forwarded()) { | |
2438 if (!_oop_cl.push(obj)) return false; | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2439 if (UseCompressedOops) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2440 if (!_oop_cl.drain<narrowOop>()) return false; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2441 } else { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2442 if (!_oop_cl.drain<oop>()) return false; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2443 } |
342 | 2444 } |
2445 // Otherwise... | |
2446 return true; | |
2447 } | |
2448 }; | |
2449 | |
2450 | |
2451 class CompleteMarkingInCSHRClosure: public HeapRegionClosure { | |
2452 CMBitMap* _bm; | |
2453 CSMarkBitMapClosure _bit_cl; | |
2454 enum SomePrivateConstants { | |
2455 MSSize = 1000 | |
2456 }; | |
2457 bool _completed; | |
2458 public: | |
2459 CompleteMarkingInCSHRClosure(ConcurrentMark* cm) : | |
2460 _bm(cm->nextMarkBitMap()), | |
2461 _bit_cl(cm, MSSize), | |
2462 _completed(true) | |
2463 {} | |
2464 | |
2465 ~CompleteMarkingInCSHRClosure() {} | |
2466 | |
2467 bool doHeapRegion(HeapRegion* r) { | |
2468 if (!r->evacuation_failed()) { | |
2469 MemRegion mr = MemRegion(r->bottom(), r->next_top_at_mark_start()); | |
2470 if (!mr.is_empty()) { | |
2471 if (!_bm->iterate(&_bit_cl, mr)) { | |
2472 _completed = false; | |
2473 return true; | |
2474 } | |
2475 } | |
2476 } | |
2477 return false; | |
2478 } | |
2479 | |
2480 bool completed() { return _completed; } | |
2481 }; | |
2482 | |
2483 class ClearMarksInHRClosure: public HeapRegionClosure { | |
2484 CMBitMap* _bm; | |
2485 public: | |
2486 ClearMarksInHRClosure(CMBitMap* bm): _bm(bm) { } | |
2487 | |
2488 bool doHeapRegion(HeapRegion* r) { | |
2489 if (!r->used_region().is_empty() && !r->evacuation_failed()) { | |
2490 MemRegion usedMR = r->used_region(); | |
2491 _bm->clearRange(r->used_region()); | |
2492 } | |
2493 return false; | |
2494 } | |
2495 }; | |
2496 | |
2497 void ConcurrentMark::complete_marking_in_collection_set() { | |
2498 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
2499 | |
2500 if (!g1h->mark_in_progress()) { | |
2501 g1h->g1_policy()->record_mark_closure_time(0.0); | |
2502 return; | |
2503 } | |
2504 | |
2505 int i = 1; | |
2506 double start = os::elapsedTime(); | |
2507 while (true) { | |
2508 i++; | |
2509 CompleteMarkingInCSHRClosure cmplt(this); | |
2510 g1h->collection_set_iterate(&cmplt); | |
2511 if (cmplt.completed()) break; | |
2512 } | |
2513 double end_time = os::elapsedTime(); | |
2514 double elapsed_time_ms = (end_time - start) * 1000.0; | |
2515 g1h->g1_policy()->record_mark_closure_time(elapsed_time_ms); | |
2516 if (PrintGCDetails) { | |
2517 gclog_or_tty->print_cr("Mark closure took %5.2f ms.", elapsed_time_ms); | |
2518 } | |
2519 | |
2520 ClearMarksInHRClosure clr(nextMarkBitMap()); | |
2521 g1h->collection_set_iterate(&clr); | |
2522 } | |
2523 | |
2524 // The next two methods deal with the following optimisation. Some | |
2525 // objects are gray by being marked and located above the finger. If | |
2526 // they are copied, during an evacuation pause, below the finger then | |
2527 // the need to be pushed on the stack. The observation is that, if | |
2528 // there are no regions in the collection set located above the | |
2529 // finger, then the above cannot happen, hence we do not need to | |
2530 // explicitly gray any objects when copying them to below the | |
2531 // finger. The global stack will be scanned to ensure that, if it | |
2532 // points to objects being copied, it will update their | |
2533 // location. There is a tricky situation with the gray objects in | |
2534 // region stack that are being coped, however. See the comment in | |
2535 // newCSet(). | |
2536 | |
2537 void ConcurrentMark::newCSet() { | |
2538 if (!concurrent_marking_in_progress()) | |
2539 // nothing to do if marking is not in progress | |
2540 return; | |
2541 | |
2542 // find what the lowest finger is among the global and local fingers | |
2543 _min_finger = _finger; | |
2544 for (int i = 0; i < (int)_max_task_num; ++i) { | |
2545 CMTask* task = _tasks[i]; | |
2546 HeapWord* task_finger = task->finger(); | |
2547 if (task_finger != NULL && task_finger < _min_finger) | |
2548 _min_finger = task_finger; | |
2549 } | |
2550 | |
2551 _should_gray_objects = false; | |
2552 | |
2553 // This fixes a very subtle and fustrating bug. It might be the case | |
2554 // that, during en evacuation pause, heap regions that contain | |
2555 // objects that are gray (by being in regions contained in the | |
2556 // region stack) are included in the collection set. Since such gray | |
2557 // objects will be moved, and because it's not easy to redirect | |
2558 // region stack entries to point to a new location (because objects | |
2559 // in one region might be scattered to multiple regions after they | |
2560 // are copied), one option is to ensure that all marked objects | |
2561 // copied during a pause are pushed on the stack. Notice, however, | |
2562 // that this problem can only happen when the region stack is not | |
2563 // empty during an evacuation pause. So, we make the fix a bit less | |
2564 // conservative and ensure that regions are pushed on the stack, | |
2565 // irrespective whether all collection set regions are below the | |
2566 // finger, if the region stack is not empty. This is expected to be | |
2567 // a rare case, so I don't think it's necessary to be smarted about it. | |
2568 if (!region_stack_empty()) | |
2569 _should_gray_objects = true; | |
2570 } | |
2571 | |
2572 void ConcurrentMark::registerCSetRegion(HeapRegion* hr) { | |
2573 if (!concurrent_marking_in_progress()) | |
2574 return; | |
2575 | |
2576 HeapWord* region_end = hr->end(); | |
2577 if (region_end > _min_finger) | |
2578 _should_gray_objects = true; | |
2579 } | |
2580 | |
2581 // abandon current marking iteration due to a Full GC | |
2582 void ConcurrentMark::abort() { | |
2583 // Clear all marks to force marking thread to do nothing | |
2584 _nextMarkBitMap->clearAll(); | |
2585 // Empty mark stack | |
2586 clear_marking_state(); | |
2587 for (int i = 0; i < (int)_max_task_num; ++i) | |
2588 _tasks[i]->clear_region_fields(); | |
2589 _has_aborted = true; | |
2590 | |
2591 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
2592 satb_mq_set.abandon_partial_marking(); | |
2593 satb_mq_set.set_active_all_threads(false); | |
2594 } | |
2595 | |
2596 static void print_ms_time_info(const char* prefix, const char* name, | |
2597 NumberSeq& ns) { | |
2598 gclog_or_tty->print_cr("%s%5d %12s: total time = %8.2f s (avg = %8.2f ms).", | |
2599 prefix, ns.num(), name, ns.sum()/1000.0, ns.avg()); | |
2600 if (ns.num() > 0) { | |
2601 gclog_or_tty->print_cr("%s [std. dev = %8.2f ms, max = %8.2f ms]", | |
2602 prefix, ns.sd(), ns.maximum()); | |
2603 } | |
2604 } | |
2605 | |
2606 void ConcurrentMark::print_summary_info() { | |
2607 gclog_or_tty->print_cr(" Concurrent marking:"); | |
2608 print_ms_time_info(" ", "init marks", _init_times); | |
2609 print_ms_time_info(" ", "remarks", _remark_times); | |
2610 { | |
2611 print_ms_time_info(" ", "final marks", _remark_mark_times); | |
2612 print_ms_time_info(" ", "weak refs", _remark_weak_ref_times); | |
2613 | |
2614 } | |
2615 print_ms_time_info(" ", "cleanups", _cleanup_times); | |
2616 gclog_or_tty->print_cr(" Final counting total time = %8.2f s (avg = %8.2f ms).", | |
2617 _total_counting_time, | |
2618 (_cleanup_times.num() > 0 ? _total_counting_time * 1000.0 / | |
2619 (double)_cleanup_times.num() | |
2620 : 0.0)); | |
2621 if (G1ScrubRemSets) { | |
2622 gclog_or_tty->print_cr(" RS scrub total time = %8.2f s (avg = %8.2f ms).", | |
2623 _total_rs_scrub_time, | |
2624 (_cleanup_times.num() > 0 ? _total_rs_scrub_time * 1000.0 / | |
2625 (double)_cleanup_times.num() | |
2626 : 0.0)); | |
2627 } | |
2628 gclog_or_tty->print_cr(" Total stop_world time = %8.2f s.", | |
2629 (_init_times.sum() + _remark_times.sum() + | |
2630 _cleanup_times.sum())/1000.0); | |
2631 gclog_or_tty->print_cr(" Total concurrent time = %8.2f s " | |
2632 "(%8.2f s marking, %8.2f s counting).", | |
2633 cmThread()->vtime_accum(), | |
2634 cmThread()->vtime_mark_accum(), | |
2635 cmThread()->vtime_count_accum()); | |
2636 } | |
2637 | |
1019 | 2638 void ConcurrentMark::print_worker_threads_on(outputStream* st) const { |
2639 _parallel_workers->print_worker_threads_on(st); | |
2640 } | |
2641 | |
342 | 2642 // Closures |
2643 // XXX: there seems to be a lot of code duplication here; | |
2644 // should refactor and consolidate the shared code. | |
2645 | |
2646 // This closure is used to mark refs into the CMS generation in | |
2647 // the CMS bit map. Called at the first checkpoint. | |
2648 | |
2649 // We take a break if someone is trying to stop the world. | |
2650 bool ConcurrentMark::do_yield_check(int worker_i) { | |
2651 if (should_yield()) { | |
2652 if (worker_i == 0) | |
2653 _g1h->g1_policy()->record_concurrent_pause(); | |
2654 cmThread()->yield(); | |
2655 if (worker_i == 0) | |
2656 _g1h->g1_policy()->record_concurrent_pause_end(); | |
2657 return true; | |
2658 } else { | |
2659 return false; | |
2660 } | |
2661 } | |
2662 | |
2663 bool ConcurrentMark::should_yield() { | |
2664 return cmThread()->should_yield(); | |
2665 } | |
2666 | |
2667 bool ConcurrentMark::containing_card_is_marked(void* p) { | |
2668 size_t offset = pointer_delta(p, _g1h->reserved_region().start(), 1); | |
2669 return _card_bm.at(offset >> CardTableModRefBS::card_shift); | |
2670 } | |
2671 | |
2672 bool ConcurrentMark::containing_cards_are_marked(void* start, | |
2673 void* last) { | |
2674 return | |
2675 containing_card_is_marked(start) && | |
2676 containing_card_is_marked(last); | |
2677 } | |
2678 | |
2679 #ifndef PRODUCT | |
2680 // for debugging purposes | |
2681 void ConcurrentMark::print_finger() { | |
2682 gclog_or_tty->print_cr("heap ["PTR_FORMAT", "PTR_FORMAT"), global finger = "PTR_FORMAT, | |
2683 _heap_start, _heap_end, _finger); | |
2684 for (int i = 0; i < (int) _max_task_num; ++i) { | |
2685 gclog_or_tty->print(" %d: "PTR_FORMAT, i, _tasks[i]->finger()); | |
2686 } | |
2687 gclog_or_tty->print_cr(""); | |
2688 } | |
2689 #endif | |
2690 | |
2691 // Closure for iteration over bitmaps | |
2692 class CMBitMapClosure : public BitMapClosure { | |
2693 private: | |
2694 // the bitmap that is being iterated over | |
2695 CMBitMap* _nextMarkBitMap; | |
2696 ConcurrentMark* _cm; | |
2697 CMTask* _task; | |
2698 // true if we're scanning a heap region claimed by the task (so that | |
2699 // we move the finger along), false if we're not, i.e. currently when | |
2700 // scanning a heap region popped from the region stack (so that we | |
2701 // do not move the task finger along; it'd be a mistake if we did so). | |
2702 bool _scanning_heap_region; | |
2703 | |
2704 public: | |
2705 CMBitMapClosure(CMTask *task, | |
2706 ConcurrentMark* cm, | |
2707 CMBitMap* nextMarkBitMap) | |
2708 : _task(task), _cm(cm), _nextMarkBitMap(nextMarkBitMap) { } | |
2709 | |
2710 void set_scanning_heap_region(bool scanning_heap_region) { | |
2711 _scanning_heap_region = scanning_heap_region; | |
2712 } | |
2713 | |
2714 bool do_bit(size_t offset) { | |
2715 HeapWord* addr = _nextMarkBitMap->offsetToHeapWord(offset); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2716 assert(_nextMarkBitMap->isMarked(addr), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2717 assert( addr < _cm->finger(), "invariant"); |
342 | 2718 |
2719 if (_scanning_heap_region) { | |
2720 statsOnly( _task->increase_objs_found_on_bitmap() ); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2721 assert(addr >= _task->finger(), "invariant"); |
342 | 2722 // We move that task's local finger along. |
2723 _task->move_finger_to(addr); | |
2724 } else { | |
2725 // We move the task's region finger along. | |
2726 _task->move_region_finger_to(addr); | |
2727 } | |
2728 | |
2729 _task->scan_object(oop(addr)); | |
2730 // we only partially drain the local queue and global stack | |
2731 _task->drain_local_queue(true); | |
2732 _task->drain_global_stack(true); | |
2733 | |
2734 // if the has_aborted flag has been raised, we need to bail out of | |
2735 // the iteration | |
2736 return !_task->has_aborted(); | |
2737 } | |
2738 }; | |
2739 | |
2740 // Closure for iterating over objects, currently only used for | |
2741 // processing SATB buffers. | |
2742 class CMObjectClosure : public ObjectClosure { | |
2743 private: | |
2744 CMTask* _task; | |
2745 | |
2746 public: | |
2747 void do_object(oop obj) { | |
2748 _task->deal_with_reference(obj); | |
2749 } | |
2750 | |
2751 CMObjectClosure(CMTask* task) : _task(task) { } | |
2752 }; | |
2753 | |
2754 // Closure for iterating over object fields | |
2755 class CMOopClosure : public OopClosure { | |
2756 private: | |
2757 G1CollectedHeap* _g1h; | |
2758 ConcurrentMark* _cm; | |
2759 CMTask* _task; | |
2760 | |
2761 public: | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2762 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2763 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2764 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2765 template <class T> void do_oop_work(T* p) { |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2766 assert(_g1h->is_in_g1_reserved((HeapWord*) p), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2767 assert(!_g1h->heap_region_containing((HeapWord*) p)->is_on_free_list(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2768 "invariant"); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2769 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2770 oop obj = oopDesc::load_decode_heap_oop(p); |
342 | 2771 if (_cm->verbose_high()) |
2772 gclog_or_tty->print_cr("[%d] we're looking at location " | |
2773 "*"PTR_FORMAT" = "PTR_FORMAT, | |
2774 _task->task_id(), p, (void*) obj); | |
2775 _task->deal_with_reference(obj); | |
2776 } | |
2777 | |
2778 CMOopClosure(G1CollectedHeap* g1h, | |
2779 ConcurrentMark* cm, | |
2780 CMTask* task) | |
2781 : _g1h(g1h), _cm(cm), _task(task) { } | |
2782 }; | |
2783 | |
2784 void CMTask::setup_for_region(HeapRegion* hr) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2785 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2786 assert(hr != NULL, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2787 "claim_region() should have filtered out continues humongous regions"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2788 assert(!hr->continuesHumongous(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2789 "claim_region() should have filtered out continues humongous regions"); |
342 | 2790 |
2791 if (_cm->verbose_low()) | |
2792 gclog_or_tty->print_cr("[%d] setting up for region "PTR_FORMAT, | |
2793 _task_id, hr); | |
2794 | |
2795 _curr_region = hr; | |
2796 _finger = hr->bottom(); | |
2797 update_region_limit(); | |
2798 } | |
2799 | |
2800 void CMTask::update_region_limit() { | |
2801 HeapRegion* hr = _curr_region; | |
2802 HeapWord* bottom = hr->bottom(); | |
2803 HeapWord* limit = hr->next_top_at_mark_start(); | |
2804 | |
2805 if (limit == bottom) { | |
2806 if (_cm->verbose_low()) | |
2807 gclog_or_tty->print_cr("[%d] found an empty region " | |
2808 "["PTR_FORMAT", "PTR_FORMAT")", | |
2809 _task_id, bottom, limit); | |
2810 // The region was collected underneath our feet. | |
2811 // We set the finger to bottom to ensure that the bitmap | |
2812 // iteration that will follow this will not do anything. | |
2813 // (this is not a condition that holds when we set the region up, | |
2814 // as the region is not supposed to be empty in the first place) | |
2815 _finger = bottom; | |
2816 } else if (limit >= _region_limit) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2817 assert(limit >= _finger, "peace of mind"); |
342 | 2818 } else { |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2819 assert(limit < _region_limit, "only way to get here"); |
342 | 2820 // This can happen under some pretty unusual circumstances. An |
2821 // evacuation pause empties the region underneath our feet (NTAMS | |
2822 // at bottom). We then do some allocation in the region (NTAMS | |
2823 // stays at bottom), followed by the region being used as a GC | |
2824 // alloc region (NTAMS will move to top() and the objects | |
2825 // originally below it will be grayed). All objects now marked in | |
2826 // the region are explicitly grayed, if below the global finger, | |
2827 // and we do not need in fact to scan anything else. So, we simply | |
2828 // set _finger to be limit to ensure that the bitmap iteration | |
2829 // doesn't do anything. | |
2830 _finger = limit; | |
2831 } | |
2832 | |
2833 _region_limit = limit; | |
2834 } | |
2835 | |
2836 void CMTask::giveup_current_region() { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2837 assert(_curr_region != NULL, "invariant"); |
342 | 2838 if (_cm->verbose_low()) |
2839 gclog_or_tty->print_cr("[%d] giving up region "PTR_FORMAT, | |
2840 _task_id, _curr_region); | |
2841 clear_region_fields(); | |
2842 } | |
2843 | |
2844 void CMTask::clear_region_fields() { | |
2845 // Values for these three fields that indicate that we're not | |
2846 // holding on to a region. | |
2847 _curr_region = NULL; | |
2848 _finger = NULL; | |
2849 _region_limit = NULL; | |
2850 | |
2851 _region_finger = NULL; | |
2852 } | |
2853 | |
2854 void CMTask::reset(CMBitMap* nextMarkBitMap) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2855 guarantee(nextMarkBitMap != NULL, "invariant"); |
342 | 2856 |
2857 if (_cm->verbose_low()) | |
2858 gclog_or_tty->print_cr("[%d] resetting", _task_id); | |
2859 | |
2860 _nextMarkBitMap = nextMarkBitMap; | |
2861 clear_region_fields(); | |
2862 | |
2863 _calls = 0; | |
2864 _elapsed_time_ms = 0.0; | |
2865 _termination_time_ms = 0.0; | |
2866 _termination_start_time_ms = 0.0; | |
2867 | |
2868 #if _MARKING_STATS_ | |
2869 _local_pushes = 0; | |
2870 _local_pops = 0; | |
2871 _local_max_size = 0; | |
2872 _objs_scanned = 0; | |
2873 _global_pushes = 0; | |
2874 _global_pops = 0; | |
2875 _global_max_size = 0; | |
2876 _global_transfers_to = 0; | |
2877 _global_transfers_from = 0; | |
2878 _region_stack_pops = 0; | |
2879 _regions_claimed = 0; | |
2880 _objs_found_on_bitmap = 0; | |
2881 _satb_buffers_processed = 0; | |
2882 _steal_attempts = 0; | |
2883 _steals = 0; | |
2884 _aborted = 0; | |
2885 _aborted_overflow = 0; | |
2886 _aborted_cm_aborted = 0; | |
2887 _aborted_yield = 0; | |
2888 _aborted_timed_out = 0; | |
2889 _aborted_satb = 0; | |
2890 _aborted_termination = 0; | |
2891 #endif // _MARKING_STATS_ | |
2892 } | |
2893 | |
2894 bool CMTask::should_exit_termination() { | |
2895 regular_clock_call(); | |
2896 // This is called when we are in the termination protocol. We should | |
2897 // quit if, for some reason, this task wants to abort or the global | |
2898 // stack is not empty (this means that we can get work from it). | |
2899 return !_cm->mark_stack_empty() || has_aborted(); | |
2900 } | |
2901 | |
2902 // This determines whether the method below will check both the local | |
2903 // and global fingers when determining whether to push on the stack a | |
2904 // gray object (value 1) or whether it will only check the global one | |
2905 // (value 0). The tradeoffs are that the former will be a bit more | |
2906 // accurate and possibly push less on the stack, but it might also be | |
2907 // a little bit slower. | |
2908 | |
2909 #define _CHECK_BOTH_FINGERS_ 1 | |
2910 | |
2911 void CMTask::deal_with_reference(oop obj) { | |
2912 if (_cm->verbose_high()) | |
2913 gclog_or_tty->print_cr("[%d] we're dealing with reference = "PTR_FORMAT, | |
2914 _task_id, (void*) obj); | |
2915 | |
2916 ++_refs_reached; | |
2917 | |
2918 HeapWord* objAddr = (HeapWord*) obj; | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2919 assert(obj->is_oop_or_null(true /* ignore mark word */), "Error"); |
342 | 2920 if (_g1h->is_in_g1_reserved(objAddr)) { |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2921 assert(obj != NULL, "is_in_g1_reserved should ensure this"); |
342 | 2922 HeapRegion* hr = _g1h->heap_region_containing(obj); |
2923 if (_g1h->is_obj_ill(obj, hr)) { | |
2924 if (_cm->verbose_high()) | |
2925 gclog_or_tty->print_cr("[%d] "PTR_FORMAT" is not considered marked", | |
2926 _task_id, (void*) obj); | |
2927 | |
2928 // we need to mark it first | |
2929 if (_nextMarkBitMap->parMark(objAddr)) { | |
2930 // No OrderAccess:store_load() is needed. It is implicit in the | |
2931 // CAS done in parMark(objAddr) above | |
2932 HeapWord* global_finger = _cm->finger(); | |
2933 | |
2934 #if _CHECK_BOTH_FINGERS_ | |
2935 // we will check both the local and global fingers | |
2936 | |
2937 if (_finger != NULL && objAddr < _finger) { | |
2938 if (_cm->verbose_high()) | |
2939 gclog_or_tty->print_cr("[%d] below the local finger ("PTR_FORMAT"), " | |
2940 "pushing it", _task_id, _finger); | |
2941 push(obj); | |
2942 } else if (_curr_region != NULL && objAddr < _region_limit) { | |
2943 // do nothing | |
2944 } else if (objAddr < global_finger) { | |
2945 // Notice that the global finger might be moving forward | |
2946 // concurrently. This is not a problem. In the worst case, we | |
2947 // mark the object while it is above the global finger and, by | |
2948 // the time we read the global finger, it has moved forward | |
2949 // passed this object. In this case, the object will probably | |
2950 // be visited when a task is scanning the region and will also | |
2951 // be pushed on the stack. So, some duplicate work, but no | |
2952 // correctness problems. | |
2953 | |
2954 if (_cm->verbose_high()) | |
2955 gclog_or_tty->print_cr("[%d] below the global finger " | |
2956 "("PTR_FORMAT"), pushing it", | |
2957 _task_id, global_finger); | |
2958 push(obj); | |
2959 } else { | |
2960 // do nothing | |
2961 } | |
2962 #else // _CHECK_BOTH_FINGERS_ | |
2963 // we will only check the global finger | |
2964 | |
2965 if (objAddr < global_finger) { | |
2966 // see long comment above | |
2967 | |
2968 if (_cm->verbose_high()) | |
2969 gclog_or_tty->print_cr("[%d] below the global finger " | |
2970 "("PTR_FORMAT"), pushing it", | |
2971 _task_id, global_finger); | |
2972 push(obj); | |
2973 } | |
2974 #endif // _CHECK_BOTH_FINGERS_ | |
2975 } | |
2976 } | |
2977 } | |
2978 } | |
2979 | |
2980 void CMTask::push(oop obj) { | |
2981 HeapWord* objAddr = (HeapWord*) obj; | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2982 assert(_g1h->is_in_g1_reserved(objAddr), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2983 assert(!_g1h->heap_region_containing(objAddr)->is_on_free_list(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2984 "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2985 assert(!_g1h->is_obj_ill(obj), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2986 assert(_nextMarkBitMap->isMarked(objAddr), "invariant"); |
342 | 2987 |
2988 if (_cm->verbose_high()) | |
2989 gclog_or_tty->print_cr("[%d] pushing "PTR_FORMAT, _task_id, (void*) obj); | |
2990 | |
2991 if (!_task_queue->push(obj)) { | |
2992 // The local task queue looks full. We need to push some entries | |
2993 // to the global stack. | |
2994 | |
2995 if (_cm->verbose_medium()) | |
2996 gclog_or_tty->print_cr("[%d] task queue overflow, " | |
2997 "moving entries to the global stack", | |
2998 _task_id); | |
2999 move_entries_to_global_stack(); | |
3000 | |
3001 // this should succeed since, even if we overflow the global | |
3002 // stack, we should have definitely removed some entries from the | |
3003 // local queue. So, there must be space on it. | |
3004 bool success = _task_queue->push(obj); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3005 assert(success, "invariant"); |
342 | 3006 } |
3007 | |
3008 statsOnly( int tmp_size = _task_queue->size(); | |
3009 if (tmp_size > _local_max_size) | |
3010 _local_max_size = tmp_size; | |
3011 ++_local_pushes ); | |
3012 } | |
3013 | |
3014 void CMTask::reached_limit() { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3015 assert(_words_scanned >= _words_scanned_limit || |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3016 _refs_reached >= _refs_reached_limit , |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3017 "shouldn't have been called otherwise"); |
342 | 3018 regular_clock_call(); |
3019 } | |
3020 | |
3021 void CMTask::regular_clock_call() { | |
3022 if (has_aborted()) | |
3023 return; | |
3024 | |
3025 // First, we need to recalculate the words scanned and refs reached | |
3026 // limits for the next clock call. | |
3027 recalculate_limits(); | |
3028 | |
3029 // During the regular clock call we do the following | |
3030 | |
3031 // (1) If an overflow has been flagged, then we abort. | |
3032 if (_cm->has_overflown()) { | |
3033 set_has_aborted(); | |
3034 return; | |
3035 } | |
3036 | |
3037 // If we are not concurrent (i.e. we're doing remark) we don't need | |
3038 // to check anything else. The other steps are only needed during | |
3039 // the concurrent marking phase. | |
3040 if (!concurrent()) | |
3041 return; | |
3042 | |
3043 // (2) If marking has been aborted for Full GC, then we also abort. | |
3044 if (_cm->has_aborted()) { | |
3045 set_has_aborted(); | |
3046 statsOnly( ++_aborted_cm_aborted ); | |
3047 return; | |
3048 } | |
3049 | |
3050 double curr_time_ms = os::elapsedVTime() * 1000.0; | |
3051 | |
3052 // (3) If marking stats are enabled, then we update the step history. | |
3053 #if _MARKING_STATS_ | |
3054 if (_words_scanned >= _words_scanned_limit) | |
3055 ++_clock_due_to_scanning; | |
3056 if (_refs_reached >= _refs_reached_limit) | |
3057 ++_clock_due_to_marking; | |
3058 | |
3059 double last_interval_ms = curr_time_ms - _interval_start_time_ms; | |
3060 _interval_start_time_ms = curr_time_ms; | |
3061 _all_clock_intervals_ms.add(last_interval_ms); | |
3062 | |
3063 if (_cm->verbose_medium()) { | |
3064 gclog_or_tty->print_cr("[%d] regular clock, interval = %1.2lfms, " | |
3065 "scanned = %d%s, refs reached = %d%s", | |
3066 _task_id, last_interval_ms, | |
3067 _words_scanned, | |
3068 (_words_scanned >= _words_scanned_limit) ? " (*)" : "", | |
3069 _refs_reached, | |
3070 (_refs_reached >= _refs_reached_limit) ? " (*)" : ""); | |
3071 } | |
3072 #endif // _MARKING_STATS_ | |
3073 | |
3074 // (4) We check whether we should yield. If we have to, then we abort. | |
3075 if (_cm->should_yield()) { | |
3076 // We should yield. To do this we abort the task. The caller is | |
3077 // responsible for yielding. | |
3078 set_has_aborted(); | |
3079 statsOnly( ++_aborted_yield ); | |
3080 return; | |
3081 } | |
3082 | |
3083 // (5) We check whether we've reached our time quota. If we have, | |
3084 // then we abort. | |
3085 double elapsed_time_ms = curr_time_ms - _start_time_ms; | |
3086 if (elapsed_time_ms > _time_target_ms) { | |
3087 set_has_aborted(); | |
3088 _has_aborted_timed_out = true; | |
3089 statsOnly( ++_aborted_timed_out ); | |
3090 return; | |
3091 } | |
3092 | |
3093 // (6) Finally, we check whether there are enough completed STAB | |
3094 // buffers available for processing. If there are, we abort. | |
3095 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
3096 if (!_draining_satb_buffers && satb_mq_set.process_completed_buffers()) { | |
3097 if (_cm->verbose_low()) | |
3098 gclog_or_tty->print_cr("[%d] aborting to deal with pending SATB buffers", | |
3099 _task_id); | |
3100 // we do need to process SATB buffers, we'll abort and restart | |
3101 // the marking task to do so | |
3102 set_has_aborted(); | |
3103 statsOnly( ++_aborted_satb ); | |
3104 return; | |
3105 } | |
3106 } | |
3107 | |
3108 void CMTask::recalculate_limits() { | |
3109 _real_words_scanned_limit = _words_scanned + words_scanned_period; | |
3110 _words_scanned_limit = _real_words_scanned_limit; | |
3111 | |
3112 _real_refs_reached_limit = _refs_reached + refs_reached_period; | |
3113 _refs_reached_limit = _real_refs_reached_limit; | |
3114 } | |
3115 | |
3116 void CMTask::decrease_limits() { | |
3117 // This is called when we believe that we're going to do an infrequent | |
3118 // operation which will increase the per byte scanned cost (i.e. move | |
3119 // entries to/from the global stack). It basically tries to decrease the | |
3120 // scanning limit so that the clock is called earlier. | |
3121 | |
3122 if (_cm->verbose_medium()) | |
3123 gclog_or_tty->print_cr("[%d] decreasing limits", _task_id); | |
3124 | |
3125 _words_scanned_limit = _real_words_scanned_limit - | |
3126 3 * words_scanned_period / 4; | |
3127 _refs_reached_limit = _real_refs_reached_limit - | |
3128 3 * refs_reached_period / 4; | |
3129 } | |
3130 | |
3131 void CMTask::move_entries_to_global_stack() { | |
3132 // local array where we'll store the entries that will be popped | |
3133 // from the local queue | |
3134 oop buffer[global_stack_transfer_size]; | |
3135 | |
3136 int n = 0; | |
3137 oop obj; | |
3138 while (n < global_stack_transfer_size && _task_queue->pop_local(obj)) { | |
3139 buffer[n] = obj; | |
3140 ++n; | |
3141 } | |
3142 | |
3143 if (n > 0) { | |
3144 // we popped at least one entry from the local queue | |
3145 | |
3146 statsOnly( ++_global_transfers_to; _local_pops += n ); | |
3147 | |
3148 if (!_cm->mark_stack_push(buffer, n)) { | |
3149 if (_cm->verbose_low()) | |
3150 gclog_or_tty->print_cr("[%d] aborting due to global stack overflow", _task_id); | |
3151 set_has_aborted(); | |
3152 } else { | |
3153 // the transfer was successful | |
3154 | |
3155 if (_cm->verbose_medium()) | |
3156 gclog_or_tty->print_cr("[%d] pushed %d entries to the global stack", | |
3157 _task_id, n); | |
3158 statsOnly( int tmp_size = _cm->mark_stack_size(); | |
3159 if (tmp_size > _global_max_size) | |
3160 _global_max_size = tmp_size; | |
3161 _global_pushes += n ); | |
3162 } | |
3163 } | |
3164 | |
3165 // this operation was quite expensive, so decrease the limits | |
3166 decrease_limits(); | |
3167 } | |
3168 | |
3169 void CMTask::get_entries_from_global_stack() { | |
3170 // local array where we'll store the entries that will be popped | |
3171 // from the global stack. | |
3172 oop buffer[global_stack_transfer_size]; | |
3173 int n; | |
3174 _cm->mark_stack_pop(buffer, global_stack_transfer_size, &n); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3175 assert(n <= global_stack_transfer_size, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3176 "we should not pop more than the given limit"); |
342 | 3177 if (n > 0) { |
3178 // yes, we did actually pop at least one entry | |
3179 | |
3180 statsOnly( ++_global_transfers_from; _global_pops += n ); | |
3181 if (_cm->verbose_medium()) | |
3182 gclog_or_tty->print_cr("[%d] popped %d entries from the global stack", | |
3183 _task_id, n); | |
3184 for (int i = 0; i < n; ++i) { | |
3185 bool success = _task_queue->push(buffer[i]); | |
3186 // We only call this when the local queue is empty or under a | |
3187 // given target limit. So, we do not expect this push to fail. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3188 assert(success, "invariant"); |
342 | 3189 } |
3190 | |
3191 statsOnly( int tmp_size = _task_queue->size(); | |
3192 if (tmp_size > _local_max_size) | |
3193 _local_max_size = tmp_size; | |
3194 _local_pushes += n ); | |
3195 } | |
3196 | |
3197 // this operation was quite expensive, so decrease the limits | |
3198 decrease_limits(); | |
3199 } | |
3200 | |
3201 void CMTask::drain_local_queue(bool partially) { | |
3202 if (has_aborted()) | |
3203 return; | |
3204 | |
3205 // Decide what the target size is, depending whether we're going to | |
3206 // drain it partially (so that other tasks can steal if they run out | |
3207 // of things to do) or totally (at the very end). | |
3208 size_t target_size; | |
3209 if (partially) | |
3210 target_size = MIN2((size_t)_task_queue->max_elems()/3, GCDrainStackTargetSize); | |
3211 else | |
3212 target_size = 0; | |
3213 | |
3214 if (_task_queue->size() > target_size) { | |
3215 if (_cm->verbose_high()) | |
3216 gclog_or_tty->print_cr("[%d] draining local queue, target size = %d", | |
3217 _task_id, target_size); | |
3218 | |
3219 oop obj; | |
3220 bool ret = _task_queue->pop_local(obj); | |
3221 while (ret) { | |
3222 statsOnly( ++_local_pops ); | |
3223 | |
3224 if (_cm->verbose_high()) | |
3225 gclog_or_tty->print_cr("[%d] popped "PTR_FORMAT, _task_id, | |
3226 (void*) obj); | |
3227 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3228 assert(_g1h->is_in_g1_reserved((HeapWord*) obj), "invariant" ); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3229 assert(!_g1h->heap_region_containing(obj)->is_on_free_list(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3230 "invariant"); |
342 | 3231 |
3232 scan_object(obj); | |
3233 | |
3234 if (_task_queue->size() <= target_size || has_aborted()) | |
3235 ret = false; | |
3236 else | |
3237 ret = _task_queue->pop_local(obj); | |
3238 } | |
3239 | |
3240 if (_cm->verbose_high()) | |
3241 gclog_or_tty->print_cr("[%d] drained local queue, size = %d", | |
3242 _task_id, _task_queue->size()); | |
3243 } | |
3244 } | |
3245 | |
3246 void CMTask::drain_global_stack(bool partially) { | |
3247 if (has_aborted()) | |
3248 return; | |
3249 | |
3250 // We have a policy to drain the local queue before we attempt to | |
3251 // drain the global stack. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3252 assert(partially || _task_queue->size() == 0, "invariant"); |
342 | 3253 |
3254 // Decide what the target size is, depending whether we're going to | |
3255 // drain it partially (so that other tasks can steal if they run out | |
3256 // of things to do) or totally (at the very end). Notice that, | |
3257 // because we move entries from the global stack in chunks or | |
3258 // because another task might be doing the same, we might in fact | |
3259 // drop below the target. But, this is not a problem. | |
3260 size_t target_size; | |
3261 if (partially) | |
3262 target_size = _cm->partial_mark_stack_size_target(); | |
3263 else | |
3264 target_size = 0; | |
3265 | |
3266 if (_cm->mark_stack_size() > target_size) { | |
3267 if (_cm->verbose_low()) | |
3268 gclog_or_tty->print_cr("[%d] draining global_stack, target size %d", | |
3269 _task_id, target_size); | |
3270 | |
3271 while (!has_aborted() && _cm->mark_stack_size() > target_size) { | |
3272 get_entries_from_global_stack(); | |
3273 drain_local_queue(partially); | |
3274 } | |
3275 | |
3276 if (_cm->verbose_low()) | |
3277 gclog_or_tty->print_cr("[%d] drained global stack, size = %d", | |
3278 _task_id, _cm->mark_stack_size()); | |
3279 } | |
3280 } | |
3281 | |
3282 // SATB Queue has several assumptions on whether to call the par or | |
3283 // non-par versions of the methods. this is why some of the code is | |
3284 // replicated. We should really get rid of the single-threaded version | |
3285 // of the code to simplify things. | |
3286 void CMTask::drain_satb_buffers() { | |
3287 if (has_aborted()) | |
3288 return; | |
3289 | |
3290 // We set this so that the regular clock knows that we're in the | |
3291 // middle of draining buffers and doesn't set the abort flag when it | |
3292 // notices that SATB buffers are available for draining. It'd be | |
3293 // very counter productive if it did that. :-) | |
3294 _draining_satb_buffers = true; | |
3295 | |
3296 CMObjectClosure oc(this); | |
3297 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
3298 if (ParallelGCThreads > 0) | |
3299 satb_mq_set.set_par_closure(_task_id, &oc); | |
3300 else | |
3301 satb_mq_set.set_closure(&oc); | |
3302 | |
3303 // This keeps claiming and applying the closure to completed buffers | |
3304 // until we run out of buffers or we need to abort. | |
3305 if (ParallelGCThreads > 0) { | |
3306 while (!has_aborted() && | |
3307 satb_mq_set.par_apply_closure_to_completed_buffer(_task_id)) { | |
3308 if (_cm->verbose_medium()) | |
3309 gclog_or_tty->print_cr("[%d] processed an SATB buffer", _task_id); | |
3310 statsOnly( ++_satb_buffers_processed ); | |
3311 regular_clock_call(); | |
3312 } | |
3313 } else { | |
3314 while (!has_aborted() && | |
3315 satb_mq_set.apply_closure_to_completed_buffer()) { | |
3316 if (_cm->verbose_medium()) | |
3317 gclog_or_tty->print_cr("[%d] processed an SATB buffer", _task_id); | |
3318 statsOnly( ++_satb_buffers_processed ); | |
3319 regular_clock_call(); | |
3320 } | |
3321 } | |
3322 | |
3323 if (!concurrent() && !has_aborted()) { | |
3324 // We should only do this during remark. | |
3325 if (ParallelGCThreads > 0) | |
3326 satb_mq_set.par_iterate_closure_all_threads(_task_id); | |
3327 else | |
3328 satb_mq_set.iterate_closure_all_threads(); | |
3329 } | |
3330 | |
3331 _draining_satb_buffers = false; | |
3332 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3333 assert(has_aborted() || |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3334 concurrent() || |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3335 satb_mq_set.completed_buffers_num() == 0, "invariant"); |
342 | 3336 |
3337 if (ParallelGCThreads > 0) | |
3338 satb_mq_set.set_par_closure(_task_id, NULL); | |
3339 else | |
3340 satb_mq_set.set_closure(NULL); | |
3341 | |
3342 // again, this was a potentially expensive operation, decrease the | |
3343 // limits to get the regular clock call early | |
3344 decrease_limits(); | |
3345 } | |
3346 | |
3347 void CMTask::drain_region_stack(BitMapClosure* bc) { | |
3348 if (has_aborted()) | |
3349 return; | |
3350 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3351 assert(_region_finger == NULL, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3352 "it should be NULL when we're not scanning a region"); |
342 | 3353 |
3354 if (!_cm->region_stack_empty()) { | |
3355 if (_cm->verbose_low()) | |
3356 gclog_or_tty->print_cr("[%d] draining region stack, size = %d", | |
3357 _task_id, _cm->region_stack_size()); | |
3358 | |
3359 MemRegion mr = _cm->region_stack_pop(); | |
3360 // it returns MemRegion() if the pop fails | |
3361 statsOnly(if (mr.start() != NULL) ++_region_stack_pops ); | |
3362 | |
3363 while (mr.start() != NULL) { | |
3364 if (_cm->verbose_medium()) | |
3365 gclog_or_tty->print_cr("[%d] we are scanning region " | |
3366 "["PTR_FORMAT", "PTR_FORMAT")", | |
3367 _task_id, mr.start(), mr.end()); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3368 assert(mr.end() <= _cm->finger(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3369 "otherwise the region shouldn't be on the stack"); |
342 | 3370 assert(!mr.is_empty(), "Only non-empty regions live on the region stack"); |
3371 if (_nextMarkBitMap->iterate(bc, mr)) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3372 assert(!has_aborted(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3373 "cannot abort the task without aborting the bitmap iteration"); |
342 | 3374 |
3375 // We finished iterating over the region without aborting. | |
3376 regular_clock_call(); | |
3377 if (has_aborted()) | |
3378 mr = MemRegion(); | |
3379 else { | |
3380 mr = _cm->region_stack_pop(); | |
3381 // it returns MemRegion() if the pop fails | |
3382 statsOnly(if (mr.start() != NULL) ++_region_stack_pops ); | |
3383 } | |
3384 } else { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3385 assert(has_aborted(), "currently the only way to do so"); |
342 | 3386 |
3387 // The only way to abort the bitmap iteration is to return | |
3388 // false from the do_bit() method. However, inside the | |
3389 // do_bit() method we move the _region_finger to point to the | |
3390 // object currently being looked at. So, if we bail out, we | |
3391 // have definitely set _region_finger to something non-null. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3392 assert(_region_finger != NULL, "invariant"); |
342 | 3393 |
3394 // The iteration was actually aborted. So now _region_finger | |
3395 // points to the address of the object we last scanned. If we | |
3396 // leave it there, when we restart this task, we will rescan | |
3397 // the object. It is easy to avoid this. We move the finger by | |
3398 // enough to point to the next possible object header (the | |
3399 // bitmap knows by how much we need to move it as it knows its | |
3400 // granularity). | |
3401 MemRegion newRegion = | |
3402 MemRegion(_nextMarkBitMap->nextWord(_region_finger), mr.end()); | |
3403 | |
3404 if (!newRegion.is_empty()) { | |
3405 if (_cm->verbose_low()) { | |
3406 gclog_or_tty->print_cr("[%d] pushing unscanned region" | |
3407 "[" PTR_FORMAT "," PTR_FORMAT ") on region stack", | |
3408 _task_id, | |
3409 newRegion.start(), newRegion.end()); | |
3410 } | |
3411 // Now push the part of the region we didn't scan on the | |
3412 // region stack to make sure a task scans it later. | |
3413 _cm->region_stack_push(newRegion); | |
3414 } | |
3415 // break from while | |
3416 mr = MemRegion(); | |
3417 } | |
3418 _region_finger = NULL; | |
3419 } | |
3420 | |
3421 if (_cm->verbose_low()) | |
3422 gclog_or_tty->print_cr("[%d] drained region stack, size = %d", | |
3423 _task_id, _cm->region_stack_size()); | |
3424 } | |
3425 } | |
3426 | |
3427 void CMTask::print_stats() { | |
3428 gclog_or_tty->print_cr("Marking Stats, task = %d, calls = %d", | |
3429 _task_id, _calls); | |
3430 gclog_or_tty->print_cr(" Elapsed time = %1.2lfms, Termination time = %1.2lfms", | |
3431 _elapsed_time_ms, _termination_time_ms); | |
3432 gclog_or_tty->print_cr(" Step Times (cum): num = %d, avg = %1.2lfms, sd = %1.2lfms", | |
3433 _step_times_ms.num(), _step_times_ms.avg(), | |
3434 _step_times_ms.sd()); | |
3435 gclog_or_tty->print_cr(" max = %1.2lfms, total = %1.2lfms", | |
3436 _step_times_ms.maximum(), _step_times_ms.sum()); | |
3437 | |
3438 #if _MARKING_STATS_ | |
3439 gclog_or_tty->print_cr(" Clock Intervals (cum): num = %d, avg = %1.2lfms, sd = %1.2lfms", | |
3440 _all_clock_intervals_ms.num(), _all_clock_intervals_ms.avg(), | |
3441 _all_clock_intervals_ms.sd()); | |
3442 gclog_or_tty->print_cr(" max = %1.2lfms, total = %1.2lfms", | |
3443 _all_clock_intervals_ms.maximum(), | |
3444 _all_clock_intervals_ms.sum()); | |
3445 gclog_or_tty->print_cr(" Clock Causes (cum): scanning = %d, marking = %d", | |
3446 _clock_due_to_scanning, _clock_due_to_marking); | |
3447 gclog_or_tty->print_cr(" Objects: scanned = %d, found on the bitmap = %d", | |
3448 _objs_scanned, _objs_found_on_bitmap); | |
3449 gclog_or_tty->print_cr(" Local Queue: pushes = %d, pops = %d, max size = %d", | |
3450 _local_pushes, _local_pops, _local_max_size); | |
3451 gclog_or_tty->print_cr(" Global Stack: pushes = %d, pops = %d, max size = %d", | |
3452 _global_pushes, _global_pops, _global_max_size); | |
3453 gclog_or_tty->print_cr(" transfers to = %d, transfers from = %d", | |
3454 _global_transfers_to,_global_transfers_from); | |
3455 gclog_or_tty->print_cr(" Regions: claimed = %d, Region Stack: pops = %d", | |
3456 _regions_claimed, _region_stack_pops); | |
3457 gclog_or_tty->print_cr(" SATB buffers: processed = %d", _satb_buffers_processed); | |
3458 gclog_or_tty->print_cr(" Steals: attempts = %d, successes = %d", | |
3459 _steal_attempts, _steals); | |
3460 gclog_or_tty->print_cr(" Aborted: %d, due to", _aborted); | |
3461 gclog_or_tty->print_cr(" overflow: %d, global abort: %d, yield: %d", | |
3462 _aborted_overflow, _aborted_cm_aborted, _aborted_yield); | |
3463 gclog_or_tty->print_cr(" time out: %d, SATB: %d, termination: %d", | |
3464 _aborted_timed_out, _aborted_satb, _aborted_termination); | |
3465 #endif // _MARKING_STATS_ | |
3466 } | |
3467 | |
3468 /***************************************************************************** | |
3469 | |
3470 The do_marking_step(time_target_ms) method is the building block | |
3471 of the parallel marking framework. It can be called in parallel | |
3472 with other invocations of do_marking_step() on different tasks | |
3473 (but only one per task, obviously) and concurrently with the | |
3474 mutator threads, or during remark, hence it eliminates the need | |
3475 for two versions of the code. When called during remark, it will | |
3476 pick up from where the task left off during the concurrent marking | |
3477 phase. Interestingly, tasks are also claimable during evacuation | |
3478 pauses too, since do_marking_step() ensures that it aborts before | |
3479 it needs to yield. | |
3480 | |
3481 The data structures that is uses to do marking work are the | |
3482 following: | |
3483 | |
3484 (1) Marking Bitmap. If there are gray objects that appear only | |
3485 on the bitmap (this happens either when dealing with an overflow | |
3486 or when the initial marking phase has simply marked the roots | |
3487 and didn't push them on the stack), then tasks claim heap | |
3488 regions whose bitmap they then scan to find gray objects. A | |
3489 global finger indicates where the end of the last claimed region | |
3490 is. A local finger indicates how far into the region a task has | |
3491 scanned. The two fingers are used to determine how to gray an | |
3492 object (i.e. whether simply marking it is OK, as it will be | |
3493 visited by a task in the future, or whether it needs to be also | |
3494 pushed on a stack). | |
3495 | |
3496 (2) Local Queue. The local queue of the task which is accessed | |
3497 reasonably efficiently by the task. Other tasks can steal from | |
3498 it when they run out of work. Throughout the marking phase, a | |
3499 task attempts to keep its local queue short but not totally | |
3500 empty, so that entries are available for stealing by other | |
3501 tasks. Only when there is no more work, a task will totally | |
3502 drain its local queue. | |
3503 | |
3504 (3) Global Mark Stack. This handles local queue overflow. During | |
3505 marking only sets of entries are moved between it and the local | |
3506 queues, as access to it requires a mutex and more fine-grain | |
3507 interaction with it which might cause contention. If it | |
3508 overflows, then the marking phase should restart and iterate | |
3509 over the bitmap to identify gray objects. Throughout the marking | |
3510 phase, tasks attempt to keep the global mark stack at a small | |
3511 length but not totally empty, so that entries are available for | |
3512 popping by other tasks. Only when there is no more work, tasks | |
3513 will totally drain the global mark stack. | |
3514 | |
3515 (4) Global Region Stack. Entries on it correspond to areas of | |
3516 the bitmap that need to be scanned since they contain gray | |
3517 objects. Pushes on the region stack only happen during | |
3518 evacuation pauses and typically correspond to areas covered by | |
3519 GC LABS. If it overflows, then the marking phase should restart | |
3520 and iterate over the bitmap to identify gray objects. Tasks will | |
3521 try to totally drain the region stack as soon as possible. | |
3522 | |
3523 (5) SATB Buffer Queue. This is where completed SATB buffers are | |
3524 made available. Buffers are regularly removed from this queue | |
3525 and scanned for roots, so that the queue doesn't get too | |
3526 long. During remark, all completed buffers are processed, as | |
3527 well as the filled in parts of any uncompleted buffers. | |
3528 | |
3529 The do_marking_step() method tries to abort when the time target | |
3530 has been reached. There are a few other cases when the | |
3531 do_marking_step() method also aborts: | |
3532 | |
3533 (1) When the marking phase has been aborted (after a Full GC). | |
3534 | |
3535 (2) When a global overflow (either on the global stack or the | |
3536 region stack) has been triggered. Before the task aborts, it | |
3537 will actually sync up with the other tasks to ensure that all | |
3538 the marking data structures (local queues, stacks, fingers etc.) | |
3539 are re-initialised so that when do_marking_step() completes, | |
3540 the marking phase can immediately restart. | |
3541 | |
3542 (3) When enough completed SATB buffers are available. The | |
3543 do_marking_step() method only tries to drain SATB buffers right | |
3544 at the beginning. So, if enough buffers are available, the | |
3545 marking step aborts and the SATB buffers are processed at | |
3546 the beginning of the next invocation. | |
3547 | |
3548 (4) To yield. when we have to yield then we abort and yield | |
3549 right at the end of do_marking_step(). This saves us from a lot | |
3550 of hassle as, by yielding we might allow a Full GC. If this | |
3551 happens then objects will be compacted underneath our feet, the | |
3552 heap might shrink, etc. We save checking for this by just | |
3553 aborting and doing the yield right at the end. | |
3554 | |
3555 From the above it follows that the do_marking_step() method should | |
3556 be called in a loop (or, otherwise, regularly) until it completes. | |
3557 | |
3558 If a marking step completes without its has_aborted() flag being | |
3559 true, it means it has completed the current marking phase (and | |
3560 also all other marking tasks have done so and have all synced up). | |
3561 | |
3562 A method called regular_clock_call() is invoked "regularly" (in | |
3563 sub ms intervals) throughout marking. It is this clock method that | |
3564 checks all the abort conditions which were mentioned above and | |
3565 decides when the task should abort. A work-based scheme is used to | |
3566 trigger this clock method: when the number of object words the | |
3567 marking phase has scanned or the number of references the marking | |
3568 phase has visited reach a given limit. Additional invocations to | |
3569 the method clock have been planted in a few other strategic places | |
3570 too. The initial reason for the clock method was to avoid calling | |
3571 vtime too regularly, as it is quite expensive. So, once it was in | |
3572 place, it was natural to piggy-back all the other conditions on it | |
3573 too and not constantly check them throughout the code. | |
3574 | |
3575 *****************************************************************************/ | |
3576 | |
3577 void CMTask::do_marking_step(double time_target_ms) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3578 assert(time_target_ms >= 1.0, "minimum granularity is 1ms"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3579 assert(concurrent() == _cm->concurrent(), "they should be the same"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3580 |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3581 assert(concurrent() || _cm->region_stack_empty(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3582 "the region stack should have been cleared before remark"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3583 assert(_region_finger == NULL, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3584 "this should be non-null only when a region is being scanned"); |
342 | 3585 |
3586 G1CollectorPolicy* g1_policy = _g1h->g1_policy(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3587 assert(_task_queues != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3588 assert(_task_queue != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3589 assert(_task_queues->queue(_task_id) == _task_queue, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3590 |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3591 assert(!_claimed, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3592 "only one thread should claim this task at any one time"); |
342 | 3593 |
3594 // OK, this doesn't safeguard again all possible scenarios, as it is | |
3595 // possible for two threads to set the _claimed flag at the same | |
3596 // time. But it is only for debugging purposes anyway and it will | |
3597 // catch most problems. | |
3598 _claimed = true; | |
3599 | |
3600 _start_time_ms = os::elapsedVTime() * 1000.0; | |
3601 statsOnly( _interval_start_time_ms = _start_time_ms ); | |
3602 | |
3603 double diff_prediction_ms = | |
3604 g1_policy->get_new_prediction(&_marking_step_diffs_ms); | |
3605 _time_target_ms = time_target_ms - diff_prediction_ms; | |
3606 | |
3607 // set up the variables that are used in the work-based scheme to | |
3608 // call the regular clock method | |
3609 _words_scanned = 0; | |
3610 _refs_reached = 0; | |
3611 recalculate_limits(); | |
3612 | |
3613 // clear all flags | |
3614 clear_has_aborted(); | |
3615 _has_aborted_timed_out = false; | |
3616 _draining_satb_buffers = false; | |
3617 | |
3618 ++_calls; | |
3619 | |
3620 if (_cm->verbose_low()) | |
3621 gclog_or_tty->print_cr("[%d] >>>>>>>>>> START, call = %d, " | |
3622 "target = %1.2lfms >>>>>>>>>>", | |
3623 _task_id, _calls, _time_target_ms); | |
3624 | |
3625 // Set up the bitmap and oop closures. Anything that uses them is | |
3626 // eventually called from this method, so it is OK to allocate these | |
3627 // statically. | |
3628 CMBitMapClosure bitmap_closure(this, _cm, _nextMarkBitMap); | |
3629 CMOopClosure oop_closure(_g1h, _cm, this); | |
3630 set_oop_closure(&oop_closure); | |
3631 | |
3632 if (_cm->has_overflown()) { | |
3633 // This can happen if the region stack or the mark stack overflows | |
3634 // during a GC pause and this task, after a yield point, | |
3635 // restarts. We have to abort as we need to get into the overflow | |
3636 // protocol which happens right at the end of this task. | |
3637 set_has_aborted(); | |
3638 } | |
3639 | |
3640 // First drain any available SATB buffers. After this, we will not | |
3641 // look at SATB buffers before the next invocation of this method. | |
3642 // If enough completed SATB buffers are queued up, the regular clock | |
3643 // will abort this task so that it restarts. | |
3644 drain_satb_buffers(); | |
3645 // ...then partially drain the local queue and the global stack | |
3646 drain_local_queue(true); | |
3647 drain_global_stack(true); | |
3648 | |
3649 // Then totally drain the region stack. We will not look at | |
3650 // it again before the next invocation of this method. Entries on | |
3651 // the region stack are only added during evacuation pauses, for | |
3652 // which we have to yield. When we do, we abort the task anyway so | |
3653 // it will look at the region stack again when it restarts. | |
3654 bitmap_closure.set_scanning_heap_region(false); | |
3655 drain_region_stack(&bitmap_closure); | |
3656 // ...then partially drain the local queue and the global stack | |
3657 drain_local_queue(true); | |
3658 drain_global_stack(true); | |
3659 | |
3660 do { | |
3661 if (!has_aborted() && _curr_region != NULL) { | |
3662 // This means that we're already holding on to a region. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3663 assert(_finger != NULL, "if region is not NULL, then the finger " |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3664 "should not be NULL either"); |
342 | 3665 |
3666 // We might have restarted this task after an evacuation pause | |
3667 // which might have evacuated the region we're holding on to | |
3668 // underneath our feet. Let's read its limit again to make sure | |
3669 // that we do not iterate over a region of the heap that | |
3670 // contains garbage (update_region_limit() will also move | |
3671 // _finger to the start of the region if it is found empty). | |
3672 update_region_limit(); | |
3673 // We will start from _finger not from the start of the region, | |
3674 // as we might be restarting this task after aborting half-way | |
3675 // through scanning this region. In this case, _finger points to | |
3676 // the address where we last found a marked object. If this is a | |
3677 // fresh region, _finger points to start(). | |
3678 MemRegion mr = MemRegion(_finger, _region_limit); | |
3679 | |
3680 if (_cm->verbose_low()) | |
3681 gclog_or_tty->print_cr("[%d] we're scanning part " | |
3682 "["PTR_FORMAT", "PTR_FORMAT") " | |
3683 "of region "PTR_FORMAT, | |
3684 _task_id, _finger, _region_limit, _curr_region); | |
3685 | |
3686 // Let's iterate over the bitmap of the part of the | |
3687 // region that is left. | |
3688 bitmap_closure.set_scanning_heap_region(true); | |
3689 if (mr.is_empty() || | |
3690 _nextMarkBitMap->iterate(&bitmap_closure, mr)) { | |
3691 // We successfully completed iterating over the region. Now, | |
3692 // let's give up the region. | |
3693 giveup_current_region(); | |
3694 regular_clock_call(); | |
3695 } else { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3696 assert(has_aborted(), "currently the only way to do so"); |
342 | 3697 // The only way to abort the bitmap iteration is to return |
3698 // false from the do_bit() method. However, inside the | |
3699 // do_bit() method we move the _finger to point to the | |
3700 // object currently being looked at. So, if we bail out, we | |
3701 // have definitely set _finger to something non-null. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3702 assert(_finger != NULL, "invariant"); |
342 | 3703 |
3704 // Region iteration was actually aborted. So now _finger | |
3705 // points to the address of the object we last scanned. If we | |
3706 // leave it there, when we restart this task, we will rescan | |
3707 // the object. It is easy to avoid this. We move the finger by | |
3708 // enough to point to the next possible object header (the | |
3709 // bitmap knows by how much we need to move it as it knows its | |
3710 // granularity). | |
3711 move_finger_to(_nextMarkBitMap->nextWord(_finger)); | |
3712 } | |
3713 } | |
3714 // At this point we have either completed iterating over the | |
3715 // region we were holding on to, or we have aborted. | |
3716 | |
3717 // We then partially drain the local queue and the global stack. | |
3718 // (Do we really need this?) | |
3719 drain_local_queue(true); | |
3720 drain_global_stack(true); | |
3721 | |
3722 // Read the note on the claim_region() method on why it might | |
3723 // return NULL with potentially more regions available for | |
3724 // claiming and why we have to check out_of_regions() to determine | |
3725 // whether we're done or not. | |
3726 while (!has_aborted() && _curr_region == NULL && !_cm->out_of_regions()) { | |
3727 // We are going to try to claim a new region. We should have | |
3728 // given up on the previous one. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3729 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3730 assert(_curr_region == NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3731 assert(_finger == NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3732 assert(_region_limit == NULL, "invariant"); |
342 | 3733 if (_cm->verbose_low()) |
3734 gclog_or_tty->print_cr("[%d] trying to claim a new region", _task_id); | |
3735 HeapRegion* claimed_region = _cm->claim_region(_task_id); | |
3736 if (claimed_region != NULL) { | |
3737 // Yes, we managed to claim one | |
3738 statsOnly( ++_regions_claimed ); | |
3739 | |
3740 if (_cm->verbose_low()) | |
3741 gclog_or_tty->print_cr("[%d] we successfully claimed " | |
3742 "region "PTR_FORMAT, | |
3743 _task_id, claimed_region); | |
3744 | |
3745 setup_for_region(claimed_region); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3746 assert(_curr_region == claimed_region, "invariant"); |
342 | 3747 } |
3748 // It is important to call the regular clock here. It might take | |
3749 // a while to claim a region if, for example, we hit a large | |
3750 // block of empty regions. So we need to call the regular clock | |
3751 // method once round the loop to make sure it's called | |
3752 // frequently enough. | |
3753 regular_clock_call(); | |
3754 } | |
3755 | |
3756 if (!has_aborted() && _curr_region == NULL) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3757 assert(_cm->out_of_regions(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3758 "at this point we should be out of regions"); |
342 | 3759 } |
3760 } while ( _curr_region != NULL && !has_aborted()); | |
3761 | |
3762 if (!has_aborted()) { | |
3763 // We cannot check whether the global stack is empty, since other | |
343
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3764 // tasks might be pushing objects to it concurrently. We also cannot |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3765 // check if the region stack is empty because if a thread is aborting |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3766 // it can push a partially done region back. |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3767 assert(_cm->out_of_regions(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3768 "at this point we should be out of regions"); |
342 | 3769 |
3770 if (_cm->verbose_low()) | |
3771 gclog_or_tty->print_cr("[%d] all regions claimed", _task_id); | |
3772 | |
3773 // Try to reduce the number of available SATB buffers so that | |
3774 // remark has less work to do. | |
3775 drain_satb_buffers(); | |
3776 } | |
3777 | |
3778 // Since we've done everything else, we can now totally drain the | |
3779 // local queue and global stack. | |
3780 drain_local_queue(false); | |
3781 drain_global_stack(false); | |
3782 | |
3783 // Attempt at work stealing from other task's queues. | |
3784 if (!has_aborted()) { | |
3785 // We have not aborted. This means that we have finished all that | |
3786 // we could. Let's try to do some stealing... | |
3787 | |
3788 // We cannot check whether the global stack is empty, since other | |
343
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3789 // tasks might be pushing objects to it concurrently. We also cannot |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3790 // check if the region stack is empty because if a thread is aborting |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3791 // it can push a partially done region back. |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3792 assert(_cm->out_of_regions() && _task_queue->size() == 0, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3793 "only way to reach here"); |
342 | 3794 |
3795 if (_cm->verbose_low()) | |
3796 gclog_or_tty->print_cr("[%d] starting to steal", _task_id); | |
3797 | |
3798 while (!has_aborted()) { | |
3799 oop obj; | |
3800 statsOnly( ++_steal_attempts ); | |
3801 | |
3802 if (_cm->try_stealing(_task_id, &_hash_seed, obj)) { | |
3803 if (_cm->verbose_medium()) | |
3804 gclog_or_tty->print_cr("[%d] stolen "PTR_FORMAT" successfully", | |
3805 _task_id, (void*) obj); | |
3806 | |
3807 statsOnly( ++_steals ); | |
3808 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3809 assert(_nextMarkBitMap->isMarked((HeapWord*) obj), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3810 "any stolen object should be marked"); |
342 | 3811 scan_object(obj); |
3812 | |
3813 // And since we're towards the end, let's totally drain the | |
3814 // local queue and global stack. | |
3815 drain_local_queue(false); | |
3816 drain_global_stack(false); | |
3817 } else { | |
3818 break; | |
3819 } | |
3820 } | |
3821 } | |
3822 | |
3823 // We still haven't aborted. Now, let's try to get into the | |
3824 // termination protocol. | |
3825 if (!has_aborted()) { | |
3826 // We cannot check whether the global stack is empty, since other | |
343
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3827 // tasks might be concurrently pushing objects on it. We also cannot |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3828 // check if the region stack is empty because if a thread is aborting |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3829 // it can push a partially done region back. |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3830 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3831 assert(_cm->out_of_regions(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3832 assert(_task_queue->size() == 0, "only way to reach here"); |
342 | 3833 |
3834 if (_cm->verbose_low()) | |
3835 gclog_or_tty->print_cr("[%d] starting termination protocol", _task_id); | |
3836 | |
3837 _termination_start_time_ms = os::elapsedVTime() * 1000.0; | |
3838 // The CMTask class also extends the TerminatorTerminator class, | |
3839 // hence its should_exit_termination() method will also decide | |
3840 // whether to exit the termination protocol or not. | |
3841 bool finished = _cm->terminator()->offer_termination(this); | |
3842 double termination_end_time_ms = os::elapsedVTime() * 1000.0; | |
3843 _termination_time_ms += | |
3844 termination_end_time_ms - _termination_start_time_ms; | |
3845 | |
3846 if (finished) { | |
3847 // We're all done. | |
3848 | |
3849 if (_task_id == 0) { | |
3850 // let's allow task 0 to do this | |
3851 if (concurrent()) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3852 assert(_cm->concurrent_marking_in_progress(), "invariant"); |
342 | 3853 // we need to set this to false before the next |
3854 // safepoint. This way we ensure that the marking phase | |
3855 // doesn't observe any more heap expansions. | |
3856 _cm->clear_concurrent_marking_in_progress(); | |
3857 } | |
3858 } | |
3859 | |
3860 // We can now guarantee that the global stack is empty, since | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3861 // all other tasks have finished. We separated the guarantees so |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3862 // that, if a condition is false, we can immediately find out |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3863 // which one. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3864 guarantee(_cm->out_of_regions(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3865 guarantee(_cm->region_stack_empty(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3866 guarantee(_cm->mark_stack_empty(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3867 guarantee(_task_queue->size() == 0, "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3868 guarantee(!_cm->has_overflown(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3869 guarantee(!_cm->mark_stack_overflow(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3870 guarantee(!_cm->region_stack_overflow(), "only way to reach here"); |
342 | 3871 |
3872 if (_cm->verbose_low()) | |
3873 gclog_or_tty->print_cr("[%d] all tasks terminated", _task_id); | |
3874 } else { | |
3875 // Apparently there's more work to do. Let's abort this task. It | |
3876 // will restart it and we can hopefully find more things to do. | |
3877 | |
3878 if (_cm->verbose_low()) | |
3879 gclog_or_tty->print_cr("[%d] apparently there is more work to do", _task_id); | |
3880 | |
3881 set_has_aborted(); | |
3882 statsOnly( ++_aborted_termination ); | |
3883 } | |
3884 } | |
3885 | |
3886 // Mainly for debugging purposes to make sure that a pointer to the | |
3887 // closure which was statically allocated in this frame doesn't | |
3888 // escape it by accident. | |
3889 set_oop_closure(NULL); | |
3890 double end_time_ms = os::elapsedVTime() * 1000.0; | |
3891 double elapsed_time_ms = end_time_ms - _start_time_ms; | |
3892 // Update the step history. | |
3893 _step_times_ms.add(elapsed_time_ms); | |
3894 | |
3895 if (has_aborted()) { | |
3896 // The task was aborted for some reason. | |
3897 | |
3898 statsOnly( ++_aborted ); | |
3899 | |
3900 if (_has_aborted_timed_out) { | |
3901 double diff_ms = elapsed_time_ms - _time_target_ms; | |
3902 // Keep statistics of how well we did with respect to hitting | |
3903 // our target only if we actually timed out (if we aborted for | |
3904 // other reasons, then the results might get skewed). | |
3905 _marking_step_diffs_ms.add(diff_ms); | |
3906 } | |
3907 | |
3908 if (_cm->has_overflown()) { | |
3909 // This is the interesting one. We aborted because a global | |
3910 // overflow was raised. This means we have to restart the | |
3911 // marking phase and start iterating over regions. However, in | |
3912 // order to do this we have to make sure that all tasks stop | |
3913 // what they are doing and re-initialise in a safe manner. We | |
3914 // will achieve this with the use of two barrier sync points. | |
3915 | |
3916 if (_cm->verbose_low()) | |
3917 gclog_or_tty->print_cr("[%d] detected overflow", _task_id); | |
3918 | |
3919 _cm->enter_first_sync_barrier(_task_id); | |
3920 // When we exit this sync barrier we know that all tasks have | |
3921 // stopped doing marking work. So, it's now safe to | |
3922 // re-initialise our data structures. At the end of this method, | |
3923 // task 0 will clear the global data structures. | |
3924 | |
3925 statsOnly( ++_aborted_overflow ); | |
3926 | |
3927 // We clear the local state of this task... | |
3928 clear_region_fields(); | |
3929 | |
3930 // ...and enter the second barrier. | |
3931 _cm->enter_second_sync_barrier(_task_id); | |
3932 // At this point everything has bee re-initialised and we're | |
3933 // ready to restart. | |
3934 } | |
3935 | |
3936 if (_cm->verbose_low()) { | |
3937 gclog_or_tty->print_cr("[%d] <<<<<<<<<< ABORTING, target = %1.2lfms, " | |
3938 "elapsed = %1.2lfms <<<<<<<<<<", | |
3939 _task_id, _time_target_ms, elapsed_time_ms); | |
3940 if (_cm->has_aborted()) | |
3941 gclog_or_tty->print_cr("[%d] ========== MARKING ABORTED ==========", | |
3942 _task_id); | |
3943 } | |
3944 } else { | |
3945 if (_cm->verbose_low()) | |
3946 gclog_or_tty->print_cr("[%d] <<<<<<<<<< FINISHED, target = %1.2lfms, " | |
3947 "elapsed = %1.2lfms <<<<<<<<<<", | |
3948 _task_id, _time_target_ms, elapsed_time_ms); | |
3949 } | |
3950 | |
3951 _claimed = false; | |
3952 } | |
3953 | |
3954 CMTask::CMTask(int task_id, | |
3955 ConcurrentMark* cm, | |
3956 CMTaskQueue* task_queue, | |
3957 CMTaskQueueSet* task_queues) | |
3958 : _g1h(G1CollectedHeap::heap()), | |
3959 _task_id(task_id), _cm(cm), | |
3960 _claimed(false), | |
3961 _nextMarkBitMap(NULL), _hash_seed(17), | |
3962 _task_queue(task_queue), | |
3963 _task_queues(task_queues), | |
3964 _oop_closure(NULL) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3965 guarantee(task_queue != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3966 guarantee(task_queues != NULL, "invariant"); |
342 | 3967 |
3968 statsOnly( _clock_due_to_scanning = 0; | |
3969 _clock_due_to_marking = 0 ); | |
3970 | |
3971 _marking_step_diffs_ms.add(0.5); | |
3972 } |