1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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>
69 int remove_if(CB& should_remove);
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;
91 }
92
93 void CodeRootSetTable::remove_entry(Entry* e, Entry* previous) {
94 int index = hash_to_index(e->hash());
95 assert((e == bucket(index)) == (previous == NULL), "if e is the first entry then previous should be null");
96
97 if (previous == NULL) {
98 set_entry(index, e->next());
99 } else {
100 previous->set_next(e->next());
215 void CodeRootSetTable::purge() {
216 CodeRootSetTable* table = _purge_list;
217 _purge_list = NULL;
218 while (table != NULL) {
219 CodeRootSetTable* to_purge = table;
220 table = table->_purge_next;
221 delete to_purge;
222 }
223 }
224
225 void G1CodeRootSet::move_to_large() {
226 CodeRootSetTable* temp = new CodeRootSetTable(LargeSize);
227
228 _table->copy_to(temp);
229
230 CodeRootSetTable::purge_list_append(_table);
231
232 OrderAccess::release_store_ptr(&_table, temp);
233 }
234
235
236 void G1CodeRootSet::purge() {
237 CodeRootSetTable::purge();
238 }
239
240 size_t G1CodeRootSet::static_mem_size() {
241 return CodeRootSetTable::static_mem_size();
242 }
243
244 void G1CodeRootSet::add(nmethod* method) {
245 bool added = false;
246 if (is_empty()) {
247 allocate_small_table();
248 }
249 added = _table->add(method);
250 if (_length == Threshold) {
251 move_to_large();
252 }
253 if (added) {
254 ++_length;
255 }
256 }
257
258 bool G1CodeRootSet::remove(nmethod* method) {
259 bool removed = false;
260 if (_table != NULL) {
261 removed = _table->remove(method);
262 }
263 if (removed) {
264 _length--;
265 if (_length == 0) {
266 clear();
267 }
268 }
269 return removed;
270 }
271
272 bool G1CodeRootSet::contains(nmethod* method) {
273 CodeRootSetTable* table = load_acquire_table();
274 if (table != NULL) {
275 return table->contains(method);
276 }
277 return false;
278 }
279
280 void G1CodeRootSet::clear() {
281 delete _table;
282 _table = NULL;
283 _length = 0;
284 }
285
286 size_t G1CodeRootSet::mem_size() {
287 return sizeof(*this) +
288 (_table != NULL ? sizeof(CodeRootSetTable) + _table->entry_size() * _length : 0);
289 }
290
291 void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const {
292 if (_table != NULL) {
293 _table->nmethods_do(blk);
294 }
295 }
296
297 class CleanCallback : public StackObj {
298 class PointsIntoHRDetectionClosure : public OopClosure {
299 HeapRegion* _hr;
300 public:
301 bool _points_into;
302 PointsIntoHRDetectionClosure(HeapRegion* hr) : _hr(hr), _points_into(false) {}
303
304 void do_oop(narrowOop* o) {
305 do_oop_work(o);
306 }
307
308 void do_oop(oop* o) {
|
1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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>
69 int remove_if(CB& should_remove);
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 size_t mem_size();
79 };
80
81 CodeRootSetTable* volatile CodeRootSetTable::_purge_list = NULL;
82
83 size_t CodeRootSetTable::mem_size() {
84 return sizeof(CodeRootSetTable) + (entry_size() * number_of_entries()) + (sizeof(HashtableBucket<mtGC>) * table_size());
85 }
86
87 CodeRootSetTable::Entry* CodeRootSetTable::new_entry(nmethod* nm) {
88 unsigned int hash = compute_hash(nm);
89 Entry* entry = (Entry*) new_entry_free_list();
90 if (entry == NULL) {
91 entry = (Entry*) NEW_C_HEAP_ARRAY2(char, entry_size(), mtGC, CURRENT_PC);
92 }
93 entry->set_next(NULL);
94 entry->set_hash(hash);
95 entry->set_literal(nm);
96 return entry;
97 }
98
99 void CodeRootSetTable::remove_entry(Entry* e, Entry* previous) {
100 int index = hash_to_index(e->hash());
101 assert((e == bucket(index)) == (previous == NULL), "if e is the first entry then previous should be null");
102
103 if (previous == NULL) {
104 set_entry(index, e->next());
105 } else {
106 previous->set_next(e->next());
221 void CodeRootSetTable::purge() {
222 CodeRootSetTable* table = _purge_list;
223 _purge_list = NULL;
224 while (table != NULL) {
225 CodeRootSetTable* to_purge = table;
226 table = table->_purge_next;
227 delete to_purge;
228 }
229 }
230
231 void G1CodeRootSet::move_to_large() {
232 CodeRootSetTable* temp = new CodeRootSetTable(LargeSize);
233
234 _table->copy_to(temp);
235
236 CodeRootSetTable::purge_list_append(_table);
237
238 OrderAccess::release_store_ptr(&_table, temp);
239 }
240
241 void G1CodeRootSet::purge() {
242 CodeRootSetTable::purge();
243 }
244
245 size_t G1CodeRootSet::static_mem_size() {
246 return CodeRootSetTable::static_mem_size();
247 }
248
249 void G1CodeRootSet::add(nmethod* method) {
250 bool added = false;
251 if (is_empty()) {
252 allocate_small_table();
253 }
254 added = _table->add(method);
255 if (added) {
256 if (_length == Threshold) {
257 move_to_large();
258 }
259 ++_length;
260 }
261 assert(_length == (size_t)_table->number_of_entries(), "sizes should match");
262 }
263
264 bool G1CodeRootSet::remove(nmethod* method) {
265 bool removed = false;
266 if (_table != NULL) {
267 removed = _table->remove(method);
268 }
269 if (removed) {
270 _length--;
271 if (_length == 0) {
272 clear();
273 }
274 }
275 assert((_length == 0 && _table == NULL) ||
276 (_length == (size_t)_table->number_of_entries()), "sizes should match");
277 return removed;
278 }
279
280 bool G1CodeRootSet::contains(nmethod* method) {
281 CodeRootSetTable* table = load_acquire_table(); // contains() may be called outside of lock, so ensure mem sync.
282 if (table != NULL) {
283 return table->contains(method);
284 }
285 return false;
286 }
287
288 void G1CodeRootSet::clear() {
289 delete _table;
290 _table = NULL;
291 _length = 0;
292 }
293
294 size_t G1CodeRootSet::mem_size() {
295 return sizeof(*this) + (_table != NULL ? _table->mem_size() : 0);
296 }
297
298 void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const {
299 if (_table != NULL) {
300 _table->nmethods_do(blk);
301 }
302 }
303
304 class CleanCallback : public StackObj {
305 class PointsIntoHRDetectionClosure : public OopClosure {
306 HeapRegion* _hr;
307 public:
308 bool _points_into;
309 PointsIntoHRDetectionClosure(HeapRegion* hr) : _hr(hr), _points_into(false) {}
310
311 void do_oop(narrowOop* o) {
312 do_oop_work(o);
313 }
314
315 void do_oop(oop* o) {
|