Thu, 12 Oct 2017 21:27:07 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" |
mgerdin@6987 | 27 | #include "gc_implementation/g1/heapRegion.hpp" |
aoqi@0 | 28 | #include "memory/space.hpp" |
aoqi@0 | 29 | #include "oops/oop.inline.hpp" |
aoqi@0 | 30 | #include "runtime/java.hpp" |
aoqi@0 | 31 | #include "services/memTracker.hpp" |
aoqi@0 | 32 | |
aoqi@0 | 33 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
aoqi@0 | 34 | |
aoqi@0 | 35 | ////////////////////////////////////////////////////////////////////// |
aoqi@0 | 36 | // G1BlockOffsetSharedArray |
aoqi@0 | 37 | ////////////////////////////////////////////////////////////////////// |
aoqi@0 | 38 | |
tschatzl@7051 | 39 | G1BlockOffsetSharedArray::G1BlockOffsetSharedArray(MemRegion heap, G1RegionToSpaceMapper* storage) : |
tschatzl@7051 | 40 | _reserved(), _end(NULL), _listener(), _offset_array(NULL) { |
aoqi@0 | 41 | |
tschatzl@7051 | 42 | _reserved = heap; |
tschatzl@7051 | 43 | _end = NULL; |
aoqi@0 | 44 | |
tschatzl@7051 | 45 | MemRegion bot_reserved = storage->reserved(); |
tschatzl@7051 | 46 | |
tschatzl@7051 | 47 | _offset_array = (u_char*)bot_reserved.start(); |
tschatzl@7051 | 48 | _end = _reserved.end(); |
tschatzl@7051 | 49 | |
tschatzl@7051 | 50 | storage->set_mapping_changed_listener(&_listener); |
tschatzl@7051 | 51 | |
aoqi@0 | 52 | if (TraceBlockOffsetTable) { |
aoqi@0 | 53 | gclog_or_tty->print_cr("G1BlockOffsetSharedArray::G1BlockOffsetSharedArray: "); |
aoqi@0 | 54 | gclog_or_tty->print_cr(" " |
aoqi@0 | 55 | " rs.base(): " INTPTR_FORMAT |
aoqi@0 | 56 | " rs.size(): " INTPTR_FORMAT |
aoqi@0 | 57 | " rs end(): " INTPTR_FORMAT, |
tschatzl@7051 | 58 | bot_reserved.start(), bot_reserved.byte_size(), bot_reserved.end()); |
aoqi@0 | 59 | } |
aoqi@0 | 60 | } |
aoqi@0 | 61 | |
aoqi@0 | 62 | bool G1BlockOffsetSharedArray::is_card_boundary(HeapWord* p) const { |
aoqi@0 | 63 | assert(p >= _reserved.start(), "just checking"); |
aoqi@0 | 64 | size_t delta = pointer_delta(p, _reserved.start()); |
aoqi@0 | 65 | return (delta & right_n_bits(LogN_words)) == (size_t)NoBits; |
aoqi@0 | 66 | } |
aoqi@0 | 67 | |
aoqi@0 | 68 | ////////////////////////////////////////////////////////////////////// |
aoqi@0 | 69 | // G1BlockOffsetArray |
aoqi@0 | 70 | ////////////////////////////////////////////////////////////////////// |
aoqi@0 | 71 | |
aoqi@0 | 72 | G1BlockOffsetArray::G1BlockOffsetArray(G1BlockOffsetSharedArray* array, |
brutisso@7256 | 73 | MemRegion mr) : |
aoqi@0 | 74 | G1BlockOffsetTable(mr.start(), mr.end()), |
aoqi@0 | 75 | _unallocated_block(_bottom), |
brutisso@7256 | 76 | _array(array), _gsp(NULL) { |
aoqi@0 | 77 | assert(_bottom <= _end, "arguments out of order"); |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
mgerdin@6987 | 80 | void G1BlockOffsetArray::set_space(G1OffsetTableContigSpace* sp) { |
mgerdin@6987 | 81 | _gsp = sp; |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | // The arguments follow the normal convention of denoting |
aoqi@0 | 85 | // a right-open interval: [start, end) |
aoqi@0 | 86 | void |
aoqi@0 | 87 | G1BlockOffsetArray:: set_remainder_to_point_to_start(HeapWord* start, HeapWord* end) { |
aoqi@0 | 88 | |
aoqi@0 | 89 | if (start >= end) { |
aoqi@0 | 90 | // The start address is equal to the end address (or to |
aoqi@0 | 91 | // the right of the end address) so there are not cards |
aoqi@0 | 92 | // that need to be updated.. |
aoqi@0 | 93 | return; |
aoqi@0 | 94 | } |
aoqi@0 | 95 | |
aoqi@0 | 96 | // Write the backskip value for each region. |
aoqi@0 | 97 | // |
aoqi@0 | 98 | // offset |
aoqi@0 | 99 | // card 2nd 3rd |
aoqi@0 | 100 | // | +- 1st | | |
aoqi@0 | 101 | // v v v v |
aoqi@0 | 102 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+- |
aoqi@0 | 103 | // |x|0|0|0|0|0|0|0|1|1|1|1|1|1| ... |1|1|1|1|2|2|2|2|2|2| ... |
aoqi@0 | 104 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+- |
aoqi@0 | 105 | // 11 19 75 |
aoqi@0 | 106 | // 12 |
aoqi@0 | 107 | // |
aoqi@0 | 108 | // offset card is the card that points to the start of an object |
aoqi@0 | 109 | // x - offset value of offset card |
aoqi@0 | 110 | // 1st - start of first logarithmic region |
aoqi@0 | 111 | // 0 corresponds to logarithmic value N_words + 0 and 2**(3 * 0) = 1 |
aoqi@0 | 112 | // 2nd - start of second logarithmic region |
aoqi@0 | 113 | // 1 corresponds to logarithmic value N_words + 1 and 2**(3 * 1) = 8 |
aoqi@0 | 114 | // 3rd - start of third logarithmic region |
aoqi@0 | 115 | // 2 corresponds to logarithmic value N_words + 2 and 2**(3 * 2) = 64 |
aoqi@0 | 116 | // |
aoqi@0 | 117 | // integer below the block offset entry is an example of |
aoqi@0 | 118 | // the index of the entry |
aoqi@0 | 119 | // |
aoqi@0 | 120 | // Given an address, |
aoqi@0 | 121 | // Find the index for the address |
aoqi@0 | 122 | // Find the block offset table entry |
aoqi@0 | 123 | // Convert the entry to a back slide |
aoqi@0 | 124 | // (e.g., with today's, offset = 0x81 => |
aoqi@0 | 125 | // back slip = 2**(3*(0x81 - N_words)) = 2**3) = 8 |
aoqi@0 | 126 | // Move back N (e.g., 8) entries and repeat with the |
aoqi@0 | 127 | // value of the new entry |
aoqi@0 | 128 | // |
aoqi@0 | 129 | size_t start_card = _array->index_for(start); |
aoqi@0 | 130 | size_t end_card = _array->index_for(end-1); |
aoqi@0 | 131 | assert(start ==_array->address_for_index(start_card), "Precondition"); |
aoqi@0 | 132 | assert(end ==_array->address_for_index(end_card)+N_words, "Precondition"); |
aoqi@0 | 133 | set_remainder_to_point_to_start_incl(start_card, end_card); // closed interval |
aoqi@0 | 134 | } |
aoqi@0 | 135 | |
aoqi@0 | 136 | // Unlike the normal convention in this code, the argument here denotes |
aoqi@0 | 137 | // a closed, inclusive interval: [start_card, end_card], cf set_remainder_to_point_to_start() |
aoqi@0 | 138 | // above. |
aoqi@0 | 139 | void |
aoqi@0 | 140 | G1BlockOffsetArray::set_remainder_to_point_to_start_incl(size_t start_card, size_t end_card) { |
aoqi@0 | 141 | if (start_card > end_card) { |
aoqi@0 | 142 | return; |
aoqi@0 | 143 | } |
aoqi@0 | 144 | assert(start_card > _array->index_for(_bottom), "Cannot be first card"); |
aoqi@0 | 145 | assert(_array->offset_array(start_card-1) <= N_words, |
aoqi@0 | 146 | "Offset card has an unexpected value"); |
aoqi@0 | 147 | size_t start_card_for_region = start_card; |
aoqi@0 | 148 | u_char offset = max_jubyte; |
aoqi@0 | 149 | for (int i = 0; i < BlockOffsetArray::N_powers; i++) { |
aoqi@0 | 150 | // -1 so that the the card with the actual offset is counted. Another -1 |
aoqi@0 | 151 | // so that the reach ends in this region and not at the start |
aoqi@0 | 152 | // of the next. |
aoqi@0 | 153 | size_t reach = start_card - 1 + (BlockOffsetArray::power_to_cards_back(i+1) - 1); |
aoqi@0 | 154 | offset = N_words + i; |
aoqi@0 | 155 | if (reach >= end_card) { |
aoqi@0 | 156 | _array->set_offset_array(start_card_for_region, end_card, offset); |
aoqi@0 | 157 | start_card_for_region = reach + 1; |
aoqi@0 | 158 | break; |
aoqi@0 | 159 | } |
aoqi@0 | 160 | _array->set_offset_array(start_card_for_region, reach, offset); |
aoqi@0 | 161 | start_card_for_region = reach + 1; |
aoqi@0 | 162 | } |
aoqi@0 | 163 | assert(start_card_for_region > end_card, "Sanity check"); |
aoqi@0 | 164 | DEBUG_ONLY(check_all_cards(start_card, end_card);) |
aoqi@0 | 165 | } |
aoqi@0 | 166 | |
aoqi@0 | 167 | // The card-interval [start_card, end_card] is a closed interval; this |
aoqi@0 | 168 | // is an expensive check -- use with care and only under protection of |
aoqi@0 | 169 | // suitable flag. |
aoqi@0 | 170 | void G1BlockOffsetArray::check_all_cards(size_t start_card, size_t end_card) const { |
aoqi@0 | 171 | |
aoqi@0 | 172 | if (end_card < start_card) { |
aoqi@0 | 173 | return; |
aoqi@0 | 174 | } |
aoqi@0 | 175 | guarantee(_array->offset_array(start_card) == N_words, "Wrong value in second card"); |
aoqi@0 | 176 | for (size_t c = start_card + 1; c <= end_card; c++ /* yeah! */) { |
aoqi@0 | 177 | u_char entry = _array->offset_array(c); |
aoqi@0 | 178 | if (c - start_card > BlockOffsetArray::power_to_cards_back(1)) { |
aoqi@0 | 179 | guarantee(entry > N_words, |
aoqi@0 | 180 | err_msg("Should be in logarithmic region - " |
aoqi@0 | 181 | "entry: " UINT32_FORMAT ", " |
aoqi@0 | 182 | "_array->offset_array(c): " UINT32_FORMAT ", " |
aoqi@0 | 183 | "N_words: " UINT32_FORMAT, |
aoqi@0 | 184 | entry, _array->offset_array(c), N_words)); |
aoqi@0 | 185 | } |
aoqi@0 | 186 | size_t backskip = BlockOffsetArray::entry_to_cards_back(entry); |
aoqi@0 | 187 | size_t landing_card = c - backskip; |
aoqi@0 | 188 | guarantee(landing_card >= (start_card - 1), "Inv"); |
aoqi@0 | 189 | if (landing_card >= start_card) { |
aoqi@0 | 190 | guarantee(_array->offset_array(landing_card) <= entry, |
aoqi@0 | 191 | err_msg("Monotonicity - landing_card offset: " UINT32_FORMAT ", " |
aoqi@0 | 192 | "entry: " UINT32_FORMAT, |
aoqi@0 | 193 | _array->offset_array(landing_card), entry)); |
aoqi@0 | 194 | } else { |
aoqi@0 | 195 | guarantee(landing_card == start_card - 1, "Tautology"); |
aoqi@0 | 196 | // Note that N_words is the maximum offset value |
aoqi@0 | 197 | guarantee(_array->offset_array(landing_card) <= N_words, |
aoqi@0 | 198 | err_msg("landing card offset: " UINT32_FORMAT ", " |
aoqi@0 | 199 | "N_words: " UINT32_FORMAT, |
aoqi@0 | 200 | _array->offset_array(landing_card), N_words)); |
aoqi@0 | 201 | } |
aoqi@0 | 202 | } |
aoqi@0 | 203 | } |
aoqi@0 | 204 | |
aoqi@0 | 205 | HeapWord* G1BlockOffsetArray::block_start_unsafe(const void* addr) { |
aoqi@0 | 206 | assert(_bottom <= addr && addr < _end, |
aoqi@0 | 207 | "addr must be covered by this Array"); |
aoqi@0 | 208 | // Must read this exactly once because it can be modified by parallel |
aoqi@0 | 209 | // allocation. |
aoqi@0 | 210 | HeapWord* ub = _unallocated_block; |
aoqi@0 | 211 | if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) { |
aoqi@0 | 212 | assert(ub < _end, "tautology (see above)"); |
aoqi@0 | 213 | return ub; |
aoqi@0 | 214 | } |
aoqi@0 | 215 | // Otherwise, find the block start using the table. |
aoqi@0 | 216 | HeapWord* q = block_at_or_preceding(addr, false, 0); |
aoqi@0 | 217 | return forward_to_block_containing_addr(q, addr); |
aoqi@0 | 218 | } |
aoqi@0 | 219 | |
aoqi@0 | 220 | // This duplicates a little code from the above: unavoidable. |
aoqi@0 | 221 | HeapWord* |
aoqi@0 | 222 | G1BlockOffsetArray::block_start_unsafe_const(const void* addr) const { |
aoqi@0 | 223 | assert(_bottom <= addr && addr < _end, |
aoqi@0 | 224 | "addr must be covered by this Array"); |
aoqi@0 | 225 | // Must read this exactly once because it can be modified by parallel |
aoqi@0 | 226 | // allocation. |
aoqi@0 | 227 | HeapWord* ub = _unallocated_block; |
aoqi@0 | 228 | if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) { |
aoqi@0 | 229 | assert(ub < _end, "tautology (see above)"); |
aoqi@0 | 230 | return ub; |
aoqi@0 | 231 | } |
aoqi@0 | 232 | // Otherwise, find the block start using the table. |
aoqi@0 | 233 | HeapWord* q = block_at_or_preceding(addr, false, 0); |
mgerdin@6987 | 234 | HeapWord* n = q + block_size(q); |
aoqi@0 | 235 | return forward_to_block_containing_addr_const(q, n, addr); |
aoqi@0 | 236 | } |
aoqi@0 | 237 | |
aoqi@0 | 238 | |
aoqi@0 | 239 | HeapWord* |
aoqi@0 | 240 | G1BlockOffsetArray::forward_to_block_containing_addr_slow(HeapWord* q, |
aoqi@0 | 241 | HeapWord* n, |
aoqi@0 | 242 | const void* addr) { |
aoqi@0 | 243 | // We're not in the normal case. We need to handle an important subcase |
aoqi@0 | 244 | // here: LAB allocation. An allocation previously recorded in the |
aoqi@0 | 245 | // offset table was actually a lab allocation, and was divided into |
aoqi@0 | 246 | // several objects subsequently. Fix this situation as we answer the |
aoqi@0 | 247 | // query, by updating entries as we cross them. |
aoqi@0 | 248 | |
aoqi@0 | 249 | // If the fist object's end q is at the card boundary. Start refining |
aoqi@0 | 250 | // with the corresponding card (the value of the entry will be basically |
aoqi@0 | 251 | // set to 0). If the object crosses the boundary -- start from the next card. |
aoqi@0 | 252 | size_t n_index = _array->index_for(n); |
aoqi@0 | 253 | size_t next_index = _array->index_for(n) + !_array->is_card_boundary(n); |
aoqi@0 | 254 | // Calculate a consistent next boundary. If "n" is not at the boundary |
aoqi@0 | 255 | // already, step to the boundary. |
aoqi@0 | 256 | HeapWord* next_boundary = _array->address_for_index(n_index) + |
aoqi@0 | 257 | (n_index == next_index ? 0 : N_words); |
aoqi@0 | 258 | assert(next_boundary <= _array->_end, |
aoqi@0 | 259 | err_msg("next_boundary is beyond the end of the covered region " |
aoqi@0 | 260 | " next_boundary " PTR_FORMAT " _array->_end " PTR_FORMAT, |
aoqi@0 | 261 | next_boundary, _array->_end)); |
mgerdin@6987 | 262 | if (addr >= gsp()->top()) return gsp()->top(); |
mgerdin@6987 | 263 | while (next_boundary < addr) { |
mgerdin@6987 | 264 | while (n <= next_boundary) { |
mgerdin@6987 | 265 | q = n; |
mgerdin@6987 | 266 | oop obj = oop(q); |
mgerdin@6987 | 267 | if (obj->klass_or_null() == NULL) return q; |
stefank@6992 | 268 | n += block_size(q); |
aoqi@0 | 269 | } |
mgerdin@6987 | 270 | assert(q <= next_boundary && n > next_boundary, "Consequence of loop"); |
mgerdin@6987 | 271 | // [q, n) is the block that crosses the boundary. |
mgerdin@6987 | 272 | alloc_block_work2(&next_boundary, &next_index, q, n); |
aoqi@0 | 273 | } |
aoqi@0 | 274 | return forward_to_block_containing_addr_const(q, n, addr); |
aoqi@0 | 275 | } |
aoqi@0 | 276 | |
aoqi@0 | 277 | // Note that the committed size of the covered space may have changed, |
aoqi@0 | 278 | // so the table size might also wish to change. |
aoqi@0 | 279 | void G1BlockOffsetArray::resize(size_t new_word_size) { |
aoqi@0 | 280 | HeapWord* new_end = _bottom + new_word_size; |
aoqi@0 | 281 | _end = new_end; // update _end |
aoqi@0 | 282 | } |
aoqi@0 | 283 | |
aoqi@0 | 284 | // |
aoqi@0 | 285 | // threshold_ |
aoqi@0 | 286 | // | _index_ |
aoqi@0 | 287 | // v v |
aoqi@0 | 288 | // +-------+-------+-------+-------+-------+ |
aoqi@0 | 289 | // | i-1 | i | i+1 | i+2 | i+3 | |
aoqi@0 | 290 | // +-------+-------+-------+-------+-------+ |
aoqi@0 | 291 | // ( ^ ] |
aoqi@0 | 292 | // block-start |
aoqi@0 | 293 | // |
aoqi@0 | 294 | void G1BlockOffsetArray::alloc_block_work2(HeapWord** threshold_, size_t* index_, |
aoqi@0 | 295 | HeapWord* blk_start, HeapWord* blk_end) { |
aoqi@0 | 296 | // For efficiency, do copy-in/copy-out. |
aoqi@0 | 297 | HeapWord* threshold = *threshold_; |
aoqi@0 | 298 | size_t index = *index_; |
aoqi@0 | 299 | |
aoqi@0 | 300 | assert(blk_start != NULL && blk_end > blk_start, |
aoqi@0 | 301 | "phantom block"); |
aoqi@0 | 302 | assert(blk_end > threshold, "should be past threshold"); |
aoqi@0 | 303 | assert(blk_start <= threshold, "blk_start should be at or before threshold"); |
aoqi@0 | 304 | assert(pointer_delta(threshold, blk_start) <= N_words, |
aoqi@0 | 305 | "offset should be <= BlockOffsetSharedArray::N"); |
aoqi@0 | 306 | assert(Universe::heap()->is_in_reserved(blk_start), |
aoqi@0 | 307 | "reference must be into the heap"); |
aoqi@0 | 308 | assert(Universe::heap()->is_in_reserved(blk_end-1), |
aoqi@0 | 309 | "limit must be within the heap"); |
aoqi@0 | 310 | assert(threshold == _array->_reserved.start() + index*N_words, |
aoqi@0 | 311 | "index must agree with threshold"); |
aoqi@0 | 312 | |
aoqi@0 | 313 | DEBUG_ONLY(size_t orig_index = index;) |
aoqi@0 | 314 | |
aoqi@0 | 315 | // Mark the card that holds the offset into the block. Note |
aoqi@0 | 316 | // that _next_offset_index and _next_offset_threshold are not |
aoqi@0 | 317 | // updated until the end of this method. |
aoqi@0 | 318 | _array->set_offset_array(index, threshold, blk_start); |
aoqi@0 | 319 | |
aoqi@0 | 320 | // We need to now mark the subsequent cards that this blk spans. |
aoqi@0 | 321 | |
aoqi@0 | 322 | // Index of card on which blk ends. |
aoqi@0 | 323 | size_t end_index = _array->index_for(blk_end - 1); |
aoqi@0 | 324 | |
aoqi@0 | 325 | // Are there more cards left to be updated? |
aoqi@0 | 326 | if (index + 1 <= end_index) { |
aoqi@0 | 327 | HeapWord* rem_st = _array->address_for_index(index + 1); |
aoqi@0 | 328 | // Calculate rem_end this way because end_index |
aoqi@0 | 329 | // may be the last valid index in the covered region. |
aoqi@0 | 330 | HeapWord* rem_end = _array->address_for_index(end_index) + N_words; |
aoqi@0 | 331 | set_remainder_to_point_to_start(rem_st, rem_end); |
aoqi@0 | 332 | } |
aoqi@0 | 333 | |
aoqi@0 | 334 | index = end_index + 1; |
aoqi@0 | 335 | // Calculate threshold_ this way because end_index |
aoqi@0 | 336 | // may be the last valid index in the covered region. |
aoqi@0 | 337 | threshold = _array->address_for_index(end_index) + N_words; |
aoqi@0 | 338 | assert(threshold >= blk_end, "Incorrect offset threshold"); |
aoqi@0 | 339 | |
aoqi@0 | 340 | // index_ and threshold_ updated here. |
aoqi@0 | 341 | *threshold_ = threshold; |
aoqi@0 | 342 | *index_ = index; |
aoqi@0 | 343 | |
aoqi@0 | 344 | #ifdef ASSERT |
aoqi@0 | 345 | // The offset can be 0 if the block starts on a boundary. That |
aoqi@0 | 346 | // is checked by an assertion above. |
aoqi@0 | 347 | size_t start_index = _array->index_for(blk_start); |
aoqi@0 | 348 | HeapWord* boundary = _array->address_for_index(start_index); |
aoqi@0 | 349 | assert((_array->offset_array(orig_index) == 0 && |
aoqi@0 | 350 | blk_start == boundary) || |
aoqi@0 | 351 | (_array->offset_array(orig_index) > 0 && |
aoqi@0 | 352 | _array->offset_array(orig_index) <= N_words), |
aoqi@0 | 353 | err_msg("offset array should have been set - " |
aoqi@0 | 354 | "orig_index offset: " UINT32_FORMAT ", " |
aoqi@0 | 355 | "blk_start: " PTR_FORMAT ", " |
aoqi@0 | 356 | "boundary: " PTR_FORMAT, |
aoqi@0 | 357 | _array->offset_array(orig_index), |
aoqi@0 | 358 | blk_start, boundary)); |
aoqi@0 | 359 | for (size_t j = orig_index + 1; j <= end_index; j++) { |
aoqi@0 | 360 | assert(_array->offset_array(j) > 0 && |
aoqi@0 | 361 | _array->offset_array(j) <= |
aoqi@0 | 362 | (u_char) (N_words+BlockOffsetArray::N_powers-1), |
aoqi@0 | 363 | err_msg("offset array should have been set - " |
aoqi@0 | 364 | UINT32_FORMAT " not > 0 OR " |
aoqi@0 | 365 | UINT32_FORMAT " not <= " UINT32_FORMAT, |
aoqi@0 | 366 | _array->offset_array(j), |
aoqi@0 | 367 | _array->offset_array(j), |
aoqi@0 | 368 | (u_char) (N_words+BlockOffsetArray::N_powers-1))); |
aoqi@0 | 369 | } |
aoqi@0 | 370 | #endif |
aoqi@0 | 371 | } |
aoqi@0 | 372 | |
aoqi@0 | 373 | bool |
aoqi@0 | 374 | G1BlockOffsetArray::verify_for_object(HeapWord* obj_start, |
aoqi@0 | 375 | size_t word_size) const { |
aoqi@0 | 376 | size_t first_card = _array->index_for(obj_start); |
aoqi@0 | 377 | size_t last_card = _array->index_for(obj_start + word_size - 1); |
aoqi@0 | 378 | if (!_array->is_card_boundary(obj_start)) { |
aoqi@0 | 379 | // If the object is not on a card boundary the BOT entry of the |
aoqi@0 | 380 | // first card should point to another object so we should not |
aoqi@0 | 381 | // check that one. |
aoqi@0 | 382 | first_card += 1; |
aoqi@0 | 383 | } |
aoqi@0 | 384 | for (size_t card = first_card; card <= last_card; card += 1) { |
aoqi@0 | 385 | HeapWord* card_addr = _array->address_for_index(card); |
aoqi@0 | 386 | HeapWord* block_start = block_start_const(card_addr); |
aoqi@0 | 387 | if (block_start != obj_start) { |
aoqi@0 | 388 | gclog_or_tty->print_cr("block start: "PTR_FORMAT" is incorrect - " |
aoqi@0 | 389 | "card index: "SIZE_FORMAT" " |
aoqi@0 | 390 | "card addr: "PTR_FORMAT" BOT entry: %u " |
aoqi@0 | 391 | "obj: "PTR_FORMAT" word size: "SIZE_FORMAT" " |
aoqi@0 | 392 | "cards: ["SIZE_FORMAT","SIZE_FORMAT"]", |
aoqi@0 | 393 | block_start, card, card_addr, |
aoqi@0 | 394 | _array->offset_array(card), |
aoqi@0 | 395 | obj_start, word_size, first_card, last_card); |
aoqi@0 | 396 | return false; |
aoqi@0 | 397 | } |
aoqi@0 | 398 | } |
aoqi@0 | 399 | return true; |
aoqi@0 | 400 | } |
aoqi@0 | 401 | |
aoqi@0 | 402 | #ifndef PRODUCT |
aoqi@0 | 403 | void |
aoqi@0 | 404 | G1BlockOffsetArray::print_on(outputStream* out) { |
aoqi@0 | 405 | size_t from_index = _array->index_for(_bottom); |
aoqi@0 | 406 | size_t to_index = _array->index_for(_end); |
aoqi@0 | 407 | out->print_cr(">> BOT for area ["PTR_FORMAT","PTR_FORMAT") " |
aoqi@0 | 408 | "cards ["SIZE_FORMAT","SIZE_FORMAT")", |
aoqi@0 | 409 | _bottom, _end, from_index, to_index); |
aoqi@0 | 410 | for (size_t i = from_index; i < to_index; ++i) { |
aoqi@0 | 411 | out->print_cr(" entry "SIZE_FORMAT_W(8)" | "PTR_FORMAT" : %3u", |
aoqi@0 | 412 | i, _array->address_for_index(i), |
aoqi@0 | 413 | (uint) _array->offset_array(i)); |
aoqi@0 | 414 | } |
aoqi@0 | 415 | } |
aoqi@0 | 416 | #endif // !PRODUCT |
aoqi@0 | 417 | |
aoqi@0 | 418 | ////////////////////////////////////////////////////////////////////// |
aoqi@0 | 419 | // G1BlockOffsetArrayContigSpace |
aoqi@0 | 420 | ////////////////////////////////////////////////////////////////////// |
aoqi@0 | 421 | |
aoqi@0 | 422 | HeapWord* |
aoqi@0 | 423 | G1BlockOffsetArrayContigSpace::block_start_unsafe(const void* addr) { |
aoqi@0 | 424 | assert(_bottom <= addr && addr < _end, |
aoqi@0 | 425 | "addr must be covered by this Array"); |
aoqi@0 | 426 | HeapWord* q = block_at_or_preceding(addr, true, _next_offset_index-1); |
aoqi@0 | 427 | return forward_to_block_containing_addr(q, addr); |
aoqi@0 | 428 | } |
aoqi@0 | 429 | |
aoqi@0 | 430 | HeapWord* |
aoqi@0 | 431 | G1BlockOffsetArrayContigSpace:: |
aoqi@0 | 432 | block_start_unsafe_const(const void* addr) const { |
aoqi@0 | 433 | assert(_bottom <= addr && addr < _end, |
aoqi@0 | 434 | "addr must be covered by this Array"); |
aoqi@0 | 435 | HeapWord* q = block_at_or_preceding(addr, true, _next_offset_index-1); |
mgerdin@6987 | 436 | HeapWord* n = q + block_size(q); |
aoqi@0 | 437 | return forward_to_block_containing_addr_const(q, n, addr); |
aoqi@0 | 438 | } |
aoqi@0 | 439 | |
aoqi@0 | 440 | G1BlockOffsetArrayContigSpace:: |
aoqi@0 | 441 | G1BlockOffsetArrayContigSpace(G1BlockOffsetSharedArray* array, |
aoqi@0 | 442 | MemRegion mr) : |
brutisso@7256 | 443 | G1BlockOffsetArray(array, mr) |
aoqi@0 | 444 | { |
aoqi@0 | 445 | _next_offset_threshold = NULL; |
aoqi@0 | 446 | _next_offset_index = 0; |
aoqi@0 | 447 | } |
aoqi@0 | 448 | |
tschatzl@7051 | 449 | HeapWord* G1BlockOffsetArrayContigSpace::initialize_threshold_raw() { |
tschatzl@7051 | 450 | assert(!Universe::heap()->is_in_reserved(_array->_offset_array), |
tschatzl@7051 | 451 | "just checking"); |
tschatzl@7051 | 452 | _next_offset_index = _array->index_for_raw(_bottom); |
tschatzl@7051 | 453 | _next_offset_index++; |
tschatzl@7051 | 454 | _next_offset_threshold = |
tschatzl@7051 | 455 | _array->address_for_index_raw(_next_offset_index); |
tschatzl@7051 | 456 | return _next_offset_threshold; |
tschatzl@7051 | 457 | } |
tschatzl@7051 | 458 | |
tschatzl@7051 | 459 | void G1BlockOffsetArrayContigSpace::zero_bottom_entry_raw() { |
tschatzl@7051 | 460 | assert(!Universe::heap()->is_in_reserved(_array->_offset_array), |
tschatzl@7051 | 461 | "just checking"); |
tschatzl@7051 | 462 | size_t bottom_index = _array->index_for_raw(_bottom); |
tschatzl@7051 | 463 | assert(_array->address_for_index_raw(bottom_index) == _bottom, |
tschatzl@7051 | 464 | "Precondition of call"); |
tschatzl@7051 | 465 | _array->set_offset_array_raw(bottom_index, 0); |
tschatzl@7051 | 466 | } |
tschatzl@7051 | 467 | |
aoqi@0 | 468 | HeapWord* G1BlockOffsetArrayContigSpace::initialize_threshold() { |
aoqi@0 | 469 | assert(!Universe::heap()->is_in_reserved(_array->_offset_array), |
aoqi@0 | 470 | "just checking"); |
aoqi@0 | 471 | _next_offset_index = _array->index_for(_bottom); |
aoqi@0 | 472 | _next_offset_index++; |
aoqi@0 | 473 | _next_offset_threshold = |
aoqi@0 | 474 | _array->address_for_index(_next_offset_index); |
aoqi@0 | 475 | return _next_offset_threshold; |
aoqi@0 | 476 | } |
aoqi@0 | 477 | |
aoqi@0 | 478 | void |
aoqi@0 | 479 | G1BlockOffsetArrayContigSpace::set_for_starts_humongous(HeapWord* new_top) { |
aoqi@0 | 480 | assert(new_top <= _end, "_end should have already been updated"); |
aoqi@0 | 481 | |
aoqi@0 | 482 | // The first BOT entry should have offset 0. |
tschatzl@7050 | 483 | reset_bot(); |
aoqi@0 | 484 | alloc_block(_bottom, new_top); |
aoqi@0 | 485 | } |
aoqi@0 | 486 | |
aoqi@0 | 487 | #ifndef PRODUCT |
aoqi@0 | 488 | void |
aoqi@0 | 489 | G1BlockOffsetArrayContigSpace::print_on(outputStream* out) { |
aoqi@0 | 490 | G1BlockOffsetArray::print_on(out); |
aoqi@0 | 491 | out->print_cr(" next offset threshold: "PTR_FORMAT, _next_offset_threshold); |
aoqi@0 | 492 | out->print_cr(" next offset index: "SIZE_FORMAT, _next_offset_index); |
aoqi@0 | 493 | } |
aoqi@0 | 494 | #endif // !PRODUCT |