src/share/vm/classfile/dictionary.cpp

Fri, 27 Feb 2009 13:27:09 -0800

author
twisti
date
Fri, 27 Feb 2009 13:27:09 -0800
changeset 1040
98cb887364d3
parent 631
d1605aabd0a1
child 1145
e5b0439ef4ae
permissions
-rw-r--r--

6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never

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

mercurial