359 "just checking");
360 }
361
362 int** FromCardCache::_cache = NULL;
363 uint FromCardCache::_max_regions = 0;
364 size_t FromCardCache::_static_mem_size = 0;
365
366 void FromCardCache::initialize(uint n_par_rs, uint max_num_regions) {
367 guarantee(_cache == NULL, "Should not call this multiple times");
368
369 _max_regions = max_num_regions;
370 _cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs,
371 _max_regions,
372 &_static_mem_size);
373
374 invalidate(0, _max_regions);
375 }
376
377 void FromCardCache::invalidate(uint start_idx, size_t new_num_regions) {
378 guarantee((size_t)start_idx + new_num_regions <= max_uintx,
379 err_msg("Trying to invalidate beyond maximum region, from %u size " SIZE_FORMAT,
380 start_idx, new_num_regions));
381 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
382 uint end_idx = (start_idx + (uint)new_num_regions);
383 assert(end_idx <= _max_regions, "Must be within max.");
384 for (uint j = start_idx; j < end_idx; j++) {
385 set(i, j, InvalidCard);
386 }
387 }
388 }
389
390 #ifndef PRODUCT
391 void FromCardCache::print(outputStream* out) {
392 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
393 for (uint j = 0; j < _max_regions; j++) {
394 out->print_cr("_from_card_cache[%u][%u] = %d.",
395 i, j, at(i, j));
396 }
397 }
398 }
399 #endif
400
996 }
997
998 bool HeapRegionRemSetIterator::fine_has_next(size_t& card_index) {
999 if (fine_has_next()) {
1000 _cur_card_in_prt =
1001 _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
1002 }
1003 if (_cur_card_in_prt == HeapRegion::CardsPerRegion) {
1004 // _fine_cur_prt may still be NULL in case if there are not PRTs at all for
1005 // the remembered set.
1006 if (_fine_cur_prt == NULL || _fine_cur_prt->next() == NULL) {
1007 return false;
1008 }
1009 PerRegionTable* next_prt = _fine_cur_prt->next();
1010 switch_to_prt(next_prt);
1011 _cur_card_in_prt = _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
1012 }
1013
1014 card_index = _cur_region_card_offset + _cur_card_in_prt;
1015 guarantee(_cur_card_in_prt < HeapRegion::CardsPerRegion,
1016 err_msg("Card index " SIZE_FORMAT " must be within the region", _cur_card_in_prt));
1017 return true;
1018 }
1019
1020 bool HeapRegionRemSetIterator::fine_has_next() {
1021 return _cur_card_in_prt != HeapRegion::CardsPerRegion;
1022 }
1023
1024 void HeapRegionRemSetIterator::switch_to_prt(PerRegionTable* prt) {
1025 assert(prt != NULL, "Cannot switch to NULL prt");
1026 _fine_cur_prt = prt;
1027
1028 HeapWord* r_bot = _fine_cur_prt->hr()->bottom();
1029 _cur_region_card_offset = _bosa->index_for(r_bot);
1030
1031 // The bitmap scan for the PRT always scans from _cur_region_cur_card + 1.
1032 // To avoid special-casing this start case, and not miss the first bitmap
1033 // entry, initialize _cur_region_cur_card with -1 instead of 0.
1034 _cur_card_in_prt = (size_t)-1;
1035 }
1036
1165
1166 void HeapRegionRemSet::reset_for_cleanup_tasks() {
1167 SparsePRT::reset_for_cleanup_tasks();
1168 }
1169
1170 void HeapRegionRemSet::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
1171 _other_regions.do_cleanup_work(hrrs_cleanup_task);
1172 }
1173
1174 void
1175 HeapRegionRemSet::finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task) {
1176 SparsePRT::finish_cleanup_task(hrrs_cleanup_task);
1177 }
1178
1179 #ifndef PRODUCT
1180 void PerRegionTable::test_fl_mem_size() {
1181 PerRegionTable* dummy = alloc(NULL);
1182
1183 size_t min_prt_size = sizeof(void*) + dummy->bm()->size_in_words() * HeapWordSize;
1184 assert(dummy->mem_size() > min_prt_size,
1185 err_msg("PerRegionTable memory usage is suspiciously small, only has " SIZE_FORMAT " bytes. "
1186 "Should be at least " SIZE_FORMAT " bytes.", dummy->mem_size(), min_prt_size));
1187 free(dummy);
1188 guarantee(dummy->mem_size() == fl_mem_size(), "fl_mem_size() does not return the correct element size");
1189 // try to reset the state
1190 _free_list = NULL;
1191 delete dummy;
1192 }
1193
1194 void HeapRegionRemSet::test_prt() {
1195 PerRegionTable::test_fl_mem_size();
1196 }
1197
1198 void HeapRegionRemSet::test() {
1199 os::sleep(Thread::current(), (jlong)5000, false);
1200 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1201
1202 // Run with "-XX:G1LogRSetRegionEntries=2", so that 1 and 5 end up in same
1203 // hash bucket.
1204 HeapRegion* hr0 = g1h->region_at(0);
1205 HeapRegion* hr1 = g1h->region_at(1);
1206 HeapRegion* hr2 = g1h->region_at(5);
|
359 "just checking");
360 }
361
362 int** FromCardCache::_cache = NULL;
363 uint FromCardCache::_max_regions = 0;
364 size_t FromCardCache::_static_mem_size = 0;
365
366 void FromCardCache::initialize(uint n_par_rs, uint max_num_regions) {
367 guarantee(_cache == NULL, "Should not call this multiple times");
368
369 _max_regions = max_num_regions;
370 _cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs,
371 _max_regions,
372 &_static_mem_size);
373
374 invalidate(0, _max_regions);
375 }
376
377 void FromCardCache::invalidate(uint start_idx, size_t new_num_regions) {
378 guarantee((size_t)start_idx + new_num_regions <= max_uintx,
379 "Trying to invalidate beyond maximum region, from %u size " SIZE_FORMAT,
380 start_idx, new_num_regions);
381 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
382 uint end_idx = (start_idx + (uint)new_num_regions);
383 assert(end_idx <= _max_regions, "Must be within max.");
384 for (uint j = start_idx; j < end_idx; j++) {
385 set(i, j, InvalidCard);
386 }
387 }
388 }
389
390 #ifndef PRODUCT
391 void FromCardCache::print(outputStream* out) {
392 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
393 for (uint j = 0; j < _max_regions; j++) {
394 out->print_cr("_from_card_cache[%u][%u] = %d.",
395 i, j, at(i, j));
396 }
397 }
398 }
399 #endif
400
996 }
997
998 bool HeapRegionRemSetIterator::fine_has_next(size_t& card_index) {
999 if (fine_has_next()) {
1000 _cur_card_in_prt =
1001 _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
1002 }
1003 if (_cur_card_in_prt == HeapRegion::CardsPerRegion) {
1004 // _fine_cur_prt may still be NULL in case if there are not PRTs at all for
1005 // the remembered set.
1006 if (_fine_cur_prt == NULL || _fine_cur_prt->next() == NULL) {
1007 return false;
1008 }
1009 PerRegionTable* next_prt = _fine_cur_prt->next();
1010 switch_to_prt(next_prt);
1011 _cur_card_in_prt = _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
1012 }
1013
1014 card_index = _cur_region_card_offset + _cur_card_in_prt;
1015 guarantee(_cur_card_in_prt < HeapRegion::CardsPerRegion,
1016 "Card index " SIZE_FORMAT " must be within the region", _cur_card_in_prt);
1017 return true;
1018 }
1019
1020 bool HeapRegionRemSetIterator::fine_has_next() {
1021 return _cur_card_in_prt != HeapRegion::CardsPerRegion;
1022 }
1023
1024 void HeapRegionRemSetIterator::switch_to_prt(PerRegionTable* prt) {
1025 assert(prt != NULL, "Cannot switch to NULL prt");
1026 _fine_cur_prt = prt;
1027
1028 HeapWord* r_bot = _fine_cur_prt->hr()->bottom();
1029 _cur_region_card_offset = _bosa->index_for(r_bot);
1030
1031 // The bitmap scan for the PRT always scans from _cur_region_cur_card + 1.
1032 // To avoid special-casing this start case, and not miss the first bitmap
1033 // entry, initialize _cur_region_cur_card with -1 instead of 0.
1034 _cur_card_in_prt = (size_t)-1;
1035 }
1036
1165
1166 void HeapRegionRemSet::reset_for_cleanup_tasks() {
1167 SparsePRT::reset_for_cleanup_tasks();
1168 }
1169
1170 void HeapRegionRemSet::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
1171 _other_regions.do_cleanup_work(hrrs_cleanup_task);
1172 }
1173
1174 void
1175 HeapRegionRemSet::finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task) {
1176 SparsePRT::finish_cleanup_task(hrrs_cleanup_task);
1177 }
1178
1179 #ifndef PRODUCT
1180 void PerRegionTable::test_fl_mem_size() {
1181 PerRegionTable* dummy = alloc(NULL);
1182
1183 size_t min_prt_size = sizeof(void*) + dummy->bm()->size_in_words() * HeapWordSize;
1184 assert(dummy->mem_size() > min_prt_size,
1185 "PerRegionTable memory usage is suspiciously small, only has " SIZE_FORMAT " bytes. "
1186 "Should be at least " SIZE_FORMAT " bytes.", dummy->mem_size(), min_prt_size);
1187 free(dummy);
1188 guarantee(dummy->mem_size() == fl_mem_size(), "fl_mem_size() does not return the correct element size");
1189 // try to reset the state
1190 _free_list = NULL;
1191 delete dummy;
1192 }
1193
1194 void HeapRegionRemSet::test_prt() {
1195 PerRegionTable::test_fl_mem_size();
1196 }
1197
1198 void HeapRegionRemSet::test() {
1199 os::sleep(Thread::current(), (jlong)5000, false);
1200 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1201
1202 // Run with "-XX:G1LogRSetRegionEntries=2", so that 1 and 5 end up in same
1203 // hash bucket.
1204 HeapRegion* hr0 = g1h->region_at(0);
1205 HeapRegion* hr1 = g1h->region_at(1);
1206 HeapRegion* hr2 = g1h->region_at(5);
|