src/hotspot/share/oops/instanceKlass.cpp
changeset 51329 9c68699bebe5
parent 51268 4ac20e5f96ce
child 51334 cc2c79d22508
equal deleted inserted replaced
51328:fad2334b2906 51329:9c68699bebe5
   437   }
   437   }
   438 }
   438 }
   439 
   439 
   440 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
   440 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
   441                                           const Klass* super_klass,
   441                                           const Klass* super_klass,
   442                                           Array<Klass*>* local_interfaces,
   442                                           Array<InstanceKlass*>* local_interfaces,
   443                                           Array<Klass*>* transitive_interfaces) {
   443                                           Array<InstanceKlass*>* transitive_interfaces) {
   444   // Only deallocate transitive interfaces if not empty, same as super class
   444   // Only deallocate transitive interfaces if not empty, same as super class
   445   // or same as local interfaces.  See code in parseClassFile.
   445   // or same as local interfaces.  See code in parseClassFile.
   446   Array<Klass*>* ti = transitive_interfaces;
   446   Array<InstanceKlass*>* ti = transitive_interfaces;
   447   if (ti != Universe::the_empty_klass_array() && ti != local_interfaces) {
   447   if (ti != Universe::the_empty_instance_klass_array() && ti != local_interfaces) {
   448     // check that the interfaces don't come from super class
   448     // check that the interfaces don't come from super class
   449     Array<Klass*>* sti = (super_klass == NULL) ? NULL :
   449     Array<InstanceKlass*>* sti = (super_klass == NULL) ? NULL :
   450                     InstanceKlass::cast(super_klass)->transitive_interfaces();
   450                     InstanceKlass::cast(super_klass)->transitive_interfaces();
   451     if (ti != sti && ti != NULL && !ti->is_shared()) {
   451     if (ti != sti && ti != NULL && !ti->is_shared()) {
   452       MetadataFactory::free_array<Klass*>(loader_data, ti);
   452       MetadataFactory::free_array<InstanceKlass*>(loader_data, ti);
   453     }
   453     }
   454   }
   454   }
   455 
   455 
   456   // local interfaces can be empty
   456   // local interfaces can be empty
   457   if (local_interfaces != Universe::the_empty_klass_array() &&
   457   if (local_interfaces != Universe::the_empty_instance_klass_array() &&
   458       local_interfaces != NULL && !local_interfaces->is_shared()) {
   458       local_interfaces != NULL && !local_interfaces->is_shared()) {
   459     MetadataFactory::free_array<Klass*>(loader_data, local_interfaces);
   459     MetadataFactory::free_array<InstanceKlass*>(loader_data, local_interfaces);
   460   }
   460   }
   461 }
   461 }
   462 
   462 
   463 // This function deallocates the metadata and C heap pointers that the
   463 // This function deallocates the metadata and C heap pointers that the
   464 // InstanceKlass points to.
   464 // InstanceKlass points to.
   515   // This array is in Klass, but remove it with the InstanceKlass since
   515   // This array is in Klass, but remove it with the InstanceKlass since
   516   // this place would be the only caller and it can share memory with transitive
   516   // this place would be the only caller and it can share memory with transitive
   517   // interfaces.
   517   // interfaces.
   518   if (secondary_supers() != NULL &&
   518   if (secondary_supers() != NULL &&
   519       secondary_supers() != Universe::the_empty_klass_array() &&
   519       secondary_supers() != Universe::the_empty_klass_array() &&
   520       secondary_supers() != transitive_interfaces() &&
   520       // see comments in compute_secondary_supers about the following cast
       
   521       (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
   521       !secondary_supers()->is_shared()) {
   522       !secondary_supers()->is_shared()) {
   522     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
   523     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
   523   }
   524   }
   524   set_secondary_supers(NULL);
   525   set_secondary_supers(NULL);
   525 
   526 
   753     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
   754     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
   754     ik_super->link_class_impl(throw_verifyerror, CHECK_false);
   755     ik_super->link_class_impl(throw_verifyerror, CHECK_false);
   755   }
   756   }
   756 
   757 
   757   // link all interfaces implemented by this class before linking this class
   758   // link all interfaces implemented by this class before linking this class
   758   Array<Klass*>* interfaces = local_interfaces();
   759   Array<InstanceKlass*>* interfaces = local_interfaces();
   759   int num_interfaces = interfaces->length();
   760   int num_interfaces = interfaces->length();
   760   for (int index = 0; index < num_interfaces; index++) {
   761   for (int index = 0; index < num_interfaces; index++) {
   761     InstanceKlass* interk = InstanceKlass::cast(interfaces->at(index));
   762     InstanceKlass* interk = interfaces->at(index);
   762     interk->link_class_impl(throw_verifyerror, CHECK_false);
   763     interk->link_class_impl(throw_verifyerror, CHECK_false);
   763   }
   764   }
   764 
   765 
   765   // in case the class is linked in the process of linking its superclasses
   766   // in case the class is linked in the process of linking its superclasses
   766   if (is_linked()) {
   767   if (is_linked()) {
   870 
   871 
   871 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
   872 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
   872 void InstanceKlass::initialize_super_interfaces(TRAPS) {
   873 void InstanceKlass::initialize_super_interfaces(TRAPS) {
   873   assert (has_nonstatic_concrete_methods(), "caller should have checked this");
   874   assert (has_nonstatic_concrete_methods(), "caller should have checked this");
   874   for (int i = 0; i < local_interfaces()->length(); ++i) {
   875   for (int i = 0; i < local_interfaces()->length(); ++i) {
   875     Klass* iface = local_interfaces()->at(i);
   876     InstanceKlass* ik = local_interfaces()->at(i);
   876     InstanceKlass* ik = InstanceKlass::cast(iface);
       
   877 
   877 
   878     // Initialization is depth first search ie. we start with top of the inheritance tree
   878     // Initialization is depth first search ie. we start with top of the inheritance tree
   879     // has_nonstatic_concrete_methods drives searching superinterfaces since it
   879     // has_nonstatic_concrete_methods drives searching superinterfaces since it
   880     // means has_nonstatic_concrete_methods in its superinterface hierarchy
   880     // means has_nonstatic_concrete_methods in its superinterface hierarchy
   881     if (ik->has_nonstatic_concrete_methods()) {
   881     if (ik->has_nonstatic_concrete_methods()) {
  1115   else
  1115   else
  1116     return Klass::can_be_primary_super_slow();
  1116     return Klass::can_be_primary_super_slow();
  1117 }
  1117 }
  1118 
  1118 
  1119 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots,
  1119 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots,
  1120                                                                Array<Klass*>* transitive_interfaces) {
  1120                                                                Array<InstanceKlass*>* transitive_interfaces) {
  1121   // The secondaries are the implemented interfaces.
  1121   // The secondaries are the implemented interfaces.
  1122   Array<Klass*>* interfaces = transitive_interfaces;
  1122   Array<InstanceKlass*>* interfaces = transitive_interfaces;
  1123   int num_secondaries = num_extra_slots + interfaces->length();
  1123   int num_secondaries = num_extra_slots + interfaces->length();
  1124   if (num_secondaries == 0) {
  1124   if (num_secondaries == 0) {
  1125     // Must share this for correct bootstrapping!
  1125     // Must share this for correct bootstrapping!
  1126     set_secondary_supers(Universe::the_empty_klass_array());
  1126     set_secondary_supers(Universe::the_empty_klass_array());
  1127     return NULL;
  1127     return NULL;
  1128   } else if (num_extra_slots == 0) {
  1128   } else if (num_extra_slots == 0) {
  1129     // The secondary super list is exactly the same as the transitive interfaces.
  1129     // The secondary super list is exactly the same as the transitive interfaces, so
       
  1130     // let's use it instead of making a copy.
  1130     // Redefine classes has to be careful not to delete this!
  1131     // Redefine classes has to be careful not to delete this!
  1131     set_secondary_supers(interfaces);
  1132     // We need the cast because Array<Klass*> is NOT a supertype of Array<InstanceKlass*>,
       
  1133     // (but it's safe to do here because we won't write into _secondary_supers from this point on).
       
  1134     set_secondary_supers((Array<Klass*>*)(address)interfaces);
  1132     return NULL;
  1135     return NULL;
  1133   } else {
  1136   } else {
  1134     // Copy transitive interfaces to a temporary growable array to be constructed
  1137     // Copy transitive interfaces to a temporary growable array to be constructed
  1135     // into the secondary super list with extra slots.
  1138     // into the secondary super list with extra slots.
  1136     GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length());
  1139     GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length());
  1789 // Do NOT return private or static methods, new in JDK8 which are not externally visible
  1792 // Do NOT return private or static methods, new in JDK8 which are not externally visible
  1790 // They should only be found in the initial InterfaceMethodRef
  1793 // They should only be found in the initial InterfaceMethodRef
  1791 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
  1794 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
  1792                                                        Symbol* signature,
  1795                                                        Symbol* signature,
  1793                                                        DefaultsLookupMode defaults_mode) const {
  1796                                                        DefaultsLookupMode defaults_mode) const {
  1794   Array<Klass*>* all_ifs = transitive_interfaces();
  1797   Array<InstanceKlass*>* all_ifs = transitive_interfaces();
  1795   int num_ifs = all_ifs->length();
  1798   int num_ifs = all_ifs->length();
  1796   InstanceKlass *ik = NULL;
  1799   InstanceKlass *ik = NULL;
  1797   for (int i = 0; i < num_ifs; i++) {
  1800   for (int i = 0; i < num_ifs; i++) {
  1798     ik = InstanceKlass::cast(all_ifs->at(i));
  1801     ik = all_ifs->at(i);
  1799     Method* m = ik->lookup_method(name, signature);
  1802     Method* m = ik->lookup_method(name, signature);
  1800     if (m != NULL && m->is_public() && !m->is_static() &&
  1803     if (m != NULL && m->is_public() && !m->is_static() &&
  1801         ((defaults_mode != skip_defaults) || !m->is_default_method())) {
  1804         ((defaults_mode != skip_defaults) || !m->is_default_method())) {
  1802       return m;
  1805       return m;
  1803     }
  1806     }
  2140     ResourceMark rm;
  2143     ResourceMark rm;
  2141     log_trace(class, fingerprint)("%s : super %s not fingerprinted", external_name(), java_super()->external_name());
  2144     log_trace(class, fingerprint)("%s : super %s not fingerprinted", external_name(), java_super()->external_name());
  2142     return false;
  2145     return false;
  2143   }
  2146   }
  2144 
  2147 
  2145   Array<Klass*>* local_interfaces = this->local_interfaces();
  2148   Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
  2146   if (local_interfaces != NULL) {
  2149   if (local_interfaces != NULL) {
  2147     int length = local_interfaces->length();
  2150     int length = local_interfaces->length();
  2148     for (int i = 0; i < length; i++) {
  2151     for (int i = 0; i < length; i++) {
  2149       InstanceKlass* intf = InstanceKlass::cast(local_interfaces->at(i));
  2152       InstanceKlass* intf = local_interfaces->at(i);
  2150       if (!intf->has_passed_fingerprint_check()) {
  2153       if (!intf->has_passed_fingerprint_check()) {
  2151         ResourceMark rm;
  2154         ResourceMark rm;
  2152         log_trace(class, fingerprint)("%s : interface %s not fingerprinted", external_name(), intf->external_name());
  2155         log_trace(class, fingerprint)("%s : interface %s not fingerprinted", external_name(), intf->external_name());
  2153         return false;
  2156         return false;
  2154       }
  2157       }
  2351         bad = true;
  2354         bad = true;
  2352         break;
  2355         break;
  2353       }
  2356       }
  2354     }
  2357     }
  2355     if (!bad) {
  2358     if (!bad) {
  2356       Array<Klass*>* interfaces = transitive_interfaces();
  2359       Array<InstanceKlass*>* interfaces = transitive_interfaces();
  2357       for (int i = 0; i < interfaces->length(); i++) {
  2360       for (int i = 0; i < interfaces->length(); i++) {
  2358         Klass* iface = interfaces->at(i);
  2361         InstanceKlass* iface = interfaces->at(i);
  2359         if (InstanceKlass::cast(iface)->is_in_error_state()) {
  2362         if (iface->is_in_error_state()) {
  2360           bad = true;
  2363           bad = true;
  2361           break;
  2364           break;
  2362         }
  2365         }
  2363       }
  2366       }
  2364     }
  2367     }
  3250   } else if (this == SystemDictionary::MethodType_klass()) {
  3253   } else if (this == SystemDictionary::MethodType_klass()) {
  3251     st->print(BULLET"signature: ");
  3254     st->print(BULLET"signature: ");
  3252     java_lang_invoke_MethodType::print_signature(obj, st);
  3255     java_lang_invoke_MethodType::print_signature(obj, st);
  3253     st->cr();
  3256     st->cr();
  3254   }
  3257   }
       
  3258 }
       
  3259 
       
  3260 bool InstanceKlass::verify_itable_index(int i) {
       
  3261   int method_count = klassItable::method_count_for_interface(this);
       
  3262   assert(i >= 0 && i < method_count, "index out of bounds");
       
  3263   return true;
  3255 }
  3264 }
  3256 
  3265 
  3257 #endif //PRODUCT
  3266 #endif //PRODUCT
  3258 
  3267 
  3259 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) {
  3268 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) {
  3496       "implementors cannot be interfaces");
  3505       "implementors cannot be interfaces");
  3497   }
  3506   }
  3498 
  3507 
  3499   // Verify local interfaces
  3508   // Verify local interfaces
  3500   if (local_interfaces()) {
  3509   if (local_interfaces()) {
  3501     Array<Klass*>* local_interfaces = this->local_interfaces();
  3510     Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
  3502     for (int j = 0; j < local_interfaces->length(); j++) {
  3511     for (int j = 0; j < local_interfaces->length(); j++) {
  3503       Klass* e = local_interfaces->at(j);
  3512       InstanceKlass* e = local_interfaces->at(j);
  3504       guarantee(e->is_klass() && e->is_interface(), "invalid local interface");
  3513       guarantee(e->is_klass() && e->is_interface(), "invalid local interface");
  3505     }
  3514     }
  3506   }
  3515   }
  3507 
  3516 
  3508   // Verify transitive interfaces
  3517   // Verify transitive interfaces
  3509   if (transitive_interfaces() != NULL) {
  3518   if (transitive_interfaces() != NULL) {
  3510     Array<Klass*>* transitive_interfaces = this->transitive_interfaces();
  3519     Array<InstanceKlass*>* transitive_interfaces = this->transitive_interfaces();
  3511     for (int j = 0; j < transitive_interfaces->length(); j++) {
  3520     for (int j = 0; j < transitive_interfaces->length(); j++) {
  3512       Klass* e = transitive_interfaces->at(j);
  3521       InstanceKlass* e = transitive_interfaces->at(j);
  3513       guarantee(e->is_klass() && e->is_interface(), "invalid transitive interface");
  3522       guarantee(e->is_klass() && e->is_interface(), "invalid transitive interface");
  3514     }
  3523     }
  3515   }
  3524   }
  3516 
  3525 
  3517   // Verify methods
  3526   // Verify methods