comparison src/share/vm/classfile/defaultMethods.cpp @ 14422:2b8e28fdf503

Merge
author kvn
date Tue, 05 Nov 2013 17:38:04 -0800
parents f50418dfb1b7
children fdd464c8d62e
comparison
equal deleted inserted replaced
14421:3068270ba476 14422:2b8e28fdf503
23 */ 23 */
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/genericSignatures.hpp"
29 #include "classfile/symbolTable.hpp" 28 #include "classfile/symbolTable.hpp"
30 #include "memory/allocation.hpp" 29 #include "memory/allocation.hpp"
31 #include "memory/metadataFactory.hpp" 30 #include "memory/metadataFactory.hpp"
32 #include "memory/resourceArea.hpp" 31 #include "memory/resourceArea.hpp"
33 #include "runtime/signature.hpp" 32 #include "runtime/signature.hpp"
71 void destroy() { 70 void destroy() {
72 for (int i = 0; i < _marks.length(); ++i) { 71 for (int i = 0; i < _marks.length(); ++i) {
73 _marks.at(i)->destroy(); 72 _marks.at(i)->destroy();
74 } 73 }
75 } 74 }
76 };
77
78 class ContextMark : public PseudoScopeMark {
79 private:
80 generic::Context::Mark _mark;
81 public:
82 ContextMark(const generic::Context::Mark& cm) : _mark(cm) {}
83 virtual void destroy() { _mark.destroy(); }
84 }; 75 };
85 76
86 #ifndef PRODUCT 77 #ifndef PRODUCT
87 static void print_slot(outputStream* str, Symbol* name, Symbol* signature) { 78 static void print_slot(outputStream* str, Symbol* name, Symbol* signature) {
88 ResourceMark rm; 79 ResourceMark rm;
332 GrowableArray<Pair<Method*,QualifiedState> > _members; 323 GrowableArray<Pair<Method*,QualifiedState> > _members;
333 ResourceHashtable<Method*, int> _member_index; 324 ResourceHashtable<Method*, int> _member_index;
334 325
335 Method* _selected_target; // Filled in later, if a unique target exists 326 Method* _selected_target; // Filled in later, if a unique target exists
336 Symbol* _exception_message; // If no unique target is found 327 Symbol* _exception_message; // If no unique target is found
328 Symbol* _exception_name; // If no unique target is found
337 329
338 bool contains_method(Method* method) { 330 bool contains_method(Method* method) {
339 int* lookup = _member_index.get(method); 331 int* lookup = _member_index.get(method);
340 return lookup != NULL; 332 return lookup != NULL;
341 } 333 }
351 guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index"); 343 guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index");
352 _members.at(*index).second = DISQUALIFIED; 344 _members.at(*index).second = DISQUALIFIED;
353 } 345 }
354 346
355 Symbol* generate_no_defaults_message(TRAPS) const; 347 Symbol* generate_no_defaults_message(TRAPS) const;
356 Symbol* generate_abstract_method_message(Method* method, TRAPS) const;
357 Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const; 348 Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const;
358 349
359 public: 350 public:
360 351
361 MethodFamily() 352 MethodFamily()
362 : _selected_target(NULL), _exception_message(NULL) {} 353 : _selected_target(NULL), _exception_message(NULL), _exception_name(NULL) {}
363 354
364 void set_target_if_empty(Method* m) { 355 void set_target_if_empty(Method* m) {
365 if (_selected_target == NULL && !m->is_overpass()) { 356 if (_selected_target == NULL && !m->is_overpass()) {
366 _selected_target = m; 357 _selected_target = m;
367 } 358 }
390 bool has_target() const { return _selected_target != NULL; } 381 bool has_target() const { return _selected_target != NULL; }
391 bool throws_exception() { return _exception_message != NULL; } 382 bool throws_exception() { return _exception_message != NULL; }
392 383
393 Method* get_selected_target() { return _selected_target; } 384 Method* get_selected_target() { return _selected_target; }
394 Symbol* get_exception_message() { return _exception_message; } 385 Symbol* get_exception_message() { return _exception_message; }
386 Symbol* get_exception_name() { return _exception_name; }
395 387
396 // Either sets the target or the exception error message 388 // Either sets the target or the exception error message
397 void determine_target(InstanceKlass* root, TRAPS) { 389 void determine_target(InstanceKlass* root, TRAPS) {
398 if (has_target() || throws_exception()) { 390 if (has_target() || throws_exception()) {
399 return; 391 return;
407 } 399 }
408 } 400 }
409 401
410 if (qualified_methods.length() == 0) { 402 if (qualified_methods.length() == 0) {
411 _exception_message = generate_no_defaults_message(CHECK); 403 _exception_message = generate_no_defaults_message(CHECK);
404 _exception_name = vmSymbols::java_lang_AbstractMethodError();
412 } else if (qualified_methods.length() == 1) { 405 } else if (qualified_methods.length() == 1) {
406 // leave abstract methods alone, they will be found via normal search path
413 Method* method = qualified_methods.at(0); 407 Method* method = qualified_methods.at(0);
414 if (method->is_abstract()) { 408 if (!method->is_abstract()) {
415 _exception_message = generate_abstract_method_message(method, CHECK);
416 } else {
417 _selected_target = qualified_methods.at(0); 409 _selected_target = qualified_methods.at(0);
418 } 410 }
419 } else { 411 } else {
420 _exception_message = generate_conflicts_message(&qualified_methods,CHECK); 412 _exception_message = generate_conflicts_message(&qualified_methods,CHECK);
421 } 413 _exception_name = vmSymbols::java_lang_IncompatibleClassChangeError();
422 414 if (TraceDefaultMethods) {
423 assert((has_target() ^ throws_exception()) == 1, 415 _exception_message->print_value_on(tty);
424 "One and only one must be true"); 416 tty->print_cr("");
417 }
418 }
425 } 419 }
426 420
427 bool contains_signature(Symbol* query) { 421 bool contains_signature(Symbol* query) {
428 for (int i = 0; i < _members.length(); ++i) { 422 for (int i = 0; i < _members.length(); ++i) {
429 if (query == _members.at(i).first->signature()) { 423 if (query == _members.at(i).first->signature()) {
457 void print_selected(outputStream* str, int indent) const { 451 void print_selected(outputStream* str, int indent) const {
458 assert(has_target(), "Should be called otherwise"); 452 assert(has_target(), "Should be called otherwise");
459 streamIndentor si(str, indent * 2); 453 streamIndentor si(str, indent * 2);
460 str->indent().print("Selected method: "); 454 str->indent().print("Selected method: ");
461 print_method(str, _selected_target); 455 print_method(str, _selected_target);
456 Klass* method_holder = _selected_target->method_holder();
457 if (!method_holder->is_interface()) {
458 tty->print(" : in superclass");
459 }
462 str->print_cr(""); 460 str->print_cr("");
463 } 461 }
464 462
465 void print_exception(outputStream* str, int indent) { 463 void print_exception(outputStream* str, int indent) {
466 assert(throws_exception(), "Should be called otherwise"); 464 assert(throws_exception(), "Should be called otherwise");
465 assert(_exception_name != NULL, "exception_name should be set");
467 streamIndentor si(str, indent * 2); 466 streamIndentor si(str, indent * 2);
468 str->indent().print_cr("%s", _exception_message->as_C_string()); 467 str->indent().print_cr("%s: %s", _exception_name->as_C_string(), _exception_message->as_C_string());
469 } 468 }
470 #endif // ndef PRODUCT 469 #endif // ndef PRODUCT
471 }; 470 };
472 471
473 Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const { 472 Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const {
474 return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL); 473 return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL);
475 }
476
477 Symbol* MethodFamily::generate_abstract_method_message(Method* method, TRAPS) const {
478 Symbol* klass = method->klass_name();
479 Symbol* name = method->name();
480 Symbol* sig = method->signature();
481 stringStream ss;
482 ss.print("Method ");
483 ss.write((const char*)klass->bytes(), klass->utf8_length());
484 ss.print(".");
485 ss.write((const char*)name->bytes(), name->utf8_length());
486 ss.write((const char*)sig->bytes(), sig->utf8_length());
487 ss.print(" is abstract");
488 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL);
489 } 474 }
490 475
491 Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const { 476 Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const {
492 stringStream ss; 477 stringStream ss;
493 ss.print("Conflicting default methods:"); 478 ss.print("Conflicting default methods:");
501 ss.write((const char*)name->bytes(), name->utf8_length()); 486 ss.write((const char*)name->bytes(), name->utf8_length());
502 } 487 }
503 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); 488 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL);
504 } 489 }
505 490
506 // A generic method family contains a set of all methods that implement a single
507 // language-level method. Because of erasure, these methods may have different
508 // signatures. As members of the set are collected while walking over the
509 // hierarchy, they are tagged with a qualification state. The qualification
510 // state for an erased method is set to disqualified if there exists a path
511 // from the root of hierarchy to the method that contains an interleaving
512 // language-equivalent method defined in an interface.
513 class GenericMethodFamily : public MethodFamily {
514 private:
515
516 generic::MethodDescriptor* _descriptor; // language-level description
517
518 public:
519
520 GenericMethodFamily(generic::MethodDescriptor* canonical_desc)
521 : _descriptor(canonical_desc) {}
522
523 generic::MethodDescriptor* descriptor() const { return _descriptor; }
524
525 bool descriptor_matches(generic::MethodDescriptor* md, generic::Context* ctx) {
526 return descriptor()->covariant_match(md, ctx);
527 }
528
529 #ifndef PRODUCT
530 Symbol* get_generic_sig() const {
531
532 generic::Context ctx(NULL); // empty, as _descriptor already canonicalized
533 TempNewSymbol sig = descriptor()->reify_signature(&ctx, Thread::current());
534 return sig;
535 }
536 #endif // ndef PRODUCT
537 };
538 491
539 class StateRestorer; 492 class StateRestorer;
540 493
541 // StatefulMethodFamily is a wrapper around a MethodFamily that maintains the 494 // StatefulMethodFamily is a wrapper around a MethodFamily that maintains the
542 // qualification state during hierarchy visitation, and applies that state 495 // qualification state during hierarchy visitation, and applies that state
567 void set_target_if_empty(Method* m) { _method_family->set_target_if_empty(m); } 520 void set_target_if_empty(Method* m) { _method_family->set_target_if_empty(m); }
568 521
569 MethodFamily* get_method_family() { return _method_family; } 522 MethodFamily* get_method_family() { return _method_family; }
570 523
571 StateRestorer* record_method_and_dq_further(Method* mo); 524 StateRestorer* record_method_and_dq_further(Method* mo);
572 };
573
574
575 // StatefulGenericMethodFamily is a wrapper around GenericMethodFamily that maintains the
576 // qualification state during hierarchy visitation, and applies that state
577 // when adding members to the GenericMethodFamily.
578 class StatefulGenericMethodFamily : public StatefulMethodFamily {
579
580 public:
581 StatefulGenericMethodFamily(generic::MethodDescriptor* md, generic::Context* ctx)
582 : StatefulMethodFamily(new GenericMethodFamily(md->canonicalize(ctx))) {
583
584 }
585 GenericMethodFamily* get_method_family() {
586 return (GenericMethodFamily*)_method_family;
587 }
588
589 bool descriptor_matches(generic::MethodDescriptor* md, generic::Context* ctx) {
590 return get_method_family()->descriptor_matches(md, ctx);
591 }
592 }; 525 };
593 526
594 class StateRestorer : public PseudoScopeMark { 527 class StateRestorer : public PseudoScopeMark {
595 private: 528 private:
596 StatefulMethodFamily* _method; 529 StatefulMethodFamily* _method;
614 // disqualified 547 // disqualified
615 set_qualification_state(DISQUALIFIED); 548 set_qualification_state(DISQUALIFIED);
616 return mark; 549 return mark;
617 } 550 }
618 551
619 class StatefulGenericMethodFamilies : public ResourceObj {
620 private:
621 GrowableArray<StatefulGenericMethodFamily*> _methods;
622
623 public:
624 StatefulGenericMethodFamily* find_matching(
625 generic::MethodDescriptor* md, generic::Context* ctx) {
626 for (int i = 0; i < _methods.length(); ++i) {
627 StatefulGenericMethodFamily* existing = _methods.at(i);
628 if (existing->descriptor_matches(md, ctx)) {
629 return existing;
630 }
631 }
632 return NULL;
633 }
634
635 StatefulGenericMethodFamily* find_matching_or_create(
636 generic::MethodDescriptor* md, generic::Context* ctx) {
637 StatefulGenericMethodFamily* method = find_matching(md, ctx);
638 if (method == NULL) {
639 method = new StatefulGenericMethodFamily(md, ctx);
640 _methods.append(method);
641 }
642 return method;
643 }
644
645 void extract_families_into(GrowableArray<GenericMethodFamily*>* array) {
646 for (int i = 0; i < _methods.length(); ++i) {
647 array->append(_methods.at(i)->get_method_family());
648 }
649 }
650 };
651
652 // Represents a location corresponding to a vtable slot for methods that 552 // Represents a location corresponding to a vtable slot for methods that
653 // neither the class nor any of it's ancestors provide an implementaion. 553 // neither the class nor any of it's ancestors provide an implementaion.
654 // Default methods may be present to fill this slot. 554 // Default methods may be present to fill this slot.
655 class EmptyVtableSlot : public ResourceObj { 555 class EmptyVtableSlot : public ResourceObj {
656 private: 556 private:
677 print_slot(str, name(), signature()); 577 print_slot(str, name(), signature());
678 } 578 }
679 #endif // ndef PRODUCT 579 #endif // ndef PRODUCT
680 }; 580 };
681 581
582 static bool already_in_vtable_slots(GrowableArray<EmptyVtableSlot*>* slots, Method* m) {
583 bool found = false;
584 for (int j = 0; j < slots->length(); ++j) {
585 if (slots->at(j)->name() == m->name() &&
586 slots->at(j)->signature() == m->signature() ) {
587 found = true;
588 break;
589 }
590 }
591 return found;
592 }
593
682 static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots( 594 static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots(
683 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { 595 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) {
684 596
685 assert(klass != NULL, "Must be valid class"); 597 assert(klass != NULL, "Must be valid class");
686 598
687 GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>(); 599 GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>();
688 600
689 // All miranda methods are obvious candidates 601 // All miranda methods are obvious candidates
690 for (int i = 0; i < mirandas->length(); ++i) { 602 for (int i = 0; i < mirandas->length(); ++i) {
691 EmptyVtableSlot* slot = new EmptyVtableSlot(mirandas->at(i)); 603 Method* m = mirandas->at(i);
692 slots->append(slot); 604 if (!already_in_vtable_slots(slots, m)) {
605 slots->append(new EmptyVtableSlot(m));
606 }
693 } 607 }
694 608
695 // Also any overpasses in our superclasses, that we haven't implemented. 609 // Also any overpasses in our superclasses, that we haven't implemented.
696 // (can't use the vtable because it is not guaranteed to be initialized yet) 610 // (can't use the vtable because it is not guaranteed to be initialized yet)
697 InstanceKlass* super = klass->java_super(); 611 InstanceKlass* super = klass->java_super();
703 // default method processing that occurred on behalf of our superclass, 617 // default method processing that occurred on behalf of our superclass,
704 // so it's a method we want to re-examine in this new context. That is, 618 // so it's a method we want to re-examine in this new context. That is,
705 // unless we have a real implementation of it in the current class. 619 // unless we have a real implementation of it in the current class.
706 Method* impl = klass->lookup_method(m->name(), m->signature()); 620 Method* impl = klass->lookup_method(m->name(), m->signature());
707 if (impl == NULL || impl->is_overpass()) { 621 if (impl == NULL || impl->is_overpass()) {
708 slots->append(new EmptyVtableSlot(m)); 622 if (!already_in_vtable_slots(slots, m)) {
623 slots->append(new EmptyVtableSlot(m));
624 }
625 }
626 }
627 }
628
629 // also any default methods in our superclasses
630 if (super->default_methods() != NULL) {
631 for (int i = 0; i < super->default_methods()->length(); ++i) {
632 Method* m = super->default_methods()->at(i);
633 // m is a method that would have been a miranda if not for the
634 // default method processing that occurred on behalf of our superclass,
635 // so it's a method we want to re-examine in this new context. That is,
636 // unless we have a real implementation of it in the current class.
637 Method* impl = klass->lookup_method(m->name(), m->signature());
638 if (impl == NULL || impl->is_overpass()) {
639 if (!already_in_vtable_slots(slots, m)) {
640 slots->append(new EmptyVtableSlot(m));
641 }
709 } 642 }
710 } 643 }
711 } 644 }
712 super = super->java_super(); 645 super = super->java_super();
713 } 646 }
758 bool visit() { 691 bool visit() {
759 PseudoScope* scope = PseudoScope::cast(current_data()); 692 PseudoScope* scope = PseudoScope::cast(current_data());
760 InstanceKlass* iklass = current_class(); 693 InstanceKlass* iklass = current_class();
761 694
762 Method* m = iklass->find_method(_method_name, _method_signature); 695 Method* m = iklass->find_method(_method_name, _method_signature);
763 if (m != NULL) { 696 // private interface methods are not candidates for default methods
697 // invokespecial to private interface methods doesn't use default method logic
698 // future: take access controls into account for superclass methods
699 if (m != NULL && !m->is_static() && (!iklass->is_interface() || m->is_public())) {
764 if (_family == NULL) { 700 if (_family == NULL) {
765 _family = new StatefulMethodFamily(); 701 _family = new StatefulMethodFamily();
766 } 702 }
767 703
768 if (iklass->is_interface()) { 704 if (iklass->is_interface()) {
777 return true; 713 return true;
778 } 714 }
779 715
780 }; 716 };
781 717
782 // Iterates over the type hierarchy looking for all methods with a specific 718
783 // method name. The result of this is a set of method families each of 719
784 // which is populated with a set of methods that implement the same 720 static void create_defaults_and_exceptions(
785 // language-level signature.
786 class FindMethodsByGenericSig : public HierarchyVisitor<FindMethodsByGenericSig> {
787 private:
788 // Context data
789 Thread* THREAD;
790 generic::DescriptorCache* _cache;
791 Symbol* _method_name;
792 generic::Context* _ctx;
793 StatefulGenericMethodFamilies _families;
794
795 public:
796
797 FindMethodsByGenericSig(generic::DescriptorCache* cache, Symbol* name,
798 generic::Context* ctx, Thread* thread) :
799 _cache(cache), _method_name(name), _ctx(ctx), THREAD(thread) {}
800
801 void get_discovered_families(GrowableArray<GenericMethodFamily*>* methods) {
802 _families.extract_families_into(methods);
803 }
804
805 void* new_node_data(InstanceKlass* cls) { return new PseudoScope(); }
806 void free_node_data(void* node_data) {
807 PseudoScope::cast(node_data)->destroy();
808 }
809
810 bool visit() {
811 PseudoScope* scope = PseudoScope::cast(current_data());
812 InstanceKlass* klass = current_class();
813 InstanceKlass* sub = current_depth() > 0 ? class_at_depth(1) : NULL;
814
815 ContextMark* cm = new ContextMark(_ctx->mark());
816 scope->add_mark(cm); // will restore context when scope is freed
817
818 _ctx->apply_type_arguments(sub, klass, THREAD);
819
820 int start, end = 0;
821 start = klass->find_method_by_name(_method_name, &end);
822 if (start != -1) {
823 for (int i = start; i < end; ++i) {
824 Method* m = klass->methods()->at(i);
825 // This gets the method's parameter list with its generic type
826 // parameters resolved
827 generic::MethodDescriptor* md = _cache->descriptor_for(m, THREAD);
828
829 // Find all methods on this hierarchy that match this method
830 // (name, signature). This class collects other families of this
831 // method name.
832 StatefulGenericMethodFamily* family =
833 _families.find_matching_or_create(md, _ctx);
834
835 if (klass->is_interface()) {
836 // ???
837 StateRestorer* restorer = family->record_method_and_dq_further(m);
838 scope->add_mark(restorer);
839 } else {
840 // This is the rule that methods in classes "win" (bad word) over
841 // methods in interfaces. This works because of single inheritance
842 family->set_target_if_empty(m);
843 }
844 }
845 }
846 return true;
847 }
848 };
849
850 #ifndef PRODUCT
851 static void print_generic_families(
852 GrowableArray<GenericMethodFamily*>* methods, Symbol* match) {
853 streamIndentor si(tty, 4);
854 if (methods->length() == 0) {
855 tty->indent();
856 tty->print_cr("No Logical Method found");
857 }
858 for (int i = 0; i < methods->length(); ++i) {
859 tty->indent();
860 GenericMethodFamily* lm = methods->at(i);
861 if (lm->contains_signature(match)) {
862 tty->print_cr("<Matching>");
863 } else {
864 tty->print_cr("<Non-Matching>");
865 }
866 lm->print_sig_on(tty, lm->get_generic_sig(), 1);
867 }
868 }
869 #endif // ndef PRODUCT
870
871 static void create_overpasses(
872 GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS); 721 GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS);
873
874 static void generate_generic_defaults(
875 InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots,
876 EmptyVtableSlot* slot, int current_slot_index, TRAPS) {
877
878 if (slot->is_bound()) {
879 #ifndef PRODUCT
880 if (TraceDefaultMethods) {
881 streamIndentor si(tty, 4);
882 tty->indent().print_cr("Already bound to logical method:");
883 GenericMethodFamily* lm = (GenericMethodFamily*)(slot->get_binding());
884 lm->print_sig_on(tty, lm->get_generic_sig(), 1);
885 }
886 #endif // ndef PRODUCT
887 return; // covered by previous processing
888 }
889
890 generic::DescriptorCache cache;
891
892 generic::Context ctx(&cache);
893 FindMethodsByGenericSig visitor(&cache, slot->name(), &ctx, CHECK);
894 visitor.run(klass);
895
896 GrowableArray<GenericMethodFamily*> discovered_families;
897 visitor.get_discovered_families(&discovered_families);
898
899 #ifndef PRODUCT
900 if (TraceDefaultMethods) {
901 print_generic_families(&discovered_families, slot->signature());
902 }
903 #endif // ndef PRODUCT
904
905 // Find and populate any other slots that match the discovered families
906 for (int j = current_slot_index; j < empty_slots->length(); ++j) {
907 EmptyVtableSlot* open_slot = empty_slots->at(j);
908
909 if (slot->name() == open_slot->name()) {
910 for (int k = 0; k < discovered_families.length(); ++k) {
911 GenericMethodFamily* lm = discovered_families.at(k);
912
913 if (lm->contains_signature(open_slot->signature())) {
914 lm->determine_target(klass, CHECK);
915 open_slot->bind_family(lm);
916 }
917 }
918 }
919 }
920 }
921 722
922 static void generate_erased_defaults( 723 static void generate_erased_defaults(
923 InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots, 724 InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots,
924 EmptyVtableSlot* slot, TRAPS) { 725 EmptyVtableSlot* slot, TRAPS) {
925 726
935 } 736 }
936 } 737 }
937 738
938 static void merge_in_new_methods(InstanceKlass* klass, 739 static void merge_in_new_methods(InstanceKlass* klass,
939 GrowableArray<Method*>* new_methods, TRAPS); 740 GrowableArray<Method*>* new_methods, TRAPS);
741 static void create_default_methods( InstanceKlass* klass,
742 GrowableArray<Method*>* new_methods, TRAPS);
940 743
941 // This is the guts of the default methods implementation. This is called just 744 // This is the guts of the default methods implementation. This is called just
942 // after the classfile has been parsed if some ancestor has default methods. 745 // after the classfile has been parsed if some ancestor has default methods.
943 // 746 //
944 // First if finds any name/signature slots that need any implementation (either 747 // First if finds any name/signature slots that need any implementation (either
945 // because they are miranda or a superclass's implementation is an overpass 748 // because they are miranda or a superclass's implementation is an overpass
946 // itself). For each slot, iterate over the hierarchy, using generic signature 749 // itself). For each slot, iterate over the hierarchy, to see if they contain a
947 // information to partition any methods that match the name into method families 750 // signature that matches the slot we are looking at.
948 // where each family contains methods whose signatures are equivalent at the
949 // language level (i.e., their reified parameters match and return values are
950 // covariant). Check those sets to see if they contain a signature that matches
951 // the slot we're looking at (if we're lucky, there might be other empty slots
952 // that we can fill using the same analysis).
953 // 751 //
954 // For each slot filled, we generate an overpass method that either calls the 752 // For each slot filled, we generate an overpass method that either calls the
955 // unique default method candidate using invokespecial, or throws an exception 753 // unique default method candidate using invokespecial, or throws an exception
956 // (in the case of no default method candidates, or more than one valid 754 // (in the case of no default method candidates, or more than one valid
957 // candidate). These methods are then added to the class's method list. If 755 // candidate). These methods are then added to the class's method list.
958 // the method set we're using contains methods (qualified or not) with a 756 // The JVM does not create bridges nor handle generic signatures here.
959 // different runtime signature than the method we're creating, then we have to
960 // create bridges with those signatures too.
961 void DefaultMethods::generate_default_methods( 757 void DefaultMethods::generate_default_methods(
962 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { 758 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) {
963 759
964 // This resource mark is the bound for all memory allocation that takes 760 // This resource mark is the bound for all memory allocation that takes
965 // place during default method processing. After this goes out of scope, 761 // place during default method processing. After this goes out of scope,
995 slot->print_on(tty); 791 slot->print_on(tty);
996 tty->print_cr(""); 792 tty->print_cr("");
997 } 793 }
998 #endif // ndef PRODUCT 794 #endif // ndef PRODUCT
999 795
1000 if (ParseGenericDefaults) { 796 generate_erased_defaults(klass, empty_slots, slot, CHECK);
1001 generate_generic_defaults(klass, empty_slots, slot, i, CHECK);
1002 } else {
1003 generate_erased_defaults(klass, empty_slots, slot, CHECK);
1004 }
1005 } 797 }
1006 #ifndef PRODUCT 798 #ifndef PRODUCT
1007 if (TraceDefaultMethods) { 799 if (TraceDefaultMethods) {
1008 tty->print_cr("Creating overpasses..."); 800 tty->print_cr("Creating overpasses...");
1009 } 801 }
1010 #endif // ndef PRODUCT 802 #endif // ndef PRODUCT
1011 803
1012 create_overpasses(empty_slots, klass, CHECK); 804 create_defaults_and_exceptions(empty_slots, klass, CHECK);
1013 805
1014 #ifndef PRODUCT 806 #ifndef PRODUCT
1015 if (TraceDefaultMethods) { 807 if (TraceDefaultMethods) {
1016 tty->print_cr("Default method processing complete"); 808 tty->print_cr("Default method processing complete");
1017 } 809 }
1018 #endif // ndef PRODUCT 810 #endif // ndef PRODUCT
1019 } 811 }
1020 812
1021 /** 813 static int assemble_method_error(
1022 * Generic analysis was used upon interface '_target' and found a unique 814 BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* errorName, Symbol* message, TRAPS) {
1023 * default method candidate with generic signature '_method_desc'. This 815
1024 * method is only viable if it would also be in the set of default method
1025 * candidates if we ran a full analysis on the current class.
1026 *
1027 * The only reason that the method would not be in the set of candidates for
1028 * the current class is if that there's another covariantly matching method
1029 * which is "more specific" than the found method -- i.e., one could find a
1030 * path in the interface hierarchy in which the matching method appears
1031 * before we get to '_target'.
1032 *
1033 * In order to determine this, we examine all of the implemented
1034 * interfaces. If we find path that leads to the '_target' interface, then
1035 * we examine that path to see if there are any methods that would shadow
1036 * the selected method along that path.
1037 */
1038 class ShadowChecker : public HierarchyVisitor<ShadowChecker> {
1039 protected:
1040 Thread* THREAD;
1041
1042 InstanceKlass* _target;
1043
1044 Symbol* _method_name;
1045 InstanceKlass* _method_holder;
1046 bool _found_shadow;
1047
1048
1049 public:
1050
1051 ShadowChecker(Thread* thread, Symbol* name, InstanceKlass* holder,
1052 InstanceKlass* target)
1053 : THREAD(thread), _method_name(name), _method_holder(holder),
1054 _target(target), _found_shadow(false) {}
1055
1056 void* new_node_data(InstanceKlass* cls) { return NULL; }
1057 void free_node_data(void* data) { return; }
1058
1059 bool visit() {
1060 InstanceKlass* ik = current_class();
1061 if (ik == _target && current_depth() == 1) {
1062 return false; // This was the specified super -- no need to search it
1063 }
1064 if (ik == _method_holder || ik == _target) {
1065 // We found a path that should be examined to see if it shadows _method
1066 if (path_has_shadow()) {
1067 _found_shadow = true;
1068 cancel_iteration();
1069 }
1070 return false; // no need to continue up hierarchy
1071 }
1072 return true;
1073 }
1074
1075 virtual bool path_has_shadow() = 0;
1076 bool found_shadow() { return _found_shadow; }
1077 };
1078
1079 // Used for Invokespecial.
1080 // Invokespecial is allowed to invoke a concrete interface method
1081 // and can be used to disambuiguate among qualified candidates,
1082 // which are methods in immediate superinterfaces,
1083 // but may not be used to invoke a candidate that would be shadowed
1084 // from the perspective of the caller.
1085 // Invokespecial is also used in the overpass generation today
1086 // We re-run the shadowchecker because we can't distinguish this case,
1087 // but it should return the same answer, since the overpass target
1088 // is now the invokespecial caller.
1089 class ErasedShadowChecker : public ShadowChecker {
1090 private:
1091 bool path_has_shadow() {
1092
1093 for (int i = current_depth() - 1; i > 0; --i) {
1094 InstanceKlass* ik = class_at_depth(i);
1095
1096 if (ik->is_interface()) {
1097 int end;
1098 int start = ik->find_method_by_name(_method_name, &end);
1099 if (start != -1) {
1100 return true;
1101 }
1102 }
1103 }
1104 return false;
1105 }
1106 public:
1107
1108 ErasedShadowChecker(Thread* thread, Symbol* name, InstanceKlass* holder,
1109 InstanceKlass* target)
1110 : ShadowChecker(thread, name, holder, target) {}
1111 };
1112
1113 class GenericShadowChecker : public ShadowChecker {
1114 private:
1115 generic::DescriptorCache* _cache;
1116 generic::MethodDescriptor* _method_desc;
1117
1118 bool path_has_shadow() {
1119 generic::Context ctx(_cache);
1120
1121 for (int i = current_depth() - 1; i > 0; --i) {
1122 InstanceKlass* ik = class_at_depth(i);
1123 InstanceKlass* sub = class_at_depth(i + 1);
1124 ctx.apply_type_arguments(sub, ik, THREAD);
1125
1126 if (ik->is_interface()) {
1127 int end;
1128 int start = ik->find_method_by_name(_method_name, &end);
1129 if (start != -1) {
1130 for (int j = start; j < end; ++j) {
1131 Method* mo = ik->methods()->at(j);
1132 generic::MethodDescriptor* md = _cache->descriptor_for(mo, THREAD);
1133 if (_method_desc->covariant_match(md, &ctx)) {
1134 return true;
1135 }
1136 }
1137 }
1138 }
1139 }
1140 return false;
1141 }
1142
1143 public:
1144
1145 GenericShadowChecker(generic::DescriptorCache* cache, Thread* thread,
1146 Symbol* name, InstanceKlass* holder, generic::MethodDescriptor* desc,
1147 InstanceKlass* target)
1148 : ShadowChecker(thread, name, holder, target) {
1149 _cache = cache;
1150 _method_desc = desc;
1151 }
1152 };
1153
1154
1155
1156 // Find the unique qualified candidate from the perspective of the super_class
1157 // which is the resolved_klass, which must be an immediate superinterface
1158 // of klass
1159 Method* find_erased_super_default(InstanceKlass* current_class, InstanceKlass* super_class, Symbol* method_name, Symbol* sig, TRAPS) {
1160
1161 FindMethodsByErasedSig visitor(method_name, sig);
1162 visitor.run(super_class); // find candidates from resolved_klass
1163
1164 MethodFamily* family;
1165 visitor.get_discovered_family(&family);
1166
1167 if (family != NULL) {
1168 family->determine_target(current_class, CHECK_NULL); // get target from current_class
1169 }
1170
1171 if (family->has_target()) {
1172 Method* target = family->get_selected_target();
1173 InstanceKlass* holder = InstanceKlass::cast(target->method_holder());
1174
1175 // Verify that the identified method is valid from the context of
1176 // the current class, which is the caller class for invokespecial
1177 // link resolution, i.e. ensure there it is not shadowed.
1178 // You can use invokespecial to disambiguate interface methods, but
1179 // you can not use it to skip over an interface method that would shadow it.
1180 ErasedShadowChecker checker(THREAD, target->name(), holder, super_class);
1181 checker.run(current_class);
1182
1183 if (checker.found_shadow()) {
1184 #ifndef PRODUCT
1185 if (TraceDefaultMethods) {
1186 tty->print_cr(" Only candidate found was shadowed.");
1187 }
1188 #endif // ndef PRODUCT
1189 THROW_MSG_(vmSymbols::java_lang_AbstractMethodError(),
1190 "Accessible default method not found", NULL);
1191 } else {
1192 #ifndef PRODUCT
1193 if (TraceDefaultMethods) {
1194 family->print_sig_on(tty, target->signature(), 1);
1195 }
1196 #endif // ndef PRODUCT
1197 return target;
1198 }
1199 } else {
1200 assert(family->throws_exception(), "must have target or throw");
1201 THROW_MSG_(vmSymbols::java_lang_AbstractMethodError(),
1202 family->get_exception_message()->as_C_string(), NULL);
1203 }
1204 }
1205
1206 // super_class is assumed to be the direct super of current_class
1207 Method* find_generic_super_default( InstanceKlass* current_class,
1208 InstanceKlass* super_class,
1209 Symbol* method_name, Symbol* sig, TRAPS) {
1210 generic::DescriptorCache cache;
1211 generic::Context ctx(&cache);
1212
1213 // Prime the initial generic context for current -> super_class
1214 ctx.apply_type_arguments(current_class, super_class, CHECK_NULL);
1215
1216 FindMethodsByGenericSig visitor(&cache, method_name, &ctx, CHECK_NULL);
1217 visitor.run(super_class);
1218
1219 GrowableArray<GenericMethodFamily*> families;
1220 visitor.get_discovered_families(&families);
1221
1222 #ifndef PRODUCT
1223 if (TraceDefaultMethods) {
1224 print_generic_families(&families, sig);
1225 }
1226 #endif // ndef PRODUCT
1227
1228 GenericMethodFamily* selected_family = NULL;
1229
1230 for (int i = 0; i < families.length(); ++i) {
1231 GenericMethodFamily* lm = families.at(i);
1232 if (lm->contains_signature(sig)) {
1233 lm->determine_target(current_class, CHECK_NULL);
1234 selected_family = lm;
1235 }
1236 }
1237
1238 if (selected_family->has_target()) {
1239 Method* target = selected_family->get_selected_target();
1240 InstanceKlass* holder = InstanceKlass::cast(target->method_holder());
1241
1242 // Verify that the identified method is valid from the context of
1243 // the current class
1244 GenericShadowChecker checker(&cache, THREAD, target->name(),
1245 holder, selected_family->descriptor(), super_class);
1246 checker.run(current_class);
1247
1248 if (checker.found_shadow()) {
1249 #ifndef PRODUCT
1250 if (TraceDefaultMethods) {
1251 tty->print_cr(" Only candidate found was shadowed.");
1252 }
1253 #endif // ndef PRODUCT
1254 THROW_MSG_(vmSymbols::java_lang_AbstractMethodError(),
1255 "Accessible default method not found", NULL);
1256 } else {
1257 return target;
1258 }
1259 } else {
1260 assert(selected_family->throws_exception(), "must have target or throw");
1261 THROW_MSG_(vmSymbols::java_lang_AbstractMethodError(),
1262 selected_family->get_exception_message()->as_C_string(), NULL);
1263 }
1264 }
1265
1266 // This is called during linktime when we find an invokespecial call that
1267 // refers to a direct superinterface. It indicates that we should find the
1268 // default method in the hierarchy of that superinterface, and if that method
1269 // would have been a candidate from the point of view of 'this' class, then we
1270 // return that method.
1271 // This logic assumes that the super is a direct superclass of the caller
1272 Method* DefaultMethods::find_super_default(
1273 Klass* cls, Klass* super, Symbol* method_name, Symbol* sig, TRAPS) {
1274
1275 ResourceMark rm(THREAD);
1276
1277 assert(cls != NULL && super != NULL, "Need real classes");
1278
1279 InstanceKlass* current_class = InstanceKlass::cast(cls);
1280 InstanceKlass* super_class = InstanceKlass::cast(super);
1281
1282 // Keep entire hierarchy alive for the duration of the computation
1283 KeepAliveRegistrar keepAlive(THREAD);
1284 KeepAliveVisitor loadKeepAlive(&keepAlive);
1285 loadKeepAlive.run(current_class); // get hierarchy from current class
1286
1287 #ifndef PRODUCT
1288 if (TraceDefaultMethods) {
1289 tty->print_cr("Finding super default method %s.%s%s from %s",
1290 super_class->name()->as_C_string(),
1291 method_name->as_C_string(), sig->as_C_string(),
1292 current_class->name()->as_C_string());
1293 }
1294 #endif // ndef PRODUCT
1295
1296 assert(super_class->is_interface(), "only call for default methods");
1297
1298 Method* target = NULL;
1299 if (ParseGenericDefaults) {
1300 target = find_generic_super_default(current_class, super_class,
1301 method_name, sig, CHECK_NULL);
1302 } else {
1303 target = find_erased_super_default(current_class, super_class,
1304 method_name, sig, CHECK_NULL);
1305 }
1306
1307 #ifndef PRODUCT
1308 if (target != NULL) {
1309 if (TraceDefaultMethods) {
1310 tty->print(" Returning ");
1311 print_method(tty, target, true);
1312 tty->print_cr("");
1313 }
1314 }
1315 #endif // ndef PRODUCT
1316 return target;
1317 }
1318
1319 #ifndef PRODUCT
1320 // Return true is broad type is a covariant return of narrow type
1321 static bool covariant_return_type(BasicType narrow, BasicType broad) {
1322 if (narrow == broad) {
1323 return true;
1324 }
1325 if (broad == T_OBJECT) {
1326 return true;
1327 }
1328 return false;
1329 }
1330 #endif // ndef PRODUCT
1331
1332 static int assemble_redirect(
1333 BytecodeConstantPool* cp, BytecodeBuffer* buffer,
1334 Symbol* incoming, Method* target, TRAPS) {
1335
1336 BytecodeAssembler assem(buffer, cp);
1337
1338 SignatureStream in(incoming, true);
1339 SignatureStream out(target->signature(), true);
1340 u2 parameter_count = 0;
1341
1342 assem.aload(parameter_count++); // load 'this'
1343
1344 while (!in.at_return_type()) {
1345 assert(!out.at_return_type(), "Parameter counts do not match");
1346 BasicType bt = in.type();
1347 assert(out.type() == bt, "Parameter types are not compatible");
1348 assem.load(bt, parameter_count);
1349 if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) {
1350 assem.checkcast(out.as_symbol(THREAD));
1351 } else if (bt == T_LONG || bt == T_DOUBLE) {
1352 ++parameter_count; // longs and doubles use two slots
1353 }
1354 ++parameter_count;
1355 in.next();
1356 out.next();
1357 }
1358 assert(out.at_return_type(), "Parameter counts do not match");
1359 assert(covariant_return_type(out.type(), in.type()), "Return types are not compatible");
1360
1361 if (parameter_count == 1 && (in.type() == T_LONG || in.type() == T_DOUBLE)) {
1362 ++parameter_count; // need room for return value
1363 }
1364 if (target->method_holder()->is_interface()) {
1365 assem.invokespecial(target);
1366 } else {
1367 assem.invokevirtual(target);
1368 }
1369
1370 if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) {
1371 assem.checkcast(in.as_symbol(THREAD));
1372 }
1373 assem._return(in.type());
1374 return parameter_count;
1375 }
1376
1377 static int assemble_abstract_method_error(
1378 BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* message, TRAPS) {
1379
1380 Symbol* errorName = vmSymbols::java_lang_AbstractMethodError();
1381 Symbol* init = vmSymbols::object_initializer_name(); 816 Symbol* init = vmSymbols::object_initializer_name();
1382 Symbol* sig = vmSymbols::string_void_signature(); 817 Symbol* sig = vmSymbols::string_void_signature();
1383 818
1384 BytecodeAssembler assem(buffer, cp); 819 BytecodeAssembler assem(buffer, cp);
1385 820
1420 m->set_size_of_parameters(params); 855 m->set_size_of_parameters(params);
1421 m->set_max_stack(max_stack); 856 m->set_max_stack(max_stack);
1422 m->set_max_locals(params); 857 m->set_max_locals(params);
1423 m->constMethod()->set_stackmap_data(NULL); 858 m->constMethod()->set_stackmap_data(NULL);
1424 m->set_code(code_start); 859 m->set_code(code_start);
1425 m->set_force_inline(true);
1426 860
1427 return m; 861 return m;
1428 } 862 }
1429 863
1430 static void switchover_constant_pool(BytecodeConstantPool* bpool, 864 static void switchover_constant_pool(BytecodeConstantPool* bpool,
1446 } 880 }
1447 } 881 }
1448 } 882 }
1449 } 883 }
1450 884
1451 // A "bridge" is a method created by javac to bridge the gap between 885 // Create default_methods list for the current class.
1452 // an implementation and a generically-compatible, but different, signature. 886 // With the VM only processing erased signatures, the VM only
1453 // Bridges have actual bytecode implementation in classfiles. 887 // creates an overpass in a conflict case or a case with no candidates.
1454 // An "overpass", on the other hand, performs the same function as a bridge 888 // This allows virtual methods to override the overpass, but ensures
1455 // but does not occur in a classfile; the VM creates overpass itself, 889 // that a local method search will find the exception rather than an abstract
1456 // when it needs a path to get from a call site to an default method, and 890 // or default method that is not a valid candidate.
1457 // a bridge doesn't exist. 891 static void create_defaults_and_exceptions(
1458 static void create_overpasses(
1459 GrowableArray<EmptyVtableSlot*>* slots, 892 GrowableArray<EmptyVtableSlot*>* slots,
1460 InstanceKlass* klass, TRAPS) { 893 InstanceKlass* klass, TRAPS) {
1461 894
1462 GrowableArray<Method*> overpasses; 895 GrowableArray<Method*> overpasses;
896 GrowableArray<Method*> defaults;
1463 BytecodeConstantPool bpool(klass->constants()); 897 BytecodeConstantPool bpool(klass->constants());
1464 898
1465 for (int i = 0; i < slots->length(); ++i) { 899 for (int i = 0; i < slots->length(); ++i) {
1466 EmptyVtableSlot* slot = slots->at(i); 900 EmptyVtableSlot* slot = slots->at(i);
1467 901
1468 if (slot->is_bound()) { 902 if (slot->is_bound()) {
1469 MethodFamily* method = slot->get_binding(); 903 MethodFamily* method = slot->get_binding();
1470 int max_stack = 0;
1471 BytecodeBuffer buffer; 904 BytecodeBuffer buffer;
1472 905
1473 #ifndef PRODUCT 906 #ifndef PRODUCT
1474 if (TraceDefaultMethods) { 907 if (TraceDefaultMethods) {
1475 tty->print("for slot: "); 908 tty->print("for slot: ");
1476 slot->print_on(tty); 909 slot->print_on(tty);
1477 tty->print_cr(""); 910 tty->print_cr("");
1478 if (method->has_target()) { 911 if (method->has_target()) {
1479 method->print_selected(tty, 1); 912 method->print_selected(tty, 1);
1480 } else { 913 } else if (method->throws_exception()) {
1481 method->print_exception(tty, 1); 914 method->print_exception(tty, 1);
1482 } 915 }
1483 } 916 }
1484 #endif // ndef PRODUCT 917 #endif // ndef PRODUCT
918
1485 if (method->has_target()) { 919 if (method->has_target()) {
1486 Method* selected = method->get_selected_target(); 920 Method* selected = method->get_selected_target();
1487 max_stack = assemble_redirect( 921 if (selected->method_holder()->is_interface()) {
1488 &bpool, &buffer, slot->signature(), selected, CHECK); 922 defaults.push(selected);
923 }
1489 } else if (method->throws_exception()) { 924 } else if (method->throws_exception()) {
1490 max_stack = assemble_abstract_method_error( 925 int max_stack = assemble_method_error(&bpool, &buffer,
1491 &bpool, &buffer, method->get_exception_message(), CHECK); 926 method->get_exception_name(), method->get_exception_message(), CHECK);
1492 } 927 AccessFlags flags = accessFlags_from(
1493 AccessFlags flags = accessFlags_from(
1494 JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); 928 JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE);
1495 Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), 929 Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(),
1496 flags, max_stack, slot->size_of_parameters(), 930 flags, max_stack, slot->size_of_parameters(),
1497 ConstMethod::OVERPASS, CHECK); 931 ConstMethod::OVERPASS, CHECK);
1498 if (m != NULL) { 932 // We push to the methods list:
1499 overpasses.push(m); 933 // overpass methods which are exception throwing methods
934 if (m != NULL) {
935 overpasses.push(m);
936 }
1500 } 937 }
1501 } 938 }
1502 } 939 }
1503 940
1504 #ifndef PRODUCT 941 #ifndef PRODUCT
1505 if (TraceDefaultMethods) { 942 if (TraceDefaultMethods) {
1506 tty->print_cr("Created %d overpass methods", overpasses.length()); 943 tty->print_cr("Created %d overpass methods", overpasses.length());
944 tty->print_cr("Created %d default methods", defaults.length());
1507 } 945 }
1508 #endif // ndef PRODUCT 946 #endif // ndef PRODUCT
1509 947
1510 switchover_constant_pool(&bpool, klass, &overpasses, CHECK); 948 if (overpasses.length() > 0) {
1511 merge_in_new_methods(klass, &overpasses, CHECK); 949 switchover_constant_pool(&bpool, klass, &overpasses, CHECK);
950 merge_in_new_methods(klass, &overpasses, CHECK);
951 }
952 if (defaults.length() > 0) {
953 create_default_methods(klass, &defaults, CHECK);
954 }
955 }
956
957 static void create_default_methods( InstanceKlass* klass,
958 GrowableArray<Method*>* new_methods, TRAPS) {
959
960 int new_size = new_methods->length();
961 Array<Method*>* total_default_methods = MetadataFactory::new_array<Method*>(
962 klass->class_loader_data(), new_size, NULL, CHECK);
963 for (int index = 0; index < new_size; index++ ) {
964 total_default_methods->at_put(index, new_methods->at(index));
965 }
966 Method::sort_methods(total_default_methods, false, false);
967
968 klass->set_default_methods(total_default_methods);
1512 } 969 }
1513 970
1514 static void sort_methods(GrowableArray<Method*>* methods) { 971 static void sort_methods(GrowableArray<Method*>* methods) {
1515 // Note that this must sort using the same key as is used for sorting 972 // Note that this must sort using the same key as is used for sorting
1516 // methods in InstanceKlass. 973 // methods in InstanceKlass.
1614 if (original_ordering->length() > 0) { 1071 if (original_ordering->length() > 0) {
1615 klass->set_method_ordering(merged_ordering); 1072 klass->set_method_ordering(merged_ordering);
1616 MetadataFactory::free_array(cld, original_ordering); 1073 MetadataFactory::free_array(cld, original_ordering);
1617 } 1074 }
1618 } 1075 }
1619