annotate src/share/vm/classfile/dictionary.cpp @ 1838:3b2dea75431e

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