2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2009-07-28 12:12:40 -07:00
|
|
|
* Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
|
2008-06-05 15:57:56 -07:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
|
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
|
|
* have any questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "incls/_precompiled.incl"
|
|
|
|
#include "incls/_sparsePRT.cpp.incl"
|
|
|
|
|
|
|
|
#define SPARSE_PRT_VERBOSE 0
|
|
|
|
|
2010-02-11 15:52:19 -08:00
|
|
|
#define UNROLL_CARD_LOOPS 1
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
void SparsePRT::init_iterator(SparsePRTIter* sprt_iter) {
|
|
|
|
sprt_iter->init(this);
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
void SparsePRTEntry::init(RegionIdx_t region_ind) {
|
2008-06-05 15:57:56 -07:00
|
|
|
_region_ind = region_ind;
|
|
|
|
_next_index = NullEntry;
|
2010-02-11 15:52:19 -08:00
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
#if UNROLL_CARD_LOOPS
|
2010-02-11 15:52:19 -08:00
|
|
|
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
|
|
|
|
for (int i = 0; i < cards_num(); i += UnrollFactor) {
|
|
|
|
_cards[i] = NullEntry;
|
|
|
|
_cards[i + 1] = NullEntry;
|
|
|
|
_cards[i + 2] = NullEntry;
|
|
|
|
_cards[i + 3] = NullEntry;
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
#else
|
2010-02-11 15:52:19 -08:00
|
|
|
for (int i = 0; i < cards_num(); i++)
|
2009-06-11 17:19:33 -07:00
|
|
|
_cards[i] = NullEntry;
|
2008-06-05 15:57:56 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool SparsePRTEntry::contains_card(CardIdx_t card_index) const {
|
2008-06-05 15:57:56 -07:00
|
|
|
#if UNROLL_CARD_LOOPS
|
2010-02-11 15:52:19 -08:00
|
|
|
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
|
|
|
|
for (int i = 0; i < cards_num(); i += UnrollFactor) {
|
|
|
|
if (_cards[i] == card_index ||
|
|
|
|
_cards[i + 1] == card_index ||
|
|
|
|
_cards[i + 2] == card_index ||
|
|
|
|
_cards[i + 3] == card_index) return true;
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
#else
|
2010-02-11 15:52:19 -08:00
|
|
|
for (int i = 0; i < cards_num(); i++) {
|
2008-06-05 15:57:56 -07:00
|
|
|
if (_cards[i] == card_index) return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Otherwise, we're full.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SparsePRTEntry::num_valid_cards() const {
|
|
|
|
int sum = 0;
|
|
|
|
#if UNROLL_CARD_LOOPS
|
2010-02-11 15:52:19 -08:00
|
|
|
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
|
|
|
|
for (int i = 0; i < cards_num(); i += UnrollFactor) {
|
|
|
|
sum += (_cards[i] != NullEntry);
|
|
|
|
sum += (_cards[i + 1] != NullEntry);
|
|
|
|
sum += (_cards[i + 2] != NullEntry);
|
|
|
|
sum += (_cards[i + 3] != NullEntry);
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
#else
|
2010-02-11 15:52:19 -08:00
|
|
|
for (int i = 0; i < cards_num(); i++) {
|
|
|
|
sum += (_cards[i] != NullEntry);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Otherwise, we're full.
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) {
|
2008-06-05 15:57:56 -07:00
|
|
|
#if UNROLL_CARD_LOOPS
|
2010-02-11 15:52:19 -08:00
|
|
|
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
|
|
|
|
CardIdx_t c;
|
|
|
|
for (int i = 0; i < cards_num(); i += UnrollFactor) {
|
|
|
|
c = _cards[i];
|
|
|
|
if (c == card_index) return found;
|
|
|
|
if (c == NullEntry) { _cards[i] = card_index; return added; }
|
|
|
|
c = _cards[i + 1];
|
|
|
|
if (c == card_index) return found;
|
|
|
|
if (c == NullEntry) { _cards[i + 1] = card_index; return added; }
|
|
|
|
c = _cards[i + 2];
|
|
|
|
if (c == card_index) return found;
|
|
|
|
if (c == NullEntry) { _cards[i + 2] = card_index; return added; }
|
|
|
|
c = _cards[i + 3];
|
|
|
|
if (c == card_index) return found;
|
|
|
|
if (c == NullEntry) { _cards[i + 3] = card_index; return added; }
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
#else
|
2010-02-11 15:52:19 -08:00
|
|
|
for (int i = 0; i < cards_num(); i++) {
|
2009-06-11 17:19:33 -07:00
|
|
|
CardIdx_t c = _cards[i];
|
2008-06-05 15:57:56 -07:00
|
|
|
if (c == card_index) return found;
|
2010-02-11 15:52:19 -08:00
|
|
|
if (c == NullEntry) { _cards[i] = card_index; return added; }
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Otherwise, we're full.
|
|
|
|
return overflow;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
void SparsePRTEntry::copy_cards(CardIdx_t* cards) const {
|
2008-06-05 15:57:56 -07:00
|
|
|
#if UNROLL_CARD_LOOPS
|
2010-02-11 15:52:19 -08:00
|
|
|
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
|
|
|
|
for (int i = 0; i < cards_num(); i += UnrollFactor) {
|
|
|
|
cards[i] = _cards[i];
|
|
|
|
cards[i + 1] = _cards[i + 1];
|
|
|
|
cards[i + 2] = _cards[i + 2];
|
|
|
|
cards[i + 3] = _cards[i + 3];
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
#else
|
2010-02-11 15:52:19 -08:00
|
|
|
for (int i = 0; i < cards_num(); i++) {
|
2008-06-05 15:57:56 -07:00
|
|
|
cards[i] = _cards[i];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const {
|
|
|
|
copy_cards(&e->_cards[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
RSHashTable::RSHashTable(size_t capacity) :
|
|
|
|
_capacity(capacity), _capacity_mask(capacity-1),
|
|
|
|
_occupied_entries(0), _occupied_cards(0),
|
2010-02-11 15:52:19 -08:00
|
|
|
_entries((SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, SparsePRTEntry::size() * capacity)),
|
2009-06-11 17:19:33 -07:00
|
|
|
_buckets(NEW_C_HEAP_ARRAY(int, capacity)),
|
2008-06-05 15:57:56 -07:00
|
|
|
_free_list(NullEntry), _free_region(0)
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
RSHashTable::~RSHashTable() {
|
|
|
|
if (_entries != NULL) {
|
|
|
|
FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
|
|
|
|
_entries = NULL;
|
|
|
|
}
|
|
|
|
if (_buckets != NULL) {
|
2009-06-11 17:19:33 -07:00
|
|
|
FREE_C_HEAP_ARRAY(int, _buckets);
|
2008-06-05 15:57:56 -07:00
|
|
|
_buckets = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RSHashTable::clear() {
|
|
|
|
_occupied_entries = 0;
|
|
|
|
_occupied_cards = 0;
|
|
|
|
guarantee(_entries != NULL, "INV");
|
|
|
|
guarantee(_buckets != NULL, "INV");
|
2009-06-11 17:19:33 -07:00
|
|
|
|
|
|
|
guarantee(_capacity <= ((size_t)1 << (sizeof(int)*BitsPerByte-1)) - 1,
|
|
|
|
"_capacity too large");
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
// This will put -1 == NullEntry in the key field of all entries.
|
2010-02-11 15:52:19 -08:00
|
|
|
memset(_entries, NullEntry, _capacity * SparsePRTEntry::size());
|
|
|
|
memset(_buckets, NullEntry, _capacity * sizeof(int));
|
2008-06-05 15:57:56 -07:00
|
|
|
_free_list = NullEntry;
|
|
|
|
_free_region = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool RSHashTable::add_card(RegionIdx_t region_ind, CardIdx_t card_index) {
|
2008-06-05 15:57:56 -07:00
|
|
|
SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
|
|
|
|
assert(e != NULL && e->r_ind() == region_ind,
|
|
|
|
"Postcondition of call above.");
|
|
|
|
SparsePRTEntry::AddCardResult res = e->add_card(card_index);
|
|
|
|
if (res == SparsePRTEntry::added) _occupied_cards++;
|
|
|
|
#if SPARSE_PRT_VERBOSE
|
|
|
|
gclog_or_tty->print_cr(" after add_card[%d]: valid-cards = %d.",
|
2010-02-11 15:52:19 -08:00
|
|
|
pointer_delta(e, _entries, SparsePRTEntry::size()),
|
|
|
|
e->num_valid_cards());
|
2008-06-05 15:57:56 -07:00
|
|
|
#endif
|
|
|
|
assert(e->num_valid_cards() > 0, "Postcondition");
|
|
|
|
return res != SparsePRTEntry::overflow;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) {
|
|
|
|
int ind = (int) (region_ind & capacity_mask());
|
|
|
|
int cur_ind = _buckets[ind];
|
2008-06-05 15:57:56 -07:00
|
|
|
SparsePRTEntry* cur;
|
|
|
|
while (cur_ind != NullEntry &&
|
|
|
|
(cur = entry(cur_ind))->r_ind() != region_ind) {
|
|
|
|
cur_ind = cur->next_index();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_ind == NullEntry) return false;
|
|
|
|
// Otherwise...
|
|
|
|
assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
|
|
|
|
assert(cur->num_valid_cards() > 0, "Inv");
|
|
|
|
cur->copy_cards(cards);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-11 15:52:19 -08:00
|
|
|
SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) {
|
|
|
|
int ind = (int) (region_ind & capacity_mask());
|
|
|
|
int cur_ind = _buckets[ind];
|
|
|
|
SparsePRTEntry* cur;
|
|
|
|
while (cur_ind != NullEntry &&
|
|
|
|
(cur = entry(cur_ind))->r_ind() != region_ind) {
|
|
|
|
cur_ind = cur->next_index();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_ind == NullEntry) return NULL;
|
|
|
|
// Otherwise...
|
|
|
|
assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
|
|
|
|
assert(cur->num_valid_cards() > 0, "Inv");
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool RSHashTable::delete_entry(RegionIdx_t region_ind) {
|
|
|
|
int ind = (int) (region_ind & capacity_mask());
|
|
|
|
int* prev_loc = &_buckets[ind];
|
|
|
|
int cur_ind = *prev_loc;
|
2008-06-05 15:57:56 -07:00
|
|
|
SparsePRTEntry* cur;
|
|
|
|
while (cur_ind != NullEntry &&
|
|
|
|
(cur = entry(cur_ind))->r_ind() != region_ind) {
|
|
|
|
prev_loc = cur->next_index_addr();
|
|
|
|
cur_ind = *prev_loc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_ind == NullEntry) return false;
|
|
|
|
// Otherwise, splice out "cur".
|
|
|
|
*prev_loc = cur->next_index();
|
|
|
|
_occupied_cards -= cur->num_valid_cards();
|
|
|
|
free_entry(cur_ind);
|
|
|
|
_occupied_entries--;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
SparsePRTEntry*
|
|
|
|
RSHashTable::entry_for_region_ind(RegionIdx_t region_ind) const {
|
2008-06-05 15:57:56 -07:00
|
|
|
assert(occupied_entries() < capacity(), "Precondition");
|
2009-06-11 17:19:33 -07:00
|
|
|
int ind = (int) (region_ind & capacity_mask());
|
|
|
|
int cur_ind = _buckets[ind];
|
2008-06-05 15:57:56 -07:00
|
|
|
SparsePRTEntry* cur;
|
|
|
|
while (cur_ind != NullEntry &&
|
|
|
|
(cur = entry(cur_ind))->r_ind() != region_ind) {
|
|
|
|
cur_ind = cur->next_index();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_ind != NullEntry) {
|
|
|
|
assert(cur->r_ind() == region_ind, "Loop postcondition + test");
|
|
|
|
return cur;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
SparsePRTEntry*
|
|
|
|
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
|
2008-06-05 15:57:56 -07:00
|
|
|
SparsePRTEntry* res = entry_for_region_ind(region_ind);
|
|
|
|
if (res == NULL) {
|
2009-06-11 17:19:33 -07:00
|
|
|
int new_ind = alloc_entry();
|
2008-06-05 15:57:56 -07:00
|
|
|
assert(0 <= new_ind && (size_t)new_ind < capacity(), "There should be room.");
|
|
|
|
res = entry(new_ind);
|
|
|
|
res->init(region_ind);
|
|
|
|
// Insert at front.
|
2009-06-11 17:19:33 -07:00
|
|
|
int ind = (int) (region_ind & capacity_mask());
|
2008-06-05 15:57:56 -07:00
|
|
|
res->set_next_index(_buckets[ind]);
|
|
|
|
_buckets[ind] = new_ind;
|
|
|
|
_occupied_entries++;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
int RSHashTable::alloc_entry() {
|
|
|
|
int res;
|
2008-06-05 15:57:56 -07:00
|
|
|
if (_free_list != NullEntry) {
|
|
|
|
res = _free_list;
|
|
|
|
_free_list = entry(res)->next_index();
|
|
|
|
return res;
|
|
|
|
} else if ((size_t) _free_region+1 < capacity()) {
|
|
|
|
res = _free_region;
|
|
|
|
_free_region++;
|
|
|
|
return res;
|
|
|
|
} else {
|
|
|
|
return NullEntry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
void RSHashTable::free_entry(int fi) {
|
2008-06-05 15:57:56 -07:00
|
|
|
entry(fi)->set_next_index(_free_list);
|
|
|
|
_free_list = fi;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RSHashTable::add_entry(SparsePRTEntry* e) {
|
|
|
|
assert(e->num_valid_cards() > 0, "Precondition.");
|
|
|
|
SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind());
|
|
|
|
e->copy_cards(e2);
|
|
|
|
_occupied_cards += e2->num_valid_cards();
|
|
|
|
assert(e2->num_valid_cards() > 0, "Postcondition.");
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
CardIdx_t /* RSHashTable:: */ RSHashTableIter::find_first_card_in_list() {
|
|
|
|
CardIdx_t res;
|
2008-06-05 15:57:56 -07:00
|
|
|
while (_bl_ind != RSHashTable::NullEntry) {
|
|
|
|
res = _rsht->entry(_bl_ind)->card(0);
|
|
|
|
if (res != SparsePRTEntry::NullEntry) {
|
|
|
|
return res;
|
|
|
|
} else {
|
|
|
|
_bl_ind = _rsht->entry(_bl_ind)->next_index();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Otherwise, none found:
|
|
|
|
return SparsePRTEntry::NullEntry;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
size_t /* RSHashTable:: */ RSHashTableIter::compute_card_ind(CardIdx_t ci) {
|
2008-06-05 15:57:56 -07:00
|
|
|
return
|
|
|
|
_heap_bot_card_ind
|
2009-07-30 16:22:58 -04:00
|
|
|
+ (_rsht->entry(_bl_ind)->r_ind() * HeapRegion::CardsPerRegion)
|
2008-06-05 15:57:56 -07:00
|
|
|
+ ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool /* RSHashTable:: */ RSHashTableIter::has_next(size_t& card_index) {
|
|
|
|
_card_ind++;
|
2009-06-11 17:19:33 -07:00
|
|
|
CardIdx_t ci;
|
2010-02-11 15:52:19 -08:00
|
|
|
if (_card_ind < SparsePRTEntry::cards_num() &&
|
2008-06-05 15:57:56 -07:00
|
|
|
((ci = _rsht->entry(_bl_ind)->card(_card_ind)) !=
|
|
|
|
SparsePRTEntry::NullEntry)) {
|
|
|
|
card_index = compute_card_ind(ci);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Otherwise, must find the next valid entry.
|
|
|
|
_card_ind = 0;
|
|
|
|
|
|
|
|
if (_bl_ind != RSHashTable::NullEntry) {
|
|
|
|
_bl_ind = _rsht->entry(_bl_ind)->next_index();
|
|
|
|
ci = find_first_card_in_list();
|
|
|
|
if (ci != SparsePRTEntry::NullEntry) {
|
|
|
|
card_index = compute_card_ind(ci);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we didn't return above, must go to the next non-null table index.
|
|
|
|
_tbl_ind++;
|
|
|
|
while ((size_t)_tbl_ind < _rsht->capacity()) {
|
|
|
|
_bl_ind = _rsht->_buckets[_tbl_ind];
|
|
|
|
ci = find_first_card_in_list();
|
|
|
|
if (ci != SparsePRTEntry::NullEntry) {
|
|
|
|
card_index = compute_card_ind(ci);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Otherwise, try next entry.
|
|
|
|
_tbl_ind++;
|
|
|
|
}
|
|
|
|
// Otherwise, there were no entry.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
|
2008-06-05 15:57:56 -07:00
|
|
|
SparsePRTEntry* e = entry_for_region_ind(region_index);
|
|
|
|
return (e != NULL && e->contains_card(card_index));
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t RSHashTable::mem_size() const {
|
2009-06-11 17:19:33 -07:00
|
|
|
return sizeof(this) +
|
2010-02-11 15:52:19 -08:00
|
|
|
capacity() * (SparsePRTEntry::size() + sizeof(int));
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
SparsePRT* SparsePRT::_head_expanded_list = NULL;
|
|
|
|
|
|
|
|
void SparsePRT::add_to_expanded_list(SparsePRT* sprt) {
|
|
|
|
// We could expand multiple times in a pause -- only put on list once.
|
|
|
|
if (sprt->expanded()) return;
|
|
|
|
sprt->set_expanded(true);
|
|
|
|
SparsePRT* hd = _head_expanded_list;
|
|
|
|
while (true) {
|
|
|
|
sprt->_next_expanded = hd;
|
|
|
|
SparsePRT* res =
|
|
|
|
(SparsePRT*)
|
|
|
|
Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
|
|
|
|
if (res == hd) return;
|
|
|
|
else hd = res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
SparsePRT* SparsePRT::get_from_expanded_list() {
|
|
|
|
SparsePRT* hd = _head_expanded_list;
|
|
|
|
while (hd != NULL) {
|
|
|
|
SparsePRT* next = hd->next_expanded();
|
|
|
|
SparsePRT* res =
|
|
|
|
(SparsePRT*)
|
|
|
|
Atomic::cmpxchg_ptr(next, &_head_expanded_list, hd);
|
|
|
|
if (res == hd) {
|
|
|
|
hd->set_next_expanded(NULL);
|
|
|
|
return hd;
|
|
|
|
} else {
|
|
|
|
hd = res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SparsePRT::cleanup_all() {
|
|
|
|
// First clean up all expanded tables so they agree on next and cur.
|
|
|
|
SparsePRT* sprt = get_from_expanded_list();
|
|
|
|
while (sprt != NULL) {
|
|
|
|
sprt->cleanup();
|
|
|
|
sprt = get_from_expanded_list();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SparsePRT::SparsePRT(HeapRegion* hr) :
|
|
|
|
_expanded(false), _next_expanded(NULL)
|
|
|
|
{
|
|
|
|
_cur = new RSHashTable(InitialCapacity);
|
|
|
|
_next = _cur;
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
SparsePRT::~SparsePRT() {
|
|
|
|
assert(_next != NULL && _cur != NULL, "Inv");
|
|
|
|
if (_cur != _next) { delete _cur; }
|
|
|
|
delete _next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t SparsePRT::mem_size() const {
|
|
|
|
// We ignore "_cur" here, because it either = _next, or else it is
|
|
|
|
// on the deleted list.
|
|
|
|
return sizeof(this) + _next->mem_size();
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool SparsePRT::add_card(RegionIdx_t region_id, CardIdx_t card_index) {
|
2008-06-05 15:57:56 -07:00
|
|
|
#if SPARSE_PRT_VERBOSE
|
|
|
|
gclog_or_tty->print_cr(" Adding card %d from region %d to region %d sparse.",
|
|
|
|
card_index, region_id, _hr->hrs_index());
|
|
|
|
#endif
|
|
|
|
if (_next->occupied_entries() * 2 > _next->capacity()) {
|
|
|
|
expand();
|
|
|
|
}
|
|
|
|
return _next->add_card(region_id, card_index);
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool SparsePRT::get_cards(RegionIdx_t region_id, CardIdx_t* cards) {
|
2008-06-05 15:57:56 -07:00
|
|
|
return _next->get_cards(region_id, cards);
|
|
|
|
}
|
|
|
|
|
2010-02-11 15:52:19 -08:00
|
|
|
SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) {
|
|
|
|
return _next->get_entry(region_id);
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool SparsePRT::delete_entry(RegionIdx_t region_id) {
|
2008-06-05 15:57:56 -07:00
|
|
|
return _next->delete_entry(region_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparsePRT::clear() {
|
|
|
|
// If they differ, _next is bigger then cur, so next has no chance of
|
|
|
|
// being the initial size.
|
|
|
|
if (_next != _cur) {
|
|
|
|
delete _next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_cur->capacity() != InitialCapacity) {
|
|
|
|
delete _cur;
|
|
|
|
_cur = new RSHashTable(InitialCapacity);
|
|
|
|
} else {
|
|
|
|
_cur->clear();
|
|
|
|
}
|
|
|
|
_next = _cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparsePRT::cleanup() {
|
2009-10-27 02:42:24 -07:00
|
|
|
// Make sure that the current and next tables agree.
|
|
|
|
if (_cur != _next) {
|
|
|
|
delete _cur;
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
_cur = _next;
|
2009-03-07 11:07:36 -05:00
|
|
|
set_expanded(false);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SparsePRT::expand() {
|
|
|
|
RSHashTable* last = _next;
|
|
|
|
_next = new RSHashTable(last->capacity() * 2);
|
|
|
|
|
|
|
|
#if SPARSE_PRT_VERBOSE
|
|
|
|
gclog_or_tty->print_cr(" Expanded sparse table for %d to %d.",
|
|
|
|
_hr->hrs_index(), _next->capacity());
|
|
|
|
#endif
|
|
|
|
for (size_t i = 0; i < last->capacity(); i++) {
|
|
|
|
SparsePRTEntry* e = last->entry((int)i);
|
|
|
|
if (e->valid_entry()) {
|
|
|
|
#if SPARSE_PRT_VERBOSE
|
|
|
|
gclog_or_tty->print_cr(" During expansion, transferred entry for %d.",
|
|
|
|
e->r_ind());
|
|
|
|
#endif
|
|
|
|
_next->add_entry(e);
|
|
|
|
}
|
|
|
|
}
|
2009-10-27 02:42:24 -07:00
|
|
|
if (last != _cur) {
|
|
|
|
delete last;
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
add_to_expanded_list(this);
|
|
|
|
}
|