src/share/vm/memory/blockOffsetTable.cpp

Sun, 01 Apr 2012 17:04:26 -0400

author
acorn
date
Sun, 01 Apr 2012 17:04:26 -0400
changeset 3686
749b1464aa81
parent 2943
537a4053b0f9
child 3900
d2a62e0f25eb
permissions
-rw-r--r--

Merge

duke@435 1 /*
ysr@2943 2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 27 #include "memory/blockOffsetTable.inline.hpp"
stefank@2314 28 #include "memory/iterator.hpp"
stefank@2314 29 #include "memory/space.inline.hpp"
stefank@2314 30 #include "memory/universe.hpp"
stefank@2314 31 #include "oops/oop.inline.hpp"
stefank@2314 32 #include "runtime/java.hpp"
duke@435 33
duke@435 34 //////////////////////////////////////////////////////////////////////
duke@435 35 // BlockOffsetSharedArray
duke@435 36 //////////////////////////////////////////////////////////////////////
duke@435 37
duke@435 38 BlockOffsetSharedArray::BlockOffsetSharedArray(MemRegion reserved,
duke@435 39 size_t init_word_size):
duke@435 40 _reserved(reserved), _end(NULL)
duke@435 41 {
duke@435 42 size_t size = compute_size(reserved.word_size());
duke@435 43 ReservedSpace rs(size);
duke@435 44 if (!rs.is_reserved()) {
duke@435 45 vm_exit_during_initialization("Could not reserve enough space for heap offset array");
duke@435 46 }
duke@435 47 if (!_vs.initialize(rs, 0)) {
duke@435 48 vm_exit_during_initialization("Could not reserve enough space for heap offset array");
duke@435 49 }
duke@435 50 _offset_array = (u_char*)_vs.low_boundary();
duke@435 51 resize(init_word_size);
duke@435 52 if (TraceBlockOffsetTable) {
duke@435 53 gclog_or_tty->print_cr("BlockOffsetSharedArray::BlockOffsetSharedArray: ");
duke@435 54 gclog_or_tty->print_cr(" "
duke@435 55 " rs.base(): " INTPTR_FORMAT
duke@435 56 " rs.size(): " INTPTR_FORMAT
duke@435 57 " rs end(): " INTPTR_FORMAT,
duke@435 58 rs.base(), rs.size(), rs.base() + rs.size());
duke@435 59 gclog_or_tty->print_cr(" "
duke@435 60 " _vs.low_boundary(): " INTPTR_FORMAT
duke@435 61 " _vs.high_boundary(): " INTPTR_FORMAT,
duke@435 62 _vs.low_boundary(),
duke@435 63 _vs.high_boundary());
duke@435 64 }
duke@435 65 }
duke@435 66
duke@435 67 void BlockOffsetSharedArray::resize(size_t new_word_size) {
duke@435 68 assert(new_word_size <= _reserved.word_size(), "Resize larger than reserved");
duke@435 69 size_t new_size = compute_size(new_word_size);
duke@435 70 size_t old_size = _vs.committed_size();
duke@435 71 size_t delta;
duke@435 72 char* high = _vs.high();
duke@435 73 _end = _reserved.start() + new_word_size;
duke@435 74 if (new_size > old_size) {
duke@435 75 delta = ReservedSpace::page_align_size_up(new_size - old_size);
duke@435 76 assert(delta > 0, "just checking");
duke@435 77 if (!_vs.expand_by(delta)) {
duke@435 78 // Do better than this for Merlin
duke@435 79 vm_exit_out_of_memory(delta, "offset table expansion");
duke@435 80 }
duke@435 81 assert(_vs.high() == high + delta, "invalid expansion");
duke@435 82 } else {
duke@435 83 delta = ReservedSpace::page_align_size_down(old_size - new_size);
duke@435 84 if (delta == 0) return;
duke@435 85 _vs.shrink_by(delta);
duke@435 86 assert(_vs.high() == high - delta, "invalid expansion");
duke@435 87 }
duke@435 88 }
duke@435 89
duke@435 90 bool BlockOffsetSharedArray::is_card_boundary(HeapWord* p) const {
duke@435 91 assert(p >= _reserved.start(), "just checking");
duke@435 92 size_t delta = pointer_delta(p, _reserved.start());
duke@435 93 return (delta & right_n_bits(LogN_words)) == (size_t)NoBits;
duke@435 94 }
duke@435 95
duke@435 96
duke@435 97 void BlockOffsetSharedArray::serialize(SerializeOopClosure* soc,
duke@435 98 HeapWord* start, HeapWord* end) {
duke@435 99 assert(_offset_array[0] == 0, "objects can't cross covered areas");
duke@435 100 assert(start <= end, "bad address range");
duke@435 101 size_t start_index = index_for(start);
duke@435 102 size_t end_index = index_for(end-1)+1;
duke@435 103 soc->do_region(&_offset_array[start_index],
duke@435 104 (end_index - start_index) * sizeof(_offset_array[0]));
duke@435 105 }
duke@435 106
duke@435 107 //////////////////////////////////////////////////////////////////////
duke@435 108 // BlockOffsetArray
duke@435 109 //////////////////////////////////////////////////////////////////////
duke@435 110
duke@435 111 BlockOffsetArray::BlockOffsetArray(BlockOffsetSharedArray* array,
ysr@2071 112 MemRegion mr, bool init_to_zero_) :
duke@435 113 BlockOffsetTable(mr.start(), mr.end()),
ysr@2071 114 _array(array)
duke@435 115 {
duke@435 116 assert(_bottom <= _end, "arguments out of order");
ysr@2071 117 set_init_to_zero(init_to_zero_);
ysr@2071 118 if (!init_to_zero_) {
duke@435 119 // initialize cards to point back to mr.start()
duke@435 120 set_remainder_to_point_to_start(mr.start() + N_words, mr.end());
duke@435 121 _array->set_offset_array(0, 0); // set first card to 0
duke@435 122 }
duke@435 123 }
duke@435 124
duke@435 125
duke@435 126 // The arguments follow the normal convention of denoting
duke@435 127 // a right-open interval: [start, end)
duke@435 128 void
duke@435 129 BlockOffsetArray::
ysr@2071 130 set_remainder_to_point_to_start(HeapWord* start, HeapWord* end, bool reducing) {
duke@435 131
ysr@2071 132 check_reducing_assertion(reducing);
duke@435 133 if (start >= end) {
duke@435 134 // The start address is equal to the end address (or to
duke@435 135 // the right of the end address) so there are not cards
duke@435 136 // that need to be updated..
duke@435 137 return;
duke@435 138 }
duke@435 139
duke@435 140 // Write the backskip value for each region.
duke@435 141 //
duke@435 142 // offset
duke@435 143 // card 2nd 3rd
duke@435 144 // | +- 1st | |
duke@435 145 // v v v v
duke@435 146 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-
duke@435 147 // |x|0|0|0|0|0|0|0|1|1|1|1|1|1| ... |1|1|1|1|2|2|2|2|2|2| ...
duke@435 148 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-
duke@435 149 // 11 19 75
duke@435 150 // 12
duke@435 151 //
duke@435 152 // offset card is the card that points to the start of an object
duke@435 153 // x - offset value of offset card
duke@435 154 // 1st - start of first logarithmic region
duke@435 155 // 0 corresponds to logarithmic value N_words + 0 and 2**(3 * 0) = 1
duke@435 156 // 2nd - start of second logarithmic region
duke@435 157 // 1 corresponds to logarithmic value N_words + 1 and 2**(3 * 1) = 8
duke@435 158 // 3rd - start of third logarithmic region
duke@435 159 // 2 corresponds to logarithmic value N_words + 2 and 2**(3 * 2) = 64
duke@435 160 //
duke@435 161 // integer below the block offset entry is an example of
duke@435 162 // the index of the entry
duke@435 163 //
duke@435 164 // Given an address,
duke@435 165 // Find the index for the address
duke@435 166 // Find the block offset table entry
duke@435 167 // Convert the entry to a back slide
duke@435 168 // (e.g., with today's, offset = 0x81 =>
duke@435 169 // back slip = 2**(3*(0x81 - N_words)) = 2**3) = 8
duke@435 170 // Move back N (e.g., 8) entries and repeat with the
duke@435 171 // value of the new entry
duke@435 172 //
duke@435 173 size_t start_card = _array->index_for(start);
duke@435 174 size_t end_card = _array->index_for(end-1);
duke@435 175 assert(start ==_array->address_for_index(start_card), "Precondition");
duke@435 176 assert(end ==_array->address_for_index(end_card)+N_words, "Precondition");
ysr@2071 177 set_remainder_to_point_to_start_incl(start_card, end_card, reducing); // closed interval
duke@435 178 }
duke@435 179
duke@435 180
duke@435 181 // Unlike the normal convention in this code, the argument here denotes
duke@435 182 // a closed, inclusive interval: [start_card, end_card], cf set_remainder_to_point_to_start()
duke@435 183 // above.
duke@435 184 void
ysr@2071 185 BlockOffsetArray::set_remainder_to_point_to_start_incl(size_t start_card, size_t end_card, bool reducing) {
ysr@2071 186
ysr@2071 187 check_reducing_assertion(reducing);
duke@435 188 if (start_card > end_card) {
duke@435 189 return;
duke@435 190 }
duke@435 191 assert(start_card > _array->index_for(_bottom), "Cannot be first card");
duke@435 192 assert(_array->offset_array(start_card-1) <= N_words,
duke@435 193 "Offset card has an unexpected value");
duke@435 194 size_t start_card_for_region = start_card;
duke@435 195 u_char offset = max_jubyte;
ysr@777 196 for (int i = 0; i < N_powers; i++) {
duke@435 197 // -1 so that the the card with the actual offset is counted. Another -1
duke@435 198 // so that the reach ends in this region and not at the start
duke@435 199 // of the next.
duke@435 200 size_t reach = start_card - 1 + (power_to_cards_back(i+1) - 1);
duke@435 201 offset = N_words + i;
duke@435 202 if (reach >= end_card) {
ysr@2071 203 _array->set_offset_array(start_card_for_region, end_card, offset, reducing);
duke@435 204 start_card_for_region = reach + 1;
duke@435 205 break;
duke@435 206 }
ysr@2071 207 _array->set_offset_array(start_card_for_region, reach, offset, reducing);
duke@435 208 start_card_for_region = reach + 1;
duke@435 209 }
duke@435 210 assert(start_card_for_region > end_card, "Sanity check");
duke@435 211 DEBUG_ONLY(check_all_cards(start_card, end_card);)
duke@435 212 }
duke@435 213
duke@435 214 // The card-interval [start_card, end_card] is a closed interval; this
duke@435 215 // is an expensive check -- use with care and only under protection of
duke@435 216 // suitable flag.
duke@435 217 void BlockOffsetArray::check_all_cards(size_t start_card, size_t end_card) const {
duke@435 218
duke@435 219 if (end_card < start_card) {
duke@435 220 return;
duke@435 221 }
duke@435 222 guarantee(_array->offset_array(start_card) == N_words, "Wrong value in second card");
ysr@2071 223 u_char last_entry = N_words;
duke@435 224 for (size_t c = start_card + 1; c <= end_card; c++ /* yeah! */) {
duke@435 225 u_char entry = _array->offset_array(c);
ysr@2071 226 guarantee(entry >= last_entry, "Monotonicity");
duke@435 227 if (c - start_card > power_to_cards_back(1)) {
duke@435 228 guarantee(entry > N_words, "Should be in logarithmic region");
duke@435 229 }
duke@435 230 size_t backskip = entry_to_cards_back(entry);
duke@435 231 size_t landing_card = c - backskip;
duke@435 232 guarantee(landing_card >= (start_card - 1), "Inv");
duke@435 233 if (landing_card >= start_card) {
ysr@2071 234 guarantee(_array->offset_array(landing_card) <= entry, "Monotonicity");
duke@435 235 } else {
ysr@2071 236 guarantee(landing_card == (start_card - 1), "Tautology");
ysr@2071 237 // Note that N_words is the maximum offset value
duke@435 238 guarantee(_array->offset_array(landing_card) <= N_words, "Offset value");
duke@435 239 }
ysr@2071 240 last_entry = entry; // remember for monotonicity test
duke@435 241 }
duke@435 242 }
duke@435 243
duke@435 244
duke@435 245 void
duke@435 246 BlockOffsetArray::alloc_block(HeapWord* blk_start, HeapWord* blk_end) {
duke@435 247 assert(blk_start != NULL && blk_end > blk_start,
duke@435 248 "phantom block");
duke@435 249 single_block(blk_start, blk_end);
duke@435 250 }
duke@435 251
duke@435 252 // Action_mark - update the BOT for the block [blk_start, blk_end).
duke@435 253 // Current typical use is for splitting a block.
duke@435 254 // Action_single - udpate the BOT for an allocation.
duke@435 255 // Action_verify - BOT verification.
duke@435 256 void
duke@435 257 BlockOffsetArray::do_block_internal(HeapWord* blk_start,
duke@435 258 HeapWord* blk_end,
ysr@2071 259 Action action, bool reducing) {
duke@435 260 assert(Universe::heap()->is_in_reserved(blk_start),
duke@435 261 "reference must be into the heap");
duke@435 262 assert(Universe::heap()->is_in_reserved(blk_end-1),
duke@435 263 "limit must be within the heap");
duke@435 264 // This is optimized to make the test fast, assuming we only rarely
duke@435 265 // cross boundaries.
duke@435 266 uintptr_t end_ui = (uintptr_t)(blk_end - 1);
duke@435 267 uintptr_t start_ui = (uintptr_t)blk_start;
duke@435 268 // Calculate the last card boundary preceding end of blk
duke@435 269 intptr_t boundary_before_end = (intptr_t)end_ui;
duke@435 270 clear_bits(boundary_before_end, right_n_bits(LogN));
duke@435 271 if (start_ui <= (uintptr_t)boundary_before_end) {
duke@435 272 // blk starts at or crosses a boundary
duke@435 273 // Calculate index of card on which blk begins
duke@435 274 size_t start_index = _array->index_for(blk_start);
duke@435 275 // Index of card on which blk ends
duke@435 276 size_t end_index = _array->index_for(blk_end - 1);
duke@435 277 // Start address of card on which blk begins
duke@435 278 HeapWord* boundary = _array->address_for_index(start_index);
duke@435 279 assert(boundary <= blk_start, "blk should start at or after boundary");
duke@435 280 if (blk_start != boundary) {
duke@435 281 // blk starts strictly after boundary
duke@435 282 // adjust card boundary and start_index forward to next card
duke@435 283 boundary += N_words;
duke@435 284 start_index++;
duke@435 285 }
duke@435 286 assert(start_index <= end_index, "monotonicity of index_for()");
duke@435 287 assert(boundary <= (HeapWord*)boundary_before_end, "tautology");
duke@435 288 switch (action) {
duke@435 289 case Action_mark: {
duke@435 290 if (init_to_zero()) {
ysr@2071 291 _array->set_offset_array(start_index, boundary, blk_start, reducing);
duke@435 292 break;
duke@435 293 } // Else fall through to the next case
duke@435 294 }
duke@435 295 case Action_single: {
ysr@2071 296 _array->set_offset_array(start_index, boundary, blk_start, reducing);
duke@435 297 // We have finished marking the "offset card". We need to now
duke@435 298 // mark the subsequent cards that this blk spans.
duke@435 299 if (start_index < end_index) {
duke@435 300 HeapWord* rem_st = _array->address_for_index(start_index) + N_words;
duke@435 301 HeapWord* rem_end = _array->address_for_index(end_index) + N_words;
ysr@2071 302 set_remainder_to_point_to_start(rem_st, rem_end, reducing);
duke@435 303 }
duke@435 304 break;
duke@435 305 }
duke@435 306 case Action_check: {
duke@435 307 _array->check_offset_array(start_index, boundary, blk_start);
duke@435 308 // We have finished checking the "offset card". We need to now
duke@435 309 // check the subsequent cards that this blk spans.
duke@435 310 check_all_cards(start_index + 1, end_index);
duke@435 311 break;
duke@435 312 }
duke@435 313 default:
duke@435 314 ShouldNotReachHere();
duke@435 315 }
duke@435 316 }
duke@435 317 }
duke@435 318
duke@435 319 // The range [blk_start, blk_end) represents a single contiguous block
duke@435 320 // of storage; modify the block offset table to represent this
duke@435 321 // information; Right-open interval: [blk_start, blk_end)
duke@435 322 // NOTE: this method does _not_ adjust _unallocated_block.
duke@435 323 void
duke@435 324 BlockOffsetArray::single_block(HeapWord* blk_start,
duke@435 325 HeapWord* blk_end) {
duke@435 326 do_block_internal(blk_start, blk_end, Action_single);
duke@435 327 }
duke@435 328
duke@435 329 void BlockOffsetArray::verify() const {
duke@435 330 // For each entry in the block offset table, verify that
duke@435 331 // the entry correctly finds the start of an object at the
duke@435 332 // first address covered by the block or to the left of that
duke@435 333 // first address.
duke@435 334
duke@435 335 size_t next_index = 1;
duke@435 336 size_t last_index = last_active_index();
duke@435 337
duke@435 338 // Use for debugging. Initialize to NULL to distinguish the
duke@435 339 // first iteration through the while loop.
duke@435 340 HeapWord* last_p = NULL;
duke@435 341 HeapWord* last_start = NULL;
duke@435 342 oop last_o = NULL;
duke@435 343
duke@435 344 while (next_index <= last_index) {
duke@435 345 // Use an address past the start of the address for
duke@435 346 // the entry.
duke@435 347 HeapWord* p = _array->address_for_index(next_index) + 1;
duke@435 348 if (p >= _end) {
duke@435 349 // That's all of the allocated block table.
duke@435 350 return;
duke@435 351 }
duke@435 352 // block_start() asserts that start <= p.
duke@435 353 HeapWord* start = block_start(p);
duke@435 354 // First check if the start is an allocated block and only
duke@435 355 // then if it is a valid object.
duke@435 356 oop o = oop(start);
duke@435 357 assert(!Universe::is_fully_initialized() ||
duke@435 358 _sp->is_free_block(start) ||
duke@435 359 o->is_oop_or_null(), "Bad object was found");
duke@435 360 next_index++;
duke@435 361 last_p = p;
duke@435 362 last_start = start;
duke@435 363 last_o = o;
duke@435 364 }
duke@435 365 }
duke@435 366
duke@435 367 //////////////////////////////////////////////////////////////////////
duke@435 368 // BlockOffsetArrayNonContigSpace
duke@435 369 //////////////////////////////////////////////////////////////////////
duke@435 370
duke@435 371 // The block [blk_start, blk_end) has been allocated;
duke@435 372 // adjust the block offset table to represent this information;
duke@435 373 // NOTE: Clients of BlockOffsetArrayNonContigSpace: consider using
duke@435 374 // the somewhat more lightweight split_block() or
duke@435 375 // (when init_to_zero()) mark_block() wherever possible.
duke@435 376 // right-open interval: [blk_start, blk_end)
duke@435 377 void
duke@435 378 BlockOffsetArrayNonContigSpace::alloc_block(HeapWord* blk_start,
duke@435 379 HeapWord* blk_end) {
duke@435 380 assert(blk_start != NULL && blk_end > blk_start,
duke@435 381 "phantom block");
duke@435 382 single_block(blk_start, blk_end);
duke@435 383 allocated(blk_start, blk_end);
duke@435 384 }
duke@435 385
duke@435 386 // Adjust BOT to show that a previously whole block has been split
duke@435 387 // into two. We verify the BOT for the first part (prefix) and
duke@435 388 // update the BOT for the second part (suffix).
duke@435 389 // blk is the start of the block
duke@435 390 // blk_size is the size of the original block
duke@435 391 // left_blk_size is the size of the first part of the split
duke@435 392 void BlockOffsetArrayNonContigSpace::split_block(HeapWord* blk,
duke@435 393 size_t blk_size,
duke@435 394 size_t left_blk_size) {
duke@435 395 // Verify that the BOT shows [blk, blk + blk_size) to be one block.
duke@435 396 verify_single_block(blk, blk_size);
duke@435 397 // Update the BOT to indicate that [blk + left_blk_size, blk + blk_size)
duke@435 398 // is one single block.
duke@435 399 assert(blk_size > 0, "Should be positive");
duke@435 400 assert(left_blk_size > 0, "Should be positive");
duke@435 401 assert(left_blk_size < blk_size, "Not a split");
duke@435 402
duke@435 403 // Start addresses of prefix block and suffix block.
duke@435 404 HeapWord* pref_addr = blk;
duke@435 405 HeapWord* suff_addr = blk + left_blk_size;
duke@435 406 HeapWord* end_addr = blk + blk_size;
duke@435 407
duke@435 408 // Indices for starts of prefix block and suffix block.
duke@435 409 size_t pref_index = _array->index_for(pref_addr);
duke@435 410 if (_array->address_for_index(pref_index) != pref_addr) {
ysr@2071 411 // pref_addr does not begin pref_index
duke@435 412 pref_index++;
duke@435 413 }
duke@435 414
duke@435 415 size_t suff_index = _array->index_for(suff_addr);
duke@435 416 if (_array->address_for_index(suff_index) != suff_addr) {
duke@435 417 // suff_addr does not begin suff_index
duke@435 418 suff_index++;
duke@435 419 }
duke@435 420
duke@435 421 // Definition: A block B, denoted [B_start, B_end) __starts__
duke@435 422 // a card C, denoted [C_start, C_end), where C_start and C_end
duke@435 423 // are the heap addresses that card C covers, iff
duke@435 424 // B_start <= C_start < B_end.
duke@435 425 //
duke@435 426 // We say that a card C "is started by" a block B, iff
duke@435 427 // B "starts" C.
duke@435 428 //
duke@435 429 // Note that the cardinality of the set of cards {C}
duke@435 430 // started by a block B can be 0, 1, or more.
duke@435 431 //
duke@435 432 // Below, pref_index and suff_index are, respectively, the
duke@435 433 // first (least) card indices that the prefix and suffix of
duke@435 434 // the split start; end_index is one more than the index of
duke@435 435 // the last (greatest) card that blk starts.
duke@435 436 size_t end_index = _array->index_for(end_addr - 1) + 1;
duke@435 437
duke@435 438 // Calculate the # cards that the prefix and suffix affect.
duke@435 439 size_t num_pref_cards = suff_index - pref_index;
duke@435 440
duke@435 441 size_t num_suff_cards = end_index - suff_index;
duke@435 442 // Change the cards that need changing
duke@435 443 if (num_suff_cards > 0) {
duke@435 444 HeapWord* boundary = _array->address_for_index(suff_index);
duke@435 445 // Set the offset card for suffix block
ysr@2071 446 _array->set_offset_array(suff_index, boundary, suff_addr, true /* reducing */);
duke@435 447 // Change any further cards that need changing in the suffix
duke@435 448 if (num_pref_cards > 0) {
duke@435 449 if (num_pref_cards >= num_suff_cards) {
duke@435 450 // Unilaterally fix all of the suffix cards: closed card
duke@435 451 // index interval in args below.
ysr@2071 452 set_remainder_to_point_to_start_incl(suff_index + 1, end_index - 1, true /* reducing */);
duke@435 453 } else {
duke@435 454 // Unilaterally fix the first (num_pref_cards - 1) following
duke@435 455 // the "offset card" in the suffix block.
duke@435 456 set_remainder_to_point_to_start_incl(suff_index + 1,
ysr@2071 457 suff_index + num_pref_cards - 1, true /* reducing */);
duke@435 458 // Fix the appropriate cards in the remainder of the
duke@435 459 // suffix block -- these are the last num_pref_cards
duke@435 460 // cards in each power block of the "new" range plumbed
duke@435 461 // from suff_addr.
duke@435 462 bool more = true;
duke@435 463 uint i = 1;
duke@435 464 while (more && (i < N_powers)) {
duke@435 465 size_t back_by = power_to_cards_back(i);
duke@435 466 size_t right_index = suff_index + back_by - 1;
duke@435 467 size_t left_index = right_index - num_pref_cards + 1;
duke@435 468 if (right_index >= end_index - 1) { // last iteration
duke@435 469 right_index = end_index - 1;
duke@435 470 more = false;
duke@435 471 }
duke@435 472 if (back_by > num_pref_cards) {
duke@435 473 // Fill in the remainder of this "power block", if it
duke@435 474 // is non-null.
duke@435 475 if (left_index <= right_index) {
duke@435 476 _array->set_offset_array(left_index, right_index,
ysr@2071 477 N_words + i - 1, true /* reducing */);
duke@435 478 } else {
duke@435 479 more = false; // we are done
duke@435 480 }
duke@435 481 i++;
duke@435 482 break;
duke@435 483 }
duke@435 484 i++;
duke@435 485 }
duke@435 486 while (more && (i < N_powers)) {
duke@435 487 size_t back_by = power_to_cards_back(i);
duke@435 488 size_t right_index = suff_index + back_by - 1;
duke@435 489 size_t left_index = right_index - num_pref_cards + 1;
duke@435 490 if (right_index >= end_index - 1) { // last iteration
duke@435 491 right_index = end_index - 1;
duke@435 492 if (left_index > right_index) {
duke@435 493 break;
duke@435 494 }
duke@435 495 more = false;
duke@435 496 }
duke@435 497 assert(left_index <= right_index, "Error");
ysr@2071 498 _array->set_offset_array(left_index, right_index, N_words + i - 1, true /* reducing */);
duke@435 499 i++;
duke@435 500 }
duke@435 501 }
duke@435 502 } // else no more cards to fix in suffix
duke@435 503 } // else nothing needs to be done
duke@435 504 // Verify that we did the right thing
duke@435 505 verify_single_block(pref_addr, left_blk_size);
duke@435 506 verify_single_block(suff_addr, blk_size - left_blk_size);
duke@435 507 }
duke@435 508
duke@435 509
duke@435 510 // Mark the BOT such that if [blk_start, blk_end) straddles a card
duke@435 511 // boundary, the card following the first such boundary is marked
duke@435 512 // with the appropriate offset.
duke@435 513 // NOTE: this method does _not_ adjust _unallocated_block or
duke@435 514 // any cards subsequent to the first one.
duke@435 515 void
duke@435 516 BlockOffsetArrayNonContigSpace::mark_block(HeapWord* blk_start,
ysr@2071 517 HeapWord* blk_end, bool reducing) {
ysr@2071 518 do_block_internal(blk_start, blk_end, Action_mark, reducing);
duke@435 519 }
duke@435 520
duke@435 521 HeapWord* BlockOffsetArrayNonContigSpace::block_start_unsafe(
duke@435 522 const void* addr) const {
duke@435 523 assert(_array->offset_array(0) == 0, "objects can't cross covered areas");
duke@435 524 assert(_bottom <= addr && addr < _end,
duke@435 525 "addr must be covered by this Array");
duke@435 526 // Must read this exactly once because it can be modified by parallel
duke@435 527 // allocation.
duke@435 528 HeapWord* ub = _unallocated_block;
duke@435 529 if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) {
duke@435 530 assert(ub < _end, "tautology (see above)");
duke@435 531 return ub;
duke@435 532 }
duke@435 533
duke@435 534 // Otherwise, find the block start using the table.
duke@435 535 size_t index = _array->index_for(addr);
duke@435 536 HeapWord* q = _array->address_for_index(index);
duke@435 537
duke@435 538 uint offset = _array->offset_array(index); // Extend u_char to uint.
duke@435 539 while (offset >= N_words) {
duke@435 540 // The excess of the offset from N_words indicates a power of Base
duke@435 541 // to go back by.
duke@435 542 size_t n_cards_back = entry_to_cards_back(offset);
duke@435 543 q -= (N_words * n_cards_back);
ysr@2891 544 assert(q >= _sp->bottom(),
ysr@2891 545 err_msg("q = " PTR_FORMAT " crossed below bottom = " PTR_FORMAT,
ysr@2891 546 q, _sp->bottom()));
ysr@2891 547 assert(q < _sp->end(),
ysr@2891 548 err_msg("q = " PTR_FORMAT " crossed above end = " PTR_FORMAT,
ysr@2891 549 q, _sp->end()));
duke@435 550 index -= n_cards_back;
duke@435 551 offset = _array->offset_array(index);
duke@435 552 }
duke@435 553 assert(offset < N_words, "offset too large");
duke@435 554 index--;
duke@435 555 q -= offset;
ysr@2891 556 assert(q >= _sp->bottom(),
ysr@2891 557 err_msg("q = " PTR_FORMAT " crossed below bottom = " PTR_FORMAT,
ysr@2891 558 q, _sp->bottom()));
ysr@2891 559 assert(q < _sp->end(),
ysr@2891 560 err_msg("q = " PTR_FORMAT " crossed above end = " PTR_FORMAT,
ysr@2891 561 q, _sp->end()));
duke@435 562 HeapWord* n = q;
duke@435 563
duke@435 564 while (n <= addr) {
duke@435 565 debug_only(HeapWord* last = q); // for debugging
duke@435 566 q = n;
duke@435 567 n += _sp->block_size(n);
ysr@2891 568 assert(n > q,
ysr@2943 569 err_msg("Looping at n = " PTR_FORMAT " with last = " PTR_FORMAT","
ysr@2943 570 " while querying blk_start(" PTR_FORMAT ")"
ysr@2943 571 " on _sp = [" PTR_FORMAT "," PTR_FORMAT ")",
ysr@2943 572 n, last, addr, _sp->bottom(), _sp->end()));
duke@435 573 }
ysr@2943 574 assert(q <= addr,
ysr@2943 575 err_msg("wrong order for current (" INTPTR_FORMAT ")" " <= arg (" INTPTR_FORMAT ")",
ysr@2943 576 q, addr));
ysr@2943 577 assert(addr <= n,
ysr@2943 578 err_msg("wrong order for arg (" INTPTR_FORMAT ") <= next (" INTPTR_FORMAT ")",
ysr@2943 579 addr, n));
duke@435 580 return q;
duke@435 581 }
duke@435 582
duke@435 583 HeapWord* BlockOffsetArrayNonContigSpace::block_start_careful(
duke@435 584 const void* addr) const {
duke@435 585 assert(_array->offset_array(0) == 0, "objects can't cross covered areas");
duke@435 586
duke@435 587 assert(_bottom <= addr && addr < _end,
duke@435 588 "addr must be covered by this Array");
duke@435 589 // Must read this exactly once because it can be modified by parallel
duke@435 590 // allocation.
duke@435 591 HeapWord* ub = _unallocated_block;
duke@435 592 if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) {
duke@435 593 assert(ub < _end, "tautology (see above)");
duke@435 594 return ub;
duke@435 595 }
duke@435 596
duke@435 597 // Otherwise, find the block start using the table, but taking
duke@435 598 // care (cf block_start_unsafe() above) not to parse any objects/blocks
duke@435 599 // on the cards themsleves.
duke@435 600 size_t index = _array->index_for(addr);
duke@435 601 assert(_array->address_for_index(index) == addr,
duke@435 602 "arg should be start of card");
duke@435 603
duke@435 604 HeapWord* q = (HeapWord*)addr;
duke@435 605 uint offset;
duke@435 606 do {
duke@435 607 offset = _array->offset_array(index);
duke@435 608 if (offset < N_words) {
duke@435 609 q -= offset;
duke@435 610 } else {
duke@435 611 size_t n_cards_back = entry_to_cards_back(offset);
duke@435 612 q -= (n_cards_back * N_words);
duke@435 613 index -= n_cards_back;
duke@435 614 }
duke@435 615 } while (offset >= N_words);
duke@435 616 assert(q <= addr, "block start should be to left of arg");
duke@435 617 return q;
duke@435 618 }
duke@435 619
duke@435 620 #ifndef PRODUCT
duke@435 621 // Verification & debugging - ensure that the offset table reflects the fact
duke@435 622 // that the block [blk_start, blk_end) or [blk, blk + size) is a
duke@435 623 // single block of storage. NOTE: can't const this because of
duke@435 624 // call to non-const do_block_internal() below.
duke@435 625 void BlockOffsetArrayNonContigSpace::verify_single_block(
duke@435 626 HeapWord* blk_start, HeapWord* blk_end) {
duke@435 627 if (VerifyBlockOffsetArray) {
duke@435 628 do_block_internal(blk_start, blk_end, Action_check);
duke@435 629 }
duke@435 630 }
duke@435 631
duke@435 632 void BlockOffsetArrayNonContigSpace::verify_single_block(
duke@435 633 HeapWord* blk, size_t size) {
duke@435 634 verify_single_block(blk, blk + size);
duke@435 635 }
duke@435 636
duke@435 637 // Verify that the given block is before _unallocated_block
duke@435 638 void BlockOffsetArrayNonContigSpace::verify_not_unallocated(
duke@435 639 HeapWord* blk_start, HeapWord* blk_end) const {
duke@435 640 if (BlockOffsetArrayUseUnallocatedBlock) {
duke@435 641 assert(blk_start < blk_end, "Block inconsistency?");
duke@435 642 assert(blk_end <= _unallocated_block, "_unallocated_block problem");
duke@435 643 }
duke@435 644 }
duke@435 645
duke@435 646 void BlockOffsetArrayNonContigSpace::verify_not_unallocated(
duke@435 647 HeapWord* blk, size_t size) const {
duke@435 648 verify_not_unallocated(blk, blk + size);
duke@435 649 }
duke@435 650 #endif // PRODUCT
duke@435 651
duke@435 652 size_t BlockOffsetArrayNonContigSpace::last_active_index() const {
duke@435 653 if (_unallocated_block == _bottom) {
duke@435 654 return 0;
duke@435 655 } else {
duke@435 656 return _array->index_for(_unallocated_block - 1);
duke@435 657 }
duke@435 658 }
duke@435 659
duke@435 660 //////////////////////////////////////////////////////////////////////
duke@435 661 // BlockOffsetArrayContigSpace
duke@435 662 //////////////////////////////////////////////////////////////////////
duke@435 663
duke@435 664 HeapWord* BlockOffsetArrayContigSpace::block_start_unsafe(const void* addr) const {
duke@435 665 assert(_array->offset_array(0) == 0, "objects can't cross covered areas");
duke@435 666
duke@435 667 // Otherwise, find the block start using the table.
duke@435 668 assert(_bottom <= addr && addr < _end,
duke@435 669 "addr must be covered by this Array");
duke@435 670 size_t index = _array->index_for(addr);
duke@435 671 // We must make sure that the offset table entry we use is valid. If
duke@435 672 // "addr" is past the end, start at the last known one and go forward.
duke@435 673 index = MIN2(index, _next_offset_index-1);
duke@435 674 HeapWord* q = _array->address_for_index(index);
duke@435 675
duke@435 676 uint offset = _array->offset_array(index); // Extend u_char to uint.
duke@435 677 while (offset > N_words) {
duke@435 678 // The excess of the offset from N_words indicates a power of Base
duke@435 679 // to go back by.
duke@435 680 size_t n_cards_back = entry_to_cards_back(offset);
duke@435 681 q -= (N_words * n_cards_back);
duke@435 682 assert(q >= _sp->bottom(), "Went below bottom!");
duke@435 683 index -= n_cards_back;
duke@435 684 offset = _array->offset_array(index);
duke@435 685 }
duke@435 686 while (offset == N_words) {
duke@435 687 assert(q >= _sp->bottom(), "Went below bottom!");
duke@435 688 q -= N_words;
duke@435 689 index--;
duke@435 690 offset = _array->offset_array(index);
duke@435 691 }
duke@435 692 assert(offset < N_words, "offset too large");
duke@435 693 q -= offset;
duke@435 694 HeapWord* n = q;
duke@435 695
duke@435 696 while (n <= addr) {
duke@435 697 debug_only(HeapWord* last = q); // for debugging
duke@435 698 q = n;
duke@435 699 n += _sp->block_size(n);
duke@435 700 }
duke@435 701 assert(q <= addr, "wrong order for current and arg");
duke@435 702 assert(addr <= n, "wrong order for arg and next");
duke@435 703 return q;
duke@435 704 }
duke@435 705
duke@435 706 //
duke@435 707 // _next_offset_threshold
duke@435 708 // | _next_offset_index
duke@435 709 // v v
duke@435 710 // +-------+-------+-------+-------+-------+
duke@435 711 // | i-1 | i | i+1 | i+2 | i+3 |
duke@435 712 // +-------+-------+-------+-------+-------+
duke@435 713 // ( ^ ]
duke@435 714 // block-start
duke@435 715 //
duke@435 716
duke@435 717 void BlockOffsetArrayContigSpace::alloc_block_work(HeapWord* blk_start,
duke@435 718 HeapWord* blk_end) {
duke@435 719 assert(blk_start != NULL && blk_end > blk_start,
duke@435 720 "phantom block");
duke@435 721 assert(blk_end > _next_offset_threshold,
duke@435 722 "should be past threshold");
duke@435 723 assert(blk_start <= _next_offset_threshold,
jcoomes@1844 724 "blk_start should be at or before threshold");
duke@435 725 assert(pointer_delta(_next_offset_threshold, blk_start) <= N_words,
duke@435 726 "offset should be <= BlockOffsetSharedArray::N");
duke@435 727 assert(Universe::heap()->is_in_reserved(blk_start),
duke@435 728 "reference must be into the heap");
duke@435 729 assert(Universe::heap()->is_in_reserved(blk_end-1),
duke@435 730 "limit must be within the heap");
duke@435 731 assert(_next_offset_threshold ==
duke@435 732 _array->_reserved.start() + _next_offset_index*N_words,
duke@435 733 "index must agree with threshold");
duke@435 734
duke@435 735 debug_only(size_t orig_next_offset_index = _next_offset_index;)
duke@435 736
duke@435 737 // Mark the card that holds the offset into the block. Note
duke@435 738 // that _next_offset_index and _next_offset_threshold are not
duke@435 739 // updated until the end of this method.
duke@435 740 _array->set_offset_array(_next_offset_index,
duke@435 741 _next_offset_threshold,
duke@435 742 blk_start);
duke@435 743
duke@435 744 // We need to now mark the subsequent cards that this blk spans.
duke@435 745
duke@435 746 // Index of card on which blk ends.
duke@435 747 size_t end_index = _array->index_for(blk_end - 1);
duke@435 748
duke@435 749 // Are there more cards left to be updated?
duke@435 750 if (_next_offset_index + 1 <= end_index) {
duke@435 751 HeapWord* rem_st = _array->address_for_index(_next_offset_index + 1);
duke@435 752 // Calculate rem_end this way because end_index
duke@435 753 // may be the last valid index in the covered region.
duke@435 754 HeapWord* rem_end = _array->address_for_index(end_index) + N_words;
duke@435 755 set_remainder_to_point_to_start(rem_st, rem_end);
duke@435 756 }
duke@435 757
duke@435 758 // _next_offset_index and _next_offset_threshold updated here.
duke@435 759 _next_offset_index = end_index + 1;
duke@435 760 // Calculate _next_offset_threshold this way because end_index
duke@435 761 // may be the last valid index in the covered region.
ysr@2071 762 _next_offset_threshold = _array->address_for_index(end_index) + N_words;
ysr@2071 763 assert(_next_offset_threshold >= blk_end, "Incorrect offset threshold");
duke@435 764
duke@435 765 #ifdef ASSERT
duke@435 766 // The offset can be 0 if the block starts on a boundary. That
duke@435 767 // is checked by an assertion above.
duke@435 768 size_t start_index = _array->index_for(blk_start);
duke@435 769 HeapWord* boundary = _array->address_for_index(start_index);
duke@435 770 assert((_array->offset_array(orig_next_offset_index) == 0 &&
duke@435 771 blk_start == boundary) ||
duke@435 772 (_array->offset_array(orig_next_offset_index) > 0 &&
duke@435 773 _array->offset_array(orig_next_offset_index) <= N_words),
duke@435 774 "offset array should have been set");
duke@435 775 for (size_t j = orig_next_offset_index + 1; j <= end_index; j++) {
duke@435 776 assert(_array->offset_array(j) > 0 &&
duke@435 777 _array->offset_array(j) <= (u_char) (N_words+N_powers-1),
duke@435 778 "offset array should have been set");
duke@435 779 }
duke@435 780 #endif
duke@435 781 }
duke@435 782
duke@435 783 HeapWord* BlockOffsetArrayContigSpace::initialize_threshold() {
duke@435 784 assert(!Universe::heap()->is_in_reserved(_array->_offset_array),
duke@435 785 "just checking");
duke@435 786 _next_offset_index = _array->index_for(_bottom);
duke@435 787 _next_offset_index++;
duke@435 788 _next_offset_threshold =
duke@435 789 _array->address_for_index(_next_offset_index);
duke@435 790 return _next_offset_threshold;
duke@435 791 }
duke@435 792
duke@435 793 void BlockOffsetArrayContigSpace::zero_bottom_entry() {
duke@435 794 assert(!Universe::heap()->is_in_reserved(_array->_offset_array),
duke@435 795 "just checking");
duke@435 796 size_t bottom_index = _array->index_for(_bottom);
duke@435 797 _array->set_offset_array(bottom_index, 0);
duke@435 798 }
duke@435 799
duke@435 800
duke@435 801 void BlockOffsetArrayContigSpace::serialize(SerializeOopClosure* soc) {
duke@435 802 if (soc->reading()) {
duke@435 803 // Null these values so that the serializer won't object to updating them.
duke@435 804 _next_offset_threshold = NULL;
duke@435 805 _next_offset_index = 0;
duke@435 806 }
duke@435 807 soc->do_ptr(&_next_offset_threshold);
duke@435 808 soc->do_size_t(&_next_offset_index);
duke@435 809 }
duke@435 810
duke@435 811 size_t BlockOffsetArrayContigSpace::last_active_index() const {
duke@435 812 size_t result = _next_offset_index - 1;
duke@435 813 return result >= 0 ? result : 0;
duke@435 814 }

mercurial