1 /* 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" 27 #include "gc_implementation/g1/heapRegion.hpp" 28 #include "memory/space.hpp" 29 #include "oops/oop.inline.hpp" 30 #include "runtime/java.hpp" 31 #include "services/memTracker.hpp" 32 33 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 34 35 void G1BlockOffsetSharedArrayMappingChangedListener::on_commit(uint start_idx, size_t num_regions) { 36 // Nothing to do. The BOT is hard-wired to be part of the HeapRegion, and we cannot 37 // retrieve it here since this would cause firing of several asserts. The code 38 // exacuted after commit of a region already needs to do some re-initialization of 39 // the HeapRegion, so we combine that. 40 } 41 42 ////////////////////////////////////////////////////////////////////// 43 // G1BlockOffsetSharedArray 44 ////////////////////////////////////////////////////////////////////// 45 46 G1BlockOffsetSharedArray::G1BlockOffsetSharedArray(MemRegion heap, G1RegionToSpaceMapper* storage) : 47 _reserved(), _end(NULL), _listener(), _offset_array(NULL) { 48 49 _reserved = heap; 50 _end = NULL; 51 52 MemRegion bot_reserved = storage->reserved(); 53 54 _offset_array = (u_char*)bot_reserved.start(); 55 _end = _reserved.end(); 56 57 storage->set_mapping_changed_listener(&_listener); 58 59 if (TraceBlockOffsetTable) { 60 gclog_or_tty->print_cr("G1BlockOffsetSharedArray::G1BlockOffsetSharedArray: "); 61 gclog_or_tty->print_cr(" " 62 " rs.base(): " INTPTR_FORMAT 63 " rs.size(): " INTPTR_FORMAT 64 " rs end(): " INTPTR_FORMAT, 65 bot_reserved.start(), bot_reserved.byte_size(), bot_reserved.end()); 66 } 67 } 68 69 bool G1BlockOffsetSharedArray::is_card_boundary(HeapWord* p) const { 70 assert(p >= _reserved.start(), "just checking"); 71 size_t delta = pointer_delta(p, _reserved.start()); 72 return (delta & right_n_bits(LogN_words)) == (size_t)NoBits; 73 } 74 75 void G1BlockOffsetSharedArray::set_offset_array(HeapWord* left, HeapWord* right, u_char offset) { 76 set_offset_array(index_for(left), index_for(right -1), offset); 77 } 78 79 ////////////////////////////////////////////////////////////////////// 80 // G1BlockOffsetArray 81 ////////////////////////////////////////////////////////////////////// 82 83 G1BlockOffsetArray::G1BlockOffsetArray(G1BlockOffsetSharedArray* array, 84 MemRegion mr, bool init_to_zero) : 85 G1BlockOffsetTable(mr.start(), mr.end()), 86 _unallocated_block(_bottom), 87 _array(array), _gsp(NULL), 88 _init_to_zero(init_to_zero) { 89 assert(_bottom <= _end, "arguments out of order"); 90 if (!_init_to_zero) { 91 // initialize cards to point back to mr.start() 92 set_remainder_to_point_to_start(mr.start() + N_words, mr.end()); 93 _array->set_offset_array(0, 0); // set first card to 0 94 } 95 } 96 97 void G1BlockOffsetArray::set_space(G1OffsetTableContigSpace* sp) { 98 _gsp = sp; 99 } 100 101 // The arguments follow the normal convention of denoting 102 // a right-open interval: [start, end) 103 void 104 G1BlockOffsetArray:: set_remainder_to_point_to_start(HeapWord* start, HeapWord* end) { 105 106 if (start >= end) { 107 // The start address is equal to the end address (or to 108 // the right of the end address) so there are not cards 109 // that need to be updated.. 110 return; 111 } 112 113 // Write the backskip value for each region. 114 // 115 // offset 116 // card 2nd 3rd 117 // | +- 1st | | 118 // v v v v 119 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+- 120 // |x|0|0|0|0|0|0|0|1|1|1|1|1|1| ... |1|1|1|1|2|2|2|2|2|2| ... 121 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+- 122 // 11 19 75 123 // 12 124 // 125 // offset card is the card that points to the start of an object 126 // x - offset value of offset card 127 // 1st - start of first logarithmic region 128 // 0 corresponds to logarithmic value N_words + 0 and 2**(3 * 0) = 1 129 // 2nd - start of second logarithmic region 130 // 1 corresponds to logarithmic value N_words + 1 and 2**(3 * 1) = 8 131 // 3rd - start of third logarithmic region 132 // 2 corresponds to logarithmic value N_words + 2 and 2**(3 * 2) = 64 133 // 134 // integer below the block offset entry is an example of 135 // the index of the entry 136 // 137 // Given an address, 138 // Find the index for the address 139 // Find the block offset table entry 140 // Convert the entry to a back slide 141 // (e.g., with today's, offset = 0x81 => 142 // back slip = 2**(3*(0x81 - N_words)) = 2**3) = 8 143 // Move back N (e.g., 8) entries and repeat with the 144 // value of the new entry 145 // 146 size_t start_card = _array->index_for(start); 147 size_t end_card = _array->index_for(end-1); 148 assert(start ==_array->address_for_index(start_card), "Precondition"); 149 assert(end ==_array->address_for_index(end_card)+N_words, "Precondition"); 150 set_remainder_to_point_to_start_incl(start_card, end_card); // closed interval 151 } 152 153 // Unlike the normal convention in this code, the argument here denotes 154 // a closed, inclusive interval: [start_card, end_card], cf set_remainder_to_point_to_start() 155 // above. 156 void 157 G1BlockOffsetArray::set_remainder_to_point_to_start_incl(size_t start_card, size_t end_card) { 158 if (start_card > end_card) { 159 return; 160 } 161 assert(start_card > _array->index_for(_bottom), "Cannot be first card"); 162 assert(_array->offset_array(start_card-1) <= N_words, 163 "Offset card has an unexpected value"); 164 size_t start_card_for_region = start_card; 165 u_char offset = max_jubyte; 166 for (int i = 0; i < BlockOffsetArray::N_powers; i++) { 167 // -1 so that the the card with the actual offset is counted. Another -1 168 // so that the reach ends in this region and not at the start 169 // of the next. 170 size_t reach = start_card - 1 + (BlockOffsetArray::power_to_cards_back(i+1) - 1); 171 offset = N_words + i; 172 if (reach >= end_card) { 173 _array->set_offset_array(start_card_for_region, end_card, offset); 174 start_card_for_region = reach + 1; 175 break; 176 } 177 _array->set_offset_array(start_card_for_region, reach, offset); 178 start_card_for_region = reach + 1; 179 } 180 assert(start_card_for_region > end_card, "Sanity check"); 181 DEBUG_ONLY(check_all_cards(start_card, end_card);) 182 } 183 184 // The block [blk_start, blk_end) has been allocated; 185 // adjust the block offset table to represent this information; 186 // right-open interval: [blk_start, blk_end) 187 void 188 G1BlockOffsetArray::alloc_block(HeapWord* blk_start, HeapWord* blk_end) { 189 mark_block(blk_start, blk_end); 190 allocated(blk_start, blk_end); 191 } 192 193 // Adjust BOT to show that a previously whole block has been split 194 // into two. 195 void G1BlockOffsetArray::split_block(HeapWord* blk, size_t blk_size, 196 size_t left_blk_size) { 197 // Verify that the BOT shows [blk, blk + blk_size) to be one block. 198 verify_single_block(blk, blk_size); 199 // Update the BOT to indicate that [blk + left_blk_size, blk + blk_size) 200 // is one single block. 201 mark_block(blk + left_blk_size, blk + blk_size); 202 } 203 204 205 // Action_mark - update the BOT for the block [blk_start, blk_end). 206 // Current typical use is for splitting a block. 207 // Action_single - update the BOT for an allocation. 208 // Action_verify - BOT verification. 209 void G1BlockOffsetArray::do_block_internal(HeapWord* blk_start, 210 HeapWord* blk_end, 211 Action action) { 212 assert(Universe::heap()->is_in_reserved(blk_start), 213 "reference must be into the heap"); 214 assert(Universe::heap()->is_in_reserved(blk_end-1), 215 "limit must be within the heap"); 216 // This is optimized to make the test fast, assuming we only rarely 217 // cross boundaries. 218 uintptr_t end_ui = (uintptr_t)(blk_end - 1); 219 uintptr_t start_ui = (uintptr_t)blk_start; 220 // Calculate the last card boundary preceding end of blk 221 intptr_t boundary_before_end = (intptr_t)end_ui; 222 clear_bits(boundary_before_end, right_n_bits(LogN)); 223 if (start_ui <= (uintptr_t)boundary_before_end) { 224 // blk starts at or crosses a boundary 225 // Calculate index of card on which blk begins 226 size_t start_index = _array->index_for(blk_start); 227 // Index of card on which blk ends 228 size_t end_index = _array->index_for(blk_end - 1); 229 // Start address of card on which blk begins 230 HeapWord* boundary = _array->address_for_index(start_index); 231 assert(boundary <= blk_start, "blk should start at or after boundary"); 232 if (blk_start != boundary) { 233 // blk starts strictly after boundary 234 // adjust card boundary and start_index forward to next card 235 boundary += N_words; 236 start_index++; 237 } 238 assert(start_index <= end_index, "monotonicity of index_for()"); 239 assert(boundary <= (HeapWord*)boundary_before_end, "tautology"); 240 switch (action) { 241 case Action_mark: { 242 if (init_to_zero()) { 243 _array->set_offset_array(start_index, boundary, blk_start); 244 break; 245 } // Else fall through to the next case 246 } 247 case Action_single: { 248 _array->set_offset_array(start_index, boundary, blk_start); 249 // We have finished marking the "offset card". We need to now 250 // mark the subsequent cards that this blk spans. 251 if (start_index < end_index) { 252 HeapWord* rem_st = _array->address_for_index(start_index) + N_words; 253 HeapWord* rem_end = _array->address_for_index(end_index) + N_words; 254 set_remainder_to_point_to_start(rem_st, rem_end); 255 } 256 break; 257 } 258 case Action_check: { 259 _array->check_offset_array(start_index, boundary, blk_start); 260 // We have finished checking the "offset card". We need to now 261 // check the subsequent cards that this blk spans. 262 check_all_cards(start_index + 1, end_index); 263 break; 264 } 265 default: 266 ShouldNotReachHere(); 267 } 268 } 269 } 270 271 // The card-interval [start_card, end_card] is a closed interval; this 272 // is an expensive check -- use with care and only under protection of 273 // suitable flag. 274 void G1BlockOffsetArray::check_all_cards(size_t start_card, size_t end_card) const { 275 276 if (end_card < start_card) { 277 return; 278 } 279 guarantee(_array->offset_array(start_card) == N_words, "Wrong value in second card"); 280 for (size_t c = start_card + 1; c <= end_card; c++ /* yeah! */) { 281 u_char entry = _array->offset_array(c); 282 if (c - start_card > BlockOffsetArray::power_to_cards_back(1)) { 283 guarantee(entry > N_words, 284 err_msg("Should be in logarithmic region - " 285 "entry: %u, " 286 "_array->offset_array(c): %u, " 287 "N_words: %u", 288 (uint)entry, (uint)_array->offset_array(c), (uint)N_words)); 289 } 290 size_t backskip = BlockOffsetArray::entry_to_cards_back(entry); 291 size_t landing_card = c - backskip; 292 guarantee(landing_card >= (start_card - 1), "Inv"); 293 if (landing_card >= start_card) { 294 guarantee(_array->offset_array(landing_card) <= entry, 295 err_msg("Monotonicity - landing_card offset: %u, " 296 "entry: %u", 297 (uint)_array->offset_array(landing_card), (uint)entry)); 298 } else { 299 guarantee(landing_card == start_card - 1, "Tautology"); 300 // Note that N_words is the maximum offset value 301 guarantee(_array->offset_array(landing_card) <= N_words, 302 err_msg("landing card offset: %u, " 303 "N_words: %u", 304 (uint)_array->offset_array(landing_card), (uint)N_words)); 305 } 306 } 307 } 308 309 // The range [blk_start, blk_end) represents a single contiguous block 310 // of storage; modify the block offset table to represent this 311 // information; Right-open interval: [blk_start, blk_end) 312 // NOTE: this method does _not_ adjust _unallocated_block. 313 void 314 G1BlockOffsetArray::single_block(HeapWord* blk_start, HeapWord* blk_end) { 315 do_block_internal(blk_start, blk_end, Action_single); 316 } 317 318 // Mark the BOT such that if [blk_start, blk_end) straddles a card 319 // boundary, the card following the first such boundary is marked 320 // with the appropriate offset. 321 // NOTE: this method does _not_ adjust _unallocated_block or 322 // any cards subsequent to the first one. 323 void 324 G1BlockOffsetArray::mark_block(HeapWord* blk_start, HeapWord* blk_end) { 325 do_block_internal(blk_start, blk_end, Action_mark); 326 } 327 328 HeapWord* G1BlockOffsetArray::block_start_unsafe(const void* addr) { 329 assert(_bottom <= addr && addr < _end, 330 "addr must be covered by this Array"); 331 // Must read this exactly once because it can be modified by parallel 332 // allocation. 333 HeapWord* ub = _unallocated_block; 334 if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) { 335 assert(ub < _end, "tautology (see above)"); 336 return ub; 337 } 338 // Otherwise, find the block start using the table. 339 HeapWord* q = block_at_or_preceding(addr, false, 0); 340 return forward_to_block_containing_addr(q, addr); 341 } 342 343 // This duplicates a little code from the above: unavoidable. 344 HeapWord* 345 G1BlockOffsetArray::block_start_unsafe_const(const void* addr) const { 346 assert(_bottom <= addr && addr < _end, 347 "addr must be covered by this Array"); 348 // Must read this exactly once because it can be modified by parallel 349 // allocation. 350 HeapWord* ub = _unallocated_block; 351 if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) { 352 assert(ub < _end, "tautology (see above)"); 353 return ub; 354 } 355 // Otherwise, find the block start using the table. 356 HeapWord* q = block_at_or_preceding(addr, false, 0); 357 HeapWord* n = q + block_size(q); 358 return forward_to_block_containing_addr_const(q, n, addr); 359 } 360 361 362 HeapWord* 363 G1BlockOffsetArray::forward_to_block_containing_addr_slow(HeapWord* q, 364 HeapWord* n, 365 const void* addr) { 366 // We're not in the normal case. We need to handle an important subcase 367 // here: LAB allocation. An allocation previously recorded in the 368 // offset table was actually a lab allocation, and was divided into 369 // several objects subsequently. Fix this situation as we answer the 370 // query, by updating entries as we cross them. 371 372 // If the fist object's end q is at the card boundary. Start refining 373 // with the corresponding card (the value of the entry will be basically 374 // set to 0). If the object crosses the boundary -- start from the next card. 375 size_t n_index = _array->index_for(n); 376 size_t next_index = _array->index_for(n) + !_array->is_card_boundary(n); 377 // Calculate a consistent next boundary. If "n" is not at the boundary 378 // already, step to the boundary. 379 HeapWord* next_boundary = _array->address_for_index(n_index) + 380 (n_index == next_index ? 0 : N_words); 381 assert(next_boundary <= _array->_end, 382 err_msg("next_boundary is beyond the end of the covered region " 383 " next_boundary " PTR_FORMAT " _array->_end " PTR_FORMAT, 384 next_boundary, _array->_end)); 385 if (addr >= gsp()->top()) return gsp()->top(); 386 while (next_boundary < addr) { 387 while (n <= next_boundary) { 388 q = n; 389 oop obj = oop(q); 390 if (obj->klass_or_null() == NULL) return q; 391 n += block_size(q); 392 } 393 assert(q <= next_boundary && n > next_boundary, "Consequence of loop"); 394 // [q, n) is the block that crosses the boundary. 395 alloc_block_work2(&next_boundary, &next_index, q, n); 396 } 397 return forward_to_block_containing_addr_const(q, n, addr); 398 } 399 400 HeapWord* G1BlockOffsetArray::block_start_careful(const void* addr) const { 401 assert(_array->offset_array(0) == 0, "objects can't cross covered areas"); 402 403 assert(_bottom <= addr && addr < _end, 404 "addr must be covered by this Array"); 405 // Must read this exactly once because it can be modified by parallel 406 // allocation. 407 HeapWord* ub = _unallocated_block; 408 if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) { 409 assert(ub < _end, "tautology (see above)"); 410 return ub; 411 } 412 413 // Otherwise, find the block start using the table, but taking 414 // care (cf block_start_unsafe() above) not to parse any objects/blocks 415 // on the cards themselves. 416 size_t index = _array->index_for(addr); 417 assert(_array->address_for_index(index) == addr, 418 "arg should be start of card"); 419 420 HeapWord* q = (HeapWord*)addr; 421 uint offset; 422 do { 423 offset = _array->offset_array(index--); 424 q -= offset; 425 } while (offset == N_words); 426 assert(q <= addr, "block start should be to left of arg"); 427 return q; 428 } 429 430 // Note that the committed size of the covered space may have changed, 431 // so the table size might also wish to change. 432 void G1BlockOffsetArray::resize(size_t new_word_size) { 433 HeapWord* new_end = _bottom + new_word_size; 434 if (_end < new_end && !init_to_zero()) { 435 // verify that the old and new boundaries are also card boundaries 436 assert(_array->is_card_boundary(_end), 437 "_end not a card boundary"); 438 assert(_array->is_card_boundary(new_end), 439 "new _end would not be a card boundary"); 440 // set all the newly added cards 441 _array->set_offset_array(_end, new_end, N_words); 442 } 443 _end = new_end; // update _end 444 } 445 446 void G1BlockOffsetArray::set_region(MemRegion mr) { 447 _bottom = mr.start(); 448 _end = mr.end(); 449 } 450 451 // 452 // threshold_ 453 // | _index_ 454 // v v 455 // +-------+-------+-------+-------+-------+ 456 // | i-1 | i | i+1 | i+2 | i+3 | 457 // +-------+-------+-------+-------+-------+ 458 // ( ^ ] 459 // block-start 460 // 461 void G1BlockOffsetArray::alloc_block_work2(HeapWord** threshold_, size_t* index_, 462 HeapWord* blk_start, HeapWord* blk_end) { 463 // For efficiency, do copy-in/copy-out. 464 HeapWord* threshold = *threshold_; 465 size_t index = *index_; 466 467 assert(blk_start != NULL && blk_end > blk_start, 468 "phantom block"); 469 assert(blk_end > threshold, "should be past threshold"); 470 assert(blk_start <= threshold, "blk_start should be at or before threshold"); 471 assert(pointer_delta(threshold, blk_start) <= N_words, 472 "offset should be <= BlockOffsetSharedArray::N"); 473 assert(Universe::heap()->is_in_reserved(blk_start), 474 "reference must be into the heap"); 475 assert(Universe::heap()->is_in_reserved(blk_end-1), 476 "limit must be within the heap"); 477 assert(threshold == _array->_reserved.start() + index*N_words, 478 "index must agree with threshold"); 479 480 DEBUG_ONLY(size_t orig_index = index;) 481 482 // Mark the card that holds the offset into the block. Note 483 // that _next_offset_index and _next_offset_threshold are not 484 // updated until the end of this method. 485 _array->set_offset_array(index, threshold, blk_start); 486 487 // We need to now mark the subsequent cards that this blk spans. 488 489 // Index of card on which blk ends. 490 size_t end_index = _array->index_for(blk_end - 1); 491 492 // Are there more cards left to be updated? 493 if (index + 1 <= end_index) { 494 HeapWord* rem_st = _array->address_for_index(index + 1); 495 // Calculate rem_end this way because end_index 496 // may be the last valid index in the covered region. 497 HeapWord* rem_end = _array->address_for_index(end_index) + N_words; 498 set_remainder_to_point_to_start(rem_st, rem_end); 499 } 500 501 index = end_index + 1; 502 // Calculate threshold_ this way because end_index 503 // may be the last valid index in the covered region. 504 threshold = _array->address_for_index(end_index) + N_words; 505 assert(threshold >= blk_end, "Incorrect offset threshold"); 506 507 // index_ and threshold_ updated here. 508 *threshold_ = threshold; 509 *index_ = index; 510 511 #ifdef ASSERT 512 // The offset can be 0 if the block starts on a boundary. That 513 // is checked by an assertion above. 514 size_t start_index = _array->index_for(blk_start); 515 HeapWord* boundary = _array->address_for_index(start_index); 516 assert((_array->offset_array(orig_index) == 0 && 517 blk_start == boundary) || 518 (_array->offset_array(orig_index) > 0 && 519 _array->offset_array(orig_index) <= N_words), 520 err_msg("offset array should have been set - " 521 "orig_index offset: %u, " 522 "blk_start: " PTR_FORMAT ", " 523 "boundary: " PTR_FORMAT, 524 (uint)_array->offset_array(orig_index), 525 blk_start, boundary)); 526 for (size_t j = orig_index + 1; j <= end_index; j++) { 527 assert(_array->offset_array(j) > 0 && 528 _array->offset_array(j) <= 529 (u_char) (N_words+BlockOffsetArray::N_powers-1), 530 err_msg("offset array should have been set - " 531 "%u not > 0 OR %u not <= %u", 532 (uint) _array->offset_array(j), 533 (uint) _array->offset_array(j), 534 (uint) (N_words+BlockOffsetArray::N_powers-1))); 535 } 536 #endif 537 } 538 539 bool 540 G1BlockOffsetArray::verify_for_object(HeapWord* obj_start, 541 size_t word_size) const { 542 size_t first_card = _array->index_for(obj_start); 543 size_t last_card = _array->index_for(obj_start + word_size - 1); 544 if (!_array->is_card_boundary(obj_start)) { 545 // If the object is not on a card boundary the BOT entry of the 546 // first card should point to another object so we should not 547 // check that one. 548 first_card += 1; 549 } 550 for (size_t card = first_card; card <= last_card; card += 1) { 551 HeapWord* card_addr = _array->address_for_index(card); 552 HeapWord* block_start = block_start_const(card_addr); 553 if (block_start != obj_start) { 554 gclog_or_tty->print_cr("block start: "PTR_FORMAT" is incorrect - " 555 "card index: "SIZE_FORMAT" " 556 "card addr: "PTR_FORMAT" BOT entry: %u " 557 "obj: "PTR_FORMAT" word size: "SIZE_FORMAT" " 558 "cards: ["SIZE_FORMAT","SIZE_FORMAT"]", 559 block_start, card, card_addr, 560 _array->offset_array(card), 561 obj_start, word_size, first_card, last_card); 562 return false; 563 } 564 } 565 return true; 566 } 567 568 #ifndef PRODUCT 569 void 570 G1BlockOffsetArray::print_on(outputStream* out) { 571 size_t from_index = _array->index_for(_bottom); 572 size_t to_index = _array->index_for(_end); 573 out->print_cr(">> BOT for area ["PTR_FORMAT","PTR_FORMAT") " 574 "cards ["SIZE_FORMAT","SIZE_FORMAT")", 575 _bottom, _end, from_index, to_index); 576 for (size_t i = from_index; i < to_index; ++i) { 577 out->print_cr(" entry "SIZE_FORMAT_W(8)" | "PTR_FORMAT" : %3u", 578 i, _array->address_for_index(i), 579 (uint) _array->offset_array(i)); 580 } 581 } 582 #endif // !PRODUCT 583 584 ////////////////////////////////////////////////////////////////////// 585 // G1BlockOffsetArrayContigSpace 586 ////////////////////////////////////////////////////////////////////// 587 588 HeapWord* 589 G1BlockOffsetArrayContigSpace::block_start_unsafe(const void* addr) { 590 assert(_bottom <= addr && addr < _end, 591 "addr must be covered by this Array"); 592 HeapWord* q = block_at_or_preceding(addr, true, _next_offset_index-1); 593 return forward_to_block_containing_addr(q, addr); 594 } 595 596 HeapWord* 597 G1BlockOffsetArrayContigSpace:: 598 block_start_unsafe_const(const void* addr) const { 599 assert(_bottom <= addr && addr < _end, 600 "addr must be covered by this Array"); 601 HeapWord* q = block_at_or_preceding(addr, true, _next_offset_index-1); 602 HeapWord* n = q + block_size(q); 603 return forward_to_block_containing_addr_const(q, n, addr); 604 } 605 606 G1BlockOffsetArrayContigSpace:: 607 G1BlockOffsetArrayContigSpace(G1BlockOffsetSharedArray* array, 608 MemRegion mr) : 609 G1BlockOffsetArray(array, mr, true) 610 { 611 _next_offset_threshold = NULL; 612 _next_offset_index = 0; 613 } 614 615 HeapWord* G1BlockOffsetArrayContigSpace::initialize_threshold_raw() { 616 assert(!Universe::heap()->is_in_reserved(_array->_offset_array), 617 "just checking"); 618 _next_offset_index = _array->index_for_raw(_bottom); 619 _next_offset_index++; 620 _next_offset_threshold = 621 _array->address_for_index_raw(_next_offset_index); 622 return _next_offset_threshold; 623 } 624 625 void G1BlockOffsetArrayContigSpace::zero_bottom_entry_raw() { 626 assert(!Universe::heap()->is_in_reserved(_array->_offset_array), 627 "just checking"); 628 size_t bottom_index = _array->index_for_raw(_bottom); 629 assert(_array->address_for_index_raw(bottom_index) == _bottom, 630 "Precondition of call"); 631 _array->set_offset_array_raw(bottom_index, 0); 632 } 633 634 HeapWord* G1BlockOffsetArrayContigSpace::initialize_threshold() { 635 assert(!Universe::heap()->is_in_reserved(_array->_offset_array), 636 "just checking"); 637 _next_offset_index = _array->index_for(_bottom); 638 _next_offset_index++; 639 _next_offset_threshold = 640 _array->address_for_index(_next_offset_index); 641 return _next_offset_threshold; 642 } 643 644 void G1BlockOffsetArrayContigSpace::zero_bottom_entry() { 645 assert(!Universe::heap()->is_in_reserved(_array->_offset_array), 646 "just checking"); 647 size_t bottom_index = _array->index_for(_bottom); 648 assert(_array->address_for_index(bottom_index) == _bottom, 649 "Precondition of call"); 650 _array->set_offset_array(bottom_index, 0); 651 } 652 653 void 654 G1BlockOffsetArrayContigSpace::set_for_starts_humongous(HeapWord* new_top) { 655 assert(new_top <= _end, "_end should have already been updated"); 656 657 // The first BOT entry should have offset 0. 658 reset_bot(); 659 alloc_block(_bottom, new_top); 660 } 661 662 #ifndef PRODUCT 663 void 664 G1BlockOffsetArrayContigSpace::print_on(outputStream* out) { 665 G1BlockOffsetArray::print_on(out); 666 out->print_cr(" next offset threshold: "PTR_FORMAT, _next_offset_threshold); 667 out->print_cr(" next offset index: "SIZE_FORMAT, _next_offset_index); 668 } 669 #endif // !PRODUCT