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