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

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7257
e7d0505c8a30
parent 6876
710a3c8b516e
child 9703
2fdf635bcf28
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
tschatzl@7051 28 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
aoqi@0 29 #include "memory/memRegion.hpp"
aoqi@0 30 #include "runtime/virtualspace.hpp"
aoqi@0 31 #include "utilities/globalDefinitions.hpp"
aoqi@0 32
aoqi@0 33 // The CollectedHeap type requires subtypes to implement a method
aoqi@0 34 // "block_start". For some subtypes, notably generational
aoqi@0 35 // systems using card-table-based write barriers, the efficiency of this
aoqi@0 36 // operation may be important. Implementations of the "BlockOffsetArray"
aoqi@0 37 // class may be useful in providing such efficient implementations.
aoqi@0 38 //
aoqi@0 39 // While generally mirroring the structure of the BOT for GenCollectedHeap,
aoqi@0 40 // the following types are tailored more towards G1's uses; these should,
aoqi@0 41 // however, be merged back into a common BOT to avoid code duplication
aoqi@0 42 // and reduce maintenance overhead.
aoqi@0 43 //
aoqi@0 44 // G1BlockOffsetTable (abstract)
aoqi@0 45 // -- G1BlockOffsetArray (uses G1BlockOffsetSharedArray)
aoqi@0 46 // -- G1BlockOffsetArrayContigSpace
aoqi@0 47 //
aoqi@0 48 // A main impediment to the consolidation of this code might be the
aoqi@0 49 // effect of making some of the block_start*() calls non-const as
aoqi@0 50 // below. Whether that might adversely affect performance optimizations
aoqi@0 51 // that compilers might normally perform in the case of non-G1
aoqi@0 52 // collectors needs to be carefully investigated prior to any such
aoqi@0 53 // consolidation.
aoqi@0 54
aoqi@0 55 // Forward declarations
aoqi@0 56 class G1BlockOffsetSharedArray;
mgerdin@6987 57 class G1OffsetTableContigSpace;
aoqi@0 58
aoqi@0 59 class G1BlockOffsetTable VALUE_OBJ_CLASS_SPEC {
aoqi@0 60 friend class VMStructs;
aoqi@0 61 protected:
aoqi@0 62 // These members describe the region covered by the table.
aoqi@0 63
aoqi@0 64 // The space this table is covering.
aoqi@0 65 HeapWord* _bottom; // == reserved.start
aoqi@0 66 HeapWord* _end; // End of currently allocated region.
aoqi@0 67
aoqi@0 68 public:
aoqi@0 69 // Initialize the table to cover the given space.
aoqi@0 70 // The contents of the initial table are undefined.
aoqi@0 71 G1BlockOffsetTable(HeapWord* bottom, HeapWord* end) :
aoqi@0 72 _bottom(bottom), _end(end)
aoqi@0 73 {
aoqi@0 74 assert(_bottom <= _end, "arguments out of order");
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 // Note that the committed size of the covered space may have changed,
aoqi@0 78 // so the table size might also wish to change.
aoqi@0 79 virtual void resize(size_t new_word_size) = 0;
aoqi@0 80
aoqi@0 81 virtual void set_bottom(HeapWord* new_bottom) {
aoqi@0 82 assert(new_bottom <= _end,
aoqi@0 83 err_msg("new_bottom (" PTR_FORMAT ") > _end (" PTR_FORMAT ")",
aoqi@0 84 p2i(new_bottom), p2i(_end)));
aoqi@0 85 _bottom = new_bottom;
aoqi@0 86 resize(pointer_delta(_end, _bottom));
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 // Requires "addr" to be contained by a block, and returns the address of
aoqi@0 90 // the start of that block. (May have side effects, namely updating of
aoqi@0 91 // shared array entries that "point" too far backwards. This can occur,
aoqi@0 92 // for example, when LAB allocation is used in a space covered by the
aoqi@0 93 // table.)
aoqi@0 94 virtual HeapWord* block_start_unsafe(const void* addr) = 0;
aoqi@0 95 // Same as above, but does not have any of the possible side effects
aoqi@0 96 // discussed above.
aoqi@0 97 virtual HeapWord* block_start_unsafe_const(const void* addr) const = 0;
aoqi@0 98
aoqi@0 99 // Returns the address of the start of the block containing "addr", or
aoqi@0 100 // else "null" if it is covered by no block. (May have side effects,
aoqi@0 101 // namely updating of shared array entries that "point" too far
aoqi@0 102 // backwards. This can occur, for example, when lab allocation is used
aoqi@0 103 // in a space covered by the table.)
aoqi@0 104 inline HeapWord* block_start(const void* addr);
aoqi@0 105 // Same as above, but does not have any of the possible side effects
aoqi@0 106 // discussed above.
aoqi@0 107 inline HeapWord* block_start_const(const void* addr) const;
aoqi@0 108 };
aoqi@0 109
tschatzl@7051 110 class G1BlockOffsetSharedArrayMappingChangedListener : public G1MappingChangedListener {
tschatzl@7051 111 public:
tschatzl@7257 112 virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
brutisso@7256 113 // Nothing to do. The BOT is hard-wired to be part of the HeapRegion, and we cannot
brutisso@7256 114 // retrieve it here since this would cause firing of several asserts. The code
brutisso@7256 115 // executed after commit of a region already needs to do some re-initialization of
brutisso@7256 116 // the HeapRegion, so we combine that.
brutisso@7256 117 }
tschatzl@7051 118 };
tschatzl@7051 119
aoqi@0 120 // This implementation of "G1BlockOffsetTable" divides the covered region
aoqi@0 121 // into "N"-word subregions (where "N" = 2^"LogN". An array with an entry
aoqi@0 122 // for each such subregion indicates how far back one must go to find the
aoqi@0 123 // start of the chunk that includes the first word of the subregion.
aoqi@0 124 //
aoqi@0 125 // Each BlockOffsetArray is owned by a Space. However, the actual array
aoqi@0 126 // may be shared by several BlockOffsetArrays; this is useful
aoqi@0 127 // when a single resizable area (such as a generation) is divided up into
aoqi@0 128 // several spaces in which contiguous allocation takes place,
aoqi@0 129 // such as, for example, in G1 or in the train generation.)
aoqi@0 130
aoqi@0 131 // Here is the shared array type.
aoqi@0 132
aoqi@0 133 class G1BlockOffsetSharedArray: public CHeapObj<mtGC> {
aoqi@0 134 friend class G1BlockOffsetArray;
aoqi@0 135 friend class G1BlockOffsetArrayContigSpace;
aoqi@0 136 friend class VMStructs;
aoqi@0 137
aoqi@0 138 private:
tschatzl@7051 139 G1BlockOffsetSharedArrayMappingChangedListener _listener;
aoqi@0 140 // The reserved region covered by the shared array.
aoqi@0 141 MemRegion _reserved;
aoqi@0 142
aoqi@0 143 // End of the current committed region.
aoqi@0 144 HeapWord* _end;
aoqi@0 145
aoqi@0 146 // Array for keeping offsets for retrieving object start fast given an
aoqi@0 147 // address.
aoqi@0 148 u_char* _offset_array; // byte array keeping backwards offsets
aoqi@0 149
aoqi@0 150 void check_offset(size_t offset, const char* msg) const {
aoqi@0 151 assert(offset <= N_words,
aoqi@0 152 err_msg("%s - "
aoqi@0 153 "offset: " SIZE_FORMAT ", N_words: " UINT32_FORMAT,
aoqi@0 154 msg, offset, N_words));
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 // Bounds checking accessors:
aoqi@0 158 // For performance these have to devolve to array accesses in product builds.
tschatzl@7051 159 inline u_char offset_array(size_t index) const;
aoqi@0 160
tschatzl@7051 161 void set_offset_array_raw(size_t index, u_char offset) {
aoqi@0 162 _offset_array[index] = offset;
aoqi@0 163 }
aoqi@0 164
tschatzl@7051 165 inline void set_offset_array(size_t index, u_char offset);
aoqi@0 166
tschatzl@7051 167 inline void set_offset_array(size_t index, HeapWord* high, HeapWord* low);
aoqi@0 168
tschatzl@7051 169 inline void set_offset_array(size_t left, size_t right, u_char offset);
aoqi@0 170
aoqi@0 171 bool is_card_boundary(HeapWord* p) const;
aoqi@0 172
tschatzl@7051 173 public:
tschatzl@7051 174
aoqi@0 175 // Return the number of slots needed for an offset array
aoqi@0 176 // that covers mem_region_words words.
tschatzl@7051 177 static size_t compute_size(size_t mem_region_words) {
tschatzl@7051 178 size_t number_of_slots = (mem_region_words / N_words);
tschatzl@7051 179 return ReservedSpace::allocation_align_size_up(number_of_slots);
aoqi@0 180 }
aoqi@0 181
aoqi@0 182 enum SomePublicConstants {
aoqi@0 183 LogN = 9,
aoqi@0 184 LogN_words = LogN - LogHeapWordSize,
aoqi@0 185 N_bytes = 1 << LogN,
aoqi@0 186 N_words = 1 << LogN_words
aoqi@0 187 };
aoqi@0 188
aoqi@0 189 // Initialize the table to cover from "base" to (at least)
aoqi@0 190 // "base + init_word_size". In the future, the table may be expanded
aoqi@0 191 // (see "resize" below) up to the size of "_reserved" (which must be at
aoqi@0 192 // least "init_word_size".) The contents of the initial table are
aoqi@0 193 // undefined; it is the responsibility of the constituent
aoqi@0 194 // G1BlockOffsetTable(s) to initialize cards.
tschatzl@7051 195 G1BlockOffsetSharedArray(MemRegion heap, G1RegionToSpaceMapper* storage);
aoqi@0 196
aoqi@0 197 // Return the appropriate index into "_offset_array" for "p".
aoqi@0 198 inline size_t index_for(const void* p) const;
tschatzl@7051 199 inline size_t index_for_raw(const void* p) const;
aoqi@0 200
aoqi@0 201 // Return the address indicating the start of the region corresponding to
aoqi@0 202 // "index" in "_offset_array".
aoqi@0 203 inline HeapWord* address_for_index(size_t index) const;
tschatzl@7051 204 // Variant of address_for_index that does not check the index for validity.
tschatzl@7051 205 inline HeapWord* address_for_index_raw(size_t index) const {
tschatzl@7051 206 return _reserved.start() + (index << LogN_words);
tschatzl@7051 207 }
aoqi@0 208 };
aoqi@0 209
aoqi@0 210 // And here is the G1BlockOffsetTable subtype that uses the array.
aoqi@0 211
aoqi@0 212 class G1BlockOffsetArray: public G1BlockOffsetTable {
aoqi@0 213 friend class G1BlockOffsetSharedArray;
aoqi@0 214 friend class G1BlockOffsetArrayContigSpace;
aoqi@0 215 friend class VMStructs;
aoqi@0 216 private:
aoqi@0 217 enum SomePrivateConstants {
aoqi@0 218 N_words = G1BlockOffsetSharedArray::N_words,
aoqi@0 219 LogN = G1BlockOffsetSharedArray::LogN
aoqi@0 220 };
aoqi@0 221
aoqi@0 222 // This is the array, which can be shared by several BlockOffsetArray's
aoqi@0 223 // servicing different
aoqi@0 224 G1BlockOffsetSharedArray* _array;
aoqi@0 225
aoqi@0 226 // The space that owns this subregion.
mgerdin@6987 227 G1OffsetTableContigSpace* _gsp;
aoqi@0 228
aoqi@0 229 // The portion [_unallocated_block, _sp.end()) of the space that
aoqi@0 230 // is a single block known not to contain any objects.
aoqi@0 231 // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag.
aoqi@0 232 HeapWord* _unallocated_block;
aoqi@0 233
aoqi@0 234 // Sets the entries
aoqi@0 235 // corresponding to the cards starting at "start" and ending at "end"
aoqi@0 236 // to point back to the card before "start": the interval [start, end)
aoqi@0 237 // is right-open.
aoqi@0 238 void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end);
aoqi@0 239 // Same as above, except that the args here are a card _index_ interval
aoqi@0 240 // that is closed: [start_index, end_index]
aoqi@0 241 void set_remainder_to_point_to_start_incl(size_t start, size_t end);
aoqi@0 242
aoqi@0 243 protected:
aoqi@0 244
mgerdin@6987 245 G1OffsetTableContigSpace* gsp() const { return _gsp; }
mgerdin@6987 246
mgerdin@6987 247 inline size_t block_size(const HeapWord* p) const;
aoqi@0 248
aoqi@0 249 // Returns the address of a block whose start is at most "addr".
aoqi@0 250 // If "has_max_index" is true, "assumes "max_index" is the last valid one
aoqi@0 251 // in the array.
aoqi@0 252 inline HeapWord* block_at_or_preceding(const void* addr,
aoqi@0 253 bool has_max_index,
aoqi@0 254 size_t max_index) const;
aoqi@0 255
aoqi@0 256 // "q" is a block boundary that is <= "addr"; "n" is the address of the
aoqi@0 257 // next block (or the end of the space.) Return the address of the
aoqi@0 258 // beginning of the block that contains "addr". Does so without side
aoqi@0 259 // effects (see, e.g., spec of block_start.)
aoqi@0 260 inline HeapWord*
aoqi@0 261 forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,
aoqi@0 262 const void* addr) const;
aoqi@0 263
aoqi@0 264 // "q" is a block boundary that is <= "addr"; return the address of the
aoqi@0 265 // beginning of the block that contains "addr". May have side effects
aoqi@0 266 // on "this", by updating imprecise entries.
aoqi@0 267 inline HeapWord* forward_to_block_containing_addr(HeapWord* q,
aoqi@0 268 const void* addr);
aoqi@0 269
aoqi@0 270 // "q" is a block boundary that is <= "addr"; "n" is the address of the
aoqi@0 271 // next block (or the end of the space.) Return the address of the
aoqi@0 272 // beginning of the block that contains "addr". May have side effects
aoqi@0 273 // on "this", by updating imprecise entries.
aoqi@0 274 HeapWord* forward_to_block_containing_addr_slow(HeapWord* q,
aoqi@0 275 HeapWord* n,
aoqi@0 276 const void* addr);
aoqi@0 277
aoqi@0 278 // Requires that "*threshold_" be the first array entry boundary at or
aoqi@0 279 // above "blk_start", and that "*index_" be the corresponding array
aoqi@0 280 // index. If the block starts at or crosses "*threshold_", records
aoqi@0 281 // "blk_start" as the appropriate block start for the array index
aoqi@0 282 // starting at "*threshold_", and for any other indices crossed by the
aoqi@0 283 // block. Updates "*threshold_" and "*index_" to correspond to the first
aoqi@0 284 // index after the block end.
aoqi@0 285 void alloc_block_work2(HeapWord** threshold_, size_t* index_,
aoqi@0 286 HeapWord* blk_start, HeapWord* blk_end);
aoqi@0 287
aoqi@0 288 public:
aoqi@0 289 // The space may not have it's bottom and top set yet, which is why the
brutisso@7256 290 // region is passed as a parameter. The elements of the array are
brutisso@7256 291 // initialized to zero.
brutisso@7256 292 G1BlockOffsetArray(G1BlockOffsetSharedArray* array, MemRegion mr);
aoqi@0 293
aoqi@0 294 // Note: this ought to be part of the constructor, but that would require
aoqi@0 295 // "this" to be passed as a parameter to a member constructor for
aoqi@0 296 // the containing concrete subtype of Space.
aoqi@0 297 // This would be legal C++, but MS VC++ doesn't allow it.
mgerdin@6987 298 void set_space(G1OffsetTableContigSpace* sp);
aoqi@0 299
aoqi@0 300 // Resets the covered region to one with the same _bottom as before but
aoqi@0 301 // the "new_word_size".
aoqi@0 302 void resize(size_t new_word_size);
aoqi@0 303
aoqi@0 304 virtual HeapWord* block_start_unsafe(const void* addr);
aoqi@0 305 virtual HeapWord* block_start_unsafe_const(const void* addr) const;
aoqi@0 306
aoqi@0 307 // Used by region verification. Checks that the contents of the
aoqi@0 308 // BOT reflect that there's a single object that spans the address
aoqi@0 309 // range [obj_start, obj_start + word_size); returns true if this is
aoqi@0 310 // the case, returns false if it's not.
aoqi@0 311 bool verify_for_object(HeapWord* obj_start, size_t word_size) const;
aoqi@0 312
aoqi@0 313 void check_all_cards(size_t left_card, size_t right_card) const;
aoqi@0 314
aoqi@0 315 virtual void print_on(outputStream* out) PRODUCT_RETURN;
aoqi@0 316 };
aoqi@0 317
aoqi@0 318 // A subtype of BlockOffsetArray that takes advantage of the fact
aoqi@0 319 // that its underlying space is a ContiguousSpace, so that its "active"
aoqi@0 320 // region can be more efficiently tracked (than for a non-contiguous space).
aoqi@0 321 class G1BlockOffsetArrayContigSpace: public G1BlockOffsetArray {
aoqi@0 322 friend class VMStructs;
aoqi@0 323
aoqi@0 324 // allocation boundary at which offset array must be updated
aoqi@0 325 HeapWord* _next_offset_threshold;
aoqi@0 326 size_t _next_offset_index; // index corresponding to that boundary
aoqi@0 327
aoqi@0 328 // Work function to be called when allocation start crosses the next
aoqi@0 329 // threshold in the contig space.
aoqi@0 330 void alloc_block_work1(HeapWord* blk_start, HeapWord* blk_end) {
aoqi@0 331 alloc_block_work2(&_next_offset_threshold, &_next_offset_index,
aoqi@0 332 blk_start, blk_end);
aoqi@0 333 }
aoqi@0 334
brutisso@7256 335 // Zero out the entry for _bottom (offset will be zero). Does not check for availability of the
tschatzl@7051 336 // memory first.
tschatzl@7051 337 void zero_bottom_entry_raw();
tschatzl@7051 338 // Variant of initialize_threshold that does not check for availability of the
tschatzl@7051 339 // memory first.
tschatzl@7051 340 HeapWord* initialize_threshold_raw();
aoqi@0 341 public:
aoqi@0 342 G1BlockOffsetArrayContigSpace(G1BlockOffsetSharedArray* array, MemRegion mr);
aoqi@0 343
aoqi@0 344 // Initialize the threshold to reflect the first boundary after the
aoqi@0 345 // bottom of the covered region.
aoqi@0 346 HeapWord* initialize_threshold();
aoqi@0 347
tschatzl@7050 348 void reset_bot() {
tschatzl@7051 349 zero_bottom_entry_raw();
tschatzl@7051 350 initialize_threshold_raw();
tschatzl@7050 351 }
aoqi@0 352
aoqi@0 353 // Return the next threshold, the point at which the table should be
aoqi@0 354 // updated.
aoqi@0 355 HeapWord* threshold() const { return _next_offset_threshold; }
aoqi@0 356
aoqi@0 357 // These must be guaranteed to work properly (i.e., do nothing)
aoqi@0 358 // when "blk_start" ("blk" for second version) is "NULL". In this
aoqi@0 359 // implementation, that's true because NULL is represented as 0, and thus
aoqi@0 360 // never exceeds the "_next_offset_threshold".
aoqi@0 361 void alloc_block(HeapWord* blk_start, HeapWord* blk_end) {
aoqi@0 362 if (blk_end > _next_offset_threshold)
aoqi@0 363 alloc_block_work1(blk_start, blk_end);
aoqi@0 364 }
aoqi@0 365 void alloc_block(HeapWord* blk, size_t size) {
aoqi@0 366 alloc_block(blk, blk+size);
aoqi@0 367 }
aoqi@0 368
aoqi@0 369 HeapWord* block_start_unsafe(const void* addr);
aoqi@0 370 HeapWord* block_start_unsafe_const(const void* addr) const;
aoqi@0 371
aoqi@0 372 void set_for_starts_humongous(HeapWord* new_top);
aoqi@0 373
aoqi@0 374 virtual void print_on(outputStream* out) PRODUCT_RETURN;
aoqi@0 375 };
aoqi@0 376
aoqi@0 377 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_HPP

mercurial