1/* 2 * Copyright (c) 2017, 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_VM_GC_G1_G1CONCURRENTMARKBITMAP_HPP 26#define SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_HPP 27 28#include "gc/g1/g1RegionToSpaceMapper.hpp" 29#include "memory/allocation.hpp" 30#include "memory/memRegion.hpp" 31#include "utilities/bitMap.hpp" 32#include "utilities/globalDefinitions.hpp" 33#include "utilities/macros.hpp" 34 35class G1CMBitMap; 36class G1CMTask; 37class G1ConcurrentMark; 38 39// Closure for iteration over bitmaps 40class G1CMBitMapClosure VALUE_OBJ_CLASS_SPEC { 41private: 42 G1ConcurrentMark* const _cm; 43 G1CMTask* const _task; 44public: 45 G1CMBitMapClosure(G1CMTask *task, G1ConcurrentMark* cm) : _task(task), _cm(cm) { } 46 47 bool do_addr(HeapWord* const addr); 48}; 49 50class G1CMBitMapMappingChangedListener : public G1MappingChangedListener { 51 private: 52 G1CMBitMap* _bm; 53 public: 54 G1CMBitMapMappingChangedListener() : _bm(NULL) {} 55 56 void set_bitmap(G1CMBitMap* bm) { _bm = bm; } 57 58 virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled); 59}; 60 61// A generic mark bitmap for concurrent marking. This is essentially a wrapper 62// around the BitMap class that is based on HeapWords, with one bit per (1 << _shifter) HeapWords. 63class G1CMBitMap VALUE_OBJ_CLASS_SPEC { 64private: 65 MemRegion _covered; // The heap area covered by this bitmap. 66 67 const int _shifter; // Shift amount from heap index to bit index in the bitmap. 68 69 BitMapView _bm; // The actual bitmap. 70 71 G1CMBitMapMappingChangedListener _listener; 72 73 inline void check_mark(HeapWord* addr) NOT_DEBUG_RETURN; 74 75 // Convert from bit offset to address. 76 HeapWord* offset_to_addr(size_t offset) const { 77 return _covered.start() + (offset << _shifter); 78 } 79 // Convert from address to bit offset. 80 size_t addr_to_offset(const HeapWord* addr) const { 81 return pointer_delta(addr, _covered.start()) >> _shifter; 82 } 83public: 84 static size_t compute_size(size_t heap_size); 85 // Returns the amount of bytes on the heap between two marks in the bitmap. 86 static size_t mark_distance(); 87 // Returns how many bytes (or bits) of the heap a single byte (or bit) of the 88 // mark bitmap corresponds to. This is the same as the mark distance above. 89 static size_t heap_map_factor() { 90 return mark_distance(); 91 } 92 93 G1CMBitMap() : _covered(), _bm(), _shifter(LogMinObjAlignment), _listener() { _listener.set_bitmap(this); } 94 95 // Initializes the underlying BitMap to cover the given area. 96 void initialize(MemRegion heap, G1RegionToSpaceMapper* storage); 97 98 // Read marks 99 bool is_marked(HeapWord* addr) const { 100 assert(_covered.contains(addr), 101 "Address " PTR_FORMAT " is outside underlying space from " PTR_FORMAT " to " PTR_FORMAT, 102 p2i(addr), p2i(_covered.start()), p2i(_covered.end())); 103 return _bm.at(addr_to_offset(addr)); 104 } 105 106 // Apply the closure to the addresses that correspond to marked bits in the bitmap. 107 inline bool iterate(G1CMBitMapClosure* cl, MemRegion mr); 108 109 // Return the address corresponding to the next marked bit at or after 110 // "addr", and before "limit", if "limit" is non-NULL. If there is no 111 // such bit, returns "limit" if that is non-NULL, or else "endWord()". 112 inline HeapWord* get_next_marked_addr(const HeapWord* addr, 113 const HeapWord* limit) const; 114 115 // The argument addr should be the start address of a valid object 116 inline HeapWord* addr_after_obj(HeapWord* addr); 117 118 void print_on_error(outputStream* st, const char* prefix) const; 119 120 // Write marks. 121 inline void mark(HeapWord* addr); 122 inline void clear(HeapWord* addr); 123 inline bool par_mark(HeapWord* addr); 124 125 void clear_range(MemRegion mr); 126}; 127 128#endif // SHARE_VM_GC_G1_G1CONCURRENTMARKBITMAP_HPP 129