src/share/vm/memory/blockOffsetTable.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 4061
859cd1a76f8a
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2012, 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 #ifndef SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP
aoqi@0 26 #define SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP
aoqi@0 27
aoqi@0 28 #include "memory/memRegion.hpp"
aoqi@0 29 #include "runtime/virtualspace.hpp"
aoqi@0 30 #include "utilities/globalDefinitions.hpp"
aoqi@0 31
aoqi@0 32 // The CollectedHeap type requires subtypes to implement a method
aoqi@0 33 // "block_start". For some subtypes, notably generational
aoqi@0 34 // systems using card-table-based write barriers, the efficiency of this
aoqi@0 35 // operation may be important. Implementations of the "BlockOffsetArray"
aoqi@0 36 // class may be useful in providing such efficient implementations.
aoqi@0 37 //
aoqi@0 38 // BlockOffsetTable (abstract)
aoqi@0 39 // - BlockOffsetArray (abstract)
aoqi@0 40 // - BlockOffsetArrayNonContigSpace
aoqi@0 41 // - BlockOffsetArrayContigSpace
aoqi@0 42 //
aoqi@0 43
aoqi@0 44 class ContiguousSpace;
aoqi@0 45
aoqi@0 46 //////////////////////////////////////////////////////////////////////////
aoqi@0 47 // The BlockOffsetTable "interface"
aoqi@0 48 //////////////////////////////////////////////////////////////////////////
aoqi@0 49 class BlockOffsetTable VALUE_OBJ_CLASS_SPEC {
aoqi@0 50 friend class VMStructs;
aoqi@0 51 protected:
aoqi@0 52 // These members describe the region covered by the table.
aoqi@0 53
aoqi@0 54 // The space this table is covering.
aoqi@0 55 HeapWord* _bottom; // == reserved.start
aoqi@0 56 HeapWord* _end; // End of currently allocated region.
aoqi@0 57
aoqi@0 58 public:
aoqi@0 59 // Initialize the table to cover the given space.
aoqi@0 60 // The contents of the initial table are undefined.
aoqi@0 61 BlockOffsetTable(HeapWord* bottom, HeapWord* end):
aoqi@0 62 _bottom(bottom), _end(end) {
aoqi@0 63 assert(_bottom <= _end, "arguments out of order");
aoqi@0 64 }
aoqi@0 65
aoqi@0 66 // Note that the committed size of the covered space may have changed,
aoqi@0 67 // so the table size might also wish to change.
aoqi@0 68 virtual void resize(size_t new_word_size) = 0;
aoqi@0 69
aoqi@0 70 virtual void set_bottom(HeapWord* new_bottom) {
aoqi@0 71 assert(new_bottom <= _end, "new_bottom > _end");
aoqi@0 72 _bottom = new_bottom;
aoqi@0 73 resize(pointer_delta(_end, _bottom));
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 // Requires "addr" to be contained by a block, and returns the address of
aoqi@0 77 // the start of that block.
aoqi@0 78 virtual HeapWord* block_start_unsafe(const void* addr) const = 0;
aoqi@0 79
aoqi@0 80 // Returns the address of the start of the block containing "addr", or
aoqi@0 81 // else "null" if it is covered by no block.
aoqi@0 82 HeapWord* block_start(const void* addr) const;
aoqi@0 83 };
aoqi@0 84
aoqi@0 85 //////////////////////////////////////////////////////////////////////////
aoqi@0 86 // One implementation of "BlockOffsetTable," the BlockOffsetArray,
aoqi@0 87 // divides the covered region into "N"-word subregions (where
aoqi@0 88 // "N" = 2^"LogN". An array with an entry for each such subregion
aoqi@0 89 // indicates how far back one must go to find the start of the
aoqi@0 90 // chunk that includes the first word of the subregion.
aoqi@0 91 //
aoqi@0 92 // Each BlockOffsetArray is owned by a Space. However, the actual array
aoqi@0 93 // may be shared by several BlockOffsetArrays; this is useful
aoqi@0 94 // when a single resizable area (such as a generation) is divided up into
aoqi@0 95 // several spaces in which contiguous allocation takes place. (Consider,
aoqi@0 96 // for example, the garbage-first generation.)
aoqi@0 97
aoqi@0 98 // Here is the shared array type.
aoqi@0 99 //////////////////////////////////////////////////////////////////////////
aoqi@0 100 // BlockOffsetSharedArray
aoqi@0 101 //////////////////////////////////////////////////////////////////////////
aoqi@0 102 class BlockOffsetSharedArray: public CHeapObj<mtGC> {
aoqi@0 103 friend class BlockOffsetArray;
aoqi@0 104 friend class BlockOffsetArrayNonContigSpace;
aoqi@0 105 friend class BlockOffsetArrayContigSpace;
aoqi@0 106 friend class VMStructs;
aoqi@0 107
aoqi@0 108 private:
aoqi@0 109 enum SomePrivateConstants {
aoqi@0 110 LogN = 9,
aoqi@0 111 LogN_words = LogN - LogHeapWordSize,
aoqi@0 112 N_bytes = 1 << LogN,
aoqi@0 113 N_words = 1 << LogN_words
aoqi@0 114 };
aoqi@0 115
aoqi@0 116 bool _init_to_zero;
aoqi@0 117
aoqi@0 118 // The reserved region covered by the shared array.
aoqi@0 119 MemRegion _reserved;
aoqi@0 120
aoqi@0 121 // End of the current committed region.
aoqi@0 122 HeapWord* _end;
aoqi@0 123
aoqi@0 124 // Array for keeping offsets for retrieving object start fast given an
aoqi@0 125 // address.
aoqi@0 126 VirtualSpace _vs;
aoqi@0 127 u_char* _offset_array; // byte array keeping backwards offsets
aoqi@0 128
aoqi@0 129 protected:
aoqi@0 130 // Bounds checking accessors:
aoqi@0 131 // For performance these have to devolve to array accesses in product builds.
aoqi@0 132 u_char offset_array(size_t index) const {
aoqi@0 133 assert(index < _vs.committed_size(), "index out of range");
aoqi@0 134 return _offset_array[index];
aoqi@0 135 }
aoqi@0 136 // An assertion-checking helper method for the set_offset_array() methods below.
aoqi@0 137 void check_reducing_assertion(bool reducing);
aoqi@0 138
aoqi@0 139 void set_offset_array(size_t index, u_char offset, bool reducing = false) {
aoqi@0 140 check_reducing_assertion(reducing);
aoqi@0 141 assert(index < _vs.committed_size(), "index out of range");
aoqi@0 142 assert(!reducing || _offset_array[index] >= offset, "Not reducing");
aoqi@0 143 _offset_array[index] = offset;
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 void set_offset_array(size_t index, HeapWord* high, HeapWord* low, bool reducing = false) {
aoqi@0 147 check_reducing_assertion(reducing);
aoqi@0 148 assert(index < _vs.committed_size(), "index out of range");
aoqi@0 149 assert(high >= low, "addresses out of order");
aoqi@0 150 assert(pointer_delta(high, low) <= N_words, "offset too large");
aoqi@0 151 assert(!reducing || _offset_array[index] >= (u_char)pointer_delta(high, low),
aoqi@0 152 "Not reducing");
aoqi@0 153 _offset_array[index] = (u_char)pointer_delta(high, low);
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 void set_offset_array(HeapWord* left, HeapWord* right, u_char offset, bool reducing = false) {
aoqi@0 157 check_reducing_assertion(reducing);
aoqi@0 158 assert(index_for(right - 1) < _vs.committed_size(),
aoqi@0 159 "right address out of range");
aoqi@0 160 assert(left < right, "Heap addresses out of order");
aoqi@0 161 size_t num_cards = pointer_delta(right, left) >> LogN_words;
aoqi@0 162
aoqi@0 163 // Below, we may use an explicit loop instead of memset()
aoqi@0 164 // because on certain platforms memset() can give concurrent
aoqi@0 165 // readers "out-of-thin-air," phantom zeros; see 6948537.
aoqi@0 166 if (UseMemSetInBOT) {
aoqi@0 167 memset(&_offset_array[index_for(left)], offset, num_cards);
aoqi@0 168 } else {
aoqi@0 169 size_t i = index_for(left);
aoqi@0 170 const size_t end = i + num_cards;
aoqi@0 171 for (; i < end; i++) {
aoqi@0 172 // Elided until CR 6977974 is fixed properly.
aoqi@0 173 // assert(!reducing || _offset_array[i] >= offset, "Not reducing");
aoqi@0 174 _offset_array[i] = offset;
aoqi@0 175 }
aoqi@0 176 }
aoqi@0 177 }
aoqi@0 178
aoqi@0 179 void set_offset_array(size_t left, size_t right, u_char offset, bool reducing = false) {
aoqi@0 180 check_reducing_assertion(reducing);
aoqi@0 181 assert(right < _vs.committed_size(), "right address out of range");
aoqi@0 182 assert(left <= right, "indexes out of order");
aoqi@0 183 size_t num_cards = right - left + 1;
aoqi@0 184
aoqi@0 185 // Below, we may use an explicit loop instead of memset
aoqi@0 186 // because on certain platforms memset() can give concurrent
aoqi@0 187 // readers "out-of-thin-air," phantom zeros; see 6948537.
aoqi@0 188 if (UseMemSetInBOT) {
aoqi@0 189 memset(&_offset_array[left], offset, num_cards);
aoqi@0 190 } else {
aoqi@0 191 size_t i = left;
aoqi@0 192 const size_t end = i + num_cards;
aoqi@0 193 for (; i < end; i++) {
aoqi@0 194 // Elided until CR 6977974 is fixed properly.
aoqi@0 195 // assert(!reducing || _offset_array[i] >= offset, "Not reducing");
aoqi@0 196 _offset_array[i] = offset;
aoqi@0 197 }
aoqi@0 198 }
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 void check_offset_array(size_t index, HeapWord* high, HeapWord* low) const {
aoqi@0 202 assert(index < _vs.committed_size(), "index out of range");
aoqi@0 203 assert(high >= low, "addresses out of order");
aoqi@0 204 assert(pointer_delta(high, low) <= N_words, "offset too large");
aoqi@0 205 assert(_offset_array[index] == pointer_delta(high, low),
aoqi@0 206 "Wrong offset");
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 bool is_card_boundary(HeapWord* p) const;
aoqi@0 210
aoqi@0 211 // Return the number of slots needed for an offset array
aoqi@0 212 // that covers mem_region_words words.
aoqi@0 213 // We always add an extra slot because if an object
aoqi@0 214 // ends on a card boundary we put a 0 in the next
aoqi@0 215 // offset array slot, so we want that slot always
aoqi@0 216 // to be reserved.
aoqi@0 217
aoqi@0 218 size_t compute_size(size_t mem_region_words) {
aoqi@0 219 size_t number_of_slots = (mem_region_words / N_words) + 1;
aoqi@0 220 return ReservedSpace::allocation_align_size_up(number_of_slots);
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 public:
aoqi@0 224 // Initialize the table to cover from "base" to (at least)
aoqi@0 225 // "base + init_word_size". In the future, the table may be expanded
aoqi@0 226 // (see "resize" below) up to the size of "_reserved" (which must be at
aoqi@0 227 // least "init_word_size".) The contents of the initial table are
aoqi@0 228 // undefined; it is the responsibility of the constituent
aoqi@0 229 // BlockOffsetTable(s) to initialize cards.
aoqi@0 230 BlockOffsetSharedArray(MemRegion reserved, size_t init_word_size);
aoqi@0 231
aoqi@0 232 // Notes a change in the committed size of the region covered by the
aoqi@0 233 // table. The "new_word_size" may not be larger than the size of the
aoqi@0 234 // reserved region this table covers.
aoqi@0 235 void resize(size_t new_word_size);
aoqi@0 236
aoqi@0 237 void set_bottom(HeapWord* new_bottom);
aoqi@0 238
aoqi@0 239 // Whether entries should be initialized to zero. Used currently only for
aoqi@0 240 // error checking.
aoqi@0 241 void set_init_to_zero(bool val) { _init_to_zero = val; }
aoqi@0 242 bool init_to_zero() { return _init_to_zero; }
aoqi@0 243
aoqi@0 244 // Updates all the BlockOffsetArray's sharing this shared array to
aoqi@0 245 // reflect the current "top"'s of their spaces.
aoqi@0 246 void update_offset_arrays(); // Not yet implemented!
aoqi@0 247
aoqi@0 248 // Return the appropriate index into "_offset_array" for "p".
aoqi@0 249 size_t index_for(const void* p) const;
aoqi@0 250
aoqi@0 251 // Return the address indicating the start of the region corresponding to
aoqi@0 252 // "index" in "_offset_array".
aoqi@0 253 HeapWord* address_for_index(size_t index) const;
aoqi@0 254
aoqi@0 255 // Return the address "p" incremented by the size of
aoqi@0 256 // a region. This method does not align the address
aoqi@0 257 // returned to the start of a region. It is a simple
aoqi@0 258 // primitive.
aoqi@0 259 HeapWord* inc_by_region_size(HeapWord* p) const { return p + N_words; }
aoqi@0 260 };
aoqi@0 261
aoqi@0 262 //////////////////////////////////////////////////////////////////////////
aoqi@0 263 // The BlockOffsetArray whose subtypes use the BlockOffsetSharedArray.
aoqi@0 264 //////////////////////////////////////////////////////////////////////////
aoqi@0 265 class BlockOffsetArray: public BlockOffsetTable {
aoqi@0 266 friend class VMStructs;
aoqi@0 267 friend class G1BlockOffsetArray; // temp. until we restructure and cleanup
aoqi@0 268 protected:
aoqi@0 269 // The following enums are used by do_block_internal() below
aoqi@0 270 enum Action {
aoqi@0 271 Action_single, // BOT records a single block (see single_block())
aoqi@0 272 Action_mark, // BOT marks the start of a block (see mark_block())
aoqi@0 273 Action_check // Check that BOT records block correctly
aoqi@0 274 // (see verify_single_block()).
aoqi@0 275 };
aoqi@0 276
aoqi@0 277 enum SomePrivateConstants {
aoqi@0 278 N_words = BlockOffsetSharedArray::N_words,
aoqi@0 279 LogN = BlockOffsetSharedArray::LogN,
aoqi@0 280 // entries "e" of at least N_words mean "go back by Base^(e-N_words)."
aoqi@0 281 // All entries are less than "N_words + N_powers".
aoqi@0 282 LogBase = 4,
aoqi@0 283 Base = (1 << LogBase),
aoqi@0 284 N_powers = 14
aoqi@0 285 };
aoqi@0 286
aoqi@0 287 static size_t power_to_cards_back(uint i) {
aoqi@0 288 return (size_t)1 << (LogBase * i);
aoqi@0 289 }
aoqi@0 290 static size_t power_to_words_back(uint i) {
aoqi@0 291 return power_to_cards_back(i) * N_words;
aoqi@0 292 }
aoqi@0 293 static size_t entry_to_cards_back(u_char entry) {
aoqi@0 294 assert(entry >= N_words, "Precondition");
aoqi@0 295 return power_to_cards_back(entry - N_words);
aoqi@0 296 }
aoqi@0 297 static size_t entry_to_words_back(u_char entry) {
aoqi@0 298 assert(entry >= N_words, "Precondition");
aoqi@0 299 return power_to_words_back(entry - N_words);
aoqi@0 300 }
aoqi@0 301
aoqi@0 302 // The shared array, which is shared with other BlockOffsetArray's
aoqi@0 303 // corresponding to different spaces within a generation or span of
aoqi@0 304 // memory.
aoqi@0 305 BlockOffsetSharedArray* _array;
aoqi@0 306
aoqi@0 307 // The space that owns this subregion.
aoqi@0 308 Space* _sp;
aoqi@0 309
aoqi@0 310 // If true, array entries are initialized to 0; otherwise, they are
aoqi@0 311 // initialized to point backwards to the beginning of the covered region.
aoqi@0 312 bool _init_to_zero;
aoqi@0 313
aoqi@0 314 // An assertion-checking helper method for the set_remainder*() methods below.
aoqi@0 315 void check_reducing_assertion(bool reducing) { _array->check_reducing_assertion(reducing); }
aoqi@0 316
aoqi@0 317 // Sets the entries
aoqi@0 318 // corresponding to the cards starting at "start" and ending at "end"
aoqi@0 319 // to point back to the card before "start": the interval [start, end)
aoqi@0 320 // is right-open. The last parameter, reducing, indicates whether the
aoqi@0 321 // updates to individual entries always reduce the entry from a higher
aoqi@0 322 // to a lower value. (For example this would hold true during a temporal
aoqi@0 323 // regime during which only block splits were updating the BOT.
aoqi@0 324 void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end, bool reducing = false);
aoqi@0 325 // Same as above, except that the args here are a card _index_ interval
aoqi@0 326 // that is closed: [start_index, end_index]
aoqi@0 327 void set_remainder_to_point_to_start_incl(size_t start, size_t end, bool reducing = false);
aoqi@0 328
aoqi@0 329 // A helper function for BOT adjustment/verification work
aoqi@0 330 void do_block_internal(HeapWord* blk_start, HeapWord* blk_end, Action action, bool reducing = false);
aoqi@0 331
aoqi@0 332 public:
aoqi@0 333 // The space may not have its bottom and top set yet, which is why the
aoqi@0 334 // region is passed as a parameter. If "init_to_zero" is true, the
aoqi@0 335 // elements of the array are initialized to zero. Otherwise, they are
aoqi@0 336 // initialized to point backwards to the beginning.
aoqi@0 337 BlockOffsetArray(BlockOffsetSharedArray* array, MemRegion mr,
aoqi@0 338 bool init_to_zero_);
aoqi@0 339
aoqi@0 340 // Note: this ought to be part of the constructor, but that would require
aoqi@0 341 // "this" to be passed as a parameter to a member constructor for
aoqi@0 342 // the containing concrete subtype of Space.
aoqi@0 343 // This would be legal C++, but MS VC++ doesn't allow it.
aoqi@0 344 void set_space(Space* sp) { _sp = sp; }
aoqi@0 345
aoqi@0 346 // Resets the covered region to the given "mr".
aoqi@0 347 void set_region(MemRegion mr) {
aoqi@0 348 _bottom = mr.start();
aoqi@0 349 _end = mr.end();
aoqi@0 350 }
aoqi@0 351
aoqi@0 352 // Note that the committed size of the covered space may have changed,
aoqi@0 353 // so the table size might also wish to change.
aoqi@0 354 virtual void resize(size_t new_word_size) {
aoqi@0 355 HeapWord* new_end = _bottom + new_word_size;
aoqi@0 356 if (_end < new_end && !init_to_zero()) {
aoqi@0 357 // verify that the old and new boundaries are also card boundaries
aoqi@0 358 assert(_array->is_card_boundary(_end),
aoqi@0 359 "_end not a card boundary");
aoqi@0 360 assert(_array->is_card_boundary(new_end),
aoqi@0 361 "new _end would not be a card boundary");
aoqi@0 362 // set all the newly added cards
aoqi@0 363 _array->set_offset_array(_end, new_end, N_words);
aoqi@0 364 }
aoqi@0 365 _end = new_end; // update _end
aoqi@0 366 }
aoqi@0 367
aoqi@0 368 // Adjust the BOT to show that it has a single block in the
aoqi@0 369 // range [blk_start, blk_start + size). All necessary BOT
aoqi@0 370 // cards are adjusted, but _unallocated_block isn't.
aoqi@0 371 void single_block(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 372 void single_block(HeapWord* blk, size_t size) {
aoqi@0 373 single_block(blk, blk + size);
aoqi@0 374 }
aoqi@0 375
aoqi@0 376 // When the alloc_block() call returns, the block offset table should
aoqi@0 377 // have enough information such that any subsequent block_start() call
aoqi@0 378 // with an argument equal to an address that is within the range
aoqi@0 379 // [blk_start, blk_end) would return the value blk_start, provided
aoqi@0 380 // there have been no calls in between that reset this information
aoqi@0 381 // (e.g. see BlockOffsetArrayNonContigSpace::single_block() call
aoqi@0 382 // for an appropriate range covering the said interval).
aoqi@0 383 // These methods expect to be called with [blk_start, blk_end)
aoqi@0 384 // representing a block of memory in the heap.
aoqi@0 385 virtual void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 386 void alloc_block(HeapWord* blk, size_t size) {
aoqi@0 387 alloc_block(blk, blk + size);
aoqi@0 388 }
aoqi@0 389
aoqi@0 390 // If true, initialize array slots with no allocated blocks to zero.
aoqi@0 391 // Otherwise, make them point back to the front.
aoqi@0 392 bool init_to_zero() { return _init_to_zero; }
aoqi@0 393 // Corresponding setter
aoqi@0 394 void set_init_to_zero(bool val) {
aoqi@0 395 _init_to_zero = val;
aoqi@0 396 assert(_array != NULL, "_array should be non-NULL");
aoqi@0 397 _array->set_init_to_zero(val);
aoqi@0 398 }
aoqi@0 399
aoqi@0 400 // Debugging
aoqi@0 401 // Return the index of the last entry in the "active" region.
aoqi@0 402 virtual size_t last_active_index() const = 0;
aoqi@0 403 // Verify the block offset table
aoqi@0 404 void verify() const;
aoqi@0 405 void check_all_cards(size_t left_card, size_t right_card) const;
aoqi@0 406 };
aoqi@0 407
aoqi@0 408 ////////////////////////////////////////////////////////////////////////////
aoqi@0 409 // A subtype of BlockOffsetArray that takes advantage of the fact
aoqi@0 410 // that its underlying space is a NonContiguousSpace, so that some
aoqi@0 411 // specialized interfaces can be made available for spaces that
aoqi@0 412 // manipulate the table.
aoqi@0 413 ////////////////////////////////////////////////////////////////////////////
aoqi@0 414 class BlockOffsetArrayNonContigSpace: public BlockOffsetArray {
aoqi@0 415 friend class VMStructs;
aoqi@0 416 private:
aoqi@0 417 // The portion [_unallocated_block, _sp.end()) of the space that
aoqi@0 418 // is a single block known not to contain any objects.
aoqi@0 419 // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag.
aoqi@0 420 HeapWord* _unallocated_block;
aoqi@0 421
aoqi@0 422 public:
aoqi@0 423 BlockOffsetArrayNonContigSpace(BlockOffsetSharedArray* array, MemRegion mr):
aoqi@0 424 BlockOffsetArray(array, mr, false),
aoqi@0 425 _unallocated_block(_bottom) { }
aoqi@0 426
aoqi@0 427 // accessor
aoqi@0 428 HeapWord* unallocated_block() const {
aoqi@0 429 assert(BlockOffsetArrayUseUnallocatedBlock,
aoqi@0 430 "_unallocated_block is not being maintained");
aoqi@0 431 return _unallocated_block;
aoqi@0 432 }
aoqi@0 433
aoqi@0 434 void set_unallocated_block(HeapWord* block) {
aoqi@0 435 assert(BlockOffsetArrayUseUnallocatedBlock,
aoqi@0 436 "_unallocated_block is not being maintained");
aoqi@0 437 assert(block >= _bottom && block <= _end, "out of range");
aoqi@0 438 _unallocated_block = block;
aoqi@0 439 }
aoqi@0 440
aoqi@0 441 // These methods expect to be called with [blk_start, blk_end)
aoqi@0 442 // representing a block of memory in the heap.
aoqi@0 443 void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 444 void alloc_block(HeapWord* blk, size_t size) {
aoqi@0 445 alloc_block(blk, blk + size);
aoqi@0 446 }
aoqi@0 447
aoqi@0 448 // The following methods are useful and optimized for a
aoqi@0 449 // non-contiguous space.
aoqi@0 450
aoqi@0 451 // Given a block [blk_start, blk_start + full_blk_size), and
aoqi@0 452 // a left_blk_size < full_blk_size, adjust the BOT to show two
aoqi@0 453 // blocks [blk_start, blk_start + left_blk_size) and
aoqi@0 454 // [blk_start + left_blk_size, blk_start + full_blk_size).
aoqi@0 455 // It is assumed (and verified in the non-product VM) that the
aoqi@0 456 // BOT was correct for the original block.
aoqi@0 457 void split_block(HeapWord* blk_start, size_t full_blk_size,
aoqi@0 458 size_t left_blk_size);
aoqi@0 459
aoqi@0 460 // Adjust BOT to show that it has a block in the range
aoqi@0 461 // [blk_start, blk_start + size). Only the first card
aoqi@0 462 // of BOT is touched. It is assumed (and verified in the
aoqi@0 463 // non-product VM) that the remaining cards of the block
aoqi@0 464 // are correct.
aoqi@0 465 void mark_block(HeapWord* blk_start, HeapWord* blk_end, bool reducing = false);
aoqi@0 466 void mark_block(HeapWord* blk, size_t size, bool reducing = false) {
aoqi@0 467 mark_block(blk, blk + size, reducing);
aoqi@0 468 }
aoqi@0 469
aoqi@0 470 // Adjust _unallocated_block to indicate that a particular
aoqi@0 471 // block has been newly allocated or freed. It is assumed (and
aoqi@0 472 // verified in the non-product VM) that the BOT is correct for
aoqi@0 473 // the given block.
aoqi@0 474 void allocated(HeapWord* blk_start, HeapWord* blk_end, bool reducing = false) {
aoqi@0 475 // Verify that the BOT shows [blk, blk + blk_size) to be one block.
aoqi@0 476 verify_single_block(blk_start, blk_end);
aoqi@0 477 if (BlockOffsetArrayUseUnallocatedBlock) {
aoqi@0 478 _unallocated_block = MAX2(_unallocated_block, blk_end);
aoqi@0 479 }
aoqi@0 480 }
aoqi@0 481
aoqi@0 482 void allocated(HeapWord* blk, size_t size, bool reducing = false) {
aoqi@0 483 allocated(blk, blk + size, reducing);
aoqi@0 484 }
aoqi@0 485
aoqi@0 486 void freed(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 487 void freed(HeapWord* blk, size_t size);
aoqi@0 488
aoqi@0 489 HeapWord* block_start_unsafe(const void* addr) const;
aoqi@0 490
aoqi@0 491 // Requires "addr" to be the start of a card and returns the
aoqi@0 492 // start of the block that contains the given address.
aoqi@0 493 HeapWord* block_start_careful(const void* addr) const;
aoqi@0 494
aoqi@0 495 // Verification & debugging: ensure that the offset table reflects
aoqi@0 496 // the fact that the block [blk_start, blk_end) or [blk, blk + size)
aoqi@0 497 // is a single block of storage. NOTE: can't const this because of
aoqi@0 498 // call to non-const do_block_internal() below.
aoqi@0 499 void verify_single_block(HeapWord* blk_start, HeapWord* blk_end)
aoqi@0 500 PRODUCT_RETURN;
aoqi@0 501 void verify_single_block(HeapWord* blk, size_t size) PRODUCT_RETURN;
aoqi@0 502
aoqi@0 503 // Verify that the given block is before _unallocated_block
aoqi@0 504 void verify_not_unallocated(HeapWord* blk_start, HeapWord* blk_end)
aoqi@0 505 const PRODUCT_RETURN;
aoqi@0 506 void verify_not_unallocated(HeapWord* blk, size_t size)
aoqi@0 507 const PRODUCT_RETURN;
aoqi@0 508
aoqi@0 509 // Debugging support
aoqi@0 510 virtual size_t last_active_index() const;
aoqi@0 511 };
aoqi@0 512
aoqi@0 513 ////////////////////////////////////////////////////////////////////////////
aoqi@0 514 // A subtype of BlockOffsetArray that takes advantage of the fact
aoqi@0 515 // that its underlying space is a ContiguousSpace, so that its "active"
aoqi@0 516 // region can be more efficiently tracked (than for a non-contiguous space).
aoqi@0 517 ////////////////////////////////////////////////////////////////////////////
aoqi@0 518 class BlockOffsetArrayContigSpace: public BlockOffsetArray {
aoqi@0 519 friend class VMStructs;
aoqi@0 520 private:
aoqi@0 521 // allocation boundary at which offset array must be updated
aoqi@0 522 HeapWord* _next_offset_threshold;
aoqi@0 523 size_t _next_offset_index; // index corresponding to that boundary
aoqi@0 524
aoqi@0 525 // Work function when allocation start crosses threshold.
aoqi@0 526 void alloc_block_work(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 527
aoqi@0 528 public:
aoqi@0 529 BlockOffsetArrayContigSpace(BlockOffsetSharedArray* array, MemRegion mr):
aoqi@0 530 BlockOffsetArray(array, mr, true) {
aoqi@0 531 _next_offset_threshold = NULL;
aoqi@0 532 _next_offset_index = 0;
aoqi@0 533 }
aoqi@0 534
aoqi@0 535 void set_contig_space(ContiguousSpace* sp) { set_space((Space*)sp); }
aoqi@0 536
aoqi@0 537 // Initialize the threshold for an empty heap.
aoqi@0 538 HeapWord* initialize_threshold();
aoqi@0 539 // Zero out the entry for _bottom (offset will be zero)
aoqi@0 540 void zero_bottom_entry();
aoqi@0 541
aoqi@0 542 // Return the next threshold, the point at which the table should be
aoqi@0 543 // updated.
aoqi@0 544 HeapWord* threshold() const { return _next_offset_threshold; }
aoqi@0 545
aoqi@0 546 // In general, these methods expect to be called with
aoqi@0 547 // [blk_start, blk_end) representing a block of memory in the heap.
aoqi@0 548 // In this implementation, however, we are OK even if blk_start and/or
aoqi@0 549 // blk_end are NULL because NULL is represented as 0, and thus
aoqi@0 550 // never exceeds the "_next_offset_threshold".
aoqi@0 551 void alloc_block(HeapWord* blk_start, HeapWord* blk_end) {
aoqi@0 552 if (blk_end > _next_offset_threshold) {
aoqi@0 553 alloc_block_work(blk_start, blk_end);
aoqi@0 554 }
aoqi@0 555 }
aoqi@0 556 void alloc_block(HeapWord* blk, size_t size) {
aoqi@0 557 alloc_block(blk, blk + size);
aoqi@0 558 }
aoqi@0 559
aoqi@0 560 HeapWord* block_start_unsafe(const void* addr) const;
aoqi@0 561
aoqi@0 562 // Debugging support
aoqi@0 563 virtual size_t last_active_index() const;
aoqi@0 564 };
aoqi@0 565
aoqi@0 566 #endif // SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP

mercurial