< prev index next >

src/hotspot/share/oops/klassVtable.cpp

Print this page




 675     } else {
 676       break;
 677     }
 678   }
 679 
 680   // If found_pkg_prvt_method is set, then the ONLY matching method in the
 681   // superclasses is package private in another package. That matching method will
 682   // prevent a miranda vtable entry from being created. Because the target method can not
 683   // override the package private method in another package, then it needs to be the root
 684   // for its own vtable entry.
 685   if (found_pkg_prvt_method) {
 686      return true;
 687   }
 688 
 689   // if the target method is public or protected it may have a matching
 690   // miranda method in the super, whose entry it should re-use.
 691   // Actually, to handle cases that javac would not generate, we need
 692   // this check for all access permissions.
 693   const InstanceKlass *sk = InstanceKlass::cast(super);
 694   if (sk->has_miranda_methods()) {
 695     if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) {
 696       return false; // found a matching miranda; we do not need a new entry
 697     }
 698   }
 699   return true; // found no match; we need a new entry
 700 }
 701 
 702 // Support for miranda methods
 703 
 704 // get the vtable index of a miranda method with matching "name" and "signature"
 705 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) {
 706   // search from the bottom, might be faster
 707   for (int i = (length() - 1); i >= 0; i--) {
 708     Method* m = table()[i].method();
 709     if (is_miranda_entry_at(i) &&
 710         m->name() == name && m->signature() == signature) {
 711       return i;
 712     }
 713   }
 714   return Method::invalid_vtable_index;
 715 }


 780 //
 781 // Pass 3: They are also checked by link resolution and selection,
 782 // for invocation on a method (not interface method) reference that
 783 // resolves to a method with an interface as its method_holder.
 784 // Used as part of walking from the bottom of the vtable to find
 785 // the vtable index for the miranda method.
 786 //
 787 // Part of the Miranda Rights in the US mean that if you do not have
 788 // an attorney one will be appointed for you.
 789 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
 790                              Array<Method*>* default_methods, const Klass* super,
 791                              bool is_interface) {
 792   if (m->is_static() || m->is_private() || m->is_overpass()) {
 793     return false;
 794   }
 795   Symbol* name = m->name();
 796   Symbol* signature = m->signature();
 797 
 798   // First look in local methods to see if already covered
 799   if (InstanceKlass::find_local_method(class_methods, name, signature,
 800               Klass::find_overpass, Klass::skip_static, Klass::skip_private) != NULL)


 801   {
 802     return false;
 803   }
 804 
 805   // Check local default methods
 806   if ((default_methods != NULL) &&
 807     (InstanceKlass::find_method(default_methods, name, signature) != NULL))
 808    {
 809      return false;
 810    }
 811 
 812   // Iterate on all superclasses, which should be InstanceKlasses.
 813   // Note that we explicitly look for overpasses at each level.
 814   // Overpasses may or may not exist for supers for pass 1,
 815   // they should have been created for pass 2 and later.
 816 
 817   for (const Klass* cursuper = super; cursuper != NULL; cursuper = cursuper->super())
 818   {
 819      Method* found_mth = InstanceKlass::cast(cursuper)->find_local_method(name, signature,
 820        Klass::find_overpass, Klass::skip_static, Klass::skip_private);


 821      // Ignore non-public methods in java.lang.Object if klass is an interface.
 822      if (found_mth != NULL && (!is_interface ||
 823          !SystemDictionary::is_nonpublic_Object_method(found_mth))) {
 824        return false;
 825      }
 826   }
 827 
 828   return true;
 829 }
 830 
 831 // Scans current_interface_methods for miranda methods that do not
 832 // already appear in new_mirandas, or default methods,  and are also not defined-and-non-private
 833 // in super (superclass).  These mirandas are added to all_mirandas if it is
 834 // not null; in addition, those that are not duplicates of miranda methods
 835 // inherited by super from its interfaces are added to new_mirandas.
 836 // Thus, new_mirandas will be the set of mirandas that this class introduces,
 837 // all_mirandas will be the set of all mirandas applicable to this class
 838 // including all defined in superclasses.
 839 void klassVtable::add_new_mirandas_to_lists(
 840     GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas,


 844   // iterate thru the current interface's method to see if it a miranda
 845   int num_methods = current_interface_methods->length();
 846   for (int i = 0; i < num_methods; i++) {
 847     Method* im = current_interface_methods->at(i);
 848     bool is_duplicate = false;
 849     int num_of_current_mirandas = new_mirandas->length();
 850     // check for duplicate mirandas in different interfaces we implement
 851     for (int j = 0; j < num_of_current_mirandas; j++) {
 852       Method* miranda = new_mirandas->at(j);
 853       if ((im->name() == miranda->name()) &&
 854           (im->signature() == miranda->signature())) {
 855         is_duplicate = true;
 856         break;
 857       }
 858     }
 859 
 860     if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable
 861       if (is_miranda(im, class_methods, default_methods, super, is_interface)) { // is it a miranda at all?
 862         const InstanceKlass *sk = InstanceKlass::cast(super);
 863         // check if it is a duplicate of a super's miranda
 864         if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::find_defaults) == NULL) {
 865           new_mirandas->append(im);
 866         }
 867         if (all_mirandas != NULL) {
 868           all_mirandas->append(im);
 869         }
 870       }
 871     }
 872   }
 873 }
 874 
 875 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas,
 876                                GrowableArray<Method*>* all_mirandas,
 877                                const Klass* super,
 878                                Array<Method*>* class_methods,
 879                                Array<Method*>* default_methods,
 880                                Array<InstanceKlass*>* local_interfaces,
 881                                bool is_interface) {
 882   assert((new_mirandas->length() == 0) , "current mirandas must be 0");
 883 
 884   // iterate thru the local interfaces looking for a miranda


1196 
1197 void klassItable::initialize_itable_for_interface(int method_table_offset, InstanceKlass* interf, bool checkconstraints, TRAPS) {
1198   assert(interf->is_interface(), "must be");
1199   Array<Method*>* methods = interf->methods();
1200   int nof_methods = methods->length();
1201   HandleMark hm(THREAD);
1202   Handle interface_loader (THREAD, interf->class_loader());
1203 
1204   int ime_count = method_count_for_interface(interf);
1205   for (int i = 0; i < nof_methods; i++) {
1206     Method* m = methods->at(i);
1207     Method* target = NULL;
1208     if (m->has_itable_index()) {
1209       // This search must match the runtime resolution, i.e. selection search for invokeinterface
1210       // to correctly enforce loader constraints for interface method inheritance.
1211       // Private methods are skipped as a private class method can never be the implementation
1212       // of an interface method.
1213       // Invokespecial does not perform selection based on the receiver, so it does not use
1214       // the cached itable.
1215       target = LinkResolver::lookup_instance_method_in_klasses(_klass, m->name(), m->signature(),
1216                                                                Klass::skip_private, CHECK);
1217     }
1218     if (target == NULL || !target->is_public() || target->is_abstract() || target->is_overpass()) {
1219       assert(target == NULL || !target->is_overpass() || target->is_public(),
1220              "Non-public overpass method!");
1221       // Entry does not resolve. Leave it empty for AbstractMethodError or other error.
1222       if (!(target == NULL) && !target->is_public()) {
1223         // Stuff an IllegalAccessError throwing method in there instead.
1224         itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
1225             initialize(Universe::throw_illegal_access_error());
1226       }
1227     } else {
1228       // Entry did resolve, check loader constraints before initializing
1229       // if checkconstraints requested
1230       if (checkconstraints) {
1231         Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1232         InstanceKlass* method_holder = target->method_holder();
1233         if (method_holder_loader() != interface_loader()) {
1234           ResourceMark rm(THREAD);
1235           Symbol* failed_type_symbol =
1236             SystemDictionary::check_signature_loaders(m->signature(),




 675     } else {
 676       break;
 677     }
 678   }
 679 
 680   // If found_pkg_prvt_method is set, then the ONLY matching method in the
 681   // superclasses is package private in another package. That matching method will
 682   // prevent a miranda vtable entry from being created. Because the target method can not
 683   // override the package private method in another package, then it needs to be the root
 684   // for its own vtable entry.
 685   if (found_pkg_prvt_method) {
 686      return true;
 687   }
 688 
 689   // if the target method is public or protected it may have a matching
 690   // miranda method in the super, whose entry it should re-use.
 691   // Actually, to handle cases that javac would not generate, we need
 692   // this check for all access permissions.
 693   const InstanceKlass *sk = InstanceKlass::cast(super);
 694   if (sk->has_miranda_methods()) {
 695     if (sk->lookup_method_in_all_interfaces(name, signature, Klass::DefaultsLookupMode::find_defaults) != NULL) {
 696       return false; // found a matching miranda; we do not need a new entry
 697     }
 698   }
 699   return true; // found no match; we need a new entry
 700 }
 701 
 702 // Support for miranda methods
 703 
 704 // get the vtable index of a miranda method with matching "name" and "signature"
 705 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) {
 706   // search from the bottom, might be faster
 707   for (int i = (length() - 1); i >= 0; i--) {
 708     Method* m = table()[i].method();
 709     if (is_miranda_entry_at(i) &&
 710         m->name() == name && m->signature() == signature) {
 711       return i;
 712     }
 713   }
 714   return Method::invalid_vtable_index;
 715 }


 780 //
 781 // Pass 3: They are also checked by link resolution and selection,
 782 // for invocation on a method (not interface method) reference that
 783 // resolves to a method with an interface as its method_holder.
 784 // Used as part of walking from the bottom of the vtable to find
 785 // the vtable index for the miranda method.
 786 //
 787 // Part of the Miranda Rights in the US mean that if you do not have
 788 // an attorney one will be appointed for you.
 789 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
 790                              Array<Method*>* default_methods, const Klass* super,
 791                              bool is_interface) {
 792   if (m->is_static() || m->is_private() || m->is_overpass()) {
 793     return false;
 794   }
 795   Symbol* name = m->name();
 796   Symbol* signature = m->signature();
 797 
 798   // First look in local methods to see if already covered
 799   if (InstanceKlass::find_local_method(class_methods, name, signature,
 800                                        Klass::OverpassLookupMode::find_overpass,
 801                                        Klass::StaticLookupMode::skip_static,
 802                                        Klass::PrivateLookupMode::skip_private) != NULL)
 803   {
 804     return false;
 805   }
 806 
 807   // Check local default methods
 808   if ((default_methods != NULL) &&
 809     (InstanceKlass::find_method(default_methods, name, signature) != NULL))
 810    {
 811      return false;
 812    }
 813 
 814   // Iterate on all superclasses, which should be InstanceKlasses.
 815   // Note that we explicitly look for overpasses at each level.
 816   // Overpasses may or may not exist for supers for pass 1,
 817   // they should have been created for pass 2 and later.
 818 
 819   for (const Klass* cursuper = super; cursuper != NULL; cursuper = cursuper->super())
 820   {
 821      Method* found_mth = InstanceKlass::cast(cursuper)->find_local_method(name, signature,
 822                                                                           Klass::OverpassLookupMode::find_overpass,
 823                                                                           Klass::StaticLookupMode::skip_static,
 824                                                                           Klass::PrivateLookupMode::skip_private);
 825      // Ignore non-public methods in java.lang.Object if klass is an interface.
 826      if (found_mth != NULL && (!is_interface ||
 827          !SystemDictionary::is_nonpublic_Object_method(found_mth))) {
 828        return false;
 829      }
 830   }
 831 
 832   return true;
 833 }
 834 
 835 // Scans current_interface_methods for miranda methods that do not
 836 // already appear in new_mirandas, or default methods,  and are also not defined-and-non-private
 837 // in super (superclass).  These mirandas are added to all_mirandas if it is
 838 // not null; in addition, those that are not duplicates of miranda methods
 839 // inherited by super from its interfaces are added to new_mirandas.
 840 // Thus, new_mirandas will be the set of mirandas that this class introduces,
 841 // all_mirandas will be the set of all mirandas applicable to this class
 842 // including all defined in superclasses.
 843 void klassVtable::add_new_mirandas_to_lists(
 844     GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas,


 848   // iterate thru the current interface's method to see if it a miranda
 849   int num_methods = current_interface_methods->length();
 850   for (int i = 0; i < num_methods; i++) {
 851     Method* im = current_interface_methods->at(i);
 852     bool is_duplicate = false;
 853     int num_of_current_mirandas = new_mirandas->length();
 854     // check for duplicate mirandas in different interfaces we implement
 855     for (int j = 0; j < num_of_current_mirandas; j++) {
 856       Method* miranda = new_mirandas->at(j);
 857       if ((im->name() == miranda->name()) &&
 858           (im->signature() == miranda->signature())) {
 859         is_duplicate = true;
 860         break;
 861       }
 862     }
 863 
 864     if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable
 865       if (is_miranda(im, class_methods, default_methods, super, is_interface)) { // is it a miranda at all?
 866         const InstanceKlass *sk = InstanceKlass::cast(super);
 867         // check if it is a duplicate of a super's miranda
 868         if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::DefaultsLookupMode::find_defaults) == NULL) {
 869           new_mirandas->append(im);
 870         }
 871         if (all_mirandas != NULL) {
 872           all_mirandas->append(im);
 873         }
 874       }
 875     }
 876   }
 877 }
 878 
 879 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas,
 880                                GrowableArray<Method*>* all_mirandas,
 881                                const Klass* super,
 882                                Array<Method*>* class_methods,
 883                                Array<Method*>* default_methods,
 884                                Array<InstanceKlass*>* local_interfaces,
 885                                bool is_interface) {
 886   assert((new_mirandas->length() == 0) , "current mirandas must be 0");
 887 
 888   // iterate thru the local interfaces looking for a miranda


1200 
1201 void klassItable::initialize_itable_for_interface(int method_table_offset, InstanceKlass* interf, bool checkconstraints, TRAPS) {
1202   assert(interf->is_interface(), "must be");
1203   Array<Method*>* methods = interf->methods();
1204   int nof_methods = methods->length();
1205   HandleMark hm(THREAD);
1206   Handle interface_loader (THREAD, interf->class_loader());
1207 
1208   int ime_count = method_count_for_interface(interf);
1209   for (int i = 0; i < nof_methods; i++) {
1210     Method* m = methods->at(i);
1211     Method* target = NULL;
1212     if (m->has_itable_index()) {
1213       // This search must match the runtime resolution, i.e. selection search for invokeinterface
1214       // to correctly enforce loader constraints for interface method inheritance.
1215       // Private methods are skipped as a private class method can never be the implementation
1216       // of an interface method.
1217       // Invokespecial does not perform selection based on the receiver, so it does not use
1218       // the cached itable.
1219       target = LinkResolver::lookup_instance_method_in_klasses(_klass, m->name(), m->signature(),
1220                                                                Klass::PrivateLookupMode::skip_private, CHECK);
1221     }
1222     if (target == NULL || !target->is_public() || target->is_abstract() || target->is_overpass()) {
1223       assert(target == NULL || !target->is_overpass() || target->is_public(),
1224              "Non-public overpass method!");
1225       // Entry does not resolve. Leave it empty for AbstractMethodError or other error.
1226       if (!(target == NULL) && !target->is_public()) {
1227         // Stuff an IllegalAccessError throwing method in there instead.
1228         itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
1229             initialize(Universe::throw_illegal_access_error());
1230       }
1231     } else {
1232       // Entry did resolve, check loader constraints before initializing
1233       // if checkconstraints requested
1234       if (checkconstraints) {
1235         Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1236         InstanceKlass* method_holder = target->method_holder();
1237         if (method_holder_loader() != interface_loader()) {
1238           ResourceMark rm(THREAD);
1239           Symbol* failed_type_symbol =
1240             SystemDictionary::check_signature_loaders(m->signature(),


< prev index next >