blockOffsetTable.hpp revision 645
337N/A * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A// The CollectedHeap type requires subtypes to implement a method 0N/A// "block_start". For some subtypes, notably generational 0N/A// systems using card-table-based write barriers, the efficiency of this 0N/A// operation may be important. Implementations of the "BlockOffsetArray" 0N/A// class may be useful in providing such efficient implementations. 0N/A// BlockOffsetTable (abstract) 0N/A// - BlockOffsetArray (abstract) 0N/A// - BlockOffsetArrayNonContigSpace 0N/A// - BlockOffsetArrayContigSpace 0N/A////////////////////////////////////////////////////////////////////////// 0N/A// The BlockOffsetTable "interface" 0N/A////////////////////////////////////////////////////////////////////////// 0N/A // These members describe the region covered by the table. 0N/A // The space this table is covering. 0N/A // Initialize the table to cover the given space. 0N/A // The contents of the initial table are undefined. 0N/A // Note that the committed size of the covered space may have changed, 0N/A // so the table size might also wish to change. 0N/A // Requires "addr" to be contained by a block, and returns the address of 0N/A // the start of that block. 0N/A // Returns the address of the start of the block containing "addr", or 0N/A // else "null" if it is covered by no block. 0N/A////////////////////////////////////////////////////////////////////////// 0N/A// One implementation of "BlockOffsetTable," the BlockOffsetArray, 0N/A// divides the covered region into "N"-word subregions (where 0N/A// "N" = 2^"LogN". An array with an entry for each such subregion 0N/A// indicates how far back one must go to find the start of the 0N/A// chunk that includes the first word of the subregion. 0N/A// Each BlockOffsetArray is owned by a Space. However, the actual array 0N/A// may be shared by several BlockOffsetArrays; this is useful 0N/A// when a single resizable area (such as a generation) is divided up into 0N/A// several spaces in which contiguous allocation takes place. (Consider, 0N/A// for example, the garbage-first generation.) 0N/A// Here is the shared array type. 0N/A////////////////////////////////////////////////////////////////////////// 0N/A// BlockOffsetSharedArray 0N/A////////////////////////////////////////////////////////////////////////// 0N/A // The reserved region covered by the shared array. 0N/A // End of the current committed region. 0N/A // Array for keeping offsets for retrieving object start fast given an 0N/A // Bounds checking accessors: 0N/A // For performance these have to devolve to array accesses in product builds. 0N/A "right address out of range");
0N/A // Return the number of slots needed for an offset array 0N/A // that covers mem_region_words words. 0N/A // We always add an extra slot because if an object 0N/A // ends on a card boundary we put a 0 in the next 0N/A // offset array slot, so we want that slot always 0N/A // Initialize the table to cover from "base" to (at least) 0N/A // "base + init_word_size". In the future, the table may be expanded 0N/A // (see "resize" below) up to the size of "_reserved" (which must be at 0N/A // least "init_word_size".) The contents of the initial table are 0N/A // undefined; it is the responsibility of the constituent 0N/A // BlockOffsetTable(s) to initialize cards. 0N/A // Notes a change in the committed size of the region covered by the 0N/A // table. The "new_word_size" may not be larger than the size of the 0N/A // reserved region this table covers. 0N/A // Updates all the BlockOffsetArray's sharing this shared array to 0N/A // reflect the current "top"'s of their spaces. 0N/A // Return the appropriate index into "_offset_array" for "p". 0N/A // Return the address indicating the start of the region corresponding to 0N/A // "index" in "_offset_array". 301N/A // Return the address "p" incremented by the size of 301N/A // a region. This method does not align the address 301N/A // returned to the start of a region. It is a simple 0N/A // Shared space support 0N/A////////////////////////////////////////////////////////////////////////// 0N/A// The BlockOffsetArray whose subtypes use the BlockOffsetSharedArray. 0N/A////////////////////////////////////////////////////////////////////////// 0N/A // The following enums are used by do_block_internal() below 0N/A // (see verify_single_block()). 0N/A // entries "e" of at least N_words mean "go back by Base^(e-N_words)." 0N/A // All entries are less than "N_words + N_powers". 0N/A // The shared array, which is shared with other BlockOffsetArray's 0N/A // corresponding to different spaces within a generation or span of 0N/A // The space that owns this subregion. 0N/A // If true, array entries are initialized to 0; otherwise, they are 0N/A // initialized to point backwards to the beginning of the covered region. 0N/A // corresponding to the cards starting at "start" and ending at "end" 0N/A // to point back to the card before "start": the interval [start, end) 0N/A // Same as above, except that the args here are a card _index_ interval 0N/A // that is closed: [start_index, end_index] 0N/A // The space may not have its bottom and top set yet, which is why the 0N/A // region is passed as a parameter. If "init_to_zero" is true, the 0N/A // elements of the array are initialized to zero. Otherwise, they are 0N/A // initialized to point backwards to the beginning. 0N/A // Note: this ought to be part of the constructor, but that would require 0N/A // "this" to be passed as a parameter to a member constructor for 0N/A // the containing concrete subtype of Space. 0N/A // This would be legal C++, but MS VC++ doesn't allow it. 0N/A // Resets the covered region to the given "mr". 0N/A // Note that the committed size of the covered space may have changed, 0N/A // so the table size might also wish to change. 0N/A // verify that the old and new boundaries are also card boundaries 0N/A "_end not a card boundary");
0N/A "new _end would not be a card boundary");
0N/A // set all the newly added cards 0N/A // Adjust the BOT to show that it has a single block in the 0N/A // range [blk_start, blk_start + size). All necessary BOT 0N/A // cards are adjusted, but _unallocated_block isn't. 0N/A // When the alloc_block() call returns, the block offset table should 0N/A // have enough information such that any subsequent block_start() call 0N/A // with an argument equal to an address that is within the range 0N/A // [blk_start, blk_end) would return the value blk_start, provided 0N/A // there have been no calls in between that reset this information 0N/A // (e.g. see BlockOffsetArrayNonContigSpace::single_block() call 0N/A // for an appropriate range covering the said interval). 0N/A // These methods expect to be called with [blk_start, blk_end) 0N/A // representing a block of memory in the heap. 0N/A // If true, initialize array slots with no allocated blocks to zero. 0N/A // Otherwise, make them point back to the front. 0N/A // Return the index of the last entry in the "active" region. 0N/A // Verify the block offset table 0N/A//////////////////////////////////////////////////////////////////////////// 0N/A// A subtype of BlockOffsetArray that takes advantage of the fact 0N/A// that its underlying space is a NonContiguousSpace, so that some 0N/A// specialized interfaces can be made available for spaces that 0N/A// manipulate the table. 0N/A//////////////////////////////////////////////////////////////////////////// 0N/A // The portion [_unallocated_block, _sp.end()) of the space that 0N/A // is a single block known not to contain any objects. 0N/A // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag. 0N/A "_unallocated_block is not being maintained");
0N/A "_unallocated_block is not being maintained");
0N/A // These methods expect to be called with [blk_start, blk_end) 0N/A // representing a block of memory in the heap. 0N/A // The following methods are useful and optimized for a 0N/A // non-contiguous space. 0N/A // Given a block [blk_start, blk_start + full_blk_size), and 0N/A // a left_blk_size < full_blk_size, adjust the BOT to show two 0N/A // blocks [blk_start, blk_start + left_blk_size) and 0N/A // [blk_start + left_blk_size, blk_start + full_blk_size). 0N/A // It is assumed (and verified in the non-product VM) that the 0N/A // BOT was correct for the original block. 0N/A // Adjust BOT to show that it has a block in the range 0N/A // [blk_start, blk_start + size). Only the first card 0N/A // of BOT is touched. It is assumed (and verified in the 0N/A // non-product VM) that the remaining cards of the block 0N/A // Adjust _unallocated_block to indicate that a particular 0N/A // block has been newly allocated or freed. It is assumed (and 0N/A // verified in the non-product VM) that the BOT is correct for 0N/A // Verify that the BOT shows [blk, blk + blk_size) to be one block. 0N/A // Requires "addr" to be the start of a card and returns the 0N/A // start of the block that contains the given address. 0N/A // Verification & debugging: ensure that the offset table reflects 0N/A // the fact that the block [blk_start, blk_end) or [blk, blk + size) 0N/A // is a single block of storage. NOTE: can't const this because of 0N/A // call to non-const do_block_internal() below. 0N/A // Verify that the given block is before _unallocated_block 0N/A // Debugging support 0N/A//////////////////////////////////////////////////////////////////////////// 0N/A// A subtype of BlockOffsetArray that takes advantage of the fact 0N/A// that its underlying space is a ContiguousSpace, so that its "active" 0N/A// region can be more efficiently tracked (than for a non-contiguous space). 0N/A//////////////////////////////////////////////////////////////////////////// 0N/A // allocation boundary at which offset array must be updated 0N/A // Work function when allocation start crosses threshold. 0N/A // Initialize the threshold for an empty heap. 0N/A // Zero out the entry for _bottom (offset will be zero) 0N/A // Return the next threshold, the point at which the table should be 0N/A // In general, these methods expect to be called with 0N/A // [blk_start, blk_end) representing a block of memory in the heap. 0N/A // In this implementation, however, we are OK even if blk_start and/or 0N/A // blk_end are NULL because NULL is represented as 0, and thus 0N/A // never exceeds the "_next_offset_threshold". 0N/A // Debugging support