author | drwhite |
Fri, 22 Jan 2016 06:13:52 -0500 | |
changeset 35879 | 9892f53e92c9 |
parent 35461 | 1068dcb8d315 |
child 35880 | 7b253cfc2eac |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
35879 | 2 |
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. |
1374 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5346
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5346
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5346
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/g1/concurrentG1Refine.hpp" |
27 |
#include "gc/g1/g1BlockOffsetTable.inline.hpp" |
|
28 |
#include "gc/g1/g1CollectedHeap.inline.hpp" |
|
29 |
#include "gc/g1/heapRegionManager.inline.hpp" |
|
30 |
#include "gc/g1/heapRegionRemSet.hpp" |
|
31 |
#include "gc/shared/space.inline.hpp" |
|
7397 | 32 |
#include "memory/allocation.hpp" |
23452
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
23451
diff
changeset
|
33 |
#include "memory/padded.inline.hpp" |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
34 |
#include "oops/oop.inline.hpp" |
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
24424
diff
changeset
|
35 |
#include "runtime/atomic.inline.hpp" |
7397 | 36 |
#include "utilities/bitMap.inline.hpp" |
37 |
#include "utilities/globalDefinitions.hpp" |
|
19339 | 38 |
#include "utilities/growableArray.hpp" |
1374 | 39 |
|
13195 | 40 |
class PerRegionTable: public CHeapObj<mtGC> { |
1374 | 41 |
friend class OtherRegionsTable; |
42 |
friend class HeapRegionRemSetIterator; |
|
43 |
||
44 |
HeapRegion* _hr; |
|
45 |
BitMap _bm; |
|
46 |
jint _occupied; |
|
47 |
||
13335 | 48 |
// next pointer for free/allocated 'all' list |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
49 |
PerRegionTable* _next; |
1374 | 50 |
|
13335 | 51 |
// prev pointer for the allocated 'all' list |
52 |
PerRegionTable* _prev; |
|
1374 | 53 |
|
13335 | 54 |
// next pointer in collision list |
55 |
PerRegionTable * _collision_list_next; |
|
1374 | 56 |
|
13335 | 57 |
// Global free list of PRTs |
58 |
static PerRegionTable* _free_list; |
|
1374 | 59 |
|
60 |
protected: |
|
61 |
// We need access in order to union things into the base table. |
|
62 |
BitMap* bm() { return &_bm; } |
|
63 |
||
64 |
void recount_occupied() { |
|
65 |
_occupied = (jint) bm()->count_one_bits(); |
|
66 |
} |
|
67 |
||
68 |
PerRegionTable(HeapRegion* hr) : |
|
69 |
_hr(hr), |
|
70 |
_occupied(0), |
|
13335 | 71 |
_bm(HeapRegion::CardsPerRegion, false /* in-resource-area */), |
72 |
_collision_list_next(NULL), _next(NULL), _prev(NULL) |
|
1374 | 73 |
{} |
74 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
75 |
void add_card_work(CardIdx_t from_card, bool par) { |
1374 | 76 |
if (!_bm.at(from_card)) { |
77 |
if (par) { |
|
78 |
if (_bm.par_at_put(from_card, 1)) { |
|
79 |
Atomic::inc(&_occupied); |
|
80 |
} |
|
81 |
} else { |
|
82 |
_bm.at_put(from_card, 1); |
|
83 |
_occupied++; |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
||
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
88 |
void add_reference_work(OopOrNarrowOopStar from, bool par) { |
1374 | 89 |
// Must make this robust in case "from" is not in "_hr", because of |
90 |
// concurrency. |
|
91 |
||
92 |
HeapRegion* loc_hr = hr(); |
|
93 |
// If the test below fails, then this table was reused concurrently |
|
94 |
// with this operation. This is OK, since the old table was coarsened, |
|
95 |
// and adding a bit to the new table is never incorrect. |
|
10767
4ce4a9b10523
7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents:
10677
diff
changeset
|
96 |
// If the table used to belong to a continues humongous region and is |
4ce4a9b10523
7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents:
10677
diff
changeset
|
97 |
// now reused for the corresponding start humongous region, we need to |
4ce4a9b10523
7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents:
10677
diff
changeset
|
98 |
// make sure that we detect this. Thus, we call is_in_reserved_raw() |
4ce4a9b10523
7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents:
10677
diff
changeset
|
99 |
// instead of just is_in_reserved() here. |
33786
ac8da6513351
8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents:
33783
diff
changeset
|
100 |
if (loc_hr->is_in_reserved(from)) { |
1374 | 101 |
size_t hw_offset = pointer_delta((HeapWord*)from, loc_hr->bottom()); |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
102 |
CardIdx_t from_card = (CardIdx_t) |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
103 |
hw_offset >> (CardTableModRefBS::card_shift - LogHeapWordSize); |
1374 | 104 |
|
10677
370a8da2d63f
7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
johnc
parents:
10243
diff
changeset
|
105 |
assert(0 <= from_card && (size_t)from_card < HeapRegion::CardsPerRegion, |
3697
ea9211aa02f5
6819085: G1: use larger and/or user settable region size
tonyp
parents:
3262
diff
changeset
|
106 |
"Must be in range."); |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
107 |
add_card_work(from_card, par); |
1374 | 108 |
} |
109 |
} |
|
110 |
||
111 |
public: |
|
112 |
||
113 |
HeapRegion* hr() const { return _hr; } |
|
114 |
||
115 |
jint occupied() const { |
|
116 |
// Overkill, but if we ever need it... |
|
117 |
// guarantee(_occupied == _bm.count_one_bits(), "Check"); |
|
118 |
return _occupied; |
|
119 |
} |
|
120 |
||
13335 | 121 |
void init(HeapRegion* hr, bool clear_links_to_all_list) { |
122 |
if (clear_links_to_all_list) { |
|
123 |
set_next(NULL); |
|
124 |
set_prev(NULL); |
|
125 |
} |
|
1374 | 126 |
_hr = hr; |
13335 | 127 |
_collision_list_next = NULL; |
1374 | 128 |
_occupied = 0; |
129 |
_bm.clear(); |
|
130 |
} |
|
131 |
||
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
132 |
void add_reference(OopOrNarrowOopStar from) { |
1374 | 133 |
add_reference_work(from, /*parallel*/ true); |
134 |
} |
|
135 |
||
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
136 |
void seq_add_reference(OopOrNarrowOopStar from) { |
1374 | 137 |
add_reference_work(from, /*parallel*/ false); |
138 |
} |
|
139 |
||
140 |
void scrub(CardTableModRefBS* ctbs, BitMap* card_bm) { |
|
141 |
HeapWord* hr_bot = hr()->bottom(); |
|
1676
d80e69372634
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
1374
diff
changeset
|
142 |
size_t hr_first_card_index = ctbs->index_for(hr_bot); |
1374 | 143 |
bm()->set_intersection_at_offset(*card_bm, hr_first_card_index); |
144 |
recount_occupied(); |
|
145 |
} |
|
146 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
147 |
void add_card(CardIdx_t from_card_index) { |
1374 | 148 |
add_card_work(from_card_index, /*parallel*/ true); |
149 |
} |
|
150 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
151 |
void seq_add_card(CardIdx_t from_card_index) { |
1374 | 152 |
add_card_work(from_card_index, /*parallel*/ false); |
153 |
} |
|
154 |
||
155 |
// (Destructively) union the bitmap of the current table into the given |
|
156 |
// bitmap (which is assumed to be of the same size.) |
|
157 |
void union_bitmap_into(BitMap* bm) { |
|
158 |
bm->set_union(_bm); |
|
159 |
} |
|
160 |
||
161 |
// Mem size in bytes. |
|
162 |
size_t mem_size() const { |
|
24108
dfc2242fc6b0
8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents:
24106
diff
changeset
|
163 |
return sizeof(PerRegionTable) + _bm.size_in_words() * HeapWordSize; |
1374 | 164 |
} |
165 |
||
166 |
// Requires "from" to be in "hr()". |
|
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
167 |
bool contains_reference(OopOrNarrowOopStar from) const { |
1374 | 168 |
assert(hr()->is_in_reserved(from), "Precondition."); |
169 |
size_t card_ind = pointer_delta(from, hr()->bottom(), |
|
170 |
CardTableModRefBS::card_size); |
|
171 |
return _bm.at(card_ind); |
|
172 |
} |
|
173 |
||
13335 | 174 |
// Bulk-free the PRTs from prt to last, assumes that they are |
175 |
// linked together using their _next field. |
|
176 |
static void bulk_free(PerRegionTable* prt, PerRegionTable* last) { |
|
1374 | 177 |
while (true) { |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
178 |
PerRegionTable* fl = _free_list; |
13335 | 179 |
last->set_next(fl); |
180 |
PerRegionTable* res = (PerRegionTable*) Atomic::cmpxchg_ptr(prt, &_free_list, fl); |
|
181 |
if (res == fl) { |
|
182 |
return; |
|
183 |
} |
|
1374 | 184 |
} |
185 |
ShouldNotReachHere(); |
|
186 |
} |
|
187 |
||
13335 | 188 |
static void free(PerRegionTable* prt) { |
189 |
bulk_free(prt, prt); |
|
190 |
} |
|
191 |
||
192 |
// Returns an initialized PerRegionTable instance. |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
193 |
static PerRegionTable* alloc(HeapRegion* hr) { |
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
194 |
PerRegionTable* fl = _free_list; |
1374 | 195 |
while (fl != NULL) { |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
196 |
PerRegionTable* nxt = fl->next(); |
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
197 |
PerRegionTable* res = |
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
198 |
(PerRegionTable*) |
1374 | 199 |
Atomic::cmpxchg_ptr(nxt, &_free_list, fl); |
200 |
if (res == fl) { |
|
13335 | 201 |
fl->init(hr, true); |
1374 | 202 |
return fl; |
203 |
} else { |
|
204 |
fl = _free_list; |
|
205 |
} |
|
206 |
} |
|
207 |
assert(fl == NULL, "Loop condition."); |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
208 |
return new PerRegionTable(hr); |
1374 | 209 |
} |
210 |
||
13335 | 211 |
PerRegionTable* next() const { return _next; } |
212 |
void set_next(PerRegionTable* next) { _next = next; } |
|
213 |
PerRegionTable* prev() const { return _prev; } |
|
214 |
void set_prev(PerRegionTable* prev) { _prev = prev; } |
|
215 |
||
216 |
// Accessor and Modification routines for the pointer for the |
|
217 |
// singly linked collision list that links the PRTs within the |
|
218 |
// OtherRegionsTable::_fine_grain_regions hash table. |
|
219 |
// |
|
220 |
// It might be useful to also make the collision list doubly linked |
|
221 |
// to avoid iteration over the collisions list during scrubbing/deletion. |
|
222 |
// OTOH there might not be many collisions. |
|
223 |
||
224 |
PerRegionTable* collision_list_next() const { |
|
225 |
return _collision_list_next; |
|
226 |
} |
|
227 |
||
228 |
void set_collision_list_next(PerRegionTable* next) { |
|
229 |
_collision_list_next = next; |
|
230 |
} |
|
231 |
||
232 |
PerRegionTable** collision_list_next_addr() { |
|
233 |
return &_collision_list_next; |
|
234 |
} |
|
235 |
||
1374 | 236 |
static size_t fl_mem_size() { |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
237 |
PerRegionTable* cur = _free_list; |
1374 | 238 |
size_t res = 0; |
239 |
while (cur != NULL) { |
|
17631
17992863b0ab
8014405: G1: PerRegionTable::fl_mem_size() calculates size of the free list using wrong element sizes
tschatzl
parents:
17398
diff
changeset
|
240 |
res += cur->mem_size(); |
1374 | 241 |
cur = cur->next(); |
242 |
} |
|
243 |
return res; |
|
244 |
} |
|
17631
17992863b0ab
8014405: G1: PerRegionTable::fl_mem_size() calculates size of the free list using wrong element sizes
tschatzl
parents:
17398
diff
changeset
|
245 |
|
17992863b0ab
8014405: G1: PerRegionTable::fl_mem_size() calculates size of the free list using wrong element sizes
tschatzl
parents:
17398
diff
changeset
|
246 |
static void test_fl_mem_size(); |
1374 | 247 |
}; |
248 |
||
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
249 |
PerRegionTable* PerRegionTable::_free_list = NULL; |
1374 | 250 |
|
251 |
size_t OtherRegionsTable::_max_fine_entries = 0; |
|
252 |
size_t OtherRegionsTable::_mod_max_fine_entries_mask = 0; |
|
253 |
size_t OtherRegionsTable::_fine_eviction_stride = 0; |
|
254 |
size_t OtherRegionsTable::_fine_eviction_sample_size = 0; |
|
255 |
||
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
256 |
OtherRegionsTable::OtherRegionsTable(HeapRegion* hr, Mutex* m) : |
1374 | 257 |
_g1h(G1CollectedHeap::heap()), |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
258 |
_hr(hr), _m(m), |
1374 | 259 |
_coarse_map(G1CollectedHeap::heap()->max_regions(), |
260 |
false /* in-resource-area */), |
|
261 |
_fine_grain_regions(NULL), |
|
13335 | 262 |
_first_all_fine_prts(NULL), _last_all_fine_prts(NULL), |
1374 | 263 |
_n_fine_entries(0), _n_coarse_entries(0), |
264 |
_fine_eviction_start(0), |
|
265 |
_sparse_table(hr) |
|
266 |
{ |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
267 |
typedef PerRegionTable* PerRegionTablePtr; |
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
268 |
|
1374 | 269 |
if (_max_fine_entries == 0) { |
270 |
assert(_mod_max_fine_entries_mask == 0, "Both or none."); |
|
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
271 |
size_t max_entries_log = (size_t)log2_long((jlong)G1RSetRegionEntries); |
13752
92f03fcf979a
7197906: BlockOffsetArray::power_to_cards_back() needs to handle > 32 bit shifts
brutisso
parents:
13335
diff
changeset
|
272 |
_max_fine_entries = (size_t)1 << max_entries_log; |
1374 | 273 |
_mod_max_fine_entries_mask = _max_fine_entries - 1; |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
274 |
|
1374 | 275 |
assert(_fine_eviction_sample_size == 0 |
276 |
&& _fine_eviction_stride == 0, "All init at same time."); |
|
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
277 |
_fine_eviction_sample_size = MAX2((size_t)4, max_entries_log); |
1374 | 278 |
_fine_eviction_stride = _max_fine_entries / _fine_eviction_sample_size; |
279 |
} |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
280 |
|
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17119
diff
changeset
|
281 |
_fine_grain_regions = NEW_C_HEAP_ARRAY3(PerRegionTablePtr, _max_fine_entries, |
25946 | 282 |
mtGC, CURRENT_PC, AllocFailStrategy::RETURN_NULL); |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
283 |
|
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
284 |
if (_fine_grain_regions == NULL) { |
17087
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
17031
diff
changeset
|
285 |
vm_exit_out_of_memory(sizeof(void*)*_max_fine_entries, OOM_MALLOC_ERROR, |
1374 | 286 |
"Failed to allocate _fine_grain_entries."); |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
287 |
} |
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
288 |
|
1374 | 289 |
for (size_t i = 0; i < _max_fine_entries; i++) { |
290 |
_fine_grain_regions[i] = NULL; |
|
291 |
} |
|
292 |
} |
|
293 |
||
13335 | 294 |
void OtherRegionsTable::link_to_all(PerRegionTable* prt) { |
295 |
// We always append to the beginning of the list for convenience; |
|
296 |
// the order of entries in this list does not matter. |
|
297 |
if (_first_all_fine_prts != NULL) { |
|
298 |
assert(_first_all_fine_prts->prev() == NULL, "invariant"); |
|
299 |
_first_all_fine_prts->set_prev(prt); |
|
300 |
prt->set_next(_first_all_fine_prts); |
|
301 |
} else { |
|
302 |
// this is the first element we insert. Adjust the "last" pointer |
|
303 |
_last_all_fine_prts = prt; |
|
304 |
assert(prt->next() == NULL, "just checking"); |
|
305 |
} |
|
306 |
// the new element is always the first element without a predecessor |
|
307 |
prt->set_prev(NULL); |
|
308 |
_first_all_fine_prts = prt; |
|
309 |
||
310 |
assert(prt->prev() == NULL, "just checking"); |
|
311 |
assert(_first_all_fine_prts == prt, "just checking"); |
|
312 |
assert((_first_all_fine_prts == NULL && _last_all_fine_prts == NULL) || |
|
313 |
(_first_all_fine_prts != NULL && _last_all_fine_prts != NULL), |
|
314 |
"just checking"); |
|
315 |
assert(_last_all_fine_prts == NULL || _last_all_fine_prts->next() == NULL, |
|
316 |
"just checking"); |
|
317 |
assert(_first_all_fine_prts == NULL || _first_all_fine_prts->prev() == NULL, |
|
318 |
"just checking"); |
|
319 |
} |
|
320 |
||
321 |
void OtherRegionsTable::unlink_from_all(PerRegionTable* prt) { |
|
322 |
if (prt->prev() != NULL) { |
|
323 |
assert(_first_all_fine_prts != prt, "just checking"); |
|
324 |
prt->prev()->set_next(prt->next()); |
|
325 |
// removing the last element in the list? |
|
326 |
if (_last_all_fine_prts == prt) { |
|
327 |
_last_all_fine_prts = prt->prev(); |
|
328 |
} |
|
329 |
} else { |
|
330 |
assert(_first_all_fine_prts == prt, "just checking"); |
|
331 |
_first_all_fine_prts = prt->next(); |
|
332 |
// list is empty now? |
|
333 |
if (_first_all_fine_prts == NULL) { |
|
334 |
_last_all_fine_prts = NULL; |
|
335 |
} |
|
336 |
} |
|
337 |
||
338 |
if (prt->next() != NULL) { |
|
339 |
prt->next()->set_prev(prt->prev()); |
|
340 |
} |
|
341 |
||
342 |
prt->set_next(NULL); |
|
343 |
prt->set_prev(NULL); |
|
344 |
||
345 |
assert((_first_all_fine_prts == NULL && _last_all_fine_prts == NULL) || |
|
346 |
(_first_all_fine_prts != NULL && _last_all_fine_prts != NULL), |
|
347 |
"just checking"); |
|
348 |
assert(_last_all_fine_prts == NULL || _last_all_fine_prts->next() == NULL, |
|
349 |
"just checking"); |
|
350 |
assert(_first_all_fine_prts == NULL || _first_all_fine_prts->prev() == NULL, |
|
351 |
"just checking"); |
|
352 |
} |
|
353 |
||
26850
515ff48cf5f0
8036116: Fix thread-id types in G1 remembered set implementations
brutisso
parents:
26424
diff
changeset
|
354 |
void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, uint tid) { |
28030 | 355 |
uint cur_hrm_ind = _hr->hrm_index(); |
1374 | 356 |
|
357 |
int from_card = (int)(uintptr_t(from) >> CardTableModRefBS::card_shift); |
|
358 |
||
35200
7802299b31e7
8145671: Rename FromCardCache to G1FromCardCache
tschatzl
parents:
35199
diff
changeset
|
359 |
if (G1FromCardCache::contains_or_replace(tid, cur_hrm_ind, from_card)) { |
1374 | 360 |
assert(contains_reference(from), "We just added it!"); |
361 |
return; |
|
362 |
} |
|
363 |
||
364 |
// Note that this may be a continued H region. |
|
33786
ac8da6513351
8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents:
33783
diff
changeset
|
365 |
HeapRegion* from_hr = _g1h->heap_region_containing(from); |
26424
639e661f19f3
8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents:
26422
diff
changeset
|
366 |
RegionIdx_t from_hrm_ind = (RegionIdx_t) from_hr->hrm_index(); |
1374 | 367 |
|
368 |
// If the region is already coarsened, return. |
|
26424
639e661f19f3
8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents:
26422
diff
changeset
|
369 |
if (_coarse_map.at(from_hrm_ind)) { |
1374 | 370 |
assert(contains_reference(from), "We just added it!"); |
371 |
return; |
|
372 |
} |
|
373 |
||
374 |
// Otherwise find a per-region table to add it to. |
|
26424
639e661f19f3
8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents:
26422
diff
changeset
|
375 |
size_t ind = from_hrm_ind & _mod_max_fine_entries_mask; |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
376 |
PerRegionTable* prt = find_region_table(ind, from_hr); |
1374 | 377 |
if (prt == NULL) { |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
378 |
MutexLockerEx x(_m, Mutex::_no_safepoint_check_flag); |
1374 | 379 |
// Confirm that it's really not there... |
380 |
prt = find_region_table(ind, from_hr); |
|
381 |
if (prt == NULL) { |
|
382 |
||
383 |
uintptr_t from_hr_bot_card_index = |
|
384 |
uintptr_t(from_hr->bottom()) |
|
385 |
>> CardTableModRefBS::card_shift; |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
386 |
CardIdx_t card_index = from_card - from_hr_bot_card_index; |
10677
370a8da2d63f
7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
johnc
parents:
10243
diff
changeset
|
387 |
assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion, |
1374 | 388 |
"Must be in range."); |
389 |
if (G1HRRSUseSparseTable && |
|
26424
639e661f19f3
8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents:
26422
diff
changeset
|
390 |
_sparse_table.add_card(from_hrm_ind, card_index)) { |
1374 | 391 |
assert(contains_reference_locked(from), "We just added it!"); |
392 |
return; |
|
393 |
} |
|
394 |
||
395 |
if (_n_fine_entries == _max_fine_entries) { |
|
396 |
prt = delete_region_table(); |
|
13335 | 397 |
// There is no need to clear the links to the 'all' list here: |
398 |
// prt will be reused immediately, i.e. remain in the 'all' list. |
|
399 |
prt->init(from_hr, false /* clear_links_to_all_list */); |
|
1374 | 400 |
} else { |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
401 |
prt = PerRegionTable::alloc(from_hr); |
13335 | 402 |
link_to_all(prt); |
1374 | 403 |
} |
404 |
||
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
405 |
PerRegionTable* first_prt = _fine_grain_regions[ind]; |
13335 | 406 |
prt->set_collision_list_next(first_prt); |
30765
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
407 |
// The assignment into _fine_grain_regions allows the prt to |
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
408 |
// start being used concurrently. In addition to |
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
409 |
// collision_list_next which must be visible (else concurrent |
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
410 |
// parsing of the list, if any, may fail to see other entries), |
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
411 |
// the content of the prt must be visible (else for instance |
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
412 |
// some mark bits may not yet seem cleared or a 'later' update |
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
413 |
// performed by a concurrent thread could be undone when the |
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
414 |
// zeroing becomes visible). This requires store ordering. |
32398da8ba8f
8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents:
30764
diff
changeset
|
415 |
OrderAccess::release_store_ptr((volatile PerRegionTable*)&_fine_grain_regions[ind], prt); |
1374 | 416 |
_n_fine_entries++; |
417 |
||
418 |
if (G1HRRSUseSparseTable) { |
|
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
419 |
// Transfer from sparse to fine-grain. |
26424
639e661f19f3
8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents:
26422
diff
changeset
|
420 |
SparsePRTEntry *sprt_entry = _sparse_table.get_entry(from_hrm_ind); |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
421 |
assert(sprt_entry != NULL, "There should have been an entry"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
422 |
for (int i = 0; i < SparsePRTEntry::cards_num(); i++) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
423 |
CardIdx_t c = sprt_entry->card(i); |
1374 | 424 |
if (c != SparsePRTEntry::NullEntry) { |
425 |
prt->add_card(c); |
|
426 |
} |
|
427 |
} |
|
428 |
// Now we can delete the sparse entry. |
|
26424
639e661f19f3
8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents:
26422
diff
changeset
|
429 |
bool res = _sparse_table.delete_entry(from_hrm_ind); |
1374 | 430 |
assert(res, "It should have been there."); |
431 |
} |
|
432 |
} |
|
433 |
assert(prt != NULL && prt->hr() == from_hr, "consequence"); |
|
434 |
} |
|
435 |
// Note that we can't assert "prt->hr() == from_hr", because of the |
|
436 |
// possibility of concurrent reuse. But see head comment of |
|
437 |
// OtherRegionsTable for why this is OK. |
|
438 |
assert(prt != NULL, "Inv"); |
|
439 |
||
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
440 |
prt->add_reference(from); |
1374 | 441 |
assert(contains_reference(from), "We just added it!"); |
442 |
} |
|
443 |
||
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
444 |
PerRegionTable* |
1374 | 445 |
OtherRegionsTable::find_region_table(size_t ind, HeapRegion* hr) const { |
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
28379
diff
changeset
|
446 |
assert(ind < _max_fine_entries, "Preconditions."); |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
447 |
PerRegionTable* prt = _fine_grain_regions[ind]; |
1374 | 448 |
while (prt != NULL && prt->hr() != hr) { |
13335 | 449 |
prt = prt->collision_list_next(); |
1374 | 450 |
} |
451 |
// Loop postcondition is the method postcondition. |
|
452 |
return prt; |
|
453 |
} |
|
454 |
||
455 |
jint OtherRegionsTable::_n_coarsenings = 0; |
|
456 |
||
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
457 |
PerRegionTable* OtherRegionsTable::delete_region_table() { |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
458 |
assert(_m->owned_by_self(), "Precondition"); |
1374 | 459 |
assert(_n_fine_entries == _max_fine_entries, "Precondition"); |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
460 |
PerRegionTable* max = NULL; |
1374 | 461 |
jint max_occ = 0; |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33105
diff
changeset
|
462 |
PerRegionTable** max_prev = NULL; |
1374 | 463 |
size_t max_ind; |
464 |
||
465 |
size_t i = _fine_eviction_start; |
|
466 |
for (size_t k = 0; k < _fine_eviction_sample_size; k++) { |
|
467 |
size_t ii = i; |
|
468 |
// Make sure we get a non-NULL sample. |
|
469 |
while (_fine_grain_regions[ii] == NULL) { |
|
470 |
ii++; |
|
471 |
if (ii == _max_fine_entries) ii = 0; |
|
472 |
guarantee(ii != i, "We must find one."); |
|
473 |
} |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
474 |
PerRegionTable** prev = &_fine_grain_regions[ii]; |
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
475 |
PerRegionTable* cur = *prev; |
1374 | 476 |
while (cur != NULL) { |
477 |
jint cur_occ = cur->occupied(); |
|
478 |
if (max == NULL || cur_occ > max_occ) { |
|
479 |
max = cur; |
|
480 |
max_prev = prev; |
|
481 |
max_ind = i; |
|
482 |
max_occ = cur_occ; |
|
483 |
} |
|
13335 | 484 |
prev = cur->collision_list_next_addr(); |
485 |
cur = cur->collision_list_next(); |
|
1374 | 486 |
} |
487 |
i = i + _fine_eviction_stride; |
|
488 |
if (i >= _n_fine_entries) i = i - _n_fine_entries; |
|
489 |
} |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
490 |
|
1374 | 491 |
_fine_eviction_start++; |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
492 |
|
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
493 |
if (_fine_eviction_start >= _n_fine_entries) { |
1374 | 494 |
_fine_eviction_start -= _n_fine_entries; |
495 |
} |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
496 |
|
1374 | 497 |
guarantee(max != NULL, "Since _n_fine_entries > 0"); |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33105
diff
changeset
|
498 |
guarantee(max_prev != NULL, "Since max != NULL."); |
1374 | 499 |
|
500 |
// Set the corresponding coarse bit. |
|
26316
93f6b40c038b
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
26160
diff
changeset
|
501 |
size_t max_hrm_index = (size_t) max->hr()->hrm_index(); |
93f6b40c038b
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
26160
diff
changeset
|
502 |
if (!_coarse_map.at(max_hrm_index)) { |
93f6b40c038b
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
26160
diff
changeset
|
503 |
_coarse_map.at_put(max_hrm_index, true); |
1374 | 504 |
_n_coarse_entries++; |
505 |
} |
|
506 |
||
507 |
// Unsplice. |
|
13335 | 508 |
*max_prev = max->collision_list_next(); |
1374 | 509 |
Atomic::inc(&_n_coarsenings); |
510 |
_n_fine_entries--; |
|
511 |
return max; |
|
512 |
} |
|
513 |
||
514 |
void OtherRegionsTable::scrub(CardTableModRefBS* ctbs, |
|
515 |
BitMap* region_bm, BitMap* card_bm) { |
|
516 |
// First eliminated garbage regions from the coarse map. |
|
35061 | 517 |
log_develop_trace(gc, remset, scrub)("Scrubbing region %u:", _hr->hrm_index()); |
1374 | 518 |
|
519 |
assert(_coarse_map.size() == region_bm->size(), "Precondition"); |
|
35061 | 520 |
log_develop_trace(gc, remset, scrub)(" Coarse map: before = " SIZE_FORMAT "...", _n_coarse_entries); |
1374 | 521 |
_coarse_map.set_intersection(*region_bm); |
522 |
_n_coarse_entries = _coarse_map.count_one_bits(); |
|
35061 | 523 |
log_develop_trace(gc, remset, scrub)(" after = " SIZE_FORMAT ".", _n_coarse_entries); |
1374 | 524 |
|
525 |
// Now do the fine-grained maps. |
|
526 |
for (size_t i = 0; i < _max_fine_entries; i++) { |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
527 |
PerRegionTable* cur = _fine_grain_regions[i]; |
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
528 |
PerRegionTable** prev = &_fine_grain_regions[i]; |
1374 | 529 |
while (cur != NULL) { |
13335 | 530 |
PerRegionTable* nxt = cur->collision_list_next(); |
1374 | 531 |
// If the entire region is dead, eliminate. |
35061 | 532 |
log_develop_trace(gc, remset, scrub)(" For other region %u:", cur->hr()->hrm_index()); |
26316
93f6b40c038b
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
26160
diff
changeset
|
533 |
if (!region_bm->at((size_t) cur->hr()->hrm_index())) { |
1374 | 534 |
*prev = nxt; |
13335 | 535 |
cur->set_collision_list_next(NULL); |
1374 | 536 |
_n_fine_entries--; |
35061 | 537 |
log_develop_trace(gc, remset, scrub)(" deleted via region map."); |
13335 | 538 |
unlink_from_all(cur); |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
539 |
PerRegionTable::free(cur); |
1374 | 540 |
} else { |
541 |
// Do fine-grain elimination. |
|
35061 | 542 |
log_develop_trace(gc, remset, scrub)(" occ: before = %4d.", cur->occupied()); |
1374 | 543 |
cur->scrub(ctbs, card_bm); |
35061 | 544 |
log_develop_trace(gc, remset, scrub)(" after = %4d.", cur->occupied()); |
1374 | 545 |
// Did that empty the table completely? |
546 |
if (cur->occupied() == 0) { |
|
547 |
*prev = nxt; |
|
13335 | 548 |
cur->set_collision_list_next(NULL); |
1374 | 549 |
_n_fine_entries--; |
13335 | 550 |
unlink_from_all(cur); |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
551 |
PerRegionTable::free(cur); |
1374 | 552 |
} else { |
13335 | 553 |
prev = cur->collision_list_next_addr(); |
1374 | 554 |
} |
555 |
} |
|
556 |
cur = nxt; |
|
557 |
} |
|
558 |
} |
|
559 |
// Since we may have deleted a from_card_cache entry from the RS, clear |
|
560 |
// the FCC. |
|
561 |
clear_fcc(); |
|
562 |
} |
|
563 |
||
28379
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
564 |
bool OtherRegionsTable::occupancy_less_or_equal_than(size_t limit) const { |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
565 |
if (limit <= (size_t)G1RSetSparseRegionEntries) { |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
566 |
return occ_coarse() == 0 && _first_all_fine_prts == NULL && occ_sparse() <= limit; |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
567 |
} else { |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
568 |
// Current uses of this method may only use values less than G1RSetSparseRegionEntries |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
569 |
// for the limit. The solution, comparing against occupied() would be too slow |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
570 |
// at this time. |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
571 |
Unimplemented(); |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
572 |
return false; |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
573 |
} |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
574 |
} |
e6784fc8fff2
8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents:
28170
diff
changeset
|
575 |
|
25889
221296ac4359
8027959: Early reclamation of large objects in G1
tschatzl
parents:
25492
diff
changeset
|
576 |
bool OtherRegionsTable::is_empty() const { |
221296ac4359
8027959: Early reclamation of large objects in G1
tschatzl
parents:
25492
diff
changeset
|
577 |
return occ_sparse() == 0 && occ_coarse() == 0 && _first_all_fine_prts == NULL; |
221296ac4359
8027959: Early reclamation of large objects in G1
tschatzl
parents:
25492
diff
changeset
|
578 |
} |
1374 | 579 |
|
580 |
size_t OtherRegionsTable::occupied() const { |
|
581 |
size_t sum = occ_fine(); |
|
582 |
sum += occ_sparse(); |
|
583 |
sum += occ_coarse(); |
|
584 |
return sum; |
|
585 |
} |
|
586 |
||
587 |
size_t OtherRegionsTable::occ_fine() const { |
|
588 |
size_t sum = 0; |
|
13335 | 589 |
|
590 |
size_t num = 0; |
|
591 |
PerRegionTable * cur = _first_all_fine_prts; |
|
592 |
while (cur != NULL) { |
|
593 |
sum += cur->occupied(); |
|
594 |
cur = cur->next(); |
|
595 |
num++; |
|
1374 | 596 |
} |
13335 | 597 |
guarantee(num == _n_fine_entries, "just checking"); |
1374 | 598 |
return sum; |
599 |
} |
|
600 |
||
601 |
size_t OtherRegionsTable::occ_coarse() const { |
|
3697
ea9211aa02f5
6819085: G1: use larger and/or user settable region size
tonyp
parents:
3262
diff
changeset
|
602 |
return (_n_coarse_entries * HeapRegion::CardsPerRegion); |
1374 | 603 |
} |
604 |
||
605 |
size_t OtherRegionsTable::occ_sparse() const { |
|
606 |
return _sparse_table.occupied(); |
|
607 |
} |
|
608 |
||
609 |
size_t OtherRegionsTable::mem_size() const { |
|
610 |
size_t sum = 0; |
|
17395
2cd3ef1be718
8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents:
17119
diff
changeset
|
611 |
// all PRTs are of the same size so it is sufficient to query only one of them. |
2cd3ef1be718
8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents:
17119
diff
changeset
|
612 |
if (_first_all_fine_prts != NULL) { |
2cd3ef1be718
8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents:
17119
diff
changeset
|
613 |
assert(_last_all_fine_prts != NULL && |
2cd3ef1be718
8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents:
17119
diff
changeset
|
614 |
_first_all_fine_prts->mem_size() == _last_all_fine_prts->mem_size(), "check that mem_size() is constant"); |
2cd3ef1be718
8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents:
17119
diff
changeset
|
615 |
sum += _first_all_fine_prts->mem_size() * _n_fine_entries; |
1374 | 616 |
} |
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
617 |
sum += (sizeof(PerRegionTable*) * _max_fine_entries); |
1374 | 618 |
sum += (_coarse_map.size_in_words() * HeapWordSize); |
619 |
sum += (_sparse_table.mem_size()); |
|
24108
dfc2242fc6b0
8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents:
24106
diff
changeset
|
620 |
sum += sizeof(OtherRegionsTable) - sizeof(_sparse_table); // Avoid double counting above. |
1374 | 621 |
return sum; |
622 |
} |
|
623 |
||
624 |
size_t OtherRegionsTable::static_mem_size() { |
|
35200
7802299b31e7
8145671: Rename FromCardCache to G1FromCardCache
tschatzl
parents:
35199
diff
changeset
|
625 |
return G1FromCardCache::static_mem_size(); |
1374 | 626 |
} |
627 |
||
628 |
size_t OtherRegionsTable::fl_mem_size() { |
|
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
629 |
return PerRegionTable::fl_mem_size(); |
1374 | 630 |
} |
631 |
||
632 |
void OtherRegionsTable::clear_fcc() { |
|
35200
7802299b31e7
8145671: Rename FromCardCache to G1FromCardCache
tschatzl
parents:
35199
diff
changeset
|
633 |
G1FromCardCache::clear(_hr->hrm_index()); |
1374 | 634 |
} |
635 |
||
636 |
void OtherRegionsTable::clear() { |
|
13335 | 637 |
// if there are no entries, skip this step |
638 |
if (_first_all_fine_prts != NULL) { |
|
639 |
guarantee(_first_all_fine_prts != NULL && _last_all_fine_prts != NULL, "just checking"); |
|
640 |
PerRegionTable::bulk_free(_first_all_fine_prts, _last_all_fine_prts); |
|
641 |
memset(_fine_grain_regions, 0, _max_fine_entries * sizeof(_fine_grain_regions[0])); |
|
642 |
} else { |
|
643 |
guarantee(_first_all_fine_prts == NULL && _last_all_fine_prts == NULL, "just checking"); |
|
1374 | 644 |
} |
13335 | 645 |
|
646 |
_first_all_fine_prts = _last_all_fine_prts = NULL; |
|
1374 | 647 |
_sparse_table.clear(); |
648 |
_coarse_map.clear(); |
|
649 |
_n_fine_entries = 0; |
|
650 |
_n_coarse_entries = 0; |
|
651 |
||
652 |
clear_fcc(); |
|
653 |
} |
|
654 |
||
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
655 |
bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const { |
1374 | 656 |
// Cast away const in this case. |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
657 |
MutexLockerEx x((Mutex*)_m, Mutex::_no_safepoint_check_flag); |
1374 | 658 |
return contains_reference_locked(from); |
659 |
} |
|
660 |
||
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
661 |
bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const { |
33786
ac8da6513351
8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents:
33783
diff
changeset
|
662 |
HeapRegion* hr = _g1h->heap_region_containing(from); |
26316
93f6b40c038b
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
26160
diff
changeset
|
663 |
RegionIdx_t hr_ind = (RegionIdx_t) hr->hrm_index(); |
1374 | 664 |
// Is this region in the coarse map? |
665 |
if (_coarse_map.at(hr_ind)) return true; |
|
666 |
||
13113
ab3870a79b18
6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents:
12779
diff
changeset
|
667 |
PerRegionTable* prt = find_region_table(hr_ind & _mod_max_fine_entries_mask, |
1374 | 668 |
hr); |
669 |
if (prt != NULL) { |
|
670 |
return prt->contains_reference(from); |
|
671 |
||
672 |
} else { |
|
673 |
uintptr_t from_card = |
|
674 |
(uintptr_t(from) >> CardTableModRefBS::card_shift); |
|
675 |
uintptr_t hr_bot_card_index = |
|
676 |
uintptr_t(hr->bottom()) >> CardTableModRefBS::card_shift; |
|
677 |
assert(from_card >= hr_bot_card_index, "Inv"); |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
678 |
CardIdx_t card_index = from_card - hr_bot_card_index; |
10677
370a8da2d63f
7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
johnc
parents:
10243
diff
changeset
|
679 |
assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion, |
3697
ea9211aa02f5
6819085: G1: use larger and/or user settable region size
tonyp
parents:
3262
diff
changeset
|
680 |
"Must be in range."); |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2882
diff
changeset
|
681 |
return _sparse_table.contains_card(hr_ind, card_index); |
1374 | 682 |
} |
683 |
} |
|
684 |
||
8072 | 685 |
void |
686 |
OtherRegionsTable::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) { |
|
687 |
_sparse_table.do_cleanup_work(hrrs_cleanup_task); |
|
688 |
} |
|
689 |
||
35461 | 690 |
HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetTable* bot, |
1374 | 691 |
HeapRegion* hr) |
35461 | 692 |
: _bot(bot), |
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
26850
diff
changeset
|
693 |
_m(Mutex::leaf, FormatBuffer<128>("HeapRegionRemSet lock #%u", hr->hrm_index()), true, Monitor::_safepoint_check_never), |
26160 | 694 |
_code_roots(), _other_regions(hr, &_m), _iter_state(Unclaimed), _iter_claimed(0) { |
10000
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
695 |
reset_for_par_iteration(); |
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
696 |
} |
1374 | 697 |
|
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
698 |
void HeapRegionRemSet::setup_remset_size() { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
699 |
// Setup sparse and fine-grain tables sizes. |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
700 |
// table_size = base * (log(region_size / 1M) + 1) |
12779
06778de5193e
7171936: LOG_G incorrectly defined in globalDefinitions.hpp
brutisso
parents:
12381
diff
changeset
|
701 |
const int LOG_M = 20; |
06778de5193e
7171936: LOG_G incorrectly defined in globalDefinitions.hpp
brutisso
parents:
12381
diff
changeset
|
702 |
int region_size_log_mb = MAX2(HeapRegion::LogOfHRGrainBytes - LOG_M, 0); |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
703 |
if (FLAG_IS_DEFAULT(G1RSetSparseRegionEntries)) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
704 |
G1RSetSparseRegionEntries = G1RSetSparseRegionEntriesBase * (region_size_log_mb + 1); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
705 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
706 |
if (FLAG_IS_DEFAULT(G1RSetRegionEntries)) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
707 |
G1RSetRegionEntries = G1RSetRegionEntriesBase * (region_size_log_mb + 1); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
708 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
709 |
guarantee(G1RSetSparseRegionEntries > 0 && G1RSetRegionEntries > 0 , "Sanity"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
710 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
711 |
|
1374 | 712 |
bool HeapRegionRemSet::claim_iter() { |
713 |
if (_iter_state != Unclaimed) return false; |
|
714 |
jint res = Atomic::cmpxchg(Claimed, (jint*)(&_iter_state), Unclaimed); |
|
715 |
return (res == Unclaimed); |
|
716 |
} |
|
717 |
||
718 |
void HeapRegionRemSet::set_iter_complete() { |
|
719 |
_iter_state = Complete; |
|
720 |
} |
|
721 |
||
722 |
bool HeapRegionRemSet::iter_is_complete() { |
|
723 |
return _iter_state == Complete; |
|
724 |
} |
|
725 |
||
726 |
#ifndef PRODUCT |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
727 |
void HeapRegionRemSet::print() { |
17108
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
728 |
HeapRegionRemSetIterator iter(this); |
1374 | 729 |
size_t card_index; |
730 |
while (iter.has_next(card_index)) { |
|
35461 | 731 |
HeapWord* card_start = _bot->address_for_index(card_index); |
35061 | 732 |
tty->print_cr(" Card " PTR_FORMAT, p2i(card_start)); |
1374 | 733 |
} |
734 |
if (iter.n_yielded() != occupied()) { |
|
35061 | 735 |
tty->print_cr("Yielded disagrees with occupied:"); |
736 |
tty->print_cr(" " SIZE_FORMAT_W(6) " yielded (" SIZE_FORMAT_W(6) |
|
24092
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
23858
diff
changeset
|
737 |
" coarse, " SIZE_FORMAT_W(6) " fine).", |
1374 | 738 |
iter.n_yielded(), |
739 |
iter.n_yielded_coarse(), iter.n_yielded_fine()); |
|
35061 | 740 |
tty->print_cr(" " SIZE_FORMAT_W(6) " occ (" SIZE_FORMAT_W(6) |
24092
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
23858
diff
changeset
|
741 |
" coarse, " SIZE_FORMAT_W(6) " fine).", |
1374 | 742 |
occupied(), occ_coarse(), occ_fine()); |
743 |
} |
|
744 |
guarantee(iter.n_yielded() == occupied(), |
|
745 |
"We should have yielded all the represented cards."); |
|
746 |
} |
|
747 |
#endif |
|
748 |
||
749 |
void HeapRegionRemSet::cleanup() { |
|
750 |
SparsePRT::cleanup_all(); |
|
751 |
} |
|
752 |
||
753 |
void HeapRegionRemSet::clear() { |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
754 |
MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag); |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
755 |
clear_locked(); |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
756 |
} |
19339 | 757 |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
758 |
void HeapRegionRemSet::clear_locked() { |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
759 |
_code_roots.clear(); |
1374 | 760 |
_other_regions.clear(); |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
761 |
assert(occupied_locked() == 0, "Should be clear."); |
10000
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
762 |
reset_for_par_iteration(); |
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
763 |
} |
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
764 |
|
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
765 |
void HeapRegionRemSet::reset_for_par_iteration() { |
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
766 |
_iter_state = Unclaimed; |
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
767 |
_iter_claimed = 0; |
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
768 |
// It's good to check this to make sure that the two methods are in sync. |
5bbb58b0dbb9
7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents:
9989
diff
changeset
|
769 |
assert(verify_ready_for_par_iteration(), "post-condition"); |
1374 | 770 |
} |
771 |
||
772 |
void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs, |
|
773 |
BitMap* region_bm, BitMap* card_bm) { |
|
774 |
_other_regions.scrub(ctbs, region_bm, card_bm); |
|
775 |
} |
|
776 |
||
19339 | 777 |
// Code roots support |
26422 | 778 |
// |
779 |
// The code root set is protected by two separate locking schemes |
|
780 |
// When at safepoint the per-hrrs lock must be held during modifications |
|
781 |
// except when doing a full gc. |
|
782 |
// When not at safepoint the CodeCache_lock must be held during modifications. |
|
783 |
// When concurrent readers access the contains() function |
|
784 |
// (during the evacuation phase) no removals are allowed. |
|
19339 | 785 |
|
786 |
void HeapRegionRemSet::add_strong_code_root(nmethod* nm) { |
|
787 |
assert(nm != NULL, "sanity"); |
|
35879 | 788 |
assert((!CodeCache_lock->owned_by_self() || SafepointSynchronize::is_at_safepoint()), |
789 |
"should call add_strong_code_root_locked instead. CodeCache_lock->owned_by_self(): %s, is_at_safepoint(): %s", |
|
790 |
BOOL_TO_STR(CodeCache_lock->owned_by_self()), BOOL_TO_STR(SafepointSynchronize::is_at_safepoint())); |
|
26422 | 791 |
// Optimistic unlocked contains-check |
792 |
if (!_code_roots.contains(nm)) { |
|
793 |
MutexLockerEx ml(&_m, Mutex::_no_safepoint_check_flag); |
|
794 |
add_strong_code_root_locked(nm); |
|
795 |
} |
|
796 |
} |
|
797 |
||
798 |
void HeapRegionRemSet::add_strong_code_root_locked(nmethod* nm) { |
|
799 |
assert(nm != NULL, "sanity"); |
|
35879 | 800 |
assert((CodeCache_lock->owned_by_self() || |
801 |
(SafepointSynchronize::is_at_safepoint() && |
|
802 |
(_m.owned_by_self() || Thread::current()->is_VM_thread()))), |
|
803 |
"not safely locked. CodeCache_lock->owned_by_self(): %s, is_at_safepoint(): %s, _m.owned_by_self(): %s, Thread::current()->is_VM_thread(): %s", |
|
804 |
BOOL_TO_STR(CodeCache_lock->owned_by_self()), BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()), |
|
805 |
BOOL_TO_STR(_m.owned_by_self()), BOOL_TO_STR(Thread::current()->is_VM_thread())); |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
806 |
_code_roots.add(nm); |
19339 | 807 |
} |
808 |
||
809 |
void HeapRegionRemSet::remove_strong_code_root(nmethod* nm) { |
|
810 |
assert(nm != NULL, "sanity"); |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
811 |
assert_locked_or_safepoint(CodeCache_lock); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
812 |
|
26422 | 813 |
MutexLockerEx ml(CodeCache_lock->owned_by_self() ? NULL : &_m, Mutex::_no_safepoint_check_flag); |
814 |
_code_roots.remove(nm); |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
815 |
|
19339 | 816 |
// Check that there were no duplicates |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
817 |
guarantee(!_code_roots.contains(nm), "duplicate entry found"); |
19339 | 818 |
} |
819 |
||
26422 | 820 |
void HeapRegionRemSet::strong_code_roots_do(CodeBlobClosure* blk) const { |
821 |
_code_roots.nmethods_do(blk); |
|
19339 | 822 |
} |
823 |
||
26422 | 824 |
void HeapRegionRemSet::clean_strong_code_roots(HeapRegion* hr) { |
825 |
_code_roots.clean(hr); |
|
19339 | 826 |
} |
827 |
||
828 |
size_t HeapRegionRemSet::strong_code_roots_mem_size() { |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
829 |
return _code_roots.mem_size(); |
19339 | 830 |
} |
831 |
||
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
21563
diff
changeset
|
832 |
HeapRegionRemSetIterator:: HeapRegionRemSetIterator(HeapRegionRemSet* hrrs) : |
17108
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
833 |
_hrrs(hrrs), |
1374 | 834 |
_g1h(G1CollectedHeap::heap()), |
17108
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
835 |
_coarse_map(&hrrs->_other_regions._coarse_map), |
35461 | 836 |
_bot(hrrs->_bot), |
17108
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
837 |
_is(Sparse), |
1374 | 838 |
// Set these values so that we increment to the first region. |
17108
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
839 |
_coarse_cur_region_index(-1), |
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
840 |
_coarse_cur_region_cur_card(HeapRegion::CardsPerRegion-1), |
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
841 |
_cur_card_in_prt(HeapRegion::CardsPerRegion), |
17108
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
842 |
_fine_cur_prt(NULL), |
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
843 |
_n_yielded_coarse(0), |
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
844 |
_n_yielded_fine(0), |
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
845 |
_n_yielded_sparse(0), |
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
846 |
_sparse_iter(&hrrs->_other_regions._sparse_table) {} |
1374 | 847 |
|
848 |
bool HeapRegionRemSetIterator::coarse_has_next(size_t& card_index) { |
|
849 |
if (_hrrs->_other_regions._n_coarse_entries == 0) return false; |
|
850 |
// Go to the next card. |
|
851 |
_coarse_cur_region_cur_card++; |
|
852 |
// Was the last the last card in the current region? |
|
3697
ea9211aa02f5
6819085: G1: use larger and/or user settable region size
tonyp
parents:
3262
diff
changeset
|
853 |
if (_coarse_cur_region_cur_card == HeapRegion::CardsPerRegion) { |
1374 | 854 |
// Yes: find the next region. This may leave _coarse_cur_region_index |
855 |
// Set to the last index, in which case there are no more coarse |
|
856 |
// regions. |
|
857 |
_coarse_cur_region_index = |
|
858 |
(int) _coarse_map->get_next_one_offset(_coarse_cur_region_index + 1); |
|
859 |
if ((size_t)_coarse_cur_region_index < _coarse_map->size()) { |
|
860 |
_coarse_cur_region_cur_card = 0; |
|
861 |
HeapWord* r_bot = |
|
12381
1438e0fbfa27
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
10767
diff
changeset
|
862 |
_g1h->region_at((uint) _coarse_cur_region_index)->bottom(); |
35461 | 863 |
_cur_region_card_offset = _bot->index_for(r_bot); |
1374 | 864 |
} else { |
865 |
return false; |
|
866 |
} |
|
867 |
} |
|
868 |
// If we didn't return false above, then we can yield a card. |
|
869 |
card_index = _cur_region_card_offset + _coarse_cur_region_cur_card; |
|
870 |
return true; |
|
871 |
} |
|
872 |
||
873 |
bool HeapRegionRemSetIterator::fine_has_next(size_t& card_index) { |
|
874 |
if (fine_has_next()) { |
|
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
875 |
_cur_card_in_prt = |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
876 |
_fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1); |
1374 | 877 |
} |
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
878 |
if (_cur_card_in_prt == HeapRegion::CardsPerRegion) { |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
879 |
// _fine_cur_prt may still be NULL in case if there are not PRTs at all for |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
880 |
// the remembered set. |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
881 |
if (_fine_cur_prt == NULL || _fine_cur_prt->next() == NULL) { |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
882 |
return false; |
1374 | 883 |
} |
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
884 |
PerRegionTable* next_prt = _fine_cur_prt->next(); |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
885 |
switch_to_prt(next_prt); |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
886 |
_cur_card_in_prt = _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1); |
1374 | 887 |
} |
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
888 |
|
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
889 |
card_index = _cur_region_card_offset + _cur_card_in_prt; |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
890 |
guarantee(_cur_card_in_prt < HeapRegion::CardsPerRegion, |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31592
diff
changeset
|
891 |
"Card index " SIZE_FORMAT " must be within the region", _cur_card_in_prt); |
1374 | 892 |
return true; |
893 |
} |
|
894 |
||
895 |
bool HeapRegionRemSetIterator::fine_has_next() { |
|
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
896 |
return _cur_card_in_prt != HeapRegion::CardsPerRegion; |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
897 |
} |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
898 |
|
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
899 |
void HeapRegionRemSetIterator::switch_to_prt(PerRegionTable* prt) { |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
900 |
assert(prt != NULL, "Cannot switch to NULL prt"); |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
901 |
_fine_cur_prt = prt; |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
902 |
|
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
903 |
HeapWord* r_bot = _fine_cur_prt->hr()->bottom(); |
35461 | 904 |
_cur_region_card_offset = _bot->index_for(r_bot); |
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
905 |
|
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
906 |
// The bitmap scan for the PRT always scans from _cur_region_cur_card + 1. |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
907 |
// To avoid special-casing this start case, and not miss the first bitmap |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
908 |
// entry, initialize _cur_region_cur_card with -1 instead of 0. |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
909 |
_cur_card_in_prt = (size_t)-1; |
1374 | 910 |
} |
911 |
||
912 |
bool HeapRegionRemSetIterator::has_next(size_t& card_index) { |
|
913 |
switch (_is) { |
|
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
914 |
case Sparse: { |
1374 | 915 |
if (_sparse_iter.has_next(card_index)) { |
916 |
_n_yielded_sparse++; |
|
917 |
return true; |
|
918 |
} |
|
919 |
// Otherwise, deliberate fall-through |
|
920 |
_is = Fine; |
|
24101
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
921 |
PerRegionTable* initial_fine_prt = _hrrs->_other_regions._first_all_fine_prts; |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
922 |
if (initial_fine_prt != NULL) { |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
923 |
switch_to_prt(_hrrs->_other_regions._first_all_fine_prts); |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
924 |
} |
bd1a2ee20760
8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents:
24092
diff
changeset
|
925 |
} |
1374 | 926 |
case Fine: |
927 |
if (fine_has_next(card_index)) { |
|
928 |
_n_yielded_fine++; |
|
929 |
return true; |
|
930 |
} |
|
931 |
// Otherwise, deliberate fall-through |
|
932 |
_is = Coarse; |
|
933 |
case Coarse: |
|
934 |
if (coarse_has_next(card_index)) { |
|
935 |
_n_yielded_coarse++; |
|
936 |
return true; |
|
937 |
} |
|
938 |
// Otherwise... |
|
939 |
break; |
|
940 |
} |
|
941 |
assert(ParallelGCThreads > 1 || |
|
942 |
n_yielded() == _hrrs->occupied(), |
|
943 |
"Should have yielded all the cards in the rem set " |
|
944 |
"(in the non-par case)."); |
|
945 |
return false; |
|
946 |
} |
|
947 |
||
8072 | 948 |
void HeapRegionRemSet::reset_for_cleanup_tasks() { |
949 |
SparsePRT::reset_for_cleanup_tasks(); |
|
950 |
} |
|
951 |
||
952 |
void HeapRegionRemSet::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) { |
|
953 |
_other_regions.do_cleanup_work(hrrs_cleanup_task); |
|
954 |
} |
|
955 |
||
956 |
void |
|
957 |
HeapRegionRemSet::finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task) { |
|
958 |
SparsePRT::finish_cleanup_task(hrrs_cleanup_task); |
|
959 |
} |
|
960 |
||
1374 | 961 |
#ifndef PRODUCT |
962 |
void HeapRegionRemSet::test() { |
|
963 |
os::sleep(Thread::current(), (jlong)5000, false); |
|
964 |
G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
|
965 |
||
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4900
diff
changeset
|
966 |
// Run with "-XX:G1LogRSetRegionEntries=2", so that 1 and 5 end up in same |
1374 | 967 |
// hash bucket. |
968 |
HeapRegion* hr0 = g1h->region_at(0); |
|
969 |
HeapRegion* hr1 = g1h->region_at(1); |
|
970 |
HeapRegion* hr2 = g1h->region_at(5); |
|
971 |
HeapRegion* hr3 = g1h->region_at(6); |
|
972 |
HeapRegion* hr4 = g1h->region_at(7); |
|
973 |
HeapRegion* hr5 = g1h->region_at(8); |
|
974 |
||
975 |
HeapWord* hr1_start = hr1->bottom(); |
|
976 |
HeapWord* hr1_mid = hr1_start + HeapRegion::GrainWords/2; |
|
977 |
HeapWord* hr1_last = hr1->end() - 1; |
|
978 |
||
979 |
HeapWord* hr2_start = hr2->bottom(); |
|
980 |
HeapWord* hr2_mid = hr2_start + HeapRegion::GrainWords/2; |
|
981 |
HeapWord* hr2_last = hr2->end() - 1; |
|
982 |
||
983 |
HeapWord* hr3_start = hr3->bottom(); |
|
984 |
HeapWord* hr3_mid = hr3_start + HeapRegion::GrainWords/2; |
|
985 |
HeapWord* hr3_last = hr3->end() - 1; |
|
986 |
||
987 |
HeapRegionRemSet* hrrs = hr0->rem_set(); |
|
988 |
||
989 |
// Make three references from region 0x101... |
|
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
990 |
hrrs->add_reference((OopOrNarrowOopStar)hr1_start); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
991 |
hrrs->add_reference((OopOrNarrowOopStar)hr1_mid); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
992 |
hrrs->add_reference((OopOrNarrowOopStar)hr1_last); |
1374 | 993 |
|
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
994 |
hrrs->add_reference((OopOrNarrowOopStar)hr2_start); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
995 |
hrrs->add_reference((OopOrNarrowOopStar)hr2_mid); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
996 |
hrrs->add_reference((OopOrNarrowOopStar)hr2_last); |
1374 | 997 |
|
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
998 |
hrrs->add_reference((OopOrNarrowOopStar)hr3_start); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
999 |
hrrs->add_reference((OopOrNarrowOopStar)hr3_mid); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
1000 |
hrrs->add_reference((OopOrNarrowOopStar)hr3_last); |
1374 | 1001 |
|
1002 |
// Now cause a coarsening. |
|
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
1003 |
hrrs->add_reference((OopOrNarrowOopStar)hr4->bottom()); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2996
diff
changeset
|
1004 |
hrrs->add_reference((OopOrNarrowOopStar)hr5->bottom()); |
1374 | 1005 |
|
1006 |
// Now, does iteration yield these three? |
|
17108
cf72dcf9a8f2
8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents:
13752
diff
changeset
|
1007 |
HeapRegionRemSetIterator iter(hrrs); |
1374 | 1008 |
size_t sum = 0; |
1009 |
size_t card_index; |
|
1010 |
while (iter.has_next(card_index)) { |
|
1011 |
HeapWord* card_start = |
|
35461 | 1012 |
G1CollectedHeap::heap()->bot()->address_for_index(card_index); |
35061 | 1013 |
tty->print_cr(" Card " PTR_FORMAT ".", p2i(card_start)); |
1374 | 1014 |
sum++; |
1015 |
} |
|
1016 |
guarantee(sum == 11 - 3 + 2048, "Failure"); |
|
1017 |
guarantee(sum == hrrs->occupied(), "Failure"); |
|
1018 |
} |
|
1019 |
#endif |