src/hotspot/share/classfile/defaultMethods.cpp
changeset 48463 474cec233fb2
parent 47554 bc112140e089
child 49677 a1a7456dd8b9
equal deleted inserted replaced
48462:0bce2ae39928 48463:474cec233fb2
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "classfile/bytecodeAssembler.hpp"
    26 #include "classfile/bytecodeAssembler.hpp"
    27 #include "classfile/defaultMethods.hpp"
    27 #include "classfile/defaultMethods.hpp"
    28 #include "classfile/symbolTable.hpp"
    28 #include "classfile/symbolTable.hpp"
       
    29 #include "classfile/systemDictionary.hpp"
    29 #include "logging/log.hpp"
    30 #include "logging/log.hpp"
    30 #include "logging/logStream.hpp"
    31 #include "logging/logStream.hpp"
    31 #include "memory/allocation.hpp"
    32 #include "memory/allocation.hpp"
    32 #include "memory/metadataFactory.hpp"
    33 #include "memory/metadataFactory.hpp"
    33 #include "memory/resourceArea.hpp"
    34 #include "memory/resourceArea.hpp"
   681  private:
   682  private:
   682   // Context data
   683   // Context data
   683   Symbol* _method_name;
   684   Symbol* _method_name;
   684   Symbol* _method_signature;
   685   Symbol* _method_signature;
   685   StatefulMethodFamily*  _family;
   686   StatefulMethodFamily*  _family;
       
   687   bool _cur_class_is_interface;
   686 
   688 
   687  public:
   689  public:
   688   FindMethodsByErasedSig(Symbol* name, Symbol* signature) :
   690   FindMethodsByErasedSig(Symbol* name, Symbol* signature, bool is_interf) :
   689       _method_name(name), _method_signature(signature),
   691       _method_name(name), _method_signature(signature), _cur_class_is_interface(is_interf),
   690       _family(NULL) {}
   692       _family(NULL) {}
   691 
   693 
   692   void get_discovered_family(MethodFamily** family) {
   694   void get_discovered_family(MethodFamily** family) {
   693       if (_family != NULL) {
   695       if (_family != NULL) {
   694         *family = _family->get_method_family();
   696         *family = _family->get_method_family();
   707   bool visit() {
   709   bool visit() {
   708     PseudoScope* scope = PseudoScope::cast(current_data());
   710     PseudoScope* scope = PseudoScope::cast(current_data());
   709     InstanceKlass* iklass = current_class();
   711     InstanceKlass* iklass = current_class();
   710 
   712 
   711     Method* m = iklass->find_method(_method_name, _method_signature);
   713     Method* m = iklass->find_method(_method_name, _method_signature);
   712     // private interface methods are not candidates for default methods
   714     // Private interface methods are not candidates for default methods.
   713     // invokespecial to private interface methods doesn't use default method logic
   715     // invokespecial to private interface methods doesn't use default method logic.
   714     // private class methods are not candidates for default methods,
   716     // Private class methods are not candidates for default methods.
   715     // private methods do not override default methods, so need to perform
   717     // Private methods do not override default methods, so need to perform
   716     // default method inheritance without including private methods
   718     // default method inheritance without including private methods.
   717     // The overpasses are your supertypes' errors, we do not include them
   719     // The overpasses are your supertypes' errors, we do not include them.
   718     // future: take access controls into account for superclass methods
   720     // Non-public methods in java.lang.Object are not candidates for default
   719     if (m != NULL && !m->is_static() && !m->is_overpass() && !m->is_private()) {
   721     // methods.
       
   722     // Future: take access controls into account for superclass methods
       
   723     if (m != NULL && !m->is_static() && !m->is_overpass() && !m->is_private() &&
       
   724      (!_cur_class_is_interface || !SystemDictionary::is_nonpublic_Object_method(m))) {
   720       if (_family == NULL) {
   725       if (_family == NULL) {
   721         _family = new StatefulMethodFamily();
   726         _family = new StatefulMethodFamily();
   722       }
   727       }
   723 
   728 
   724       if (iklass->is_interface()) {
   729       if (iklass->is_interface()) {
   725         StateRestorer* restorer = _family->record_method_and_dq_further(m);
   730         StateRestorer* restorer = _family->record_method_and_dq_further(m);
   726         scope->add_mark(restorer);
   731         scope->add_mark(restorer);
   727       } else {
   732       } else {
   728         // This is the rule that methods in classes "win" (bad word) over
   733         // This is the rule that methods in classes "win" (bad word) over
   729         // methods in interfaces. This works because of single inheritance
   734         // methods in interfaces. This works because of single inheritance.
   730         // private methods in classes do not "win", they will be found
   735         // Private methods in classes do not "win", they will be found
   731         // first on searching, but overriding for invokevirtual needs
   736         // first on searching, but overriding for invokevirtual needs
   732         // to find default method candidates for the same signature
   737         // to find default method candidates for the same signature
   733         _family->set_target_if_empty(m);
   738         _family->set_target_if_empty(m);
   734       }
   739       }
   735     }
   740     }
   743 static void create_defaults_and_exceptions(
   748 static void create_defaults_and_exceptions(
   744     GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS);
   749     GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS);
   745 
   750 
   746 static void generate_erased_defaults(
   751 static void generate_erased_defaults(
   747      InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots,
   752      InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots,
   748      EmptyVtableSlot* slot, TRAPS) {
   753      EmptyVtableSlot* slot, bool is_intf, TRAPS) {
   749 
   754 
   750   // sets up a set of methods with the same exact erased signature
   755   // sets up a set of methods with the same exact erased signature
   751   FindMethodsByErasedSig visitor(slot->name(), slot->signature());
   756   FindMethodsByErasedSig visitor(slot->name(), slot->signature(), is_intf);
   752   visitor.run(klass);
   757   visitor.run(klass);
   753 
   758 
   754   MethodFamily* family;
   759   MethodFamily* family;
   755   visitor.get_discovered_family(&family);
   760   visitor.get_discovered_family(&family);
   756   if (family != NULL) {
   761   if (family != NULL) {
   815       streamIndentor si(&ls, 2);
   820       streamIndentor si(&ls, 2);
   816       ls.indent().print("Looking for default methods for slot ");
   821       ls.indent().print("Looking for default methods for slot ");
   817       slot->print_on(&ls);
   822       slot->print_on(&ls);
   818       ls.cr();
   823       ls.cr();
   819     }
   824     }
   820     generate_erased_defaults(klass, empty_slots, slot, CHECK);
   825     generate_erased_defaults(klass, empty_slots, slot, klass->is_interface(), CHECK);
   821   }
   826   }
   822   log_debug(defaultmethods)("Creating defaults and overpasses...");
   827   log_debug(defaultmethods)("Creating defaults and overpasses...");
   823   create_defaults_and_exceptions(empty_slots, klass, CHECK);
   828   create_defaults_and_exceptions(empty_slots, klass, CHECK);
   824   log_debug(defaultmethods)("Default method processing complete");
   829   log_debug(defaultmethods)("Default method processing complete");
   825 }
   830 }