src/share/vm/memory/blockOffsetTable.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/blockOffsetTable.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,566 @@
     1.4 +/*
     1.5 + * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP
    1.29 +#define SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP
    1.30 +
    1.31 +#include "memory/memRegion.hpp"
    1.32 +#include "runtime/virtualspace.hpp"
    1.33 +#include "utilities/globalDefinitions.hpp"
    1.34 +
    1.35 +// The CollectedHeap type requires subtypes to implement a method
    1.36 +// "block_start".  For some subtypes, notably generational
    1.37 +// systems using card-table-based write barriers, the efficiency of this
    1.38 +// operation may be important.  Implementations of the "BlockOffsetArray"
    1.39 +// class may be useful in providing such efficient implementations.
    1.40 +//
    1.41 +// BlockOffsetTable (abstract)
    1.42 +//   - BlockOffsetArray (abstract)
    1.43 +//     - BlockOffsetArrayNonContigSpace
    1.44 +//     - BlockOffsetArrayContigSpace
    1.45 +//
    1.46 +
    1.47 +class ContiguousSpace;
    1.48 +
    1.49 +//////////////////////////////////////////////////////////////////////////
    1.50 +// The BlockOffsetTable "interface"
    1.51 +//////////////////////////////////////////////////////////////////////////
    1.52 +class BlockOffsetTable VALUE_OBJ_CLASS_SPEC {
    1.53 +  friend class VMStructs;
    1.54 +protected:
    1.55 +  // These members describe the region covered by the table.
    1.56 +
    1.57 +  // The space this table is covering.
    1.58 +  HeapWord* _bottom;    // == reserved.start
    1.59 +  HeapWord* _end;       // End of currently allocated region.
    1.60 +
    1.61 +public:
    1.62 +  // Initialize the table to cover the given space.
    1.63 +  // The contents of the initial table are undefined.
    1.64 +  BlockOffsetTable(HeapWord* bottom, HeapWord* end):
    1.65 +    _bottom(bottom), _end(end) {
    1.66 +    assert(_bottom <= _end, "arguments out of order");
    1.67 +  }
    1.68 +
    1.69 +  // Note that the committed size of the covered space may have changed,
    1.70 +  // so the table size might also wish to change.
    1.71 +  virtual void resize(size_t new_word_size) = 0;
    1.72 +
    1.73 +  virtual void set_bottom(HeapWord* new_bottom) {
    1.74 +    assert(new_bottom <= _end, "new_bottom > _end");
    1.75 +    _bottom = new_bottom;
    1.76 +    resize(pointer_delta(_end, _bottom));
    1.77 +  }
    1.78 +
    1.79 +  // Requires "addr" to be contained by a block, and returns the address of
    1.80 +  // the start of that block.
    1.81 +  virtual HeapWord* block_start_unsafe(const void* addr) const = 0;
    1.82 +
    1.83 +  // Returns the address of the start of the block containing "addr", or
    1.84 +  // else "null" if it is covered by no block.
    1.85 +  HeapWord* block_start(const void* addr) const;
    1.86 +};
    1.87 +
    1.88 +//////////////////////////////////////////////////////////////////////////
    1.89 +// One implementation of "BlockOffsetTable," the BlockOffsetArray,
    1.90 +// divides the covered region into "N"-word subregions (where
    1.91 +// "N" = 2^"LogN".  An array with an entry for each such subregion
    1.92 +// indicates how far back one must go to find the start of the
    1.93 +// chunk that includes the first word of the subregion.
    1.94 +//
    1.95 +// Each BlockOffsetArray is owned by a Space.  However, the actual array
    1.96 +// may be shared by several BlockOffsetArrays; this is useful
    1.97 +// when a single resizable area (such as a generation) is divided up into
    1.98 +// several spaces in which contiguous allocation takes place.  (Consider,
    1.99 +// for example, the garbage-first generation.)
   1.100 +
   1.101 +// Here is the shared array type.
   1.102 +//////////////////////////////////////////////////////////////////////////
   1.103 +// BlockOffsetSharedArray
   1.104 +//////////////////////////////////////////////////////////////////////////
   1.105 +class BlockOffsetSharedArray: public CHeapObj<mtGC> {
   1.106 +  friend class BlockOffsetArray;
   1.107 +  friend class BlockOffsetArrayNonContigSpace;
   1.108 +  friend class BlockOffsetArrayContigSpace;
   1.109 +  friend class VMStructs;
   1.110 +
   1.111 + private:
   1.112 +  enum SomePrivateConstants {
   1.113 +    LogN = 9,
   1.114 +    LogN_words = LogN - LogHeapWordSize,
   1.115 +    N_bytes = 1 << LogN,
   1.116 +    N_words = 1 << LogN_words
   1.117 +  };
   1.118 +
   1.119 +  bool _init_to_zero;
   1.120 +
   1.121 +  // The reserved region covered by the shared array.
   1.122 +  MemRegion _reserved;
   1.123 +
   1.124 +  // End of the current committed region.
   1.125 +  HeapWord* _end;
   1.126 +
   1.127 +  // Array for keeping offsets for retrieving object start fast given an
   1.128 +  // address.
   1.129 +  VirtualSpace _vs;
   1.130 +  u_char* _offset_array;          // byte array keeping backwards offsets
   1.131 +
   1.132 + protected:
   1.133 +  // Bounds checking accessors:
   1.134 +  // For performance these have to devolve to array accesses in product builds.
   1.135 +  u_char offset_array(size_t index) const {
   1.136 +    assert(index < _vs.committed_size(), "index out of range");
   1.137 +    return _offset_array[index];
   1.138 +  }
   1.139 +  // An assertion-checking helper method for the set_offset_array() methods below.
   1.140 +  void check_reducing_assertion(bool reducing);
   1.141 +
   1.142 +  void set_offset_array(size_t index, u_char offset, bool reducing = false) {
   1.143 +    check_reducing_assertion(reducing);
   1.144 +    assert(index < _vs.committed_size(), "index out of range");
   1.145 +    assert(!reducing || _offset_array[index] >= offset, "Not reducing");
   1.146 +    _offset_array[index] = offset;
   1.147 +  }
   1.148 +
   1.149 +  void set_offset_array(size_t index, HeapWord* high, HeapWord* low, bool reducing = false) {
   1.150 +    check_reducing_assertion(reducing);
   1.151 +    assert(index < _vs.committed_size(), "index out of range");
   1.152 +    assert(high >= low, "addresses out of order");
   1.153 +    assert(pointer_delta(high, low) <= N_words, "offset too large");
   1.154 +    assert(!reducing || _offset_array[index] >=  (u_char)pointer_delta(high, low),
   1.155 +           "Not reducing");
   1.156 +    _offset_array[index] = (u_char)pointer_delta(high, low);
   1.157 +  }
   1.158 +
   1.159 +  void set_offset_array(HeapWord* left, HeapWord* right, u_char offset, bool reducing = false) {
   1.160 +    check_reducing_assertion(reducing);
   1.161 +    assert(index_for(right - 1) < _vs.committed_size(),
   1.162 +           "right address out of range");
   1.163 +    assert(left  < right, "Heap addresses out of order");
   1.164 +    size_t num_cards = pointer_delta(right, left) >> LogN_words;
   1.165 +
   1.166 +    // Below, we may use an explicit loop instead of memset()
   1.167 +    // because on certain platforms memset() can give concurrent
   1.168 +    // readers "out-of-thin-air," phantom zeros; see 6948537.
   1.169 +    if (UseMemSetInBOT) {
   1.170 +      memset(&_offset_array[index_for(left)], offset, num_cards);
   1.171 +    } else {
   1.172 +      size_t i = index_for(left);
   1.173 +      const size_t end = i + num_cards;
   1.174 +      for (; i < end; i++) {
   1.175 +        // Elided until CR 6977974 is fixed properly.
   1.176 +        // assert(!reducing || _offset_array[i] >= offset, "Not reducing");
   1.177 +        _offset_array[i] = offset;
   1.178 +      }
   1.179 +    }
   1.180 +  }
   1.181 +
   1.182 +  void set_offset_array(size_t left, size_t right, u_char offset, bool reducing = false) {
   1.183 +    check_reducing_assertion(reducing);
   1.184 +    assert(right < _vs.committed_size(), "right address out of range");
   1.185 +    assert(left  <= right, "indexes out of order");
   1.186 +    size_t num_cards = right - left + 1;
   1.187 +
   1.188 +    // Below, we may use an explicit loop instead of memset
   1.189 +    // because on certain platforms memset() can give concurrent
   1.190 +    // readers "out-of-thin-air," phantom zeros; see 6948537.
   1.191 +    if (UseMemSetInBOT) {
   1.192 +      memset(&_offset_array[left], offset, num_cards);
   1.193 +    } else {
   1.194 +      size_t i = left;
   1.195 +      const size_t end = i + num_cards;
   1.196 +      for (; i < end; i++) {
   1.197 +        // Elided until CR 6977974 is fixed properly.
   1.198 +        // assert(!reducing || _offset_array[i] >= offset, "Not reducing");
   1.199 +        _offset_array[i] = offset;
   1.200 +      }
   1.201 +    }
   1.202 +  }
   1.203 +
   1.204 +  void check_offset_array(size_t index, HeapWord* high, HeapWord* low) const {
   1.205 +    assert(index < _vs.committed_size(), "index out of range");
   1.206 +    assert(high >= low, "addresses out of order");
   1.207 +    assert(pointer_delta(high, low) <= N_words, "offset too large");
   1.208 +    assert(_offset_array[index] == pointer_delta(high, low),
   1.209 +           "Wrong offset");
   1.210 +  }
   1.211 +
   1.212 +  bool is_card_boundary(HeapWord* p) const;
   1.213 +
   1.214 +  // Return the number of slots needed for an offset array
   1.215 +  // that covers mem_region_words words.
   1.216 +  // We always add an extra slot because if an object
   1.217 +  // ends on a card boundary we put a 0 in the next
   1.218 +  // offset array slot, so we want that slot always
   1.219 +  // to be reserved.
   1.220 +
   1.221 +  size_t compute_size(size_t mem_region_words) {
   1.222 +    size_t number_of_slots = (mem_region_words / N_words) + 1;
   1.223 +    return ReservedSpace::allocation_align_size_up(number_of_slots);
   1.224 +  }
   1.225 +
   1.226 +public:
   1.227 +  // Initialize the table to cover from "base" to (at least)
   1.228 +  // "base + init_word_size".  In the future, the table may be expanded
   1.229 +  // (see "resize" below) up to the size of "_reserved" (which must be at
   1.230 +  // least "init_word_size".)  The contents of the initial table are
   1.231 +  // undefined; it is the responsibility of the constituent
   1.232 +  // BlockOffsetTable(s) to initialize cards.
   1.233 +  BlockOffsetSharedArray(MemRegion reserved, size_t init_word_size);
   1.234 +
   1.235 +  // Notes a change in the committed size of the region covered by the
   1.236 +  // table.  The "new_word_size" may not be larger than the size of the
   1.237 +  // reserved region this table covers.
   1.238 +  void resize(size_t new_word_size);
   1.239 +
   1.240 +  void set_bottom(HeapWord* new_bottom);
   1.241 +
   1.242 +  // Whether entries should be initialized to zero. Used currently only for
   1.243 +  // error checking.
   1.244 +  void set_init_to_zero(bool val) { _init_to_zero = val; }
   1.245 +  bool init_to_zero() { return _init_to_zero; }
   1.246 +
   1.247 +  // Updates all the BlockOffsetArray's sharing this shared array to
   1.248 +  // reflect the current "top"'s of their spaces.
   1.249 +  void update_offset_arrays();   // Not yet implemented!
   1.250 +
   1.251 +  // Return the appropriate index into "_offset_array" for "p".
   1.252 +  size_t index_for(const void* p) const;
   1.253 +
   1.254 +  // Return the address indicating the start of the region corresponding to
   1.255 +  // "index" in "_offset_array".
   1.256 +  HeapWord* address_for_index(size_t index) const;
   1.257 +
   1.258 +  // Return the address "p" incremented by the size of
   1.259 +  // a region.  This method does not align the address
   1.260 +  // returned to the start of a region.  It is a simple
   1.261 +  // primitive.
   1.262 +  HeapWord* inc_by_region_size(HeapWord* p) const { return p + N_words; }
   1.263 +};
   1.264 +
   1.265 +//////////////////////////////////////////////////////////////////////////
   1.266 +// The BlockOffsetArray whose subtypes use the BlockOffsetSharedArray.
   1.267 +//////////////////////////////////////////////////////////////////////////
   1.268 +class BlockOffsetArray: public BlockOffsetTable {
   1.269 +  friend class VMStructs;
   1.270 +  friend class G1BlockOffsetArray; // temp. until we restructure and cleanup
   1.271 + protected:
   1.272 +  // The following enums are used by do_block_internal() below
   1.273 +  enum Action {
   1.274 +    Action_single,      // BOT records a single block (see single_block())
   1.275 +    Action_mark,        // BOT marks the start of a block (see mark_block())
   1.276 +    Action_check        // Check that BOT records block correctly
   1.277 +                        // (see verify_single_block()).
   1.278 +  };
   1.279 +
   1.280 +  enum SomePrivateConstants {
   1.281 +    N_words = BlockOffsetSharedArray::N_words,
   1.282 +    LogN    = BlockOffsetSharedArray::LogN,
   1.283 +    // entries "e" of at least N_words mean "go back by Base^(e-N_words)."
   1.284 +    // All entries are less than "N_words + N_powers".
   1.285 +    LogBase = 4,
   1.286 +    Base = (1 << LogBase),
   1.287 +    N_powers = 14
   1.288 +  };
   1.289 +
   1.290 +  static size_t power_to_cards_back(uint i) {
   1.291 +    return (size_t)1 << (LogBase * i);
   1.292 +  }
   1.293 +  static size_t power_to_words_back(uint i) {
   1.294 +    return power_to_cards_back(i) * N_words;
   1.295 +  }
   1.296 +  static size_t entry_to_cards_back(u_char entry) {
   1.297 +    assert(entry >= N_words, "Precondition");
   1.298 +    return power_to_cards_back(entry - N_words);
   1.299 +  }
   1.300 +  static size_t entry_to_words_back(u_char entry) {
   1.301 +    assert(entry >= N_words, "Precondition");
   1.302 +    return power_to_words_back(entry - N_words);
   1.303 +  }
   1.304 +
   1.305 +  // The shared array, which is shared with other BlockOffsetArray's
   1.306 +  // corresponding to different spaces within a generation or span of
   1.307 +  // memory.
   1.308 +  BlockOffsetSharedArray* _array;
   1.309 +
   1.310 +  // The space that owns this subregion.
   1.311 +  Space* _sp;
   1.312 +
   1.313 +  // If true, array entries are initialized to 0; otherwise, they are
   1.314 +  // initialized to point backwards to the beginning of the covered region.
   1.315 +  bool _init_to_zero;
   1.316 +
   1.317 +  // An assertion-checking helper method for the set_remainder*() methods below.
   1.318 +  void check_reducing_assertion(bool reducing) { _array->check_reducing_assertion(reducing); }
   1.319 +
   1.320 +  // Sets the entries
   1.321 +  // corresponding to the cards starting at "start" and ending at "end"
   1.322 +  // to point back to the card before "start": the interval [start, end)
   1.323 +  // is right-open. The last parameter, reducing, indicates whether the
   1.324 +  // updates to individual entries always reduce the entry from a higher
   1.325 +  // to a lower value. (For example this would hold true during a temporal
   1.326 +  // regime during which only block splits were updating the BOT.
   1.327 +  void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end, bool reducing = false);
   1.328 +  // Same as above, except that the args here are a card _index_ interval
   1.329 +  // that is closed: [start_index, end_index]
   1.330 +  void set_remainder_to_point_to_start_incl(size_t start, size_t end, bool reducing = false);
   1.331 +
   1.332 +  // A helper function for BOT adjustment/verification work
   1.333 +  void do_block_internal(HeapWord* blk_start, HeapWord* blk_end, Action action, bool reducing = false);
   1.334 +
   1.335 + public:
   1.336 +  // The space may not have its bottom and top set yet, which is why the
   1.337 +  // region is passed as a parameter.  If "init_to_zero" is true, the
   1.338 +  // elements of the array are initialized to zero.  Otherwise, they are
   1.339 +  // initialized to point backwards to the beginning.
   1.340 +  BlockOffsetArray(BlockOffsetSharedArray* array, MemRegion mr,
   1.341 +                   bool init_to_zero_);
   1.342 +
   1.343 +  // Note: this ought to be part of the constructor, but that would require
   1.344 +  // "this" to be passed as a parameter to a member constructor for
   1.345 +  // the containing concrete subtype of Space.
   1.346 +  // This would be legal C++, but MS VC++ doesn't allow it.
   1.347 +  void set_space(Space* sp) { _sp = sp; }
   1.348 +
   1.349 +  // Resets the covered region to the given "mr".
   1.350 +  void set_region(MemRegion mr) {
   1.351 +    _bottom = mr.start();
   1.352 +    _end = mr.end();
   1.353 +  }
   1.354 +
   1.355 +  // Note that the committed size of the covered space may have changed,
   1.356 +  // so the table size might also wish to change.
   1.357 +  virtual void resize(size_t new_word_size) {
   1.358 +    HeapWord* new_end = _bottom + new_word_size;
   1.359 +    if (_end < new_end && !init_to_zero()) {
   1.360 +      // verify that the old and new boundaries are also card boundaries
   1.361 +      assert(_array->is_card_boundary(_end),
   1.362 +             "_end not a card boundary");
   1.363 +      assert(_array->is_card_boundary(new_end),
   1.364 +             "new _end would not be a card boundary");
   1.365 +      // set all the newly added cards
   1.366 +      _array->set_offset_array(_end, new_end, N_words);
   1.367 +    }
   1.368 +    _end = new_end;  // update _end
   1.369 +  }
   1.370 +
   1.371 +  // Adjust the BOT to show that it has a single block in the
   1.372 +  // range [blk_start, blk_start + size). All necessary BOT
   1.373 +  // cards are adjusted, but _unallocated_block isn't.
   1.374 +  void single_block(HeapWord* blk_start, HeapWord* blk_end);
   1.375 +  void single_block(HeapWord* blk, size_t size) {
   1.376 +    single_block(blk, blk + size);
   1.377 +  }
   1.378 +
   1.379 +  // When the alloc_block() call returns, the block offset table should
   1.380 +  // have enough information such that any subsequent block_start() call
   1.381 +  // with an argument equal to an address that is within the range
   1.382 +  // [blk_start, blk_end) would return the value blk_start, provided
   1.383 +  // there have been no calls in between that reset this information
   1.384 +  // (e.g. see BlockOffsetArrayNonContigSpace::single_block() call
   1.385 +  // for an appropriate range covering the said interval).
   1.386 +  // These methods expect to be called with [blk_start, blk_end)
   1.387 +  // representing a block of memory in the heap.
   1.388 +  virtual void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
   1.389 +  void alloc_block(HeapWord* blk, size_t size) {
   1.390 +    alloc_block(blk, blk + size);
   1.391 +  }
   1.392 +
   1.393 +  // If true, initialize array slots with no allocated blocks to zero.
   1.394 +  // Otherwise, make them point back to the front.
   1.395 +  bool init_to_zero() { return _init_to_zero; }
   1.396 +  // Corresponding setter
   1.397 +  void set_init_to_zero(bool val) {
   1.398 +    _init_to_zero = val;
   1.399 +    assert(_array != NULL, "_array should be non-NULL");
   1.400 +    _array->set_init_to_zero(val);
   1.401 +  }
   1.402 +
   1.403 +  // Debugging
   1.404 +  // Return the index of the last entry in the "active" region.
   1.405 +  virtual size_t last_active_index() const = 0;
   1.406 +  // Verify the block offset table
   1.407 +  void verify() const;
   1.408 +  void check_all_cards(size_t left_card, size_t right_card) const;
   1.409 +};
   1.410 +
   1.411 +////////////////////////////////////////////////////////////////////////////
   1.412 +// A subtype of BlockOffsetArray that takes advantage of the fact
   1.413 +// that its underlying space is a NonContiguousSpace, so that some
   1.414 +// specialized interfaces can be made available for spaces that
   1.415 +// manipulate the table.
   1.416 +////////////////////////////////////////////////////////////////////////////
   1.417 +class BlockOffsetArrayNonContigSpace: public BlockOffsetArray {
   1.418 +  friend class VMStructs;
   1.419 + private:
   1.420 +  // The portion [_unallocated_block, _sp.end()) of the space that
   1.421 +  // is a single block known not to contain any objects.
   1.422 +  // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag.
   1.423 +  HeapWord* _unallocated_block;
   1.424 +
   1.425 + public:
   1.426 +  BlockOffsetArrayNonContigSpace(BlockOffsetSharedArray* array, MemRegion mr):
   1.427 +    BlockOffsetArray(array, mr, false),
   1.428 +    _unallocated_block(_bottom) { }
   1.429 +
   1.430 +  // accessor
   1.431 +  HeapWord* unallocated_block() const {
   1.432 +    assert(BlockOffsetArrayUseUnallocatedBlock,
   1.433 +           "_unallocated_block is not being maintained");
   1.434 +    return _unallocated_block;
   1.435 +  }
   1.436 +
   1.437 +  void set_unallocated_block(HeapWord* block) {
   1.438 +    assert(BlockOffsetArrayUseUnallocatedBlock,
   1.439 +           "_unallocated_block is not being maintained");
   1.440 +    assert(block >= _bottom && block <= _end, "out of range");
   1.441 +    _unallocated_block = block;
   1.442 +  }
   1.443 +
   1.444 +  // These methods expect to be called with [blk_start, blk_end)
   1.445 +  // representing a block of memory in the heap.
   1.446 +  void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
   1.447 +  void alloc_block(HeapWord* blk, size_t size) {
   1.448 +    alloc_block(blk, blk + size);
   1.449 +  }
   1.450 +
   1.451 +  // The following methods are useful and optimized for a
   1.452 +  // non-contiguous space.
   1.453 +
   1.454 +  // Given a block [blk_start, blk_start + full_blk_size), and
   1.455 +  // a left_blk_size < full_blk_size, adjust the BOT to show two
   1.456 +  // blocks [blk_start, blk_start + left_blk_size) and
   1.457 +  // [blk_start + left_blk_size, blk_start + full_blk_size).
   1.458 +  // It is assumed (and verified in the non-product VM) that the
   1.459 +  // BOT was correct for the original block.
   1.460 +  void split_block(HeapWord* blk_start, size_t full_blk_size,
   1.461 +                           size_t left_blk_size);
   1.462 +
   1.463 +  // Adjust BOT to show that it has a block in the range
   1.464 +  // [blk_start, blk_start + size). Only the first card
   1.465 +  // of BOT is touched. It is assumed (and verified in the
   1.466 +  // non-product VM) that the remaining cards of the block
   1.467 +  // are correct.
   1.468 +  void mark_block(HeapWord* blk_start, HeapWord* blk_end, bool reducing = false);
   1.469 +  void mark_block(HeapWord* blk, size_t size, bool reducing = false) {
   1.470 +    mark_block(blk, blk + size, reducing);
   1.471 +  }
   1.472 +
   1.473 +  // Adjust _unallocated_block to indicate that a particular
   1.474 +  // block has been newly allocated or freed. It is assumed (and
   1.475 +  // verified in the non-product VM) that the BOT is correct for
   1.476 +  // the given block.
   1.477 +  void allocated(HeapWord* blk_start, HeapWord* blk_end, bool reducing = false) {
   1.478 +    // Verify that the BOT shows [blk, blk + blk_size) to be one block.
   1.479 +    verify_single_block(blk_start, blk_end);
   1.480 +    if (BlockOffsetArrayUseUnallocatedBlock) {
   1.481 +      _unallocated_block = MAX2(_unallocated_block, blk_end);
   1.482 +    }
   1.483 +  }
   1.484 +
   1.485 +  void allocated(HeapWord* blk, size_t size, bool reducing = false) {
   1.486 +    allocated(blk, blk + size, reducing);
   1.487 +  }
   1.488 +
   1.489 +  void freed(HeapWord* blk_start, HeapWord* blk_end);
   1.490 +  void freed(HeapWord* blk, size_t size);
   1.491 +
   1.492 +  HeapWord* block_start_unsafe(const void* addr) const;
   1.493 +
   1.494 +  // Requires "addr" to be the start of a card and returns the
   1.495 +  // start of the block that contains the given address.
   1.496 +  HeapWord* block_start_careful(const void* addr) const;
   1.497 +
   1.498 +  // Verification & debugging: ensure that the offset table reflects
   1.499 +  // the fact that the block [blk_start, blk_end) or [blk, blk + size)
   1.500 +  // is a single block of storage. NOTE: can't const this because of
   1.501 +  // call to non-const do_block_internal() below.
   1.502 +  void verify_single_block(HeapWord* blk_start, HeapWord* blk_end)
   1.503 +    PRODUCT_RETURN;
   1.504 +  void verify_single_block(HeapWord* blk, size_t size) PRODUCT_RETURN;
   1.505 +
   1.506 +  // Verify that the given block is before _unallocated_block
   1.507 +  void verify_not_unallocated(HeapWord* blk_start, HeapWord* blk_end)
   1.508 +    const PRODUCT_RETURN;
   1.509 +  void verify_not_unallocated(HeapWord* blk, size_t size)
   1.510 +    const PRODUCT_RETURN;
   1.511 +
   1.512 +  // Debugging support
   1.513 +  virtual size_t last_active_index() const;
   1.514 +};
   1.515 +
   1.516 +////////////////////////////////////////////////////////////////////////////
   1.517 +// A subtype of BlockOffsetArray that takes advantage of the fact
   1.518 +// that its underlying space is a ContiguousSpace, so that its "active"
   1.519 +// region can be more efficiently tracked (than for a non-contiguous space).
   1.520 +////////////////////////////////////////////////////////////////////////////
   1.521 +class BlockOffsetArrayContigSpace: public BlockOffsetArray {
   1.522 +  friend class VMStructs;
   1.523 + private:
   1.524 +  // allocation boundary at which offset array must be updated
   1.525 +  HeapWord* _next_offset_threshold;
   1.526 +  size_t    _next_offset_index;      // index corresponding to that boundary
   1.527 +
   1.528 +  // Work function when allocation start crosses threshold.
   1.529 +  void alloc_block_work(HeapWord* blk_start, HeapWord* blk_end);
   1.530 +
   1.531 + public:
   1.532 +  BlockOffsetArrayContigSpace(BlockOffsetSharedArray* array, MemRegion mr):
   1.533 +    BlockOffsetArray(array, mr, true) {
   1.534 +    _next_offset_threshold = NULL;
   1.535 +    _next_offset_index = 0;
   1.536 +  }
   1.537 +
   1.538 +  void set_contig_space(ContiguousSpace* sp) { set_space((Space*)sp); }
   1.539 +
   1.540 +  // Initialize the threshold for an empty heap.
   1.541 +  HeapWord* initialize_threshold();
   1.542 +  // Zero out the entry for _bottom (offset will be zero)
   1.543 +  void      zero_bottom_entry();
   1.544 +
   1.545 +  // Return the next threshold, the point at which the table should be
   1.546 +  // updated.
   1.547 +  HeapWord* threshold() const { return _next_offset_threshold; }
   1.548 +
   1.549 +  // In general, these methods expect to be called with
   1.550 +  // [blk_start, blk_end) representing a block of memory in the heap.
   1.551 +  // In this implementation, however, we are OK even if blk_start and/or
   1.552 +  // blk_end are NULL because NULL is represented as 0, and thus
   1.553 +  // never exceeds the "_next_offset_threshold".
   1.554 +  void alloc_block(HeapWord* blk_start, HeapWord* blk_end) {
   1.555 +    if (blk_end > _next_offset_threshold) {
   1.556 +      alloc_block_work(blk_start, blk_end);
   1.557 +    }
   1.558 +  }
   1.559 +  void alloc_block(HeapWord* blk, size_t size) {
   1.560 +    alloc_block(blk, blk + size);
   1.561 +  }
   1.562 +
   1.563 +  HeapWord* block_start_unsafe(const void* addr) const;
   1.564 +
   1.565 +  // Debugging support
   1.566 +  virtual size_t last_active_index() const;
   1.567 +};
   1.568 +
   1.569 +#endif // SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP

mercurial