annotate src/hotspot/share/gc/shared/blockOffsetTable.hpp @ 52321:31b159f30fb2

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