src/share/vm/classfile/dictionary.cpp

Wed, 12 Sep 2018 10:11:31 -0400

author
coleenp
date
Wed, 12 Sep 2018 10:11:31 -0400
changeset 9530
9fce84e6f51a
parent 9327
f96fcd9e1e1b
child 9572
624a0741915c
permissions
-rw-r--r--

8210094: Better loading of classloader classes
Reviewed-by: acorn, hseigel, ahgross, rhalade

     1 /*
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "classfile/dictionary.hpp"
    27 #include "classfile/systemDictionary.hpp"
    28 #include "classfile/systemDictionaryShared.hpp"
    29 #include "memory/iterator.hpp"
    30 #include "oops/oop.inline.hpp"
    31 #include "prims/jvmtiRedefineClassesTrace.hpp"
    32 #include "runtime/orderAccess.inline.hpp"
    33 #include "utilities/hashtable.inline.hpp"
    35 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    37 DictionaryEntry*  Dictionary::_current_class_entry = NULL;
    38 int               Dictionary::_current_class_index =    0;
    40 size_t Dictionary::entry_size() {
    41   if (DumpSharedSpaces) {
    42     return SystemDictionaryShared::dictionary_entry_size();
    43   } else {
    44     return sizeof(DictionaryEntry);
    45   }
    46 }
    48 Dictionary::Dictionary(int table_size)
    49   : TwoOopHashtable<Klass*, mtClass>(table_size, (int)entry_size()) {
    50   _current_class_index = 0;
    51   _current_class_entry = NULL;
    52   _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
    53 };
    56 Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t,
    57                        int number_of_entries)
    58   : TwoOopHashtable<Klass*, mtClass>(table_size, (int)entry_size(), t, number_of_entries) {
    59   _current_class_index = 0;
    60   _current_class_entry = NULL;
    61   _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
    62 };
    64 ProtectionDomainCacheEntry* Dictionary::cache_get(oop protection_domain) {
    65   return _pd_cache_table->get(protection_domain);
    66 }
    68 DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass,
    69                                        ClassLoaderData* loader_data) {
    70   DictionaryEntry* entry = (DictionaryEntry*)Hashtable<Klass*, mtClass>::new_entry(hash, klass);
    71   entry->set_loader_data(loader_data);
    72   entry->set_pd_set(NULL);
    73   assert(klass->oop_is_instance(), "Must be");
    74   if (DumpSharedSpaces) {
    75     SystemDictionaryShared::init_shared_dictionary_entry(klass, entry);
    76   }
    77   return entry;
    78 }
    81 void Dictionary::free_entry(DictionaryEntry* entry) {
    82   // avoid recursion when deleting linked list
    83   while (entry->pd_set() != NULL) {
    84     ProtectionDomainEntry* to_delete = entry->pd_set();
    85     entry->set_pd_set(to_delete->next());
    86     delete to_delete;
    87   }
    88   Hashtable<Klass*, mtClass>::free_entry(entry);
    89 }
    92 bool DictionaryEntry::contains_protection_domain(oop protection_domain) const {
    93 #ifdef ASSERT
    94   if (protection_domain == InstanceKlass::cast(klass())->protection_domain()) {
    95     // Ensure this doesn't show up in the pd_set (invariant)
    96     bool in_pd_set = false;
    97     for (ProtectionDomainEntry* current = _pd_set;
    98                                 current != NULL;
    99                                 current = current->next()) {
   100       if (current->protection_domain() == protection_domain) {
   101         in_pd_set = true;
   102         break;
   103       }
   104     }
   105     if (in_pd_set) {
   106       assert(false, "A klass's protection domain should not show up "
   107                     "in its sys. dict. PD set");
   108     }
   109   }
   110 #endif /* ASSERT */
   112   if (protection_domain == InstanceKlass::cast(klass())->protection_domain()) {
   113     // Succeeds trivially
   114     return true;
   115   }
   117   for (ProtectionDomainEntry* current = _pd_set;
   118                               current != NULL;
   119                               current = current->next()) {
   120     if (current->protection_domain() == protection_domain) return true;
   121   }
   122   return false;
   123 }
   126 void DictionaryEntry::add_protection_domain(Dictionary* dict, oop protection_domain) {
   127   assert_locked_or_safepoint(SystemDictionary_lock);
   128   if (!contains_protection_domain(protection_domain)) {
   129     ProtectionDomainCacheEntry* entry = dict->cache_get(protection_domain);
   130     ProtectionDomainEntry* new_head =
   131                 new ProtectionDomainEntry(entry, _pd_set);
   132     // Warning: Preserve store ordering.  The SystemDictionary is read
   133     //          without locks.  The new ProtectionDomainEntry must be
   134     //          complete before other threads can be allowed to see it
   135     //          via a store to _pd_set.
   136     OrderAccess::release_store_ptr(&_pd_set, new_head);
   137   }
   138   if (TraceProtectionDomainVerification && WizardMode) {
   139     print();
   140   }
   141 }
   144 void Dictionary::do_unloading() {
   145   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
   147   // Remove unloadable entries and classes from system dictionary
   148   // The placeholder array has been handled in always_strong_oops_do.
   149   DictionaryEntry* probe = NULL;
   150   for (int index = 0; index < table_size(); index++) {
   151     for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
   152       probe = *p;
   153       Klass* e = probe->klass();
   154       ClassLoaderData* loader_data = probe->loader_data();
   156       InstanceKlass* ik = InstanceKlass::cast(e);
   158       // Non-unloadable classes were handled in always_strong_oops_do
   159       if (!is_strongly_reachable(loader_data, e)) {
   160         // Entry was not visited in phase1 (negated test from phase1)
   161         assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader");
   163         // Do we need to delete this system dictionary entry?
   164         if (loader_data->is_unloading()) {
   165           *p = probe->next();
   166           if (probe == _current_class_entry) {
   167             _current_class_entry = NULL;
   168           }
   169           free_entry(probe);
   170           continue;
   171         }
   172       }
   173       p = probe->next_addr();
   174     }
   175   }
   176 }
   178 void Dictionary::roots_oops_do(OopClosure* strong, OopClosure* weak) {
   179   // Skip the strong roots probe marking if the closures are the same.
   180   if (strong == weak) {
   181     oops_do(strong);
   182     return;
   183   }
   185   for (int index = 0; index < table_size(); index++) {
   186     for (DictionaryEntry *probe = bucket(index);
   187                           probe != NULL;
   188                           probe = probe->next()) {
   189       Klass* e = probe->klass();
   190       ClassLoaderData* loader_data = probe->loader_data();
   191       if (is_strongly_reachable(loader_data, e)) {
   192         probe->set_strongly_reachable();
   193       }
   194     }
   195   }
   196   _pd_cache_table->roots_oops_do(strong, weak);
   197 }
   199 void Dictionary::remove_classes_in_error_state() {
   200   assert(DumpSharedSpaces, "supported only when dumping");
   201   DictionaryEntry* probe = NULL;
   202   for (int index = 0; index < table_size(); index++) {
   203     for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
   204       probe = *p;
   205       InstanceKlass* ik = InstanceKlass::cast(probe->klass());
   206       if (ik->is_in_error_state()) { // purge this entry
   207         *p = probe->next();
   208         if (probe == _current_class_entry) {
   209           _current_class_entry = NULL;
   210         }
   211         free_entry(probe);
   212         ResourceMark rm;
   213         tty->print_cr("Preload Warning: Removed error class: %s", ik->external_name());
   214         continue;
   215       }
   217       p = probe->next_addr();
   218     }
   219   }
   220 }
   222 void Dictionary::always_strong_oops_do(OopClosure* blk) {
   223   // Follow all system classes and temporary placeholders in dictionary; only
   224   // protection domain oops contain references into the heap. In a first
   225   // pass over the system dictionary determine which need to be treated as
   226   // strongly reachable and mark them as such.
   227   for (int index = 0; index < table_size(); index++) {
   228     for (DictionaryEntry *probe = bucket(index);
   229                           probe != NULL;
   230                           probe = probe->next()) {
   231       Klass* e = probe->klass();
   232       ClassLoaderData* loader_data = probe->loader_data();
   233       if (is_strongly_reachable(loader_data, e)) {
   234         probe->set_strongly_reachable();
   235       }
   236     }
   237   }
   238   // Then iterate over the protection domain cache to apply the closure on the
   239   // previously marked ones.
   240   _pd_cache_table->always_strong_oops_do(blk);
   241 }
   244 void Dictionary::always_strong_classes_do(KlassClosure* closure) {
   245   // Follow all system classes and temporary placeholders in dictionary
   246   for (int index = 0; index < table_size(); index++) {
   247     for (DictionaryEntry* probe = bucket(index);
   248                           probe != NULL;
   249                           probe = probe->next()) {
   250       Klass* e = probe->klass();
   251       ClassLoaderData* loader_data = probe->loader_data();
   252       if (is_strongly_reachable(loader_data, e)) {
   253         closure->do_klass(e);
   254       }
   255     }
   256   }
   257 }
   260 //   Just the classes from defining class loaders
   261 void Dictionary::classes_do(void f(Klass*)) {
   262   for (int index = 0; index < table_size(); index++) {
   263     for (DictionaryEntry* probe = bucket(index);
   264                           probe != NULL;
   265                           probe = probe->next()) {
   266       Klass* k = probe->klass();
   267       if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) {
   268         f(k);
   269       }
   270     }
   271   }
   272 }
   274 // Added for initialize_itable_for_klass to handle exceptions
   275 //   Just the classes from defining class loaders
   276 void Dictionary::classes_do(void f(Klass*, TRAPS), TRAPS) {
   277   for (int index = 0; index < table_size(); index++) {
   278     for (DictionaryEntry* probe = bucket(index);
   279                           probe != NULL;
   280                           probe = probe->next()) {
   281       Klass* k = probe->klass();
   282       if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) {
   283         f(k, CHECK);
   284       }
   285     }
   286   }
   287 }
   289 //   All classes, and their class loaders
   290 // Don't iterate over placeholders
   291 void Dictionary::classes_do(void f(Klass*, ClassLoaderData*)) {
   292   for (int index = 0; index < table_size(); index++) {
   293     for (DictionaryEntry* probe = bucket(index);
   294                           probe != NULL;
   295                           probe = probe->next()) {
   296       Klass* k = probe->klass();
   297       f(k, probe->loader_data());
   298     }
   299   }
   300 }
   302 void Dictionary::oops_do(OopClosure* f) {
   303   // Only the protection domain oops contain references into the heap. Iterate
   304   // over all of them.
   305   _pd_cache_table->oops_do(f);
   306 }
   308 void Dictionary::methods_do(void f(Method*)) {
   309   for (int index = 0; index < table_size(); index++) {
   310     for (DictionaryEntry* probe = bucket(index);
   311                           probe != NULL;
   312                           probe = probe->next()) {
   313       Klass* k = probe->klass();
   314       if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) {
   315         // only take klass is we have the entry with the defining class loader
   316         InstanceKlass::cast(k)->methods_do(f);
   317       }
   318     }
   319   }
   320 }
   322 void Dictionary::unlink(BoolObjectClosure* is_alive) {
   323   // Only the protection domain cache table may contain references to the heap
   324   // that need to be unlinked.
   325   _pd_cache_table->unlink(is_alive);
   326 }
   328 Klass* Dictionary::try_get_next_class() {
   329   while (true) {
   330     if (_current_class_entry != NULL) {
   331       Klass* k = _current_class_entry->klass();
   332       _current_class_entry = _current_class_entry->next();
   333       return k;
   334     }
   335     _current_class_index = (_current_class_index + 1) % table_size();
   336     _current_class_entry = bucket(_current_class_index);
   337   }
   338   // never reached
   339 }
   341 // Add a loaded class to the system dictionary.
   342 // Readers of the SystemDictionary aren't always locked, so _buckets
   343 // is volatile. The store of the next field in the constructor is
   344 // also cast to volatile;  we do this to ensure store order is maintained
   345 // by the compilers.
   347 void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data,
   348                            KlassHandle obj) {
   349   assert_locked_or_safepoint(SystemDictionary_lock);
   350   assert(obj() != NULL, "adding NULL obj");
   351   assert(obj()->name() == class_name, "sanity check on name");
   352   assert(loader_data != NULL, "Must be non-NULL");
   354   unsigned int hash = compute_hash(class_name, loader_data);
   355   int index = hash_to_index(hash);
   356   DictionaryEntry* entry = new_entry(hash, obj(), loader_data);
   357   add_entry(index, entry);
   358 }
   361 // This routine does not lock the system dictionary.
   362 //
   363 // Since readers don't hold a lock, we must make sure that system
   364 // dictionary entries are only removed at a safepoint (when only one
   365 // thread is running), and are added to in a safe way (all links must
   366 // be updated in an MT-safe manner).
   367 //
   368 // Callers should be aware that an entry could be added just after
   369 // _buckets[index] is read here, so the caller will not see the new entry.
   370 DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
   371                                        Symbol* class_name,
   372                                        ClassLoaderData* loader_data) {
   373   debug_only(_lookup_count++);
   374   for (DictionaryEntry* entry = bucket(index);
   375                         entry != NULL;
   376                         entry = entry->next()) {
   377     if (entry->hash() == hash && entry->equals(class_name, loader_data)) {
   378       return entry;
   379     }
   380     debug_only(_lookup_length++);
   381   }
   382   return NULL;
   383 }
   386 Klass* Dictionary::find(int index, unsigned int hash, Symbol* name,
   387                           ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
   388   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
   389   if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
   390     return entry->klass();
   391   } else {
   392     return NULL;
   393   }
   394 }
   397 Klass* Dictionary::find_class(int index, unsigned int hash,
   398                                 Symbol* name, ClassLoaderData* loader_data) {
   399   assert_locked_or_safepoint(SystemDictionary_lock);
   400   assert (index == index_for(name, loader_data), "incorrect index?");
   402   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
   403   return (entry != NULL) ? entry->klass() : (Klass*)NULL;
   404 }
   407 // Variant of find_class for shared classes.  No locking required, as
   408 // that table is static.
   410 Klass* Dictionary::find_shared_class(int index, unsigned int hash,
   411                                        Symbol* name) {
   412   assert (index == index_for(name, NULL), "incorrect index?");
   414   DictionaryEntry* entry = get_entry(index, hash, name, NULL);
   415   return (entry != NULL) ? entry->klass() : (Klass*)NULL;
   416 }
   419 void Dictionary::add_protection_domain(int index, unsigned int hash,
   420                                        instanceKlassHandle klass,
   421                                        ClassLoaderData* loader_data, Handle protection_domain,
   422                                        TRAPS) {
   423   Symbol*  klass_name = klass->name();
   424   DictionaryEntry* entry = get_entry(index, hash, klass_name, loader_data);
   426   assert(entry != NULL,"entry must be present, we just created it");
   427   assert(protection_domain() != NULL,
   428          "real protection domain should be present");
   430   entry->add_protection_domain(this, protection_domain());
   432   assert(entry->contains_protection_domain(protection_domain()),
   433          "now protection domain should be present");
   434 }
   437 bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
   438                                             Symbol* name,
   439                                             ClassLoaderData* loader_data,
   440                                             Handle protection_domain) {
   441   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
   442   return entry->is_valid_protection_domain(protection_domain);
   443 }
   446 void Dictionary::reorder_dictionary() {
   448   // Copy all the dictionary entries into a single master list.
   450   DictionaryEntry* master_list = NULL;
   451   for (int i = 0; i < table_size(); ++i) {
   452     DictionaryEntry* p = bucket(i);
   453     while (p != NULL) {
   454       DictionaryEntry* tmp;
   455       tmp = p->next();
   456       p->set_next(master_list);
   457       master_list = p;
   458       p = tmp;
   459     }
   460     set_entry(i, NULL);
   461   }
   463   // Add the dictionary entries back to the list in the correct buckets.
   464   while (master_list != NULL) {
   465     DictionaryEntry* p = master_list;
   466     master_list = master_list->next();
   467     p->set_next(NULL);
   468     Symbol* class_name = InstanceKlass::cast((Klass*)(p->klass()))->name();
   469     // Since the null class loader data isn't copied to the CDS archive,
   470     // compute the hash with NULL for loader data.
   471     unsigned int hash = compute_hash(class_name, NULL);
   472     int index = hash_to_index(hash);
   473     p->set_hash(hash);
   474     p->set_loader_data(NULL);   // loader_data isn't copied to CDS
   475     p->set_next(bucket(index));
   476     set_entry(index, p);
   477   }
   478 }
   480 ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size)
   481   : Hashtable<oop, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
   482 {
   483 }
   485 void ProtectionDomainCacheTable::unlink(BoolObjectClosure* is_alive) {
   486   assert(SafepointSynchronize::is_at_safepoint(), "must be");
   487   for (int i = 0; i < table_size(); ++i) {
   488     ProtectionDomainCacheEntry** p = bucket_addr(i);
   489     ProtectionDomainCacheEntry* entry = bucket(i);
   490     while (entry != NULL) {
   491       if (is_alive->do_object_b(entry->literal())) {
   492         p = entry->next_addr();
   493       } else {
   494         *p = entry->next();
   495         free_entry(entry);
   496       }
   497       entry = *p;
   498     }
   499   }
   500 }
   502 void ProtectionDomainCacheTable::oops_do(OopClosure* f) {
   503   for (int index = 0; index < table_size(); index++) {
   504     for (ProtectionDomainCacheEntry* probe = bucket(index);
   505                                      probe != NULL;
   506                                      probe = probe->next()) {
   507       probe->oops_do(f);
   508     }
   509   }
   510 }
   512 void ProtectionDomainCacheTable::roots_oops_do(OopClosure* strong, OopClosure* weak) {
   513   for (int index = 0; index < table_size(); index++) {
   514     for (ProtectionDomainCacheEntry* probe = bucket(index);
   515                                      probe != NULL;
   516                                      probe = probe->next()) {
   517       if (probe->is_strongly_reachable()) {
   518         probe->reset_strongly_reachable();
   519         probe->oops_do(strong);
   520       } else {
   521         if (weak != NULL) {
   522           probe->oops_do(weak);
   523         }
   524       }
   525     }
   526   }
   527 }
   529 uint ProtectionDomainCacheTable::bucket_size() {
   530   return sizeof(ProtectionDomainCacheEntry);
   531 }
   533 #ifndef PRODUCT
   534 void ProtectionDomainCacheTable::print() {
   535   tty->print_cr("Protection domain cache table (table_size=%d, classes=%d)",
   536                 table_size(), number_of_entries());
   537   for (int index = 0; index < table_size(); index++) {
   538     for (ProtectionDomainCacheEntry* probe = bucket(index);
   539                                      probe != NULL;
   540                                      probe = probe->next()) {
   541       probe->print();
   542     }
   543   }
   544 }
   546 void ProtectionDomainCacheEntry::print() {
   547   tty->print_cr("entry " PTR_FORMAT " value " PTR_FORMAT " strongly_reachable %d next " PTR_FORMAT,
   548                 this, (void*)literal(), _strongly_reachable, next());
   549 }
   550 #endif
   552 void ProtectionDomainCacheTable::verify() {
   553   int element_count = 0;
   554   for (int index = 0; index < table_size(); index++) {
   555     for (ProtectionDomainCacheEntry* probe = bucket(index);
   556                                      probe != NULL;
   557                                      probe = probe->next()) {
   558       probe->verify();
   559       element_count++;
   560     }
   561   }
   562   guarantee(number_of_entries() == element_count,
   563             "Verify of protection domain cache table failed");
   564   debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
   565 }
   567 void ProtectionDomainCacheEntry::verify() {
   568   guarantee(literal()->is_oop(), "must be an oop");
   569 }
   571 void ProtectionDomainCacheTable::always_strong_oops_do(OopClosure* f) {
   572   // the caller marked the protection domain cache entries that we need to apply
   573   // the closure on. Only process them.
   574   for (int index = 0; index < table_size(); index++) {
   575     for (ProtectionDomainCacheEntry* probe = bucket(index);
   576                                      probe != NULL;
   577                                      probe = probe->next()) {
   578       if (probe->is_strongly_reachable()) {
   579         probe->reset_strongly_reachable();
   580         probe->oops_do(f);
   581       }
   582     }
   583   }
   584 }
   586 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(oop protection_domain) {
   587   unsigned int hash = compute_hash(protection_domain);
   588   int index = hash_to_index(hash);
   590   ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain);
   591   if (entry == NULL) {
   592     entry = add_entry(index, hash, protection_domain);
   593   }
   594   return entry;
   595 }
   597 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, oop protection_domain) {
   598   for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) {
   599     if (e->protection_domain() == protection_domain) {
   600       return e;
   601     }
   602   }
   604   return NULL;
   605 }
   607 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, oop protection_domain) {
   608   assert_locked_or_safepoint(SystemDictionary_lock);
   609   assert(index == index_for(protection_domain), "incorrect index?");
   610   assert(find_entry(index, protection_domain) == NULL, "no double entry");
   612   ProtectionDomainCacheEntry* p = new_entry(hash, protection_domain);
   613   Hashtable<oop, mtClass>::add_entry(index, p);
   614   return p;
   615 }
   617 void ProtectionDomainCacheTable::free(ProtectionDomainCacheEntry* to_delete) {
   618   unsigned int hash = compute_hash(to_delete->protection_domain());
   619   int index = hash_to_index(hash);
   621   ProtectionDomainCacheEntry** p = bucket_addr(index);
   622   ProtectionDomainCacheEntry* entry = bucket(index);
   623   while (true) {
   624     assert(entry != NULL, "sanity");
   626     if (entry == to_delete) {
   627       *p = entry->next();
   628       Hashtable<oop, mtClass>::free_entry(entry);
   629       break;
   630     } else {
   631       p = entry->next_addr();
   632       entry = *p;
   633     }
   634   }
   635 }
   637 SymbolPropertyTable::SymbolPropertyTable(int table_size)
   638   : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry))
   639 {
   640 }
   641 SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t,
   642                                          int number_of_entries)
   643   : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries)
   644 {
   645 }
   648 SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash,
   649                                                      Symbol* sym,
   650                                                      intptr_t sym_mode) {
   651   assert(index == index_for(sym, sym_mode), "incorrect index?");
   652   for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
   653     if (p->hash() == hash && p->symbol() == sym && p->symbol_mode() == sym_mode) {
   654       return p;
   655     }
   656   }
   657   return NULL;
   658 }
   661 SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash,
   662                                                     Symbol* sym, intptr_t sym_mode) {
   663   assert_locked_or_safepoint(SystemDictionary_lock);
   664   assert(index == index_for(sym, sym_mode), "incorrect index?");
   665   assert(find_entry(index, hash, sym, sym_mode) == NULL, "no double entry");
   667   SymbolPropertyEntry* p = new_entry(hash, sym, sym_mode);
   668   Hashtable<Symbol*, mtSymbol>::add_entry(index, p);
   669   return p;
   670 }
   672 void SymbolPropertyTable::oops_do(OopClosure* f) {
   673   for (int index = 0; index < table_size(); index++) {
   674     for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
   675       if (p->method_type() != NULL) {
   676         f->do_oop(p->method_type_addr());
   677       }
   678     }
   679   }
   680 }
   682 void SymbolPropertyTable::methods_do(void f(Method*)) {
   683   for (int index = 0; index < table_size(); index++) {
   684     for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
   685       Method* prop = p->method();
   686       if (prop != NULL) {
   687         f((Method*)prop);
   688       }
   689     }
   690   }
   691 }
   694 // ----------------------------------------------------------------------------
   696 void Dictionary::print(bool details) {
   697   ResourceMark rm;
   698   HandleMark   hm;
   700   if (details) {
   701     tty->print_cr("Java system dictionary (table_size=%d, classes=%d)",
   702                    table_size(), number_of_entries());
   703     tty->print_cr("^ indicates that initiating loader is different from "
   704                   "defining loader");
   705   }
   707   for (int index = 0; index < table_size(); index++) {
   708     for (DictionaryEntry* probe = bucket(index);
   709                           probe != NULL;
   710                           probe = probe->next()) {
   711       if (Verbose) tty->print("%4d: ", index);
   712       Klass* e = probe->klass();
   713       ClassLoaderData* loader_data =  probe->loader_data();
   714       bool is_defining_class =
   715          (loader_data == InstanceKlass::cast(e)->class_loader_data());
   716       tty->print("%s%s", ((!details) || is_defining_class) ? " " : "^",
   717                    e->external_name());
   719       if (details) {
   720         tty->print(", loader ");
   721         if (loader_data != NULL) {
   722           loader_data->print_value();
   723         } else {
   724           tty->print("NULL");
   725         }
   726       }
   727       tty->cr();
   728     }
   729   }
   731   if (details) {
   732     tty->cr();
   733     _pd_cache_table->print();
   734   }
   735   tty->cr();
   736 }
   738 void Dictionary::verify() {
   739   guarantee(number_of_entries() >= 0, "Verify of system dictionary failed");
   741   int element_count = 0;
   742   for (int index = 0; index < table_size(); index++) {
   743     for (DictionaryEntry* probe = bucket(index);
   744                           probe != NULL;
   745                           probe = probe->next()) {
   746       Klass* e = probe->klass();
   747       ClassLoaderData* loader_data = probe->loader_data();
   748       guarantee(e->oop_is_instance(),
   749                               "Verify of system dictionary failed");
   750       // class loader must be present;  a null class loader is the
   751       // boostrap loader
   752       guarantee(loader_data != NULL || DumpSharedSpaces ||
   753                 loader_data->class_loader() == NULL ||
   754                 loader_data->class_loader()->is_instance(),
   755                 "checking type of class_loader");
   756       e->verify();
   757       probe->verify_protection_domain_set();
   758       element_count++;
   759     }
   760   }
   761   guarantee(number_of_entries() == element_count,
   762             "Verify of system dictionary failed");
   763   debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
   765   _pd_cache_table->verify();
   766 }

mercurial