1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
605 // For classes that were not javac'd together, we also do transitive overriding around
606 // methods that have less accessibility
607 if ((!super_method->is_static()) &&
608 (!super_method->is_private())) {
609 if (superk->is_override(super_method, classloader, classname, THREAD)) {
610 return false;
611 // else keep looking for transitive overrides
612 }
613 }
614
615 // Start with lookup result and continue to search up
616 k = superk->super(); // haven't found an override match yet; continue to look
617 }
618
619 // if the target method is public or protected it may have a matching
620 // miranda method in the super, whose entry it should re-use.
621 // Actually, to handle cases that javac would not generate, we need
622 // this check for all access permissions.
623 InstanceKlass *sk = InstanceKlass::cast(super);
624 if (sk->has_miranda_methods()) {
625 if (sk->lookup_method_in_all_interfaces(name, signature, false) != NULL) {
626 return false; // found a matching miranda; we do not need a new entry
627 }
628 }
629 return true; // found no match; we need a new entry
630 }
631
632 // Support for miranda methods
633
634 // get the vtable index of a miranda method with matching "name" and "signature"
635 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) {
636 // search from the bottom, might be faster
637 for (int i = (length() - 1); i >= 0; i--) {
638 Method* m = table()[i].method();
639 if (is_miranda_entry_at(i) &&
640 m->name() == name && m->signature() == signature) {
641 return i;
642 }
643 }
644 return Method::invalid_vtable_index;
645 }
681 if (m->is_static() || m->is_private() || m->is_overpass()) {
682 return false;
683 }
684 Symbol* name = m->name();
685 Symbol* signature = m->signature();
686
687 if (InstanceKlass::find_instance_method(class_methods, name, signature) == NULL) {
688 // did not find it in the method table of the current class
689 if ((default_methods == NULL) ||
690 InstanceKlass::find_method(default_methods, name, signature) == NULL) {
691 if (super == NULL) {
692 // super doesn't exist
693 return true;
694 }
695
696 Method* mo = InstanceKlass::cast(super)->lookup_method(name, signature);
697 while (mo != NULL && mo->access_flags().is_static()
698 && mo->method_holder() != NULL
699 && mo->method_holder()->super() != NULL)
700 {
701 mo = mo->method_holder()->super()->uncached_lookup_method(name, signature);
702 }
703 if (mo == NULL || mo->access_flags().is_private() ) {
704 // super class hierarchy does not implement it or protection is different
705 return true;
706 }
707 }
708 }
709
710 return false;
711 }
712
713 // Scans current_interface_methods for miranda methods that do not
714 // already appear in new_mirandas, or default methods, and are also not defined-and-non-private
715 // in super (superclass). These mirandas are added to all_mirandas if it is
716 // not null; in addition, those that are not duplicates of miranda methods
717 // inherited by super from its interfaces are added to new_mirandas.
718 // Thus, new_mirandas will be the set of mirandas that this class introduces,
719 // all_mirandas will be the set of all mirandas applicable to this class
720 // including all defined in superclasses.
721 void klassVtable::add_new_mirandas_to_lists(
726 // iterate thru the current interface's method to see if it a miranda
727 int num_methods = current_interface_methods->length();
728 for (int i = 0; i < num_methods; i++) {
729 Method* im = current_interface_methods->at(i);
730 bool is_duplicate = false;
731 int num_of_current_mirandas = new_mirandas->length();
732 // check for duplicate mirandas in different interfaces we implement
733 for (int j = 0; j < num_of_current_mirandas; j++) {
734 Method* miranda = new_mirandas->at(j);
735 if ((im->name() == miranda->name()) &&
736 (im->signature() == miranda->signature())) {
737 is_duplicate = true;
738 break;
739 }
740 }
741
742 if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable
743 if (is_miranda(im, class_methods, default_methods, super)) { // is it a miranda at all?
744 InstanceKlass *sk = InstanceKlass::cast(super);
745 // check if it is a duplicate of a super's miranda
746 if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), false) == NULL) {
747 new_mirandas->append(im);
748 }
749 if (all_mirandas != NULL) {
750 all_mirandas->append(im);
751 }
752 }
753 }
754 }
755 }
756
757 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas,
758 GrowableArray<Method*>* all_mirandas,
759 Klass* super, Array<Method*>* class_methods,
760 Array<Method*>* default_methods,
761 Array<Klass*>* local_interfaces) {
762 assert((new_mirandas->length() == 0) , "current mirandas must be 0");
763
764 // iterate thru the local interfaces looking for a miranda
765 int num_local_ifs = local_interfaces->length();
766 for (int i = 0; i < num_local_ifs; i++) {
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
605 // For classes that were not javac'd together, we also do transitive overriding around
606 // methods that have less accessibility
607 if ((!super_method->is_static()) &&
608 (!super_method->is_private())) {
609 if (superk->is_override(super_method, classloader, classname, THREAD)) {
610 return false;
611 // else keep looking for transitive overrides
612 }
613 }
614
615 // Start with lookup result and continue to search up
616 k = superk->super(); // haven't found an override match yet; continue to look
617 }
618
619 // if the target method is public or protected it may have a matching
620 // miranda method in the super, whose entry it should re-use.
621 // Actually, to handle cases that javac would not generate, we need
622 // this check for all access permissions.
623 InstanceKlass *sk = InstanceKlass::cast(super);
624 if (sk->has_miranda_methods()) {
625 if (sk->lookup_method_in_all_interfaces(name, signature, Klass::normal) != NULL) {
626 return false; // found a matching miranda; we do not need a new entry
627 }
628 }
629 return true; // found no match; we need a new entry
630 }
631
632 // Support for miranda methods
633
634 // get the vtable index of a miranda method with matching "name" and "signature"
635 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) {
636 // search from the bottom, might be faster
637 for (int i = (length() - 1); i >= 0; i--) {
638 Method* m = table()[i].method();
639 if (is_miranda_entry_at(i) &&
640 m->name() == name && m->signature() == signature) {
641 return i;
642 }
643 }
644 return Method::invalid_vtable_index;
645 }
681 if (m->is_static() || m->is_private() || m->is_overpass()) {
682 return false;
683 }
684 Symbol* name = m->name();
685 Symbol* signature = m->signature();
686
687 if (InstanceKlass::find_instance_method(class_methods, name, signature) == NULL) {
688 // did not find it in the method table of the current class
689 if ((default_methods == NULL) ||
690 InstanceKlass::find_method(default_methods, name, signature) == NULL) {
691 if (super == NULL) {
692 // super doesn't exist
693 return true;
694 }
695
696 Method* mo = InstanceKlass::cast(super)->lookup_method(name, signature);
697 while (mo != NULL && mo->access_flags().is_static()
698 && mo->method_holder() != NULL
699 && mo->method_holder()->super() != NULL)
700 {
701 mo = mo->method_holder()->super()->uncached_lookup_method(name, signature, Klass::normal);
702 }
703 if (mo == NULL || mo->access_flags().is_private() ) {
704 // super class hierarchy does not implement it or protection is different
705 return true;
706 }
707 }
708 }
709
710 return false;
711 }
712
713 // Scans current_interface_methods for miranda methods that do not
714 // already appear in new_mirandas, or default methods, and are also not defined-and-non-private
715 // in super (superclass). These mirandas are added to all_mirandas if it is
716 // not null; in addition, those that are not duplicates of miranda methods
717 // inherited by super from its interfaces are added to new_mirandas.
718 // Thus, new_mirandas will be the set of mirandas that this class introduces,
719 // all_mirandas will be the set of all mirandas applicable to this class
720 // including all defined in superclasses.
721 void klassVtable::add_new_mirandas_to_lists(
726 // iterate thru the current interface's method to see if it a miranda
727 int num_methods = current_interface_methods->length();
728 for (int i = 0; i < num_methods; i++) {
729 Method* im = current_interface_methods->at(i);
730 bool is_duplicate = false;
731 int num_of_current_mirandas = new_mirandas->length();
732 // check for duplicate mirandas in different interfaces we implement
733 for (int j = 0; j < num_of_current_mirandas; j++) {
734 Method* miranda = new_mirandas->at(j);
735 if ((im->name() == miranda->name()) &&
736 (im->signature() == miranda->signature())) {
737 is_duplicate = true;
738 break;
739 }
740 }
741
742 if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable
743 if (is_miranda(im, class_methods, default_methods, super)) { // is it a miranda at all?
744 InstanceKlass *sk = InstanceKlass::cast(super);
745 // check if it is a duplicate of a super's miranda
746 if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::normal) == NULL) {
747 new_mirandas->append(im);
748 }
749 if (all_mirandas != NULL) {
750 all_mirandas->append(im);
751 }
752 }
753 }
754 }
755 }
756
757 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas,
758 GrowableArray<Method*>* all_mirandas,
759 Klass* super, Array<Method*>* class_methods,
760 Array<Method*>* default_methods,
761 Array<Klass*>* local_interfaces) {
762 assert((new_mirandas->length() == 0) , "current mirandas must be 0");
763
764 // iterate thru the local interfaces looking for a miranda
765 int num_local_ifs = local_interfaces->length();
766 for (int i = 0; i < num_local_ifs; i++) {
|