src/share/vm/memory/blockOffsetTable.cpp

Tue, 24 Feb 2015 15:04:52 -0500

author
dlong
date
Tue, 24 Feb 2015 15:04:52 -0500
changeset 7598
ddce0b7cee93
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
child 9327
f96fcd9e1e1b
permissions
-rw-r--r--

8072383: resolve conflicts between open and closed ports
Summary: refactor close to remove references to closed ports
Reviewed-by: kvn, simonis, sgehwolf, dholmes

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

mercurial