|
1 /* |
|
2 * Copyright (c) 2018, 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_SHARED_MARKBITMAP_HPP |
|
26 #define SHARE_VM_GC_SHARED_MARKBITMAP_HPP |
|
27 |
|
28 #include "memory/memRegion.hpp" |
|
29 #include "oops/oopsHierarchy.hpp" |
|
30 #include "utilities/bitMap.hpp" |
|
31 |
|
32 // A generic mark bitmap for concurrent marking. This is essentially a wrapper |
|
33 // around the BitMap class that is based on HeapWords, with one bit per (1 << _shifter) HeapWords. |
|
34 class MarkBitMap { |
|
35 protected: |
|
36 MemRegion _covered; // The heap area covered by this bitmap. |
|
37 |
|
38 const int _shifter; // Shift amount from heap index to bit index in the bitmap. |
|
39 |
|
40 BitMapView _bm; // The actual bitmap. |
|
41 |
|
42 virtual void check_mark(HeapWord* addr) NOT_DEBUG_RETURN; |
|
43 |
|
44 // Convert from bit offset to address. |
|
45 HeapWord* offset_to_addr(size_t offset) const { |
|
46 return _covered.start() + (offset << _shifter); |
|
47 } |
|
48 // Convert from address to bit offset. |
|
49 size_t addr_to_offset(const HeapWord* addr) const { |
|
50 return pointer_delta(addr, _covered.start()) >> _shifter; |
|
51 } |
|
52 public: |
|
53 static size_t compute_size(size_t heap_size); |
|
54 // Returns the amount of bytes on the heap between two marks in the bitmap. |
|
55 static size_t mark_distance(); |
|
56 // Returns how many bytes (or bits) of the heap a single byte (or bit) of the |
|
57 // mark bitmap corresponds to. This is the same as the mark distance above. |
|
58 static size_t heap_map_factor() { |
|
59 return mark_distance(); |
|
60 } |
|
61 |
|
62 MarkBitMap() : _covered(), _shifter(LogMinObjAlignment), _bm() {} |
|
63 |
|
64 // Initializes the underlying BitMap to cover the given area. |
|
65 void initialize(MemRegion heap, MemRegion storage); |
|
66 |
|
67 // Read marks |
|
68 bool is_marked(oop obj) const; |
|
69 bool is_marked(HeapWord* addr) const { |
|
70 assert(_covered.contains(addr), |
|
71 "Address " PTR_FORMAT " is outside underlying space from " PTR_FORMAT " to " PTR_FORMAT, |
|
72 p2i(addr), p2i(_covered.start()), p2i(_covered.end())); |
|
73 return _bm.at(addr_to_offset(addr)); |
|
74 } |
|
75 |
|
76 // Return the address corresponding to the next marked bit at or after |
|
77 // "addr", and before "limit", if "limit" is non-NULL. If there is no |
|
78 // such bit, returns "limit" if that is non-NULL, or else "endWord()". |
|
79 inline HeapWord* get_next_marked_addr(const HeapWord* addr, |
|
80 const HeapWord* limit) const; |
|
81 |
|
82 void print_on_error(outputStream* st, const char* prefix) const; |
|
83 |
|
84 // Write marks. |
|
85 inline void mark(HeapWord* addr); |
|
86 inline void clear(HeapWord* addr); |
|
87 inline void clear(oop obj); |
|
88 inline bool par_mark(HeapWord* addr); |
|
89 inline bool par_mark(oop obj); |
|
90 |
|
91 void clear_range(MemRegion mr); |
|
92 }; |
|
93 |
|
94 #endif // SHARE_VM_GC_SHARED_MARKBITMAP_HPP |