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(); 692 if (is_miranda_entry_at(i) && 693 m->name() == name && m->signature() == signature) { 694 return i; 695 } 696 } 697 return Method::invalid_vtable_index; 698 } 699 | 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, set flag to TRUE for use below where existance of a 667 // miranda method is checked. 668 assert(super_method->is_package_private(), "super_method must be package private"); 669 assert(!superk->is_same_class_package(classloader(), classname), 670 "Must be different packages"); 671 found_pkg_prvt_method = true; 672 } 673 674 // Start with lookup result and continue to search up, for versions supporting transitive override 675 if (major_version >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) { 676 k = superk->super(); // haven't found an override match yet; continue to look 677 } else { 678 break; 679 } 680 } 681 682 // Only look for a miranda method if the method was not found in a package 683 // private class because, if it was found in a package private class, then 684 // there will be no miranda method, even if the method is also in a super 685 // interface. 686 if (!found_pkg_prvt_method) { 687 // if the target method is public or protected it may have a matching 688 // miranda method in the super, whose entry it should re-use. 689 // Actually, to handle cases that javac would not generate, we need 690 // this check for all access permissions. 691 const InstanceKlass *sk = InstanceKlass::cast(super); 692 if (sk->has_miranda_methods()) { 693 if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) { 694 return false; // found a matching miranda; we do not need a new entry 695 } 696 } 697 } 698 return true; // found no match; we need a new entry 699 } 700 701 // Support for miranda methods 702 703 // get the vtable index of a miranda method with matching "name" and "signature" 704 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) { 705 // search from the bottom, might be faster 706 for (int i = (length() - 1); i >= 0; i--) { 707 Method* m = table()[i].method(); 708 if (is_miranda_entry_at(i) && 709 m->name() == name && m->signature() == signature) { 710 return i; 711 } 712 } 713 return Method::invalid_vtable_index; 714 } 715 |