Path: blob/master/src/hotspot/share/gc/g1/g1BlockOffsetTable.hpp
40957 views
/*1* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_G1_G1BLOCKOFFSETTABLE_HPP25#define SHARE_GC_G1_G1BLOCKOFFSETTABLE_HPP2627#include "gc/g1/g1RegionToSpaceMapper.hpp"28#include "gc/shared/blockOffsetTable.hpp"29#include "memory/memRegion.hpp"30#include "memory/virtualspace.hpp"31#include "utilities/globalDefinitions.hpp"3233// Forward declarations34class G1BlockOffsetTable;35class HeapRegion;3637// This implementation of "G1BlockOffsetTable" divides the covered region38// into "N"-word subregions (where "N" = 2^"LogN". An array with an entry39// for each such subregion indicates how far back one must go to find the40// start of the chunk that includes the first word of the subregion.41//42// Each G1BlockOffsetTablePart is owned by a HeapRegion.4344class G1BlockOffsetTable: public CHeapObj<mtGC> {45friend class G1BlockOffsetTablePart;46friend class VMStructs;4748private:49// The reserved region covered by the table.50MemRegion _reserved;5152// Array for keeping offsets for retrieving object start fast given an53// address.54volatile u_char* _offset_array; // byte array keeping backwards offsets5556void check_offset(size_t offset, const char* msg) const {57assert(offset <= BOTConstants::N_words,58"%s - offset: " SIZE_FORMAT ", N_words: %u",59msg, offset, BOTConstants::N_words);60}6162// Bounds checking accessors:63// For performance these have to devolve to array accesses in product builds.64inline u_char offset_array(size_t index) const;6566inline void set_offset_array_raw(size_t index, u_char offset);67inline void set_offset_array(size_t index, u_char offset);6869inline void set_offset_array(size_t index, HeapWord* high, HeapWord* low);7071inline void set_offset_array(size_t left, size_t right, u_char offset);7273bool is_card_boundary(HeapWord* p) const;7475void check_index(size_t index, const char* msg) const NOT_DEBUG_RETURN;7677public:7879// Return the number of slots needed for an offset array80// that covers mem_region_words words.81static size_t compute_size(size_t mem_region_words) {82size_t number_of_slots = (mem_region_words / BOTConstants::N_words);83return ReservedSpace::allocation_align_size_up(number_of_slots);84}8586// Returns how many bytes of the heap a single byte of the BOT corresponds to.87static size_t heap_map_factor() {88return BOTConstants::N_bytes;89}9091// Initialize the Block Offset Table to cover the memory region passed92// in the heap parameter.93G1BlockOffsetTable(MemRegion heap, G1RegionToSpaceMapper* storage);9495// Return the appropriate index into "_offset_array" for "p".96inline size_t index_for(const void* p) const;97inline size_t index_for_raw(const void* p) const;9899// Return the address indicating the start of the region corresponding to100// "index" in "_offset_array".101inline HeapWord* address_for_index(size_t index) const;102// Variant of address_for_index that does not check the index for validity.103inline HeapWord* address_for_index_raw(size_t index) const {104return _reserved.start() + (index << BOTConstants::LogN_words);105}106};107108class G1BlockOffsetTablePart {109friend class G1BlockOffsetTable;110friend class VMStructs;111private:112// allocation boundary at which offset array must be updated113HeapWord* _next_offset_threshold;114size_t _next_offset_index; // index corresponding to that boundary115116// Indicates if an object can span into this G1BlockOffsetTablePart.117debug_only(bool _object_can_span;)118119// This is the global BlockOffsetTable.120G1BlockOffsetTable* _bot;121122// The region that owns this subregion.123HeapRegion* _hr;124125// Sets the entries126// corresponding to the cards starting at "start" and ending at "end"127// to point back to the card before "start": the interval [start, end)128// is right-open.129void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end);130// Same as above, except that the args here are a card _index_ interval131// that is closed: [start_index, end_index]132void set_remainder_to_point_to_start_incl(size_t start, size_t end);133134// Zero out the entry for _bottom (offset will be zero). Does not check for availability of the135// memory first.136void zero_bottom_entry_raw();137// Variant of initialize_threshold that does not check for availability of the138// memory first.139HeapWord* initialize_threshold_raw();140141inline size_t block_size(const HeapWord* p) const;142143// Returns the address of a block whose start is at most "addr".144// If "has_max_index" is true, "assumes "max_index" is the last valid one145// in the array.146inline HeapWord* block_at_or_preceding(const void* addr,147bool has_max_index,148size_t max_index) const;149150// "q" is a block boundary that is <= "addr"; "n" is the address of the151// next block (or the end of the space.) Return the address of the152// beginning of the block that contains "addr". Does so without side153// effects (see, e.g., spec of block_start.)154inline HeapWord* forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,155const void* addr) const;156157// "q" is a block boundary that is <= "addr"; return the address of the158// beginning of the block that contains "addr". May have side effects159// on "this", by updating imprecise entries.160inline HeapWord* forward_to_block_containing_addr(HeapWord* q,161const void* addr);162163// "q" is a block boundary that is <= "addr"; "n" is the address of the164// next block (or the end of the space.) Return the address of the165// beginning of the block that contains "addr". May have side effects166// on "this", by updating imprecise entries.167HeapWord* forward_to_block_containing_addr_slow(HeapWord* q,168HeapWord* n,169const void* addr);170171// Requires that "*threshold_" be the first array entry boundary at or172// above "blk_start", and that "*index_" be the corresponding array173// index. If the block starts at or crosses "*threshold_", records174// "blk_start" as the appropriate block start for the array index175// starting at "*threshold_", and for any other indices crossed by the176// block. Updates "*threshold_" and "*index_" to correspond to the first177// index after the block end.178void alloc_block_work(HeapWord** threshold_, size_t* index_,179HeapWord* blk_start, HeapWord* blk_end);180181void check_all_cards(size_t left_card, size_t right_card) const;182183public:184// The elements of the array are initialized to zero.185G1BlockOffsetTablePart(G1BlockOffsetTable* array, HeapRegion* hr);186187void update();188189void verify() const;190191// Returns the address of the start of the block containing "addr", or192// else "null" if it is covered by no block. (May have side effects,193// namely updating of shared array entries that "point" too far194// backwards. This can occur, for example, when lab allocation is used195// in a space covered by the table.)196inline HeapWord* block_start(const void* addr);197// Same as above, but does not have any of the possible side effects198// discussed above.199inline HeapWord* block_start_const(const void* addr) const;200201// Initialize the threshold to reflect the first boundary after the202// bottom of the covered region.203HeapWord* initialize_threshold();204205void reset_bot() {206zero_bottom_entry_raw();207initialize_threshold_raw();208}209210// Return the next threshold, the point at which the table should be211// updated.212HeapWord* threshold() const { return _next_offset_threshold; }213214// These must be guaranteed to work properly (i.e., do nothing)215// when "blk_start" ("blk" for second version) is "NULL". In this216// implementation, that's true because NULL is represented as 0, and thus217// never exceeds the "_next_offset_threshold".218void alloc_block(HeapWord* blk_start, HeapWord* blk_end) {219if (blk_end > _next_offset_threshold) {220alloc_block_work(&_next_offset_threshold, &_next_offset_index, blk_start, blk_end);221}222}223void alloc_block(HeapWord* blk, size_t size) {224alloc_block(blk, blk+size);225}226227void set_for_starts_humongous(HeapWord* obj_top, size_t fill_size);228void set_object_can_span(bool can_span) NOT_DEBUG_RETURN;229230void print_on(outputStream* out) PRODUCT_RETURN;231};232233#endif // SHARE_GC_G1_G1BLOCKOFFSETTABLE_HPP234235236