Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP |
aoqi@0 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "gc_implementation/g1/g1BlockOffsetTable.hpp" |
aoqi@0 | 29 | #include "memory/space.hpp" |
aoqi@0 | 30 | |
aoqi@0 | 31 | inline HeapWord* G1BlockOffsetTable::block_start(const void* addr) { |
aoqi@0 | 32 | if (addr >= _bottom && addr < _end) { |
aoqi@0 | 33 | return block_start_unsafe(addr); |
aoqi@0 | 34 | } else { |
aoqi@0 | 35 | return NULL; |
aoqi@0 | 36 | } |
aoqi@0 | 37 | } |
aoqi@0 | 38 | |
aoqi@0 | 39 | inline HeapWord* |
aoqi@0 | 40 | G1BlockOffsetTable::block_start_const(const void* addr) const { |
aoqi@0 | 41 | if (addr >= _bottom && addr < _end) { |
aoqi@0 | 42 | return block_start_unsafe_const(addr); |
aoqi@0 | 43 | } else { |
aoqi@0 | 44 | return NULL; |
aoqi@0 | 45 | } |
aoqi@0 | 46 | } |
aoqi@0 | 47 | |
aoqi@0 | 48 | inline size_t G1BlockOffsetSharedArray::index_for(const void* p) const { |
aoqi@0 | 49 | char* pc = (char*)p; |
aoqi@0 | 50 | assert(pc >= (char*)_reserved.start() && |
aoqi@0 | 51 | pc < (char*)_reserved.end(), |
aoqi@0 | 52 | err_msg("p (" PTR_FORMAT ") not in reserved [" PTR_FORMAT ", " PTR_FORMAT ")", |
aoqi@0 | 53 | p2i(p), p2i(_reserved.start()), p2i(_reserved.end()))); |
aoqi@0 | 54 | size_t delta = pointer_delta(pc, _reserved.start(), sizeof(char)); |
aoqi@0 | 55 | size_t result = delta >> LogN; |
aoqi@0 | 56 | check_index(result, "bad index from address"); |
aoqi@0 | 57 | return result; |
aoqi@0 | 58 | } |
aoqi@0 | 59 | |
aoqi@0 | 60 | inline HeapWord* |
aoqi@0 | 61 | G1BlockOffsetSharedArray::address_for_index(size_t index) const { |
aoqi@0 | 62 | check_index(index, "index out of range"); |
aoqi@0 | 63 | HeapWord* result = _reserved.start() + (index << LogN_words); |
aoqi@0 | 64 | assert(result >= _reserved.start() && result < _reserved.end(), |
aoqi@0 | 65 | err_msg("bad address from index result " PTR_FORMAT |
aoqi@0 | 66 | " _reserved.start() " PTR_FORMAT " _reserved.end() " |
aoqi@0 | 67 | PTR_FORMAT, |
aoqi@0 | 68 | p2i(result), p2i(_reserved.start()), p2i(_reserved.end()))); |
aoqi@0 | 69 | return result; |
aoqi@0 | 70 | } |
aoqi@0 | 71 | |
aoqi@0 | 72 | inline HeapWord* |
aoqi@0 | 73 | G1BlockOffsetArray::block_at_or_preceding(const void* addr, |
aoqi@0 | 74 | bool has_max_index, |
aoqi@0 | 75 | size_t max_index) const { |
aoqi@0 | 76 | assert(_array->offset_array(0) == 0, "objects can't cross covered areas"); |
aoqi@0 | 77 | size_t index = _array->index_for(addr); |
aoqi@0 | 78 | // We must make sure that the offset table entry we use is valid. If |
aoqi@0 | 79 | // "addr" is past the end, start at the last known one and go forward. |
aoqi@0 | 80 | if (has_max_index) { |
aoqi@0 | 81 | index = MIN2(index, max_index); |
aoqi@0 | 82 | } |
aoqi@0 | 83 | HeapWord* q = _array->address_for_index(index); |
aoqi@0 | 84 | |
aoqi@0 | 85 | uint offset = _array->offset_array(index); // Extend u_char to uint. |
aoqi@0 | 86 | while (offset >= N_words) { |
aoqi@0 | 87 | // The excess of the offset from N_words indicates a power of Base |
aoqi@0 | 88 | // to go back by. |
aoqi@0 | 89 | size_t n_cards_back = BlockOffsetArray::entry_to_cards_back(offset); |
aoqi@0 | 90 | q -= (N_words * n_cards_back); |
aoqi@0 | 91 | assert(q >= _sp->bottom(), "Went below bottom!"); |
aoqi@0 | 92 | index -= n_cards_back; |
aoqi@0 | 93 | offset = _array->offset_array(index); |
aoqi@0 | 94 | } |
aoqi@0 | 95 | assert(offset < N_words, "offset too large"); |
aoqi@0 | 96 | q -= offset; |
aoqi@0 | 97 | return q; |
aoqi@0 | 98 | } |
aoqi@0 | 99 | |
aoqi@0 | 100 | inline HeapWord* |
aoqi@0 | 101 | G1BlockOffsetArray:: |
aoqi@0 | 102 | forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n, |
aoqi@0 | 103 | const void* addr) const { |
aoqi@0 | 104 | if (csp() != NULL) { |
aoqi@0 | 105 | if (addr >= csp()->top()) return csp()->top(); |
aoqi@0 | 106 | while (n <= addr) { |
aoqi@0 | 107 | q = n; |
aoqi@0 | 108 | oop obj = oop(q); |
aoqi@0 | 109 | if (obj->klass_or_null() == NULL) return q; |
aoqi@0 | 110 | n += obj->size(); |
aoqi@0 | 111 | } |
aoqi@0 | 112 | } else { |
aoqi@0 | 113 | while (n <= addr) { |
aoqi@0 | 114 | q = n; |
aoqi@0 | 115 | oop obj = oop(q); |
aoqi@0 | 116 | if (obj->klass_or_null() == NULL) return q; |
aoqi@0 | 117 | n += _sp->block_size(q); |
aoqi@0 | 118 | } |
aoqi@0 | 119 | } |
aoqi@0 | 120 | assert(q <= n, "wrong order for q and addr"); |
aoqi@0 | 121 | assert(addr < n, "wrong order for addr and n"); |
aoqi@0 | 122 | return q; |
aoqi@0 | 123 | } |
aoqi@0 | 124 | |
aoqi@0 | 125 | inline HeapWord* |
aoqi@0 | 126 | G1BlockOffsetArray::forward_to_block_containing_addr(HeapWord* q, |
aoqi@0 | 127 | const void* addr) { |
aoqi@0 | 128 | if (oop(q)->klass_or_null() == NULL) return q; |
aoqi@0 | 129 | HeapWord* n = q + _sp->block_size(q); |
aoqi@0 | 130 | // In the normal case, where the query "addr" is a card boundary, and the |
aoqi@0 | 131 | // offset table chunks are the same size as cards, the block starting at |
aoqi@0 | 132 | // "q" will contain addr, so the test below will fail, and we'll fall |
aoqi@0 | 133 | // through quickly. |
aoqi@0 | 134 | if (n <= addr) { |
aoqi@0 | 135 | q = forward_to_block_containing_addr_slow(q, n, addr); |
aoqi@0 | 136 | } |
aoqi@0 | 137 | assert(q <= addr, "wrong order for current and arg"); |
aoqi@0 | 138 | return q; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | ////////////////////////////////////////////////////////////////////////// |
aoqi@0 | 142 | // BlockOffsetArrayNonContigSpace inlines |
aoqi@0 | 143 | ////////////////////////////////////////////////////////////////////////// |
aoqi@0 | 144 | inline void G1BlockOffsetArray::freed(HeapWord* blk_start, HeapWord* blk_end) { |
aoqi@0 | 145 | // Verify that the BOT shows [blk_start, blk_end) to be one block. |
aoqi@0 | 146 | verify_single_block(blk_start, blk_end); |
aoqi@0 | 147 | // adjust _unallocated_block upward or downward |
aoqi@0 | 148 | // as appropriate |
aoqi@0 | 149 | if (BlockOffsetArrayUseUnallocatedBlock) { |
aoqi@0 | 150 | assert(_unallocated_block <= _end, |
aoqi@0 | 151 | "Inconsistent value for _unallocated_block"); |
aoqi@0 | 152 | if (blk_end >= _unallocated_block && blk_start <= _unallocated_block) { |
aoqi@0 | 153 | // CMS-specific note: a block abutting _unallocated_block to |
aoqi@0 | 154 | // its left is being freed, a new block is being added or |
aoqi@0 | 155 | // we are resetting following a compaction |
aoqi@0 | 156 | _unallocated_block = blk_start; |
aoqi@0 | 157 | } |
aoqi@0 | 158 | } |
aoqi@0 | 159 | } |
aoqi@0 | 160 | |
aoqi@0 | 161 | inline void G1BlockOffsetArray::freed(HeapWord* blk, size_t size) { |
aoqi@0 | 162 | freed(blk, blk + size); |
aoqi@0 | 163 | } |
aoqi@0 | 164 | |
aoqi@0 | 165 | #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BLOCKOFFSETTABLE_INLINE_HPP |