aoqi@0: /* aoqi@0: * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP aoqi@0: #define SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP aoqi@0: aoqi@0: #include "memory/memRegion.hpp" aoqi@0: #include "runtime/virtualspace.hpp" aoqi@0: #include "utilities/globalDefinitions.hpp" aoqi@0: aoqi@0: // The CollectedHeap type requires subtypes to implement a method aoqi@0: // "block_start". For some subtypes, notably generational aoqi@0: // systems using card-table-based write barriers, the efficiency of this aoqi@0: // operation may be important. Implementations of the "BlockOffsetArray" aoqi@0: // class may be useful in providing such efficient implementations. aoqi@0: // aoqi@0: // BlockOffsetTable (abstract) aoqi@0: // - BlockOffsetArray (abstract) aoqi@0: // - BlockOffsetArrayNonContigSpace aoqi@0: // - BlockOffsetArrayContigSpace aoqi@0: // aoqi@0: aoqi@0: class ContiguousSpace; aoqi@0: aoqi@0: ////////////////////////////////////////////////////////////////////////// aoqi@0: // The BlockOffsetTable "interface" aoqi@0: ////////////////////////////////////////////////////////////////////////// aoqi@0: class BlockOffsetTable VALUE_OBJ_CLASS_SPEC { aoqi@0: friend class VMStructs; aoqi@0: protected: aoqi@0: // These members describe the region covered by the table. aoqi@0: aoqi@0: // The space this table is covering. aoqi@0: HeapWord* _bottom; // == reserved.start aoqi@0: HeapWord* _end; // End of currently allocated region. aoqi@0: aoqi@0: public: aoqi@0: // Initialize the table to cover the given space. aoqi@0: // The contents of the initial table are undefined. aoqi@0: BlockOffsetTable(HeapWord* bottom, HeapWord* end): aoqi@0: _bottom(bottom), _end(end) { aoqi@0: assert(_bottom <= _end, "arguments out of order"); aoqi@0: } aoqi@0: aoqi@0: // Note that the committed size of the covered space may have changed, aoqi@0: // so the table size might also wish to change. aoqi@0: virtual void resize(size_t new_word_size) = 0; aoqi@0: aoqi@0: virtual void set_bottom(HeapWord* new_bottom) { aoqi@0: assert(new_bottom <= _end, "new_bottom > _end"); aoqi@0: _bottom = new_bottom; aoqi@0: resize(pointer_delta(_end, _bottom)); aoqi@0: } aoqi@0: aoqi@0: // Requires "addr" to be contained by a block, and returns the address of aoqi@0: // the start of that block. aoqi@0: virtual HeapWord* block_start_unsafe(const void* addr) const = 0; aoqi@0: aoqi@0: // Returns the address of the start of the block containing "addr", or aoqi@0: // else "null" if it is covered by no block. aoqi@0: HeapWord* block_start(const void* addr) const; aoqi@0: }; aoqi@0: aoqi@0: ////////////////////////////////////////////////////////////////////////// aoqi@0: // One implementation of "BlockOffsetTable," the BlockOffsetArray, aoqi@0: // divides the covered region into "N"-word subregions (where aoqi@0: // "N" = 2^"LogN". An array with an entry for each such subregion aoqi@0: // indicates how far back one must go to find the start of the aoqi@0: // chunk that includes the first word of the subregion. aoqi@0: // aoqi@0: // Each BlockOffsetArray is owned by a Space. However, the actual array aoqi@0: // may be shared by several BlockOffsetArrays; this is useful aoqi@0: // when a single resizable area (such as a generation) is divided up into aoqi@0: // several spaces in which contiguous allocation takes place. (Consider, aoqi@0: // for example, the garbage-first generation.) aoqi@0: aoqi@0: // Here is the shared array type. aoqi@0: ////////////////////////////////////////////////////////////////////////// aoqi@0: // BlockOffsetSharedArray aoqi@0: ////////////////////////////////////////////////////////////////////////// aoqi@0: class BlockOffsetSharedArray: public CHeapObj { aoqi@0: friend class BlockOffsetArray; aoqi@0: friend class BlockOffsetArrayNonContigSpace; aoqi@0: friend class BlockOffsetArrayContigSpace; aoqi@0: friend class VMStructs; aoqi@0: aoqi@0: private: aoqi@0: enum SomePrivateConstants { aoqi@0: LogN = 9, aoqi@0: LogN_words = LogN - LogHeapWordSize, aoqi@0: N_bytes = 1 << LogN, aoqi@0: N_words = 1 << LogN_words aoqi@0: }; aoqi@0: aoqi@0: bool _init_to_zero; aoqi@0: aoqi@0: // The reserved region covered by the shared array. aoqi@0: MemRegion _reserved; aoqi@0: aoqi@0: // End of the current committed region. aoqi@0: HeapWord* _end; aoqi@0: aoqi@0: // Array for keeping offsets for retrieving object start fast given an aoqi@0: // address. aoqi@0: VirtualSpace _vs; aoqi@0: u_char* _offset_array; // byte array keeping backwards offsets aoqi@0: aoqi@0: protected: aoqi@0: // Bounds checking accessors: aoqi@0: // For performance these have to devolve to array accesses in product builds. aoqi@0: u_char offset_array(size_t index) const { aoqi@0: assert(index < _vs.committed_size(), "index out of range"); aoqi@0: return _offset_array[index]; aoqi@0: } aoqi@0: // An assertion-checking helper method for the set_offset_array() methods below. aoqi@0: void check_reducing_assertion(bool reducing); aoqi@0: aoqi@0: void set_offset_array(size_t index, u_char offset, bool reducing = false) { aoqi@0: check_reducing_assertion(reducing); aoqi@0: assert(index < _vs.committed_size(), "index out of range"); aoqi@0: assert(!reducing || _offset_array[index] >= offset, "Not reducing"); aoqi@0: _offset_array[index] = offset; aoqi@0: } aoqi@0: aoqi@0: void set_offset_array(size_t index, HeapWord* high, HeapWord* low, bool reducing = false) { aoqi@0: check_reducing_assertion(reducing); aoqi@0: assert(index < _vs.committed_size(), "index out of range"); aoqi@0: assert(high >= low, "addresses out of order"); aoqi@0: assert(pointer_delta(high, low) <= N_words, "offset too large"); aoqi@0: assert(!reducing || _offset_array[index] >= (u_char)pointer_delta(high, low), aoqi@0: "Not reducing"); aoqi@0: _offset_array[index] = (u_char)pointer_delta(high, low); aoqi@0: } aoqi@0: aoqi@0: void set_offset_array(HeapWord* left, HeapWord* right, u_char offset, bool reducing = false) { aoqi@0: check_reducing_assertion(reducing); aoqi@0: assert(index_for(right - 1) < _vs.committed_size(), aoqi@0: "right address out of range"); aoqi@0: assert(left < right, "Heap addresses out of order"); aoqi@0: size_t num_cards = pointer_delta(right, left) >> LogN_words; aoqi@0: aoqi@0: // Below, we may use an explicit loop instead of memset() aoqi@0: // because on certain platforms memset() can give concurrent aoqi@0: // readers "out-of-thin-air," phantom zeros; see 6948537. aoqi@0: if (UseMemSetInBOT) { aoqi@0: memset(&_offset_array[index_for(left)], offset, num_cards); aoqi@0: } else { aoqi@0: size_t i = index_for(left); aoqi@0: const size_t end = i + num_cards; aoqi@0: for (; i < end; i++) { aoqi@0: // Elided until CR 6977974 is fixed properly. aoqi@0: // assert(!reducing || _offset_array[i] >= offset, "Not reducing"); aoqi@0: _offset_array[i] = offset; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void set_offset_array(size_t left, size_t right, u_char offset, bool reducing = false) { aoqi@0: check_reducing_assertion(reducing); aoqi@0: assert(right < _vs.committed_size(), "right address out of range"); aoqi@0: assert(left <= right, "indexes out of order"); aoqi@0: size_t num_cards = right - left + 1; aoqi@0: aoqi@0: // Below, we may use an explicit loop instead of memset aoqi@0: // because on certain platforms memset() can give concurrent aoqi@0: // readers "out-of-thin-air," phantom zeros; see 6948537. aoqi@0: if (UseMemSetInBOT) { aoqi@0: memset(&_offset_array[left], offset, num_cards); aoqi@0: } else { aoqi@0: size_t i = left; aoqi@0: const size_t end = i + num_cards; aoqi@0: for (; i < end; i++) { aoqi@0: // Elided until CR 6977974 is fixed properly. aoqi@0: // assert(!reducing || _offset_array[i] >= offset, "Not reducing"); aoqi@0: _offset_array[i] = offset; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void check_offset_array(size_t index, HeapWord* high, HeapWord* low) const { aoqi@0: assert(index < _vs.committed_size(), "index out of range"); aoqi@0: assert(high >= low, "addresses out of order"); aoqi@0: assert(pointer_delta(high, low) <= N_words, "offset too large"); aoqi@0: assert(_offset_array[index] == pointer_delta(high, low), aoqi@0: "Wrong offset"); aoqi@0: } aoqi@0: aoqi@0: bool is_card_boundary(HeapWord* p) const; aoqi@0: aoqi@0: // Return the number of slots needed for an offset array aoqi@0: // that covers mem_region_words words. aoqi@0: // We always add an extra slot because if an object aoqi@0: // ends on a card boundary we put a 0 in the next aoqi@0: // offset array slot, so we want that slot always aoqi@0: // to be reserved. aoqi@0: aoqi@0: size_t compute_size(size_t mem_region_words) { aoqi@0: size_t number_of_slots = (mem_region_words / N_words) + 1; aoqi@0: return ReservedSpace::allocation_align_size_up(number_of_slots); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: // Initialize the table to cover from "base" to (at least) aoqi@0: // "base + init_word_size". In the future, the table may be expanded aoqi@0: // (see "resize" below) up to the size of "_reserved" (which must be at aoqi@0: // least "init_word_size".) The contents of the initial table are aoqi@0: // undefined; it is the responsibility of the constituent aoqi@0: // BlockOffsetTable(s) to initialize cards. aoqi@0: BlockOffsetSharedArray(MemRegion reserved, size_t init_word_size); aoqi@0: aoqi@0: // Notes a change in the committed size of the region covered by the aoqi@0: // table. The "new_word_size" may not be larger than the size of the aoqi@0: // reserved region this table covers. aoqi@0: void resize(size_t new_word_size); aoqi@0: aoqi@0: void set_bottom(HeapWord* new_bottom); aoqi@0: aoqi@0: // Whether entries should be initialized to zero. Used currently only for aoqi@0: // error checking. aoqi@0: void set_init_to_zero(bool val) { _init_to_zero = val; } aoqi@0: bool init_to_zero() { return _init_to_zero; } aoqi@0: aoqi@0: // Updates all the BlockOffsetArray's sharing this shared array to aoqi@0: // reflect the current "top"'s of their spaces. aoqi@0: void update_offset_arrays(); // Not yet implemented! aoqi@0: aoqi@0: // Return the appropriate index into "_offset_array" for "p". aoqi@0: size_t index_for(const void* p) const; aoqi@0: aoqi@0: // Return the address indicating the start of the region corresponding to aoqi@0: // "index" in "_offset_array". aoqi@0: HeapWord* address_for_index(size_t index) const; aoqi@0: aoqi@0: // Return the address "p" incremented by the size of aoqi@0: // a region. This method does not align the address aoqi@0: // returned to the start of a region. It is a simple aoqi@0: // primitive. aoqi@0: HeapWord* inc_by_region_size(HeapWord* p) const { return p + N_words; } aoqi@0: }; aoqi@0: aoqi@0: ////////////////////////////////////////////////////////////////////////// aoqi@0: // The BlockOffsetArray whose subtypes use the BlockOffsetSharedArray. aoqi@0: ////////////////////////////////////////////////////////////////////////// aoqi@0: class BlockOffsetArray: public BlockOffsetTable { aoqi@0: friend class VMStructs; aoqi@0: friend class G1BlockOffsetArray; // temp. until we restructure and cleanup aoqi@0: protected: aoqi@0: // The following enums are used by do_block_internal() below aoqi@0: enum Action { aoqi@0: Action_single, // BOT records a single block (see single_block()) aoqi@0: Action_mark, // BOT marks the start of a block (see mark_block()) aoqi@0: Action_check // Check that BOT records block correctly aoqi@0: // (see verify_single_block()). aoqi@0: }; aoqi@0: aoqi@0: enum SomePrivateConstants { aoqi@0: N_words = BlockOffsetSharedArray::N_words, aoqi@0: LogN = BlockOffsetSharedArray::LogN, aoqi@0: // entries "e" of at least N_words mean "go back by Base^(e-N_words)." aoqi@0: // All entries are less than "N_words + N_powers". aoqi@0: LogBase = 4, aoqi@0: Base = (1 << LogBase), aoqi@0: N_powers = 14 aoqi@0: }; aoqi@0: aoqi@0: static size_t power_to_cards_back(uint i) { aoqi@0: return (size_t)1 << (LogBase * i); aoqi@0: } aoqi@0: static size_t power_to_words_back(uint i) { aoqi@0: return power_to_cards_back(i) * N_words; aoqi@0: } aoqi@0: static size_t entry_to_cards_back(u_char entry) { aoqi@0: assert(entry >= N_words, "Precondition"); aoqi@0: return power_to_cards_back(entry - N_words); aoqi@0: } aoqi@0: static size_t entry_to_words_back(u_char entry) { aoqi@0: assert(entry >= N_words, "Precondition"); aoqi@0: return power_to_words_back(entry - N_words); aoqi@0: } aoqi@0: aoqi@0: // The shared array, which is shared with other BlockOffsetArray's aoqi@0: // corresponding to different spaces within a generation or span of aoqi@0: // memory. aoqi@0: BlockOffsetSharedArray* _array; aoqi@0: aoqi@0: // The space that owns this subregion. aoqi@0: Space* _sp; aoqi@0: aoqi@0: // If true, array entries are initialized to 0; otherwise, they are aoqi@0: // initialized to point backwards to the beginning of the covered region. aoqi@0: bool _init_to_zero; aoqi@0: aoqi@0: // An assertion-checking helper method for the set_remainder*() methods below. aoqi@0: void check_reducing_assertion(bool reducing) { _array->check_reducing_assertion(reducing); } aoqi@0: aoqi@0: // Sets the entries aoqi@0: // corresponding to the cards starting at "start" and ending at "end" aoqi@0: // to point back to the card before "start": the interval [start, end) aoqi@0: // is right-open. The last parameter, reducing, indicates whether the aoqi@0: // updates to individual entries always reduce the entry from a higher aoqi@0: // to a lower value. (For example this would hold true during a temporal aoqi@0: // regime during which only block splits were updating the BOT. aoqi@0: void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end, bool reducing = false); aoqi@0: // Same as above, except that the args here are a card _index_ interval aoqi@0: // that is closed: [start_index, end_index] aoqi@0: void set_remainder_to_point_to_start_incl(size_t start, size_t end, bool reducing = false); aoqi@0: aoqi@0: // A helper function for BOT adjustment/verification work aoqi@0: void do_block_internal(HeapWord* blk_start, HeapWord* blk_end, Action action, bool reducing = false); aoqi@0: aoqi@0: public: aoqi@0: // The space may not have its bottom and top set yet, which is why the aoqi@0: // region is passed as a parameter. If "init_to_zero" is true, the aoqi@0: // elements of the array are initialized to zero. Otherwise, they are aoqi@0: // initialized to point backwards to the beginning. aoqi@0: BlockOffsetArray(BlockOffsetSharedArray* array, MemRegion mr, aoqi@0: bool init_to_zero_); aoqi@0: aoqi@0: // Note: this ought to be part of the constructor, but that would require aoqi@0: // "this" to be passed as a parameter to a member constructor for aoqi@0: // the containing concrete subtype of Space. aoqi@0: // This would be legal C++, but MS VC++ doesn't allow it. aoqi@0: void set_space(Space* sp) { _sp = sp; } aoqi@0: aoqi@0: // Resets the covered region to the given "mr". aoqi@0: void set_region(MemRegion mr) { aoqi@0: _bottom = mr.start(); aoqi@0: _end = mr.end(); aoqi@0: } aoqi@0: aoqi@0: // Note that the committed size of the covered space may have changed, aoqi@0: // so the table size might also wish to change. aoqi@0: virtual void resize(size_t new_word_size) { aoqi@0: HeapWord* new_end = _bottom + new_word_size; aoqi@0: if (_end < new_end && !init_to_zero()) { aoqi@0: // verify that the old and new boundaries are also card boundaries aoqi@0: assert(_array->is_card_boundary(_end), aoqi@0: "_end not a card boundary"); aoqi@0: assert(_array->is_card_boundary(new_end), aoqi@0: "new _end would not be a card boundary"); aoqi@0: // set all the newly added cards aoqi@0: _array->set_offset_array(_end, new_end, N_words); aoqi@0: } aoqi@0: _end = new_end; // update _end aoqi@0: } aoqi@0: aoqi@0: // Adjust the BOT to show that it has a single block in the aoqi@0: // range [blk_start, blk_start + size). All necessary BOT aoqi@0: // cards are adjusted, but _unallocated_block isn't. aoqi@0: void single_block(HeapWord* blk_start, HeapWord* blk_end); aoqi@0: void single_block(HeapWord* blk, size_t size) { aoqi@0: single_block(blk, blk + size); aoqi@0: } aoqi@0: aoqi@0: // When the alloc_block() call returns, the block offset table should aoqi@0: // have enough information such that any subsequent block_start() call aoqi@0: // with an argument equal to an address that is within the range aoqi@0: // [blk_start, blk_end) would return the value blk_start, provided aoqi@0: // there have been no calls in between that reset this information aoqi@0: // (e.g. see BlockOffsetArrayNonContigSpace::single_block() call aoqi@0: // for an appropriate range covering the said interval). aoqi@0: // These methods expect to be called with [blk_start, blk_end) aoqi@0: // representing a block of memory in the heap. aoqi@0: virtual void alloc_block(HeapWord* blk_start, HeapWord* blk_end); aoqi@0: void alloc_block(HeapWord* blk, size_t size) { aoqi@0: alloc_block(blk, blk + size); aoqi@0: } aoqi@0: aoqi@0: // If true, initialize array slots with no allocated blocks to zero. aoqi@0: // Otherwise, make them point back to the front. aoqi@0: bool init_to_zero() { return _init_to_zero; } aoqi@0: // Corresponding setter aoqi@0: void set_init_to_zero(bool val) { aoqi@0: _init_to_zero = val; aoqi@0: assert(_array != NULL, "_array should be non-NULL"); aoqi@0: _array->set_init_to_zero(val); aoqi@0: } aoqi@0: aoqi@0: // Debugging aoqi@0: // Return the index of the last entry in the "active" region. aoqi@0: virtual size_t last_active_index() const = 0; aoqi@0: // Verify the block offset table aoqi@0: void verify() const; aoqi@0: void check_all_cards(size_t left_card, size_t right_card) const; aoqi@0: }; aoqi@0: aoqi@0: //////////////////////////////////////////////////////////////////////////// aoqi@0: // A subtype of BlockOffsetArray that takes advantage of the fact aoqi@0: // that its underlying space is a NonContiguousSpace, so that some aoqi@0: // specialized interfaces can be made available for spaces that aoqi@0: // manipulate the table. aoqi@0: //////////////////////////////////////////////////////////////////////////// aoqi@0: class BlockOffsetArrayNonContigSpace: public BlockOffsetArray { aoqi@0: friend class VMStructs; aoqi@0: private: aoqi@0: // The portion [_unallocated_block, _sp.end()) of the space that aoqi@0: // is a single block known not to contain any objects. aoqi@0: // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag. aoqi@0: HeapWord* _unallocated_block; aoqi@0: aoqi@0: public: aoqi@0: BlockOffsetArrayNonContigSpace(BlockOffsetSharedArray* array, MemRegion mr): aoqi@0: BlockOffsetArray(array, mr, false), aoqi@0: _unallocated_block(_bottom) { } aoqi@0: aoqi@0: // accessor aoqi@0: HeapWord* unallocated_block() const { aoqi@0: assert(BlockOffsetArrayUseUnallocatedBlock, aoqi@0: "_unallocated_block is not being maintained"); aoqi@0: return _unallocated_block; aoqi@0: } aoqi@0: aoqi@0: void set_unallocated_block(HeapWord* block) { aoqi@0: assert(BlockOffsetArrayUseUnallocatedBlock, aoqi@0: "_unallocated_block is not being maintained"); aoqi@0: assert(block >= _bottom && block <= _end, "out of range"); aoqi@0: _unallocated_block = block; aoqi@0: } aoqi@0: aoqi@0: // These methods expect to be called with [blk_start, blk_end) aoqi@0: // representing a block of memory in the heap. aoqi@0: void alloc_block(HeapWord* blk_start, HeapWord* blk_end); aoqi@0: void alloc_block(HeapWord* blk, size_t size) { aoqi@0: alloc_block(blk, blk + size); aoqi@0: } aoqi@0: aoqi@0: // The following methods are useful and optimized for a aoqi@0: // non-contiguous space. aoqi@0: aoqi@0: // Given a block [blk_start, blk_start + full_blk_size), and aoqi@0: // a left_blk_size < full_blk_size, adjust the BOT to show two aoqi@0: // blocks [blk_start, blk_start + left_blk_size) and aoqi@0: // [blk_start + left_blk_size, blk_start + full_blk_size). aoqi@0: // It is assumed (and verified in the non-product VM) that the aoqi@0: // BOT was correct for the original block. aoqi@0: void split_block(HeapWord* blk_start, size_t full_blk_size, aoqi@0: size_t left_blk_size); aoqi@0: aoqi@0: // Adjust BOT to show that it has a block in the range aoqi@0: // [blk_start, blk_start + size). Only the first card aoqi@0: // of BOT is touched. It is assumed (and verified in the aoqi@0: // non-product VM) that the remaining cards of the block aoqi@0: // are correct. aoqi@0: void mark_block(HeapWord* blk_start, HeapWord* blk_end, bool reducing = false); aoqi@0: void mark_block(HeapWord* blk, size_t size, bool reducing = false) { aoqi@0: mark_block(blk, blk + size, reducing); aoqi@0: } aoqi@0: aoqi@0: // Adjust _unallocated_block to indicate that a particular aoqi@0: // block has been newly allocated or freed. It is assumed (and aoqi@0: // verified in the non-product VM) that the BOT is correct for aoqi@0: // the given block. aoqi@0: void allocated(HeapWord* blk_start, HeapWord* blk_end, bool reducing = false) { aoqi@0: // Verify that the BOT shows [blk, blk + blk_size) to be one block. aoqi@0: verify_single_block(blk_start, blk_end); aoqi@0: if (BlockOffsetArrayUseUnallocatedBlock) { aoqi@0: _unallocated_block = MAX2(_unallocated_block, blk_end); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void allocated(HeapWord* blk, size_t size, bool reducing = false) { aoqi@0: allocated(blk, blk + size, reducing); aoqi@0: } aoqi@0: aoqi@0: void freed(HeapWord* blk_start, HeapWord* blk_end); aoqi@0: void freed(HeapWord* blk, size_t size); aoqi@0: aoqi@0: HeapWord* block_start_unsafe(const void* addr) const; aoqi@0: aoqi@0: // Requires "addr" to be the start of a card and returns the aoqi@0: // start of the block that contains the given address. aoqi@0: HeapWord* block_start_careful(const void* addr) const; aoqi@0: aoqi@0: // Verification & debugging: ensure that the offset table reflects aoqi@0: // the fact that the block [blk_start, blk_end) or [blk, blk + size) aoqi@0: // is a single block of storage. NOTE: can't const this because of aoqi@0: // call to non-const do_block_internal() below. aoqi@0: void verify_single_block(HeapWord* blk_start, HeapWord* blk_end) aoqi@0: PRODUCT_RETURN; aoqi@0: void verify_single_block(HeapWord* blk, size_t size) PRODUCT_RETURN; aoqi@0: aoqi@0: // Verify that the given block is before _unallocated_block aoqi@0: void verify_not_unallocated(HeapWord* blk_start, HeapWord* blk_end) aoqi@0: const PRODUCT_RETURN; aoqi@0: void verify_not_unallocated(HeapWord* blk, size_t size) aoqi@0: const PRODUCT_RETURN; aoqi@0: aoqi@0: // Debugging support aoqi@0: virtual size_t last_active_index() const; aoqi@0: }; aoqi@0: aoqi@0: //////////////////////////////////////////////////////////////////////////// aoqi@0: // A subtype of BlockOffsetArray that takes advantage of the fact aoqi@0: // that its underlying space is a ContiguousSpace, so that its "active" aoqi@0: // region can be more efficiently tracked (than for a non-contiguous space). aoqi@0: //////////////////////////////////////////////////////////////////////////// aoqi@0: class BlockOffsetArrayContigSpace: public BlockOffsetArray { aoqi@0: friend class VMStructs; aoqi@0: private: aoqi@0: // allocation boundary at which offset array must be updated aoqi@0: HeapWord* _next_offset_threshold; aoqi@0: size_t _next_offset_index; // index corresponding to that boundary aoqi@0: aoqi@0: // Work function when allocation start crosses threshold. aoqi@0: void alloc_block_work(HeapWord* blk_start, HeapWord* blk_end); aoqi@0: aoqi@0: public: aoqi@0: BlockOffsetArrayContigSpace(BlockOffsetSharedArray* array, MemRegion mr): aoqi@0: BlockOffsetArray(array, mr, true) { aoqi@0: _next_offset_threshold = NULL; aoqi@0: _next_offset_index = 0; aoqi@0: } aoqi@0: aoqi@0: void set_contig_space(ContiguousSpace* sp) { set_space((Space*)sp); } aoqi@0: aoqi@0: // Initialize the threshold for an empty heap. aoqi@0: HeapWord* initialize_threshold(); aoqi@0: // Zero out the entry for _bottom (offset will be zero) aoqi@0: void zero_bottom_entry(); aoqi@0: aoqi@0: // Return the next threshold, the point at which the table should be aoqi@0: // updated. aoqi@0: HeapWord* threshold() const { return _next_offset_threshold; } aoqi@0: aoqi@0: // In general, these methods expect to be called with aoqi@0: // [blk_start, blk_end) representing a block of memory in the heap. aoqi@0: // In this implementation, however, we are OK even if blk_start and/or aoqi@0: // blk_end are NULL because NULL is represented as 0, and thus aoqi@0: // never exceeds the "_next_offset_threshold". aoqi@0: void alloc_block(HeapWord* blk_start, HeapWord* blk_end) { aoqi@0: if (blk_end > _next_offset_threshold) { aoqi@0: alloc_block_work(blk_start, blk_end); aoqi@0: } aoqi@0: } aoqi@0: void alloc_block(HeapWord* blk, size_t size) { aoqi@0: alloc_block(blk, blk + size); aoqi@0: } aoqi@0: aoqi@0: HeapWord* block_start_unsafe(const void* addr) const; aoqi@0: aoqi@0: // Debugging support aoqi@0: virtual size_t last_active_index() const; aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP