Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp @ 17758:ae7336d6337e
8034868: Extract G1 From Card Cache into separate class
Summary: Refactor the From Card Cache into a separate class.
Reviewed-by: jmasa
author | tschatzl |
---|---|
date | Mon, 24 Mar 2014 15:30:50 +0100 |
parents | 96b1c2e06e25 |
children | 8847586c9037 |
comparison
equal
deleted
inserted
replaced
17757:eff02b5bd56c | 17758:ae7336d6337e |
---|---|
356 "just checking"); | 356 "just checking"); |
357 assert(_first_all_fine_prts == NULL || _first_all_fine_prts->prev() == NULL, | 357 assert(_first_all_fine_prts == NULL || _first_all_fine_prts->prev() == NULL, |
358 "just checking"); | 358 "just checking"); |
359 } | 359 } |
360 | 360 |
361 int** OtherRegionsTable::_from_card_cache = NULL; | 361 int** FromCardCache::_cache = NULL; |
362 uint OtherRegionsTable::_from_card_cache_max_regions = 0; | 362 uint FromCardCache::_max_regions = 0; |
363 size_t OtherRegionsTable::_from_card_cache_mem_size = 0; | 363 size_t FromCardCache::_static_mem_size = 0; |
364 | |
365 void FromCardCache::initialize(uint n_par_rs, uint max_num_regions) { | |
366 guarantee(_cache == NULL, "Should not call this multiple times"); | |
367 | |
368 _max_regions = max_num_regions; | |
369 _cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs, | |
370 _max_regions, | |
371 &_static_mem_size); | |
372 | |
373 for (uint i = 0; i < n_par_rs; i++) { | |
374 for (uint j = 0; j < _max_regions; j++) { | |
375 set(i, j, InvalidCard); | |
376 } | |
377 } | |
378 } | |
379 | |
380 void FromCardCache::shrink(uint new_num_regions) { | |
381 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { | |
382 assert(new_num_regions <= _max_regions, "Must be within max."); | |
383 for (uint j = new_num_regions; j < _max_regions; j++) { | |
384 set(i, j, InvalidCard); | |
385 } | |
386 } | |
387 } | |
388 | |
389 #ifndef PRODUCT | |
390 void FromCardCache::print(outputStream* out) { | |
391 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { | |
392 for (uint j = 0; j < _max_regions; j++) { | |
393 out->print_cr("_from_card_cache["UINT32_FORMAT"]["UINT32_FORMAT"] = "INT32_FORMAT".", | |
394 i, j, at(i, j)); | |
395 } | |
396 } | |
397 } | |
398 #endif | |
399 | |
400 void FromCardCache::clear(uint region_idx) { | |
401 uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets(); | |
402 for (uint i = 0; i < num_par_remsets; i++) { | |
403 set(i, region_idx, InvalidCard); | |
404 } | |
405 } | |
364 | 406 |
365 void OtherRegionsTable::init_from_card_cache(uint max_regions) { | 407 void OtherRegionsTable::init_from_card_cache(uint max_regions) { |
366 guarantee(_from_card_cache == NULL, "Should not call this multiple times"); | 408 FromCardCache::initialize(HeapRegionRemSet::num_par_rem_sets(), max_regions); |
367 uint n_par_rs = HeapRegionRemSet::num_par_rem_sets(); | 409 } |
368 | 410 |
369 _from_card_cache_max_regions = max_regions; | 411 void OtherRegionsTable::shrink_from_card_cache(uint new_num_regions) { |
370 _from_card_cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs, | 412 FromCardCache::shrink(new_num_regions); |
371 _from_card_cache_max_regions, | 413 } |
372 &_from_card_cache_mem_size); | 414 |
373 | |
374 for (uint i = 0; i < n_par_rs; i++) { | |
375 for (uint j = 0; j < _from_card_cache_max_regions; j++) { | |
376 _from_card_cache[i][j] = -1; // An invalid value. | |
377 } | |
378 } | |
379 } | |
380 | |
381 void OtherRegionsTable::shrink_from_card_cache(uint new_n_regs) { | |
382 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { | |
383 assert(new_n_regs <= _from_card_cache_max_regions, "Must be within max."); | |
384 for (uint j = new_n_regs; j < _from_card_cache_max_regions; j++) { | |
385 _from_card_cache[i][j] = -1; // An invalid value. | |
386 } | |
387 } | |
388 } | |
389 | |
390 #ifndef PRODUCT | |
391 void OtherRegionsTable::print_from_card_cache() { | 415 void OtherRegionsTable::print_from_card_cache() { |
392 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { | 416 FromCardCache::print(); |
393 for (uint j = 0; j < _from_card_cache_max_regions; j++) { | 417 } |
394 gclog_or_tty->print_cr("_from_card_cache[%d][%d] = %d.", | |
395 i, j, _from_card_cache[i][j]); | |
396 } | |
397 } | |
398 } | |
399 #endif | |
400 | 418 |
401 void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, int tid) { | 419 void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, int tid) { |
402 size_t cur_hrs_ind = (size_t) hr()->hrs_index(); | 420 uint cur_hrs_ind = hr()->hrs_index(); |
403 | 421 |
404 if (G1TraceHeapRegionRememberedSet) { | 422 if (G1TraceHeapRegionRememberedSet) { |
405 gclog_or_tty->print_cr("ORT::add_reference_work(" PTR_FORMAT "->" PTR_FORMAT ").", | 423 gclog_or_tty->print_cr("ORT::add_reference_work(" PTR_FORMAT "->" PTR_FORMAT ").", |
406 from, | 424 from, |
407 UseCompressedOops | 425 UseCompressedOops |
410 } | 428 } |
411 | 429 |
412 int from_card = (int)(uintptr_t(from) >> CardTableModRefBS::card_shift); | 430 int from_card = (int)(uintptr_t(from) >> CardTableModRefBS::card_shift); |
413 | 431 |
414 if (G1TraceHeapRegionRememberedSet) { | 432 if (G1TraceHeapRegionRememberedSet) { |
415 gclog_or_tty->print_cr("Table for [" PTR_FORMAT "...): card %d (cache = %d)", | 433 gclog_or_tty->print_cr("Table for [" PTR_FORMAT "...): card %d (cache = "INT32_FORMAT")", |
416 hr()->bottom(), from_card, | 434 hr()->bottom(), from_card, |
417 _from_card_cache[tid][cur_hrs_ind]); | 435 FromCardCache::at((uint)tid, cur_hrs_ind)); |
418 } | 436 } |
419 | 437 |
420 if (from_card == _from_card_cache[tid][cur_hrs_ind]) { | 438 if (FromCardCache::contains_or_replace((uint)tid, cur_hrs_ind, from_card)) { |
421 if (G1TraceHeapRegionRememberedSet) { | 439 if (G1TraceHeapRegionRememberedSet) { |
422 gclog_or_tty->print_cr(" from-card cache hit."); | 440 gclog_or_tty->print_cr(" from-card cache hit."); |
423 } | 441 } |
424 assert(contains_reference(from), "We just added it!"); | 442 assert(contains_reference(from), "We just added it!"); |
425 return; | 443 return; |
426 } else { | |
427 _from_card_cache[tid][cur_hrs_ind] = from_card; | |
428 } | 444 } |
429 | 445 |
430 // Note that this may be a continued H region. | 446 // Note that this may be a continued H region. |
431 HeapRegion* from_hr = _g1h->heap_region_containing_raw(from); | 447 HeapRegion* from_hr = _g1h->heap_region_containing_raw(from); |
432 RegionIdx_t from_hrs_ind = (RegionIdx_t) from_hr->hrs_index(); | 448 RegionIdx_t from_hrs_ind = (RegionIdx_t) from_hr->hrs_index(); |
720 sum += sizeof(*this) - sizeof(_sparse_table); // Avoid double counting above. | 736 sum += sizeof(*this) - sizeof(_sparse_table); // Avoid double counting above. |
721 return sum; | 737 return sum; |
722 } | 738 } |
723 | 739 |
724 size_t OtherRegionsTable::static_mem_size() { | 740 size_t OtherRegionsTable::static_mem_size() { |
725 return _from_card_cache_mem_size; | 741 return FromCardCache::static_mem_size(); |
726 } | 742 } |
727 | 743 |
728 size_t OtherRegionsTable::fl_mem_size() { | 744 size_t OtherRegionsTable::fl_mem_size() { |
729 return PerRegionTable::fl_mem_size(); | 745 return PerRegionTable::fl_mem_size(); |
730 } | 746 } |
731 | 747 |
732 void OtherRegionsTable::clear_fcc() { | 748 void OtherRegionsTable::clear_fcc() { |
733 uint hrs_idx = hr()->hrs_index(); | 749 FromCardCache::clear(hr()->hrs_index()); |
734 uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets(); | |
735 for (uint i = 0; i < num_par_remsets; i++) { | |
736 _from_card_cache[i][hrs_idx] = -1; | |
737 } | |
738 } | 750 } |
739 | 751 |
740 void OtherRegionsTable::clear() { | 752 void OtherRegionsTable::clear() { |
741 // if there are no entries, skip this step | 753 // if there are no entries, skip this step |
742 if (_first_all_fine_prts != NULL) { | 754 if (_first_all_fine_prts != NULL) { |
766 _coarse_map.par_at_put(hrs_ind, 0); | 778 _coarse_map.par_at_put(hrs_ind, 0); |
767 } | 779 } |
768 // Check to see if any of the fcc entries come from here. | 780 // Check to see if any of the fcc entries come from here. |
769 uint hr_ind = hr()->hrs_index(); | 781 uint hr_ind = hr()->hrs_index(); |
770 for (uint tid = 0; tid < HeapRegionRemSet::num_par_rem_sets(); tid++) { | 782 for (uint tid = 0; tid < HeapRegionRemSet::num_par_rem_sets(); tid++) { |
771 int fcc_ent = _from_card_cache[tid][hr_ind]; | 783 int fcc_ent = FromCardCache::at(tid, hr_ind); |
772 if (fcc_ent != -1) { | 784 if (fcc_ent != FromCardCache::InvalidCard) { |
773 HeapWord* card_addr = (HeapWord*) | 785 HeapWord* card_addr = (HeapWord*) |
774 (uintptr_t(fcc_ent) << CardTableModRefBS::card_shift); | 786 (uintptr_t(fcc_ent) << CardTableModRefBS::card_shift); |
775 if (hr()->is_in_reserved(card_addr)) { | 787 if (hr()->is_in_reserved(card_addr)) { |
776 // Clear the from card cache. | 788 // Clear the from card cache. |
777 _from_card_cache[tid][hr_ind] = -1; | 789 FromCardCache::set(tid, hr_ind, FromCardCache::InvalidCard); |
778 } | 790 } |
779 } | 791 } |
780 } | 792 } |
781 } | 793 } |
782 | 794 |
828 CardIdx_t card_index = from_card - hr_bot_card_index; | 840 CardIdx_t card_index = from_card - hr_bot_card_index; |
829 assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion, | 841 assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion, |
830 "Must be in range."); | 842 "Must be in range."); |
831 return _sparse_table.contains_card(hr_ind, card_index); | 843 return _sparse_table.contains_card(hr_ind, card_index); |
832 } | 844 } |
833 | |
834 | |
835 } | 845 } |
836 | 846 |
837 void | 847 void |
838 OtherRegionsTable::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) { | 848 OtherRegionsTable::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) { |
839 _sparse_table.do_cleanup_work(hrrs_cleanup_task); | 849 _sparse_table.do_cleanup_work(hrrs_cleanup_task); |
929 | 939 |
930 void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs, | 940 void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs, |
931 BitMap* region_bm, BitMap* card_bm) { | 941 BitMap* region_bm, BitMap* card_bm) { |
932 _other_regions.scrub(ctbs, region_bm, card_bm); | 942 _other_regions.scrub(ctbs, region_bm, card_bm); |
933 } | 943 } |
934 | |
935 | 944 |
936 // Code roots support | 945 // Code roots support |
937 | 946 |
938 void HeapRegionRemSet::add_strong_code_root(nmethod* nm) { | 947 void HeapRegionRemSet::add_strong_code_root(nmethod* nm) { |
939 assert(nm != NULL, "sanity"); | 948 assert(nm != NULL, "sanity"); |