src/share/vm/classfile/dictionary.cpp

Wed, 24 Apr 2013 16:19:35 -0400

author
coleenp
date
Wed, 24 Apr 2013 16:19:35 -0400
changeset 4981
d587a5c30bd8
parent 4667
1f9994892f89
child 5100
43083e670adf
permissions
-rw-r--r--

8011803: release_C_heap_structures is never called for anonymous classes.
Summary: Call this function from the ClassLoaderData destructor instead of the system dictionary walk.
Reviewed-by: stefank, mgerdin

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

mercurial