Mercurial > hg > graal-jvmci-8
comparison src/share/vm/classfile/defaultMethods.cpp @ 13086:096c224171c4
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 20 Nov 2013 00:10:38 +0100 |
parents | cefad50507d8 fce21ac5968d |
children | 02f27ecb4f3a |
comparison
equal
deleted
inserted
replaced
12782:92b7ec34ddfa | 13086:096c224171c4 |
---|---|
169 _cancelled = false; | 169 _cancelled = false; |
170 _path.clear(); | 170 _path.clear(); |
171 } | 171 } |
172 bool is_cancelled() const { return _cancelled; } | 172 bool is_cancelled() const { return _cancelled; } |
173 | 173 |
174 // This code used to skip interface classes because their only | |
175 // superclass was j.l.Object which would be also covered by class | |
176 // superclass hierarchy walks. Now that the starting point can be | |
177 // an interface, we must ensure we catch j.l.Object as the super. | |
174 static bool has_super(InstanceKlass* cls) { | 178 static bool has_super(InstanceKlass* cls) { |
175 return cls->super() != NULL && !cls->is_interface(); | 179 return cls->super() != NULL; |
176 } | 180 } |
177 | 181 |
178 Node* node_at_depth(int i) const { | 182 Node* node_at_depth(int i) const { |
179 return (i >= _path.length()) ? NULL : _path.at(_path.length() - i - 1); | 183 return (i >= _path.length()) ? NULL : _path.at(_path.length() - i - 1); |
180 } | 184 } |
343 guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index"); | 347 guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index"); |
344 _members.at(*index).second = DISQUALIFIED; | 348 _members.at(*index).second = DISQUALIFIED; |
345 } | 349 } |
346 | 350 |
347 Symbol* generate_no_defaults_message(TRAPS) const; | 351 Symbol* generate_no_defaults_message(TRAPS) const; |
348 Symbol* generate_abstract_method_message(Method* method, TRAPS) const; | |
349 Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const; | 352 Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const; |
350 | 353 |
351 public: | 354 public: |
352 | 355 |
353 MethodFamily() | 356 MethodFamily() |
390 void determine_target(InstanceKlass* root, TRAPS) { | 393 void determine_target(InstanceKlass* root, TRAPS) { |
391 if (has_target() || throws_exception()) { | 394 if (has_target() || throws_exception()) { |
392 return; | 395 return; |
393 } | 396 } |
394 | 397 |
398 // Qualified methods are maximally-specific methods | |
399 // These include public, instance concrete (=default) and abstract methods | |
395 GrowableArray<Method*> qualified_methods; | 400 GrowableArray<Method*> qualified_methods; |
401 int num_defaults = 0; | |
402 int default_index = -1; | |
403 int qualified_index = -1; | |
396 for (int i = 0; i < _members.length(); ++i) { | 404 for (int i = 0; i < _members.length(); ++i) { |
397 Pair<Method*,QualifiedState> entry = _members.at(i); | 405 Pair<Method*,QualifiedState> entry = _members.at(i); |
398 if (entry.second == QUALIFIED) { | 406 if (entry.second == QUALIFIED) { |
399 qualified_methods.append(entry.first); | 407 qualified_methods.append(entry.first); |
408 qualified_index++; | |
409 if (entry.first->is_default_method()) { | |
410 num_defaults++; | |
411 default_index = qualified_index; | |
412 | |
413 } | |
400 } | 414 } |
401 } | 415 } |
402 | 416 |
403 if (qualified_methods.length() == 0) { | 417 if (qualified_methods.length() == 0) { |
404 _exception_message = generate_no_defaults_message(CHECK); | 418 _exception_message = generate_no_defaults_message(CHECK); |
405 _exception_name = vmSymbols::java_lang_AbstractMethodError(); | 419 _exception_name = vmSymbols::java_lang_AbstractMethodError(); |
406 } else if (qualified_methods.length() == 1) { | 420 // If only one qualified method is default, select that |
407 Method* method = qualified_methods.at(0); | 421 } else if (num_defaults == 1) { |
408 if (method->is_abstract()) { | 422 _selected_target = qualified_methods.at(default_index); |
409 _exception_message = generate_abstract_method_message(method, CHECK); | 423 } else if (num_defaults > 1) { |
410 _exception_name = vmSymbols::java_lang_AbstractMethodError(); | |
411 } else { | |
412 _selected_target = qualified_methods.at(0); | |
413 } | |
414 } else { | |
415 _exception_message = generate_conflicts_message(&qualified_methods,CHECK); | 424 _exception_message = generate_conflicts_message(&qualified_methods,CHECK); |
416 _exception_name = vmSymbols::java_lang_IncompatibleClassChangeError(); | 425 _exception_name = vmSymbols::java_lang_IncompatibleClassChangeError(); |
417 } | 426 if (TraceDefaultMethods) { |
418 | 427 _exception_message->print_value_on(tty); |
419 assert((has_target() ^ throws_exception()) == 1, | 428 tty->print_cr(""); |
420 "One and only one must be true"); | 429 } |
430 } | |
431 // leave abstract methods alone, they will be found via normal search path | |
421 } | 432 } |
422 | 433 |
423 bool contains_signature(Symbol* query) { | 434 bool contains_signature(Symbol* query) { |
424 for (int i = 0; i < _members.length(); ++i) { | 435 for (int i = 0; i < _members.length(); ++i) { |
425 if (query == _members.at(i).first->signature()) { | 436 if (query == _members.at(i).first->signature()) { |
471 #endif // ndef PRODUCT | 482 #endif // ndef PRODUCT |
472 }; | 483 }; |
473 | 484 |
474 Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const { | 485 Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const { |
475 return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL); | 486 return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL); |
476 } | |
477 | |
478 Symbol* MethodFamily::generate_abstract_method_message(Method* method, TRAPS) const { | |
479 Symbol* klass = method->klass_name(); | |
480 Symbol* name = method->name(); | |
481 Symbol* sig = method->signature(); | |
482 stringStream ss; | |
483 ss.print("Method "); | |
484 ss.write((const char*)klass->bytes(), klass->utf8_length()); | |
485 ss.print("."); | |
486 ss.write((const char*)name->bytes(), name->utf8_length()); | |
487 ss.write((const char*)sig->bytes(), sig->utf8_length()); | |
488 ss.print(" is abstract"); | |
489 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); | |
490 } | 487 } |
491 | 488 |
492 Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const { | 489 Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const { |
493 stringStream ss; | 490 stringStream ss; |
494 ss.print("Conflicting default methods:"); | 491 ss.print("Conflicting default methods:"); |
593 print_slot(str, name(), signature()); | 590 print_slot(str, name(), signature()); |
594 } | 591 } |
595 #endif // ndef PRODUCT | 592 #endif // ndef PRODUCT |
596 }; | 593 }; |
597 | 594 |
595 static bool already_in_vtable_slots(GrowableArray<EmptyVtableSlot*>* slots, Method* m) { | |
596 bool found = false; | |
597 for (int j = 0; j < slots->length(); ++j) { | |
598 if (slots->at(j)->name() == m->name() && | |
599 slots->at(j)->signature() == m->signature() ) { | |
600 found = true; | |
601 break; | |
602 } | |
603 } | |
604 return found; | |
605 } | |
606 | |
598 static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots( | 607 static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots( |
599 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { | 608 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { |
600 | 609 |
601 assert(klass != NULL, "Must be valid class"); | 610 assert(klass != NULL, "Must be valid class"); |
602 | 611 |
603 GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>(); | 612 GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>(); |
604 | 613 |
605 // All miranda methods are obvious candidates | 614 // All miranda methods are obvious candidates |
606 for (int i = 0; i < mirandas->length(); ++i) { | 615 for (int i = 0; i < mirandas->length(); ++i) { |
607 EmptyVtableSlot* slot = new EmptyVtableSlot(mirandas->at(i)); | 616 Method* m = mirandas->at(i); |
608 slots->append(slot); | 617 if (!already_in_vtable_slots(slots, m)) { |
618 slots->append(new EmptyVtableSlot(m)); | |
619 } | |
609 } | 620 } |
610 | 621 |
611 // Also any overpasses in our superclasses, that we haven't implemented. | 622 // Also any overpasses in our superclasses, that we haven't implemented. |
612 // (can't use the vtable because it is not guaranteed to be initialized yet) | 623 // (can't use the vtable because it is not guaranteed to be initialized yet) |
613 InstanceKlass* super = klass->java_super(); | 624 InstanceKlass* super = klass->java_super(); |
619 // default method processing that occurred on behalf of our superclass, | 630 // default method processing that occurred on behalf of our superclass, |
620 // so it's a method we want to re-examine in this new context. That is, | 631 // so it's a method we want to re-examine in this new context. That is, |
621 // unless we have a real implementation of it in the current class. | 632 // unless we have a real implementation of it in the current class. |
622 Method* impl = klass->lookup_method(m->name(), m->signature()); | 633 Method* impl = klass->lookup_method(m->name(), m->signature()); |
623 if (impl == NULL || impl->is_overpass()) { | 634 if (impl == NULL || impl->is_overpass()) { |
624 slots->append(new EmptyVtableSlot(m)); | 635 if (!already_in_vtable_slots(slots, m)) { |
636 slots->append(new EmptyVtableSlot(m)); | |
637 } | |
638 } | |
639 } | |
640 } | |
641 | |
642 // also any default methods in our superclasses | |
643 if (super->default_methods() != NULL) { | |
644 for (int i = 0; i < super->default_methods()->length(); ++i) { | |
645 Method* m = super->default_methods()->at(i); | |
646 // m is a method that would have been a miranda if not for the | |
647 // default method processing that occurred on behalf of our superclass, | |
648 // so it's a method we want to re-examine in this new context. That is, | |
649 // unless we have a real implementation of it in the current class. | |
650 Method* impl = klass->lookup_method(m->name(), m->signature()); | |
651 if (impl == NULL || impl->is_overpass()) { | |
652 if (!already_in_vtable_slots(slots, m)) { | |
653 slots->append(new EmptyVtableSlot(m)); | |
654 } | |
625 } | 655 } |
626 } | 656 } |
627 } | 657 } |
628 super = super->java_super(); | 658 super = super->java_super(); |
629 } | 659 } |
676 InstanceKlass* iklass = current_class(); | 706 InstanceKlass* iklass = current_class(); |
677 | 707 |
678 Method* m = iklass->find_method(_method_name, _method_signature); | 708 Method* m = iklass->find_method(_method_name, _method_signature); |
679 // private interface methods are not candidates for default methods | 709 // private interface methods are not candidates for default methods |
680 // invokespecial to private interface methods doesn't use default method logic | 710 // invokespecial to private interface methods doesn't use default method logic |
711 // The overpasses are your supertypes' errors, we do not include them | |
681 // future: take access controls into account for superclass methods | 712 // future: take access controls into account for superclass methods |
682 if (m != NULL && (!iklass->is_interface() || m->is_public())) { | 713 if (m != NULL && !m->is_static() && !m->is_overpass() && |
714 (!iklass->is_interface() || m->is_public())) { | |
683 if (_family == NULL) { | 715 if (_family == NULL) { |
684 _family = new StatefulMethodFamily(); | 716 _family = new StatefulMethodFamily(); |
685 } | 717 } |
686 | 718 |
687 if (iklass->is_interface()) { | 719 if (iklass->is_interface()) { |
698 | 730 |
699 }; | 731 }; |
700 | 732 |
701 | 733 |
702 | 734 |
703 static void create_overpasses( | 735 static void create_defaults_and_exceptions( |
704 GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS); | 736 GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS); |
705 | 737 |
706 static void generate_erased_defaults( | 738 static void generate_erased_defaults( |
707 InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots, | 739 InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots, |
708 EmptyVtableSlot* slot, TRAPS) { | 740 EmptyVtableSlot* slot, TRAPS) { |
718 slot->bind_family(family); | 750 slot->bind_family(family); |
719 } | 751 } |
720 } | 752 } |
721 | 753 |
722 static void merge_in_new_methods(InstanceKlass* klass, | 754 static void merge_in_new_methods(InstanceKlass* klass, |
755 GrowableArray<Method*>* new_methods, TRAPS); | |
756 static void create_default_methods( InstanceKlass* klass, | |
723 GrowableArray<Method*>* new_methods, TRAPS); | 757 GrowableArray<Method*>* new_methods, TRAPS); |
724 | 758 |
725 // This is the guts of the default methods implementation. This is called just | 759 // This is the guts of the default methods implementation. This is called just |
726 // after the classfile has been parsed if some ancestor has default methods. | 760 // after the classfile has been parsed if some ancestor has default methods. |
727 // | 761 // |
751 loadKeepAlive.run(klass); | 785 loadKeepAlive.run(klass); |
752 | 786 |
753 #ifndef PRODUCT | 787 #ifndef PRODUCT |
754 if (TraceDefaultMethods) { | 788 if (TraceDefaultMethods) { |
755 ResourceMark rm; // be careful with these! | 789 ResourceMark rm; // be careful with these! |
756 tty->print_cr("Class %s requires default method processing", | 790 tty->print_cr("%s %s requires default method processing", |
791 klass->is_interface() ? "Interface" : "Class", | |
757 klass->name()->as_klass_external_name()); | 792 klass->name()->as_klass_external_name()); |
758 PrintHierarchy printer; | 793 PrintHierarchy printer; |
759 printer.run(klass); | 794 printer.run(klass); |
760 } | 795 } |
761 #endif // ndef PRODUCT | 796 #endif // ndef PRODUCT |
776 | 811 |
777 generate_erased_defaults(klass, empty_slots, slot, CHECK); | 812 generate_erased_defaults(klass, empty_slots, slot, CHECK); |
778 } | 813 } |
779 #ifndef PRODUCT | 814 #ifndef PRODUCT |
780 if (TraceDefaultMethods) { | 815 if (TraceDefaultMethods) { |
781 tty->print_cr("Creating overpasses..."); | 816 tty->print_cr("Creating defaults and overpasses..."); |
782 } | 817 } |
783 #endif // ndef PRODUCT | 818 #endif // ndef PRODUCT |
784 | 819 |
785 create_overpasses(empty_slots, klass, CHECK); | 820 create_defaults_and_exceptions(empty_slots, klass, CHECK); |
786 | 821 |
787 #ifndef PRODUCT | 822 #ifndef PRODUCT |
788 if (TraceDefaultMethods) { | 823 if (TraceDefaultMethods) { |
789 tty->print_cr("Default method processing complete"); | 824 tty->print_cr("Default method processing complete"); |
790 } | 825 } |
791 #endif // ndef PRODUCT | 826 #endif // ndef PRODUCT |
792 } | |
793 | |
794 | |
795 | |
796 #ifdef ASSERT | |
797 // Return true is broad type is a covariant return of narrow type | |
798 static bool covariant_return_type(BasicType narrow, BasicType broad) { | |
799 if (narrow == broad) { | |
800 return true; | |
801 } | |
802 if (broad == T_OBJECT) { | |
803 return true; | |
804 } | |
805 return false; | |
806 } | |
807 #endif | |
808 | |
809 static int assemble_redirect( | |
810 BytecodeConstantPool* cp, BytecodeBuffer* buffer, | |
811 Symbol* incoming, Method* target, TRAPS) { | |
812 | |
813 BytecodeAssembler assem(buffer, cp); | |
814 | |
815 SignatureStream in(incoming, true); | |
816 SignatureStream out(target->signature(), true); | |
817 u2 parameter_count = 0; | |
818 | |
819 assem.aload(parameter_count++); // load 'this' | |
820 | |
821 while (!in.at_return_type()) { | |
822 assert(!out.at_return_type(), "Parameter counts do not match"); | |
823 BasicType bt = in.type(); | |
824 assert(out.type() == bt, "Parameter types are not compatible"); | |
825 assem.load(bt, parameter_count); | |
826 if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) { | |
827 assem.checkcast(out.as_symbol(THREAD)); | |
828 } else if (bt == T_LONG || bt == T_DOUBLE) { | |
829 ++parameter_count; // longs and doubles use two slots | |
830 } | |
831 ++parameter_count; | |
832 in.next(); | |
833 out.next(); | |
834 } | |
835 assert(out.at_return_type(), "Parameter counts do not match"); | |
836 assert(covariant_return_type(out.type(), in.type()), "Return types are not compatible"); | |
837 | |
838 if (parameter_count == 1 && (in.type() == T_LONG || in.type() == T_DOUBLE)) { | |
839 ++parameter_count; // need room for return value | |
840 } | |
841 if (target->method_holder()->is_interface()) { | |
842 assem.invokespecial(target); | |
843 } else { | |
844 assem.invokevirtual(target); | |
845 } | |
846 | |
847 if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) { | |
848 assem.checkcast(in.as_symbol(THREAD)); | |
849 } | |
850 assem._return(in.type()); | |
851 return parameter_count; | |
852 } | 827 } |
853 | 828 |
854 static int assemble_method_error( | 829 static int assemble_method_error( |
855 BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* errorName, Symbol* message, TRAPS) { | 830 BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* errorName, Symbol* message, TRAPS) { |
856 | 831 |
896 m->set_size_of_parameters(params); | 871 m->set_size_of_parameters(params); |
897 m->set_max_stack(max_stack); | 872 m->set_max_stack(max_stack); |
898 m->set_max_locals(params); | 873 m->set_max_locals(params); |
899 m->constMethod()->set_stackmap_data(NULL); | 874 m->constMethod()->set_stackmap_data(NULL); |
900 m->set_code(code_start); | 875 m->set_code(code_start); |
901 m->set_force_inline(true); | |
902 | 876 |
903 return m; | 877 return m; |
904 } | 878 } |
905 | 879 |
906 static void switchover_constant_pool(BytecodeConstantPool* bpool, | 880 static void switchover_constant_pool(BytecodeConstantPool* bpool, |
922 } | 896 } |
923 } | 897 } |
924 } | 898 } |
925 } | 899 } |
926 | 900 |
927 // A "bridge" is a method created by javac to bridge the gap between | 901 // Create default_methods list for the current class. |
928 // an implementation and a generically-compatible, but different, signature. | 902 // With the VM only processing erased signatures, the VM only |
929 // Bridges have actual bytecode implementation in classfiles. | 903 // creates an overpass in a conflict case or a case with no candidates. |
930 // An "overpass", on the other hand, performs the same function as a bridge | 904 // This allows virtual methods to override the overpass, but ensures |
931 // but does not occur in a classfile; the VM creates overpass itself, | 905 // that a local method search will find the exception rather than an abstract |
932 // when it needs a path to get from a call site to an default method, and | 906 // or default method that is not a valid candidate. |
933 // a bridge doesn't exist. | 907 static void create_defaults_and_exceptions( |
934 static void create_overpasses( | |
935 GrowableArray<EmptyVtableSlot*>* slots, | 908 GrowableArray<EmptyVtableSlot*>* slots, |
936 InstanceKlass* klass, TRAPS) { | 909 InstanceKlass* klass, TRAPS) { |
937 | 910 |
938 GrowableArray<Method*> overpasses; | 911 GrowableArray<Method*> overpasses; |
912 GrowableArray<Method*> defaults; | |
939 BytecodeConstantPool bpool(klass->constants()); | 913 BytecodeConstantPool bpool(klass->constants()); |
940 | 914 |
941 for (int i = 0; i < slots->length(); ++i) { | 915 for (int i = 0; i < slots->length(); ++i) { |
942 EmptyVtableSlot* slot = slots->at(i); | 916 EmptyVtableSlot* slot = slots->at(i); |
943 | 917 |
944 if (slot->is_bound()) { | 918 if (slot->is_bound()) { |
945 MethodFamily* method = slot->get_binding(); | 919 MethodFamily* method = slot->get_binding(); |
946 int max_stack = 0; | |
947 BytecodeBuffer buffer; | 920 BytecodeBuffer buffer; |
948 | 921 |
949 #ifndef PRODUCT | 922 #ifndef PRODUCT |
950 if (TraceDefaultMethods) { | 923 if (TraceDefaultMethods) { |
951 tty->print("for slot: "); | 924 tty->print("for slot: "); |
952 slot->print_on(tty); | 925 slot->print_on(tty); |
953 tty->print_cr(""); | 926 tty->print_cr(""); |
954 if (method->has_target()) { | 927 if (method->has_target()) { |
955 method->print_selected(tty, 1); | 928 method->print_selected(tty, 1); |
956 } else { | 929 } else if (method->throws_exception()) { |
957 method->print_exception(tty, 1); | 930 method->print_exception(tty, 1); |
958 } | 931 } |
959 } | 932 } |
960 #endif // ndef PRODUCT | 933 #endif // ndef PRODUCT |
934 | |
961 if (method->has_target()) { | 935 if (method->has_target()) { |
962 Method* selected = method->get_selected_target(); | 936 Method* selected = method->get_selected_target(); |
963 if (selected->method_holder()->is_interface()) { | 937 if (selected->method_holder()->is_interface()) { |
964 max_stack = assemble_redirect( | 938 defaults.push(selected); |
965 &bpool, &buffer, slot->signature(), selected, CHECK); | |
966 } | 939 } |
967 } else if (method->throws_exception()) { | 940 } else if (method->throws_exception()) { |
968 max_stack = assemble_method_error(&bpool, &buffer, method->get_exception_name(), method->get_exception_message(), CHECK); | 941 int max_stack = assemble_method_error(&bpool, &buffer, |
969 } | 942 method->get_exception_name(), method->get_exception_message(), CHECK); |
970 if (max_stack != 0) { | |
971 AccessFlags flags = accessFlags_from( | 943 AccessFlags flags = accessFlags_from( |
972 JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); | 944 JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); |
973 Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), | 945 Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), |
974 flags, max_stack, slot->size_of_parameters(), | 946 flags, max_stack, slot->size_of_parameters(), |
975 ConstMethod::OVERPASS, CHECK); | 947 ConstMethod::OVERPASS, CHECK); |
948 // We push to the methods list: | |
949 // overpass methods which are exception throwing methods | |
976 if (m != NULL) { | 950 if (m != NULL) { |
977 overpasses.push(m); | 951 overpasses.push(m); |
978 } | 952 } |
979 } | 953 } |
980 } | 954 } |
981 } | 955 } |
982 | 956 |
983 #ifndef PRODUCT | 957 #ifndef PRODUCT |
984 if (TraceDefaultMethods) { | 958 if (TraceDefaultMethods) { |
985 tty->print_cr("Created %d overpass methods", overpasses.length()); | 959 tty->print_cr("Created %d overpass methods", overpasses.length()); |
960 tty->print_cr("Created %d default methods", defaults.length()); | |
986 } | 961 } |
987 #endif // ndef PRODUCT | 962 #endif // ndef PRODUCT |
988 | 963 |
989 switchover_constant_pool(&bpool, klass, &overpasses, CHECK); | 964 if (overpasses.length() > 0) { |
990 merge_in_new_methods(klass, &overpasses, CHECK); | 965 switchover_constant_pool(&bpool, klass, &overpasses, CHECK); |
966 merge_in_new_methods(klass, &overpasses, CHECK); | |
967 } | |
968 if (defaults.length() > 0) { | |
969 create_default_methods(klass, &defaults, CHECK); | |
970 } | |
971 } | |
972 | |
973 static void create_default_methods( InstanceKlass* klass, | |
974 GrowableArray<Method*>* new_methods, TRAPS) { | |
975 | |
976 int new_size = new_methods->length(); | |
977 Array<Method*>* total_default_methods = MetadataFactory::new_array<Method*>( | |
978 klass->class_loader_data(), new_size, NULL, CHECK); | |
979 for (int index = 0; index < new_size; index++ ) { | |
980 total_default_methods->at_put(index, new_methods->at(index)); | |
981 } | |
982 Method::sort_methods(total_default_methods, false, false); | |
983 | |
984 klass->set_default_methods(total_default_methods); | |
991 } | 985 } |
992 | 986 |
993 static void sort_methods(GrowableArray<Method*>* methods) { | 987 static void sort_methods(GrowableArray<Method*>* methods) { |
994 // Note that this must sort using the same key as is used for sorting | 988 // Note that this must sort using the same key as is used for sorting |
995 // methods in InstanceKlass. | 989 // methods in InstanceKlass. |
1087 // Replace klass methods with new merged lists | 1081 // Replace klass methods with new merged lists |
1088 klass->set_methods(merged_methods); | 1082 klass->set_methods(merged_methods); |
1089 klass->set_initial_method_idnum(new_size); | 1083 klass->set_initial_method_idnum(new_size); |
1090 | 1084 |
1091 ClassLoaderData* cld = klass->class_loader_data(); | 1085 ClassLoaderData* cld = klass->class_loader_data(); |
1092 MetadataFactory::free_array(cld, original_methods); | 1086 if (original_methods ->length() > 0) { |
1087 MetadataFactory::free_array(cld, original_methods); | |
1088 } | |
1093 if (original_ordering->length() > 0) { | 1089 if (original_ordering->length() > 0) { |
1094 klass->set_method_ordering(merged_ordering); | 1090 klass->set_method_ordering(merged_ordering); |
1095 MetadataFactory::free_array(cld, original_ordering); | 1091 MetadataFactory::free_array(cld, original_ordering); |
1096 } | 1092 } |
1097 } | 1093 } |