1.1 --- a/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp Mon Mar 24 15:30:46 2014 +0100 1.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp Mon Mar 24 15:30:50 2014 +0100 1.3 @@ -358,48 +358,66 @@ 1.4 "just checking"); 1.5 } 1.6 1.7 -int** OtherRegionsTable::_from_card_cache = NULL; 1.8 -uint OtherRegionsTable::_from_card_cache_max_regions = 0; 1.9 -size_t OtherRegionsTable::_from_card_cache_mem_size = 0; 1.10 +int** FromCardCache::_cache = NULL; 1.11 +uint FromCardCache::_max_regions = 0; 1.12 +size_t FromCardCache::_static_mem_size = 0; 1.13 1.14 -void OtherRegionsTable::init_from_card_cache(uint max_regions) { 1.15 - guarantee(_from_card_cache == NULL, "Should not call this multiple times"); 1.16 - uint n_par_rs = HeapRegionRemSet::num_par_rem_sets(); 1.17 +void FromCardCache::initialize(uint n_par_rs, uint max_num_regions) { 1.18 + guarantee(_cache == NULL, "Should not call this multiple times"); 1.19 1.20 - _from_card_cache_max_regions = max_regions; 1.21 - _from_card_cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs, 1.22 - _from_card_cache_max_regions, 1.23 - &_from_card_cache_mem_size); 1.24 + _max_regions = max_num_regions; 1.25 + _cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs, 1.26 + _max_regions, 1.27 + &_static_mem_size); 1.28 1.29 for (uint i = 0; i < n_par_rs; i++) { 1.30 - for (uint j = 0; j < _from_card_cache_max_regions; j++) { 1.31 - _from_card_cache[i][j] = -1; // An invalid value. 1.32 + for (uint j = 0; j < _max_regions; j++) { 1.33 + set(i, j, InvalidCard); 1.34 } 1.35 } 1.36 } 1.37 1.38 -void OtherRegionsTable::shrink_from_card_cache(uint new_n_regs) { 1.39 +void FromCardCache::shrink(uint new_num_regions) { 1.40 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { 1.41 - assert(new_n_regs <= _from_card_cache_max_regions, "Must be within max."); 1.42 - for (uint j = new_n_regs; j < _from_card_cache_max_regions; j++) { 1.43 - _from_card_cache[i][j] = -1; // An invalid value. 1.44 + assert(new_num_regions <= _max_regions, "Must be within max."); 1.45 + for (uint j = new_num_regions; j < _max_regions; j++) { 1.46 + set(i, j, InvalidCard); 1.47 } 1.48 } 1.49 } 1.50 1.51 #ifndef PRODUCT 1.52 -void OtherRegionsTable::print_from_card_cache() { 1.53 +void FromCardCache::print(outputStream* out) { 1.54 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) { 1.55 - for (uint j = 0; j < _from_card_cache_max_regions; j++) { 1.56 - gclog_or_tty->print_cr("_from_card_cache[%d][%d] = %d.", 1.57 - i, j, _from_card_cache[i][j]); 1.58 + for (uint j = 0; j < _max_regions; j++) { 1.59 + out->print_cr("_from_card_cache["UINT32_FORMAT"]["UINT32_FORMAT"] = "INT32_FORMAT".", 1.60 + i, j, at(i, j)); 1.61 } 1.62 } 1.63 } 1.64 #endif 1.65 1.66 +void FromCardCache::clear(uint region_idx) { 1.67 + uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets(); 1.68 + for (uint i = 0; i < num_par_remsets; i++) { 1.69 + set(i, region_idx, InvalidCard); 1.70 + } 1.71 +} 1.72 + 1.73 +void OtherRegionsTable::init_from_card_cache(uint max_regions) { 1.74 + FromCardCache::initialize(HeapRegionRemSet::num_par_rem_sets(), max_regions); 1.75 +} 1.76 + 1.77 +void OtherRegionsTable::shrink_from_card_cache(uint new_num_regions) { 1.78 + FromCardCache::shrink(new_num_regions); 1.79 +} 1.80 + 1.81 +void OtherRegionsTable::print_from_card_cache() { 1.82 + FromCardCache::print(); 1.83 +} 1.84 + 1.85 void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, int tid) { 1.86 - size_t cur_hrs_ind = (size_t) hr()->hrs_index(); 1.87 + uint cur_hrs_ind = hr()->hrs_index(); 1.88 1.89 if (G1TraceHeapRegionRememberedSet) { 1.90 gclog_or_tty->print_cr("ORT::add_reference_work(" PTR_FORMAT "->" PTR_FORMAT ").", 1.91 @@ -412,19 +430,17 @@ 1.92 int from_card = (int)(uintptr_t(from) >> CardTableModRefBS::card_shift); 1.93 1.94 if (G1TraceHeapRegionRememberedSet) { 1.95 - gclog_or_tty->print_cr("Table for [" PTR_FORMAT "...): card %d (cache = %d)", 1.96 + gclog_or_tty->print_cr("Table for [" PTR_FORMAT "...): card %d (cache = "INT32_FORMAT")", 1.97 hr()->bottom(), from_card, 1.98 - _from_card_cache[tid][cur_hrs_ind]); 1.99 + FromCardCache::at((uint)tid, cur_hrs_ind)); 1.100 } 1.101 1.102 - if (from_card == _from_card_cache[tid][cur_hrs_ind]) { 1.103 + if (FromCardCache::contains_or_replace((uint)tid, cur_hrs_ind, from_card)) { 1.104 if (G1TraceHeapRegionRememberedSet) { 1.105 gclog_or_tty->print_cr(" from-card cache hit."); 1.106 } 1.107 assert(contains_reference(from), "We just added it!"); 1.108 return; 1.109 - } else { 1.110 - _from_card_cache[tid][cur_hrs_ind] = from_card; 1.111 } 1.112 1.113 // Note that this may be a continued H region. 1.114 @@ -722,7 +738,7 @@ 1.115 } 1.116 1.117 size_t OtherRegionsTable::static_mem_size() { 1.118 - return _from_card_cache_mem_size; 1.119 + return FromCardCache::static_mem_size(); 1.120 } 1.121 1.122 size_t OtherRegionsTable::fl_mem_size() { 1.123 @@ -730,11 +746,7 @@ 1.124 } 1.125 1.126 void OtherRegionsTable::clear_fcc() { 1.127 - uint hrs_idx = hr()->hrs_index(); 1.128 - uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets(); 1.129 - for (uint i = 0; i < num_par_remsets; i++) { 1.130 - _from_card_cache[i][hrs_idx] = -1; 1.131 - } 1.132 + FromCardCache::clear(hr()->hrs_index()); 1.133 } 1.134 1.135 void OtherRegionsTable::clear() { 1.136 @@ -768,13 +780,13 @@ 1.137 // Check to see if any of the fcc entries come from here. 1.138 uint hr_ind = hr()->hrs_index(); 1.139 for (uint tid = 0; tid < HeapRegionRemSet::num_par_rem_sets(); tid++) { 1.140 - int fcc_ent = _from_card_cache[tid][hr_ind]; 1.141 - if (fcc_ent != -1) { 1.142 + int fcc_ent = FromCardCache::at(tid, hr_ind); 1.143 + if (fcc_ent != FromCardCache::InvalidCard) { 1.144 HeapWord* card_addr = (HeapWord*) 1.145 (uintptr_t(fcc_ent) << CardTableModRefBS::card_shift); 1.146 if (hr()->is_in_reserved(card_addr)) { 1.147 // Clear the from card cache. 1.148 - _from_card_cache[tid][hr_ind] = -1; 1.149 + FromCardCache::set(tid, hr_ind, FromCardCache::InvalidCard); 1.150 } 1.151 } 1.152 } 1.153 @@ -830,8 +842,6 @@ 1.154 "Must be in range."); 1.155 return _sparse_table.contains_card(hr_ind, card_index); 1.156 } 1.157 - 1.158 - 1.159 } 1.160 1.161 void 1.162 @@ -932,7 +942,6 @@ 1.163 _other_regions.scrub(ctbs, region_bm, card_bm); 1.164 } 1.165 1.166 - 1.167 // Code roots support 1.168 1.169 void HeapRegionRemSet::add_strong_code_root(nmethod* nm) {