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) != 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 }
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()) == 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++) {
1068 }
1069 nof_methods -= 1;
1070 }
1071 // no methods have itable indices
1072 return 0;
1073 }
1074
1075
1076 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) {
1077 Array<Method*>* methods = InstanceKlass::cast(interf_h())->methods();
1078 int nof_methods = methods->length();
1079 HandleMark hm;
1080 assert(nof_methods > 0, "at least one method must exist for interface to be in vtable");
1081 Handle interface_loader (THREAD, InstanceKlass::cast(interf_h())->class_loader());
1082
1083 int ime_count = method_count_for_interface(interf_h());
1084 for (int i = 0; i < nof_methods; i++) {
1085 Method* m = methods->at(i);
1086 methodHandle target;
1087 if (m->has_itable_index()) {
1088 LinkResolver::lookup_instance_method_in_klasses(target, _klass, m->name(), m->signature(), CHECK);
1089 }
1090 if (target == NULL || !target->is_public() || target->is_abstract()) {
1091 // Entry does not resolve. Leave it empty for AbstractMethodError.
1092 if (!(target == NULL) && !target->is_public()) {
1093 // Stuff an IllegalAccessError throwing method in there instead.
1094 itableOffsetEntry::method_entry(_klass(), method_table_offset)[m->itable_index()].
1095 initialize(Universe::throw_illegal_access_error());
1096 }
1097 } else {
1098 // Entry did resolve, check loader constraints before initializing
1099 // if checkconstraints requested
1100 if (checkconstraints) {
1101 Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1102 if (method_holder_loader() != interface_loader()) {
1103 ResourceMark rm(THREAD);
1104 Symbol* failed_type_symbol =
1105 SystemDictionary::check_signature_loaders(m->signature(),
1106 method_holder_loader,
1107 interface_loader,
|
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 }
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++) {
1068 }
1069 nof_methods -= 1;
1070 }
1071 // no methods have itable indices
1072 return 0;
1073 }
1074
1075
1076 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) {
1077 Array<Method*>* methods = InstanceKlass::cast(interf_h())->methods();
1078 int nof_methods = methods->length();
1079 HandleMark hm;
1080 assert(nof_methods > 0, "at least one method must exist for interface to be in vtable");
1081 Handle interface_loader (THREAD, InstanceKlass::cast(interf_h())->class_loader());
1082
1083 int ime_count = method_count_for_interface(interf_h());
1084 for (int i = 0; i < nof_methods; i++) {
1085 Method* m = methods->at(i);
1086 methodHandle target;
1087 if (m->has_itable_index()) {
1088 // This search must match the runtime resolution, i.e. selection search for invokeinterface
1089 // to correctly enforce loader constraints for interface method inheritance
1090 LinkResolver::lookup_instance_method_in_klasses(target, _klass, m->name(), m->signature(), CHECK);
1091 }
1092 if (target == NULL || !target->is_public() || target->is_abstract()) {
1093 // Entry does not resolve. Leave it empty for AbstractMethodError.
1094 if (!(target == NULL) && !target->is_public()) {
1095 // Stuff an IllegalAccessError throwing method in there instead.
1096 itableOffsetEntry::method_entry(_klass(), method_table_offset)[m->itable_index()].
1097 initialize(Universe::throw_illegal_access_error());
1098 }
1099 } else {
1100 // Entry did resolve, check loader constraints before initializing
1101 // if checkconstraints requested
1102 if (checkconstraints) {
1103 Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1104 if (method_holder_loader() != interface_loader()) {
1105 ResourceMark rm(THREAD);
1106 Symbol* failed_type_symbol =
1107 SystemDictionary::check_signature_loaders(m->signature(),
1108 method_holder_loader,
1109 interface_loader,
|