author | tschatzl |
Thu, 06 Aug 2015 15:49:50 +0200 | |
changeset 32185 | 49a57ff2c3cb |
parent 31592 | 43f48e165466 |
child 33093 | 5aa0f908f8cd |
permissions | -rw-r--r-- |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
1 |
/* |
30764 | 2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
4 |
* |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
8 |
* |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
13 |
* accompanied this code). |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
14 |
* |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
18 |
* |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
21 |
* questions. |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
22 |
* |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
23 |
*/ |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
24 |
|
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
26422 | 26 |
#include "code/codeCache.hpp" |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
27 |
#include "code/nmethod.hpp" |
30764 | 28 |
#include "gc/g1/g1CodeCacheRemSet.hpp" |
29 |
#include "gc/g1/heapRegion.hpp" |
|
26422 | 30 |
#include "memory/heap.hpp" |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
31 |
#include "memory/iterator.hpp" |
26422 | 32 |
#include "oops/oop.inline.hpp" |
33 |
#include "utilities/hashtable.inline.hpp" |
|
34 |
#include "utilities/stack.inline.hpp" |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
35 |
|
26422 | 36 |
class CodeRootSetTable : public Hashtable<nmethod*, mtGC> { |
37 |
friend class G1CodeRootSetTest; |
|
38 |
typedef HashtableEntry<nmethod*, mtGC> Entry; |
|
39 |
||
40 |
static CodeRootSetTable* volatile _purge_list; |
|
41 |
||
42 |
CodeRootSetTable* _purge_next; |
|
43 |
||
44 |
unsigned int compute_hash(nmethod* nm) { |
|
45 |
uintptr_t hash = (uintptr_t)nm; |
|
46 |
return hash ^ (hash >> 7); // code heap blocks are 128byte aligned |
|
47 |
} |
|
48 |
||
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
49 |
void remove_entry(Entry* e, Entry* previous); |
26422 | 50 |
Entry* new_entry(nmethod* nm); |
51 |
||
52 |
public: |
|
53 |
CodeRootSetTable(int size) : Hashtable<nmethod*, mtGC>(size, sizeof(Entry)), _purge_next(NULL) {} |
|
54 |
~CodeRootSetTable(); |
|
55 |
||
56 |
// Needs to be protected locks |
|
57 |
bool add(nmethod* nm); |
|
58 |
bool remove(nmethod* nm); |
|
59 |
||
60 |
// Can be called without locking |
|
61 |
bool contains(nmethod* nm); |
|
62 |
||
63 |
int entry_size() const { return BasicHashtable<mtGC>::entry_size(); } |
|
64 |
||
65 |
void copy_to(CodeRootSetTable* new_table); |
|
66 |
void nmethods_do(CodeBlobClosure* blk); |
|
67 |
||
68 |
template<typename CB> |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
69 |
int remove_if(CB& should_remove); |
26422 | 70 |
|
71 |
static void purge_list_append(CodeRootSetTable* tbl); |
|
72 |
static void purge(); |
|
73 |
||
74 |
static size_t static_mem_size() { |
|
75 |
return sizeof(_purge_list); |
|
76 |
} |
|
77 |
}; |
|
78 |
||
79 |
CodeRootSetTable* volatile CodeRootSetTable::_purge_list = NULL; |
|
80 |
||
81 |
CodeRootSetTable::Entry* CodeRootSetTable::new_entry(nmethod* nm) { |
|
82 |
unsigned int hash = compute_hash(nm); |
|
83 |
Entry* entry = (Entry*) new_entry_free_list(); |
|
84 |
if (entry == NULL) { |
|
85 |
entry = (Entry*) NEW_C_HEAP_ARRAY2(char, entry_size(), mtGC, CURRENT_PC); |
|
86 |
} |
|
87 |
entry->set_next(NULL); |
|
88 |
entry->set_hash(hash); |
|
89 |
entry->set_literal(nm); |
|
90 |
return entry; |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
91 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
92 |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
93 |
void CodeRootSetTable::remove_entry(Entry* e, Entry* previous) { |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
94 |
int index = hash_to_index(e->hash()); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
95 |
assert((e == bucket(index)) == (previous == NULL), "if e is the first entry then previous should be null"); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
96 |
|
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
97 |
if (previous == NULL) { |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
98 |
set_entry(index, e->next()); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
99 |
} else { |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
100 |
previous->set_next(e->next()); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
101 |
} |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
102 |
free_entry(e); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
103 |
} |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
104 |
|
26422 | 105 |
CodeRootSetTable::~CodeRootSetTable() { |
106 |
for (int index = 0; index < table_size(); ++index) { |
|
107 |
for (Entry* e = bucket(index); e != NULL; ) { |
|
108 |
Entry* to_remove = e; |
|
109 |
// read next before freeing. |
|
110 |
e = e->next(); |
|
111 |
unlink_entry(to_remove); |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
26574
diff
changeset
|
112 |
FREE_C_HEAP_ARRAY(char, to_remove); |
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
113 |
} |
26422 | 114 |
} |
115 |
assert(number_of_entries() == 0, "should have removed all entries"); |
|
116 |
free_buckets(); |
|
117 |
for (BasicHashtableEntry<mtGC>* e = new_entry_free_list(); e != NULL; e = new_entry_free_list()) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
26574
diff
changeset
|
118 |
FREE_C_HEAP_ARRAY(char, e); |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
119 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
120 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
121 |
|
26422 | 122 |
bool CodeRootSetTable::add(nmethod* nm) { |
123 |
if (!contains(nm)) { |
|
124 |
Entry* e = new_entry(nm); |
|
125 |
int index = hash_to_index(e->hash()); |
|
126 |
add_entry(index, e); |
|
127 |
return true; |
|
128 |
} |
|
129 |
return false; |
|
130 |
} |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
131 |
|
26422 | 132 |
bool CodeRootSetTable::contains(nmethod* nm) { |
133 |
int index = hash_to_index(compute_hash(nm)); |
|
134 |
for (Entry* e = bucket(index); e != NULL; e = e->next()) { |
|
135 |
if (e->literal() == nm) { |
|
136 |
return true; |
|
137 |
} |
|
138 |
} |
|
139 |
return false; |
|
140 |
} |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
141 |
|
26422 | 142 |
bool CodeRootSetTable::remove(nmethod* nm) { |
143 |
int index = hash_to_index(compute_hash(nm)); |
|
144 |
Entry* previous = NULL; |
|
145 |
for (Entry* e = bucket(index); e != NULL; previous = e, e = e->next()) { |
|
146 |
if (e->literal() == nm) { |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
147 |
remove_entry(e, previous); |
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
148 |
return true; |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
149 |
} |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
150 |
} |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
151 |
return false; |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
152 |
} |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
153 |
|
26422 | 154 |
void CodeRootSetTable::copy_to(CodeRootSetTable* new_table) { |
155 |
for (int index = 0; index < table_size(); ++index) { |
|
156 |
for (Entry* e = bucket(index); e != NULL; e = e->next()) { |
|
157 |
new_table->add(e->literal()); |
|
158 |
} |
|
159 |
} |
|
160 |
new_table->copy_freelist(this); |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
161 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
162 |
|
26422 | 163 |
void CodeRootSetTable::nmethods_do(CodeBlobClosure* blk) { |
164 |
for (int index = 0; index < table_size(); ++index) { |
|
165 |
for (Entry* e = bucket(index); e != NULL; e = e->next()) { |
|
166 |
blk->do_code_blob(e->literal()); |
|
167 |
} |
|
168 |
} |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
169 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
170 |
|
26422 | 171 |
template<typename CB> |
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
172 |
int CodeRootSetTable::remove_if(CB& should_remove) { |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
173 |
int num_removed = 0; |
26422 | 174 |
for (int index = 0; index < table_size(); ++index) { |
175 |
Entry* previous = NULL; |
|
176 |
Entry* e = bucket(index); |
|
177 |
while (e != NULL) { |
|
178 |
Entry* next = e->next(); |
|
179 |
if (should_remove(e->literal())) { |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
180 |
remove_entry(e, previous); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
181 |
++num_removed; |
26422 | 182 |
} else { |
183 |
previous = e; |
|
184 |
} |
|
185 |
e = next; |
|
186 |
} |
|
187 |
} |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
188 |
return num_removed; |
26422 | 189 |
} |
190 |
||
191 |
G1CodeRootSet::~G1CodeRootSet() { |
|
192 |
delete _table; |
|
24099
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
193 |
} |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
194 |
|
26422 | 195 |
CodeRootSetTable* G1CodeRootSet::load_acquire_table() { |
196 |
return (CodeRootSetTable*) OrderAccess::load_ptr_acquire(&_table); |
|
197 |
} |
|
198 |
||
199 |
void G1CodeRootSet::allocate_small_table() { |
|
200 |
_table = new CodeRootSetTable(SmallSize); |
|
201 |
} |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
202 |
|
26422 | 203 |
void CodeRootSetTable::purge_list_append(CodeRootSetTable* table) { |
204 |
for (;;) { |
|
205 |
table->_purge_next = _purge_list; |
|
206 |
CodeRootSetTable* old = (CodeRootSetTable*) Atomic::cmpxchg_ptr(table, &_purge_list, table->_purge_next); |
|
207 |
if (old == table->_purge_next) { |
|
208 |
break; |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
212 |
|
26422 | 213 |
void CodeRootSetTable::purge() { |
214 |
CodeRootSetTable* table = _purge_list; |
|
215 |
_purge_list = NULL; |
|
216 |
while (table != NULL) { |
|
217 |
CodeRootSetTable* to_purge = table; |
|
218 |
table = table->_purge_next; |
|
219 |
delete to_purge; |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
220 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
221 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
222 |
|
26422 | 223 |
void G1CodeRootSet::move_to_large() { |
224 |
CodeRootSetTable* temp = new CodeRootSetTable(LargeSize); |
|
225 |
||
226 |
_table->copy_to(temp); |
|
227 |
||
228 |
CodeRootSetTable::purge_list_append(_table); |
|
229 |
||
230 |
OrderAccess::release_store_ptr(&_table, temp); |
|
24099
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
231 |
} |
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
232 |
|
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
233 |
|
26422 | 234 |
void G1CodeRootSet::purge() { |
235 |
CodeRootSetTable::purge(); |
|
236 |
} |
|
237 |
||
238 |
size_t G1CodeRootSet::static_mem_size() { |
|
239 |
return CodeRootSetTable::static_mem_size(); |
|
240 |
} |
|
241 |
||
242 |
void G1CodeRootSet::add(nmethod* method) { |
|
243 |
bool added = false; |
|
244 |
if (is_empty()) { |
|
245 |
allocate_small_table(); |
|
246 |
} |
|
247 |
added = _table->add(method); |
|
248 |
if (_length == Threshold) { |
|
249 |
move_to_large(); |
|
250 |
} |
|
251 |
if (added) { |
|
252 |
++_length; |
|
253 |
} |
|
254 |
} |
|
255 |
||
256 |
bool G1CodeRootSet::remove(nmethod* method) { |
|
257 |
bool removed = false; |
|
258 |
if (_table != NULL) { |
|
259 |
removed = _table->remove(method); |
|
260 |
} |
|
261 |
if (removed) { |
|
262 |
_length--; |
|
263 |
if (_length == 0) { |
|
264 |
clear(); |
|
265 |
} |
|
266 |
} |
|
267 |
return removed; |
|
268 |
} |
|
269 |
||
270 |
bool G1CodeRootSet::contains(nmethod* method) { |
|
271 |
CodeRootSetTable* table = load_acquire_table(); |
|
272 |
if (table != NULL) { |
|
273 |
return table->contains(method); |
|
24099
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
274 |
} |
26422 | 275 |
return false; |
276 |
} |
|
277 |
||
278 |
void G1CodeRootSet::clear() { |
|
279 |
delete _table; |
|
280 |
_table = NULL; |
|
281 |
_length = 0; |
|
282 |
} |
|
283 |
||
284 |
size_t G1CodeRootSet::mem_size() { |
|
285 |
return sizeof(*this) + |
|
286 |
(_table != NULL ? sizeof(CodeRootSetTable) + _table->entry_size() * _length : 0); |
|
287 |
} |
|
288 |
||
289 |
void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const { |
|
290 |
if (_table != NULL) { |
|
291 |
_table->nmethods_do(blk); |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
class CleanCallback : public StackObj { |
|
296 |
class PointsIntoHRDetectionClosure : public OopClosure { |
|
297 |
HeapRegion* _hr; |
|
298 |
public: |
|
299 |
bool _points_into; |
|
300 |
PointsIntoHRDetectionClosure(HeapRegion* hr) : _hr(hr), _points_into(false) {} |
|
301 |
||
302 |
void do_oop(narrowOop* o) { |
|
303 |
do_oop_work(o); |
|
304 |
} |
|
305 |
||
306 |
void do_oop(oop* o) { |
|
307 |
do_oop_work(o); |
|
308 |
} |
|
309 |
||
310 |
template <typename T> |
|
311 |
void do_oop_work(T* p) { |
|
312 |
if (_hr->is_in(oopDesc::load_decode_heap_oop(p))) { |
|
313 |
_points_into = true; |
|
314 |
} |
|
315 |
} |
|
316 |
}; |
|
317 |
||
318 |
PointsIntoHRDetectionClosure _detector; |
|
319 |
CodeBlobToOopClosure _blobs; |
|
320 |
||
321 |
public: |
|
322 |
CleanCallback(HeapRegion* hr) : _detector(hr), _blobs(&_detector, !CodeBlobToOopClosure::FixRelocations) {} |
|
323 |
||
324 |
bool operator() (nmethod* nm) { |
|
325 |
_detector._points_into = false; |
|
326 |
_blobs.do_code_blob(nm); |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
327 |
return !_detector._points_into; |
26422 | 328 |
} |
329 |
}; |
|
330 |
||
331 |
void G1CodeRootSet::clean(HeapRegion* owner) { |
|
332 |
CleanCallback should_clean(owner); |
|
333 |
if (_table != NULL) { |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
334 |
int removed = _table->remove_if(should_clean); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
335 |
assert((size_t)removed <= _length, "impossible"); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
336 |
_length -= removed; |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
337 |
} |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
338 |
if (_length == 0) { |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
339 |
clear(); |
26422 | 340 |
} |
24099
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
341 |
} |
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
342 |
|
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
343 |
#ifndef PRODUCT |
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
344 |
|
26422 | 345 |
class G1CodeRootSetTest { |
346 |
public: |
|
347 |
static void test() { |
|
348 |
{ |
|
349 |
G1CodeRootSet set1; |
|
350 |
assert(set1.is_empty(), "Code root set must be initially empty but is not."); |
|
351 |
||
352 |
assert(G1CodeRootSet::static_mem_size() == sizeof(void*), |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
353 |
err_msg("The code root set's static memory usage is incorrect, " SIZE_FORMAT " bytes", G1CodeRootSet::static_mem_size())); |
26422 | 354 |
|
355 |
set1.add((nmethod*)1); |
|
356 |
assert(set1.length() == 1, err_msg("Added exactly one element, but set contains " |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
357 |
SIZE_FORMAT " elements", set1.length())); |
26422 | 358 |
|
359 |
const size_t num_to_add = (size_t)G1CodeRootSet::Threshold + 1; |
|
360 |
||
361 |
for (size_t i = 1; i <= num_to_add; i++) { |
|
362 |
set1.add((nmethod*)1); |
|
363 |
} |
|
364 |
assert(set1.length() == 1, |
|
365 |
err_msg("Duplicate detection should not have increased the set size but " |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
366 |
"is " SIZE_FORMAT, set1.length())); |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
367 |
|
26422 | 368 |
for (size_t i = 2; i <= num_to_add; i++) { |
369 |
set1.add((nmethod*)(uintptr_t)(i)); |
|
370 |
} |
|
371 |
assert(set1.length() == num_to_add, |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
372 |
err_msg("After adding in total " SIZE_FORMAT " distinct code roots, they " |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
373 |
"need to be in the set, but there are only " SIZE_FORMAT, |
26422 | 374 |
num_to_add, set1.length())); |
375 |
||
376 |
assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable"); |
|
377 |
||
378 |
size_t num_popped = 0; |
|
379 |
for (size_t i = 1; i <= num_to_add; i++) { |
|
380 |
bool removed = set1.remove((nmethod*)i); |
|
381 |
if (removed) { |
|
382 |
num_popped += 1; |
|
383 |
} else { |
|
384 |
break; |
|
385 |
} |
|
386 |
} |
|
387 |
assert(num_popped == num_to_add, |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
388 |
err_msg("Managed to pop " SIZE_FORMAT " code roots, but only " SIZE_FORMAT " " |
26422 | 389 |
"were added", num_popped, num_to_add)); |
390 |
assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable"); |
|
391 |
||
392 |
G1CodeRootSet::purge(); |
|
393 |
||
394 |
assert(CodeRootSetTable::_purge_list == NULL, "should have purged old small tables"); |
|
395 |
||
396 |
} |
|
397 |
||
398 |
} |
|
399 |
}; |
|
400 |
||
401 |
void TestCodeCacheRemSet_test() { |
|
402 |
G1CodeRootSetTest::test(); |
|
24099
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
403 |
} |
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
404 |
|
9c132a88935d
8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents:
23451
diff
changeset
|
405 |
#endif |