663 inline oop Dependencies::DepStream::recorded_oop_at(int i) { 664 return (_code != NULL) 665 ? _code->oop_at(i) 666 : JNIHandles::resolve(_deps->oop_recorder()->oop_at(i)); 667 } 668 669 Metadata* Dependencies::DepStream::argument(int i) { 670 Metadata* result = recorded_metadata_at(argument_index(i)); 671 672 if (result == NULL) { // Explicit context argument can be compressed 673 int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg 674 if (ctxkj >= 0 && i == ctxkj && ctxkj+1 < argument_count()) { 675 result = ctxk_encoded_as_null(type(), argument(ctxkj+1)); 676 } 677 } 678 679 assert(result == NULL || result->is_klass() || result->is_method(), "must be"); 680 return result; 681 } 682 683 oop Dependencies::DepStream::argument_oop(int i) { 684 oop result = recorded_oop_at(argument_index(i)); 685 assert(result == NULL || result->is_oop(), "must be"); 686 return result; 687 } 688 689 Klass* Dependencies::DepStream::context_type() { 690 assert(must_be_in_vm(), "raw oops here"); 691 692 // Most dependencies have an explicit context type argument. 693 { 694 int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg 695 if (ctxkj >= 0) { 696 Metadata* k = argument(ctxkj); 697 assert(k != NULL && k->is_klass(), "type check"); 698 return (Klass*)k; 699 } 700 } 701 702 // Some dependencies are using the klass of the first object 703 // argument as implicit context type (e.g. call_site_target_value). 704 { 705 int ctxkj = dep_implicit_context_arg(type()); 706 if (ctxkj >= 0) { 707 Klass* k = argument_oop(ctxkj)->klass(); 708 assert(k != NULL && k->is_klass(), "type check"); 709 return (Klass*) k; 710 } 711 } 712 713 // And some dependencies don't have a context type at all, 714 // e.g. evol_method. 715 return NULL; 716 } 717 718 /// Checking dependencies: 719 720 // This hierarchy walker inspects subtypes of a given type, 721 // trying to find a "bad" class which breaks a dependency. 722 // Such a class is called a "witness" to the broken dependency. 723 // While searching around, we ignore "participants", which 724 // are already known to the dependency. 725 class ClassHierarchyWalker { 726 public: 727 enum { PARTICIPANT_LIMIT = 3 }; 728 729 private: 730 // optional method descriptor to check for: 731 Symbol* _name; 732 Symbol* _signature; 733 734 // special classes which are not allowed to be witnesses: 735 Klass* _participants[PARTICIPANT_LIMIT+1]; 736 int _num_participants; | 663 inline oop Dependencies::DepStream::recorded_oop_at(int i) { 664 return (_code != NULL) 665 ? _code->oop_at(i) 666 : JNIHandles::resolve(_deps->oop_recorder()->oop_at(i)); 667 } 668 669 Metadata* Dependencies::DepStream::argument(int i) { 670 Metadata* result = recorded_metadata_at(argument_index(i)); 671 672 if (result == NULL) { // Explicit context argument can be compressed 673 int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg 674 if (ctxkj >= 0 && i == ctxkj && ctxkj+1 < argument_count()) { 675 result = ctxk_encoded_as_null(type(), argument(ctxkj+1)); 676 } 677 } 678 679 assert(result == NULL || result->is_klass() || result->is_method(), "must be"); 680 return result; 681 } 682 683 /** 684 * Returns a unique identifier for each dependency argument. 685 */ 686 uintptr_t Dependencies::DepStream::get_identifier(int i) { 687 if (has_oop_argument()) { 688 return (uintptr_t)(oopDesc*)argument_oop(i); 689 } else { 690 return (uintptr_t)argument(i); 691 } 692 } 693 694 oop Dependencies::DepStream::argument_oop(int i) { 695 oop result = recorded_oop_at(argument_index(i)); 696 assert(result == NULL || result->is_oop(), "must be"); 697 return result; 698 } 699 700 Klass* Dependencies::DepStream::context_type() { 701 assert(must_be_in_vm(), "raw oops here"); 702 703 // Most dependencies have an explicit context type argument. 704 { 705 int ctxkj = dep_context_arg(type()); // -1 if no explicit context arg 706 if (ctxkj >= 0) { 707 Metadata* k = argument(ctxkj); 708 assert(k != NULL && k->is_klass(), "type check"); 709 return (Klass*)k; 710 } 711 } 712 713 // Some dependencies are using the klass of the first object 714 // argument as implicit context type (e.g. call_site_target_value). 715 { 716 int ctxkj = dep_implicit_context_arg(type()); 717 if (ctxkj >= 0) { 718 Klass* k = argument_oop(ctxkj)->klass(); 719 assert(k != NULL && k->is_klass(), "type check"); 720 return (Klass*) k; 721 } 722 } 723 724 // And some dependencies don't have a context type at all, 725 // e.g. evol_method. 726 return NULL; 727 } 728 729 // ----------------- DependencySignature -------------------------------------- 730 bool DependencySignature::equals(const DependencySignature& sig) const { 731 if (type() != sig.type()) { 732 return false; 733 } 734 735 if (args_count() != sig.args_count()) { 736 return false; 737 } 738 739 for (int i = 0; i < sig.args_count(); i++) { 740 if (arg(i) != sig.arg(i)) { 741 return false; 742 } 743 } 744 return true; 745 } 746 747 void* DependencySignature::operator new (size_t size) throw() { 748 return NEW_RESOURCE_ARRAY(DependencySignature, 1); 749 } 750 751 // ----------------- DependencySignatureBuffer -------------------------------------- 752 DependencySignatureBuffer::DependencySignatureBuffer() { 753 _signatures = NEW_RESOURCE_ARRAY(GrowableArray<DependencySignature*>*, Dependencies::TYPE_LIMIT); 754 memset(_signatures, 0, sizeof(DependencySignature*) * Dependencies::TYPE_LIMIT); 755 } 756 757 /* Check if arguments are identical. Two dependency signatures are considered 758 * identical, if the type as well as all argument identifiers are identical. 759 * If the dependency has not already been checked, the dependency signature is 760 * added to the checked dependencies of the same type. The function returns 761 * false, which causes the dependency to be checked in the caller. 762 */ 763 bool DependencySignatureBuffer::add_if_missing(const DependencySignature& sig) { 764 const int index = sig.type(); 765 GrowableArray<DependencySignature*>* buffer = _signatures[index]; 766 if (buffer == NULL) { 767 buffer = new GrowableArray<DependencySignature*>(); 768 _signatures[index] = buffer; 769 } 770 771 // Check if we have already checked the dependency 772 for (int i = 0; i < buffer->length(); i++) { 773 DependencySignature* checked_signature = buffer->at(i); 774 if (checked_signature->equals(sig)) { 775 return true; 776 } 777 } 778 779 buffer->append(new DependencySignature(sig)); 780 return false; 781 } 782 783 784 /// Checking dependencies: 785 786 // This hierarchy walker inspects subtypes of a given type, 787 // trying to find a "bad" class which breaks a dependency. 788 // Such a class is called a "witness" to the broken dependency. 789 // While searching around, we ignore "participants", which 790 // are already known to the dependency. 791 class ClassHierarchyWalker { 792 public: 793 enum { PARTICIPANT_LIMIT = 3 }; 794 795 private: 796 // optional method descriptor to check for: 797 Symbol* _name; 798 Symbol* _signature; 799 800 // special classes which are not allowed to be witnesses: 801 Klass* _participants[PARTICIPANT_LIMIT+1]; 802 int _num_participants; |