annotate src/share/vm/gc_implementation/g1/g1BlockOffsetTable.cpp @ 2025:2250ee17e258

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