annotate src/hotspot/share/gc/shared/markBitMap.hpp @ 52321:31b159f30fb2

8180193: Make marking bitmap code available to other GCs Reviewed-by: shade, stefank
author rkennke
date Wed, 29 Aug 2018 20:15:09 +0200
parents
children 5b87d3fc1093
rev   line source
rkennke@52321 1 /*
rkennke@52321 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
rkennke@52321 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
rkennke@52321 4 *
rkennke@52321 5 * This code is free software; you can redistribute it and/or modify it
rkennke@52321 6 * under the terms of the GNU General Public License version 2 only, as
rkennke@52321 7 * published by the Free Software Foundation.
rkennke@52321 8 *
rkennke@52321 9 * This code is distributed in the hope that it will be useful, but WITHOUT
rkennke@52321 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
rkennke@52321 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
rkennke@52321 12 * version 2 for more details (a copy is included in the LICENSE file that
rkennke@52321 13 * accompanied this code).
rkennke@52321 14 *
rkennke@52321 15 * You should have received a copy of the GNU General Public License version
rkennke@52321 16 * 2 along with this work; if not, write to the Free Software Foundation,
rkennke@52321 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
rkennke@52321 18 *
rkennke@52321 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
rkennke@52321 20 * or visit www.oracle.com if you need additional information or have any
rkennke@52321 21 * questions.
rkennke@52321 22 *
rkennke@52321 23 */
rkennke@52321 24
rkennke@52321 25 #ifndef SHARE_VM_GC_SHARED_MARKBITMAP_HPP
rkennke@52321 26 #define SHARE_VM_GC_SHARED_MARKBITMAP_HPP
rkennke@52321 27
rkennke@52321 28 #include "memory/memRegion.hpp"
rkennke@52321 29 #include "oops/oopsHierarchy.hpp"
rkennke@52321 30 #include "utilities/bitMap.hpp"
rkennke@52321 31
rkennke@52321 32 // A generic mark bitmap for concurrent marking. This is essentially a wrapper
rkennke@52321 33 // around the BitMap class that is based on HeapWords, with one bit per (1 << _shifter) HeapWords.
rkennke@52321 34 class MarkBitMap {
rkennke@52321 35 protected:
rkennke@52321 36 MemRegion _covered; // The heap area covered by this bitmap.
rkennke@52321 37
rkennke@52321 38 const int _shifter; // Shift amount from heap index to bit index in the bitmap.
rkennke@52321 39
rkennke@52321 40 BitMapView _bm; // The actual bitmap.
rkennke@52321 41
rkennke@52321 42 virtual void check_mark(HeapWord* addr) NOT_DEBUG_RETURN;
rkennke@52321 43
rkennke@52321 44 // Convert from bit offset to address.
rkennke@52321 45 HeapWord* offset_to_addr(size_t offset) const {
rkennke@52321 46 return _covered.start() + (offset << _shifter);
rkennke@52321 47 }
rkennke@52321 48 // Convert from address to bit offset.
rkennke@52321 49 size_t addr_to_offset(const HeapWord* addr) const {
rkennke@52321 50 return pointer_delta(addr, _covered.start()) >> _shifter;
rkennke@52321 51 }
rkennke@52321 52 public:
rkennke@52321 53 static size_t compute_size(size_t heap_size);
rkennke@52321 54 // Returns the amount of bytes on the heap between two marks in the bitmap.
rkennke@52321 55 static size_t mark_distance();
rkennke@52321 56 // Returns how many bytes (or bits) of the heap a single byte (or bit) of the
rkennke@52321 57 // mark bitmap corresponds to. This is the same as the mark distance above.
rkennke@52321 58 static size_t heap_map_factor() {
rkennke@52321 59 return mark_distance();
rkennke@52321 60 }
rkennke@52321 61
rkennke@52321 62 MarkBitMap() : _covered(), _shifter(LogMinObjAlignment), _bm() {}
rkennke@52321 63
rkennke@52321 64 // Initializes the underlying BitMap to cover the given area.
rkennke@52321 65 void initialize(MemRegion heap, MemRegion storage);
rkennke@52321 66
rkennke@52321 67 // Read marks
rkennke@52321 68 bool is_marked(oop obj) const;
rkennke@52321 69 bool is_marked(HeapWord* addr) const {
rkennke@52321 70 assert(_covered.contains(addr),
rkennke@52321 71 "Address " PTR_FORMAT " is outside underlying space from " PTR_FORMAT " to " PTR_FORMAT,
rkennke@52321 72 p2i(addr), p2i(_covered.start()), p2i(_covered.end()));
rkennke@52321 73 return _bm.at(addr_to_offset(addr));
rkennke@52321 74 }
rkennke@52321 75
rkennke@52321 76 // Return the address corresponding to the next marked bit at or after
rkennke@52321 77 // "addr", and before "limit", if "limit" is non-NULL. If there is no
rkennke@52321 78 // such bit, returns "limit" if that is non-NULL, or else "endWord()".
rkennke@52321 79 inline HeapWord* get_next_marked_addr(const HeapWord* addr,
rkennke@52321 80 const HeapWord* limit) const;
rkennke@52321 81
rkennke@52321 82 void print_on_error(outputStream* st, const char* prefix) const;
rkennke@52321 83
rkennke@52321 84 // Write marks.
rkennke@52321 85 inline void mark(HeapWord* addr);
rkennke@52321 86 inline void clear(HeapWord* addr);
rkennke@52321 87 inline void clear(oop obj);
rkennke@52321 88 inline bool par_mark(HeapWord* addr);
rkennke@52321 89 inline bool par_mark(oop obj);
rkennke@52321 90
rkennke@52321 91 void clear_range(MemRegion mr);
rkennke@52321 92 };
rkennke@52321 93
rkennke@52321 94 #endif // SHARE_VM_GC_SHARED_MARKBITMAP_HPP