342N/A/*
4080N/A * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A *
342N/A * This code is free software; you can redistribute it and/or modify it
342N/A * under the terms of the GNU General Public License version 2 only, as
342N/A * published by the Free Software Foundation.
342N/A *
342N/A * This code is distributed in the hope that it will be useful, but WITHOUT
342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A * version 2 for more details (a copy is included in the LICENSE file that
342N/A * accompanied this code).
342N/A *
342N/A * You should have received a copy of the GNU General Public License version
342N/A * 2 along with this work; if not, write to the Free Software Foundation,
342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
342N/A *
342N/A */
342N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP
1879N/A
1879N/A#include "gc_implementation/g1/g1BlockOffsetTable.hpp"
1879N/A#include "memory/space.hpp"
1879N/A
342N/Ainline HeapWord* G1BlockOffsetTable::block_start(const void* addr) {
342N/A if (addr >= _bottom && addr < _end) {
342N/A return block_start_unsafe(addr);
342N/A } else {
342N/A return NULL;
342N/A }
342N/A}
342N/A
342N/Ainline HeapWord*
342N/AG1BlockOffsetTable::block_start_const(const void* addr) const {
342N/A if (addr >= _bottom && addr < _end) {
342N/A return block_start_unsafe_const(addr);
342N/A } else {
342N/A return NULL;
342N/A }
342N/A}
342N/A
342N/Ainline size_t G1BlockOffsetSharedArray::index_for(const void* p) const {
342N/A char* pc = (char*)p;
342N/A assert(pc >= (char*)_reserved.start() &&
342N/A pc < (char*)_reserved.end(),
4080N/A err_msg("p (" PTR_FORMAT ") not in reserved [" PTR_FORMAT ", " PTR_FORMAT ")",
4080N/A p, (char*)_reserved.start(), (char*)_reserved.end()));
342N/A size_t delta = pointer_delta(pc, _reserved.start(), sizeof(char));
342N/A size_t result = delta >> LogN;
4080N/A check_index(result, "bad index from address");
342N/A return result;
342N/A}
342N/A
342N/Ainline HeapWord*
342N/AG1BlockOffsetSharedArray::address_for_index(size_t index) const {
4080N/A check_index(index, "index out of range");
342N/A HeapWord* result = _reserved.start() + (index << LogN_words);
342N/A assert(result >= _reserved.start() && result < _reserved.end(),
342N/A "bad address from index");
342N/A return result;
342N/A}
342N/A
342N/Ainline HeapWord*
342N/AG1BlockOffsetArray::block_at_or_preceding(const void* addr,
342N/A bool has_max_index,
342N/A size_t max_index) const {
342N/A assert(_array->offset_array(0) == 0, "objects can't cross covered areas");
342N/A size_t index = _array->index_for(addr);
342N/A // We must make sure that the offset table entry we use is valid. If
342N/A // "addr" is past the end, start at the last known one and go forward.
342N/A if (has_max_index) {
342N/A index = MIN2(index, max_index);
342N/A }
342N/A HeapWord* q = _array->address_for_index(index);
342N/A
342N/A uint offset = _array->offset_array(index); // Extend u_char to uint.
342N/A while (offset >= N_words) {
342N/A // The excess of the offset from N_words indicates a power of Base
342N/A // to go back by.
342N/A size_t n_cards_back = BlockOffsetArray::entry_to_cards_back(offset);
342N/A q -= (N_words * n_cards_back);
342N/A assert(q >= _sp->bottom(), "Went below bottom!");
342N/A index -= n_cards_back;
342N/A offset = _array->offset_array(index);
342N/A }
342N/A assert(offset < N_words, "offset too large");
342N/A q -= offset;
342N/A return q;
342N/A}
342N/A
342N/Ainline HeapWord*
342N/AG1BlockOffsetArray::
342N/Aforward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,
342N/A const void* addr) const {
342N/A if (csp() != NULL) {
342N/A if (addr >= csp()->top()) return csp()->top();
342N/A while (n <= addr) {
342N/A q = n;
342N/A oop obj = oop(q);
845N/A if (obj->klass_or_null() == NULL) return q;
342N/A n += obj->size();
342N/A }
342N/A } else {
342N/A while (n <= addr) {
342N/A q = n;
342N/A oop obj = oop(q);
845N/A if (obj->klass_or_null() == NULL) return q;
342N/A n += _sp->block_size(q);
342N/A }
342N/A }
342N/A assert(q <= n, "wrong order for q and addr");
342N/A assert(addr < n, "wrong order for addr and n");
342N/A return q;
342N/A}
342N/A
342N/Ainline HeapWord*
342N/AG1BlockOffsetArray::forward_to_block_containing_addr(HeapWord* q,
342N/A const void* addr) {
845N/A if (oop(q)->klass_or_null() == NULL) return q;
342N/A HeapWord* n = q + _sp->block_size(q);
342N/A // In the normal case, where the query "addr" is a card boundary, and the
342N/A // offset table chunks are the same size as cards, the block starting at
342N/A // "q" will contain addr, so the test below will fail, and we'll fall
342N/A // through quickly.
342N/A if (n <= addr) {
342N/A q = forward_to_block_containing_addr_slow(q, n, addr);
342N/A }
342N/A assert(q <= addr, "wrong order for current and arg");
342N/A return q;
342N/A}
342N/A
342N/A//////////////////////////////////////////////////////////////////////////
342N/A// BlockOffsetArrayNonContigSpace inlines
342N/A//////////////////////////////////////////////////////////////////////////
342N/Ainline void G1BlockOffsetArray::freed(HeapWord* blk_start, HeapWord* blk_end) {
342N/A // Verify that the BOT shows [blk_start, blk_end) to be one block.
342N/A verify_single_block(blk_start, blk_end);
342N/A // adjust _unallocated_block upward or downward
342N/A // as appropriate
342N/A if (BlockOffsetArrayUseUnallocatedBlock) {
342N/A assert(_unallocated_block <= _end,
342N/A "Inconsistent value for _unallocated_block");
342N/A if (blk_end >= _unallocated_block && blk_start <= _unallocated_block) {
342N/A // CMS-specific note: a block abutting _unallocated_block to
342N/A // its left is being freed, a new block is being added or
342N/A // we are resetting following a compaction
342N/A _unallocated_block = blk_start;
342N/A }
342N/A }
342N/A}
342N/A
342N/Ainline void G1BlockOffsetArray::freed(HeapWord* blk, size_t size) {
342N/A freed(blk, blk + size);
342N/A}
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP