353 while ((size_t)_tbl_ind < _rsht->capacity()) {
354 _bl_ind = _rsht->_buckets[_tbl_ind];
355 ci = find_first_card_in_list();
356 if (ci != SparsePRTEntry::NullEntry) {
357 card_index = compute_card_ind(ci);
358 return true;
359 }
360 // Otherwise, try next entry.
361 _tbl_ind++;
362 }
363 // Otherwise, there were no entry.
364 return false;
365 }
366
367 bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
368 SparsePRTEntry* e = entry_for_region_ind(region_index);
369 return (e != NULL && e->contains_card(card_index));
370 }
371
372 size_t RSHashTable::mem_size() const {
373 return sizeof(this) +
374 capacity() * (SparsePRTEntry::size() + sizeof(int));
375 }
376
377 // ----------------------------------------------------------------------
378
379 SparsePRT* SparsePRT::_head_expanded_list = NULL;
380
381 void SparsePRT::add_to_expanded_list(SparsePRT* sprt) {
382 // We could expand multiple times in a pause -- only put on list once.
383 if (sprt->expanded()) return;
384 sprt->set_expanded(true);
385 SparsePRT* hd = _head_expanded_list;
386 while (true) {
387 sprt->_next_expanded = hd;
388 SparsePRT* res =
389 (SparsePRT*)
390 Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
391 if (res == hd) return;
392 else hd = res;
393 }
455
456
457 SparsePRT::SparsePRT(HeapRegion* hr) :
458 _hr(hr), _expanded(false), _next_expanded(NULL)
459 {
460 _cur = new RSHashTable(InitialCapacity);
461 _next = _cur;
462 }
463
464
465 SparsePRT::~SparsePRT() {
466 assert(_next != NULL && _cur != NULL, "Inv");
467 if (_cur != _next) { delete _cur; }
468 delete _next;
469 }
470
471
472 size_t SparsePRT::mem_size() const {
473 // We ignore "_cur" here, because it either = _next, or else it is
474 // on the deleted list.
475 return sizeof(this) + _next->mem_size();
476 }
477
478 bool SparsePRT::add_card(RegionIdx_t region_id, CardIdx_t card_index) {
479 #if SPARSE_PRT_VERBOSE
480 gclog_or_tty->print_cr(" Adding card %d from region %d to region %u sparse.",
481 card_index, region_id, _hr->hrs_index());
482 #endif
483 if (_next->occupied_entries() * 2 > _next->capacity()) {
484 expand();
485 }
486 return _next->add_card(region_id, card_index);
487 }
488
489 bool SparsePRT::get_cards(RegionIdx_t region_id, CardIdx_t* cards) {
490 return _next->get_cards(region_id, cards);
491 }
492
493 SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) {
494 return _next->get_entry(region_id);
495 }
|
353 while ((size_t)_tbl_ind < _rsht->capacity()) {
354 _bl_ind = _rsht->_buckets[_tbl_ind];
355 ci = find_first_card_in_list();
356 if (ci != SparsePRTEntry::NullEntry) {
357 card_index = compute_card_ind(ci);
358 return true;
359 }
360 // Otherwise, try next entry.
361 _tbl_ind++;
362 }
363 // Otherwise, there were no entry.
364 return false;
365 }
366
367 bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
368 SparsePRTEntry* e = entry_for_region_ind(region_index);
369 return (e != NULL && e->contains_card(card_index));
370 }
371
372 size_t RSHashTable::mem_size() const {
373 return sizeof(RSHashTable) +
374 capacity() * (SparsePRTEntry::size() + sizeof(int));
375 }
376
377 // ----------------------------------------------------------------------
378
379 SparsePRT* SparsePRT::_head_expanded_list = NULL;
380
381 void SparsePRT::add_to_expanded_list(SparsePRT* sprt) {
382 // We could expand multiple times in a pause -- only put on list once.
383 if (sprt->expanded()) return;
384 sprt->set_expanded(true);
385 SparsePRT* hd = _head_expanded_list;
386 while (true) {
387 sprt->_next_expanded = hd;
388 SparsePRT* res =
389 (SparsePRT*)
390 Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
391 if (res == hd) return;
392 else hd = res;
393 }
455
456
457 SparsePRT::SparsePRT(HeapRegion* hr) :
458 _hr(hr), _expanded(false), _next_expanded(NULL)
459 {
460 _cur = new RSHashTable(InitialCapacity);
461 _next = _cur;
462 }
463
464
465 SparsePRT::~SparsePRT() {
466 assert(_next != NULL && _cur != NULL, "Inv");
467 if (_cur != _next) { delete _cur; }
468 delete _next;
469 }
470
471
472 size_t SparsePRT::mem_size() const {
473 // We ignore "_cur" here, because it either = _next, or else it is
474 // on the deleted list.
475 return sizeof(SparsePRT) + _next->mem_size();
476 }
477
478 bool SparsePRT::add_card(RegionIdx_t region_id, CardIdx_t card_index) {
479 #if SPARSE_PRT_VERBOSE
480 gclog_or_tty->print_cr(" Adding card %d from region %d to region %u sparse.",
481 card_index, region_id, _hr->hrs_index());
482 #endif
483 if (_next->occupied_entries() * 2 > _next->capacity()) {
484 expand();
485 }
486 return _next->add_card(region_id, card_index);
487 }
488
489 bool SparsePRT::get_cards(RegionIdx_t region_id, CardIdx_t* cards) {
490 return _next->get_cards(region_id, cards);
491 }
492
493 SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) {
494 return _next->get_entry(region_id);
495 }
|