src/share/vm/classfile/dictionary.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File

## src/share/vm/classfile/dictionary.cpp

Print this page

     351   // never reached
     352 }
     353
     354 // Add a loaded class to the system dictionary.
     355 // Readers of the SystemDictionary aren't always locked, so _buckets
     356 // is volatile. The store of the next field in the constructor is
     357 // also cast to volatile;  we do this to ensure store order is maintained
     358 // by the compilers.
     359
     360 void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data,
     361                            KlassHandle obj) {
     362   assert_locked_or_safepoint(SystemDictionary_lock);
     363   assert(obj() != NULL, "adding NULL obj");
     364   assert(obj()->name() == class_name, "sanity check on name");
     365   assert(loader_data != NULL, "Must be non-NULL");
     366
     367   unsigned int hash = compute_hash(class_name, loader_data);
     368   int index = hash_to_index(hash);
     369   DictionaryEntry* entry = new_entry(hash, obj(), loader_data);
     370   add_entry(index, entry);

     371 }
     372
     373
     374 // This routine does not lock the system dictionary.
     375 //
     376 // Since readers don't hold a lock, we must make sure that system
     377 // dictionary entries are only removed at a safepoint (when only one
     378 // thread is running), and are added to in a safe way (all links must
     379 // be updated in an MT-safe manner).
     380 //
     381 // Callers should be aware that an entry could be added just after
     382 // _buckets[index] is read here, so the caller will not see the new entry.
     383 DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
     384                                        Symbol* class_name,
     385                                        ClassLoaderData* loader_data) {
     386   debug_only(_lookup_count++);

     387   for (DictionaryEntry* entry = bucket(index);
     388                         entry != NULL;
     389                         entry = entry->next()) {

     390     if (entry->hash() == hash && entry->equals(class_name, loader_data)) {

     391       return entry;
     392     }
     393     debug_only(_lookup_length++);
     394   }

     395   return NULL;
     396 }
     397
     398
     399 Klass* Dictionary::find(int index, unsigned int hash, Symbol* name,
     400                           ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {

     401   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
     402   if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
     403     return entry->klass();
     404   } else {
     405     return NULL;
     406   }
     407 }
     408
     409
     410 Klass* Dictionary::find_class(int index, unsigned int hash,
     411                                 Symbol* name, ClassLoaderData* loader_data) {
     412   assert_locked_or_safepoint(SystemDictionary_lock);
     413   assert (index == index_for(name, loader_data), "incorrect index?");
     414

     415   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
     416   return (entry != NULL) ? entry->klass() : (Klass*)NULL;

     417 }
     418
     419
     420 // Variant of find_class for shared classes.  No locking required, as
     421 // that table is static.
     422
     423 Klass* Dictionary::find_shared_class(int index, unsigned int hash,
     424                                        Symbol* name) {
     425   assert (index == index_for(name, NULL), "incorrect index?");
     426

     427   DictionaryEntry* entry = get_entry(index, hash, name, NULL);
     428   return (entry != NULL) ? entry->klass() : (Klass*)NULL;

     429 }
     430
     431
     432 void Dictionary::add_protection_domain(int index, unsigned int hash,
     433                                        instanceKlassHandle klass,
     434                                        ClassLoaderData* loader_data, Handle protection_domain,
     435                                        TRAPS) {
     436   Symbol*  klass_name = klass->name();

     437   DictionaryEntry* entry = get_entry(index, hash, klass_name, loader_data);
     438
     439   assert(entry != NULL,"entry must be present, we just created it");
     440   assert(protection_domain() != NULL,
     441          "real protection domain should be present");
     442
     443   entry->add_protection_domain(this, protection_domain());
     444
     445   assert(entry->contains_protection_domain(protection_domain()),
     446          "now protection domain should be present");
     447 }
     448
     449
     450 bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
     451                                             Symbol* name,
     452                                             ClassLoaderData* loader_data,
     453                                             Handle protection_domain) {

     454   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);

     455   return entry->is_valid_protection_domain(protection_domain);
     456 }
     457
     458
     459 void Dictionary::reorder_dictionary() {
     460
     461   // Copy all the dictionary entries into a single master list.
     462
     463   DictionaryEntry* master_list = NULL;
     464   for (int i = 0; i < table_size(); ++i) {
     465     DictionaryEntry* p = bucket(i);
     466     while (p != NULL) {
     467       DictionaryEntry* tmp;
     468       tmp = p->next();
     469       p->set_next(master_list);
     470       master_list = p;
     471       p = tmp;
     472     }
     473     set_entry(i, NULL);
     474   }
     693 }
     694
     695 void SymbolPropertyTable::methods_do(void f(Method*)) {
     696   for (int index = 0; index < table_size(); index++) {
     697     for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
     698       Method* prop = p->method();
     699       if (prop != NULL) {
     700         f((Method*)prop);
     701       }
     702     }
     703   }
     704 }
     705
     706
     707 // ----------------------------------------------------------------------------
     708
     709 void Dictionary::print(bool details) {
     710   ResourceMark rm;
     711   HandleMark   hm;
     712

     713   if (details) {
     714     tty->print_cr("Java system dictionary (table_size=%d, classes=%d)",
     715                    table_size(), number_of_entries());
     716     tty->print_cr("^ indicates that initiating loader is different from "
     717                   "defining loader");
     718   }
     719
     720   for (int index = 0; index < table_size(); index++) {
     721     for (DictionaryEntry* probe = bucket(index);
     722                           probe != NULL;
     723                           probe = probe->next()) {
     724       if (Verbose) tty->print("%4d: ", index);
     725       Klass* e = probe->klass();
     726       ClassLoaderData* loader_data =  probe->loader_data();
     727       bool is_defining_class =
     728          (loader_data == InstanceKlass::cast(e)->class_loader_data());
     729       tty->print("%s%s", ((!details) || is_defining_class) ? " " : "^",
     730                    e->external_name());
     731
     732       if (details) {
     734         if (loader_data != NULL) {
     735           loader_data->print_value();
     736         } else {
     737           tty->print("NULL");
     738         }
     739       }
     740       tty->cr();
     741     }
     742   }
     743
     744   if (details) {
     745     tty->cr();
     746     _pd_cache_table->print();
     747   }
     748   tty->cr();
     749 }
     750
     751 void Dictionary::verify() {
     752   guarantee(number_of_entries() >= 0, "Verify of system dictionary failed");
     753

     754   int element_count = 0;
     755   for (int index = 0; index < table_size(); index++) {
     756     for (DictionaryEntry* probe = bucket(index);
     757                           probe != NULL;
     758                           probe = probe->next()) {
     759       Klass* e = probe->klass();
     760       ClassLoaderData* loader_data = probe->loader_data();
     761       guarantee(e->oop_is_instance(),
     762                               "Verify of system dictionary failed");
     763       // class loader must be present;  a null class loader is the
     764       // boostrap loader
     765       guarantee(loader_data != NULL || DumpSharedSpaces ||
     766                 loader_data->class_loader() == NULL ||
     767                 loader_data->class_loader()->is_instance(),
     768                 "checking type of class_loader");
     769       e->verify();
     770       probe->verify_protection_domain_set();
     771       element_count++;
     772     }
     773   }
     774   guarantee(number_of_entries() == element_count,
     775             "Verify of system dictionary failed");
     776   debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
     777
     778   _pd_cache_table->verify();
     779 }
     780
     351   // never reached
     352 }
     353
     354 // Add a loaded class to the system dictionary.
     355 // Readers of the SystemDictionary aren't always locked, so _buckets
     356 // is volatile. The store of the next field in the constructor is
     357 // also cast to volatile;  we do this to ensure store order is maintained
     358 // by the compilers.
     359
     360 void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data,
     361                            KlassHandle obj) {
     362   assert_locked_or_safepoint(SystemDictionary_lock);
     363   assert(obj() != NULL, "adding NULL obj");
     364   assert(obj()->name() == class_name, "sanity check on name");
     365   assert(loader_data != NULL, "Must be non-NULL");
     366
     367   unsigned int hash = compute_hash(class_name, loader_data);
     368   int index = hash_to_index(hash);
     369   DictionaryEntry* entry = new_entry(hash, obj(), loader_data);
     370   add_entry(index, entry);
     371
     372 #ifndef PRODUCT
     373 //#ifdef PRODUCT_TEST
     374   {
     375     _debug_all_insertion_count++;
     376     _debug_insertion_count++;
     377   }
     378 #endif
     379 }
     380
     381
     382 // This routine does not lock the system dictionary.
     383 //
     384 // Since readers don't hold a lock, we must make sure that system
     385 // dictionary entries are only removed at a safepoint (when only one
     386 // thread is running), and are added to in a safe way (all links must
     387 // be updated in an MT-safe manner).
     388 //
     389 // Callers should be aware that an entry could be added just after
     390 // _buckets[index] is read here, so the caller will not see the new entry.
     391 DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
     392                                        Symbol* class_name,
     393                                        ClassLoaderData* loader_data) {
     394   debug_only(_lookup_count++);
     395
     396 #ifndef PRODUCT
     397 //#ifdef PRODUCT_TEST
     398   jlong time = os::javaTimeNanos();
     399   _debug_all_lookup_count++;
     400   _debug_lookup_count++;
     401 #endif
     402
     403   unsigned int count = 0;
     404   for (DictionaryEntry* entry = bucket(index);
     405                         entry != NULL;
     406                         entry = entry->next()) {
     407     count++;
     408     if (entry->hash() == hash && entry->equals(class_name, loader_data)) {
     409
     410       entry->_debug_lookups++;
     411 #ifndef PRODUCT
     412 //#ifdef PRODUCT_TEST
     413       {
     414         unsigned int duration = os::javaTimeNanos()-time;
     415         _debug_lookup_found_count++;
     416         _debug_lookup_found_max_duration = (_debug_lookup_found_max_duration > duration) ? _debug_lookup_found_max_duration : duration;
     417         _debug_lookup_found_total_duration += duration;
     418         _debug_chain_found_maximum_length = (_debug_chain_found_maximum_length > count) ? _debug_chain_found_maximum_length : count;
     419         _debug_chain_found_total_length += count;
     420
     421         long thread_id = os::current_thread_id();
     422         for (int i=0; i<1024; i++) {
     423           if (_debug_table_threads[i] == thread_id) {
     424             break;
     425           } else if (_debug_table_threads[i] == 0) {
     426             _debug_table_threads[i] = thread_id;
     427             break;
     428           }
     429         }
     430       }
     431 #endif
     432
     433       return entry;
     434     }
     435     debug_only(_lookup_length++);
     436   }
     437
     438 #ifndef PRODUCT
     439 //#ifdef PRODUCT_TEST
     440   {
     441     unsigned int duration = os::javaTimeNanos()-time;
     442     _debug_lookup_failed_count++;
     443     _debug_lookup_failed_max_duration = (_debug_lookup_failed_max_duration > duration) ? _debug_lookup_failed_max_duration : duration;
     444     _debug_lookup_failed_total_duration += duration;
     445     _debug_chain_failed_maximum_length = (_debug_chain_failed_maximum_length > count) ? _debug_chain_failed_maximum_length : count;
     446     _debug_chain_failed_total_length += count;
     447   }
     448 #endif
     449
     450   return NULL;
     451 }
     452
     453
     454 Klass* Dictionary::find(unsigned int hash, Symbol* name,
     455                           ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
     456
     457   int index = this->hash_to_index(hash);
     458   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
     459   if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
     460     return entry->klass();
     461   } else {
     462     return (Klass*)NULL;
     463   }
     464 }
     465
     466
     467 Klass* Dictionary::find_class(unsigned int hash,
     468                                 Symbol* name, ClassLoaderData* loader_data) {
     469   assert_locked_or_safepoint(SystemDictionary_lock);

     470
     471   int index = this->hash_to_index(hash);
     472   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
     473   if (entry != NULL) {
     474     return entry->klass();
     475   } else {
     476     return (Klass*)NULL;
     477   }
     478 }
     479
     480
     481 // Variant of find_class for shared classes.  No locking required, as
     482 // that table is static.
     483
     484 Klass* Dictionary::find_shared_class(unsigned int hash,
     485                                        Symbol* name) {

     486
     487   int index = this->hash_to_index(hash);
     488   DictionaryEntry* entry = get_entry(index, hash, name, NULL);
     489   if (entry != NULL) {
     490     return entry->klass();
     491   } else {
     492     return (Klass*)NULL;
     493   }
     494 }
     495
     496
     497 void Dictionary::add_protection_domain(unsigned int hash,
     498                                        instanceKlassHandle klass,
     499                                        ClassLoaderData* loader_data, Handle protection_domain,
     500                                        TRAPS) {
     501   Symbol*  klass_name = klass->name();
     502   int index = this->hash_to_index(hash);
     503   DictionaryEntry* entry = get_entry(index, hash, klass_name, loader_data);
     504
     505   assert(entry != NULL,"entry must be present, we just created it");
     506   assert(protection_domain() != NULL,
     507          "real protection domain should be present");
     508
     509   entry->add_protection_domain(this, protection_domain());
     510
     511   assert(entry->contains_protection_domain(protection_domain()),
     512          "now protection domain should be present");
     513 }
     514
     515
     516 bool Dictionary::is_valid_protection_domain(unsigned int hash,
     517                                             Symbol* name,
     518                                             ClassLoaderData* loader_data,
     519                                             Handle protection_domain) {
     520   int index = this->hash_to_index(hash);
     521   DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
     522
     523   assert(entry != NULL,"entry must be present");
     524
     525   return entry->is_valid_protection_domain(protection_domain);
     526 }
     527
     528
     529 void Dictionary::reorder_dictionary() {
     530
     531   // Copy all the dictionary entries into a single master list.
     532
     533   DictionaryEntry* master_list = NULL;
     534   for (int i = 0; i < table_size(); ++i) {
     535     DictionaryEntry* p = bucket(i);
     536     while (p != NULL) {
     537       DictionaryEntry* tmp;
     538       tmp = p->next();
     539       p->set_next(master_list);
     540       master_list = p;
     541       p = tmp;
     542     }
     543     set_entry(i, NULL);
     544   }
     763 }
     764
     765 void SymbolPropertyTable::methods_do(void f(Method*)) {
     766   for (int index = 0; index < table_size(); index++) {
     767     for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
     768       Method* prop = p->method();
     769       if (prop != NULL) {
     770         f((Method*)prop);
     771       }
     772     }
     773   }
     774 }
     775
     776
     777 // ----------------------------------------------------------------------------
     778
     779 void Dictionary::print(bool details) {
     780   ResourceMark rm;
     781   HandleMark   hm;
     782
     783   dump_table(tty, "SystemDictionary");//gznote: here
     784   tty->cr();
     785
     786   if (details) {
     787     tty->print_cr("Java system dictionary (table_size=%d, classes=%d)",
     788                    table_size(), number_of_entries());
     789     tty->print_cr("^ indicates that initiating loader is different from "
     790                   "defining loader");
     791   }
     792
     793   for (int index = 0; index < table_size(); index++) {
     794     for (DictionaryEntry* probe = bucket(index);
     795                           probe != NULL;
     796                           probe = probe->next()) {
     797       if (Verbose) tty->print("%4d: ", index);
     798       Klass* e = probe->klass();
     799       ClassLoaderData* loader_data =  probe->loader_data();
     800       bool is_defining_class =
     801          (loader_data == InstanceKlass::cast(e)->class_loader_data());
     802       tty->print("%s%s", ((!details) || is_defining_class) ? " " : "^",
     803                    e->external_name());
     804
     805       if (details) {
     807         if (loader_data != NULL) {
     808           loader_data->print_value();
     809         } else {
     810           tty->print("NULL");
     811         }
     812       }
     813       tty->cr();
     814     }
     815   }
     816
     817   if (details) {
     818     tty->cr();
     819     _pd_cache_table->print();
     820   }
     821   tty->cr();
     822 }
     823
     824 void Dictionary::verify() {
     825   guarantee(number_of_entries() >= 0, "Verify of system dictionary failed");
     826
     827   MutexLocker mu(SystemDictionary_lock);
     828   int actual_count = 0;
     829
     830   int element_count = 0;
     831   for (int index = 0; index < table_size(); index++) {
     832     for (DictionaryEntry* probe = bucket(index);
     833                           probe != NULL;
     834                           probe = probe->next()) {
     835       Klass* e = probe->klass();
     836       ClassLoaderData* loader_data = probe->loader_data();
     837       guarantee(e->oop_is_instance(),
     838                               "Verify of system dictionary failed");
     839       // class loader must be present;  a null class loader is the
     840       // boostrap loader
     841       guarantee(loader_data != NULL || DumpSharedSpaces ||
     842                 loader_data->class_loader() == NULL ||
     843                 loader_data->class_loader()->is_instance(),
     844                 "checking type of class_loader");
     845       e->verify();
     846       probe->verify_protection_domain_set();
     847       actual_count++;
     848     }
     849   }
     850   guarantee(number_of_entries() == actual_count, "should be equal");

     851   debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
     852
     853   _pd_cache_table->verify();
     854 }
     855

src/share/vm/classfile/dictionary.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File