src/share/vm/oops/klassVtable.cpp

Print this page




 666     Method* m = table()[i].method();
 667     if (is_miranda_entry_at(i) &&
 668         m->name() == name && m->signature() == signature) {
 669       return i;
 670     }
 671   }
 672   return Method::invalid_vtable_index;
 673 }
 674 
 675 // check if an entry at an index is miranda
 676 // requires that method m at entry be declared ("held") by an interface.
 677 bool klassVtable::is_miranda_entry_at(int i) {
 678   Method* m = method_at(i);
 679   Klass* method_holder = m->method_holder();
 680   InstanceKlass *mhk = InstanceKlass::cast(method_holder);
 681 
 682   // miranda methods are public abstract instance interface methods in a class's vtable
 683   if (mhk->is_interface()) {
 684     assert(m->is_public(), "should be public");
 685     assert(ik()->implements_interface(method_holder) , "this class should implement the interface");
 686     // the search could find a miranda or a default method
 687     if (is_miranda(m, ik()->methods(), ik()->default_methods(), ik()->super())) {
 688       return true;
 689     }
 690   }
 691   return false;
 692 }
 693 
 694 // check if a method is a miranda method, given a class's methods table,
 695 // its default_method table  and its super
 696 // Miranda methods are calculated twice:
 697 // first: before vtable size calculation: including abstract and superinterface default









 698 // We include potential default methods to give them space in the vtable.
 699 // During the first run, the default_methods list is empty
 700 // This is seen by default method creation
 701 // Second: recalculated during vtable initialization: only include abstract methods.



 702 // During the second run, default_methods is set up, so concrete methods from
 703 // superinterfaces with matching names/signatures to default_methods are already
 704 // in the default_methods list and do not need to be appended to the vtable
 705 // as mirandas
 706 // This is seen by link resolution and selection.
 707 // "miranda" means not static, not defined by this class.
 708 // private methods in interfaces do not belong in the miranda list.
 709 // the caller must make sure that the method belongs to an interface implemented by the class
 710 // Miranda methods only include public interface instance methods
 711 // Not private methods, not static methods, not default == concrete abstract
 712 // Miranda methods also do not include overpass methods in interfaces




 713 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
 714                              Array<Method*>* default_methods, Klass* super) {
 715   if (m->is_static() || m->is_private() || m->is_overpass()) {
 716     return false;
 717   }
 718   Symbol* name = m->name();
 719   Symbol* signature = m->signature();
 720   Method* mo;
 721 
 722   if ((mo = InstanceKlass::find_instance_method(class_methods, name, signature)) == NULL) {
 723     // did not find it in the method table of the current class
 724     if ((default_methods == NULL) ||
 725         InstanceKlass::find_method(default_methods, name, signature) == NULL) {
 726       if (super == NULL) {
 727         // super doesn't exist
 728         return true;
 729       }
 730 
 731       mo = InstanceKlass::cast(super)->lookup_method(name, signature);
 732       while (mo != NULL && mo->access_flags().is_static()
 733              && mo->method_holder() != NULL
 734              && mo->method_holder()->super() != NULL)
 735       {
 736          mo = mo->method_holder()->super()->uncached_lookup_method(name, signature, Klass::find_overpass);
 737       }
 738       if (mo == NULL || mo->access_flags().is_private() ) {
 739         // super class hierarchy does not implement it or protection is different
 740         return true;
 741       }
 742     }
 743   } else {
 744      // if the local class has a private method, the miranda will not
 745      // override it, so a vtable slot is needed
 746      if (mo->access_flags().is_private()) {
 747 
 748        // Second round, weed out any superinterface methods that turned
 749        // into default methods, i.e. were concrete not abstract in the end
 750        if ((default_methods == NULL) ||
 751          InstanceKlass::find_method(default_methods, name, signature) == NULL) {
 752          return true;
 753        }












 754     }
 755   }
 756 
 757   return false;
 758 }
 759 
 760 // Scans current_interface_methods for miranda methods that do not
 761 // already appear in new_mirandas, or default methods,  and are also not defined-and-non-private
 762 // in super (superclass).  These mirandas are added to all_mirandas if it is
 763 // not null; in addition, those that are not duplicates of miranda methods
 764 // inherited by super from its interfaces are added to new_mirandas.
 765 // Thus, new_mirandas will be the set of mirandas that this class introduces,
 766 // all_mirandas will be the set of all mirandas applicable to this class
 767 // including all defined in superclasses.
 768 void klassVtable::add_new_mirandas_to_lists(
 769     GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas,
 770     Array<Method*>* current_interface_methods, Array<Method*>* class_methods,
 771     Array<Method*>* default_methods, Klass* super) {
 772 
 773   // iterate thru the current interface's method to see if it a miranda
 774   int num_methods = current_interface_methods->length();
 775   for (int i = 0; i < num_methods; i++) {
 776     Method* im = current_interface_methods->at(i);
 777     bool is_duplicate = false;




 666     Method* m = table()[i].method();
 667     if (is_miranda_entry_at(i) &&
 668         m->name() == name && m->signature() == signature) {
 669       return i;
 670     }
 671   }
 672   return Method::invalid_vtable_index;
 673 }
 674 
 675 // check if an entry at an index is miranda
 676 // requires that method m at entry be declared ("held") by an interface.
 677 bool klassVtable::is_miranda_entry_at(int i) {
 678   Method* m = method_at(i);
 679   Klass* method_holder = m->method_holder();
 680   InstanceKlass *mhk = InstanceKlass::cast(method_holder);
 681 
 682   // miranda methods are public abstract instance interface methods in a class's vtable
 683   if (mhk->is_interface()) {
 684     assert(m->is_public(), "should be public");
 685     assert(ik()->implements_interface(method_holder) , "this class should implement the interface");

 686     if (is_miranda(m, ik()->methods(), ik()->default_methods(), ik()->super())) {
 687       return true;
 688     }
 689   }
 690   return false;
 691 }
 692 
 693 // Check if a method is a miranda method, given a class's methods table,
 694 // its default_method table and its super class.
 695 // "Miranda" means an abstract non-private method that would not be
 696 // overridden. A "miranda" method should only include non-private interface
 697 // instance methods, not private methods, not static methods, 
 698 // not default methods (concrete interface methods), not overpass methods.
 699 // If a given class already has a local (including overpass) method, a
 700 // default method, or any of its superclasses has the same which would have
 701 // overridden an abstract method, then this is not a miranda method.
 702 //
 703 // Miranda methods are checked multiple times.
 704 // Pass 1: during class load/class file parsing: before vtable size calculation: 
 705 // include superinterface abstract and default methods (non-private instance).
 706 // We include potential default methods to give them space in the vtable.
 707 // During the first run, the current instanceKlass has not yet been
 708 // created, the superclasses and superinterfaces do have instanceKlasses
 709 // but may not have vtables, the default_methods list is empty, no overpasses.
 710 // This is seen by default method creation.
 711 //
 712 // Pass 2: recalculated during vtable initialization: only include abstract methods.
 713 // During the second run, default_methods is set up, so concrete methods from
 714 // superinterfaces with matching names/signatures to default_methods are already
 715 // in the default_methods list and do not need to be appended to the vtable
 716 // as mirandas. Abstract methods may already have been handled via
 717 // overpasses - either local or superclass overpasses, which may be
 718 // in the vtable already.
 719 //
 720 // Pass 3: They are also checked by link resolution and selection,
 721 // for invocation on a method (not interface method) reference that
 722 // resolves to a method with an interface as its method_holder.
 723 // Used as part of walking from the bottom of the vtable to find
 724 // the vtable index for the miranda method.
 725 //
 726 // Part of the Miranda Rights in the US mean that if you do not have
 727 // an attorney one will be appointed to you.
 728 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
 729                              Array<Method*>* default_methods, Klass* super) {
 730   if (m->is_static() || m->is_private() || m->is_overpass()) {
 731     return false;
 732   }
 733   Symbol* name = m->name();
 734   Symbol* signature = m->signature();

 735 
 736   // First look in local methods to see if already covered
 737   if (InstanceKlass::find_local_method(class_methods, name, signature,
 738               Klass::find_overpass, Klass::skip_static, Klass::skip_private) != NULL) 
 739   {
 740     return false;


 741   }
 742 
 743   // Check local default methods   
 744   if ((default_methods != NULL) &&
 745     (InstanceKlass::find_method(default_methods, name, signature) != NULL)) 

 746    {
 747      return false;
















 748    }
 749 
 750   InstanceKlass* cursuper;
 751   // Iterate on all superclasses, which should have instanceKlasses
 752   // Note that we explicitly look for overpasses at each level.
 753   // Overpasses may or may not exist supers for pass 1,
 754   // they should have been created for pass 2 and later.
 755   
 756   for (cursuper = InstanceKlass::cast(super); cursuper != NULL;  cursuper = (InstanceKlass*)cursuper->super())
 757   {
 758      if (cursuper->find_local_method(name, signature, 
 759            Klass::find_overpass, Klass::skip_static, Klass::skip_private) != NULL) {
 760        return false;
 761      }
 762   } 
 763 
 764   return true;
 765 }
 766 
 767 // Scans current_interface_methods for miranda methods that do not
 768 // already appear in new_mirandas, or default methods,  and are also not defined-and-non-private
 769 // in super (superclass).  These mirandas are added to all_mirandas if it is
 770 // not null; in addition, those that are not duplicates of miranda methods
 771 // inherited by super from its interfaces are added to new_mirandas.
 772 // Thus, new_mirandas will be the set of mirandas that this class introduces,
 773 // all_mirandas will be the set of all mirandas applicable to this class
 774 // including all defined in superclasses.
 775 void klassVtable::add_new_mirandas_to_lists(
 776     GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas,
 777     Array<Method*>* current_interface_methods, Array<Method*>* class_methods,
 778     Array<Method*>* default_methods, Klass* super) {
 779 
 780   // iterate thru the current interface's method to see if it a miranda
 781   int num_methods = current_interface_methods->length();
 782   for (int i = 0; i < num_methods; i++) {
 783     Method* im = current_interface_methods->at(i);
 784     bool is_duplicate = false;