dictionary.cpp revision 9099:115188e14c15
1/* 2 * Copyright (c) 2003, 2014, 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 * 23 */ 24 25#include "precompiled.hpp" 26#include "classfile/dictionary.hpp" 27#include "classfile/systemDictionary.hpp" 28#include "memory/iterator.hpp" 29#include "oops/oop.inline.hpp" 30#include "prims/jvmtiRedefineClassesTrace.hpp" 31#include "runtime/orderAccess.inline.hpp" 32#include "utilities/hashtable.inline.hpp" 33 34DictionaryEntry* Dictionary::_current_class_entry = NULL; 35int Dictionary::_current_class_index = 0; 36 37 38Dictionary::Dictionary(int table_size) 39 : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry)) { 40 _current_class_index = 0; 41 _current_class_entry = NULL; 42 _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize); 43}; 44 45 46Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t, 47 int number_of_entries) 48 : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry), t, number_of_entries) { 49 _current_class_index = 0; 50 _current_class_entry = NULL; 51 _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize); 52}; 53 54ProtectionDomainCacheEntry* Dictionary::cache_get(oop protection_domain) { 55 return _pd_cache_table->get(protection_domain); 56} 57 58DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass, 59 ClassLoaderData* loader_data) { 60 DictionaryEntry* entry = (DictionaryEntry*)Hashtable<Klass*, mtClass>::new_entry(hash, klass); 61 entry->set_loader_data(loader_data); 62 entry->set_pd_set(NULL); 63 assert(klass->oop_is_instance(), "Must be"); 64 return entry; 65} 66 67 68void Dictionary::free_entry(DictionaryEntry* entry) { 69 // avoid recursion when deleting linked list 70 while (entry->pd_set() != NULL) { 71 ProtectionDomainEntry* to_delete = entry->pd_set(); 72 entry->set_pd_set(to_delete->next()); 73 delete to_delete; 74 } 75 Hashtable<Klass*, mtClass>::free_entry(entry); 76} 77 78 79bool DictionaryEntry::contains_protection_domain(oop protection_domain) const { 80#ifdef ASSERT 81 if (protection_domain == InstanceKlass::cast(klass())->protection_domain()) { 82 // Ensure this doesn't show up in the pd_set (invariant) 83 bool in_pd_set = false; 84 for (ProtectionDomainEntry* current = _pd_set; 85 current != NULL; 86 current = current->next()) { 87 if (current->protection_domain() == protection_domain) { 88 in_pd_set = true; 89 break; 90 } 91 } 92 if (in_pd_set) { 93 assert(false, "A klass's protection domain should not show up " 94 "in its sys. dict. PD set"); 95 } 96 } 97#endif /* ASSERT */ 98 99 if (protection_domain == InstanceKlass::cast(klass())->protection_domain()) { 100 // Succeeds trivially 101 return true; 102 } 103 104 for (ProtectionDomainEntry* current = _pd_set; 105 current != NULL; 106 current = current->next()) { 107 if (current->protection_domain() == protection_domain) return true; 108 } 109 return false; 110} 111 112 113void DictionaryEntry::add_protection_domain(Dictionary* dict, oop protection_domain) { 114 assert_locked_or_safepoint(SystemDictionary_lock); 115 if (!contains_protection_domain(protection_domain)) { 116 ProtectionDomainCacheEntry* entry = dict->cache_get(protection_domain); 117 ProtectionDomainEntry* new_head = 118 new ProtectionDomainEntry(entry, _pd_set); 119 // Warning: Preserve store ordering. The SystemDictionary is read 120 // without locks. The new ProtectionDomainEntry must be 121 // complete before other threads can be allowed to see it 122 // via a store to _pd_set. 123 OrderAccess::release_store_ptr(&_pd_set, new_head); 124 } 125 if (TraceProtectionDomainVerification && WizardMode) { 126 print(); 127 } 128} 129 130 131void Dictionary::do_unloading() { 132 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 133 134 // Remove unloadable entries and classes from system dictionary 135 // The placeholder array has been handled in always_strong_oops_do. 136 DictionaryEntry* probe = NULL; 137 for (int index = 0; index < table_size(); index++) { 138 for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) { 139 probe = *p; 140 Klass* e = probe->klass(); 141 ClassLoaderData* loader_data = probe->loader_data(); 142 143 InstanceKlass* ik = InstanceKlass::cast(e); 144 145 // Non-unloadable classes were handled in always_strong_oops_do 146 if (!is_strongly_reachable(loader_data, e)) { 147 // Entry was not visited in phase1 (negated test from phase1) 148 assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader"); 149 ClassLoaderData* k_def_class_loader_data = ik->class_loader_data(); 150 151 // Do we need to delete this system dictionary entry? 152 bool purge_entry = false; 153 154 // Do we need to delete this system dictionary entry? 155 if (loader_data->is_unloading()) { 156 // If the loader is not live this entry should always be 157 // removed (will never be looked up again). 158 purge_entry = true; 159 } else { 160 // The loader in this entry is alive. If the klass is dead, 161 // (determined by checking the defining class loader) 162 // the loader must be an initiating loader (rather than the 163 // defining loader). Remove this entry. 164 if (k_def_class_loader_data->is_unloading()) { 165 // If we get here, the class_loader_data must not be the defining 166 // loader, it must be an initiating one. 167 assert(k_def_class_loader_data != loader_data, 168 "cannot have live defining loader and unreachable klass"); 169 // Loader is live, but class and its defining loader are dead. 170 // Remove the entry. The class is going away. 171 purge_entry = true; 172 } 173 } 174 175 if (purge_entry) { 176 *p = probe->next(); 177 if (probe == _current_class_entry) { 178 _current_class_entry = NULL; 179 } 180 free_entry(probe); 181 continue; 182 } 183 } 184 p = probe->next_addr(); 185 } 186 } 187} 188 189void Dictionary::roots_oops_do(OopClosure* strong, OopClosure* weak) { 190 // Skip the strong roots probe marking if the closures are the same. 191 if (strong == weak) { 192 oops_do(strong); 193 return; 194 } 195 196 for (int index = 0; index < table_size(); index++) { 197 for (DictionaryEntry *probe = bucket(index); 198 probe != NULL; 199 probe = probe->next()) { 200 Klass* e = probe->klass(); 201 ClassLoaderData* loader_data = probe->loader_data(); 202 if (is_strongly_reachable(loader_data, e)) { 203 probe->set_strongly_reachable(); 204 } 205 } 206 } 207 _pd_cache_table->roots_oops_do(strong, weak); 208} 209 210void Dictionary::remove_classes_in_error_state() { 211 assert(DumpSharedSpaces, "supported only when dumping"); 212 DictionaryEntry* probe = NULL; 213 for (int index = 0; index < table_size(); index++) { 214 for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) { 215 probe = *p; 216 InstanceKlass* ik = InstanceKlass::cast(probe->klass()); 217 if (ik->is_in_error_state()) { // purge this entry 218 *p = probe->next(); 219 if (probe == _current_class_entry) { 220 _current_class_entry = NULL; 221 } 222 free_entry(probe); 223 ResourceMark rm; 224 tty->print_cr("Preload Warning: Removed error class: %s", ik->external_name()); 225 continue; 226 } 227 228 p = probe->next_addr(); 229 } 230 } 231} 232 233void Dictionary::always_strong_oops_do(OopClosure* blk) { 234 // Follow all system classes and temporary placeholders in dictionary; only 235 // protection domain oops contain references into the heap. In a first 236 // pass over the system dictionary determine which need to be treated as 237 // strongly reachable and mark them as such. 238 for (int index = 0; index < table_size(); index++) { 239 for (DictionaryEntry *probe = bucket(index); 240 probe != NULL; 241 probe = probe->next()) { 242 Klass* e = probe->klass(); 243 ClassLoaderData* loader_data = probe->loader_data(); 244 if (is_strongly_reachable(loader_data, e)) { 245 probe->set_strongly_reachable(); 246 } 247 } 248 } 249 // Then iterate over the protection domain cache to apply the closure on the 250 // previously marked ones. 251 _pd_cache_table->always_strong_oops_do(blk); 252} 253 254 255void Dictionary::always_strong_classes_do(KlassClosure* closure) { 256 // Follow all system classes and temporary placeholders in dictionary 257 for (int index = 0; index < table_size(); index++) { 258 for (DictionaryEntry* probe = bucket(index); 259 probe != NULL; 260 probe = probe->next()) { 261 Klass* e = probe->klass(); 262 ClassLoaderData* loader_data = probe->loader_data(); 263 if (is_strongly_reachable(loader_data, e)) { 264 closure->do_klass(e); 265 } 266 } 267 } 268} 269 270 271// Just the classes from defining class loaders 272void Dictionary::classes_do(void f(Klass*)) { 273 for (int index = 0; index < table_size(); index++) { 274 for (DictionaryEntry* probe = bucket(index); 275 probe != NULL; 276 probe = probe->next()) { 277 Klass* k = probe->klass(); 278 if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) { 279 f(k); 280 } 281 } 282 } 283} 284 285// Added for initialize_itable_for_klass to handle exceptions 286// Just the classes from defining class loaders 287void Dictionary::classes_do(void f(Klass*, TRAPS), TRAPS) { 288 for (int index = 0; index < table_size(); index++) { 289 for (DictionaryEntry* probe = bucket(index); 290 probe != NULL; 291 probe = probe->next()) { 292 Klass* k = probe->klass(); 293 if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) { 294 f(k, CHECK); 295 } 296 } 297 } 298} 299 300// All classes, and their class loaders 301// Don't iterate over placeholders 302void Dictionary::classes_do(void f(Klass*, ClassLoaderData*)) { 303 for (int index = 0; index < table_size(); index++) { 304 for (DictionaryEntry* probe = bucket(index); 305 probe != NULL; 306 probe = probe->next()) { 307 Klass* k = probe->klass(); 308 f(k, probe->loader_data()); 309 } 310 } 311} 312 313void Dictionary::oops_do(OopClosure* f) { 314 // Only the protection domain oops contain references into the heap. Iterate 315 // over all of them. 316 _pd_cache_table->oops_do(f); 317} 318 319void Dictionary::methods_do(void f(Method*)) { 320 for (int index = 0; index < table_size(); index++) { 321 for (DictionaryEntry* probe = bucket(index); 322 probe != NULL; 323 probe = probe->next()) { 324 Klass* k = probe->klass(); 325 if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) { 326 // only take klass is we have the entry with the defining class loader 327 InstanceKlass::cast(k)->methods_do(f); 328 } 329 } 330 } 331} 332 333void Dictionary::unlink(BoolObjectClosure* is_alive) { 334 // Only the protection domain cache table may contain references to the heap 335 // that need to be unlinked. 336 _pd_cache_table->unlink(is_alive); 337} 338 339Klass* Dictionary::try_get_next_class() { 340 while (true) { 341 if (_current_class_entry != NULL) { 342 Klass* k = _current_class_entry->klass(); 343 _current_class_entry = _current_class_entry->next(); 344 return k; 345 } 346 _current_class_index = (_current_class_index + 1) % table_size(); 347 _current_class_entry = bucket(_current_class_index); 348 } 349 // never reached 350} 351 352// Add a loaded class to the system dictionary. 353// Readers of the SystemDictionary aren't always locked, so _buckets 354// is volatile. The store of the next field in the constructor is 355// also cast to volatile; we do this to ensure store order is maintained 356// by the compilers. 357 358void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data, 359 KlassHandle obj) { 360 assert_locked_or_safepoint(SystemDictionary_lock); 361 assert(obj() != NULL, "adding NULL obj"); 362 assert(obj()->name() == class_name, "sanity check on name"); 363 assert(loader_data != NULL, "Must be non-NULL"); 364 365 unsigned int hash = compute_hash(class_name, loader_data); 366 int index = hash_to_index(hash); 367 DictionaryEntry* entry = new_entry(hash, obj(), loader_data); 368 add_entry(index, entry); 369} 370 371 372// This routine does not lock the system dictionary. 373// 374// Since readers don't hold a lock, we must make sure that system 375// dictionary entries are only removed at a safepoint (when only one 376// thread is running), and are added to in a safe way (all links must 377// be updated in an MT-safe manner). 378// 379// Callers should be aware that an entry could be added just after 380// _buckets[index] is read here, so the caller will not see the new entry. 381DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash, 382 Symbol* class_name, 383 ClassLoaderData* loader_data) { 384 debug_only(_lookup_count++); 385 for (DictionaryEntry* entry = bucket(index); 386 entry != NULL; 387 entry = entry->next()) { 388 if (entry->hash() == hash && entry->equals(class_name, loader_data)) { 389 return entry; 390 } 391 debug_only(_lookup_length++); 392 } 393 return NULL; 394} 395 396 397Klass* Dictionary::find(int index, unsigned int hash, Symbol* name, 398 ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { 399 DictionaryEntry* entry = get_entry(index, hash, name, loader_data); 400 if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) { 401 return entry->klass(); 402 } else { 403 return NULL; 404 } 405} 406 407 408Klass* Dictionary::find_class(int index, unsigned int hash, 409 Symbol* name, ClassLoaderData* loader_data) { 410 assert_locked_or_safepoint(SystemDictionary_lock); 411 assert (index == index_for(name, loader_data), "incorrect index?"); 412 413 DictionaryEntry* entry = get_entry(index, hash, name, loader_data); 414 return (entry != NULL) ? entry->klass() : (Klass*)NULL; 415} 416 417 418// Variant of find_class for shared classes. No locking required, as 419// that table is static. 420 421Klass* Dictionary::find_shared_class(int index, unsigned int hash, 422 Symbol* name) { 423 assert (index == index_for(name, NULL), "incorrect index?"); 424 425 DictionaryEntry* entry = get_entry(index, hash, name, NULL); 426 return (entry != NULL) ? entry->klass() : (Klass*)NULL; 427} 428 429 430void Dictionary::add_protection_domain(int index, unsigned int hash, 431 instanceKlassHandle klass, 432 ClassLoaderData* loader_data, Handle protection_domain, 433 TRAPS) { 434 Symbol* klass_name = klass->name(); 435 DictionaryEntry* entry = get_entry(index, hash, klass_name, loader_data); 436 437 assert(entry != NULL,"entry must be present, we just created it"); 438 assert(protection_domain() != NULL, 439 "real protection domain should be present"); 440 441 entry->add_protection_domain(this, protection_domain()); 442 443 assert(entry->contains_protection_domain(protection_domain()), 444 "now protection domain should be present"); 445} 446 447 448bool Dictionary::is_valid_protection_domain(int index, unsigned int hash, 449 Symbol* name, 450 ClassLoaderData* loader_data, 451 Handle protection_domain) { 452 DictionaryEntry* entry = get_entry(index, hash, name, loader_data); 453 return entry->is_valid_protection_domain(protection_domain); 454} 455 456 457void Dictionary::reorder_dictionary() { 458 459 // Copy all the dictionary entries into a single master list. 460 461 DictionaryEntry* master_list = NULL; 462 for (int i = 0; i < table_size(); ++i) { 463 DictionaryEntry* p = bucket(i); 464 while (p != NULL) { 465 DictionaryEntry* tmp; 466 tmp = p->next(); 467 p->set_next(master_list); 468 master_list = p; 469 p = tmp; 470 } 471 set_entry(i, NULL); 472 } 473 474 // Add the dictionary entries back to the list in the correct buckets. 475 while (master_list != NULL) { 476 DictionaryEntry* p = master_list; 477 master_list = master_list->next(); 478 p->set_next(NULL); 479 Symbol* class_name = InstanceKlass::cast((Klass*)(p->klass()))->name(); 480 // Since the null class loader data isn't copied to the CDS archive, 481 // compute the hash with NULL for loader data. 482 unsigned int hash = compute_hash(class_name, NULL); 483 int index = hash_to_index(hash); 484 p->set_hash(hash); 485 p->set_loader_data(NULL); // loader_data isn't copied to CDS 486 p->set_next(bucket(index)); 487 set_entry(index, p); 488 } 489} 490 491ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size) 492 : Hashtable<oop, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry)) 493{ 494} 495 496void ProtectionDomainCacheTable::unlink(BoolObjectClosure* is_alive) { 497 assert(SafepointSynchronize::is_at_safepoint(), "must be"); 498 for (int i = 0; i < table_size(); ++i) { 499 ProtectionDomainCacheEntry** p = bucket_addr(i); 500 ProtectionDomainCacheEntry* entry = bucket(i); 501 while (entry != NULL) { 502 if (is_alive->do_object_b(entry->literal())) { 503 p = entry->next_addr(); 504 } else { 505 *p = entry->next(); 506 free_entry(entry); 507 } 508 entry = *p; 509 } 510 } 511} 512 513void ProtectionDomainCacheTable::oops_do(OopClosure* f) { 514 for (int index = 0; index < table_size(); index++) { 515 for (ProtectionDomainCacheEntry* probe = bucket(index); 516 probe != NULL; 517 probe = probe->next()) { 518 probe->oops_do(f); 519 } 520 } 521} 522 523void ProtectionDomainCacheTable::roots_oops_do(OopClosure* strong, OopClosure* weak) { 524 for (int index = 0; index < table_size(); index++) { 525 for (ProtectionDomainCacheEntry* probe = bucket(index); 526 probe != NULL; 527 probe = probe->next()) { 528 if (probe->is_strongly_reachable()) { 529 probe->reset_strongly_reachable(); 530 probe->oops_do(strong); 531 } else { 532 if (weak != NULL) { 533 probe->oops_do(weak); 534 } 535 } 536 } 537 } 538} 539 540uint ProtectionDomainCacheTable::bucket_size() { 541 return sizeof(ProtectionDomainCacheEntry); 542} 543 544#ifndef PRODUCT 545void ProtectionDomainCacheTable::print() { 546 tty->print_cr("Protection domain cache table (table_size=%d, classes=%d)", 547 table_size(), number_of_entries()); 548 for (int index = 0; index < table_size(); index++) { 549 for (ProtectionDomainCacheEntry* probe = bucket(index); 550 probe != NULL; 551 probe = probe->next()) { 552 probe->print(); 553 } 554 } 555} 556 557void ProtectionDomainCacheEntry::print() { 558 tty->print_cr("entry " PTR_FORMAT " value " PTR_FORMAT " strongly_reachable %d next " PTR_FORMAT, 559 p2i(this), p2i(literal()), _strongly_reachable, p2i(next())); 560} 561#endif 562 563void ProtectionDomainCacheTable::verify() { 564 int element_count = 0; 565 for (int index = 0; index < table_size(); index++) { 566 for (ProtectionDomainCacheEntry* probe = bucket(index); 567 probe != NULL; 568 probe = probe->next()) { 569 probe->verify(); 570 element_count++; 571 } 572 } 573 guarantee(number_of_entries() == element_count, 574 "Verify of protection domain cache table failed"); 575 debug_only(verify_lookup_length((double)number_of_entries() / table_size())); 576} 577 578void ProtectionDomainCacheEntry::verify() { 579 guarantee(literal()->is_oop(), "must be an oop"); 580} 581 582void ProtectionDomainCacheTable::always_strong_oops_do(OopClosure* f) { 583 // the caller marked the protection domain cache entries that we need to apply 584 // the closure on. Only process them. 585 for (int index = 0; index < table_size(); index++) { 586 for (ProtectionDomainCacheEntry* probe = bucket(index); 587 probe != NULL; 588 probe = probe->next()) { 589 if (probe->is_strongly_reachable()) { 590 probe->reset_strongly_reachable(); 591 probe->oops_do(f); 592 } 593 } 594 } 595} 596 597ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(oop protection_domain) { 598 unsigned int hash = compute_hash(protection_domain); 599 int index = hash_to_index(hash); 600 601 ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain); 602 if (entry == NULL) { 603 entry = add_entry(index, hash, protection_domain); 604 } 605 return entry; 606} 607 608ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, oop protection_domain) { 609 for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) { 610 if (e->protection_domain() == protection_domain) { 611 return e; 612 } 613 } 614 615 return NULL; 616} 617 618ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, oop protection_domain) { 619 assert_locked_or_safepoint(SystemDictionary_lock); 620 assert(index == index_for(protection_domain), "incorrect index?"); 621 assert(find_entry(index, protection_domain) == NULL, "no double entry"); 622 623 ProtectionDomainCacheEntry* p = new_entry(hash, protection_domain); 624 Hashtable<oop, mtClass>::add_entry(index, p); 625 return p; 626} 627 628void ProtectionDomainCacheTable::free(ProtectionDomainCacheEntry* to_delete) { 629 unsigned int hash = compute_hash(to_delete->protection_domain()); 630 int index = hash_to_index(hash); 631 632 ProtectionDomainCacheEntry** p = bucket_addr(index); 633 ProtectionDomainCacheEntry* entry = bucket(index); 634 while (true) { 635 assert(entry != NULL, "sanity"); 636 637 if (entry == to_delete) { 638 *p = entry->next(); 639 Hashtable<oop, mtClass>::free_entry(entry); 640 break; 641 } else { 642 p = entry->next_addr(); 643 entry = *p; 644 } 645 } 646} 647 648SymbolPropertyTable::SymbolPropertyTable(int table_size) 649 : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry)) 650{ 651} 652SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t, 653 int number_of_entries) 654 : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries) 655{ 656} 657 658 659SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash, 660 Symbol* sym, 661 intptr_t sym_mode) { 662 assert(index == index_for(sym, sym_mode), "incorrect index?"); 663 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { 664 if (p->hash() == hash && p->symbol() == sym && p->symbol_mode() == sym_mode) { 665 return p; 666 } 667 } 668 return NULL; 669} 670 671 672SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash, 673 Symbol* sym, intptr_t sym_mode) { 674 assert_locked_or_safepoint(SystemDictionary_lock); 675 assert(index == index_for(sym, sym_mode), "incorrect index?"); 676 assert(find_entry(index, hash, sym, sym_mode) == NULL, "no double entry"); 677 678 SymbolPropertyEntry* p = new_entry(hash, sym, sym_mode); 679 Hashtable<Symbol*, mtSymbol>::add_entry(index, p); 680 return p; 681} 682 683void SymbolPropertyTable::oops_do(OopClosure* f) { 684 for (int index = 0; index < table_size(); index++) { 685 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { 686 if (p->method_type() != NULL) { 687 f->do_oop(p->method_type_addr()); 688 } 689 } 690 } 691} 692 693void SymbolPropertyTable::methods_do(void f(Method*)) { 694 for (int index = 0; index < table_size(); index++) { 695 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { 696 Method* prop = p->method(); 697 if (prop != NULL) { 698 f((Method*)prop); 699 } 700 } 701 } 702} 703 704 705// ---------------------------------------------------------------------------- 706 707void Dictionary::print(bool details) { 708 ResourceMark rm; 709 HandleMark hm; 710 711 if (details) { 712 tty->print_cr("Java system dictionary (table_size=%d, classes=%d)", 713 table_size(), number_of_entries()); 714 tty->print_cr("^ indicates that initiating loader is different from " 715 "defining loader"); 716 } 717 718 for (int index = 0; index < table_size(); index++) { 719 for (DictionaryEntry* probe = bucket(index); 720 probe != NULL; 721 probe = probe->next()) { 722 if (Verbose) tty->print("%4d: ", index); 723 Klass* e = probe->klass(); 724 ClassLoaderData* loader_data = probe->loader_data(); 725 bool is_defining_class = 726 (loader_data == InstanceKlass::cast(e)->class_loader_data()); 727 tty->print("%s%s", ((!details) || is_defining_class) ? " " : "^", 728 e->external_name()); 729 730 if (details) { 731 tty->print(", loader "); 732 if (loader_data != NULL) { 733 loader_data->print_value(); 734 } else { 735 tty->print("NULL"); 736 } 737 } 738 tty->cr(); 739 } 740 } 741 742 if (details) { 743 tty->cr(); 744 _pd_cache_table->print(); 745 } 746 tty->cr(); 747} 748 749void Dictionary::verify() { 750 guarantee(number_of_entries() >= 0, "Verify of system dictionary failed"); 751 752 int element_count = 0; 753 for (int index = 0; index < table_size(); index++) { 754 for (DictionaryEntry* probe = bucket(index); 755 probe != NULL; 756 probe = probe->next()) { 757 Klass* e = probe->klass(); 758 ClassLoaderData* loader_data = probe->loader_data(); 759 guarantee(e->oop_is_instance(), 760 "Verify of system dictionary failed"); 761 // class loader must be present; a null class loader is the 762 // boostrap loader 763 guarantee(loader_data != NULL || DumpSharedSpaces || 764 loader_data->class_loader() == NULL || 765 loader_data->class_loader()->is_instance(), 766 "checking type of class_loader"); 767 e->verify(); 768 probe->verify_protection_domain_set(); 769 element_count++; 770 } 771 } 772 guarantee(number_of_entries() == element_count, 773 "Verify of system dictionary failed"); 774 debug_only(verify_lookup_length((double)number_of_entries() / table_size())); 775 776 _pd_cache_table->verify(); 777} 778 779