src/share/vm/gc_implementation/g1/g1BlockOffsetTable.hpp

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

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_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 // While generally mirroring the structure of the BOT for GenCollectedHeap,
aoqi@0 39 // the following types are tailored more towards G1's uses; these should,
aoqi@0 40 // however, be merged back into a common BOT to avoid code duplication
aoqi@0 41 // and reduce maintenance overhead.
aoqi@0 42 //
aoqi@0 43 // G1BlockOffsetTable (abstract)
aoqi@0 44 // -- G1BlockOffsetArray (uses G1BlockOffsetSharedArray)
aoqi@0 45 // -- G1BlockOffsetArrayContigSpace
aoqi@0 46 //
aoqi@0 47 // A main impediment to the consolidation of this code might be the
aoqi@0 48 // effect of making some of the block_start*() calls non-const as
aoqi@0 49 // below. Whether that might adversely affect performance optimizations
aoqi@0 50 // that compilers might normally perform in the case of non-G1
aoqi@0 51 // collectors needs to be carefully investigated prior to any such
aoqi@0 52 // consolidation.
aoqi@0 53
aoqi@0 54 // Forward declarations
aoqi@0 55 class ContiguousSpace;
aoqi@0 56 class G1BlockOffsetSharedArray;
aoqi@0 57
aoqi@0 58 class G1BlockOffsetTable VALUE_OBJ_CLASS_SPEC {
aoqi@0 59 friend class VMStructs;
aoqi@0 60 protected:
aoqi@0 61 // These members describe the region covered by the table.
aoqi@0 62
aoqi@0 63 // The space this table is covering.
aoqi@0 64 HeapWord* _bottom; // == reserved.start
aoqi@0 65 HeapWord* _end; // End of currently allocated region.
aoqi@0 66
aoqi@0 67 public:
aoqi@0 68 // Initialize the table to cover the given space.
aoqi@0 69 // The contents of the initial table are undefined.
aoqi@0 70 G1BlockOffsetTable(HeapWord* bottom, HeapWord* end) :
aoqi@0 71 _bottom(bottom), _end(end)
aoqi@0 72 {
aoqi@0 73 assert(_bottom <= _end, "arguments out of order");
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 // Note that the committed size of the covered space may have changed,
aoqi@0 77 // so the table size might also wish to change.
aoqi@0 78 virtual void resize(size_t new_word_size) = 0;
aoqi@0 79
aoqi@0 80 virtual void set_bottom(HeapWord* new_bottom) {
aoqi@0 81 assert(new_bottom <= _end,
aoqi@0 82 err_msg("new_bottom (" PTR_FORMAT ") > _end (" PTR_FORMAT ")",
aoqi@0 83 p2i(new_bottom), p2i(_end)));
aoqi@0 84 _bottom = new_bottom;
aoqi@0 85 resize(pointer_delta(_end, _bottom));
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 // Requires "addr" to be contained by a block, and returns the address of
aoqi@0 89 // the start of that block. (May have side effects, namely updating of
aoqi@0 90 // shared array entries that "point" too far backwards. This can occur,
aoqi@0 91 // for example, when LAB allocation is used in a space covered by the
aoqi@0 92 // table.)
aoqi@0 93 virtual HeapWord* block_start_unsafe(const void* addr) = 0;
aoqi@0 94 // Same as above, but does not have any of the possible side effects
aoqi@0 95 // discussed above.
aoqi@0 96 virtual HeapWord* block_start_unsafe_const(const void* addr) const = 0;
aoqi@0 97
aoqi@0 98 // Returns the address of the start of the block containing "addr", or
aoqi@0 99 // else "null" if it is covered by no block. (May have side effects,
aoqi@0 100 // namely updating of shared array entries that "point" too far
aoqi@0 101 // backwards. This can occur, for example, when lab allocation is used
aoqi@0 102 // in a space covered by the table.)
aoqi@0 103 inline HeapWord* block_start(const void* addr);
aoqi@0 104 // Same as above, but does not have any of the possible side effects
aoqi@0 105 // discussed above.
aoqi@0 106 inline HeapWord* block_start_const(const void* addr) const;
aoqi@0 107 };
aoqi@0 108
aoqi@0 109 // This implementation of "G1BlockOffsetTable" divides the covered region
aoqi@0 110 // into "N"-word subregions (where "N" = 2^"LogN". An array with an entry
aoqi@0 111 // for each such subregion indicates how far back one must go to find the
aoqi@0 112 // start of the chunk that includes the first word of the subregion.
aoqi@0 113 //
aoqi@0 114 // Each BlockOffsetArray is owned by a Space. However, the actual array
aoqi@0 115 // may be shared by several BlockOffsetArrays; this is useful
aoqi@0 116 // when a single resizable area (such as a generation) is divided up into
aoqi@0 117 // several spaces in which contiguous allocation takes place,
aoqi@0 118 // such as, for example, in G1 or in the train generation.)
aoqi@0 119
aoqi@0 120 // Here is the shared array type.
aoqi@0 121
aoqi@0 122 class G1BlockOffsetSharedArray: public CHeapObj<mtGC> {
aoqi@0 123 friend class G1BlockOffsetArray;
aoqi@0 124 friend class G1BlockOffsetArrayContigSpace;
aoqi@0 125 friend class VMStructs;
aoqi@0 126
aoqi@0 127 private:
aoqi@0 128 // The reserved region covered by the shared array.
aoqi@0 129 MemRegion _reserved;
aoqi@0 130
aoqi@0 131 // End of the current committed region.
aoqi@0 132 HeapWord* _end;
aoqi@0 133
aoqi@0 134 // Array for keeping offsets for retrieving object start fast given an
aoqi@0 135 // address.
aoqi@0 136 VirtualSpace _vs;
aoqi@0 137 u_char* _offset_array; // byte array keeping backwards offsets
aoqi@0 138
aoqi@0 139 void check_index(size_t index, const char* msg) const {
aoqi@0 140 assert(index < _vs.committed_size(),
aoqi@0 141 err_msg("%s - "
aoqi@0 142 "index: " SIZE_FORMAT ", _vs.committed_size: " SIZE_FORMAT,
aoqi@0 143 msg, index, _vs.committed_size()));
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 void check_offset(size_t offset, const char* msg) const {
aoqi@0 147 assert(offset <= N_words,
aoqi@0 148 err_msg("%s - "
aoqi@0 149 "offset: " SIZE_FORMAT ", N_words: " UINT32_FORMAT,
aoqi@0 150 msg, offset, N_words));
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 // Bounds checking accessors:
aoqi@0 154 // For performance these have to devolve to array accesses in product builds.
aoqi@0 155 u_char offset_array(size_t index) const {
aoqi@0 156 check_index(index, "index out of range");
aoqi@0 157 return _offset_array[index];
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 void set_offset_array(size_t index, u_char offset) {
aoqi@0 161 check_index(index, "index out of range");
aoqi@0 162 check_offset(offset, "offset too large");
aoqi@0 163 _offset_array[index] = offset;
aoqi@0 164 }
aoqi@0 165
aoqi@0 166 void set_offset_array(size_t index, HeapWord* high, HeapWord* low) {
aoqi@0 167 check_index(index, "index out of range");
aoqi@0 168 assert(high >= low, "addresses out of order");
aoqi@0 169 check_offset(pointer_delta(high, low), "offset too large");
aoqi@0 170 _offset_array[index] = (u_char) pointer_delta(high, low);
aoqi@0 171 }
aoqi@0 172
aoqi@0 173 void set_offset_array(HeapWord* left, HeapWord* right, u_char offset) {
aoqi@0 174 check_index(index_for(right - 1), "right address out of range");
aoqi@0 175 assert(left < right, "Heap addresses out of order");
aoqi@0 176 size_t num_cards = pointer_delta(right, left) >> LogN_words;
aoqi@0 177 if (UseMemSetInBOT) {
aoqi@0 178 memset(&_offset_array[index_for(left)], offset, num_cards);
aoqi@0 179 } else {
aoqi@0 180 size_t i = index_for(left);
aoqi@0 181 const size_t end = i + num_cards;
aoqi@0 182 for (; i < end; i++) {
aoqi@0 183 _offset_array[i] = offset;
aoqi@0 184 }
aoqi@0 185 }
aoqi@0 186 }
aoqi@0 187
aoqi@0 188 void set_offset_array(size_t left, size_t right, u_char offset) {
aoqi@0 189 check_index(right, "right index out of range");
aoqi@0 190 assert(left <= right, "indexes out of order");
aoqi@0 191 size_t num_cards = right - left + 1;
aoqi@0 192 if (UseMemSetInBOT) {
aoqi@0 193 memset(&_offset_array[left], offset, num_cards);
aoqi@0 194 } else {
aoqi@0 195 size_t i = left;
aoqi@0 196 const size_t end = i + num_cards;
aoqi@0 197 for (; i < end; i++) {
aoqi@0 198 _offset_array[i] = offset;
aoqi@0 199 }
aoqi@0 200 }
aoqi@0 201 }
aoqi@0 202
aoqi@0 203 void check_offset_array(size_t index, HeapWord* high, HeapWord* low) const {
aoqi@0 204 check_index(index, "index out of range");
aoqi@0 205 assert(high >= low, "addresses out of order");
aoqi@0 206 check_offset(pointer_delta(high, low), "offset too large");
aoqi@0 207 assert(_offset_array[index] == pointer_delta(high, low), "Wrong offset");
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 bool is_card_boundary(HeapWord* p) const;
aoqi@0 211
aoqi@0 212 // Return the number of slots needed for an offset array
aoqi@0 213 // that covers mem_region_words words.
aoqi@0 214 // We always add an extra slot because if an object
aoqi@0 215 // ends on a card boundary we put a 0 in the next
aoqi@0 216 // offset array slot, so we want that slot always
aoqi@0 217 // to be reserved.
aoqi@0 218
aoqi@0 219 size_t compute_size(size_t mem_region_words) {
aoqi@0 220 size_t number_of_slots = (mem_region_words / N_words) + 1;
aoqi@0 221 return ReservedSpace::page_align_size_up(number_of_slots);
aoqi@0 222 }
aoqi@0 223
aoqi@0 224 public:
aoqi@0 225 enum SomePublicConstants {
aoqi@0 226 LogN = 9,
aoqi@0 227 LogN_words = LogN - LogHeapWordSize,
aoqi@0 228 N_bytes = 1 << LogN,
aoqi@0 229 N_words = 1 << LogN_words
aoqi@0 230 };
aoqi@0 231
aoqi@0 232 // Initialize the table to cover from "base" to (at least)
aoqi@0 233 // "base + init_word_size". In the future, the table may be expanded
aoqi@0 234 // (see "resize" below) up to the size of "_reserved" (which must be at
aoqi@0 235 // least "init_word_size".) The contents of the initial table are
aoqi@0 236 // undefined; it is the responsibility of the constituent
aoqi@0 237 // G1BlockOffsetTable(s) to initialize cards.
aoqi@0 238 G1BlockOffsetSharedArray(MemRegion reserved, size_t init_word_size);
aoqi@0 239
aoqi@0 240 // Notes a change in the committed size of the region covered by the
aoqi@0 241 // table. The "new_word_size" may not be larger than the size of the
aoqi@0 242 // reserved region this table covers.
aoqi@0 243 void resize(size_t new_word_size);
aoqi@0 244
aoqi@0 245 void set_bottom(HeapWord* new_bottom);
aoqi@0 246
aoqi@0 247 // Updates all the BlockOffsetArray's sharing this shared array to
aoqi@0 248 // reflect the current "top"'s of their spaces.
aoqi@0 249 void update_offset_arrays();
aoqi@0 250
aoqi@0 251 // Return the appropriate index into "_offset_array" for "p".
aoqi@0 252 inline size_t index_for(const void* p) const;
aoqi@0 253
aoqi@0 254 // Return the address indicating the start of the region corresponding to
aoqi@0 255 // "index" in "_offset_array".
aoqi@0 256 inline HeapWord* address_for_index(size_t index) const;
aoqi@0 257 };
aoqi@0 258
aoqi@0 259 // And here is the G1BlockOffsetTable subtype that uses the array.
aoqi@0 260
aoqi@0 261 class G1BlockOffsetArray: public G1BlockOffsetTable {
aoqi@0 262 friend class G1BlockOffsetSharedArray;
aoqi@0 263 friend class G1BlockOffsetArrayContigSpace;
aoqi@0 264 friend class VMStructs;
aoqi@0 265 private:
aoqi@0 266 enum SomePrivateConstants {
aoqi@0 267 N_words = G1BlockOffsetSharedArray::N_words,
aoqi@0 268 LogN = G1BlockOffsetSharedArray::LogN
aoqi@0 269 };
aoqi@0 270
aoqi@0 271 // The following enums are used by do_block_helper
aoqi@0 272 enum Action {
aoqi@0 273 Action_single, // BOT records a single block (see single_block())
aoqi@0 274 Action_mark, // BOT marks the start of a block (see mark_block())
aoqi@0 275 Action_check // Check that BOT records block correctly
aoqi@0 276 // (see verify_single_block()).
aoqi@0 277 };
aoqi@0 278
aoqi@0 279 // This is the array, which can be shared by several BlockOffsetArray's
aoqi@0 280 // servicing different
aoqi@0 281 G1BlockOffsetSharedArray* _array;
aoqi@0 282
aoqi@0 283 // The space that owns this subregion.
aoqi@0 284 Space* _sp;
aoqi@0 285
aoqi@0 286 // If "_sp" is a contiguous space, the field below is the view of "_sp"
aoqi@0 287 // as a contiguous space, else NULL.
aoqi@0 288 ContiguousSpace* _csp;
aoqi@0 289
aoqi@0 290 // If true, array entries are initialized to 0; otherwise, they are
aoqi@0 291 // initialized to point backwards to the beginning of the covered region.
aoqi@0 292 bool _init_to_zero;
aoqi@0 293
aoqi@0 294 // The portion [_unallocated_block, _sp.end()) of the space that
aoqi@0 295 // is a single block known not to contain any objects.
aoqi@0 296 // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag.
aoqi@0 297 HeapWord* _unallocated_block;
aoqi@0 298
aoqi@0 299 // Sets the entries
aoqi@0 300 // corresponding to the cards starting at "start" and ending at "end"
aoqi@0 301 // to point back to the card before "start": the interval [start, end)
aoqi@0 302 // is right-open.
aoqi@0 303 void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end);
aoqi@0 304 // Same as above, except that the args here are a card _index_ interval
aoqi@0 305 // that is closed: [start_index, end_index]
aoqi@0 306 void set_remainder_to_point_to_start_incl(size_t start, size_t end);
aoqi@0 307
aoqi@0 308 // A helper function for BOT adjustment/verification work
aoqi@0 309 void do_block_internal(HeapWord* blk_start, HeapWord* blk_end, Action action);
aoqi@0 310
aoqi@0 311 protected:
aoqi@0 312
aoqi@0 313 ContiguousSpace* csp() const { return _csp; }
aoqi@0 314
aoqi@0 315 // Returns the address of a block whose start is at most "addr".
aoqi@0 316 // If "has_max_index" is true, "assumes "max_index" is the last valid one
aoqi@0 317 // in the array.
aoqi@0 318 inline HeapWord* block_at_or_preceding(const void* addr,
aoqi@0 319 bool has_max_index,
aoqi@0 320 size_t max_index) const;
aoqi@0 321
aoqi@0 322 // "q" is a block boundary that is <= "addr"; "n" is the address of the
aoqi@0 323 // next block (or the end of the space.) Return the address of the
aoqi@0 324 // beginning of the block that contains "addr". Does so without side
aoqi@0 325 // effects (see, e.g., spec of block_start.)
aoqi@0 326 inline HeapWord*
aoqi@0 327 forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,
aoqi@0 328 const void* addr) const;
aoqi@0 329
aoqi@0 330 // "q" is a block boundary that is <= "addr"; return the address of the
aoqi@0 331 // beginning of the block that contains "addr". May have side effects
aoqi@0 332 // on "this", by updating imprecise entries.
aoqi@0 333 inline HeapWord* forward_to_block_containing_addr(HeapWord* q,
aoqi@0 334 const void* addr);
aoqi@0 335
aoqi@0 336 // "q" is a block boundary that is <= "addr"; "n" is the address of the
aoqi@0 337 // next block (or the end of the space.) Return the address of the
aoqi@0 338 // beginning of the block that contains "addr". May have side effects
aoqi@0 339 // on "this", by updating imprecise entries.
aoqi@0 340 HeapWord* forward_to_block_containing_addr_slow(HeapWord* q,
aoqi@0 341 HeapWord* n,
aoqi@0 342 const void* addr);
aoqi@0 343
aoqi@0 344 // Requires that "*threshold_" be the first array entry boundary at or
aoqi@0 345 // above "blk_start", and that "*index_" be the corresponding array
aoqi@0 346 // index. If the block starts at or crosses "*threshold_", records
aoqi@0 347 // "blk_start" as the appropriate block start for the array index
aoqi@0 348 // starting at "*threshold_", and for any other indices crossed by the
aoqi@0 349 // block. Updates "*threshold_" and "*index_" to correspond to the first
aoqi@0 350 // index after the block end.
aoqi@0 351 void alloc_block_work2(HeapWord** threshold_, size_t* index_,
aoqi@0 352 HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 353
aoqi@0 354 public:
aoqi@0 355 // The space may not have it's bottom and top set yet, which is why the
aoqi@0 356 // region is passed as a parameter. If "init_to_zero" is true, the
aoqi@0 357 // elements of the array are initialized to zero. Otherwise, they are
aoqi@0 358 // initialized to point backwards to the beginning.
aoqi@0 359 G1BlockOffsetArray(G1BlockOffsetSharedArray* array, MemRegion mr,
aoqi@0 360 bool init_to_zero);
aoqi@0 361
aoqi@0 362 // Note: this ought to be part of the constructor, but that would require
aoqi@0 363 // "this" to be passed as a parameter to a member constructor for
aoqi@0 364 // the containing concrete subtype of Space.
aoqi@0 365 // This would be legal C++, but MS VC++ doesn't allow it.
aoqi@0 366 void set_space(Space* sp);
aoqi@0 367
aoqi@0 368 // Resets the covered region to the given "mr".
aoqi@0 369 void set_region(MemRegion mr);
aoqi@0 370
aoqi@0 371 // Resets the covered region to one with the same _bottom as before but
aoqi@0 372 // the "new_word_size".
aoqi@0 373 void resize(size_t new_word_size);
aoqi@0 374
aoqi@0 375 // These must be guaranteed to work properly (i.e., do nothing)
aoqi@0 376 // when "blk_start" ("blk" for second version) is "NULL".
aoqi@0 377 virtual void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 378 virtual void alloc_block(HeapWord* blk, size_t size) {
aoqi@0 379 alloc_block(blk, blk + size);
aoqi@0 380 }
aoqi@0 381
aoqi@0 382 // The following methods are useful and optimized for a
aoqi@0 383 // general, non-contiguous space.
aoqi@0 384
aoqi@0 385 // Given a block [blk_start, blk_start + full_blk_size), and
aoqi@0 386 // a left_blk_size < full_blk_size, adjust the BOT to show two
aoqi@0 387 // blocks [blk_start, blk_start + left_blk_size) and
aoqi@0 388 // [blk_start + left_blk_size, blk_start + full_blk_size).
aoqi@0 389 // It is assumed (and verified in the non-product VM) that the
aoqi@0 390 // BOT was correct for the original block.
aoqi@0 391 void split_block(HeapWord* blk_start, size_t full_blk_size,
aoqi@0 392 size_t left_blk_size);
aoqi@0 393
aoqi@0 394 // Adjust the BOT to show that it has a single block in the
aoqi@0 395 // range [blk_start, blk_start + size). All necessary BOT
aoqi@0 396 // cards are adjusted, but _unallocated_block isn't.
aoqi@0 397 void single_block(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 398 void single_block(HeapWord* blk, size_t size) {
aoqi@0 399 single_block(blk, blk + size);
aoqi@0 400 }
aoqi@0 401
aoqi@0 402 // Adjust BOT to show that it has a block in the range
aoqi@0 403 // [blk_start, blk_start + size). Only the first card
aoqi@0 404 // of BOT is touched. It is assumed (and verified in the
aoqi@0 405 // non-product VM) that the remaining cards of the block
aoqi@0 406 // are correct.
aoqi@0 407 void mark_block(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 408 void mark_block(HeapWord* blk, size_t size) {
aoqi@0 409 mark_block(blk, blk + size);
aoqi@0 410 }
aoqi@0 411
aoqi@0 412 // Adjust _unallocated_block to indicate that a particular
aoqi@0 413 // block has been newly allocated or freed. It is assumed (and
aoqi@0 414 // verified in the non-product VM) that the BOT is correct for
aoqi@0 415 // the given block.
aoqi@0 416 inline void allocated(HeapWord* blk_start, HeapWord* blk_end) {
aoqi@0 417 // Verify that the BOT shows [blk, blk + blk_size) to be one block.
aoqi@0 418 verify_single_block(blk_start, blk_end);
aoqi@0 419 if (BlockOffsetArrayUseUnallocatedBlock) {
aoqi@0 420 _unallocated_block = MAX2(_unallocated_block, blk_end);
aoqi@0 421 }
aoqi@0 422 }
aoqi@0 423
aoqi@0 424 inline void allocated(HeapWord* blk, size_t size) {
aoqi@0 425 allocated(blk, blk + size);
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 inline void freed(HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 429
aoqi@0 430 inline void freed(HeapWord* blk, size_t size);
aoqi@0 431
aoqi@0 432 virtual HeapWord* block_start_unsafe(const void* addr);
aoqi@0 433 virtual HeapWord* block_start_unsafe_const(const void* addr) const;
aoqi@0 434
aoqi@0 435 // Requires "addr" to be the start of a card and returns the
aoqi@0 436 // start of the block that contains the given address.
aoqi@0 437 HeapWord* block_start_careful(const void* addr) const;
aoqi@0 438
aoqi@0 439 // If true, initialize array slots with no allocated blocks to zero.
aoqi@0 440 // Otherwise, make them point back to the front.
aoqi@0 441 bool init_to_zero() { return _init_to_zero; }
aoqi@0 442
aoqi@0 443 // Verification & debugging - ensure that the offset table reflects the fact
aoqi@0 444 // that the block [blk_start, blk_end) or [blk, blk + size) is a
aoqi@0 445 // single block of storage. NOTE: can;t const this because of
aoqi@0 446 // call to non-const do_block_internal() below.
aoqi@0 447 inline void verify_single_block(HeapWord* blk_start, HeapWord* blk_end) {
aoqi@0 448 if (VerifyBlockOffsetArray) {
aoqi@0 449 do_block_internal(blk_start, blk_end, Action_check);
aoqi@0 450 }
aoqi@0 451 }
aoqi@0 452
aoqi@0 453 inline void verify_single_block(HeapWord* blk, size_t size) {
aoqi@0 454 verify_single_block(blk, blk + size);
aoqi@0 455 }
aoqi@0 456
aoqi@0 457 // Used by region verification. Checks that the contents of the
aoqi@0 458 // BOT reflect that there's a single object that spans the address
aoqi@0 459 // range [obj_start, obj_start + word_size); returns true if this is
aoqi@0 460 // the case, returns false if it's not.
aoqi@0 461 bool verify_for_object(HeapWord* obj_start, size_t word_size) const;
aoqi@0 462
aoqi@0 463 // Verify that the given block is before _unallocated_block
aoqi@0 464 inline void verify_not_unallocated(HeapWord* blk_start,
aoqi@0 465 HeapWord* blk_end) const {
aoqi@0 466 if (BlockOffsetArrayUseUnallocatedBlock) {
aoqi@0 467 assert(blk_start < blk_end, "Block inconsistency?");
aoqi@0 468 assert(blk_end <= _unallocated_block, "_unallocated_block problem");
aoqi@0 469 }
aoqi@0 470 }
aoqi@0 471
aoqi@0 472 inline void verify_not_unallocated(HeapWord* blk, size_t size) const {
aoqi@0 473 verify_not_unallocated(blk, blk + size);
aoqi@0 474 }
aoqi@0 475
aoqi@0 476 void check_all_cards(size_t left_card, size_t right_card) const;
aoqi@0 477
aoqi@0 478 virtual void print_on(outputStream* out) PRODUCT_RETURN;
aoqi@0 479 };
aoqi@0 480
aoqi@0 481 // A subtype of BlockOffsetArray that takes advantage of the fact
aoqi@0 482 // that its underlying space is a ContiguousSpace, so that its "active"
aoqi@0 483 // region can be more efficiently tracked (than for a non-contiguous space).
aoqi@0 484 class G1BlockOffsetArrayContigSpace: public G1BlockOffsetArray {
aoqi@0 485 friend class VMStructs;
aoqi@0 486
aoqi@0 487 // allocation boundary at which offset array must be updated
aoqi@0 488 HeapWord* _next_offset_threshold;
aoqi@0 489 size_t _next_offset_index; // index corresponding to that boundary
aoqi@0 490
aoqi@0 491 // Work function to be called when allocation start crosses the next
aoqi@0 492 // threshold in the contig space.
aoqi@0 493 void alloc_block_work1(HeapWord* blk_start, HeapWord* blk_end) {
aoqi@0 494 alloc_block_work2(&_next_offset_threshold, &_next_offset_index,
aoqi@0 495 blk_start, blk_end);
aoqi@0 496 }
aoqi@0 497
aoqi@0 498 public:
aoqi@0 499 G1BlockOffsetArrayContigSpace(G1BlockOffsetSharedArray* array, MemRegion mr);
aoqi@0 500
aoqi@0 501 // Initialize the threshold to reflect the first boundary after the
aoqi@0 502 // bottom of the covered region.
aoqi@0 503 HeapWord* initialize_threshold();
aoqi@0 504
aoqi@0 505 // Zero out the entry for _bottom (offset will be zero).
aoqi@0 506 void zero_bottom_entry();
aoqi@0 507
aoqi@0 508 // Return the next threshold, the point at which the table should be
aoqi@0 509 // updated.
aoqi@0 510 HeapWord* threshold() const { return _next_offset_threshold; }
aoqi@0 511
aoqi@0 512 // These must be guaranteed to work properly (i.e., do nothing)
aoqi@0 513 // when "blk_start" ("blk" for second version) is "NULL". In this
aoqi@0 514 // implementation, that's true because NULL is represented as 0, and thus
aoqi@0 515 // never exceeds the "_next_offset_threshold".
aoqi@0 516 void alloc_block(HeapWord* blk_start, HeapWord* blk_end) {
aoqi@0 517 if (blk_end > _next_offset_threshold)
aoqi@0 518 alloc_block_work1(blk_start, blk_end);
aoqi@0 519 }
aoqi@0 520 void alloc_block(HeapWord* blk, size_t size) {
aoqi@0 521 alloc_block(blk, blk+size);
aoqi@0 522 }
aoqi@0 523
aoqi@0 524 HeapWord* block_start_unsafe(const void* addr);
aoqi@0 525 HeapWord* block_start_unsafe_const(const void* addr) const;
aoqi@0 526
aoqi@0 527 void set_for_starts_humongous(HeapWord* new_top);
aoqi@0 528
aoqi@0 529 virtual void print_on(outputStream* out) PRODUCT_RETURN;
aoqi@0 530 };
aoqi@0 531
aoqi@0 532 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_HPP

mercurial