author | eosterlund |
Mon, 26 Feb 2018 09:34:12 +0100 | |
changeset 49164 | 7e958a8ebcd3 |
parent 47634 | 6a0c42c40cd1 |
child 49455 | 848864ed9b17 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
49164
7e958a8ebcd3
8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents:
47634
diff
changeset
|
2 |
* Copyright (c) 2001, 2018, 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" |
30764 | 26 |
#include "gc/g1/heapRegion.hpp" |
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
27 |
#include "gc/g1/heapRegionBounds.inline.hpp" |
30764 | 28 |
#include "gc/g1/heapRegionRemSet.hpp" |
29 |
#include "gc/g1/sparsePRT.hpp" |
|
30 |
#include "gc/shared/cardTableModRefBS.hpp" |
|
31 |
#include "gc/shared/space.inline.hpp" |
|
7397 | 32 |
#include "memory/allocation.inline.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
38271
diff
changeset
|
33 |
#include "runtime/atomic.hpp" |
7397 | 34 |
#include "runtime/mutexLocker.hpp" |
1374 | 35 |
|
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
36 |
// Check that the size of the SparsePRTEntry is evenly divisible by the maximum |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
37 |
// member type to avoid SIGBUS when accessing them. |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
38 |
STATIC_ASSERT(sizeof(SparsePRTEntry) % sizeof(int) == 0); |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
39 |
|
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
40 |
void SparsePRTEntry::init(RegionIdx_t region_ind) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
41 |
// Check that the card array element type can represent all cards in the region. |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
42 |
// Choose a large SparsePRTEntry::card_elem_t (e.g. CardIdx_t) if required. |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
43 |
assert(((size_t)1 << (sizeof(SparsePRTEntry::card_elem_t) * BitsPerByte)) * |
49164
7e958a8ebcd3
8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents:
47634
diff
changeset
|
44 |
G1CardTable::card_size >= HeapRegionBounds::max_size(), "precondition"); |
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
45 |
assert(G1RSetSparseRegionEntries > 0, "precondition"); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
46 |
_region_ind = region_ind; |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
47 |
_next_index = RSHashTable::NullEntry; |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
48 |
_next_null = 0; |
1374 | 49 |
} |
50 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
51 |
bool SparsePRTEntry::contains_card(CardIdx_t card_index) const { |
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
52 |
for (int i = 0; i < num_valid_cards(); i++) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
53 |
if (card(i) == card_index) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
54 |
return true; |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
55 |
} |
1374 | 56 |
} |
57 |
return false; |
|
58 |
} |
|
59 |
||
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
60 |
SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
61 |
for (int i = 0; i < num_valid_cards(); i++) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
62 |
if (card(i) == card_index) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
63 |
return found; |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
64 |
} |
1374 | 65 |
} |
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
66 |
if (num_valid_cards() < cards_num() - 1) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
67 |
_cards[_next_null] = (card_elem_t)card_index; |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
68 |
_next_null++; |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
69 |
return added; |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
70 |
} |
1374 | 71 |
// Otherwise, we're full. |
72 |
return overflow; |
|
73 |
} |
|
74 |
||
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
75 |
void SparsePRTEntry::copy_cards(card_elem_t* cards) const { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
76 |
memcpy(cards, _cards, cards_num() * sizeof(card_elem_t)); |
1374 | 77 |
} |
78 |
||
79 |
void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const { |
|
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
80 |
copy_cards(e->_cards); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
81 |
assert(_next_null >= 0, "invariant"); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
82 |
assert(_next_null <= cards_num(), "invariant"); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
83 |
e->_next_null = _next_null; |
1374 | 84 |
} |
85 |
||
86 |
// ---------------------------------------------------------------------- |
|
87 |
||
38269
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
88 |
float RSHashTable::TableOccupancyFactor = 0.5f; |
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
89 |
|
1374 | 90 |
RSHashTable::RSHashTable(size_t capacity) : |
91 |
_capacity(capacity), _capacity_mask(capacity-1), |
|
92 |
_occupied_entries(0), _occupied_cards(0), |
|
38269
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
93 |
_entries(NULL), |
13195 | 94 |
_buckets(NEW_C_HEAP_ARRAY(int, capacity, mtGC)), |
1374 | 95 |
_free_list(NullEntry), _free_region(0) |
96 |
{ |
|
38269
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
97 |
_num_entries = (capacity * TableOccupancyFactor) + 1; |
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
98 |
_entries = (SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, _num_entries * SparsePRTEntry::size(), mtGC); |
1374 | 99 |
clear(); |
100 |
} |
|
101 |
||
102 |
RSHashTable::~RSHashTable() { |
|
103 |
if (_entries != NULL) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
26316
diff
changeset
|
104 |
FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries); |
1374 | 105 |
_entries = NULL; |
106 |
} |
|
107 |
if (_buckets != NULL) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
26316
diff
changeset
|
108 |
FREE_C_HEAP_ARRAY(int, _buckets); |
1374 | 109 |
_buckets = NULL; |
110 |
} |
|
111 |
} |
|
112 |
||
113 |
void RSHashTable::clear() { |
|
114 |
_occupied_entries = 0; |
|
115 |
_occupied_cards = 0; |
|
116 |
guarantee(_entries != NULL, "INV"); |
|
117 |
guarantee(_buckets != NULL, "INV"); |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
118 |
|
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
119 |
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
|
120 |
"_capacity too large"); |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
121 |
|
1374 | 122 |
// This will put -1 == NullEntry in the key field of all entries. |
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
41283
diff
changeset
|
123 |
memset((void*)_entries, NullEntry, _num_entries * SparsePRTEntry::size()); |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
41283
diff
changeset
|
124 |
memset((void*)_buckets, NullEntry, _capacity * sizeof(int)); |
1374 | 125 |
_free_list = NullEntry; |
126 |
_free_region = 0; |
|
127 |
} |
|
128 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
129 |
bool RSHashTable::add_card(RegionIdx_t region_ind, CardIdx_t card_index) { |
1374 | 130 |
SparsePRTEntry* e = entry_for_region_ind_create(region_ind); |
131 |
assert(e != NULL && e->r_ind() == region_ind, |
|
132 |
"Postcondition of call above."); |
|
133 |
SparsePRTEntry::AddCardResult res = e->add_card(card_index); |
|
134 |
if (res == SparsePRTEntry::added) _occupied_cards++; |
|
135 |
assert(e->num_valid_cards() > 0, "Postcondition"); |
|
136 |
return res != SparsePRTEntry::overflow; |
|
137 |
} |
|
138 |
||
24464
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
139 |
SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) const { |
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
140 |
int ind = (int) (region_ind & capacity_mask()); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
141 |
int cur_ind = _buckets[ind]; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
142 |
SparsePRTEntry* cur; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
143 |
while (cur_ind != NullEntry && |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
144 |
(cur = entry(cur_ind))->r_ind() != region_ind) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
145 |
cur_ind = cur->next_index(); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
146 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
147 |
|
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
148 |
if (cur_ind == NullEntry) return NULL; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
149 |
// Otherwise... |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
150 |
assert(cur->r_ind() == region_ind, "Postcondition of loop + test above."); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
151 |
assert(cur->num_valid_cards() > 0, "Inv"); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
152 |
return cur; |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
153 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
154 |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
155 |
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
|
156 |
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
|
157 |
int* prev_loc = &_buckets[ind]; |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
158 |
int cur_ind = *prev_loc; |
1374 | 159 |
SparsePRTEntry* cur; |
160 |
while (cur_ind != NullEntry && |
|
161 |
(cur = entry(cur_ind))->r_ind() != region_ind) { |
|
162 |
prev_loc = cur->next_index_addr(); |
|
163 |
cur_ind = *prev_loc; |
|
164 |
} |
|
165 |
||
166 |
if (cur_ind == NullEntry) return false; |
|
167 |
// Otherwise, splice out "cur". |
|
168 |
*prev_loc = cur->next_index(); |
|
169 |
_occupied_cards -= cur->num_valid_cards(); |
|
170 |
free_entry(cur_ind); |
|
171 |
_occupied_entries--; |
|
172 |
return true; |
|
173 |
} |
|
174 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
175 |
SparsePRTEntry* |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
176 |
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) { |
24464
901aa0dcba08
8042474: Clean up duplicated code in RSHashTable
brutisso
parents:
24108
diff
changeset
|
177 |
SparsePRTEntry* res = get_entry(region_ind); |
1374 | 178 |
if (res == NULL) { |
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
179 |
int new_ind = alloc_entry(); |
1374 | 180 |
res = entry(new_ind); |
181 |
res->init(region_ind); |
|
182 |
// Insert at front. |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
183 |
int ind = (int) (region_ind & capacity_mask()); |
1374 | 184 |
res->set_next_index(_buckets[ind]); |
185 |
_buckets[ind] = new_ind; |
|
186 |
_occupied_entries++; |
|
187 |
} |
|
188 |
return res; |
|
189 |
} |
|
190 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
191 |
int RSHashTable::alloc_entry() { |
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
192 |
int res; |
1374 | 193 |
if (_free_list != NullEntry) { |
194 |
res = _free_list; |
|
195 |
_free_list = entry(res)->next_index(); |
|
196 |
return res; |
|
38269
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
197 |
} else if ((size_t)_free_region < _num_entries) { |
1374 | 198 |
res = _free_region; |
199 |
_free_region++; |
|
200 |
return res; |
|
201 |
} else { |
|
202 |
return NullEntry; |
|
203 |
} |
|
204 |
} |
|
205 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
206 |
void RSHashTable::free_entry(int fi) { |
1374 | 207 |
entry(fi)->set_next_index(_free_list); |
208 |
_free_list = fi; |
|
209 |
} |
|
210 |
||
211 |
void RSHashTable::add_entry(SparsePRTEntry* e) { |
|
212 |
assert(e->num_valid_cards() > 0, "Precondition."); |
|
213 |
SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind()); |
|
214 |
e->copy_cards(e2); |
|
215 |
_occupied_cards += e2->num_valid_cards(); |
|
216 |
assert(e2->num_valid_cards() > 0, "Postcondition."); |
|
217 |
} |
|
218 |
||
6983
a8c50cedbce9
6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents:
6981
diff
changeset
|
219 |
CardIdx_t RSHashTableIter::find_first_card_in_list() { |
1374 | 220 |
while (_bl_ind != RSHashTable::NullEntry) { |
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
221 |
SparsePRTEntry* sparse_entry = _rsht->entry(_bl_ind); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
222 |
if (sparse_entry->num_valid_cards() > 0) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
223 |
return sparse_entry->card(0); |
1374 | 224 |
} else { |
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
225 |
_bl_ind = sparse_entry->next_index(); |
1374 | 226 |
} |
227 |
} |
|
228 |
// Otherwise, none found: |
|
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
229 |
return NoCardFound; |
1374 | 230 |
} |
231 |
||
6983
a8c50cedbce9
6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents:
6981
diff
changeset
|
232 |
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
|
233 |
return (_rsht->entry(_bl_ind)->r_ind() * HeapRegion::CardsPerRegion) + ci; |
1374 | 234 |
} |
235 |
||
6983
a8c50cedbce9
6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents:
6981
diff
changeset
|
236 |
bool RSHashTableIter::has_next(size_t& card_index) { |
1374 | 237 |
_card_ind++; |
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
238 |
if (_bl_ind >= 0) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
239 |
SparsePRTEntry* e = _rsht->entry(_bl_ind); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
240 |
if (_card_ind < e->num_valid_cards()) { |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
241 |
CardIdx_t ci = e->card(_card_ind); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
242 |
card_index = compute_card_ind(ci); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
243 |
return true; |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
244 |
} |
1374 | 245 |
} |
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
246 |
|
1374 | 247 |
// Otherwise, must find the next valid entry. |
248 |
_card_ind = 0; |
|
249 |
||
250 |
if (_bl_ind != RSHashTable::NullEntry) { |
|
251 |
_bl_ind = _rsht->entry(_bl_ind)->next_index(); |
|
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
252 |
CardIdx_t ci = find_first_card_in_list(); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
253 |
if (ci != NoCardFound) { |
1374 | 254 |
card_index = compute_card_ind(ci); |
255 |
return true; |
|
256 |
} |
|
257 |
} |
|
258 |
// If we didn't return above, must go to the next non-null table index. |
|
259 |
_tbl_ind++; |
|
260 |
while ((size_t)_tbl_ind < _rsht->capacity()) { |
|
261 |
_bl_ind = _rsht->_buckets[_tbl_ind]; |
|
38271
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
262 |
CardIdx_t ci = find_first_card_in_list(); |
4425ba8ed50f
8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents:
38269
diff
changeset
|
263 |
if (ci != NoCardFound) { |
1374 | 264 |
card_index = compute_card_ind(ci); |
265 |
return true; |
|
266 |
} |
|
267 |
// Otherwise, try next entry. |
|
268 |
_tbl_ind++; |
|
269 |
} |
|
270 |
// Otherwise, there were no entry. |
|
271 |
return false; |
|
272 |
} |
|
273 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
274 |
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
|
275 |
SparsePRTEntry* e = get_entry(region_index); |
1374 | 276 |
return (e != NULL && e->contains_card(card_index)); |
277 |
} |
|
278 |
||
279 |
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
|
280 |
return sizeof(RSHashTable) + |
38269
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
281 |
_num_entries * (SparsePRTEntry::size() + sizeof(int)); |
1374 | 282 |
} |
283 |
||
284 |
// ---------------------------------------------------------------------- |
|
285 |
||
41283
2615c024f3eb
8033552: Fix missing missing volatile specifiers in CAS operations in GC code
eosterlund
parents:
40655
diff
changeset
|
286 |
SparsePRT* volatile SparsePRT::_head_expanded_list = NULL; |
1374 | 287 |
|
288 |
void SparsePRT::add_to_expanded_list(SparsePRT* sprt) { |
|
289 |
// We could expand multiple times in a pause -- only put on list once. |
|
290 |
if (sprt->expanded()) return; |
|
291 |
sprt->set_expanded(true); |
|
292 |
SparsePRT* hd = _head_expanded_list; |
|
293 |
while (true) { |
|
294 |
sprt->_next_expanded = hd; |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
295 |
SparsePRT* res = Atomic::cmpxchg(sprt, &_head_expanded_list, hd); |
1374 | 296 |
if (res == hd) return; |
297 |
else hd = res; |
|
298 |
} |
|
299 |
} |
|
300 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
301 |
|
1374 | 302 |
SparsePRT* SparsePRT::get_from_expanded_list() { |
303 |
SparsePRT* hd = _head_expanded_list; |
|
304 |
while (hd != NULL) { |
|
305 |
SparsePRT* next = hd->next_expanded(); |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
306 |
SparsePRT* res = Atomic::cmpxchg(next, &_head_expanded_list, hd); |
1374 | 307 |
if (res == hd) { |
308 |
hd->set_next_expanded(NULL); |
|
309 |
return hd; |
|
310 |
} else { |
|
311 |
hd = res; |
|
312 |
} |
|
313 |
} |
|
314 |
return NULL; |
|
315 |
} |
|
316 |
||
8072 | 317 |
void SparsePRT::reset_for_cleanup_tasks() { |
318 |
_head_expanded_list = NULL; |
|
319 |
} |
|
320 |
||
321 |
void SparsePRT::do_cleanup_work(SparsePRTCleanupTask* sprt_cleanup_task) { |
|
322 |
if (should_be_on_expanded_list()) { |
|
323 |
sprt_cleanup_task->add(this); |
|
324 |
} |
|
325 |
} |
|
326 |
||
327 |
void SparsePRT::finish_cleanup_task(SparsePRTCleanupTask* sprt_cleanup_task) { |
|
328 |
assert(ParGCRareEvent_lock->owned_by_self(), "pre-condition"); |
|
329 |
SparsePRT* head = sprt_cleanup_task->head(); |
|
330 |
SparsePRT* tail = sprt_cleanup_task->tail(); |
|
331 |
if (head != NULL) { |
|
332 |
assert(tail != NULL, "if head is not NULL, so should tail"); |
|
333 |
||
334 |
tail->set_next_expanded(_head_expanded_list); |
|
335 |
_head_expanded_list = head; |
|
336 |
} else { |
|
337 |
assert(tail == NULL, "if head is NULL, so should tail"); |
|
338 |
} |
|
339 |
} |
|
340 |
||
341 |
bool SparsePRT::should_be_on_expanded_list() { |
|
342 |
if (_expanded) { |
|
343 |
assert(_cur != _next, "if _expanded is true, cur should be != _next"); |
|
344 |
} else { |
|
345 |
assert(_cur == _next, "if _expanded is false, cur should be == _next"); |
|
346 |
} |
|
347 |
return expanded(); |
|
348 |
} |
|
1374 | 349 |
|
350 |
void SparsePRT::cleanup_all() { |
|
351 |
// First clean up all expanded tables so they agree on next and cur. |
|
352 |
SparsePRT* sprt = get_from_expanded_list(); |
|
353 |
while (sprt != NULL) { |
|
354 |
sprt->cleanup(); |
|
355 |
sprt = get_from_expanded_list(); |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
||
360 |
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
|
361 |
_hr(hr), _expanded(false), _next_expanded(NULL) |
1374 | 362 |
{ |
363 |
_cur = new RSHashTable(InitialCapacity); |
|
364 |
_next = _cur; |
|
365 |
} |
|
366 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
367 |
|
1374 | 368 |
SparsePRT::~SparsePRT() { |
369 |
assert(_next != NULL && _cur != NULL, "Inv"); |
|
370 |
if (_cur != _next) { delete _cur; } |
|
371 |
delete _next; |
|
372 |
} |
|
373 |
||
374 |
||
375 |
size_t SparsePRT::mem_size() const { |
|
376 |
// We ignore "_cur" here, because it either = _next, or else it is |
|
377 |
// on the deleted list. |
|
24108
dfc2242fc6b0
8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents:
22234
diff
changeset
|
378 |
return sizeof(SparsePRT) + _next->mem_size(); |
1374 | 379 |
} |
380 |
||
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
381 |
bool SparsePRT::add_card(RegionIdx_t region_id, CardIdx_t card_index) { |
38269
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
382 |
if (_next->should_expand()) { |
1374 | 383 |
expand(); |
384 |
} |
|
385 |
return _next->add_card(region_id, card_index); |
|
386 |
} |
|
387 |
||
4902
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
388 |
SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) { |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
389 |
return _next->get_entry(region_id); |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
390 |
} |
991aaddb5165
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
4100
diff
changeset
|
391 |
|
2996
1097030e5ec3
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
2143
diff
changeset
|
392 |
bool SparsePRT::delete_entry(RegionIdx_t region_id) { |
1374 | 393 |
return _next->delete_entry(region_id); |
394 |
} |
|
395 |
||
396 |
void SparsePRT::clear() { |
|
397 |
// If they differ, _next is bigger then cur, so next has no chance of |
|
398 |
// being the initial size. |
|
399 |
if (_next != _cur) { |
|
400 |
delete _next; |
|
401 |
} |
|
402 |
||
403 |
if (_cur->capacity() != InitialCapacity) { |
|
404 |
delete _cur; |
|
405 |
_cur = new RSHashTable(InitialCapacity); |
|
406 |
} else { |
|
407 |
_cur->clear(); |
|
408 |
} |
|
409 |
_next = _cur; |
|
8072 | 410 |
_expanded = false; |
1374 | 411 |
} |
412 |
||
413 |
void SparsePRT::cleanup() { |
|
4100 | 414 |
// Make sure that the current and next tables agree. |
415 |
if (_cur != _next) { |
|
416 |
delete _cur; |
|
417 |
} |
|
1374 | 418 |
_cur = _next; |
2143
61babb9fbd6f
6810698: G1: two small bugs in the sparse remembered sets
tonyp
parents:
1374
diff
changeset
|
419 |
set_expanded(false); |
1374 | 420 |
} |
421 |
||
422 |
void SparsePRT::expand() { |
|
423 |
RSHashTable* last = _next; |
|
424 |
_next = new RSHashTable(last->capacity() * 2); |
|
38269
d18cab031e64
8155721: Sparse remset wastes half of entry memory
tschatzl
parents:
33741
diff
changeset
|
425 |
for (size_t i = 0; i < last->num_entries(); i++) { |
1374 | 426 |
SparsePRTEntry* e = last->entry((int)i); |
427 |
if (e->valid_entry()) { |
|
428 |
_next->add_entry(e); |
|
429 |
} |
|
430 |
} |
|
4100 | 431 |
if (last != _cur) { |
432 |
delete last; |
|
433 |
} |
|
1374 | 434 |
add_to_expanded_list(this); |
435 |
} |
|
8072 | 436 |
|
437 |
void SparsePRTCleanupTask::add(SparsePRT* sprt) { |
|
438 |
assert(sprt->should_be_on_expanded_list(), "pre-condition"); |
|
439 |
||
440 |
sprt->set_next_expanded(NULL); |
|
441 |
if (_tail != NULL) { |
|
442 |
_tail->set_next_expanded(sprt); |
|
443 |
} else { |
|
444 |
_head = sprt; |
|
445 |
} |
|
446 |
_tail = sprt; |
|
447 |
} |