author | stefank |
Tue, 26 Nov 2019 10:47:46 +0100 | |
changeset 59290 | 97d13893ec3c |
parent 59252 | 623722a6aeb9 |
permissions | -rw-r--r-- |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
1 |
/* |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
49592
diff
changeset
|
2 |
* Copyright (c) 2014, 2018, 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" |
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
28 |
#include "gc/g1/g1CodeRootSetTable.hpp" |
30764 | 29 |
#include "gc/g1/g1CodeCacheRemSet.hpp" |
30 |
#include "gc/g1/heapRegion.hpp" |
|
26422 | 31 |
#include "memory/heap.hpp" |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
32 |
#include "memory/iterator.hpp" |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
47634
diff
changeset
|
33 |
#include "oops/access.inline.hpp" |
26422 | 34 |
#include "oops/oop.inline.hpp" |
59290
97d13893ec3c
8234748: Clean up atomic and orderAccess includes
stefank
parents:
59252
diff
changeset
|
35 |
#include "runtime/atomic.hpp" |
26422 | 36 |
#include "utilities/hashtable.inline.hpp" |
37 |
#include "utilities/stack.inline.hpp" |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
38 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
39 |
G1CodeRootSetTable* volatile G1CodeRootSetTable::_purge_list = NULL; |
26422 | 40 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
41 |
size_t G1CodeRootSetTable::mem_size() { |
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
42 |
return sizeof(G1CodeRootSetTable) + (entry_size() * number_of_entries()) + (sizeof(HashtableBucket<mtGC>) * table_size()); |
35879 | 43 |
} |
44 |
||
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
45 |
G1CodeRootSetTable::Entry* G1CodeRootSetTable::new_entry(nmethod* nm) { |
26422 | 46 |
unsigned int hash = compute_hash(nm); |
47 |
Entry* entry = (Entry*) new_entry_free_list(); |
|
48 |
if (entry == NULL) { |
|
49 |
entry = (Entry*) NEW_C_HEAP_ARRAY2(char, entry_size(), mtGC, CURRENT_PC); |
|
50 |
} |
|
51 |
entry->set_next(NULL); |
|
52 |
entry->set_hash(hash); |
|
53 |
entry->set_literal(nm); |
|
54 |
return entry; |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
55 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
56 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
57 |
void G1CodeRootSetTable::remove_entry(Entry* e, Entry* previous) { |
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
58 |
int index = hash_to_index(e->hash()); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
59 |
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
|
60 |
|
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
61 |
if (previous == NULL) { |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
62 |
set_entry(index, e->next()); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
63 |
} else { |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
64 |
previous->set_next(e->next()); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
65 |
} |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
66 |
free_entry(e); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
67 |
} |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
68 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
69 |
G1CodeRootSetTable::~G1CodeRootSetTable() { |
26422 | 70 |
for (int index = 0; index < table_size(); ++index) { |
71 |
for (Entry* e = bucket(index); e != NULL; ) { |
|
72 |
Entry* to_remove = e; |
|
73 |
// read next before freeing. |
|
74 |
e = e->next(); |
|
75 |
unlink_entry(to_remove); |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
26574
diff
changeset
|
76 |
FREE_C_HEAP_ARRAY(char, to_remove); |
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
77 |
} |
26422 | 78 |
} |
79 |
assert(number_of_entries() == 0, "should have removed all entries"); |
|
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
49592
diff
changeset
|
80 |
// Each of the entries in new_entry_free_list() have been allocated in |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
49592
diff
changeset
|
81 |
// G1CodeRootSetTable::new_entry(). We never call the block allocator |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
49592
diff
changeset
|
82 |
// in BasicHashtable::new_entry(). |
26422 | 83 |
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
|
84 |
FREE_C_HEAP_ARRAY(char, e); |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
85 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
86 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
87 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
88 |
bool G1CodeRootSetTable::add(nmethod* nm) { |
26422 | 89 |
if (!contains(nm)) { |
90 |
Entry* e = new_entry(nm); |
|
91 |
int index = hash_to_index(e->hash()); |
|
92 |
add_entry(index, e); |
|
93 |
return true; |
|
94 |
} |
|
95 |
return false; |
|
96 |
} |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
97 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
98 |
bool G1CodeRootSetTable::contains(nmethod* nm) { |
26422 | 99 |
int index = hash_to_index(compute_hash(nm)); |
100 |
for (Entry* e = bucket(index); e != NULL; e = e->next()) { |
|
101 |
if (e->literal() == nm) { |
|
102 |
return true; |
|
103 |
} |
|
104 |
} |
|
105 |
return false; |
|
106 |
} |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
107 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
108 |
bool G1CodeRootSetTable::remove(nmethod* nm) { |
26422 | 109 |
int index = hash_to_index(compute_hash(nm)); |
110 |
Entry* previous = NULL; |
|
111 |
for (Entry* e = bucket(index); e != NULL; previous = e, e = e->next()) { |
|
112 |
if (e->literal() == nm) { |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
113 |
remove_entry(e, previous); |
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
114 |
return true; |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
115 |
} |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
116 |
} |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
117 |
return false; |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
118 |
} |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
119 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
120 |
void G1CodeRootSetTable::copy_to(G1CodeRootSetTable* new_table) { |
26422 | 121 |
for (int index = 0; index < table_size(); ++index) { |
122 |
for (Entry* e = bucket(index); e != NULL; e = e->next()) { |
|
123 |
new_table->add(e->literal()); |
|
124 |
} |
|
125 |
} |
|
126 |
new_table->copy_freelist(this); |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
127 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
128 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
129 |
void G1CodeRootSetTable::nmethods_do(CodeBlobClosure* blk) { |
26422 | 130 |
for (int index = 0; index < table_size(); ++index) { |
131 |
for (Entry* e = bucket(index); e != NULL; e = e->next()) { |
|
132 |
blk->do_code_blob(e->literal()); |
|
133 |
} |
|
134 |
} |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
135 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
136 |
|
26422 | 137 |
template<typename CB> |
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
138 |
int G1CodeRootSetTable::remove_if(CB& should_remove) { |
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
139 |
int num_removed = 0; |
26422 | 140 |
for (int index = 0; index < table_size(); ++index) { |
141 |
Entry* previous = NULL; |
|
142 |
Entry* e = bucket(index); |
|
143 |
while (e != NULL) { |
|
144 |
Entry* next = e->next(); |
|
145 |
if (should_remove(e->literal())) { |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
146 |
remove_entry(e, previous); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
147 |
++num_removed; |
26422 | 148 |
} else { |
149 |
previous = e; |
|
150 |
} |
|
151 |
e = next; |
|
152 |
} |
|
153 |
} |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
154 |
return num_removed; |
26422 | 155 |
} |
156 |
||
157 |
G1CodeRootSet::~G1CodeRootSet() { |
|
158 |
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
|
159 |
} |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
160 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
161 |
G1CodeRootSetTable* G1CodeRootSet::load_acquire_table() { |
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
52631
diff
changeset
|
162 |
return Atomic::load_acquire(&_table); |
26422 | 163 |
} |
164 |
||
165 |
void G1CodeRootSet::allocate_small_table() { |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
166 |
G1CodeRootSetTable* temp = new G1CodeRootSetTable(SmallSize); |
33093 | 167 |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
52631
diff
changeset
|
168 |
Atomic::release_store(&_table, temp); |
26422 | 169 |
} |
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
170 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
171 |
void G1CodeRootSetTable::purge_list_append(G1CodeRootSetTable* table) { |
26422 | 172 |
for (;;) { |
173 |
table->_purge_next = _purge_list; |
|
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59247
diff
changeset
|
174 |
G1CodeRootSetTable* old = Atomic::cmpxchg(&_purge_list, table->_purge_next, table); |
26422 | 175 |
if (old == table->_purge_next) { |
176 |
break; |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
180 |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
181 |
void G1CodeRootSetTable::purge() { |
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
182 |
G1CodeRootSetTable* table = _purge_list; |
26422 | 183 |
_purge_list = NULL; |
184 |
while (table != NULL) { |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
185 |
G1CodeRootSetTable* to_purge = table; |
26422 | 186 |
table = table->_purge_next; |
187 |
delete to_purge; |
|
23451
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
188 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
189 |
} |
ed2b8bb28fed
8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff
changeset
|
190 |
|
26422 | 191 |
void G1CodeRootSet::move_to_large() { |
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
192 |
G1CodeRootSetTable* temp = new G1CodeRootSetTable(LargeSize); |
26422 | 193 |
|
194 |
_table->copy_to(temp); |
|
195 |
||
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
196 |
G1CodeRootSetTable::purge_list_append(_table); |
26422 | 197 |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
52631
diff
changeset
|
198 |
Atomic::release_store(&_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
|
199 |
} |
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
|
200 |
|
26422 | 201 |
void G1CodeRootSet::purge() { |
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
202 |
G1CodeRootSetTable::purge(); |
26422 | 203 |
} |
204 |
||
205 |
size_t G1CodeRootSet::static_mem_size() { |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
206 |
return G1CodeRootSetTable::static_mem_size(); |
26422 | 207 |
} |
208 |
||
209 |
void G1CodeRootSet::add(nmethod* method) { |
|
210 |
bool added = false; |
|
211 |
if (is_empty()) { |
|
212 |
allocate_small_table(); |
|
213 |
} |
|
214 |
added = _table->add(method); |
|
215 |
if (added) { |
|
35879 | 216 |
if (_length == Threshold) { |
217 |
move_to_large(); |
|
218 |
} |
|
26422 | 219 |
++_length; |
220 |
} |
|
35879 | 221 |
assert(_length == (size_t)_table->number_of_entries(), "sizes should match"); |
26422 | 222 |
} |
223 |
||
224 |
bool G1CodeRootSet::remove(nmethod* method) { |
|
225 |
bool removed = false; |
|
226 |
if (_table != NULL) { |
|
227 |
removed = _table->remove(method); |
|
228 |
} |
|
229 |
if (removed) { |
|
230 |
_length--; |
|
231 |
if (_length == 0) { |
|
232 |
clear(); |
|
233 |
} |
|
234 |
} |
|
35879 | 235 |
assert((_length == 0 && _table == NULL) || |
236 |
(_length == (size_t)_table->number_of_entries()), "sizes should match"); |
|
26422 | 237 |
return removed; |
238 |
} |
|
239 |
||
240 |
bool G1CodeRootSet::contains(nmethod* method) { |
|
40905
94ffc131534f
8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
35879
diff
changeset
|
241 |
G1CodeRootSetTable* table = load_acquire_table(); // contains() may be called outside of lock, so ensure mem sync. |
26422 | 242 |
if (table != NULL) { |
243 |
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
|
244 |
} |
26422 | 245 |
return false; |
246 |
} |
|
247 |
||
248 |
void G1CodeRootSet::clear() { |
|
249 |
delete _table; |
|
250 |
_table = NULL; |
|
251 |
_length = 0; |
|
252 |
} |
|
253 |
||
254 |
size_t G1CodeRootSet::mem_size() { |
|
35879 | 255 |
return sizeof(*this) + (_table != NULL ? _table->mem_size() : 0); |
26422 | 256 |
} |
257 |
||
258 |
void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const { |
|
259 |
if (_table != NULL) { |
|
260 |
_table->nmethods_do(blk); |
|
261 |
} |
|
262 |
} |
|
263 |
||
264 |
class CleanCallback : public StackObj { |
|
265 |
class PointsIntoHRDetectionClosure : public OopClosure { |
|
266 |
HeapRegion* _hr; |
|
267 |
public: |
|
268 |
bool _points_into; |
|
269 |
PointsIntoHRDetectionClosure(HeapRegion* hr) : _hr(hr), _points_into(false) {} |
|
270 |
||
271 |
void do_oop(narrowOop* o) { |
|
272 |
do_oop_work(o); |
|
273 |
} |
|
274 |
||
275 |
void do_oop(oop* o) { |
|
276 |
do_oop_work(o); |
|
277 |
} |
|
278 |
||
279 |
template <typename T> |
|
280 |
void do_oop_work(T* p) { |
|
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
47634
diff
changeset
|
281 |
if (_hr->is_in(RawAccess<>::oop_load(p))) { |
26422 | 282 |
_points_into = true; |
283 |
} |
|
284 |
} |
|
285 |
}; |
|
286 |
||
287 |
PointsIntoHRDetectionClosure _detector; |
|
288 |
CodeBlobToOopClosure _blobs; |
|
289 |
||
290 |
public: |
|
291 |
CleanCallback(HeapRegion* hr) : _detector(hr), _blobs(&_detector, !CodeBlobToOopClosure::FixRelocations) {} |
|
292 |
||
293 |
bool operator() (nmethod* nm) { |
|
294 |
_detector._points_into = false; |
|
295 |
_blobs.do_code_blob(nm); |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
296 |
return !_detector._points_into; |
26422 | 297 |
} |
298 |
}; |
|
299 |
||
300 |
void G1CodeRootSet::clean(HeapRegion* owner) { |
|
301 |
CleanCallback should_clean(owner); |
|
302 |
if (_table != NULL) { |
|
26574
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
303 |
int removed = _table->remove_if(should_clean); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
304 |
assert((size_t)removed <= _length, "impossible"); |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
305 |
_length -= removed; |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
306 |
} |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
307 |
if (_length == 0) { |
59219d1be209
8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents:
26422
diff
changeset
|
308 |
clear(); |
26422 | 309 |
} |
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
|
310 |
} |