Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.inline.hpp
38920 views
/*1* Copyright (c) 2001, 2014, 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_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP25#define SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP2627#include "gc_implementation/g1/g1BlockOffsetTable.hpp"28#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"29#include "gc_implementation/g1/heapRegion.inline.hpp"30#include "memory/space.hpp"3132inline HeapWord* G1BlockOffsetTable::block_start(const void* addr) {33if (addr >= _bottom && addr < _end) {34return block_start_unsafe(addr);35} else {36return NULL;37}38}3940inline HeapWord*41G1BlockOffsetTable::block_start_const(const void* addr) const {42if (addr >= _bottom && addr < _end) {43return block_start_unsafe_const(addr);44} else {45return NULL;46}47}4849#define check_index(index, msg) \50assert((index) < (_reserved.word_size() >> LogN_words), \51err_msg("%s - index: " SIZE_FORMAT ", _vs.committed_size: " SIZE_FORMAT, \52msg, (index), (_reserved.word_size() >> LogN_words))); \53assert(G1CollectedHeap::heap()->is_in_exact(address_for_index_raw(index)), \54err_msg("Index " SIZE_FORMAT " corresponding to " PTR_FORMAT \55" (%u) is not in committed area.", \56(index), \57p2i(address_for_index_raw(index)), \58G1CollectedHeap::heap()->addr_to_region(address_for_index_raw(index))));5960u_char G1BlockOffsetSharedArray::offset_array(size_t index) const {61check_index(index, "index out of range");62return _offset_array[index];63}6465inline void G1BlockOffsetSharedArray::set_offset_array_raw(size_t index, u_char offset) {66_offset_array[index] = offset;67}6869void G1BlockOffsetSharedArray::set_offset_array(size_t index, u_char offset) {70check_index(index, "index out of range");71set_offset_array_raw(index, offset);72}7374void G1BlockOffsetSharedArray::set_offset_array(size_t index, HeapWord* high, HeapWord* low) {75check_index(index, "index out of range");76assert(high >= low, "addresses out of order");77size_t offset = pointer_delta(high, low);78check_offset(offset, "offset too large");79set_offset_array(index, (u_char)offset);80}8182void G1BlockOffsetSharedArray::set_offset_array(size_t left, size_t right, u_char offset) {83check_index(right, "right index out of range");84assert(left <= right, "indexes out of order");85size_t num_cards = right - left + 1;86if (UseMemSetInBOT) {87memset(const_cast<u_char*> (&_offset_array[left]), offset, num_cards);88} else {89size_t i = left;90const size_t end = i + num_cards;91for (; i < end; i++) {92_offset_array[i] = offset;93}94}95}9697// Variant of index_for that does not check the index for validity.98inline size_t G1BlockOffsetSharedArray::index_for_raw(const void* p) const {99return pointer_delta((char*) p, _reserved.start(), sizeof(char)) >> LogN;100}101102inline size_t G1BlockOffsetSharedArray::index_for(const void* p) const {103char* pc = (char*)p;104assert(pc >= (char*) _reserved.start() &&105pc < (char*) _reserved.end(),106err_msg("p (" PTR_FORMAT ") not in reserved [" PTR_FORMAT ", " PTR_FORMAT ")",107p2i(p), p2i(_reserved.start()), p2i(_reserved.end())));108size_t result = index_for_raw(p);109check_index(result, "bad index from address");110return result;111}112113inline HeapWord*114G1BlockOffsetSharedArray::address_for_index(size_t index) const {115check_index(index, "index out of range");116HeapWord* result = address_for_index_raw(index);117assert(result >= _reserved.start() && result < _reserved.end(),118err_msg("bad address from index result " PTR_FORMAT119" _reserved.start() " PTR_FORMAT " _reserved.end() "120PTR_FORMAT,121p2i(result), p2i(_reserved.start()), p2i(_reserved.end())));122return result;123}124125#undef check_index126127inline size_t128G1BlockOffsetArray::block_size(const HeapWord* p) const {129return gsp()->block_size(p);130}131132inline HeapWord*133G1BlockOffsetArray::block_at_or_preceding(const void* addr,134bool has_max_index,135size_t max_index) const {136assert(_array->offset_array(0) == 0, "objects can't cross covered areas");137size_t index = _array->index_for(addr);138// We must make sure that the offset table entry we use is valid. If139// "addr" is past the end, start at the last known one and go forward.140if (has_max_index) {141index = MIN2(index, max_index);142}143HeapWord* q = _array->address_for_index(index);144145uint offset = _array->offset_array(index); // Extend u_char to uint.146while (offset >= N_words) {147// The excess of the offset from N_words indicates a power of Base148// to go back by.149size_t n_cards_back = BlockOffsetArray::entry_to_cards_back(offset);150q -= (N_words * n_cards_back);151assert(q >= gsp()->bottom(), "Went below bottom!");152index -= n_cards_back;153offset = _array->offset_array(index);154}155assert(offset < N_words, "offset too large");156q -= offset;157return q;158}159160inline HeapWord*161G1BlockOffsetArray::162forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,163const void* addr) const {164if (addr >= gsp()->top()) return gsp()->top();165while (n <= addr) {166q = n;167oop obj = oop(q);168if (obj->klass_or_null_acquire() == NULL) return q;169n += block_size(q);170}171assert(q <= n, "wrong order for q and addr");172assert(addr < n, "wrong order for addr and n");173return q;174}175176inline HeapWord*177G1BlockOffsetArray::forward_to_block_containing_addr(HeapWord* q,178const void* addr) {179if (oop(q)->klass_or_null_acquire() == NULL) return q;180HeapWord* n = q + block_size(q);181// In the normal case, where the query "addr" is a card boundary, and the182// offset table chunks are the same size as cards, the block starting at183// "q" will contain addr, so the test below will fail, and we'll fall184// through quickly.185if (n <= addr) {186q = forward_to_block_containing_addr_slow(q, n, addr);187}188assert(q <= addr, "wrong order for current and arg");189return q;190}191192#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP193194195