src/hotspot/share/classfile/systemDictionary.cpp
changeset 51329 9c68699bebe5
parent 51268 4ac20e5f96ce
child 51375 b812a85b3aa4
equal deleted inserted replaced
51328:fad2334b2906 51329:9c68699bebe5
   240 {
   240 {
   241   return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
   241   return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
   242 }
   242 }
   243 
   243 
   244 
   244 
   245 // Forwards to resolve_instance_class_or_null
   245 // Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
   246 
   246 
   247 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
   247 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
   248   if (FieldType::is_array(class_name)) {
   248   if (FieldType::is_array(class_name)) {
   249     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
   249     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
   250   } else if (FieldType::is_obj(class_name)) {
   250   } else {
       
   251     return resolve_instance_class_or_null_helper(class_name, class_loader, protection_domain, THREAD);
       
   252   }
       
   253 }
       
   254 
       
   255 // name may be in the form of "java/lang/Object" or "Ljava/lang/Object;"
       
   256 InstanceKlass* SystemDictionary::resolve_instance_class_or_null_helper(Symbol* class_name,
       
   257                                                                        Handle class_loader,
       
   258                                                                        Handle protection_domain,
       
   259                                                                        TRAPS) {
       
   260   assert(class_name != NULL && !FieldType::is_array(class_name), "must be");
       
   261   if (FieldType::is_obj(class_name)) {
   251     ResourceMark rm(THREAD);
   262     ResourceMark rm(THREAD);
   252     // Ignore wrapping L and ;.
   263     // Ignore wrapping L and ;.
   253     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
   264     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
   254                                    class_name->utf8_length() - 2, CHECK_NULL);
   265                                    class_name->utf8_length() - 2, CHECK_NULL);
   255     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
   266     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
   328 // thread is loading this class/classloader.
   339 // thread is loading this class/classloader.
   329 // Be careful when modifying this code: once you have run
   340 // Be careful when modifying this code: once you have run
   330 // placeholders()->find_and_add(PlaceholderTable::LOAD_SUPER),
   341 // placeholders()->find_and_add(PlaceholderTable::LOAD_SUPER),
   331 // you need to find_and_remove it before returning.
   342 // you need to find_and_remove it before returning.
   332 // So be careful to not exit with a CHECK_ macro betweeen these calls.
   343 // So be careful to not exit with a CHECK_ macro betweeen these calls.
   333 Klass* SystemDictionary::resolve_super_or_fail(Symbol* child_name,
   344 InstanceKlass* SystemDictionary::resolve_super_or_fail(Symbol* child_name,
   334                                                  Symbol* class_name,
   345                                                        Symbol* super_name,
   335                                                  Handle class_loader,
   346                                                        Handle class_loader,
   336                                                  Handle protection_domain,
   347                                                        Handle protection_domain,
   337                                                  bool is_superclass,
   348                                                        bool is_superclass,
   338                                                  TRAPS) {
   349                                                        TRAPS) {
       
   350   assert(!FieldType::is_array(super_name), "invalid super class name");
   339 #if INCLUDE_CDS
   351 #if INCLUDE_CDS
   340   if (DumpSharedSpaces) {
   352   if (DumpSharedSpaces) {
   341     // Special processing for CDS dump time.
   353     // Special processing for CDS dump time.
   342     Klass* k = SystemDictionaryShared::dump_time_resolve_super_or_fail(child_name,
   354     InstanceKlass* k = SystemDictionaryShared::dump_time_resolve_super_or_fail(child_name,
   343         class_name, class_loader, protection_domain, is_superclass, CHECK_NULL);
   355         super_name, class_loader, protection_domain, is_superclass, CHECK_NULL);
   344     if (k) {
   356     if (k) {
   345       return k;
   357       return k;
   346     }
   358     }
   347   }
   359   }
   348 #endif // INCLUDE_CDS
   360 #endif // INCLUDE_CDS
   370   // can't throw error holding a lock
   382   // can't throw error holding a lock
   371   bool child_already_loaded = false;
   383   bool child_already_loaded = false;
   372   bool throw_circularity_error = false;
   384   bool throw_circularity_error = false;
   373   {
   385   {
   374     MutexLocker mu(SystemDictionary_lock, THREAD);
   386     MutexLocker mu(SystemDictionary_lock, THREAD);
   375     Klass* childk = find_class(d_hash, child_name, dictionary);
   387     InstanceKlass* childk = find_class(d_hash, child_name, dictionary);
   376     Klass* quicksuperk;
   388     InstanceKlass* quicksuperk;
   377     // to support // loading: if child done loading, just return superclass
   389     // to support // loading: if child done loading, just return superclass
   378     // if class_name, & class_loader don't match:
   390     // if super_name, & class_loader don't match:
   379     // if initial define, SD update will give LinkageError
   391     // if initial define, SD update will give LinkageError
   380     // if redefine: compare_class_versions will give HIERARCHY_CHANGED
   392     // if redefine: compare_class_versions will give HIERARCHY_CHANGED
   381     // so we don't throw an exception here.
   393     // so we don't throw an exception here.
   382     // see: nsk redefclass014 & java.lang.instrument Instrument032
   394     // see: nsk redefclass014 & java.lang.instrument Instrument032
   383     if ((childk != NULL ) && (is_superclass) &&
   395     if ((childk != NULL ) && (is_superclass) &&
   384        ((quicksuperk = childk->super()) != NULL) &&
   396         ((quicksuperk = childk->java_super()) != NULL) &&
   385 
   397          ((quicksuperk->name() == super_name) &&
   386          ((quicksuperk->name() == class_name) &&
       
   387             (oopDesc::equals(quicksuperk->class_loader(), class_loader())))) {
   398             (oopDesc::equals(quicksuperk->class_loader(), class_loader())))) {
   388            return quicksuperk;
   399            return quicksuperk;
   389     } else {
   400     } else {
   390       PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data);
   401       PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data);
   391       if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
   402       if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
   392           throw_circularity_error = true;
   403           throw_circularity_error = true;
   393       }
   404       }
   394     }
   405     }
   395     if (!throw_circularity_error) {
   406     if (!throw_circularity_error) {
   396       // Be careful not to exit resolve_super
   407       // Be careful not to exit resolve_super
   397       PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, class_name, THREAD);
   408       PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, super_name, THREAD);
   398     }
   409     }
   399   }
   410   }
   400   if (throw_circularity_error) {
   411   if (throw_circularity_error) {
   401       ResourceMark rm(THREAD);
   412       ResourceMark rm(THREAD);
   402       THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
   413       THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
   403   }
   414   }
   404 
   415 
   405 // java.lang.Object should have been found above
   416 // java.lang.Object should have been found above
   406   assert(class_name != NULL, "null super class for resolving");
   417   assert(super_name != NULL, "null super class for resolving");
   407   // Resolve the super class or interface, check results on return
   418   // Resolve the super class or interface, check results on return
   408   Klass* superk = SystemDictionary::resolve_or_null(class_name,
   419   InstanceKlass* superk =
   409                                                     class_loader,
   420     SystemDictionary::resolve_instance_class_or_null_helper(super_name,
   410                                                     protection_domain,
   421                                                             class_loader,
   411                                                     THREAD);
   422                                                             protection_domain,
       
   423                                                             THREAD);
   412 
   424 
   413   // Clean up of placeholders moved so that each classloadAction registrar self-cleans up
   425   // Clean up of placeholders moved so that each classloadAction registrar self-cleans up
   414   // It is no longer necessary to keep the placeholder table alive until update_dictionary
   426   // It is no longer necessary to keep the placeholder table alive until update_dictionary
   415   // or error. GC used to walk the placeholder table as strong roots.
   427   // or error. GC used to walk the placeholder table as strong roots.
   416   // The instanceKlass is kept alive because the class loader is on the stack,
   428   // The instanceKlass is kept alive because the class loader is on the stack,
   421     placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
   433     placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
   422     SystemDictionary_lock->notify_all();
   434     SystemDictionary_lock->notify_all();
   423   }
   435   }
   424   if (HAS_PENDING_EXCEPTION || superk == NULL) {
   436   if (HAS_PENDING_EXCEPTION || superk == NULL) {
   425     // can null superk
   437     // can null superk
   426     superk = handle_resolution_exception(class_name, true, superk, THREAD);
   438     Klass* k = handle_resolution_exception(super_name, true, superk, THREAD);
       
   439     assert(k == NULL || k == superk, "must be");
       
   440     if (k == NULL) {
       
   441       superk = NULL;
       
   442     }
   427   }
   443   }
   428 
   444 
   429   return superk;
   445   return superk;
   430 }
   446 }
   431 
   447 
   637 
   653 
   638 // Be careful when modifying this code: once you have run
   654 // Be careful when modifying this code: once you have run
   639 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
   655 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
   640 // you need to find_and_remove it before returning.
   656 // you need to find_and_remove it before returning.
   641 // So be careful to not exit with a CHECK_ macro betweeen these calls.
   657 // So be careful to not exit with a CHECK_ macro betweeen these calls.
   642 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
   658 //
   643                                                         Handle class_loader,
   659 // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
   644                                                         Handle protection_domain,
   660 InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
   645                                                         TRAPS) {
   661                                                                 Handle class_loader,
       
   662                                                                 Handle protection_domain,
       
   663                                                                 TRAPS) {
   646   assert(name != NULL && !FieldType::is_array(name) &&
   664   assert(name != NULL && !FieldType::is_array(name) &&
   647          !FieldType::is_obj(name), "invalid class name");
   665          !FieldType::is_obj(name), "invalid class name");
   648 
   666 
   649   EventClassLoad class_load_start_event;
   667   EventClassLoad class_load_start_event;
   650 
   668 
   661   // This call uses find which checks protection domain already matches
   679   // This call uses find which checks protection domain already matches
   662   // All subsequent calls use find_class, and set has_loaded_class so that
   680   // All subsequent calls use find_class, and set has_loaded_class so that
   663   // before we return a result we call out to java to check for valid protection domain
   681   // before we return a result we call out to java to check for valid protection domain
   664   // to allow returning the Klass* and add it to the pd_set if it is valid
   682   // to allow returning the Klass* and add it to the pd_set if it is valid
   665   {
   683   {
   666     Klass* probe = dictionary->find(d_hash, name, protection_domain);
   684     InstanceKlass* probe = dictionary->find(d_hash, name, protection_domain);
   667     if (probe != NULL) return probe;
   685     if (probe != NULL) return probe;
   668   }
   686   }
   669 
   687 
   670   // Non-bootstrap class loaders will call out to class loader and
   688   // Non-bootstrap class loaders will call out to class loader and
   671   // define via jvm/jni_DefineClass which will acquire the
   689   // define via jvm/jni_DefineClass which will acquire the
   704          class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string());
   722          class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string());
   705   {
   723   {
   706     MutexLocker mu(SystemDictionary_lock, THREAD);
   724     MutexLocker mu(SystemDictionary_lock, THREAD);
   707     InstanceKlass* check = find_class(d_hash, name, dictionary);
   725     InstanceKlass* check = find_class(d_hash, name, dictionary);
   708     if (check != NULL) {
   726     if (check != NULL) {
   709       // Klass is already loaded, so just return it
   727       // InstanceKlass is already loaded, so just return it
   710       class_has_been_loaded = true;
   728       class_has_been_loaded = true;
   711       k = check;
   729       k = check;
   712     } else {
   730     } else {
   713       placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
   731       placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
   714       if (placeholder && placeholder->super_load_in_progress()) {
   732       if (placeholder && placeholder->super_load_in_progress()) {
   875   }
   893   }
   876 #ifdef ASSERT
   894 #ifdef ASSERT
   877   {
   895   {
   878     ClassLoaderData* loader_data = k->class_loader_data();
   896     ClassLoaderData* loader_data = k->class_loader_data();
   879     MutexLocker mu(SystemDictionary_lock, THREAD);
   897     MutexLocker mu(SystemDictionary_lock, THREAD);
   880     Klass* kk = find_class(name, loader_data);
   898     InstanceKlass* kk = find_class(name, loader_data);
   881     assert(kk == k, "should be present in dictionary");
   899     assert(kk == k, "should be present in dictionary");
   882   }
   900   }
   883 #endif
   901 #endif
   884 
   902 
   885   // return if the protection domain in NULL
   903   // return if the protection domain in NULL
  1306       } else {
  1324       } else {
  1307         assert(s->is_shared(), "must be");
  1325         assert(s->is_shared(), "must be");
  1308       }
  1326       }
  1309     }
  1327     }
  1310 
  1328 
  1311     Array<Klass*>* interfaces = ik->local_interfaces();
  1329     Array<InstanceKlass*>* interfaces = ik->local_interfaces();
  1312     int num_interfaces = interfaces->length();
  1330     int num_interfaces = interfaces->length();
  1313     for (int index = 0; index < num_interfaces; index++) {
  1331     for (int index = 0; index < num_interfaces; index++) {
  1314       Klass* k = interfaces->at(index);
  1332       InstanceKlass* k = interfaces->at(index);
  1315       Symbol*  name  = k->name();
  1333       Symbol* name  = k->name();
  1316       Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL);
  1334       Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL);
  1317       if (k != i) {
  1335       if (k != i) {
  1318         // The dynamically resolved interface class is not the same as the one we used during dump time,
  1336         // The dynamically resolved interface class is not the same as the one we used during dump time,
  1319         // so we cannot use ik.
  1337         // so we cannot use ik.
  1320         return NULL;
  1338         return NULL;