src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 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_PARALLELSCAVENGE_PARMARKBITMAP_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARMARKBITMAP_HPP
aoqi@0 27
aoqi@0 28 #include "memory/memRegion.hpp"
aoqi@0 29 #include "oops/oop.hpp"
aoqi@0 30 #include "utilities/bitMap.hpp"
aoqi@0 31
aoqi@0 32 class ParMarkBitMapClosure;
aoqi@0 33 class PSVirtualSpace;
aoqi@0 34
aoqi@0 35 class ParMarkBitMap: public CHeapObj<mtGC>
aoqi@0 36 {
aoqi@0 37 public:
aoqi@0 38 typedef BitMap::idx_t idx_t;
aoqi@0 39
aoqi@0 40 // Values returned by the iterate() methods.
aoqi@0 41 enum IterationStatus { incomplete, complete, full, would_overflow };
aoqi@0 42
aoqi@0 43 inline ParMarkBitMap();
aoqi@0 44 bool initialize(MemRegion covered_region);
aoqi@0 45
aoqi@0 46 // Atomically mark an object as live.
aoqi@0 47 bool mark_obj(HeapWord* addr, size_t size);
aoqi@0 48 inline bool mark_obj(oop obj, int size);
aoqi@0 49
aoqi@0 50 // Return whether the specified begin or end bit is set.
aoqi@0 51 inline bool is_obj_beg(idx_t bit) const;
aoqi@0 52 inline bool is_obj_end(idx_t bit) const;
aoqi@0 53
aoqi@0 54 // Traditional interface for testing whether an object is marked or not (these
aoqi@0 55 // test only the begin bits).
aoqi@0 56 inline bool is_marked(idx_t bit) const;
aoqi@0 57 inline bool is_marked(HeapWord* addr) const;
aoqi@0 58 inline bool is_marked(oop obj) const;
aoqi@0 59
aoqi@0 60 inline bool is_unmarked(idx_t bit) const;
aoqi@0 61 inline bool is_unmarked(HeapWord* addr) const;
aoqi@0 62 inline bool is_unmarked(oop obj) const;
aoqi@0 63
aoqi@0 64 // Convert sizes from bits to HeapWords and back. An object that is n bits
aoqi@0 65 // long will be bits_to_words(n) words long. An object that is m words long
aoqi@0 66 // will take up words_to_bits(m) bits in the bitmap.
aoqi@0 67 inline static size_t bits_to_words(idx_t bits);
aoqi@0 68 inline static idx_t words_to_bits(size_t words);
aoqi@0 69
aoqi@0 70 // Return the size in words of an object given a begin bit and an end bit, or
aoqi@0 71 // the equivalent beg_addr and end_addr.
aoqi@0 72 inline size_t obj_size(idx_t beg_bit, idx_t end_bit) const;
aoqi@0 73 inline size_t obj_size(HeapWord* beg_addr, HeapWord* end_addr) const;
aoqi@0 74
aoqi@0 75 // Return the size in words of the object (a search is done for the end bit).
aoqi@0 76 inline size_t obj_size(idx_t beg_bit) const;
aoqi@0 77 inline size_t obj_size(HeapWord* addr) const;
aoqi@0 78
aoqi@0 79 // Apply live_closure to each live object that lies completely within the
aoqi@0 80 // range [live_range_beg, live_range_end). This is used to iterate over the
aoqi@0 81 // compacted region of the heap. Return values:
aoqi@0 82 //
aoqi@0 83 // incomplete The iteration is not complete. The last object that
aoqi@0 84 // begins in the range does not end in the range;
aoqi@0 85 // closure->source() is set to the start of that object.
aoqi@0 86 //
aoqi@0 87 // complete The iteration is complete. All objects in the range
aoqi@0 88 // were processed and the closure is not full;
aoqi@0 89 // closure->source() is set one past the end of the range.
aoqi@0 90 //
aoqi@0 91 // full The closure is full; closure->source() is set to one
aoqi@0 92 // past the end of the last object processed.
aoqi@0 93 //
aoqi@0 94 // would_overflow The next object in the range would overflow the closure;
aoqi@0 95 // closure->source() is set to the start of that object.
aoqi@0 96 IterationStatus iterate(ParMarkBitMapClosure* live_closure,
aoqi@0 97 idx_t range_beg, idx_t range_end) const;
aoqi@0 98 inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,
aoqi@0 99 HeapWord* range_beg,
aoqi@0 100 HeapWord* range_end) const;
aoqi@0 101
aoqi@0 102 // Apply live closure as above and additionally apply dead_closure to all dead
aoqi@0 103 // space in the range [range_beg, dead_range_end). Note that dead_range_end
aoqi@0 104 // must be >= range_end. This is used to iterate over the dense prefix.
aoqi@0 105 //
aoqi@0 106 // This method assumes that if the first bit in the range (range_beg) is not
aoqi@0 107 // marked, then dead space begins at that point and the dead_closure is
aoqi@0 108 // applied. Thus callers must ensure that range_beg is not in the middle of a
aoqi@0 109 // live object.
aoqi@0 110 IterationStatus iterate(ParMarkBitMapClosure* live_closure,
aoqi@0 111 ParMarkBitMapClosure* dead_closure,
aoqi@0 112 idx_t range_beg, idx_t range_end,
aoqi@0 113 idx_t dead_range_end) const;
aoqi@0 114 inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,
aoqi@0 115 ParMarkBitMapClosure* dead_closure,
aoqi@0 116 HeapWord* range_beg,
aoqi@0 117 HeapWord* range_end,
aoqi@0 118 HeapWord* dead_range_end) const;
aoqi@0 119
aoqi@0 120 // Return the number of live words in the range [beg_addr, end_obj) due to
aoqi@0 121 // objects that start in the range. If a live object extends onto the range,
aoqi@0 122 // the caller must detect and account for any live words due to that object.
aoqi@0 123 // If a live object extends beyond the end of the range, only the words within
aoqi@0 124 // the range are included in the result. The end of the range must be a live object,
aoqi@0 125 // which is the case when updating pointers. This allows a branch to be removed
aoqi@0 126 // from inside the loop.
aoqi@0 127 size_t live_words_in_range(HeapWord* beg_addr, oop end_obj) const;
aoqi@0 128
aoqi@0 129 inline HeapWord* region_start() const;
aoqi@0 130 inline HeapWord* region_end() const;
aoqi@0 131 inline size_t region_size() const;
aoqi@0 132 inline size_t size() const;
aoqi@0 133
aoqi@0 134 size_t reserved_byte_size() const { return _reserved_byte_size; }
aoqi@0 135
aoqi@0 136 // Convert a heap address to/from a bit index.
aoqi@0 137 inline idx_t addr_to_bit(HeapWord* addr) const;
aoqi@0 138 inline HeapWord* bit_to_addr(idx_t bit) const;
aoqi@0 139
aoqi@0 140 // Return the bit index of the first marked object that begins (or ends,
aoqi@0 141 // respectively) in the range [beg, end). If no object is found, return end.
aoqi@0 142 inline idx_t find_obj_beg(idx_t beg, idx_t end) const;
aoqi@0 143 inline idx_t find_obj_end(idx_t beg, idx_t end) const;
aoqi@0 144
aoqi@0 145 inline HeapWord* find_obj_beg(HeapWord* beg, HeapWord* end) const;
aoqi@0 146 inline HeapWord* find_obj_end(HeapWord* beg, HeapWord* end) const;
aoqi@0 147
aoqi@0 148 // Clear a range of bits or the entire bitmap (both begin and end bits are
aoqi@0 149 // cleared).
aoqi@0 150 inline void clear_range(idx_t beg, idx_t end);
aoqi@0 151
aoqi@0 152 // Return the number of bits required to represent the specified number of
aoqi@0 153 // HeapWords, or the specified region.
aoqi@0 154 static inline idx_t bits_required(size_t words);
aoqi@0 155 static inline idx_t bits_required(MemRegion covered_region);
aoqi@0 156
aoqi@0 157 void print_on_error(outputStream* st) const {
aoqi@0 158 st->print_cr("Marking Bits: (ParMarkBitMap*) " PTR_FORMAT, p2i(this));
aoqi@0 159 _beg_bits.print_on_error(st, " Begin Bits: ");
aoqi@0 160 _end_bits.print_on_error(st, " End Bits: ");
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 #ifdef ASSERT
aoqi@0 164 void verify_clear() const;
aoqi@0 165 inline void verify_bit(idx_t bit) const;
aoqi@0 166 inline void verify_addr(HeapWord* addr) const;
aoqi@0 167 #endif // #ifdef ASSERT
aoqi@0 168
aoqi@0 169 private:
aoqi@0 170 // Each bit in the bitmap represents one unit of 'object granularity.' Objects
aoqi@0 171 // are double-word aligned in 32-bit VMs, but not in 64-bit VMs, so the 32-bit
aoqi@0 172 // granularity is 2, 64-bit is 1.
aoqi@0 173 static inline size_t obj_granularity() { return size_t(MinObjAlignment); }
aoqi@0 174 static inline int obj_granularity_shift() { return LogMinObjAlignment; }
aoqi@0 175
aoqi@0 176 HeapWord* _region_start;
aoqi@0 177 size_t _region_size;
aoqi@0 178 BitMap _beg_bits;
aoqi@0 179 BitMap _end_bits;
aoqi@0 180 PSVirtualSpace* _virtual_space;
aoqi@0 181 size_t _reserved_byte_size;
aoqi@0 182 };
aoqi@0 183
aoqi@0 184 inline ParMarkBitMap::ParMarkBitMap():
aoqi@0 185 _beg_bits(), _end_bits(), _region_start(NULL), _region_size(0), _virtual_space(NULL), _reserved_byte_size(0)
aoqi@0 186 { }
aoqi@0 187
aoqi@0 188 inline void ParMarkBitMap::clear_range(idx_t beg, idx_t end)
aoqi@0 189 {
aoqi@0 190 _beg_bits.clear_range(beg, end);
aoqi@0 191 _end_bits.clear_range(beg, end);
aoqi@0 192 }
aoqi@0 193
aoqi@0 194 inline ParMarkBitMap::idx_t
aoqi@0 195 ParMarkBitMap::bits_required(size_t words)
aoqi@0 196 {
aoqi@0 197 // Need two bits (one begin bit, one end bit) for each unit of 'object
aoqi@0 198 // granularity' in the heap.
aoqi@0 199 return words_to_bits(words * 2);
aoqi@0 200 }
aoqi@0 201
aoqi@0 202 inline ParMarkBitMap::idx_t
aoqi@0 203 ParMarkBitMap::bits_required(MemRegion covered_region)
aoqi@0 204 {
aoqi@0 205 return bits_required(covered_region.word_size());
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 inline HeapWord*
aoqi@0 209 ParMarkBitMap::region_start() const
aoqi@0 210 {
aoqi@0 211 return _region_start;
aoqi@0 212 }
aoqi@0 213
aoqi@0 214 inline HeapWord*
aoqi@0 215 ParMarkBitMap::region_end() const
aoqi@0 216 {
aoqi@0 217 return region_start() + region_size();
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 inline size_t
aoqi@0 221 ParMarkBitMap::region_size() const
aoqi@0 222 {
aoqi@0 223 return _region_size;
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 inline size_t
aoqi@0 227 ParMarkBitMap::size() const
aoqi@0 228 {
aoqi@0 229 return _beg_bits.size();
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 inline bool ParMarkBitMap::is_obj_beg(idx_t bit) const
aoqi@0 233 {
aoqi@0 234 return _beg_bits.at(bit);
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 inline bool ParMarkBitMap::is_obj_end(idx_t bit) const
aoqi@0 238 {
aoqi@0 239 return _end_bits.at(bit);
aoqi@0 240 }
aoqi@0 241
aoqi@0 242 inline bool ParMarkBitMap::is_marked(idx_t bit) const
aoqi@0 243 {
aoqi@0 244 return is_obj_beg(bit);
aoqi@0 245 }
aoqi@0 246
aoqi@0 247 inline bool ParMarkBitMap::is_marked(HeapWord* addr) const
aoqi@0 248 {
aoqi@0 249 return is_marked(addr_to_bit(addr));
aoqi@0 250 }
aoqi@0 251
aoqi@0 252 inline bool ParMarkBitMap::is_marked(oop obj) const
aoqi@0 253 {
aoqi@0 254 return is_marked((HeapWord*)obj);
aoqi@0 255 }
aoqi@0 256
aoqi@0 257 inline bool ParMarkBitMap::is_unmarked(idx_t bit) const
aoqi@0 258 {
aoqi@0 259 return !is_marked(bit);
aoqi@0 260 }
aoqi@0 261
aoqi@0 262 inline bool ParMarkBitMap::is_unmarked(HeapWord* addr) const
aoqi@0 263 {
aoqi@0 264 return !is_marked(addr);
aoqi@0 265 }
aoqi@0 266
aoqi@0 267 inline bool ParMarkBitMap::is_unmarked(oop obj) const
aoqi@0 268 {
aoqi@0 269 return !is_marked(obj);
aoqi@0 270 }
aoqi@0 271
aoqi@0 272 inline size_t
aoqi@0 273 ParMarkBitMap::bits_to_words(idx_t bits)
aoqi@0 274 {
aoqi@0 275 return bits << obj_granularity_shift();
aoqi@0 276 }
aoqi@0 277
aoqi@0 278 inline ParMarkBitMap::idx_t
aoqi@0 279 ParMarkBitMap::words_to_bits(size_t words)
aoqi@0 280 {
aoqi@0 281 return words >> obj_granularity_shift();
aoqi@0 282 }
aoqi@0 283
aoqi@0 284 inline size_t ParMarkBitMap::obj_size(idx_t beg_bit, idx_t end_bit) const
aoqi@0 285 {
aoqi@0 286 DEBUG_ONLY(verify_bit(beg_bit);)
aoqi@0 287 DEBUG_ONLY(verify_bit(end_bit);)
aoqi@0 288 return bits_to_words(end_bit - beg_bit + 1);
aoqi@0 289 }
aoqi@0 290
aoqi@0 291 inline size_t
aoqi@0 292 ParMarkBitMap::obj_size(HeapWord* beg_addr, HeapWord* end_addr) const
aoqi@0 293 {
aoqi@0 294 DEBUG_ONLY(verify_addr(beg_addr);)
aoqi@0 295 DEBUG_ONLY(verify_addr(end_addr);)
aoqi@0 296 return pointer_delta(end_addr, beg_addr) + obj_granularity();
aoqi@0 297 }
aoqi@0 298
aoqi@0 299 inline size_t ParMarkBitMap::obj_size(idx_t beg_bit) const
aoqi@0 300 {
aoqi@0 301 const idx_t end_bit = _end_bits.get_next_one_offset_inline(beg_bit, size());
aoqi@0 302 assert(is_marked(beg_bit), "obj not marked");
aoqi@0 303 assert(end_bit < size(), "end bit missing");
aoqi@0 304 return obj_size(beg_bit, end_bit);
aoqi@0 305 }
aoqi@0 306
aoqi@0 307 inline size_t ParMarkBitMap::obj_size(HeapWord* addr) const
aoqi@0 308 {
aoqi@0 309 return obj_size(addr_to_bit(addr));
aoqi@0 310 }
aoqi@0 311
aoqi@0 312 inline ParMarkBitMap::IterationStatus
aoqi@0 313 ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
aoqi@0 314 HeapWord* range_beg,
aoqi@0 315 HeapWord* range_end) const
aoqi@0 316 {
aoqi@0 317 return iterate(live_closure, addr_to_bit(range_beg), addr_to_bit(range_end));
aoqi@0 318 }
aoqi@0 319
aoqi@0 320 inline ParMarkBitMap::IterationStatus
aoqi@0 321 ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
aoqi@0 322 ParMarkBitMapClosure* dead_closure,
aoqi@0 323 HeapWord* range_beg,
aoqi@0 324 HeapWord* range_end,
aoqi@0 325 HeapWord* dead_range_end) const
aoqi@0 326 {
aoqi@0 327 return iterate(live_closure, dead_closure,
aoqi@0 328 addr_to_bit(range_beg), addr_to_bit(range_end),
aoqi@0 329 addr_to_bit(dead_range_end));
aoqi@0 330 }
aoqi@0 331
aoqi@0 332 inline bool
aoqi@0 333 ParMarkBitMap::mark_obj(oop obj, int size)
aoqi@0 334 {
aoqi@0 335 return mark_obj((HeapWord*)obj, (size_t)size);
aoqi@0 336 }
aoqi@0 337
aoqi@0 338 inline BitMap::idx_t
aoqi@0 339 ParMarkBitMap::addr_to_bit(HeapWord* addr) const
aoqi@0 340 {
aoqi@0 341 DEBUG_ONLY(verify_addr(addr);)
aoqi@0 342 return words_to_bits(pointer_delta(addr, region_start()));
aoqi@0 343 }
aoqi@0 344
aoqi@0 345 inline HeapWord*
aoqi@0 346 ParMarkBitMap::bit_to_addr(idx_t bit) const
aoqi@0 347 {
aoqi@0 348 DEBUG_ONLY(verify_bit(bit);)
aoqi@0 349 return region_start() + bits_to_words(bit);
aoqi@0 350 }
aoqi@0 351
aoqi@0 352 inline ParMarkBitMap::idx_t
aoqi@0 353 ParMarkBitMap::find_obj_beg(idx_t beg, idx_t end) const
aoqi@0 354 {
aoqi@0 355 return _beg_bits.get_next_one_offset_inline_aligned_right(beg, end);
aoqi@0 356 }
aoqi@0 357
aoqi@0 358 inline ParMarkBitMap::idx_t
aoqi@0 359 ParMarkBitMap::find_obj_end(idx_t beg, idx_t end) const
aoqi@0 360 {
aoqi@0 361 return _end_bits.get_next_one_offset_inline_aligned_right(beg, end);
aoqi@0 362 }
aoqi@0 363
aoqi@0 364 inline HeapWord*
aoqi@0 365 ParMarkBitMap::find_obj_beg(HeapWord* beg, HeapWord* end) const
aoqi@0 366 {
aoqi@0 367 const idx_t beg_bit = addr_to_bit(beg);
aoqi@0 368 const idx_t end_bit = addr_to_bit(end);
aoqi@0 369 const idx_t search_end = BitMap::word_align_up(end_bit);
aoqi@0 370 const idx_t res_bit = MIN2(find_obj_beg(beg_bit, search_end), end_bit);
aoqi@0 371 return bit_to_addr(res_bit);
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 inline HeapWord*
aoqi@0 375 ParMarkBitMap::find_obj_end(HeapWord* beg, HeapWord* end) const
aoqi@0 376 {
aoqi@0 377 const idx_t beg_bit = addr_to_bit(beg);
aoqi@0 378 const idx_t end_bit = addr_to_bit(end);
aoqi@0 379 const idx_t search_end = BitMap::word_align_up(end_bit);
aoqi@0 380 const idx_t res_bit = MIN2(find_obj_end(beg_bit, search_end), end_bit);
aoqi@0 381 return bit_to_addr(res_bit);
aoqi@0 382 }
aoqi@0 383
aoqi@0 384 #ifdef ASSERT
aoqi@0 385 inline void ParMarkBitMap::verify_bit(idx_t bit) const {
aoqi@0 386 // Allow one past the last valid bit; useful for loop bounds.
aoqi@0 387 assert(bit <= _beg_bits.size(), "bit out of range");
aoqi@0 388 }
aoqi@0 389
aoqi@0 390 inline void ParMarkBitMap::verify_addr(HeapWord* addr) const {
aoqi@0 391 // Allow one past the last valid address; useful for loop bounds.
aoqi@0 392 assert(addr >= region_start(),
aoqi@0 393 err_msg("addr too small, addr: " PTR_FORMAT " region start: " PTR_FORMAT, p2i(addr), p2i(region_start())));
aoqi@0 394 assert(addr <= region_end(),
aoqi@0 395 err_msg("addr too big, addr: " PTR_FORMAT " region end: " PTR_FORMAT, p2i(addr), p2i(region_end())));
aoqi@0 396 }
aoqi@0 397 #endif // #ifdef ASSERT
aoqi@0 398
aoqi@0 399 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARMARKBITMAP_HPP

mercurial