< prev index next >

src/hotspot/share/oops/klassVtable.cpp

Print this page




 621   // we need a new entry if there is no superclass
 622   if (super == NULL) {
 623     return true;
 624   }
 625 
 626   // Package private methods always need a new entry to root their own
 627   // overriding. This allows transitive overriding to work.
 628   if (target_method()->is_package_private()) {
 629     return true;
 630   }
 631 
 632   // search through the super class hierarchy to see if we need
 633   // a new entry
 634   ResourceMark rm;
 635   Symbol* name = target_method()->name();
 636   Symbol* signature = target_method()->signature();
 637   const Klass* k = super;
 638   Method* super_method = NULL;
 639   InstanceKlass *holder = NULL;
 640   Method* recheck_method =  NULL;

 641   while (k != NULL) {
 642     // lookup through the hierarchy for a method with matching name and sign.
 643     super_method = InstanceKlass::cast(k)->lookup_method(name, signature);
 644     if (super_method == NULL) {
 645       break; // we still have to search for a matching miranda method
 646     }
 647     // get the class holding the matching method
 648     // make sure you use that class for is_override
 649     InstanceKlass* superk = super_method->method_holder();
 650     // we want only instance method matches
 651     // ignore private methods found via lookup_method since they do not participate in overriding,
 652     // and since we do override around them: e.g. a.m pub/b.m private/c.m pub,
 653     // ignore private, c.m pub does override a.m pub
 654     // For classes that were not javac'd together, we also do transitive overriding around
 655     // methods that have less accessibility
 656     if ((!super_method->is_static()) &&
 657        (!super_method->is_private())) {
 658       if (superk->is_override(super_method, classloader, classname, THREAD)) {
 659         return false;
 660       // else keep looking for transitive overrides
 661       }










 662     }
 663 
 664     // Start with lookup result and continue to search up, for versions supporting transitive override
 665     if (major_version >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) {
 666       k = superk->super(); // haven't found an override match yet; continue to look
 667     } else {
 668       break;
 669     }
 670   }
 671 









 672   // if the target method is public or protected it may have a matching
 673   // miranda method in the super, whose entry it should re-use.
 674   // Actually, to handle cases that javac would not generate, we need
 675   // this check for all access permissions.
 676   const InstanceKlass *sk = InstanceKlass::cast(super);
 677   if (sk->has_miranda_methods()) {
 678     if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) {
 679       return false;  // found a matching miranda; we do not need a new entry
 680     }
 681   }
 682   return true; // found no match; we need a new entry
 683 }
 684 
 685 // Support for miranda methods
 686 
 687 // get the vtable index of a miranda method with matching "name" and "signature"
 688 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) {
 689   // search from the bottom, might be faster
 690   for (int i = (length() - 1); i >= 0; i--) {
 691     Method* m = table()[i].method();




 621   // we need a new entry if there is no superclass
 622   if (super == NULL) {
 623     return true;
 624   }
 625 
 626   // Package private methods always need a new entry to root their own
 627   // overriding. This allows transitive overriding to work.
 628   if (target_method()->is_package_private()) {
 629     return true;
 630   }
 631 
 632   // search through the super class hierarchy to see if we need
 633   // a new entry
 634   ResourceMark rm;
 635   Symbol* name = target_method()->name();
 636   Symbol* signature = target_method()->signature();
 637   const Klass* k = super;
 638   Method* super_method = NULL;
 639   InstanceKlass *holder = NULL;
 640   Method* recheck_method =  NULL;
 641   bool found_pkg_prvt_method = false;
 642   while (k != NULL) {
 643     // lookup through the hierarchy for a method with matching name and sign.
 644     super_method = InstanceKlass::cast(k)->lookup_method(name, signature);
 645     if (super_method == NULL) {
 646       break; // we still have to search for a matching miranda method
 647     }
 648     // get the class holding the matching method
 649     // make sure you use that class for is_override
 650     InstanceKlass* superk = super_method->method_holder();
 651     // we want only instance method matches
 652     // ignore private methods found via lookup_method since they do not participate in overriding,
 653     // and since we do override around them: e.g. a.m pub/b.m private/c.m pub,
 654     // ignore private, c.m pub does override a.m pub
 655     // For classes that were not javac'd together, we also do transitive overriding around
 656     // methods that have less accessibility
 657     if ((!super_method->is_static()) &&
 658        (!super_method->is_private())) {
 659       if (superk->is_override(super_method, classloader, classname, THREAD)) {
 660         return false;
 661       // else keep looking for transitive overrides
 662       }
 663       // If we get here then one of the super classes has a package private method
 664       // that will not get overridden because it is in a different package.  But,
 665       // that package private method does "override" any matching methods in super
 666       // interfaces, so there will be no miranda vtable entry created.  So, set flag
 667       // to TRUE for use below, in case there are no methods in super classes that
 668       // this target method overrides.
 669       assert(super_method->is_package_private(), "super_method must be package private");
 670       assert(!superk->is_same_class_package(classloader(), classname),
 671              "Must be different packages");
 672       found_pkg_prvt_method = true;
 673     }
 674 
 675     // Start with lookup result and continue to search up, for versions supporting transitive override
 676     if (major_version >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) {
 677       k = superk->super(); // haven't found an override match yet; continue to look
 678     } else {
 679       break;
 680     }
 681   }
 682 
 683   // If found_pkg_prvt_method is set, then the ONLY matching method in the
 684   // superclasses is package private in another package. That matching method will
 685   // prevent a miranda vtable entry from being created. Because the target method can not
 686   // override the package private method in another package, then it needs to be the root
 687   // for its own vtable entry.
 688   if (found_pkg_prvt_method) {
 689      return true;
 690   }
 691 
 692   // if the target method is public or protected it may have a matching
 693   // miranda method in the super, whose entry it should re-use.
 694   // Actually, to handle cases that javac would not generate, we need
 695   // this check for all access permissions.
 696   const InstanceKlass *sk = InstanceKlass::cast(super);
 697   if (sk->has_miranda_methods()) {
 698     if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) {
 699       return false; // found a matching miranda; we do not need a new entry
 700     }
 701   }
 702   return true; // found no match; we need a new entry
 703 }
 704 
 705 // Support for miranda methods
 706 
 707 // get the vtable index of a miranda method with matching "name" and "signature"
 708 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) {
 709   // search from the bottom, might be faster
 710   for (int i = (length() - 1); i >= 0; i--) {
 711     Method* m = table()[i].method();


< prev index next >