446 _conc_workers(NULL), // may be set later |
446 _conc_workers(NULL), // may be set later |
447 _abort_preclean(false), |
447 _abort_preclean(false), |
448 _start_sampling(false), |
448 _start_sampling(false), |
449 _between_prologue_and_epilogue(false), |
449 _between_prologue_and_epilogue(false), |
450 _markBitMap(0, Mutex::leaf + 1, "CMS_markBitMap_lock"), |
450 _markBitMap(0, Mutex::leaf + 1, "CMS_markBitMap_lock"), |
451 _modUnionTable((CardTableModRefBS::card_shift - LogHeapWordSize), |
451 _modUnionTable((CardTable::card_shift - LogHeapWordSize), |
452 -1 /* lock-free */, "No_lock" /* dummy */), |
452 -1 /* lock-free */, "No_lock" /* dummy */), |
453 _modUnionClosurePar(&_modUnionTable), |
453 _modUnionClosurePar(&_modUnionTable), |
454 // Adjust my span to cover old (cms) gen |
454 // Adjust my span to cover old (cms) gen |
455 _span(cmsGen->reserved()), |
455 _span(cmsGen->reserved()), |
456 // Construct the is_alive_closure with _span & markBitMap |
456 // Construct the is_alive_closure with _span & markBitMap |
898 // be aligned to the granularity of a bit's representation |
898 // be aligned to the granularity of a bit's representation |
899 // in the heap. In the case of the MUT below, that's a |
899 // in the heap. In the case of the MUT below, that's a |
900 // card size. |
900 // card size. |
901 MemRegion mr(start, |
901 MemRegion mr(start, |
902 align_up(start + obj_size, |
902 align_up(start + obj_size, |
903 CardTableModRefBS::card_size /* bytes */)); |
903 CardTable::card_size /* bytes */)); |
904 if (par) { |
904 if (par) { |
905 _modUnionTable.par_mark_range(mr); |
905 _modUnionTable.par_mark_range(mr); |
906 } else { |
906 } else { |
907 _modUnionTable.mark_range(mr); |
907 _modUnionTable.mark_range(mr); |
908 } |
908 } |
3221 |
3221 |
3222 HeapWord* aligned_start = sp->bottom(); |
3222 HeapWord* aligned_start = sp->bottom(); |
3223 if (sp->used_region().contains(_restart_addr)) { |
3223 if (sp->used_region().contains(_restart_addr)) { |
3224 // Align down to a card boundary for the start of 0th task |
3224 // Align down to a card boundary for the start of 0th task |
3225 // for this space. |
3225 // for this space. |
3226 aligned_start = align_down(_restart_addr, CardTableModRefBS::card_size); |
3226 aligned_start = align_down(_restart_addr, CardTable::card_size); |
3227 } |
3227 } |
3228 |
3228 |
3229 size_t chunk_size = sp->marking_task_size(); |
3229 size_t chunk_size = sp->marking_task_size(); |
3230 while (!pst->is_task_claimed(/* reference */ nth_task)) { |
3230 while (!pst->is_task_claimed(/* reference */ nth_task)) { |
3231 // Having claimed the nth task in this space, |
3231 // Having claimed the nth task in this space, |
4024 stopTimer(); |
4024 stopTimer(); |
4025 CMSTokenSync x(true); // is cms thread |
4025 CMSTokenSync x(true); // is cms thread |
4026 startTimer(); |
4026 startTimer(); |
4027 sample_eden(); |
4027 sample_eden(); |
4028 // Get and clear dirty region from card table |
4028 // Get and clear dirty region from card table |
4029 dirtyRegion = _ct->ct_bs()->dirty_card_range_after_reset( |
4029 dirtyRegion = _ct->dirty_card_range_after_reset(MemRegion(nextAddr, endAddr), |
4030 MemRegion(nextAddr, endAddr), |
4030 true, |
4031 true, |
4031 CardTable::precleaned_card_val()); |
4032 CardTableModRefBS::precleaned_card_val()); |
|
4033 |
4032 |
4034 assert(dirtyRegion.start() >= nextAddr, |
4033 assert(dirtyRegion.start() >= nextAddr, |
4035 "returned region inconsistent?"); |
4034 "returned region inconsistent?"); |
4036 } |
4035 } |
4037 lastAddr = dirtyRegion.end(); |
4036 lastAddr = dirtyRegion.end(); |
4038 numDirtyCards = |
4037 numDirtyCards = |
4039 dirtyRegion.word_size()/CardTableModRefBS::card_size_in_words; |
4038 dirtyRegion.word_size()/CardTable::card_size_in_words; |
4040 |
4039 |
4041 if (!dirtyRegion.is_empty()) { |
4040 if (!dirtyRegion.is_empty()) { |
4042 stopTimer(); |
4041 stopTimer(); |
4043 CMSTokenSyncWithLocks ts(true, old_gen->freelistLock(), bitMapLock()); |
4042 CMSTokenSyncWithLocks ts(true, old_gen->freelistLock(), bitMapLock()); |
4044 startTimer(); |
4043 startTimer(); |
4048 HeapWord* stop_point = |
4047 HeapWord* stop_point = |
4049 old_gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); |
4048 old_gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); |
4050 if (stop_point != NULL) { |
4049 if (stop_point != NULL) { |
4051 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
4050 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
4052 "Should only be AbortablePreclean."); |
4051 "Should only be AbortablePreclean."); |
4053 _ct->ct_bs()->invalidate(MemRegion(stop_point, dirtyRegion.end())); |
4052 _ct->invalidate(MemRegion(stop_point, dirtyRegion.end())); |
4054 if (should_abort_preclean()) { |
4053 if (should_abort_preclean()) { |
4055 break; // out of preclean loop |
4054 break; // out of preclean loop |
4056 } else { |
4055 } else { |
4057 // Compute the next address at which preclean should pick up. |
4056 // Compute the next address at which preclean should pick up. |
4058 lastAddr = next_card_start_after_block(stop_point); |
4057 lastAddr = next_card_start_after_block(stop_point); |
4575 sp, bm, work_q, cl); |
4574 sp, bm, work_q, cl); |
4576 |
4575 |
4577 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); |
4576 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); |
4578 assert(pst->valid(), "Uninitialized use?"); |
4577 assert(pst->valid(), "Uninitialized use?"); |
4579 uint nth_task = 0; |
4578 uint nth_task = 0; |
4580 const int alignment = CardTableModRefBS::card_size * BitsPerWord; |
4579 const int alignment = CardTable::card_size * BitsPerWord; |
4581 MemRegion span = sp->used_region(); |
4580 MemRegion span = sp->used_region(); |
4582 HeapWord* start_addr = span.start(); |
4581 HeapWord* start_addr = span.start(); |
4583 HeapWord* end_addr = align_up(span.end(), alignment); |
4582 HeapWord* end_addr = align_up(span.end(), alignment); |
4584 const size_t chunk_size = sp->rescan_task_size(); // in HeapWord units |
4583 const size_t chunk_size = sp->rescan_task_size(); // in HeapWord units |
4585 assert(is_aligned(start_addr, alignment), "Check alignment"); |
4584 assert(is_aligned(start_addr, alignment), "Check alignment"); |
4601 } |
4600 } |
4602 // Iterate over the dirty cards covering this chunk, marking them |
4601 // Iterate over the dirty cards covering this chunk, marking them |
4603 // precleaned, and setting the corresponding bits in the mod union |
4602 // precleaned, and setting the corresponding bits in the mod union |
4604 // table. Since we have been careful to partition at Card and MUT-word |
4603 // table. Since we have been careful to partition at Card and MUT-word |
4605 // boundaries no synchronization is needed between parallel threads. |
4604 // boundaries no synchronization is needed between parallel threads. |
4606 _collector->_ct->ct_bs()->dirty_card_iterate(this_span, |
4605 _collector->_ct->dirty_card_iterate(this_span, |
4607 &modUnionClosure); |
4606 &modUnionClosure); |
4608 |
4607 |
4609 // Having transferred these marks into the modUnionTable, |
4608 // Having transferred these marks into the modUnionTable, |
4610 // rescan the marked objects on the dirty cards in the modUnionTable. |
4609 // rescan the marked objects on the dirty cards in the modUnionTable. |
4611 // Even if this is at a synchronous collection, the initial marking |
4610 // Even if this is at a synchronous collection, the initial marking |
4912 GCTraceTime(Trace, gc, phases) t("Grey Object Rescan", _gc_timer_cm); |
4911 GCTraceTime(Trace, gc, phases) t("Grey Object Rescan", _gc_timer_cm); |
4913 // Iterate over the dirty cards, setting the corresponding bits in the |
4912 // Iterate over the dirty cards, setting the corresponding bits in the |
4914 // mod union table. |
4913 // mod union table. |
4915 { |
4914 { |
4916 ModUnionClosure modUnionClosure(&_modUnionTable); |
4915 ModUnionClosure modUnionClosure(&_modUnionTable); |
4917 _ct->ct_bs()->dirty_card_iterate( |
4916 _ct->dirty_card_iterate(_cmsGen->used_region(), |
4918 _cmsGen->used_region(), |
4917 &modUnionClosure); |
4919 &modUnionClosure); |
|
4920 } |
4918 } |
4921 // Having transferred these marks into the modUnionTable, we just need |
4919 // Having transferred these marks into the modUnionTable, we just need |
4922 // to rescan the marked objects on the dirty cards in the modUnionTable. |
4920 // to rescan the marked objects on the dirty cards in the modUnionTable. |
4923 // The initial marking may have been done during an asynchronous |
4921 // The initial marking may have been done during an asynchronous |
4924 // collection so there may be dirty bits in the mod-union table. |
4922 // collection so there may be dirty bits in the mod-union table. |
4925 const int alignment = |
4923 const int alignment = CardTable::card_size * BitsPerWord; |
4926 CardTableModRefBS::card_size * BitsPerWord; |
|
4927 { |
4924 { |
4928 // ... First handle dirty cards in CMS gen |
4925 // ... First handle dirty cards in CMS gen |
4929 markFromDirtyCardsClosure.set_space(_cmsGen->cmsSpace()); |
4926 markFromDirtyCardsClosure.set_space(_cmsGen->cmsSpace()); |
4930 MemRegion ur = _cmsGen->used_region(); |
4927 MemRegion ur = _cmsGen->used_region(); |
4931 HeapWord* lb = ur.start(); |
4928 HeapWord* lb = ur.start(); |
5631 } else { |
5628 } else { |
5632 sz = block_size_using_printezis_bits(addr); |
5629 sz = block_size_using_printezis_bits(addr); |
5633 } |
5630 } |
5634 assert(sz > 0, "size must be nonzero"); |
5631 assert(sz > 0, "size must be nonzero"); |
5635 HeapWord* next_block = addr + sz; |
5632 HeapWord* next_block = addr + sz; |
5636 HeapWord* next_card = align_up(next_block, CardTableModRefBS::card_size); |
5633 HeapWord* next_card = align_up(next_block, CardTable::card_size); |
5637 assert(align_down((uintptr_t)addr, CardTableModRefBS::card_size) < |
5634 assert(align_down((uintptr_t)addr, CardTable::card_size) < |
5638 align_down((uintptr_t)next_card, CardTableModRefBS::card_size), |
5635 align_down((uintptr_t)next_card, CardTable::card_size), |
5639 "must be different cards"); |
5636 "must be different cards"); |
5640 return next_card; |
5637 return next_card; |
5641 } |
5638 } |
5642 |
5639 |
5643 |
5640 |
6292 |
6289 |
6293 void MarkFromRootsClosure::reset(HeapWord* addr) { |
6290 void MarkFromRootsClosure::reset(HeapWord* addr) { |
6294 assert(_markStack->isEmpty(), "would cause duplicates on stack"); |
6291 assert(_markStack->isEmpty(), "would cause duplicates on stack"); |
6295 assert(_span.contains(addr), "Out of bounds _finger?"); |
6292 assert(_span.contains(addr), "Out of bounds _finger?"); |
6296 _finger = addr; |
6293 _finger = addr; |
6297 _threshold = align_up(_finger, CardTableModRefBS::card_size); |
6294 _threshold = align_up(_finger, CardTable::card_size); |
6298 } |
6295 } |
6299 |
6296 |
6300 // Should revisit to see if this should be restructured for |
6297 // Should revisit to see if this should be restructured for |
6301 // greater efficiency. |
6298 // greater efficiency. |
6302 bool MarkFromRootsClosure::do_bit(size_t offset) { |
6299 bool MarkFromRootsClosure::do_bit(size_t offset) { |
6319 // We re-dirty the cards on which this object lies and increase |
6316 // We re-dirty the cards on which this object lies and increase |
6320 // the _threshold so that we'll come back to scan this object |
6317 // the _threshold so that we'll come back to scan this object |
6321 // during the preclean or remark phase. (CMSCleanOnEnter) |
6318 // during the preclean or remark phase. (CMSCleanOnEnter) |
6322 if (CMSCleanOnEnter) { |
6319 if (CMSCleanOnEnter) { |
6323 size_t sz = _collector->block_size_using_printezis_bits(addr); |
6320 size_t sz = _collector->block_size_using_printezis_bits(addr); |
6324 HeapWord* end_card_addr = align_up(addr + sz, CardTableModRefBS::card_size); |
6321 HeapWord* end_card_addr = align_up(addr + sz, CardTable::card_size); |
6325 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
6322 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
6326 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
6323 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
6327 // Bump _threshold to end_card_addr; note that |
6324 // Bump _threshold to end_card_addr; note that |
6328 // _threshold cannot possibly exceed end_card_addr, anyhow. |
6325 // _threshold cannot possibly exceed end_card_addr, anyhow. |
6329 // This prevents future clearing of the card as the scan proceeds |
6326 // This prevents future clearing of the card as the scan proceeds |
6406 // The set of cards to be cleared is all those that overlap |
6403 // The set of cards to be cleared is all those that overlap |
6407 // with the interval [_threshold, _finger); note that |
6404 // with the interval [_threshold, _finger); note that |
6408 // _threshold is always kept card-aligned but _finger isn't |
6405 // _threshold is always kept card-aligned but _finger isn't |
6409 // always card-aligned. |
6406 // always card-aligned. |
6410 HeapWord* old_threshold = _threshold; |
6407 HeapWord* old_threshold = _threshold; |
6411 assert(is_aligned(old_threshold, CardTableModRefBS::card_size), |
6408 assert(is_aligned(old_threshold, CardTable::card_size), |
6412 "_threshold should always be card-aligned"); |
6409 "_threshold should always be card-aligned"); |
6413 _threshold = align_up(_finger, CardTableModRefBS::card_size); |
6410 _threshold = align_up(_finger, CardTable::card_size); |
6414 MemRegion mr(old_threshold, _threshold); |
6411 MemRegion mr(old_threshold, _threshold); |
6415 assert(!mr.is_empty(), "Control point invariant"); |
6412 assert(!mr.is_empty(), "Control point invariant"); |
6416 assert(_span.contains(mr), "Should clear within span"); |
6413 assert(_span.contains(mr), "Should clear within span"); |
6417 _mut->clear_range(mr); |
6414 _mut->clear_range(mr); |
6418 } |
6415 } |
6518 // The set of cards to be cleared is all those that overlap |
6515 // The set of cards to be cleared is all those that overlap |
6519 // with the interval [_threshold, _finger); note that |
6516 // with the interval [_threshold, _finger); note that |
6520 // _threshold is always kept card-aligned but _finger isn't |
6517 // _threshold is always kept card-aligned but _finger isn't |
6521 // always card-aligned. |
6518 // always card-aligned. |
6522 HeapWord* old_threshold = _threshold; |
6519 HeapWord* old_threshold = _threshold; |
6523 assert(is_aligned(old_threshold, CardTableModRefBS::card_size), |
6520 assert(is_aligned(old_threshold, CardTable::card_size), |
6524 "_threshold should always be card-aligned"); |
6521 "_threshold should always be card-aligned"); |
6525 _threshold = align_up(_finger, CardTableModRefBS::card_size); |
6522 _threshold = align_up(_finger, CardTable::card_size); |
6526 MemRegion mr(old_threshold, _threshold); |
6523 MemRegion mr(old_threshold, _threshold); |
6527 assert(!mr.is_empty(), "Control point invariant"); |
6524 assert(!mr.is_empty(), "Control point invariant"); |
6528 assert(_span.contains(mr), "Should clear within span"); // _whole_span ?? |
6525 assert(_span.contains(mr), "Should clear within span"); // _whole_span ?? |
6529 _mut->clear_range(mr); |
6526 _mut->clear_range(mr); |
6530 } |
6527 } |
6888 // Note that no one can be interfering with us in this action |
6885 // Note that no one can be interfering with us in this action |
6889 // of dirtying the mod union table, so no locking or atomics |
6886 // of dirtying the mod union table, so no locking or atomics |
6890 // are required. |
6887 // are required. |
6891 if (obj->is_objArray()) { |
6888 if (obj->is_objArray()) { |
6892 size_t sz = obj->size(); |
6889 size_t sz = obj->size(); |
6893 HeapWord* end_card_addr = align_up(addr + sz, CardTableModRefBS::card_size); |
6890 HeapWord* end_card_addr = align_up(addr + sz, CardTable::card_size); |
6894 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
6891 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
6895 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
6892 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
6896 _mod_union_table->mark_range(redirty_range); |
6893 _mod_union_table->mark_range(redirty_range); |
6897 } else { |
6894 } else { |
6898 _mod_union_table->mark(addr); |
6895 _mod_union_table->mark(addr); |
7001 } |
6998 } |
7002 return _collector->foregroundGCIsActive(); |
6999 return _collector->foregroundGCIsActive(); |
7003 } |
7000 } |
7004 |
7001 |
7005 void MarkFromDirtyCardsClosure::do_MemRegion(MemRegion mr) { |
7002 void MarkFromDirtyCardsClosure::do_MemRegion(MemRegion mr) { |
7006 assert(((size_t)mr.start())%CardTableModRefBS::card_size_in_words == 0, |
7003 assert(((size_t)mr.start())%CardTable::card_size_in_words == 0, |
7007 "mr should be aligned to start at a card boundary"); |
7004 "mr should be aligned to start at a card boundary"); |
7008 // We'd like to assert: |
7005 // We'd like to assert: |
7009 // assert(mr.word_size()%CardTableModRefBS::card_size_in_words == 0, |
7006 // assert(mr.word_size()%CardTable::card_size_in_words == 0, |
7010 // "mr should be a range of cards"); |
7007 // "mr should be a range of cards"); |
7011 // However, that would be too strong in one case -- the last |
7008 // However, that would be too strong in one case -- the last |
7012 // partition ends at _unallocated_block which, in general, can be |
7009 // partition ends at _unallocated_block which, in general, can be |
7013 // an arbitrary boundary, not necessarily card aligned. |
7010 // an arbitrary boundary, not necessarily card aligned. |
7014 _num_dirty_cards += mr.word_size()/CardTableModRefBS::card_size_in_words; |
7011 _num_dirty_cards += mr.word_size()/CardTable::card_size_in_words; |
7015 _space->object_iterate_mem(mr, &_scan_cl); |
7012 _space->object_iterate_mem(mr, &_scan_cl); |
7016 } |
7013 } |
7017 |
7014 |
7018 SweepClosure::SweepClosure(CMSCollector* collector, |
7015 SweepClosure::SweepClosure(CMSCollector* collector, |
7019 ConcurrentMarkSweepGeneration* g, |
7016 ConcurrentMarkSweepGeneration* g, |
7618 // the cards that the object spans. No locking or atomics |
7615 // the cards that the object spans. No locking or atomics |
7619 // are needed since no one else can be mutating the mod union |
7616 // are needed since no one else can be mutating the mod union |
7620 // table. |
7617 // table. |
7621 if (obj->is_objArray()) { |
7618 if (obj->is_objArray()) { |
7622 size_t sz = obj->size(); |
7619 size_t sz = obj->size(); |
7623 HeapWord* end_card_addr = align_up(addr + sz, CardTableModRefBS::card_size); |
7620 HeapWord* end_card_addr = align_up(addr + sz, CardTable::card_size); |
7624 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
7621 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
7625 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
7622 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
7626 _collector->_modUnionTable.mark_range(redirty_range); |
7623 _collector->_modUnionTable.mark_range(redirty_range); |
7627 } else { |
7624 } else { |
7628 _collector->_modUnionTable.mark(addr); |
7625 _collector->_modUnionTable.mark(addr); |