| 1 | /* |
| 2 | * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef SHARE_GC_PARALLEL_PARMARKBITMAP_INLINE_HPP |
| 26 | #define SHARE_GC_PARALLEL_PARMARKBITMAP_INLINE_HPP |
| 27 | |
| 28 | #include "gc/parallel/parMarkBitMap.hpp" |
| 29 | #include "utilities/bitMap.inline.hpp" |
| 30 | |
| 31 | inline ParMarkBitMap::ParMarkBitMap(): |
| 32 | _region_start(NULL), _region_size(0), _beg_bits(), _end_bits(), _virtual_space(NULL), _reserved_byte_size(0) |
| 33 | { } |
| 34 | |
| 35 | inline void ParMarkBitMap::clear_range(idx_t beg, idx_t end) { |
| 36 | _beg_bits.clear_range(beg, end); |
| 37 | _end_bits.clear_range(beg, end); |
| 38 | } |
| 39 | |
| 40 | inline ParMarkBitMap::idx_t ParMarkBitMap::bits_required(size_t words) { |
| 41 | // Need two bits (one begin bit, one end bit) for each unit of 'object |
| 42 | // granularity' in the heap. |
| 43 | return words_to_bits(words * 2); |
| 44 | } |
| 45 | |
| 46 | inline ParMarkBitMap::idx_t ParMarkBitMap::bits_required(MemRegion covered_region) { |
| 47 | return bits_required(covered_region.word_size()); |
| 48 | } |
| 49 | |
| 50 | inline HeapWord* ParMarkBitMap::region_start() const { |
| 51 | return _region_start; |
| 52 | } |
| 53 | |
| 54 | inline HeapWord* ParMarkBitMap::region_end() const { |
| 55 | return region_start() + region_size(); |
| 56 | } |
| 57 | |
| 58 | inline size_t ParMarkBitMap::region_size() const { |
| 59 | return _region_size; |
| 60 | } |
| 61 | |
| 62 | inline size_t ParMarkBitMap::size() const { |
| 63 | return _beg_bits.size(); |
| 64 | } |
| 65 | |
| 66 | inline bool ParMarkBitMap::is_obj_beg(idx_t bit) const { |
| 67 | return _beg_bits.at(bit); |
| 68 | } |
| 69 | |
| 70 | inline bool ParMarkBitMap::is_obj_end(idx_t bit) const { |
| 71 | return _end_bits.at(bit); |
| 72 | } |
| 73 | |
| 74 | inline bool ParMarkBitMap::is_marked(idx_t bit) const { |
| 75 | return is_obj_beg(bit); |
| 76 | } |
| 77 | |
| 78 | inline bool ParMarkBitMap::is_marked(HeapWord* addr) const { |
| 79 | return is_marked(addr_to_bit(addr)); |
| 80 | } |
| 81 | |
| 82 | inline bool ParMarkBitMap::is_marked(oop obj) const { |
| 83 | return is_marked((HeapWord*)obj); |
| 84 | } |
| 85 | |
| 86 | inline bool ParMarkBitMap::is_unmarked(idx_t bit) const { |
| 87 | return !is_marked(bit); |
| 88 | } |
| 89 | |
| 90 | inline bool ParMarkBitMap::is_unmarked(HeapWord* addr) const { |
| 91 | return !is_marked(addr); |
| 92 | } |
| 93 | |
| 94 | inline bool ParMarkBitMap::is_unmarked(oop obj) const { |
| 95 | return !is_marked(obj); |
| 96 | } |
| 97 | |
| 98 | inline size_t ParMarkBitMap::bits_to_words(idx_t bits) { |
| 99 | return bits << obj_granularity_shift(); |
| 100 | } |
| 101 | |
| 102 | inline ParMarkBitMap::idx_t ParMarkBitMap::words_to_bits(size_t words) { |
| 103 | return words >> obj_granularity_shift(); |
| 104 | } |
| 105 | |
| 106 | inline size_t ParMarkBitMap::obj_size(idx_t beg_bit, idx_t end_bit) const { |
| 107 | DEBUG_ONLY(verify_bit(beg_bit);) |
| 108 | DEBUG_ONLY(verify_bit(end_bit);) |
| 109 | return bits_to_words(end_bit - beg_bit + 1); |
| 110 | } |
| 111 | |
| 112 | inline size_t ParMarkBitMap::obj_size(HeapWord* beg_addr, HeapWord* end_addr) const { |
| 113 | DEBUG_ONLY(verify_addr(beg_addr);) |
| 114 | DEBUG_ONLY(verify_addr(end_addr);) |
| 115 | return pointer_delta(end_addr, beg_addr) + obj_granularity(); |
| 116 | } |
| 117 | |
| 118 | inline size_t ParMarkBitMap::obj_size(idx_t beg_bit) const { |
| 119 | const idx_t end_bit = _end_bits.get_next_one_offset(beg_bit, size()); |
| 120 | assert(is_marked(beg_bit), "obj not marked" ); |
| 121 | assert(end_bit < size(), "end bit missing" ); |
| 122 | return obj_size(beg_bit, end_bit); |
| 123 | } |
| 124 | |
| 125 | inline size_t ParMarkBitMap::obj_size(HeapWord* addr) const { |
| 126 | return obj_size(addr_to_bit(addr)); |
| 127 | } |
| 128 | |
| 129 | inline ParMarkBitMap::IterationStatus ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure, |
| 130 | HeapWord* range_beg, |
| 131 | HeapWord* range_end) const { |
| 132 | return iterate(live_closure, addr_to_bit(range_beg), addr_to_bit(range_end)); |
| 133 | } |
| 134 | |
| 135 | inline ParMarkBitMap::IterationStatus ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure, |
| 136 | ParMarkBitMapClosure* dead_closure, |
| 137 | HeapWord* range_beg, |
| 138 | HeapWord* range_end, |
| 139 | HeapWord* dead_range_end) const { |
| 140 | return iterate(live_closure, dead_closure, |
| 141 | addr_to_bit(range_beg), addr_to_bit(range_end), |
| 142 | addr_to_bit(dead_range_end)); |
| 143 | } |
| 144 | |
| 145 | inline bool ParMarkBitMap::mark_obj(oop obj, int size) { |
| 146 | return mark_obj((HeapWord*)obj, (size_t)size); |
| 147 | } |
| 148 | |
| 149 | inline BitMap::idx_t ParMarkBitMap::addr_to_bit(HeapWord* addr) const { |
| 150 | DEBUG_ONLY(verify_addr(addr);) |
| 151 | return words_to_bits(pointer_delta(addr, region_start())); |
| 152 | } |
| 153 | |
| 154 | inline HeapWord* ParMarkBitMap::bit_to_addr(idx_t bit) const { |
| 155 | DEBUG_ONLY(verify_bit(bit);) |
| 156 | return region_start() + bits_to_words(bit); |
| 157 | } |
| 158 | |
| 159 | inline ParMarkBitMap::idx_t ParMarkBitMap::find_obj_beg(idx_t beg, idx_t end) const { |
| 160 | return _beg_bits.get_next_one_offset_aligned_right(beg, end); |
| 161 | } |
| 162 | |
| 163 | inline ParMarkBitMap::idx_t ParMarkBitMap::find_obj_end(idx_t beg, idx_t end) const { |
| 164 | return _end_bits.get_next_one_offset_aligned_right(beg, end); |
| 165 | } |
| 166 | |
| 167 | inline HeapWord* ParMarkBitMap::find_obj_beg(HeapWord* beg, HeapWord* end) const { |
| 168 | const idx_t beg_bit = addr_to_bit(beg); |
| 169 | const idx_t end_bit = addr_to_bit(end); |
| 170 | const idx_t search_end = BitMap::word_align_up(end_bit); |
| 171 | const idx_t res_bit = MIN2(find_obj_beg(beg_bit, search_end), end_bit); |
| 172 | return bit_to_addr(res_bit); |
| 173 | } |
| 174 | |
| 175 | inline HeapWord* ParMarkBitMap::find_obj_end(HeapWord* beg, HeapWord* end) const { |
| 176 | const idx_t beg_bit = addr_to_bit(beg); |
| 177 | const idx_t end_bit = addr_to_bit(end); |
| 178 | const idx_t search_end = BitMap::word_align_up(end_bit); |
| 179 | const idx_t res_bit = MIN2(find_obj_end(beg_bit, search_end), end_bit); |
| 180 | return bit_to_addr(res_bit); |
| 181 | } |
| 182 | |
| 183 | #ifdef ASSERT |
| 184 | inline void ParMarkBitMap::verify_bit(idx_t bit) const { |
| 185 | // Allow one past the last valid bit; useful for loop bounds. |
| 186 | assert(bit <= _beg_bits.size(), "bit out of range" ); |
| 187 | } |
| 188 | |
| 189 | inline void ParMarkBitMap::verify_addr(HeapWord* addr) const { |
| 190 | // Allow one past the last valid address; useful for loop bounds. |
| 191 | assert(addr >= region_start(), |
| 192 | "addr too small, addr: " PTR_FORMAT " region start: " PTR_FORMAT, p2i(addr), p2i(region_start())); |
| 193 | assert(addr <= region_end(), |
| 194 | "addr too big, addr: " PTR_FORMAT " region end: " PTR_FORMAT, p2i(addr), p2i(region_end())); |
| 195 | } |
| 196 | #endif // #ifdef ASSERT |
| 197 | |
| 198 | #endif // SHARE_GC_PARALLEL_PARMARKBITMAP_INLINE_HPP |
| 199 | |