dictionary.cpp revision 3465:d2a62e0f25eb
161981Sbrian/* 261981Sbrian * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 361981Sbrian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 461981Sbrian * 561981Sbrian * This code is free software; you can redistribute it and/or modify it 661981Sbrian * under the terms of the GNU General Public License version 2 only, as 761981Sbrian * published by the Free Software Foundation. 861981Sbrian * 961981Sbrian * This code is distributed in the hope that it will be useful, but WITHOUT 1061981Sbrian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1161981Sbrian * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1261981Sbrian * version 2 for more details (a copy is included in the LICENSE file that 1361981Sbrian * accompanied this code). 1461981Sbrian * 1561981Sbrian * You should have received a copy of the GNU General Public License version 1661981Sbrian * 2 along with this work; if not, write to the Free Software Foundation, 1761981Sbrian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1861981Sbrian * 1961981Sbrian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2061981Sbrian * or visit www.oracle.com if you need additional information or have any 2161981Sbrian * questions. 2261981Sbrian * 2361981Sbrian */ 2461981Sbrian 2565843Sbrian#include "precompiled.hpp" 2665843Sbrian#include "classfile/dictionary.hpp" 2765843Sbrian#include "classfile/systemDictionary.hpp" 2865843Sbrian#include "oops/oop.inline.hpp" 2965843Sbrian#include "prims/jvmtiRedefineClassesTrace.hpp" 3065843Sbrian#include "services/classLoadingService.hpp" 3165843Sbrian#include "utilities/hashtable.inline.hpp" 3265843Sbrian 3365843Sbrian 3465843SbrianDictionaryEntry* Dictionary::_current_class_entry = NULL; 3561981Sbrianint Dictionary::_current_class_index = 0; 3661981Sbrian 3761981Sbrian 3861981SbrianDictionary::Dictionary(int table_size) 3961981Sbrian : TwoOopHashtable<klassOop, mtClass>(table_size, sizeof(DictionaryEntry)) { 4061981Sbrian _current_class_index = 0; 4161981Sbrian _current_class_entry = NULL; 4261981Sbrian}; 4361981Sbrian 4461981Sbrian 4561981Sbrian 4661981SbrianDictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t, 4761981Sbrian int number_of_entries) 4861981Sbrian : TwoOopHashtable<klassOop, mtClass>(table_size, sizeof(DictionaryEntry), t, number_of_entries) { 4961981Sbrian _current_class_index = 0; 5061981Sbrian _current_class_entry = NULL; 5161981Sbrian}; 5261981Sbrian 5361981Sbrian 5461981SbrianDictionaryEntry* Dictionary::new_entry(unsigned int hash, klassOop klass, 5561981Sbrian oop loader) { 5661981Sbrian DictionaryEntry* entry; 5761981Sbrian entry = (DictionaryEntry*)Hashtable<klassOop, mtClass>::new_entry(hash, klass); 5861981Sbrian entry->set_loader(loader); 5961981Sbrian entry->set_pd_set(NULL); 6061981Sbrian return entry; 6161981Sbrian} 6261981Sbrian 6361981Sbrian 6461981SbrianDictionaryEntry* Dictionary::new_entry() { 6561981Sbrian DictionaryEntry* entry = (DictionaryEntry*)Hashtable<klassOop, mtClass>::new_entry(0L, NULL); 6661981Sbrian entry->set_loader(NULL); 6761981Sbrian entry->set_pd_set(NULL); 6861981Sbrian return entry; 6961981Sbrian} 7061981Sbrian 7161981Sbrian 7261981Sbrianvoid Dictionary::free_entry(DictionaryEntry* entry) { 7361981Sbrian // avoid recursion when deleting linked list 7474314Sbrian while (entry->pd_set() != NULL) { 7561981Sbrian ProtectionDomainEntry* to_delete = entry->pd_set(); 7661981Sbrian entry->set_pd_set(to_delete->next()); 7761981Sbrian delete to_delete; 7861981Sbrian } 7961981Sbrian Hashtable<klassOop, mtClass>::free_entry(entry); 8061981Sbrian} 8162054Sbrian 8277496Sbrian 8377492Sbrianbool DictionaryEntry::contains_protection_domain(oop protection_domain) const { 8461981Sbrian#ifdef ASSERT 8561981Sbrian if (protection_domain == instanceKlass::cast(klass())->protection_domain()) { 8661981Sbrian // Ensure this doesn't show up in the pd_set (invariant) 8761981Sbrian bool in_pd_set = false; 8861981Sbrian for (ProtectionDomainEntry* current = _pd_set; 8961981Sbrian current != NULL; 9061981Sbrian current = current->next()) { 9161981Sbrian if (current->protection_domain() == protection_domain) { 9261981Sbrian in_pd_set = true; 9362644Ssheldonh break; 9461981Sbrian } 9561981Sbrian } 9661981Sbrian if (in_pd_set) { 9761981Sbrian assert(false, "A klass's protection domain should not show up " 9861981Sbrian "in its sys. dict. PD set"); 9961981Sbrian } 10061981Sbrian } 10161981Sbrian#endif /* ASSERT */ 10261981Sbrian 10361981Sbrian if (protection_domain == instanceKlass::cast(klass())->protection_domain()) { 10461981Sbrian // Succeeds trivially 10561981Sbrian return true; 10661981Sbrian } 10761981Sbrian 10887514Scjc for (ProtectionDomainEntry* current = _pd_set; 10961981Sbrian current != NULL; 11061981Sbrian current = current->next()) { 11161981Sbrian if (current->protection_domain() == protection_domain) return true; 11262274Sbrian } 11361981Sbrian return false; 11475809Sdirk} 11575809Sdirk 11675809Sdirk 11775809Sdirkvoid DictionaryEntry::add_protection_domain(oop protection_domain) { 11872677Speter assert_locked_or_safepoint(SystemDictionary_lock); 11972677Speter if (!contains_protection_domain(protection_domain)) { 12072677Speter ProtectionDomainEntry* new_head = 12161981Sbrian new ProtectionDomainEntry(protection_domain, _pd_set); 12261981Sbrian // Warning: Preserve store ordering. The SystemDictionary is read 12361981Sbrian // without locks. The new ProtectionDomainEntry must be 12461981Sbrian // complete before other threads can be allowed to see it 12587514Scjc // via a store to _pd_set. 12687514Scjc OrderAccess::release_store_ptr(&_pd_set, new_head); 12787514Scjc } 12887514Scjc if (TraceProtectionDomainVerification && WizardMode) { 12987514Scjc print(); 13087514Scjc } 13187514Scjc} 13287514Scjc 13387514Scjc 13487514Scjcbool Dictionary::do_unloading(BoolObjectClosure* is_alive) { 13587514Scjc assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 13687514Scjc bool class_was_unloaded = false; 13787514Scjc int index = 0; // Defined here for portability! Do not move 13887514Scjc 13987514Scjc // Remove unloadable entries and classes from system dictionary 14087514Scjc // The placeholder array has been handled in always_strong_oops_do. 14187514Scjc DictionaryEntry* probe = NULL; 14287514Scjc for (index = 0; index < table_size(); index++) { 14387514Scjc for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) { 14487514Scjc probe = *p; 14587514Scjc klassOop e = probe->klass(); 14687514Scjc oop class_loader = probe->loader(); 14787514Scjc 14887514Scjc instanceKlass* ik = instanceKlass::cast(e); 14987514Scjc if (ik->previous_versions() != NULL) { 15087514Scjc // This klass has previous versions so see what we can cleanup 15187514Scjc // while it is safe to do so. 15287514Scjc 15387514Scjc int gc_count = 0; // leave debugging breadcrumbs 15487514Scjc int live_count = 0; 15587514Scjc 15687514Scjc // RC_TRACE macro has an embedded ResourceMark 15787514Scjc RC_TRACE(0x00000200, ("unload: %s: previous version length=%d", 15887514Scjc ik->external_name(), ik->previous_versions()->length())); 15987514Scjc 16087514Scjc for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) { 16187514Scjc // check the previous versions array for GC'ed weak refs 16287514Scjc PreviousVersionNode * pv_node = ik->previous_versions()->at(i); 16387514Scjc jobject cp_ref = pv_node->prev_constant_pool(); 16487514Scjc assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); 16587514Scjc if (cp_ref == NULL) { 16687514Scjc delete pv_node; 16787514Scjc ik->previous_versions()->remove_at(i); 16887514Scjc // Since we are traversing the array backwards, we don't have to 16987514Scjc // do anything special with the index. 17061981Sbrian continue; // robustness 17161981Sbrian } 17265843Sbrian 17365843Sbrian constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref); 17465843Sbrian if (pvcp == NULL) { 17565843Sbrian // this entry has been GC'ed so remove it 17665843Sbrian delete pv_node; 17765843Sbrian ik->previous_versions()->remove_at(i); 17865843Sbrian // Since we are traversing the array backwards, we don't have to 17965843Sbrian // do anything special with the index. 18065843Sbrian gc_count++; 18165843Sbrian continue; 18261981Sbrian } else { 18361981Sbrian RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i)); 18461981Sbrian if (is_alive->do_object_b(pvcp)) { 18561981Sbrian live_count++; 18661981Sbrian } else { 18761981Sbrian guarantee(false, "sanity check"); 18861981Sbrian } 18961981Sbrian } 19061981Sbrian 19161981Sbrian GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); 19261981Sbrian if (method_refs != NULL) { 19361981Sbrian RC_TRACE(0x00000200, ("unload: previous methods length=%d", 19461981Sbrian method_refs->length())); 19561981Sbrian for (int j = method_refs->length() - 1; j >= 0; j--) { 19661981Sbrian jweak method_ref = method_refs->at(j); 19761981Sbrian assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); 19861981Sbrian if (method_ref == NULL) { 19961981Sbrian method_refs->remove_at(j); 20062206Sbrian // Since we are traversing the array backwards, we don't have to 20162155Sbrian // do anything special with the index. 20262155Sbrian continue; // robustness 20361981Sbrian } 20461981Sbrian 20561981Sbrian methodOop method = (methodOop)JNIHandles::resolve(method_ref); 20661981Sbrian if (method == NULL) { 20761981Sbrian // this method entry has been GC'ed so remove it 20861981Sbrian JNIHandles::destroy_weak_global(method_ref); 20965843Sbrian method_refs->remove_at(j); 21065843Sbrian } else { 21165843Sbrian // RC_TRACE macro has an embedded ResourceMark 21265843Sbrian RC_TRACE(0x00000200, 21365843Sbrian ("unload: %s(%s): prev method @%d in version @%d is alive", 21465843Sbrian method->name()->as_C_string(), 21565843Sbrian method->signature()->as_C_string(), j, i)); 21665843Sbrian } 21765843Sbrian } 21865843Sbrian } 21961981Sbrian } 22061981Sbrian assert(ik->previous_versions()->length() == live_count, "sanity check"); 22161981Sbrian RC_TRACE(0x00000200, 22261981Sbrian ("unload: previous version stats: live=%d, GC'ed=%d", live_count, 22361981Sbrian gc_count)); 22461981Sbrian } 22561981Sbrian 22661981Sbrian // Non-unloadable classes were handled in always_strong_oops_do 22761981Sbrian if (!is_strongly_reachable(class_loader, e)) { 22861981Sbrian // Entry was not visited in phase1 (negated test from phase1) 22961981Sbrian assert(class_loader != NULL, "unloading entry with null class loader"); 23061981Sbrian oop k_def_class_loader = ik->class_loader(); 23161981Sbrian 23261981Sbrian // Do we need to delete this system dictionary entry? 23361981Sbrian bool purge_entry = false; 23461981Sbrian 23561981Sbrian // Do we need to delete this system dictionary entry? 23661981Sbrian if (!is_alive->do_object_b(class_loader)) { 23761981Sbrian // If the loader is not live this entry should always be 23861981Sbrian // removed (will never be looked up again). Note that this is 23961981Sbrian // not the same as unloading the referred class. 24061981Sbrian if (k_def_class_loader == class_loader) { 24161981Sbrian // This is the defining entry, so the referred class is about 24261981Sbrian // to be unloaded. 24361981Sbrian // Notify the debugger and clean up the class. 24461981Sbrian guarantee(!is_alive->do_object_b(e), 24561981Sbrian "klass should not be live if defining loader is not"); 246 class_was_unloaded = true; 247 // notify the debugger 248 if (JvmtiExport::should_post_class_unload()) { 249 JvmtiExport::post_class_unload(ik->as_klassOop()); 250 } 251 252 // notify ClassLoadingService of class unload 253 ClassLoadingService::notify_class_unloaded(ik); 254 255 // Clean up C heap 256 ik->release_C_heap_structures(); 257 } 258 // Also remove this system dictionary entry. 259 purge_entry = true; 260 261 } else { 262 // The loader in this entry is alive. If the klass is dead, 263 // the loader must be an initiating loader (rather than the 264 // defining loader). Remove this entry. 265 if (!is_alive->do_object_b(e)) { 266 guarantee(!is_alive->do_object_b(k_def_class_loader), 267 "defining loader should not be live if klass is not"); 268 // If we get here, the class_loader must not be the defining 269 // loader, it must be an initiating one. 270 assert(k_def_class_loader != class_loader, 271 "cannot have live defining loader and unreachable klass"); 272 273 // Loader is live, but class and its defining loader are dead. 274 // Remove the entry. The class is going away. 275 purge_entry = true; 276 } 277 } 278 279 if (purge_entry) { 280 *p = probe->next(); 281 if (probe == _current_class_entry) { 282 _current_class_entry = NULL; 283 } 284 free_entry(probe); 285 continue; 286 } 287 } 288 p = probe->next_addr(); 289 } 290 } 291 return class_was_unloaded; 292} 293 294 295void Dictionary::always_strong_classes_do(OopClosure* blk) { 296 // Follow all system classes and temporary placeholders in dictionary 297 for (int index = 0; index < table_size(); index++) { 298 for (DictionaryEntry *probe = bucket(index); 299 probe != NULL; 300 probe = probe->next()) { 301 klassOop e = probe->klass(); 302 oop class_loader = probe->loader(); 303 if (is_strongly_reachable(class_loader, e)) { 304 blk->do_oop((oop*)probe->klass_addr()); 305 if (class_loader != NULL) { 306 blk->do_oop(probe->loader_addr()); 307 } 308 probe->protection_domain_set_oops_do(blk); 309 } 310 } 311 } 312} 313 314 315// Just the classes from defining class loaders 316void Dictionary::classes_do(void f(klassOop)) { 317 for (int index = 0; index < table_size(); index++) { 318 for (DictionaryEntry* probe = bucket(index); 319 probe != NULL; 320 probe = probe->next()) { 321 klassOop k = probe->klass(); 322 if (probe->loader() == instanceKlass::cast(k)->class_loader()) { 323 f(k); 324 } 325 } 326 } 327} 328 329// Added for initialize_itable_for_klass to handle exceptions 330// Just the classes from defining class loaders 331void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) { 332 for (int index = 0; index < table_size(); index++) { 333 for (DictionaryEntry* probe = bucket(index); 334 probe != NULL; 335 probe = probe->next()) { 336 klassOop k = probe->klass(); 337 if (probe->loader() == instanceKlass::cast(k)->class_loader()) { 338 f(k, CHECK); 339 } 340 } 341 } 342} 343 344 345// All classes, and their class loaders 346// (added for helpers that use HandleMarks and ResourceMarks) 347// Don't iterate over placeholders 348void Dictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) { 349 for (int index = 0; index < table_size(); index++) { 350 for (DictionaryEntry* probe = bucket(index); 351 probe != NULL; 352 probe = probe->next()) { 353 klassOop k = probe->klass(); 354 f(k, probe->loader(), CHECK); 355 } 356 } 357} 358 359 360// All classes, and their class loaders 361// Don't iterate over placeholders 362void Dictionary::classes_do(void f(klassOop, oop)) { 363 for (int index = 0; index < table_size(); index++) { 364 for (DictionaryEntry* probe = bucket(index); 365 probe != NULL; 366 probe = probe->next()) { 367 klassOop k = probe->klass(); 368 f(k, probe->loader()); 369 } 370 } 371} 372 373 374void Dictionary::oops_do(OopClosure* f) { 375 for (int index = 0; index < table_size(); index++) { 376 for (DictionaryEntry* probe = bucket(index); 377 probe != NULL; 378 probe = probe->next()) { 379 f->do_oop((oop*)probe->klass_addr()); 380 if (probe->loader() != NULL) { 381 f->do_oop(probe->loader_addr()); 382 } 383 probe->protection_domain_set_oops_do(f); 384 } 385 } 386} 387 388 389void Dictionary::methods_do(void f(methodOop)) { 390 for (int index = 0; index < table_size(); index++) { 391 for (DictionaryEntry* probe = bucket(index); 392 probe != NULL; 393 probe = probe->next()) { 394 klassOop k = probe->klass(); 395 if (probe->loader() == instanceKlass::cast(k)->class_loader()) { 396 // only take klass is we have the entry with the defining class loader 397 instanceKlass::cast(k)->methods_do(f); 398 } 399 } 400 } 401} 402 403 404klassOop Dictionary::try_get_next_class() { 405 while (true) { 406 if (_current_class_entry != NULL) { 407 klassOop k = _current_class_entry->klass(); 408 _current_class_entry = _current_class_entry->next(); 409 return k; 410 } 411 _current_class_index = (_current_class_index + 1) % table_size(); 412 _current_class_entry = bucket(_current_class_index); 413 } 414 // never reached 415} 416 417 418// Add a loaded class to the system dictionary. 419// Readers of the SystemDictionary aren't always locked, so _buckets 420// is volatile. The store of the next field in the constructor is 421// also cast to volatile; we do this to ensure store order is maintained 422// by the compilers. 423 424void Dictionary::add_klass(Symbol* class_name, Handle class_loader, 425 KlassHandle obj) { 426 assert_locked_or_safepoint(SystemDictionary_lock); 427 assert(obj() != NULL, "adding NULL obj"); 428 assert(Klass::cast(obj())->name() == class_name, "sanity check on name"); 429 430 unsigned int hash = compute_hash(class_name, class_loader); 431 int index = hash_to_index(hash); 432 DictionaryEntry* entry = new_entry(hash, obj(), class_loader()); 433 add_entry(index, entry); 434} 435 436 437// This routine does not lock the system dictionary. 438// 439// Since readers don't hold a lock, we must make sure that system 440// dictionary entries are only removed at a safepoint (when only one 441// thread is running), and are added to in a safe way (all links must 442// be updated in an MT-safe manner). 443// 444// Callers should be aware that an entry could be added just after 445// _buckets[index] is read here, so the caller will not see the new entry. 446DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash, 447 Symbol* class_name, 448 Handle class_loader) { 449 oop loader = class_loader(); 450 debug_only(_lookup_count++); 451 for (DictionaryEntry* entry = bucket(index); 452 entry != NULL; 453 entry = entry->next()) { 454 if (entry->hash() == hash && entry->equals(class_name, loader)) { 455 return entry; 456 } 457 debug_only(_lookup_length++); 458 } 459 return NULL; 460} 461 462 463klassOop Dictionary::find(int index, unsigned int hash, Symbol* name, 464 Handle loader, Handle protection_domain, TRAPS) { 465 DictionaryEntry* entry = get_entry(index, hash, name, loader); 466 if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) { 467 return entry->klass(); 468 } else { 469 return NULL; 470 } 471} 472 473 474klassOop Dictionary::find_class(int index, unsigned int hash, 475 Symbol* name, Handle loader) { 476 assert_locked_or_safepoint(SystemDictionary_lock); 477 assert (index == index_for(name, loader), "incorrect index?"); 478 479 DictionaryEntry* entry = get_entry(index, hash, name, loader); 480 return (entry != NULL) ? entry->klass() : (klassOop)NULL; 481} 482 483 484// Variant of find_class for shared classes. No locking required, as 485// that table is static. 486 487klassOop Dictionary::find_shared_class(int index, unsigned int hash, 488 Symbol* name) { 489 assert (index == index_for(name, Handle()), "incorrect index?"); 490 491 DictionaryEntry* entry = get_entry(index, hash, name, Handle()); 492 return (entry != NULL) ? entry->klass() : (klassOop)NULL; 493} 494 495 496void Dictionary::add_protection_domain(int index, unsigned int hash, 497 instanceKlassHandle klass, 498 Handle loader, Handle protection_domain, 499 TRAPS) { 500 Symbol* klass_name = klass->name(); 501 DictionaryEntry* entry = get_entry(index, hash, klass_name, loader); 502 503 assert(entry != NULL,"entry must be present, we just created it"); 504 assert(protection_domain() != NULL, 505 "real protection domain should be present"); 506 507 entry->add_protection_domain(protection_domain()); 508 509 assert(entry->contains_protection_domain(protection_domain()), 510 "now protection domain should be present"); 511} 512 513 514bool Dictionary::is_valid_protection_domain(int index, unsigned int hash, 515 Symbol* name, 516 Handle loader, 517 Handle protection_domain) { 518 DictionaryEntry* entry = get_entry(index, hash, name, loader); 519 return entry->is_valid_protection_domain(protection_domain); 520} 521 522 523void Dictionary::reorder_dictionary() { 524 525 // Copy all the dictionary entries into a single master list. 526 527 DictionaryEntry* master_list = NULL; 528 for (int i = 0; i < table_size(); ++i) { 529 DictionaryEntry* p = bucket(i); 530 while (p != NULL) { 531 DictionaryEntry* tmp; 532 tmp = p->next(); 533 p->set_next(master_list); 534 master_list = p; 535 p = tmp; 536 } 537 set_entry(i, NULL); 538 } 539 540 // Add the dictionary entries back to the list in the correct buckets. 541 Thread *thread = Thread::current(); 542 543 while (master_list != NULL) { 544 DictionaryEntry* p = master_list; 545 master_list = master_list->next(); 546 p->set_next(NULL); 547 Symbol* class_name = instanceKlass::cast((klassOop)(p->klass()))->name(); 548 unsigned int hash = compute_hash(class_name, Handle(thread, p->loader())); 549 int index = hash_to_index(hash); 550 p->set_hash(hash); 551 p->set_next(bucket(index)); 552 set_entry(index, p); 553 } 554} 555 556SymbolPropertyTable::SymbolPropertyTable(int table_size) 557 : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry)) 558{ 559} 560SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t, 561 int number_of_entries) 562 : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries) 563{ 564} 565 566 567SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash, 568 Symbol* sym, 569 intptr_t sym_mode) { 570 assert(index == index_for(sym, sym_mode), "incorrect index?"); 571 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { 572 if (p->hash() == hash && p->symbol() == sym && p->symbol_mode() == sym_mode) { 573 return p; 574 } 575 } 576 return NULL; 577} 578 579 580SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash, 581 Symbol* sym, intptr_t sym_mode) { 582 assert_locked_or_safepoint(SystemDictionary_lock); 583 assert(index == index_for(sym, sym_mode), "incorrect index?"); 584 assert(find_entry(index, hash, sym, sym_mode) == NULL, "no double entry"); 585 586 SymbolPropertyEntry* p = new_entry(hash, sym, sym_mode); 587 Hashtable<Symbol*, mtSymbol>::add_entry(index, p); 588 return p; 589} 590 591 592void SymbolPropertyTable::oops_do(OopClosure* f) { 593 for (int index = 0; index < table_size(); index++) { 594 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { 595 if (p->property_oop() != NULL) { 596 f->do_oop(p->property_oop_addr()); 597 } 598 } 599 } 600} 601 602void SymbolPropertyTable::methods_do(void f(methodOop)) { 603 for (int index = 0; index < table_size(); index++) { 604 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { 605 oop prop = p->property_oop(); 606 if (prop != NULL && prop->is_method()) { 607 f((methodOop)prop); 608 } 609 } 610 } 611} 612 613 614// ---------------------------------------------------------------------------- 615#ifndef PRODUCT 616 617void Dictionary::print() { 618 ResourceMark rm; 619 HandleMark hm; 620 621 tty->print_cr("Java system dictionary (table_size=%d, classes=%d)", 622 table_size(), number_of_entries()); 623 tty->print_cr("^ indicates that initiating loader is different from " 624 "defining loader"); 625 626 for (int index = 0; index < table_size(); index++) { 627 for (DictionaryEntry* probe = bucket(index); 628 probe != NULL; 629 probe = probe->next()) { 630 if (Verbose) tty->print("%4d: ", index); 631 klassOop e = probe->klass(); 632 oop class_loader = probe->loader(); 633 bool is_defining_class = 634 (class_loader == instanceKlass::cast(e)->class_loader()); 635 tty->print("%s%s", is_defining_class ? " " : "^", 636 Klass::cast(e)->external_name()); 637 if (class_loader != NULL) { 638 tty->print(", loader "); 639 class_loader->print_value(); 640 } 641 tty->cr(); 642 } 643 } 644} 645 646#endif 647 648void Dictionary::verify() { 649 guarantee(number_of_entries() >= 0, "Verify of system dictionary failed"); 650 int element_count = 0; 651 for (int index = 0; index < table_size(); index++) { 652 for (DictionaryEntry* probe = bucket(index); 653 probe != NULL; 654 probe = probe->next()) { 655 klassOop e = probe->klass(); 656 oop class_loader = probe->loader(); 657 guarantee(Klass::cast(e)->oop_is_instance(), 658 "Verify of system dictionary failed"); 659 // class loader must be present; a null class loader is the 660 // boostrap loader 661 guarantee(class_loader == NULL || class_loader->is_instance(), 662 "checking type of class_loader"); 663 e->verify(); 664 probe->verify_protection_domain_set(); 665 element_count++; 666 } 667 } 668 guarantee(number_of_entries() == element_count, 669 "Verify of system dictionary failed"); 670 debug_only(verify_lookup_length((double)number_of_entries() / table_size())); 671} 672