annotate src/share/vm/gc_implementation/g1/sparsePRT.cpp @ 844:bd02caa94611

6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
author xdono
date Tue, 28 Jul 2009 12:12:40 -0700
parents d44bdab1c03d
children 2c79770d1f6e
rev   line source
ysr@342 1 /*
xdono@844 2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
ysr@342 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@342 4 *
ysr@342 5 * This code is free software; you can redistribute it and/or modify it
ysr@342 6 * under the terms of the GNU General Public License version 2 only, as
ysr@342 7 * published by the Free Software Foundation.
ysr@342 8 *
ysr@342 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@342 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@342 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@342 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@342 13 * accompanied this code).
ysr@342 14 *
ysr@342 15 * You should have received a copy of the GNU General Public License version
ysr@342 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@342 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@342 18 *
ysr@342 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@342 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@342 21 * have any questions.
ysr@342 22 *
ysr@342 23 */
ysr@342 24
ysr@342 25 #include "incls/_precompiled.incl"
ysr@342 26 #include "incls/_sparsePRT.cpp.incl"
ysr@342 27
ysr@342 28 #define SPARSE_PRT_VERBOSE 0
ysr@342 29
ysr@342 30 #define UNROLL_CARD_LOOPS 1
ysr@342 31
ysr@342 32 void SparsePRT::init_iterator(SparsePRTIter* sprt_iter) {
ysr@342 33 sprt_iter->init(this);
ysr@342 34 }
ysr@342 35
johnc@807 36 void SparsePRTEntry::init(RegionIdx_t region_ind) {
ysr@342 37 _region_ind = region_ind;
ysr@342 38 _next_index = NullEntry;
ysr@342 39 #if UNROLL_CARD_LOOPS
ysr@342 40 assert(CardsPerEntry == 4, "Assumption. If changes, un-unroll.");
ysr@342 41 _cards[0] = NullEntry;
ysr@342 42 _cards[1] = NullEntry;
ysr@342 43 _cards[2] = NullEntry;
ysr@342 44 _cards[3] = NullEntry;
ysr@342 45 #else
johnc@807 46 for (int i = 0; i < CardsPerEntry; i++)
johnc@807 47 _cards[i] = NullEntry;
ysr@342 48 #endif
ysr@342 49 }
ysr@342 50
johnc@807 51 bool SparsePRTEntry::contains_card(CardIdx_t card_index) const {
ysr@342 52 #if UNROLL_CARD_LOOPS
ysr@342 53 assert(CardsPerEntry == 4, "Assumption. If changes, un-unroll.");
ysr@342 54 if (_cards[0] == card_index) return true;
ysr@342 55 if (_cards[1] == card_index) return true;
ysr@342 56 if (_cards[2] == card_index) return true;
ysr@342 57 if (_cards[3] == card_index) return true;
ysr@342 58 #else
ysr@342 59 for (int i = 0; i < CardsPerEntry; i++) {
ysr@342 60 if (_cards[i] == card_index) return true;
ysr@342 61 }
ysr@342 62 #endif
ysr@342 63 // Otherwise, we're full.
ysr@342 64 return false;
ysr@342 65 }
ysr@342 66
ysr@342 67 int SparsePRTEntry::num_valid_cards() const {
ysr@342 68 int sum = 0;
ysr@342 69 #if UNROLL_CARD_LOOPS
ysr@342 70 assert(CardsPerEntry == 4, "Assumption. If changes, un-unroll.");
ysr@342 71 if (_cards[0] != NullEntry) sum++;
ysr@342 72 if (_cards[1] != NullEntry) sum++;
ysr@342 73 if (_cards[2] != NullEntry) sum++;
ysr@342 74 if (_cards[3] != NullEntry) sum++;
ysr@342 75 #else
ysr@342 76 for (int i = 0; i < CardsPerEntry; i++) {
ysr@342 77 if (_cards[i] != NulLEntry) sum++;
ysr@342 78 }
ysr@342 79 #endif
ysr@342 80 // Otherwise, we're full.
ysr@342 81 return sum;
ysr@342 82 }
ysr@342 83
johnc@807 84 SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) {
ysr@342 85 #if UNROLL_CARD_LOOPS
ysr@342 86 assert(CardsPerEntry == 4, "Assumption. If changes, un-unroll.");
johnc@807 87 CardIdx_t c = _cards[0];
ysr@342 88 if (c == card_index) return found;
ysr@342 89 if (c == NullEntry) { _cards[0] = card_index; return added; }
ysr@342 90 c = _cards[1];
ysr@342 91 if (c == card_index) return found;
ysr@342 92 if (c == NullEntry) { _cards[1] = card_index; return added; }
ysr@342 93 c = _cards[2];
ysr@342 94 if (c == card_index) return found;
ysr@342 95 if (c == NullEntry) { _cards[2] = card_index; return added; }
ysr@342 96 c = _cards[3];
ysr@342 97 if (c == card_index) return found;
ysr@342 98 if (c == NullEntry) { _cards[3] = card_index; return added; }
ysr@342 99 #else
ysr@342 100 for (int i = 0; i < CardsPerEntry; i++) {
johnc@807 101 CardIdx_t c = _cards[i];
ysr@342 102 if (c == card_index) return found;
johnc@807 103 if (c == NullEntry) {
johnc@807 104 _cards[i] = card_index;
johnc@807 105 return added;
johnc@807 106 }
ysr@342 107 }
ysr@342 108 #endif
ysr@342 109 // Otherwise, we're full.
ysr@342 110 return overflow;
ysr@342 111 }
ysr@342 112
johnc@807 113 void SparsePRTEntry::copy_cards(CardIdx_t* cards) const {
ysr@342 114 #if UNROLL_CARD_LOOPS
ysr@342 115 assert(CardsPerEntry == 4, "Assumption. If changes, un-unroll.");
ysr@342 116 cards[0] = _cards[0];
ysr@342 117 cards[1] = _cards[1];
ysr@342 118 cards[2] = _cards[2];
ysr@342 119 cards[3] = _cards[3];
ysr@342 120 #else
ysr@342 121 for (int i = 0; i < CardsPerEntry; i++) {
ysr@342 122 cards[i] = _cards[i];
ysr@342 123 }
ysr@342 124 #endif
ysr@342 125 }
ysr@342 126
ysr@342 127 void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const {
ysr@342 128 copy_cards(&e->_cards[0]);
ysr@342 129 }
ysr@342 130
ysr@342 131 // ----------------------------------------------------------------------
ysr@342 132
ysr@342 133 RSHashTable::RSHashTable(size_t capacity) :
ysr@342 134 _capacity(capacity), _capacity_mask(capacity-1),
ysr@342 135 _occupied_entries(0), _occupied_cards(0),
ysr@342 136 _entries(NEW_C_HEAP_ARRAY(SparsePRTEntry, capacity)),
johnc@807 137 _buckets(NEW_C_HEAP_ARRAY(int, capacity)),
ysr@342 138 _next_deleted(NULL), _deleted(false),
ysr@342 139 _free_list(NullEntry), _free_region(0)
ysr@342 140 {
ysr@342 141 clear();
ysr@342 142 }
ysr@342 143
ysr@342 144 RSHashTable::~RSHashTable() {
ysr@342 145 if (_entries != NULL) {
ysr@342 146 FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
ysr@342 147 _entries = NULL;
ysr@342 148 }
ysr@342 149 if (_buckets != NULL) {
johnc@807 150 FREE_C_HEAP_ARRAY(int, _buckets);
ysr@342 151 _buckets = NULL;
ysr@342 152 }
ysr@342 153 }
ysr@342 154
ysr@342 155 void RSHashTable::clear() {
ysr@342 156 _occupied_entries = 0;
ysr@342 157 _occupied_cards = 0;
ysr@342 158 guarantee(_entries != NULL, "INV");
ysr@342 159 guarantee(_buckets != NULL, "INV");
johnc@807 160
johnc@807 161 guarantee(_capacity <= ((size_t)1 << (sizeof(int)*BitsPerByte-1)) - 1,
johnc@807 162 "_capacity too large");
johnc@807 163
ysr@342 164 // This will put -1 == NullEntry in the key field of all entries.
ysr@342 165 memset(_entries, -1, _capacity * sizeof(SparsePRTEntry));
johnc@807 166 memset(_buckets, -1, _capacity * sizeof(int));
ysr@342 167 _free_list = NullEntry;
ysr@342 168 _free_region = 0;
ysr@342 169 }
ysr@342 170
johnc@807 171 bool RSHashTable::add_card(RegionIdx_t region_ind, CardIdx_t card_index) {
ysr@342 172 SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
ysr@342 173 assert(e != NULL && e->r_ind() == region_ind,
ysr@342 174 "Postcondition of call above.");
ysr@342 175 SparsePRTEntry::AddCardResult res = e->add_card(card_index);
ysr@342 176 if (res == SparsePRTEntry::added) _occupied_cards++;
ysr@342 177 #if SPARSE_PRT_VERBOSE
ysr@342 178 gclog_or_tty->print_cr(" after add_card[%d]: valid-cards = %d.",
ysr@342 179 pointer_delta(e, _entries, sizeof(SparsePRTEntry)),
ysr@342 180 e->num_valid_cards());
ysr@342 181 #endif
ysr@342 182 assert(e->num_valid_cards() > 0, "Postcondition");
ysr@342 183 return res != SparsePRTEntry::overflow;
ysr@342 184 }
ysr@342 185
johnc@807 186 bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) {
johnc@807 187 int ind = (int) (region_ind & capacity_mask());
johnc@807 188 int cur_ind = _buckets[ind];
ysr@342 189 SparsePRTEntry* cur;
ysr@342 190 while (cur_ind != NullEntry &&
ysr@342 191 (cur = entry(cur_ind))->r_ind() != region_ind) {
ysr@342 192 cur_ind = cur->next_index();
ysr@342 193 }
ysr@342 194
ysr@342 195 if (cur_ind == NullEntry) return false;
ysr@342 196 // Otherwise...
ysr@342 197 assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
ysr@342 198 assert(cur->num_valid_cards() > 0, "Inv");
ysr@342 199 cur->copy_cards(cards);
ysr@342 200 return true;
ysr@342 201 }
ysr@342 202
johnc@807 203 bool RSHashTable::delete_entry(RegionIdx_t region_ind) {
johnc@807 204 int ind = (int) (region_ind & capacity_mask());
johnc@807 205 int* prev_loc = &_buckets[ind];
johnc@807 206 int cur_ind = *prev_loc;
ysr@342 207 SparsePRTEntry* cur;
ysr@342 208 while (cur_ind != NullEntry &&
ysr@342 209 (cur = entry(cur_ind))->r_ind() != region_ind) {
ysr@342 210 prev_loc = cur->next_index_addr();
ysr@342 211 cur_ind = *prev_loc;
ysr@342 212 }
ysr@342 213
ysr@342 214 if (cur_ind == NullEntry) return false;
ysr@342 215 // Otherwise, splice out "cur".
ysr@342 216 *prev_loc = cur->next_index();
ysr@342 217 _occupied_cards -= cur->num_valid_cards();
ysr@342 218 free_entry(cur_ind);
ysr@342 219 _occupied_entries--;
ysr@342 220 return true;
ysr@342 221 }
ysr@342 222
johnc@807 223 SparsePRTEntry*
johnc@807 224 RSHashTable::entry_for_region_ind(RegionIdx_t region_ind) const {
ysr@342 225 assert(occupied_entries() < capacity(), "Precondition");
johnc@807 226 int ind = (int) (region_ind & capacity_mask());
johnc@807 227 int cur_ind = _buckets[ind];
ysr@342 228 SparsePRTEntry* cur;
ysr@342 229 // XXX
ysr@342 230 // int k = 0;
ysr@342 231 while (cur_ind != NullEntry &&
ysr@342 232 (cur = entry(cur_ind))->r_ind() != region_ind) {
ysr@342 233 /*
ysr@342 234 k++;
ysr@342 235 if (k > 10) {
ysr@342 236 gclog_or_tty->print_cr("RSHashTable::entry_for_region_ind(%d): "
ysr@342 237 "k = %d, cur_ind = %d.", region_ind, k, cur_ind);
ysr@342 238 if (k >= 1000) {
ysr@342 239 while (1) ;
ysr@342 240 }
ysr@342 241 }
ysr@342 242 */
ysr@342 243 cur_ind = cur->next_index();
ysr@342 244 }
ysr@342 245
ysr@342 246 if (cur_ind != NullEntry) {
ysr@342 247 assert(cur->r_ind() == region_ind, "Loop postcondition + test");
ysr@342 248 return cur;
ysr@342 249 } else {
ysr@342 250 return NULL;
ysr@342 251 }
ysr@342 252 }
ysr@342 253
johnc@807 254 SparsePRTEntry*
johnc@807 255 RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
ysr@342 256 SparsePRTEntry* res = entry_for_region_ind(region_ind);
ysr@342 257 if (res == NULL) {
johnc@807 258 int new_ind = alloc_entry();
ysr@342 259 assert(0 <= new_ind && (size_t)new_ind < capacity(), "There should be room.");
ysr@342 260 res = entry(new_ind);
ysr@342 261 res->init(region_ind);
ysr@342 262 // Insert at front.
johnc@807 263 int ind = (int) (region_ind & capacity_mask());
ysr@342 264 res->set_next_index(_buckets[ind]);
ysr@342 265 _buckets[ind] = new_ind;
ysr@342 266 _occupied_entries++;
ysr@342 267 }
ysr@342 268 return res;
ysr@342 269 }
ysr@342 270
johnc@807 271 int RSHashTable::alloc_entry() {
johnc@807 272 int res;
ysr@342 273 if (_free_list != NullEntry) {
ysr@342 274 res = _free_list;
ysr@342 275 _free_list = entry(res)->next_index();
ysr@342 276 return res;
ysr@342 277 } else if ((size_t) _free_region+1 < capacity()) {
ysr@342 278 res = _free_region;
ysr@342 279 _free_region++;
ysr@342 280 return res;
ysr@342 281 } else {
ysr@342 282 return NullEntry;
ysr@342 283 }
ysr@342 284 }
ysr@342 285
johnc@807 286 void RSHashTable::free_entry(int fi) {
ysr@342 287 entry(fi)->set_next_index(_free_list);
ysr@342 288 _free_list = fi;
ysr@342 289 }
ysr@342 290
ysr@342 291 void RSHashTable::add_entry(SparsePRTEntry* e) {
ysr@342 292 assert(e->num_valid_cards() > 0, "Precondition.");
ysr@342 293 SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind());
ysr@342 294 e->copy_cards(e2);
ysr@342 295 _occupied_cards += e2->num_valid_cards();
ysr@342 296 assert(e2->num_valid_cards() > 0, "Postcondition.");
ysr@342 297 }
ysr@342 298
ysr@342 299 RSHashTable* RSHashTable::_head_deleted_list = NULL;
ysr@342 300
ysr@342 301 void RSHashTable::add_to_deleted_list(RSHashTable* rsht) {
ysr@342 302 assert(!rsht->deleted(), "Should delete only once.");
ysr@342 303 rsht->set_deleted(true);
ysr@342 304 RSHashTable* hd = _head_deleted_list;
ysr@342 305 while (true) {
ysr@342 306 rsht->_next_deleted = hd;
ysr@342 307 RSHashTable* res =
ysr@342 308 (RSHashTable*)
ysr@342 309 Atomic::cmpxchg_ptr(rsht, &_head_deleted_list, hd);
ysr@342 310 if (res == hd) return;
ysr@342 311 else hd = res;
ysr@342 312 }
ysr@342 313 }
ysr@342 314
ysr@342 315 RSHashTable* RSHashTable::get_from_deleted_list() {
ysr@342 316 RSHashTable* hd = _head_deleted_list;
ysr@342 317 while (hd != NULL) {
ysr@342 318 RSHashTable* next = hd->next_deleted();
ysr@342 319 RSHashTable* res =
ysr@342 320 (RSHashTable*)
ysr@342 321 Atomic::cmpxchg_ptr(next, &_head_deleted_list, hd);
ysr@342 322 if (res == hd) {
ysr@342 323 hd->set_next_deleted(NULL);
ysr@342 324 hd->set_deleted(false);
ysr@342 325 return hd;
ysr@342 326 } else {
ysr@342 327 hd = res;
ysr@342 328 }
ysr@342 329 }
ysr@342 330 return NULL;
ysr@342 331 }
ysr@342 332
johnc@807 333 CardIdx_t /* RSHashTable:: */ RSHashTableIter::find_first_card_in_list() {
johnc@807 334 CardIdx_t res;
ysr@342 335 while (_bl_ind != RSHashTable::NullEntry) {
ysr@342 336 res = _rsht->entry(_bl_ind)->card(0);
ysr@342 337 if (res != SparsePRTEntry::NullEntry) {
ysr@342 338 return res;
ysr@342 339 } else {
ysr@342 340 _bl_ind = _rsht->entry(_bl_ind)->next_index();
ysr@342 341 }
ysr@342 342 }
ysr@342 343 // Otherwise, none found:
ysr@342 344 return SparsePRTEntry::NullEntry;
ysr@342 345 }
ysr@342 346
johnc@807 347 size_t /* RSHashTable:: */ RSHashTableIter::compute_card_ind(CardIdx_t ci) {
ysr@342 348 return
ysr@342 349 _heap_bot_card_ind
ysr@342 350 + (_rsht->entry(_bl_ind)->r_ind() * CardsPerRegion)
ysr@342 351 + ci;
ysr@342 352 }
ysr@342 353
ysr@342 354 bool /* RSHashTable:: */ RSHashTableIter::has_next(size_t& card_index) {
ysr@342 355 _card_ind++;
johnc@807 356 CardIdx_t ci;
ysr@342 357 if (_card_ind < SparsePRTEntry::CardsPerEntry &&
ysr@342 358 ((ci = _rsht->entry(_bl_ind)->card(_card_ind)) !=
ysr@342 359 SparsePRTEntry::NullEntry)) {
ysr@342 360 card_index = compute_card_ind(ci);
ysr@342 361 return true;
ysr@342 362 }
ysr@342 363 // Otherwise, must find the next valid entry.
ysr@342 364 _card_ind = 0;
ysr@342 365
ysr@342 366 if (_bl_ind != RSHashTable::NullEntry) {
ysr@342 367 _bl_ind = _rsht->entry(_bl_ind)->next_index();
ysr@342 368 ci = find_first_card_in_list();
ysr@342 369 if (ci != SparsePRTEntry::NullEntry) {
ysr@342 370 card_index = compute_card_ind(ci);
ysr@342 371 return true;
ysr@342 372 }
ysr@342 373 }
ysr@342 374 // If we didn't return above, must go to the next non-null table index.
ysr@342 375 _tbl_ind++;
ysr@342 376 while ((size_t)_tbl_ind < _rsht->capacity()) {
ysr@342 377 _bl_ind = _rsht->_buckets[_tbl_ind];
ysr@342 378 ci = find_first_card_in_list();
ysr@342 379 if (ci != SparsePRTEntry::NullEntry) {
ysr@342 380 card_index = compute_card_ind(ci);
ysr@342 381 return true;
ysr@342 382 }
ysr@342 383 // Otherwise, try next entry.
ysr@342 384 _tbl_ind++;
ysr@342 385 }
ysr@342 386 // Otherwise, there were no entry.
ysr@342 387 return false;
ysr@342 388 }
ysr@342 389
johnc@807 390 bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
ysr@342 391 SparsePRTEntry* e = entry_for_region_ind(region_index);
ysr@342 392 return (e != NULL && e->contains_card(card_index));
ysr@342 393 }
ysr@342 394
ysr@342 395 size_t RSHashTable::mem_size() const {
johnc@807 396 return sizeof(this) +
johnc@807 397 capacity() * (sizeof(SparsePRTEntry) + sizeof(int));
ysr@342 398 }
ysr@342 399
ysr@342 400 // ----------------------------------------------------------------------
ysr@342 401
ysr@342 402 SparsePRT* SparsePRT::_head_expanded_list = NULL;
ysr@342 403
ysr@342 404 void SparsePRT::add_to_expanded_list(SparsePRT* sprt) {
ysr@342 405 // We could expand multiple times in a pause -- only put on list once.
ysr@342 406 if (sprt->expanded()) return;
ysr@342 407 sprt->set_expanded(true);
ysr@342 408 SparsePRT* hd = _head_expanded_list;
ysr@342 409 while (true) {
ysr@342 410 sprt->_next_expanded = hd;
ysr@342 411 SparsePRT* res =
ysr@342 412 (SparsePRT*)
ysr@342 413 Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
ysr@342 414 if (res == hd) return;
ysr@342 415 else hd = res;
ysr@342 416 }
ysr@342 417 }
ysr@342 418
johnc@807 419
ysr@342 420 SparsePRT* SparsePRT::get_from_expanded_list() {
ysr@342 421 SparsePRT* hd = _head_expanded_list;
ysr@342 422 while (hd != NULL) {
ysr@342 423 SparsePRT* next = hd->next_expanded();
ysr@342 424 SparsePRT* res =
ysr@342 425 (SparsePRT*)
ysr@342 426 Atomic::cmpxchg_ptr(next, &_head_expanded_list, hd);
ysr@342 427 if (res == hd) {
ysr@342 428 hd->set_next_expanded(NULL);
ysr@342 429 return hd;
ysr@342 430 } else {
ysr@342 431 hd = res;
ysr@342 432 }
ysr@342 433 }
ysr@342 434 return NULL;
ysr@342 435 }
ysr@342 436
ysr@342 437
ysr@342 438 void SparsePRT::cleanup_all() {
ysr@342 439 // First clean up all expanded tables so they agree on next and cur.
ysr@342 440 SparsePRT* sprt = get_from_expanded_list();
ysr@342 441 while (sprt != NULL) {
ysr@342 442 sprt->cleanup();
ysr@342 443 sprt = get_from_expanded_list();
ysr@342 444 }
ysr@342 445 // Now delete all deleted RSHashTables.
ysr@342 446 RSHashTable* rsht = RSHashTable::get_from_deleted_list();
ysr@342 447 while (rsht != NULL) {
ysr@342 448 #if SPARSE_PRT_VERBOSE
ysr@342 449 gclog_or_tty->print_cr("About to delete RSHT " PTR_FORMAT ".", rsht);
ysr@342 450 #endif
ysr@342 451 delete rsht;
ysr@342 452 rsht = RSHashTable::get_from_deleted_list();
ysr@342 453 }
ysr@342 454 }
ysr@342 455
ysr@342 456
ysr@342 457 SparsePRT::SparsePRT(HeapRegion* hr) :
ysr@342 458 _expanded(false), _next_expanded(NULL)
ysr@342 459 {
ysr@342 460 _cur = new RSHashTable(InitialCapacity);
ysr@342 461 _next = _cur;
ysr@342 462 }
ysr@342 463
johnc@807 464
ysr@342 465 SparsePRT::~SparsePRT() {
ysr@342 466 assert(_next != NULL && _cur != NULL, "Inv");
ysr@342 467 if (_cur != _next) { delete _cur; }
ysr@342 468 delete _next;
ysr@342 469 }
ysr@342 470
ysr@342 471
ysr@342 472 size_t SparsePRT::mem_size() const {
ysr@342 473 // We ignore "_cur" here, because it either = _next, or else it is
ysr@342 474 // on the deleted list.
ysr@342 475 return sizeof(this) + _next->mem_size();
ysr@342 476 }
ysr@342 477
johnc@807 478 bool SparsePRT::add_card(RegionIdx_t region_id, CardIdx_t card_index) {
ysr@342 479 #if SPARSE_PRT_VERBOSE
ysr@342 480 gclog_or_tty->print_cr(" Adding card %d from region %d to region %d sparse.",
ysr@342 481 card_index, region_id, _hr->hrs_index());
ysr@342 482 #endif
ysr@342 483 if (_next->occupied_entries() * 2 > _next->capacity()) {
ysr@342 484 expand();
ysr@342 485 }
ysr@342 486 return _next->add_card(region_id, card_index);
ysr@342 487 }
ysr@342 488
johnc@807 489 bool SparsePRT::get_cards(RegionIdx_t region_id, CardIdx_t* cards) {
ysr@342 490 return _next->get_cards(region_id, cards);
ysr@342 491 }
ysr@342 492
johnc@807 493 bool SparsePRT::delete_entry(RegionIdx_t region_id) {
ysr@342 494 return _next->delete_entry(region_id);
ysr@342 495 }
ysr@342 496
ysr@342 497 void SparsePRT::clear() {
ysr@342 498 // If they differ, _next is bigger then cur, so next has no chance of
ysr@342 499 // being the initial size.
ysr@342 500 if (_next != _cur) {
ysr@342 501 delete _next;
ysr@342 502 }
ysr@342 503
ysr@342 504 if (_cur->capacity() != InitialCapacity) {
ysr@342 505 delete _cur;
ysr@342 506 _cur = new RSHashTable(InitialCapacity);
ysr@342 507 } else {
ysr@342 508 _cur->clear();
ysr@342 509 }
ysr@342 510 _next = _cur;
ysr@342 511 }
ysr@342 512
ysr@342 513 void SparsePRT::cleanup() {
ysr@342 514 // Make sure that the current and next tables agree. (Another mechanism
ysr@342 515 // takes care of deleting now-unused tables.)
ysr@342 516 _cur = _next;
tonyp@617 517 set_expanded(false);
ysr@342 518 }
ysr@342 519
ysr@342 520 void SparsePRT::expand() {
ysr@342 521 RSHashTable* last = _next;
ysr@342 522 _next = new RSHashTable(last->capacity() * 2);
ysr@342 523
ysr@342 524 #if SPARSE_PRT_VERBOSE
ysr@342 525 gclog_or_tty->print_cr(" Expanded sparse table for %d to %d.",
ysr@342 526 _hr->hrs_index(), _next->capacity());
ysr@342 527 #endif
ysr@342 528 for (size_t i = 0; i < last->capacity(); i++) {
ysr@342 529 SparsePRTEntry* e = last->entry((int)i);
ysr@342 530 if (e->valid_entry()) {
ysr@342 531 #if SPARSE_PRT_VERBOSE
ysr@342 532 gclog_or_tty->print_cr(" During expansion, transferred entry for %d.",
ysr@342 533 e->r_ind());
ysr@342 534 #endif
ysr@342 535 _next->add_entry(e);
ysr@342 536 }
ysr@342 537 }
ysr@342 538 if (last != _cur)
ysr@342 539 RSHashTable::add_to_deleted_list(last);
ysr@342 540 add_to_expanded_list(this);
ysr@342 541 }