src/share/vm/classfile/dictionary.cpp

Thu, 21 Feb 2013 17:22:15 +0100

author
stefank
date
Thu, 21 Feb 2013 17:22:15 +0100
changeset 4667
1f9994892f89
parent 4304
90273fc0a981
child 4981
d587a5c30bd8
permissions
-rw-r--r--

8008549: NPG: SystemDictionary::find(...) unnecessarily keeps class loaders alive
Summary: SystemDictionary::find(...) should not create and register ClassLoaderData objects for class loaders.
Reviewed-by: coleenp, acorn
Contributed-by: Stefan Karlsson <stefan.karlsson@oracle.com>, Erik Helin <erik.helin@oracle.com>

duke@435 1 /*
acorn@3491 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/dictionary.hpp"
stefank@2314 27 #include "classfile/systemDictionary.hpp"
stefank@2314 28 #include "oops/oop.inline.hpp"
stefank@2314 29 #include "prims/jvmtiRedefineClassesTrace.hpp"
stefank@2314 30 #include "services/classLoadingService.hpp"
stefank@2314 31 #include "utilities/hashtable.inline.hpp"
duke@435 32
duke@435 33
duke@435 34 DictionaryEntry* Dictionary::_current_class_entry = NULL;
duke@435 35 int Dictionary::_current_class_index = 0;
duke@435 36
duke@435 37
duke@435 38 Dictionary::Dictionary(int table_size)
coleenp@4037 39 : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry)) {
duke@435 40 _current_class_index = 0;
duke@435 41 _current_class_entry = NULL;
duke@435 42 };
duke@435 43
duke@435 44
duke@435 45
zgu@3900 46 Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t,
duke@435 47 int number_of_entries)
coleenp@4037 48 : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry), t, number_of_entries) {
duke@435 49 _current_class_index = 0;
duke@435 50 _current_class_entry = NULL;
duke@435 51 };
duke@435 52
duke@435 53
coleenp@4037 54 DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass,
coleenp@4037 55 ClassLoaderData* loader_data) {
coleenp@4037 56 DictionaryEntry* entry = (DictionaryEntry*)Hashtable<Klass*, mtClass>::new_entry(hash, klass);
coleenp@4037 57 entry->set_loader_data(loader_data);
duke@435 58 entry->set_pd_set(NULL);
coleenp@4037 59 assert(klass->oop_is_instance(), "Must be");
duke@435 60 return entry;
duke@435 61 }
duke@435 62
duke@435 63
duke@435 64 void Dictionary::free_entry(DictionaryEntry* entry) {
duke@435 65 // avoid recursion when deleting linked list
duke@435 66 while (entry->pd_set() != NULL) {
duke@435 67 ProtectionDomainEntry* to_delete = entry->pd_set();
duke@435 68 entry->set_pd_set(to_delete->next());
duke@435 69 delete to_delete;
duke@435 70 }
coleenp@4037 71 Hashtable<Klass*, mtClass>::free_entry(entry);
duke@435 72 }
duke@435 73
duke@435 74
duke@435 75 bool DictionaryEntry::contains_protection_domain(oop protection_domain) const {
duke@435 76 #ifdef ASSERT
coleenp@4037 77 if (protection_domain == InstanceKlass::cast(klass())->protection_domain()) {
duke@435 78 // Ensure this doesn't show up in the pd_set (invariant)
duke@435 79 bool in_pd_set = false;
duke@435 80 for (ProtectionDomainEntry* current = _pd_set;
duke@435 81 current != NULL;
duke@435 82 current = current->next()) {
duke@435 83 if (current->protection_domain() == protection_domain) {
duke@435 84 in_pd_set = true;
duke@435 85 break;
duke@435 86 }
duke@435 87 }
duke@435 88 if (in_pd_set) {
duke@435 89 assert(false, "A klass's protection domain should not show up "
duke@435 90 "in its sys. dict. PD set");
duke@435 91 }
duke@435 92 }
duke@435 93 #endif /* ASSERT */
duke@435 94
coleenp@4037 95 if (protection_domain == InstanceKlass::cast(klass())->protection_domain()) {
duke@435 96 // Succeeds trivially
duke@435 97 return true;
duke@435 98 }
duke@435 99
duke@435 100 for (ProtectionDomainEntry* current = _pd_set;
duke@435 101 current != NULL;
duke@435 102 current = current->next()) {
duke@435 103 if (current->protection_domain() == protection_domain) return true;
duke@435 104 }
duke@435 105 return false;
duke@435 106 }
duke@435 107
duke@435 108
duke@435 109 void DictionaryEntry::add_protection_domain(oop protection_domain) {
duke@435 110 assert_locked_or_safepoint(SystemDictionary_lock);
duke@435 111 if (!contains_protection_domain(protection_domain)) {
duke@435 112 ProtectionDomainEntry* new_head =
duke@435 113 new ProtectionDomainEntry(protection_domain, _pd_set);
duke@435 114 // Warning: Preserve store ordering. The SystemDictionary is read
duke@435 115 // without locks. The new ProtectionDomainEntry must be
duke@435 116 // complete before other threads can be allowed to see it
duke@435 117 // via a store to _pd_set.
duke@435 118 OrderAccess::release_store_ptr(&_pd_set, new_head);
duke@435 119 }
duke@435 120 if (TraceProtectionDomainVerification && WizardMode) {
duke@435 121 print();
duke@435 122 }
duke@435 123 }
duke@435 124
duke@435 125
coleenp@4037 126 bool Dictionary::do_unloading() {
jcoomes@1844 127 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
duke@435 128 bool class_was_unloaded = false;
duke@435 129 int index = 0; // Defined here for portability! Do not move
duke@435 130
duke@435 131 // Remove unloadable entries and classes from system dictionary
duke@435 132 // The placeholder array has been handled in always_strong_oops_do.
duke@435 133 DictionaryEntry* probe = NULL;
duke@435 134 for (index = 0; index < table_size(); index++) {
duke@435 135 for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
duke@435 136 probe = *p;
coleenp@4037 137 Klass* e = probe->klass();
coleenp@4037 138 ClassLoaderData* loader_data = probe->loader_data();
duke@435 139
coleenp@4037 140 InstanceKlass* ik = InstanceKlass::cast(e);
duke@435 141
duke@435 142 // Non-unloadable classes were handled in always_strong_oops_do
coleenp@4037 143 if (!is_strongly_reachable(loader_data, e)) {
duke@435 144 // Entry was not visited in phase1 (negated test from phase1)
coleenp@4037 145 assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader");
coleenp@4037 146 ClassLoaderData* k_def_class_loader_data = ik->class_loader_data();
duke@435 147
duke@435 148 // Do we need to delete this system dictionary entry?
duke@435 149 bool purge_entry = false;
duke@435 150
duke@435 151 // Do we need to delete this system dictionary entry?
coleenp@4037 152 if (loader_data->is_unloading()) {
duke@435 153 // If the loader is not live this entry should always be
duke@435 154 // removed (will never be looked up again). Note that this is
duke@435 155 // not the same as unloading the referred class.
coleenp@4037 156 if (k_def_class_loader_data == loader_data) {
duke@435 157 // This is the defining entry, so the referred class is about
duke@435 158 // to be unloaded.
duke@435 159 // Notify the debugger and clean up the class.
duke@435 160 class_was_unloaded = true;
duke@435 161 // notify the debugger
duke@435 162 if (JvmtiExport::should_post_class_unload()) {
coleenp@4037 163 JvmtiExport::post_class_unload(ik);
duke@435 164 }
duke@435 165
duke@435 166 // notify ClassLoadingService of class unload
duke@435 167 ClassLoadingService::notify_class_unloaded(ik);
duke@435 168
duke@435 169 // Clean up C heap
duke@435 170 ik->release_C_heap_structures();
coleenp@4037 171 ik->constants()->release_C_heap_structures();
duke@435 172 }
duke@435 173 // Also remove this system dictionary entry.
duke@435 174 purge_entry = true;
duke@435 175
duke@435 176 } else {
duke@435 177 // The loader in this entry is alive. If the klass is dead,
coleenp@4037 178 // (determined by checking the defining class loader)
duke@435 179 // the loader must be an initiating loader (rather than the
duke@435 180 // defining loader). Remove this entry.
coleenp@4037 181 if (k_def_class_loader_data->is_unloading()) {
coleenp@4037 182 // If we get here, the class_loader_data must not be the defining
duke@435 183 // loader, it must be an initiating one.
coleenp@4037 184 assert(k_def_class_loader_data != loader_data,
duke@435 185 "cannot have live defining loader and unreachable klass");
duke@435 186 // Loader is live, but class and its defining loader are dead.
duke@435 187 // Remove the entry. The class is going away.
duke@435 188 purge_entry = true;
duke@435 189 }
duke@435 190 }
duke@435 191
duke@435 192 if (purge_entry) {
duke@435 193 *p = probe->next();
duke@435 194 if (probe == _current_class_entry) {
duke@435 195 _current_class_entry = NULL;
duke@435 196 }
duke@435 197 free_entry(probe);
duke@435 198 continue;
duke@435 199 }
duke@435 200 }
duke@435 201 p = probe->next_addr();
duke@435 202 }
duke@435 203 }
duke@435 204 return class_was_unloaded;
duke@435 205 }
duke@435 206
duke@435 207
coleenp@4037 208 void Dictionary::always_strong_oops_do(OopClosure* blk) {
duke@435 209 // Follow all system classes and temporary placeholders in dictionary
duke@435 210 for (int index = 0; index < table_size(); index++) {
duke@435 211 for (DictionaryEntry *probe = bucket(index);
duke@435 212 probe != NULL;
duke@435 213 probe = probe->next()) {
coleenp@4037 214 Klass* e = probe->klass();
coleenp@4037 215 ClassLoaderData* loader_data = probe->loader_data();
coleenp@4037 216 if (is_strongly_reachable(loader_data, e)) {
duke@435 217 probe->protection_domain_set_oops_do(blk);
duke@435 218 }
duke@435 219 }
duke@435 220 }
duke@435 221 }
duke@435 222
duke@435 223
coleenp@4037 224 void Dictionary::always_strong_classes_do(KlassClosure* closure) {
coleenp@4037 225 // Follow all system classes and temporary placeholders in dictionary
duke@435 226 for (int index = 0; index < table_size(); index++) {
duke@435 227 for (DictionaryEntry* probe = bucket(index);
duke@435 228 probe != NULL;
duke@435 229 probe = probe->next()) {
coleenp@4037 230 Klass* e = probe->klass();
coleenp@4037 231 ClassLoaderData* loader_data = probe->loader_data();
coleenp@4037 232 if (is_strongly_reachable(loader_data, e)) {
coleenp@4037 233 closure->do_klass(e);
coleenp@4037 234 }
coleenp@4037 235 }
coleenp@4037 236 }
coleenp@4037 237 }
coleenp@4037 238
coleenp@4037 239
coleenp@4037 240 // Just the classes from defining class loaders
coleenp@4037 241 void Dictionary::classes_do(void f(Klass*)) {
coleenp@4037 242 for (int index = 0; index < table_size(); index++) {
coleenp@4037 243 for (DictionaryEntry* probe = bucket(index);
coleenp@4037 244 probe != NULL;
coleenp@4037 245 probe = probe->next()) {
coleenp@4037 246 Klass* k = probe->klass();
coleenp@4037 247 if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) {
duke@435 248 f(k);
duke@435 249 }
duke@435 250 }
duke@435 251 }
duke@435 252 }
duke@435 253
duke@435 254 // Added for initialize_itable_for_klass to handle exceptions
duke@435 255 // Just the classes from defining class loaders
coleenp@4037 256 void Dictionary::classes_do(void f(Klass*, TRAPS), TRAPS) {
duke@435 257 for (int index = 0; index < table_size(); index++) {
duke@435 258 for (DictionaryEntry* probe = bucket(index);
duke@435 259 probe != NULL;
duke@435 260 probe = probe->next()) {
coleenp@4037 261 Klass* k = probe->klass();
coleenp@4037 262 if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) {
duke@435 263 f(k, CHECK);
duke@435 264 }
duke@435 265 }
duke@435 266 }
duke@435 267 }
duke@435 268
duke@435 269
duke@435 270 // All classes, and their class loaders
duke@435 271 // (added for helpers that use HandleMarks and ResourceMarks)
duke@435 272 // Don't iterate over placeholders
coleenp@4037 273 void Dictionary::classes_do(void f(Klass*, ClassLoaderData*, TRAPS), TRAPS) {
duke@435 274 for (int index = 0; index < table_size(); index++) {
duke@435 275 for (DictionaryEntry* probe = bucket(index);
duke@435 276 probe != NULL;
duke@435 277 probe = probe->next()) {
coleenp@4037 278 Klass* k = probe->klass();
coleenp@4037 279 f(k, probe->loader_data(), CHECK);
duke@435 280 }
duke@435 281 }
duke@435 282 }
duke@435 283
duke@435 284
duke@435 285 // All classes, and their class loaders
duke@435 286 // Don't iterate over placeholders
coleenp@4037 287 void Dictionary::classes_do(void f(Klass*, ClassLoaderData*)) {
duke@435 288 for (int index = 0; index < table_size(); index++) {
duke@435 289 for (DictionaryEntry* probe = bucket(index);
duke@435 290 probe != NULL;
duke@435 291 probe = probe->next()) {
coleenp@4037 292 Klass* k = probe->klass();
coleenp@4037 293 f(k, probe->loader_data());
duke@435 294 }
duke@435 295 }
duke@435 296 }
duke@435 297
duke@435 298
duke@435 299 void Dictionary::oops_do(OopClosure* f) {
duke@435 300 for (int index = 0; index < table_size(); index++) {
duke@435 301 for (DictionaryEntry* probe = bucket(index);
duke@435 302 probe != NULL;
duke@435 303 probe = probe->next()) {
duke@435 304 probe->protection_domain_set_oops_do(f);
duke@435 305 }
duke@435 306 }
duke@435 307 }
duke@435 308
duke@435 309
coleenp@4037 310 void Dictionary::methods_do(void f(Method*)) {
duke@435 311 for (int index = 0; index < table_size(); index++) {
duke@435 312 for (DictionaryEntry* probe = bucket(index);
duke@435 313 probe != NULL;
duke@435 314 probe = probe->next()) {
coleenp@4037 315 Klass* k = probe->klass();
coleenp@4037 316 if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) {
duke@435 317 // only take klass is we have the entry with the defining class loader
coleenp@4037 318 InstanceKlass::cast(k)->methods_do(f);
duke@435 319 }
duke@435 320 }
duke@435 321 }
duke@435 322 }
duke@435 323
duke@435 324
coleenp@4037 325 Klass* Dictionary::try_get_next_class() {
duke@435 326 while (true) {
duke@435 327 if (_current_class_entry != NULL) {
coleenp@4037 328 Klass* k = _current_class_entry->klass();
duke@435 329 _current_class_entry = _current_class_entry->next();
duke@435 330 return k;
duke@435 331 }
duke@435 332 _current_class_index = (_current_class_index + 1) % table_size();
duke@435 333 _current_class_entry = bucket(_current_class_index);
duke@435 334 }
duke@435 335 // never reached
duke@435 336 }
duke@435 337
duke@435 338
duke@435 339 // Add a loaded class to the system dictionary.
duke@435 340 // Readers of the SystemDictionary aren't always locked, so _buckets
duke@435 341 // is volatile. The store of the next field in the constructor is
duke@435 342 // also cast to volatile; we do this to ensure store order is maintained
duke@435 343 // by the compilers.
duke@435 344
coleenp@4037 345 void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data,
duke@435 346 KlassHandle obj) {
duke@435 347 assert_locked_or_safepoint(SystemDictionary_lock);
duke@435 348 assert(obj() != NULL, "adding NULL obj");
hseigel@4278 349 assert(obj()->name() == class_name, "sanity check on name");
stefank@4667 350 assert(loader_data != NULL, "Must be non-NULL");
duke@435 351
coleenp@4037 352 unsigned int hash = compute_hash(class_name, loader_data);
duke@435 353 int index = hash_to_index(hash);
coleenp@4037 354 DictionaryEntry* entry = new_entry(hash, obj(), loader_data);
duke@435 355 add_entry(index, entry);
duke@435 356 }
duke@435 357
duke@435 358
duke@435 359 // This routine does not lock the system dictionary.
duke@435 360 //
duke@435 361 // Since readers don't hold a lock, we must make sure that system
duke@435 362 // dictionary entries are only removed at a safepoint (when only one
duke@435 363 // thread is running), and are added to in a safe way (all links must
duke@435 364 // be updated in an MT-safe manner).
duke@435 365 //
duke@435 366 // Callers should be aware that an entry could be added just after
duke@435 367 // _buckets[index] is read here, so the caller will not see the new entry.
duke@435 368 DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
coleenp@2497 369 Symbol* class_name,
coleenp@4037 370 ClassLoaderData* loader_data) {
duke@435 371 debug_only(_lookup_count++);
duke@435 372 for (DictionaryEntry* entry = bucket(index);
duke@435 373 entry != NULL;
duke@435 374 entry = entry->next()) {
coleenp@4037 375 if (entry->hash() == hash && entry->equals(class_name, loader_data)) {
duke@435 376 return entry;
duke@435 377 }
duke@435 378 debug_only(_lookup_length++);
duke@435 379 }
duke@435 380 return NULL;
duke@435 381 }
duke@435 382
duke@435 383
coleenp@4037 384 Klass* Dictionary::find(int index, unsigned int hash, Symbol* name,
coleenp@4037 385 ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
coleenp@4037 386 DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
duke@435 387 if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
duke@435 388 return entry->klass();
duke@435 389 } else {
duke@435 390 return NULL;
duke@435 391 }
duke@435 392 }
duke@435 393
duke@435 394
coleenp@4037 395 Klass* Dictionary::find_class(int index, unsigned int hash,
coleenp@4037 396 Symbol* name, ClassLoaderData* loader_data) {
duke@435 397 assert_locked_or_safepoint(SystemDictionary_lock);
coleenp@4037 398 assert (index == index_for(name, loader_data), "incorrect index?");
duke@435 399
coleenp@4037 400 DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
coleenp@4037 401 return (entry != NULL) ? entry->klass() : (Klass*)NULL;
duke@435 402 }
duke@435 403
duke@435 404
duke@435 405 // Variant of find_class for shared classes. No locking required, as
duke@435 406 // that table is static.
duke@435 407
coleenp@4037 408 Klass* Dictionary::find_shared_class(int index, unsigned int hash,
coleenp@2497 409 Symbol* name) {
coleenp@4037 410 assert (index == index_for(name, NULL), "incorrect index?");
duke@435 411
coleenp@4037 412 DictionaryEntry* entry = get_entry(index, hash, name, NULL);
coleenp@4037 413 return (entry != NULL) ? entry->klass() : (Klass*)NULL;
duke@435 414 }
duke@435 415
duke@435 416
duke@435 417 void Dictionary::add_protection_domain(int index, unsigned int hash,
duke@435 418 instanceKlassHandle klass,
coleenp@4037 419 ClassLoaderData* loader_data, Handle protection_domain,
duke@435 420 TRAPS) {
coleenp@2497 421 Symbol* klass_name = klass->name();
coleenp@4037 422 DictionaryEntry* entry = get_entry(index, hash, klass_name, loader_data);
duke@435 423
duke@435 424 assert(entry != NULL,"entry must be present, we just created it");
duke@435 425 assert(protection_domain() != NULL,
duke@435 426 "real protection domain should be present");
duke@435 427
duke@435 428 entry->add_protection_domain(protection_domain());
duke@435 429
duke@435 430 assert(entry->contains_protection_domain(protection_domain()),
duke@435 431 "now protection domain should be present");
duke@435 432 }
duke@435 433
duke@435 434
duke@435 435 bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
coleenp@2497 436 Symbol* name,
coleenp@4037 437 ClassLoaderData* loader_data,
duke@435 438 Handle protection_domain) {
coleenp@4037 439 DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
duke@435 440 return entry->is_valid_protection_domain(protection_domain);
duke@435 441 }
duke@435 442
duke@435 443
duke@435 444 void Dictionary::reorder_dictionary() {
duke@435 445
duke@435 446 // Copy all the dictionary entries into a single master list.
duke@435 447
duke@435 448 DictionaryEntry* master_list = NULL;
duke@435 449 for (int i = 0; i < table_size(); ++i) {
duke@435 450 DictionaryEntry* p = bucket(i);
duke@435 451 while (p != NULL) {
duke@435 452 DictionaryEntry* tmp;
duke@435 453 tmp = p->next();
duke@435 454 p->set_next(master_list);
duke@435 455 master_list = p;
duke@435 456 p = tmp;
duke@435 457 }
duke@435 458 set_entry(i, NULL);
duke@435 459 }
duke@435 460
duke@435 461 // Add the dictionary entries back to the list in the correct buckets.
duke@435 462 while (master_list != NULL) {
duke@435 463 DictionaryEntry* p = master_list;
duke@435 464 master_list = master_list->next();
duke@435 465 p->set_next(NULL);
coleenp@4037 466 Symbol* class_name = InstanceKlass::cast((Klass*)(p->klass()))->name();
coleenp@4037 467 // Since the null class loader data isn't copied to the CDS archive,
coleenp@4037 468 // compute the hash with NULL for loader data.
coleenp@4037 469 unsigned int hash = compute_hash(class_name, NULL);
duke@435 470 int index = hash_to_index(hash);
duke@435 471 p->set_hash(hash);
coleenp@4037 472 p->set_loader_data(NULL); // loader_data isn't copied to CDS
duke@435 473 p->set_next(bucket(index));
duke@435 474 set_entry(index, p);
duke@435 475 }
duke@435 476 }
duke@435 477
jrose@1145 478 SymbolPropertyTable::SymbolPropertyTable(int table_size)
zgu@3900 479 : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry))
jrose@1145 480 {
jrose@1145 481 }
zgu@3900 482 SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t,
jrose@1145 483 int number_of_entries)
zgu@3900 484 : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries)
jrose@1145 485 {
jrose@1145 486 }
jrose@1145 487
jrose@1145 488
jrose@1145 489 SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash,
coleenp@2497 490 Symbol* sym,
jrose@1862 491 intptr_t sym_mode) {
jrose@1862 492 assert(index == index_for(sym, sym_mode), "incorrect index?");
jrose@1145 493 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
coleenp@2497 494 if (p->hash() == hash && p->symbol() == sym && p->symbol_mode() == sym_mode) {
jrose@1145 495 return p;
jrose@1145 496 }
jrose@1145 497 }
jrose@1145 498 return NULL;
jrose@1145 499 }
jrose@1145 500
jrose@1145 501
jrose@1145 502 SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash,
coleenp@2497 503 Symbol* sym, intptr_t sym_mode) {
jrose@1145 504 assert_locked_or_safepoint(SystemDictionary_lock);
jrose@1862 505 assert(index == index_for(sym, sym_mode), "incorrect index?");
jrose@1862 506 assert(find_entry(index, hash, sym, sym_mode) == NULL, "no double entry");
jrose@1145 507
coleenp@2497 508 SymbolPropertyEntry* p = new_entry(hash, sym, sym_mode);
zgu@3900 509 Hashtable<Symbol*, mtSymbol>::add_entry(index, p);
jrose@1145 510 return p;
jrose@1145 511 }
jrose@1145 512
jrose@1145 513 void SymbolPropertyTable::oops_do(OopClosure* f) {
jrose@1145 514 for (int index = 0; index < table_size(); index++) {
jrose@1145 515 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
coleenp@4037 516 if (p->method_type() != NULL) {
coleenp@4037 517 f->do_oop(p->method_type_addr());
jrose@1145 518 }
jrose@1145 519 }
jrose@1145 520 }
jrose@1145 521 }
jrose@1145 522
coleenp@4037 523 void SymbolPropertyTable::methods_do(void f(Method*)) {
jrose@1145 524 for (int index = 0; index < table_size(); index++) {
jrose@1145 525 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
coleenp@4037 526 Method* prop = p->method();
coleenp@4037 527 if (prop != NULL) {
coleenp@4037 528 f((Method*)prop);
jrose@1145 529 }
jrose@1145 530 }
jrose@1145 531 }
jrose@1145 532 }
jrose@1145 533
duke@435 534
duke@435 535 // ----------------------------------------------------------------------------
duke@435 536 #ifndef PRODUCT
duke@435 537
duke@435 538 void Dictionary::print() {
duke@435 539 ResourceMark rm;
duke@435 540 HandleMark hm;
duke@435 541
acorn@3491 542 tty->print_cr("Java system dictionary (table_size=%d, classes=%d)",
acorn@3491 543 table_size(), number_of_entries());
duke@435 544 tty->print_cr("^ indicates that initiating loader is different from "
duke@435 545 "defining loader");
duke@435 546
duke@435 547 for (int index = 0; index < table_size(); index++) {
duke@435 548 for (DictionaryEntry* probe = bucket(index);
duke@435 549 probe != NULL;
duke@435 550 probe = probe->next()) {
duke@435 551 if (Verbose) tty->print("%4d: ", index);
coleenp@4037 552 Klass* e = probe->klass();
coleenp@4037 553 ClassLoaderData* loader_data = probe->loader_data();
duke@435 554 bool is_defining_class =
coleenp@4037 555 (loader_data == InstanceKlass::cast(e)->class_loader_data());
duke@435 556 tty->print("%s%s", is_defining_class ? " " : "^",
hseigel@4278 557 e->external_name());
coleenp@4037 558
duke@435 559 tty->print(", loader ");
coleenp@4037 560 loader_data->print_value();
duke@435 561 tty->cr();
duke@435 562 }
duke@435 563 }
duke@435 564 }
duke@435 565
duke@435 566 #endif
duke@435 567
coleenp@4037 568
duke@435 569 void Dictionary::verify() {
duke@435 570 guarantee(number_of_entries() >= 0, "Verify of system dictionary failed");
coleenp@4037 571
duke@435 572 int element_count = 0;
duke@435 573 for (int index = 0; index < table_size(); index++) {
duke@435 574 for (DictionaryEntry* probe = bucket(index);
duke@435 575 probe != NULL;
duke@435 576 probe = probe->next()) {
coleenp@4037 577 Klass* e = probe->klass();
coleenp@4037 578 ClassLoaderData* loader_data = probe->loader_data();
hseigel@4278 579 guarantee(e->oop_is_instance(),
duke@435 580 "Verify of system dictionary failed");
duke@435 581 // class loader must be present; a null class loader is the
duke@435 582 // boostrap loader
coleenp@4037 583 guarantee(loader_data != NULL || DumpSharedSpaces ||
coleenp@4304 584 loader_data->class_loader() == NULL ||
coleenp@4037 585 loader_data->class_loader()->is_instance(),
duke@435 586 "checking type of class_loader");
duke@435 587 e->verify();
duke@435 588 probe->verify_protection_domain_set();
duke@435 589 element_count++;
duke@435 590 }
duke@435 591 }
duke@435 592 guarantee(number_of_entries() == element_count,
duke@435 593 "Verify of system dictionary failed");
duke@435 594 debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
duke@435 595 }
coleenp@4037 596

mercurial