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