src/share/vm/gc_implementation/g1/g1BlockOffsetTable.inline.hpp

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 9703
2fdf635bcf28
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

ysr@777 1 /*
drchase@6680 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/g1/g1BlockOffsetTable.hpp"
mgerdin@6990 29 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
mgerdin@6990 30 #include "gc_implementation/g1/heapRegion.inline.hpp"
stefank@2314 31 #include "memory/space.hpp"
stefank@2314 32
ysr@777 33 inline HeapWord* G1BlockOffsetTable::block_start(const void* addr) {
ysr@777 34 if (addr >= _bottom && addr < _end) {
ysr@777 35 return block_start_unsafe(addr);
ysr@777 36 } else {
ysr@777 37 return NULL;
ysr@777 38 }
ysr@777 39 }
ysr@777 40
ysr@777 41 inline HeapWord*
ysr@777 42 G1BlockOffsetTable::block_start_const(const void* addr) const {
ysr@777 43 if (addr >= _bottom && addr < _end) {
ysr@777 44 return block_start_unsafe_const(addr);
ysr@777 45 } else {
ysr@777 46 return NULL;
ysr@777 47 }
ysr@777 48 }
ysr@777 49
tschatzl@7051 50 #define check_index(index, msg) \
tschatzl@7051 51 assert((index) < (_reserved.word_size() >> LogN_words), \
tschatzl@7051 52 err_msg("%s - index: "SIZE_FORMAT", _vs.committed_size: "SIZE_FORMAT, \
tschatzl@7051 53 msg, (index), (_reserved.word_size() >> LogN_words))); \
tschatzl@7051 54 assert(G1CollectedHeap::heap()->is_in_exact(address_for_index_raw(index)), \
tschatzl@7051 55 err_msg("Index "SIZE_FORMAT" corresponding to "PTR_FORMAT \
tschatzl@7051 56 " (%u) is not in committed area.", \
tschatzl@7051 57 (index), \
tschatzl@7051 58 p2i(address_for_index_raw(index)), \
tschatzl@7051 59 G1CollectedHeap::heap()->addr_to_region(address_for_index_raw(index))));
tschatzl@7051 60
tschatzl@7051 61 u_char G1BlockOffsetSharedArray::offset_array(size_t index) const {
tschatzl@7051 62 check_index(index, "index out of range");
tschatzl@7051 63 return _offset_array[index];
tschatzl@7051 64 }
tschatzl@7051 65
aph@9697 66 inline void G1BlockOffsetSharedArray::set_offset_array_raw(size_t index, u_char offset) {
aph@9697 67 _offset_array[index] = offset;
aph@9697 68 }
aph@9697 69
tschatzl@7051 70 void G1BlockOffsetSharedArray::set_offset_array(size_t index, u_char offset) {
tschatzl@7051 71 check_index(index, "index out of range");
tschatzl@7051 72 set_offset_array_raw(index, offset);
tschatzl@7051 73 }
tschatzl@7051 74
tschatzl@7051 75 void G1BlockOffsetSharedArray::set_offset_array(size_t index, HeapWord* high, HeapWord* low) {
tschatzl@7051 76 check_index(index, "index out of range");
tschatzl@7051 77 assert(high >= low, "addresses out of order");
tschatzl@7051 78 size_t offset = pointer_delta(high, low);
tschatzl@7051 79 check_offset(offset, "offset too large");
tschatzl@7051 80 set_offset_array(index, (u_char)offset);
tschatzl@7051 81 }
tschatzl@7051 82
tschatzl@7051 83 void G1BlockOffsetSharedArray::set_offset_array(size_t left, size_t right, u_char offset) {
tschatzl@7051 84 check_index(right, "right index out of range");
tschatzl@7051 85 assert(left <= right, "indexes out of order");
tschatzl@7051 86 size_t num_cards = right - left + 1;
tschatzl@7051 87 if (UseMemSetInBOT) {
aph@9697 88 memset(const_cast<u_char*> (&_offset_array[left]), offset, num_cards);
tschatzl@7051 89 } else {
tschatzl@7051 90 size_t i = left;
tschatzl@7051 91 const size_t end = i + num_cards;
tschatzl@7051 92 for (; i < end; i++) {
tschatzl@7051 93 _offset_array[i] = offset;
tschatzl@7051 94 }
tschatzl@7051 95 }
tschatzl@7051 96 }
tschatzl@7051 97
tschatzl@7051 98 // Variant of index_for that does not check the index for validity.
tschatzl@7051 99 inline size_t G1BlockOffsetSharedArray::index_for_raw(const void* p) const {
tschatzl@7051 100 return pointer_delta((char*)p, _reserved.start(), sizeof(char)) >> LogN;
tschatzl@7051 101 }
tschatzl@7051 102
ysr@777 103 inline size_t G1BlockOffsetSharedArray::index_for(const void* p) const {
ysr@777 104 char* pc = (char*)p;
ysr@777 105 assert(pc >= (char*)_reserved.start() &&
ysr@777 106 pc < (char*)_reserved.end(),
johnc@4300 107 err_msg("p (" PTR_FORMAT ") not in reserved [" PTR_FORMAT ", " PTR_FORMAT ")",
drchase@6680 108 p2i(p), p2i(_reserved.start()), p2i(_reserved.end())));
tschatzl@7051 109 size_t result = index_for_raw(p);
johnc@4300 110 check_index(result, "bad index from address");
ysr@777 111 return result;
ysr@777 112 }
ysr@777 113
ysr@777 114 inline HeapWord*
ysr@777 115 G1BlockOffsetSharedArray::address_for_index(size_t index) const {
johnc@4300 116 check_index(index, "index out of range");
tschatzl@7051 117 HeapWord* result = address_for_index_raw(index);
ysr@777 118 assert(result >= _reserved.start() && result < _reserved.end(),
coleenp@4037 119 err_msg("bad address from index result " PTR_FORMAT
coleenp@4037 120 " _reserved.start() " PTR_FORMAT " _reserved.end() "
coleenp@4037 121 PTR_FORMAT,
drchase@6680 122 p2i(result), p2i(_reserved.start()), p2i(_reserved.end())));
ysr@777 123 return result;
ysr@777 124 }
ysr@777 125
tschatzl@7051 126 #undef check_index
tschatzl@7051 127
mgerdin@6987 128 inline size_t
mgerdin@6987 129 G1BlockOffsetArray::block_size(const HeapWord* p) const {
mgerdin@6987 130 return gsp()->block_size(p);
mgerdin@6987 131 }
mgerdin@6987 132
ysr@777 133 inline HeapWord*
ysr@777 134 G1BlockOffsetArray::block_at_or_preceding(const void* addr,
ysr@777 135 bool has_max_index,
ysr@777 136 size_t max_index) const {
ysr@777 137 assert(_array->offset_array(0) == 0, "objects can't cross covered areas");
ysr@777 138 size_t index = _array->index_for(addr);
ysr@777 139 // We must make sure that the offset table entry we use is valid. If
ysr@777 140 // "addr" is past the end, start at the last known one and go forward.
ysr@777 141 if (has_max_index) {
ysr@777 142 index = MIN2(index, max_index);
ysr@777 143 }
ysr@777 144 HeapWord* q = _array->address_for_index(index);
ysr@777 145
ysr@777 146 uint offset = _array->offset_array(index); // Extend u_char to uint.
ysr@777 147 while (offset >= N_words) {
ysr@777 148 // The excess of the offset from N_words indicates a power of Base
ysr@777 149 // to go back by.
ysr@777 150 size_t n_cards_back = BlockOffsetArray::entry_to_cards_back(offset);
ysr@777 151 q -= (N_words * n_cards_back);
mgerdin@6987 152 assert(q >= gsp()->bottom(), "Went below bottom!");
ysr@777 153 index -= n_cards_back;
ysr@777 154 offset = _array->offset_array(index);
ysr@777 155 }
ysr@777 156 assert(offset < N_words, "offset too large");
ysr@777 157 q -= offset;
ysr@777 158 return q;
ysr@777 159 }
ysr@777 160
ysr@777 161 inline HeapWord*
ysr@777 162 G1BlockOffsetArray::
ysr@777 163 forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,
ysr@777 164 const void* addr) const {
mgerdin@6987 165 if (addr >= gsp()->top()) return gsp()->top();
mgerdin@6987 166 while (n <= addr) {
mgerdin@6987 167 q = n;
mgerdin@6987 168 oop obj = oop(q);
mgerdin@6987 169 if (obj->klass_or_null() == NULL) return q;
stefank@6992 170 n += block_size(q);
ysr@777 171 }
ysr@777 172 assert(q <= n, "wrong order for q and addr");
ysr@777 173 assert(addr < n, "wrong order for addr and n");
ysr@777 174 return q;
ysr@777 175 }
ysr@777 176
ysr@777 177 inline HeapWord*
ysr@777 178 G1BlockOffsetArray::forward_to_block_containing_addr(HeapWord* q,
ysr@777 179 const void* addr) {
ysr@1280 180 if (oop(q)->klass_or_null() == NULL) return q;
mgerdin@6987 181 HeapWord* n = q + block_size(q);
ysr@777 182 // In the normal case, where the query "addr" is a card boundary, and the
ysr@777 183 // offset table chunks are the same size as cards, the block starting at
ysr@777 184 // "q" will contain addr, so the test below will fail, and we'll fall
ysr@777 185 // through quickly.
ysr@777 186 if (n <= addr) {
ysr@777 187 q = forward_to_block_containing_addr_slow(q, n, addr);
ysr@777 188 }
ysr@777 189 assert(q <= addr, "wrong order for current and arg");
ysr@777 190 return q;
ysr@777 191 }
ysr@777 192
stefank@2314 193 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP

mercurial