/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "memory/memRegion.hpp"
#include "runtime/virtualspace.hpp"
#include "utilities/globalDefinitions.hpp"
// The CollectedHeap type requires subtypes to implement a method
// "block_start". For some subtypes, notably generational
// systems using card-table-based write barriers, the efficiency of this
// operation may be important. Implementations of the "BlockOffsetArray"
// class may be useful in providing such efficient implementations.
//
// While generally mirroring the structure of the BOT for GenCollectedHeap,
// the following types are tailored more towards G1's uses; these should,
// however, be merged back into a common BOT to avoid code duplication
// and reduce maintenance overhead.
//
// G1BlockOffsetTable (abstract)
// -- G1BlockOffsetArray (uses G1BlockOffsetSharedArray)
// -- G1BlockOffsetArrayContigSpace
//
// A main impediment to the consolidation of this code might be the
// effect of making some of the block_start*() calls non-const as
// below. Whether that might adversely affect performance optimizations
// that compilers might normally perform in the case of non-G1
// collectors needs to be carefully investigated prior to any such
// consolidation.
// Forward declarations
class ContiguousSpace;
class G1BlockOffsetSharedArray;
friend class VMStructs;
protected:
// These members describe the region covered by the table.
// The space this table is covering.
public:
// Initialize the table to cover the given space.
// The contents of the initial table are undefined.
{
}
// Note that the committed size of the covered space may have changed,
// so the table size might also wish to change.
new_bottom, _end));
}
// Requires "addr" to be contained by a block, and returns the address of
// the start of that block. (May have side effects, namely updating of
// shared array entries that "point" too far backwards. This can occur,
// for example, when LAB allocation is used in a space covered by the
// table.)
// Same as above, but does not have any of the possible side effects
// discussed above.
// Returns the address of the start of the block containing "addr", or
// else "null" if it is covered by no block. (May have side effects,
// namely updating of shared array entries that "point" too far
// backwards. This can occur, for example, when lab allocation is used
// in a space covered by the table.)
// Same as above, but does not have any of the possible side effects
// discussed above.
};
// This implementation of "G1BlockOffsetTable" divides the covered region
// into "N"-word subregions (where "N" = 2^"LogN". An array with an entry
// for each such subregion indicates how far back one must go to find the
// start of the chunk that includes the first word of the subregion.
//
// Each BlockOffsetArray is owned by a Space. However, the actual array
// may be shared by several BlockOffsetArrays; this is useful
// when a single resizable area (such as a generation) is divided up into
// several spaces in which contiguous allocation takes place,
// such as, for example, in G1 or in the train generation.)
// Here is the shared array type.
friend class G1BlockOffsetArray;
friend class G1BlockOffsetArrayContigSpace;
friend class VMStructs;
private:
// The reserved region covered by the shared array.
// End of the current committed region.
// Array for keeping offsets for retrieving object start fast given an
// address.
err_msg("%s - "
}
err_msg("%s - "
}
// Bounds checking accessors:
// For performance these have to devolve to array accesses in product builds.
return _offset_array[index];
}
}
}
if (UseMemSetInBOT) {
} else {
for (; i < end; i++) {
_offset_array[i] = offset;
}
}
}
if (UseMemSetInBOT) {
} else {
for (; i < end; i++) {
_offset_array[i] = offset;
}
}
}
}
bool is_card_boundary(HeapWord* p) const;
// Return the number of slots needed for an offset array
// that covers mem_region_words words.
// We always add an extra slot because if an object
// ends on a card boundary we put a 0 in the next
// offset array slot, so we want that slot always
// to be reserved.
}
public:
enum SomePublicConstants {
LogN = 9,
};
// Initialize the table to cover from "base" to (at least)
// "base + init_word_size". In the future, the table may be expanded
// (see "resize" below) up to the size of "_reserved" (which must be at
// least "init_word_size".) The contents of the initial table are
// undefined; it is the responsibility of the constituent
// G1BlockOffsetTable(s) to initialize cards.
// Notes a change in the committed size of the region covered by the
// table. The "new_word_size" may not be larger than the size of the
// reserved region this table covers.
// Updates all the BlockOffsetArray's sharing this shared array to
// reflect the current "top"'s of their spaces.
void update_offset_arrays();
// Return the appropriate index into "_offset_array" for "p".
// Return the address indicating the start of the region corresponding to
// "index" in "_offset_array".
};
// And here is the G1BlockOffsetTable subtype that uses the array.
class G1BlockOffsetArray: public G1BlockOffsetTable {
friend class G1BlockOffsetSharedArray;
friend class G1BlockOffsetArrayContigSpace;
friend class VMStructs;
private:
enum SomePrivateConstants {
};
// The following enums are used by do_block_helper
enum Action {
Action_single, // BOT records a single block (see single_block())
Action_mark, // BOT marks the start of a block (see mark_block())
Action_check // Check that BOT records block correctly
// (see verify_single_block()).
};
// This is the array, which can be shared by several BlockOffsetArray's
// servicing different
// The space that owns this subregion.
// If "_sp" is a contiguous space, the field below is the view of "_sp"
// as a contiguous space, else NULL.
// If true, array entries are initialized to 0; otherwise, they are
// initialized to point backwards to the beginning of the covered region.
bool _init_to_zero;
// The portion [_unallocated_block, _sp.end()) of the space that
// is a single block known not to contain any objects.
// NOTE: See BlockOffsetArrayUseUnallocatedBlock flag.
// Sets the entries
// corresponding to the cards starting at "start" and ending at "end"
// to point back to the card before "start": the interval [start, end)
// is right-open.
// Same as above, except that the args here are a card _index_ interval
// that is closed: [start_index, end_index]
// A helper function for BOT adjustment/verification work
protected:
// Returns the address of a block whose start is at most "addr".
// If "has_max_index" is true, "assumes "max_index" is the last valid one
// in the array.
bool has_max_index,
// "q" is a block boundary that is <= "addr"; "n" is the address of the
// next block (or the end of the space.) Return the address of the
// beginning of the block that contains "addr". Does so without side
// effects (see, e.g., spec of block_start.)
inline HeapWord*
const void* addr) const;
// "q" is a block boundary that is <= "addr"; return the address of the
// beginning of the block that contains "addr". May have side effects
// on "this", by updating imprecise entries.
const void* addr);
// "q" is a block boundary that is <= "addr"; "n" is the address of the
// next block (or the end of the space.) Return the address of the
// beginning of the block that contains "addr". May have side effects
// on "this", by updating imprecise entries.
HeapWord* n,
const void* addr);
// Requires that "*threshold_" be the first array entry boundary at or
// above "blk_start", and that "*index_" be the corresponding array
// index. If the block starts at or crosses "*threshold_", records
// "blk_start" as the appropriate block start for the array index
// starting at "*threshold_", and for any other indices crossed by the
// block. Updates "*threshold_" and "*index_" to correspond to the first
// index after the block end.
public:
// The space may not have it's bottom and top set yet, which is why the
// region is passed as a parameter. If "init_to_zero" is true, the
// elements of the array are initialized to zero. Otherwise, they are
// initialized to point backwards to the beginning.
bool init_to_zero);
// Note: this ought to be part of the constructor, but that would require
// "this" to be passed as a parameter to a member constructor for
// the containing concrete subtype of Space.
// This would be legal C++, but MS VC++ doesn't allow it.
// Resets the covered region to the given "mr".
// Resets the covered region to one with the same _bottom as before but
// the "new_word_size".
// These must be guaranteed to work properly (i.e., do nothing)
// when "blk_start" ("blk" for second version) is "NULL".
}
// The following methods are useful and optimized for a
// general, non-contiguous space.
// Given a block [blk_start, blk_start + full_blk_size), and
// a left_blk_size < full_blk_size, adjust the BOT to show two
// blocks [blk_start, blk_start + left_blk_size) and
// [blk_start + left_blk_size, blk_start + full_blk_size).
// It is assumed (and verified in the non-product VM) that the
// BOT was correct for the original block.
// Adjust the BOT to show that it has a single block in the
// range [blk_start, blk_start + size). All necessary BOT
// cards are adjusted, but _unallocated_block isn't.
}
// Adjust BOT to show that it has a block in the range
// [blk_start, blk_start + size). Only the first card
// of BOT is touched. It is assumed (and verified in the
// non-product VM) that the remaining cards of the block
// are correct.
}
// Adjust _unallocated_block to indicate that a particular
// block has been newly allocated or freed. It is assumed (and
// verified in the non-product VM) that the BOT is correct for
// the given block.
// Verify that the BOT shows [blk, blk + blk_size) to be one block.
}
}
}
// Requires "addr" to be the start of a card and returns the
// start of the block that contains the given address.
// If true, initialize array slots with no allocated blocks to zero.
// Otherwise, make them point back to the front.
bool init_to_zero() { return _init_to_zero; }
// Verification & debugging - ensure that the offset table reflects the fact
// that the block [blk_start, blk_end) or [blk, blk + size) is a
// single block of storage. NOTE: can;t const this because of
// call to non-const do_block_internal() below.
if (VerifyBlockOffsetArray) {
}
}
}
// Used by region verification. Checks that the contents of the
// BOT reflect that there's a single object that spans the address
// range [obj_start, obj_start + word_size); returns true if this is
// the case, returns false if it's not.
// Verify that the given block is before _unallocated_block
}
}
}
};
// A subtype of BlockOffsetArray that takes advantage of the fact
// that its underlying space is a ContiguousSpace, so that its "active"
// region can be more efficiently tracked (than for a non-contiguous space).
class G1BlockOffsetArrayContigSpace: public G1BlockOffsetArray {
friend class VMStructs;
// allocation boundary at which offset array must be updated
// Work function to be called when allocation start crosses the next
// threshold in the contig space.
}
public:
// Initialize the threshold to reflect the first boundary after the
// bottom of the covered region.
// Zero out the entry for _bottom (offset will be zero).
void zero_bottom_entry();
// Return the next threshold, the point at which the table should be
// updated.
// These must be guaranteed to work properly (i.e., do nothing)
// when "blk_start" ("blk" for second version) is "NULL". In this
// implementation, that's true because NULL is represented as 0, and thus
// never exceeds the "_next_offset_threshold".
if (blk_end > _next_offset_threshold)
}
}
};
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_HPP