author | pliden |
Tue, 03 Jun 2014 10:37:46 +0200 | |
changeset 24844 | d1345c68cea9 |
parent 24464 | 901aa0dcba08 |
child 25351 | 7c198a690050 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
24464
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
2 |
* Copyright (c) 2001, 2014, 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:
4902
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4902
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:
4902
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "gc_implementation/g1/heapRegion.hpp" |
|
27 |
#include "gc_implementation/g1/heapRegionRemSet.hpp" |
|
28 |
#include "gc_implementation/g1/sparsePRT.hpp" |
|
29 |
#include "memory/allocation.inline.hpp" |
|
30 |
#include "memory/cardTableModRefBS.hpp" |
|
31 |
#include "memory/space.inline.hpp" |
|
32 |
#include "runtime/mutexLocker.hpp" |
|
1374 | 33 |
|
34 |
#define SPARSE_PRT_VERBOSE 0 |
|
35 |
||
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
36 |
#define UNROLL_CARD_LOOPS 1 |
1374 | 37 |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
38 |
void SparsePRTEntry::init(RegionIdx_t region_ind) { |
1374 | 39 |
_region_ind = region_ind; |
40 |
_next_index = NullEntry; |
|
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
41 |
|
1374 | 42 |
#if UNROLL_CARD_LOOPS |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
43 |
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
44 |
for (int i = 0; i < cards_num(); i += UnrollFactor) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
45 |
_cards[i] = NullEntry; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
46 |
_cards[i + 1] = NullEntry; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
47 |
_cards[i + 2] = NullEntry; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
48 |
_cards[i + 3] = NullEntry; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
49 |
} |
1374 | 50 |
#else |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
51 |
for (int i = 0; i < cards_num(); i++) |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
52 |
_cards[i] = NullEntry; |
1374 | 53 |
#endif |
54 |
} |
|
55 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
56 |
bool SparsePRTEntry::contains_card(CardIdx_t card_index) const { |
1374 | 57 |
#if UNROLL_CARD_LOOPS |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
58 |
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
59 |
for (int i = 0; i < cards_num(); i += UnrollFactor) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
60 |
if (_cards[i] == card_index || |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
61 |
_cards[i + 1] == card_index || |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
62 |
_cards[i + 2] == card_index || |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
63 |
_cards[i + 3] == card_index) return true; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
64 |
} |
1374 | 65 |
#else |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
66 |
for (int i = 0; i < cards_num(); i++) { |
1374 | 67 |
if (_cards[i] == card_index) return true; |
68 |
} |
|
69 |
#endif |
|
70 |
// Otherwise, we're full. |
|
71 |
return false; |
|
72 |
} |
|
73 |
||
74 |
int SparsePRTEntry::num_valid_cards() const { |
|
75 |
int sum = 0; |
|
76 |
#if UNROLL_CARD_LOOPS |
|
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
77 |
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
78 |
for (int i = 0; i < cards_num(); i += UnrollFactor) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
79 |
sum += (_cards[i] != NullEntry); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
80 |
sum += (_cards[i + 1] != NullEntry); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
81 |
sum += (_cards[i + 2] != NullEntry); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
82 |
sum += (_cards[i + 3] != NullEntry); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
83 |
} |
1374 | 84 |
#else |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
85 |
for (int i = 0; i < cards_num(); i++) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
86 |
sum += (_cards[i] != NullEntry); |
1374 | 87 |
} |
88 |
#endif |
|
89 |
// Otherwise, we're full. |
|
90 |
return sum; |
|
91 |
} |
|
92 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
93 |
SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) { |
1374 | 94 |
#if UNROLL_CARD_LOOPS |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
95 |
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
96 |
CardIdx_t c; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
97 |
for (int i = 0; i < cards_num(); i += UnrollFactor) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
98 |
c = _cards[i]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
99 |
if (c == card_index) return found; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
100 |
if (c == NullEntry) { _cards[i] = card_index; return added; } |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
101 |
c = _cards[i + 1]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
102 |
if (c == card_index) return found; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
103 |
if (c == NullEntry) { _cards[i + 1] = card_index; return added; } |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
104 |
c = _cards[i + 2]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
105 |
if (c == card_index) return found; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
106 |
if (c == NullEntry) { _cards[i + 2] = card_index; return added; } |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
107 |
c = _cards[i + 3]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
108 |
if (c == card_index) return found; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
109 |
if (c == NullEntry) { _cards[i + 3] = card_index; return added; } |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
110 |
} |
1374 | 111 |
#else |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
112 |
for (int i = 0; i < cards_num(); i++) { |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
113 |
CardIdx_t c = _cards[i]; |
1374 | 114 |
if (c == card_index) return found; |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
115 |
if (c == NullEntry) { _cards[i] = card_index; return added; } |
1374 | 116 |
} |
117 |
#endif |
|
118 |
// Otherwise, we're full. |
|
119 |
return overflow; |
|
120 |
} |
|
121 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
122 |
void SparsePRTEntry::copy_cards(CardIdx_t* cards) const { |
1374 | 123 |
#if UNROLL_CARD_LOOPS |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
124 |
assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
125 |
for (int i = 0; i < cards_num(); i += UnrollFactor) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
126 |
cards[i] = _cards[i]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
127 |
cards[i + 1] = _cards[i + 1]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
128 |
cards[i + 2] = _cards[i + 2]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
129 |
cards[i + 3] = _cards[i + 3]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
130 |
} |
1374 | 131 |
#else |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
132 |
for (int i = 0; i < cards_num(); i++) { |
1374 | 133 |
cards[i] = _cards[i]; |
134 |
} |
|
135 |
#endif |
|
136 |
} |
|
137 |
||
138 |
void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const { |
|
139 |
copy_cards(&e->_cards[0]); |
|
140 |
} |
|
141 |
||
142 |
// ---------------------------------------------------------------------- |
|
143 |
||
144 |
RSHashTable::RSHashTable(size_t capacity) : |
|
145 |
_capacity(capacity), _capacity_mask(capacity-1), |
|
146 |
_occupied_entries(0), _occupied_cards(0), |
|
13195 | 147 |
_entries((SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, SparsePRTEntry::size() * capacity, mtGC)), |
148 |
_buckets(NEW_C_HEAP_ARRAY(int, capacity, mtGC)), |
|
1374 | 149 |
_free_list(NullEntry), _free_region(0) |
150 |
{ |
|
151 |
clear(); |
|
152 |
} |
|
153 |
||
154 |
RSHashTable::~RSHashTable() { |
|
155 |
if (_entries != NULL) { |
|
13195 | 156 |
FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries, mtGC); |
1374 | 157 |
_entries = NULL; |
158 |
} |
|
159 |
if (_buckets != NULL) { |
|
13195 | 160 |
FREE_C_HEAP_ARRAY(int, _buckets, mtGC); |
1374 | 161 |
_buckets = NULL; |
162 |
} |
|
163 |
} |
|
164 |
||
165 |
void RSHashTable::clear() { |
|
166 |
_occupied_entries = 0; |
|
167 |
_occupied_cards = 0; |
|
168 |
guarantee(_entries != NULL, "INV"); |
|
169 |
guarantee(_buckets != NULL, "INV"); |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
170 |
|
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
171 |
guarantee(_capacity <= ((size_t)1 << (sizeof(int)*BitsPerByte-1)) - 1, |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
172 |
"_capacity too large"); |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
173 |
|
1374 | 174 |
// This will put -1 == NullEntry in the key field of all entries. |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
175 |
memset(_entries, NullEntry, _capacity * SparsePRTEntry::size()); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
176 |
memset(_buckets, NullEntry, _capacity * sizeof(int)); |
1374 | 177 |
_free_list = NullEntry; |
178 |
_free_region = 0; |
|
179 |
} |
|
180 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
181 |
bool RSHashTable::add_card(RegionIdx_t region_ind, CardIdx_t card_index) { |
1374 | 182 |
SparsePRTEntry* e = entry_for_region_ind_create(region_ind); |
183 |
assert(e != NULL && e->r_ind() == region_ind, |
|
184 |
"Postcondition of call above."); |
|
185 |
SparsePRTEntry::AddCardResult res = e->add_card(card_index); |
|
186 |
if (res == SparsePRTEntry::added) _occupied_cards++; |
|
187 |
#if SPARSE_PRT_VERBOSE |
|
188 |
gclog_or_tty->print_cr(" after add_card[%d]: valid-cards = %d.", |
|
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
189 |
pointer_delta(e, _entries, SparsePRTEntry::size()), |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
190 |
e->num_valid_cards()); |
1374 | 191 |
#endif |
192 |
assert(e->num_valid_cards() > 0, "Postcondition"); |
|
193 |
return res != SparsePRTEntry::overflow; |
|
194 |
} |
|
195 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
196 |
bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) { |
24464
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
197 |
SparsePRTEntry* entry = get_entry(region_ind); |
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
198 |
if (entry == NULL) { |
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
199 |
return false; |
1374 | 200 |
} |
201 |
// Otherwise... |
|
24464
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
202 |
entry->copy_cards(cards); |
1374 | 203 |
return true; |
204 |
} |
|
205 |
||
24464
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
206 |
SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) const { |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
207 |
int ind = (int) (region_ind & capacity_mask()); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
208 |
int cur_ind = _buckets[ind]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
209 |
SparsePRTEntry* cur; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
210 |
while (cur_ind != NullEntry && |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
211 |
(cur = entry(cur_ind))->r_ind() != region_ind) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
212 |
cur_ind = cur->next_index(); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
213 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
214 |
|
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
215 |
if (cur_ind == NullEntry) return NULL; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
216 |
// Otherwise... |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
217 |
assert(cur->r_ind() == region_ind, "Postcondition of loop + test above."); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
218 |
assert(cur->num_valid_cards() > 0, "Inv"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
219 |
return cur; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
220 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
221 |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
222 |
bool RSHashTable::delete_entry(RegionIdx_t region_ind) { |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
223 |
int ind = (int) (region_ind & capacity_mask()); |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
224 |
int* prev_loc = &_buckets[ind]; |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
225 |
int cur_ind = *prev_loc; |
1374 | 226 |
SparsePRTEntry* cur; |
227 |
while (cur_ind != NullEntry && |
|
228 |
(cur = entry(cur_ind))->r_ind() != region_ind) { |
|
229 |
prev_loc = cur->next_index_addr(); |
|
230 |
cur_ind = *prev_loc; |
|
231 |
} |
|
232 |
||
233 |
if (cur_ind == NullEntry) return false; |
|
234 |
// Otherwise, splice out "cur". |
|
235 |
*prev_loc = cur->next_index(); |
|
236 |
_occupied_cards -= cur->num_valid_cards(); |
|
237 |
free_entry(cur_ind); |
|
238 |
_occupied_entries--; |
|
239 |
return true; |
|
240 |
} |
|
241 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
242 |
SparsePRTEntry* |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
243 |
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) { |
24464
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
244 |
SparsePRTEntry* res = get_entry(region_ind); |
1374 | 245 |
if (res == NULL) { |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
246 |
int new_ind = alloc_entry(); |
1374 | 247 |
assert(0 <= new_ind && (size_t)new_ind < capacity(), "There should be room."); |
248 |
res = entry(new_ind); |
|
249 |
res->init(region_ind); |
|
250 |
// Insert at front. |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
251 |
int ind = (int) (region_ind & capacity_mask()); |
1374 | 252 |
res->set_next_index(_buckets[ind]); |
253 |
_buckets[ind] = new_ind; |
|
254 |
_occupied_entries++; |
|
255 |
} |
|
256 |
return res; |
|
257 |
} |
|
258 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
259 |
int RSHashTable::alloc_entry() { |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
260 |
int res; |
1374 | 261 |
if (_free_list != NullEntry) { |
262 |
res = _free_list; |
|
263 |
_free_list = entry(res)->next_index(); |
|
264 |
return res; |
|
265 |
} else if ((size_t) _free_region+1 < capacity()) { |
|
266 |
res = _free_region; |
|
267 |
_free_region++; |
|
268 |
return res; |
|
269 |
} else { |
|
270 |
return NullEntry; |
|
271 |
} |
|
272 |
} |
|
273 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
274 |
void RSHashTable::free_entry(int fi) { |
1374 | 275 |
entry(fi)->set_next_index(_free_list); |
276 |
_free_list = fi; |
|
277 |
} |
|
278 |
||
279 |
void RSHashTable::add_entry(SparsePRTEntry* e) { |
|
280 |
assert(e->num_valid_cards() > 0, "Precondition."); |
|
281 |
SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind()); |
|
282 |
e->copy_cards(e2); |
|
283 |
_occupied_cards += e2->num_valid_cards(); |
|
284 |
assert(e2->num_valid_cards() > 0, "Postcondition."); |
|
285 |
} |
|
286 |
||
6983
a8c50cedbce9
6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents:
6981
diff
changeset
|
287 |
CardIdx_t RSHashTableIter::find_first_card_in_list() { |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
288 |
CardIdx_t res; |
1374 | 289 |
while (_bl_ind != RSHashTable::NullEntry) { |
290 |
res = _rsht->entry(_bl_ind)->card(0); |
|
291 |
if (res != SparsePRTEntry::NullEntry) { |
|
292 |
return res; |
|
293 |
} else { |
|
294 |
_bl_ind = _rsht->entry(_bl_ind)->next_index(); |
|
295 |
} |
|
296 |
} |
|
297 |
// Otherwise, none found: |
|
298 |
return SparsePRTEntry::NullEntry; |
|
299 |
} |
|
300 |
||
6983
a8c50cedbce9
6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents:
6981
diff
changeset
|
301 |
size_t RSHashTableIter::compute_card_ind(CardIdx_t ci) { |
6981
ecfe524b1fa7
6992189: G1: inconsistent base used in sparse rem set iterator
tonyp
parents:
6250
diff
changeset
|
302 |
return (_rsht->entry(_bl_ind)->r_ind() * HeapRegion::CardsPerRegion) + ci; |
1374 | 303 |
} |
304 |
||
6983
a8c50cedbce9
6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents:
6981
diff
changeset
|
305 |
bool RSHashTableIter::has_next(size_t& card_index) { |
1374 | 306 |
_card_ind++; |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
307 |
CardIdx_t ci; |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
308 |
if (_card_ind < SparsePRTEntry::cards_num() && |
1374 | 309 |
((ci = _rsht->entry(_bl_ind)->card(_card_ind)) != |
310 |
SparsePRTEntry::NullEntry)) { |
|
311 |
card_index = compute_card_ind(ci); |
|
312 |
return true; |
|
313 |
} |
|
314 |
// Otherwise, must find the next valid entry. |
|
315 |
_card_ind = 0; |
|
316 |
||
317 |
if (_bl_ind != RSHashTable::NullEntry) { |
|
318 |
_bl_ind = _rsht->entry(_bl_ind)->next_index(); |
|
319 |
ci = find_first_card_in_list(); |
|
320 |
if (ci != SparsePRTEntry::NullEntry) { |
|
321 |
card_index = compute_card_ind(ci); |
|
322 |
return true; |
|
323 |
} |
|
324 |
} |
|
325 |
// If we didn't return above, must go to the next non-null table index. |
|
326 |
_tbl_ind++; |
|
327 |
while ((size_t)_tbl_ind < _rsht->capacity()) { |
|
328 |
_bl_ind = _rsht->_buckets[_tbl_ind]; |
|
329 |
ci = find_first_card_in_list(); |
|
330 |
if (ci != SparsePRTEntry::NullEntry) { |
|
331 |
card_index = compute_card_ind(ci); |
|
332 |
return true; |
|
333 |
} |
|
334 |
// Otherwise, try next entry. |
|
335 |
_tbl_ind++; |
|
336 |
} |
|
337 |
// Otherwise, there were no entry. |
|
338 |
return false; |
|
339 |
} |
|
340 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
341 |
bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const { |
24464
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
342 |
SparsePRTEntry* e = get_entry(region_index); |
1374 | 343 |
return (e != NULL && e->contains_card(card_index)); |
344 |
} |
|
345 |
||
346 |
size_t RSHashTable::mem_size() const { |
|
24108
dfc2242fc6b0
8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents:
22234
diff
changeset
|
347 |
return sizeof(RSHashTable) + |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
348 |
capacity() * (SparsePRTEntry::size() + sizeof(int)); |
1374 | 349 |
} |
350 |
||
351 |
// ---------------------------------------------------------------------- |
|
352 |
||
353 |
SparsePRT* SparsePRT::_head_expanded_list = NULL; |
|
354 |
||
355 |
void SparsePRT::add_to_expanded_list(SparsePRT* sprt) { |
|
356 |
// We could expand multiple times in a pause -- only put on list once. |
|
357 |
if (sprt->expanded()) return; |
|
358 |
sprt->set_expanded(true); |
|
359 |
SparsePRT* hd = _head_expanded_list; |
|
360 |
while (true) { |
|
361 |
sprt->_next_expanded = hd; |
|
362 |
SparsePRT* res = |
|
363 |
(SparsePRT*) |
|
364 |
Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd); |
|
365 |
if (res == hd) return; |
|
366 |
else hd = res; |
|
367 |
} |
|
368 |
} |
|
369 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
370 |
|
1374 | 371 |
SparsePRT* SparsePRT::get_from_expanded_list() { |
372 |
SparsePRT* hd = _head_expanded_list; |
|
373 |
while (hd != NULL) { |
|
374 |
SparsePRT* next = hd->next_expanded(); |
|
375 |
SparsePRT* res = |
|
376 |
(SparsePRT*) |
|
377 |
Atomic::cmpxchg_ptr(next, &_head_expanded_list, hd); |
|
378 |
if (res == hd) { |
|
379 |
hd->set_next_expanded(NULL); |
|
380 |
return hd; |
|
381 |
} else { |
|
382 |
hd = res; |
|
383 |
} |
|
384 |
} |
|
385 |
return NULL; |
|
386 |
} |
|
387 |
||
8072 | 388 |
void SparsePRT::reset_for_cleanup_tasks() { |
389 |
_head_expanded_list = NULL; |
|
390 |
} |
|
391 |
||
392 |
void SparsePRT::do_cleanup_work(SparsePRTCleanupTask* sprt_cleanup_task) { |
|
393 |
if (should_be_on_expanded_list()) { |
|
394 |
sprt_cleanup_task->add(this); |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
void SparsePRT::finish_cleanup_task(SparsePRTCleanupTask* sprt_cleanup_task) { |
|
399 |
assert(ParGCRareEvent_lock->owned_by_self(), "pre-condition"); |
|
400 |
SparsePRT* head = sprt_cleanup_task->head(); |
|
401 |
SparsePRT* tail = sprt_cleanup_task->tail(); |
|
402 |
if (head != NULL) { |
|
403 |
assert(tail != NULL, "if head is not NULL, so should tail"); |
|
404 |
||
405 |
tail->set_next_expanded(_head_expanded_list); |
|
406 |
_head_expanded_list = head; |
|
407 |
} else { |
|
408 |
assert(tail == NULL, "if head is NULL, so should tail"); |
|
409 |
} |
|
410 |
} |
|
411 |
||
412 |
bool SparsePRT::should_be_on_expanded_list() { |
|
413 |
if (_expanded) { |
|
414 |
assert(_cur != _next, "if _expanded is true, cur should be != _next"); |
|
415 |
} else { |
|
416 |
assert(_cur == _next, "if _expanded is false, cur should be == _next"); |
|
417 |
} |
|
418 |
return expanded(); |
|
419 |
} |
|
1374 | 420 |
|
421 |
void SparsePRT::cleanup_all() { |
|
422 |
// First clean up all expanded tables so they agree on next and cur. |
|
423 |
SparsePRT* sprt = get_from_expanded_list(); |
|
424 |
while (sprt != NULL) { |
|
425 |
sprt->cleanup(); |
|
426 |
sprt = get_from_expanded_list(); |
|
427 |
} |
|
428 |
} |
|
429 |
||
430 |
||
431 |
SparsePRT::SparsePRT(HeapRegion* hr) : |
|
6250
5680f968c721
6930581: G1: assert(ParallelGCThreads > 1 || n_yielded() == _hrrs->occupied(),"Should have yielded all the ..
johnc
parents:
5547
diff
changeset
|
432 |
_hr(hr), _expanded(false), _next_expanded(NULL) |
1374 | 433 |
{ |
434 |
_cur = new RSHashTable(InitialCapacity); |
|
435 |
_next = _cur; |
|
436 |
} |
|
437 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
438 |
|
1374 | 439 |
SparsePRT::~SparsePRT() { |
440 |
assert(_next != NULL && _cur != NULL, "Inv"); |
|
441 |
if (_cur != _next) { delete _cur; } |
|
442 |
delete _next; |
|
443 |
} |
|
444 |
||
445 |
||
446 |
size_t SparsePRT::mem_size() const { |
|
447 |
// We ignore "_cur" here, because it either = _next, or else it is |
|
448 |
// on the deleted list. |
|
24108
dfc2242fc6b0
8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents:
22234
diff
changeset
|
449 |
return sizeof(SparsePRT) + _next->mem_size(); |
1374 | 450 |
} |
451 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
452 |
bool SparsePRT::add_card(RegionIdx_t region_id, CardIdx_t card_index) { |
1374 | 453 |
#if SPARSE_PRT_VERBOSE |
12381
1438e0fbfa27
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
9989
diff
changeset
|
454 |
gclog_or_tty->print_cr(" Adding card %d from region %d to region %u sparse.", |
9989 | 455 |
card_index, region_id, _hr->hrs_index()); |
1374 | 456 |
#endif |
457 |
if (_next->occupied_entries() * 2 > _next->capacity()) { |
|
458 |
expand(); |
|
459 |
} |
|
460 |
return _next->add_card(region_id, card_index); |
|
461 |
} |
|
462 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
463 |
bool SparsePRT::get_cards(RegionIdx_t region_id, CardIdx_t* cards) { |
1374 | 464 |
return _next->get_cards(region_id, cards); |
465 |
} |
|
466 |
||
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
467 |
SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
468 |
return _next->get_entry(region_id); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
469 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
470 |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
471 |
bool SparsePRT::delete_entry(RegionIdx_t region_id) { |
1374 | 472 |
return _next->delete_entry(region_id); |
473 |
} |
|
474 |
||
475 |
void SparsePRT::clear() { |
|
476 |
// If they differ, _next is bigger then cur, so next has no chance of |
|
477 |
// being the initial size. |
|
478 |
if (_next != _cur) { |
|
479 |
delete _next; |
|
480 |
} |
|
481 |
||
482 |
if (_cur->capacity() != InitialCapacity) { |
|
483 |
delete _cur; |
|
484 |
_cur = new RSHashTable(InitialCapacity); |
|
485 |
} else { |
|
486 |
_cur->clear(); |
|
487 |
} |
|
488 |
_next = _cur; |
|
8072 | 489 |
_expanded = false; |
1374 | 490 |
} |
491 |
||
492 |
void SparsePRT::cleanup() { |
|
4100 | 493 |
// Make sure that the current and next tables agree. |
494 |
if (_cur != _next) { |
|
495 |
delete _cur; |
|
496 |
} |
|
1374 | 497 |
_cur = _next; |
2143
61babb9fbd6f
6810698: G1: two small bugs in the sparse remembered sets
tonyp
parents:
1374
diff
changeset
|
498 |
set_expanded(false); |
1374 | 499 |
} |
500 |
||
501 |
void SparsePRT::expand() { |
|
502 |
RSHashTable* last = _next; |
|
503 |
_next = new RSHashTable(last->capacity() * 2); |
|
504 |
||
505 |
#if SPARSE_PRT_VERBOSE |
|
12381
1438e0fbfa27
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
9989
diff
changeset
|
506 |
gclog_or_tty->print_cr(" Expanded sparse table for %u to %d.", |
9989 | 507 |
_hr->hrs_index(), _next->capacity()); |
1374 | 508 |
#endif |
509 |
for (size_t i = 0; i < last->capacity(); i++) { |
|
510 |
SparsePRTEntry* e = last->entry((int)i); |
|
511 |
if (e->valid_entry()) { |
|
512 |
#if SPARSE_PRT_VERBOSE |
|
513 |
gclog_or_tty->print_cr(" During expansion, transferred entry for %d.", |
|
514 |
e->r_ind()); |
|
515 |
#endif |
|
516 |
_next->add_entry(e); |
|
517 |
} |
|
518 |
} |
|
4100 | 519 |
if (last != _cur) { |
520 |
delete last; |
|
521 |
} |
|
1374 | 522 |
add_to_expanded_list(this); |
523 |
} |
|
8072 | 524 |
|
525 |
void SparsePRTCleanupTask::add(SparsePRT* sprt) { |
|
526 |
assert(sprt->should_be_on_expanded_list(), "pre-condition"); |
|
527 |
||
528 |
sprt->set_next_expanded(NULL); |
|
529 |
if (_tail != NULL) { |
|
530 |
_tail->set_next_expanded(sprt); |
|
531 |
} else { |
|
532 |
_head = sprt; |
|
533 |
} |
|
534 |
_tail = sprt; |
|
535 |
} |