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