/*
* 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 "precompiled.hpp"
#include "gc_interface/collectedHeap.inline.hpp"
#include "memory/blockOffsetTable.inline.hpp"
#include "memory/iterator.hpp"
#include "memory/space.inline.hpp"
#include "memory/universe.hpp"
#include "oops/oop.inline.hpp"
#include "services/memTracker.hpp"
//////////////////////////////////////////////////////////////////////
// BlockOffsetSharedArray
//////////////////////////////////////////////////////////////////////
{
if (!rs.is_reserved()) {
vm_exit_during_initialization("Could not reserve enough space for heap offset array");
}
vm_exit_during_initialization("Could not reserve enough space for heap offset array");
}
if (TraceBlockOffsetTable) {
" rs.base(): " INTPTR_FORMAT
" rs.size(): " INTPTR_FORMAT
" rs end(): " INTPTR_FORMAT,
" _vs.low_boundary(): " INTPTR_FORMAT
" _vs.high_boundary(): " INTPTR_FORMAT,
_vs.low_boundary(),
_vs.high_boundary());
}
}
// Do better than this for Merlin
}
} else {
if (delta == 0) return;
}
}
}
}
//////////////////////////////////////////////////////////////////////
// BlockOffsetArray
//////////////////////////////////////////////////////////////////////
{
if (!init_to_zero_) {
// initialize cards to point back to mr.start()
}
}
// The arguments follow the normal convention of denoting
// a right-open interval: [start, end)
void
// The start address is equal to the end address (or to
// the right of the end address) so there are not cards
// that need to be updated..
return;
}
// Write the backskip value for each region.
//
// offset
// card 2nd 3rd
// | +- 1st | |
// v v v v
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-
// |x|0|0|0|0|0|0|0|1|1|1|1|1|1| ... |1|1|1|1|2|2|2|2|2|2| ...
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-
// 11 19 75
// 12
//
// offset card is the card that points to the start of an object
// x - offset value of offset card
// 1st - start of first logarithmic region
// 0 corresponds to logarithmic value N_words + 0 and 2**(3 * 0) = 1
// 2nd - start of second logarithmic region
// 1 corresponds to logarithmic value N_words + 1 and 2**(3 * 1) = 8
// 3rd - start of third logarithmic region
// 2 corresponds to logarithmic value N_words + 2 and 2**(3 * 2) = 64
//
// integer below the block offset entry is an example of
// the index of the entry
//
// Given an address,
// Find the index for the address
// Find the block offset table entry
// Convert the entry to a back slide
// (e.g., with today's, offset = 0x81 =>
// back slip = 2**(3*(0x81 - N_words)) = 2**3) = 8
// Move back N (e.g., 8) entries and repeat with the
// value of the new entry
//
}
// Unlike the normal convention in this code, the argument here denotes
// a closed, inclusive interval: [start_card, end_card], cf set_remainder_to_point_to_start()
// above.
void
BlockOffsetArray::set_remainder_to_point_to_start_incl(size_t start_card, size_t end_card, bool reducing) {
if (start_card > end_card) {
return;
}
"Offset card has an unexpected value");
for (int i = 0; i < N_powers; i++) {
// -1 so that the the card with the actual offset is counted. Another -1
// so that the reach ends in this region and not at the start
// of the next.
break;
}
}
}
// The card-interval [start_card, end_card] is a closed interval; this
// is an expensive check -- use with care and only under protection of
// suitable flag.
if (end_card < start_card) {
return;
}
}
if (landing_card >= start_card) {
} else {
// Note that N_words is the maximum offset value
}
}
}
void
"phantom block");
}
// Action_mark - update the BOT for the block [blk_start, blk_end).
// Current typical use is for splitting a block.
// Action_single - udpate the BOT for an allocation.
// Action_verify - BOT verification.
void
"reference must be into the heap");
"limit must be within the heap");
// This is optimized to make the test fast, assuming we only rarely
// cross boundaries.
// Calculate the last card boundary preceding end of blk
// blk starts at or crosses a boundary
// Calculate index of card on which blk begins
// Index of card on which blk ends
// Start address of card on which blk begins
// blk starts strictly after boundary
// adjust card boundary and start_index forward to next card
start_index++;
}
switch (action) {
case Action_mark: {
if (init_to_zero()) {
break;
} // Else fall through to the next case
}
case Action_single: {
// We have finished marking the "offset card". We need to now
// mark the subsequent cards that this blk spans.
if (start_index < end_index) {
}
break;
}
case Action_check: {
// We have finished checking the "offset card". We need to now
// check the subsequent cards that this blk spans.
break;
}
default:
}
}
}
// The range [blk_start, blk_end) represents a single contiguous block
// of storage; modify the block offset table to represent this
// information; Right-open interval: [blk_start, blk_end)
// NOTE: this method does _not_ adjust _unallocated_block.
void
}
// For each entry in the block offset table, verify that
// the entry correctly finds the start of an object at the
// first address covered by the block or to the left of that
// first address.
// Use for debugging. Initialize to NULL to distinguish the
// first iteration through the while loop.
while (next_index <= last_index) {
// Use an address past the start of the address for
// the entry.
if (p >= _end) {
// That's all of the allocated block table.
return;
}
// block_start() asserts that start <= p.
// First check if the start is an allocated block and only
// then if it is a valid object.
o->is_oop_or_null(), "Bad object was found");
next_index++;
last_p = p;
last_start = start;
last_o = o;
}
}
//////////////////////////////////////////////////////////////////////
// BlockOffsetArrayNonContigSpace
//////////////////////////////////////////////////////////////////////
// The block [blk_start, blk_end) has been allocated;
// adjust the block offset table to represent this information;
// NOTE: Clients of BlockOffsetArrayNonContigSpace: consider using
// the somewhat more lightweight split_block() or
// (when init_to_zero()) mark_block() wherever possible.
// right-open interval: [blk_start, blk_end)
void
"phantom block");
}
// Adjust BOT to show that a previously whole block has been split
// into two. We verify the BOT for the first part (prefix) and
// update the BOT for the second part (suffix).
// blk is the start of the block
// blk_size is the size of the original block
// left_blk_size is the size of the first part of the split
// Verify that the BOT shows [blk, blk + blk_size) to be one block.
// Update the BOT to indicate that [blk + left_blk_size, blk + blk_size)
// is one single block.
// Start addresses of prefix block and suffix block.
// Indices for starts of prefix block and suffix block.
// pref_addr does not begin pref_index
pref_index++;
}
// suff_addr does not begin suff_index
suff_index++;
}
// Definition: A block B, denoted [B_start, B_end) __starts__
// a card C, denoted [C_start, C_end), where C_start and C_end
// are the heap addresses that card C covers, iff
// B_start <= C_start < B_end.
//
// We say that a card C "is started by" a block B, iff
// B "starts" C.
//
// Note that the cardinality of the set of cards {C}
// started by a block B can be 0, 1, or more.
//
// Below, pref_index and suff_index are, respectively, the
// first (least) card indices that the prefix and suffix of
// the split start; end_index is one more than the index of
// the last (greatest) card that blk starts.
// Calculate the # cards that the prefix and suffix affect.
// Change the cards that need changing
if (num_suff_cards > 0) {
// Set the offset card for suffix block
// Change any further cards that need changing in the suffix
if (num_pref_cards > 0) {
if (num_pref_cards >= num_suff_cards) {
// Unilaterally fix all of the suffix cards: closed card
// index interval in args below.
} else {
// Unilaterally fix the first (num_pref_cards - 1) following
// the "offset card" in the suffix block.
// Fix the appropriate cards in the remainder of the
// suffix block -- these are the last num_pref_cards
// cards in each power block of the "new" range plumbed
// from suff_addr.
bool more = true;
uint i = 1;
more = false;
}
if (back_by > num_pref_cards) {
// Fill in the remainder of this "power block", if it
// is non-null.
if (left_index <= right_index) {
} else {
more = false; // we are done
}
i++;
break;
}
i++;
}
if (left_index > right_index) {
break;
}
more = false;
}
i++;
}
}
} // else no more cards to fix in suffix
} // else nothing needs to be done
// Verify that we did the right thing
}
// Mark the BOT such that if [blk_start, blk_end) straddles a card
// boundary, the card following the first such boundary is marked
// with the appropriate offset.
// NOTE: this method does _not_ adjust _unallocated_block or
// any cards subsequent to the first one.
void
}
const void* addr) const {
"addr must be covered by this Array");
// Must read this exactly once because it can be modified by parallel
// allocation.
return ub;
}
// Otherwise, find the block start using the table.
// The excess of the offset from N_words indicates a power of Base
// to go back by.
q -= (N_words * n_cards_back);
index -= n_cards_back;
}
index--;
q -= offset;
HeapWord* n = q;
while (n <= addr) {
q = n;
n += _sp->block_size(n);
assert(n > q,
}
q, addr));
addr, n));
return q;
}
const void* addr) const {
"addr must be covered by this Array");
// Must read this exactly once because it can be modified by parallel
// allocation.
return ub;
}
// Otherwise, find the block start using the table, but taking
// on the cards themsleves.
"arg should be start of card");
do {
q -= offset;
} else {
q -= (n_cards_back * N_words);
index -= n_cards_back;
}
return q;
}
#ifndef PRODUCT
// 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) {
}
}
}
// Verify that the given block is before _unallocated_block
}
}
}
#endif // PRODUCT
if (_unallocated_block == _bottom) {
return 0;
} else {
}
}
//////////////////////////////////////////////////////////////////////
// BlockOffsetArrayContigSpace
//////////////////////////////////////////////////////////////////////
// Otherwise, find the block start using the table.
"addr must be covered by this Array");
// We must make sure that the offset table entry we use is valid. If
// "addr" is past the end, start at the last known one and go forward.
// The excess of the offset from N_words indicates a power of Base
// to go back by.
q -= (N_words * n_cards_back);
index -= n_cards_back;
}
q -= N_words;
index--;
}
q -= offset;
HeapWord* n = q;
while (n <= addr) {
q = n;
n += _sp->block_size(n);
}
return q;
}
//
// _next_offset_threshold
// | _next_offset_index
// v v
// +-------+-------+-------+-------+-------+
// | i-1 | i | i+1 | i+2 | i+3 |
// +-------+-------+-------+-------+-------+
// ( ^ ]
// block-start
//
"phantom block");
"should be past threshold");
"blk_start should be at or before threshold");
"offset should be <= BlockOffsetSharedArray::N");
"reference must be into the heap");
"limit must be within the heap");
"index must agree with threshold");
// Mark the card that holds the offset into the block. Note
// that _next_offset_index and _next_offset_threshold are not
// updated until the end of this method.
// We need to now mark the subsequent cards that this blk spans.
// Index of card on which blk ends.
// Are there more cards left to be updated?
// Calculate rem_end this way because end_index
// may be the last valid index in the covered region.
}
// _next_offset_index and _next_offset_threshold updated here.
// Calculate _next_offset_threshold this way because end_index
// may be the last valid index in the covered region.
#ifdef ASSERT
// The offset can be 0 if the block starts on a boundary. That
// is checked by an assertion above.
"offset array should have been set");
"offset array should have been set");
}
#endif
}
"just checking");
return _next_offset_threshold;
}
"just checking");
}
// Null these values so that the serializer won't object to updating them.
_next_offset_index = 0;
}
}
}