765 // if the method in question is public, protected, or private. 766 // If the answer is not root_m, it is conservatively correct 767 // to return NULL, even if the CHA encountered irrelevant 768 // methods in other packages. 769 // %%% TO DO: Work out logic for package-private methods 770 // with the same name but different vtable indexes. 771 return NULL; 772 } 773 return CURRENT_THREAD_ENV->get_method(target()); 774 } 775 776 // ------------------------------------------------------------------ 777 // ciMethod::resolve_invoke 778 // 779 // Given a known receiver klass, find the target for the call. 780 // Return NULL if the call has no target or the target is abstract. 781 ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access) { 782 check_is_loaded(); 783 VM_ENTRY_MARK; 784 785 KlassHandle caller_klass (THREAD, caller->get_Klass()); 786 KlassHandle h_recv (THREAD, exact_receiver->get_Klass()); 787 KlassHandle h_resolved (THREAD, holder()->get_Klass()); 788 Symbol* h_name = name()->get_symbol(); 789 Symbol* h_signature = signature()->get_symbol(); 790 791 LinkInfo link_info(h_resolved, h_name, h_signature, caller_klass, 792 check_access ? LinkInfo::needs_access_check : LinkInfo::skip_access_check); 793 methodHandle m; 794 // Only do exact lookup if receiver klass has been linked. Otherwise, 795 // the vtable has not been setup, and the LinkResolver will fail. 796 if (h_recv->is_array_klass() 797 || 798 InstanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) { 799 if (holder()->is_interface()) { 800 m = LinkResolver::resolve_interface_call_or_null(h_recv, link_info); 801 } else { 802 m = LinkResolver::resolve_virtual_call_or_null(h_recv, link_info); 803 } 804 } 805 806 if (m.is_null()) { 807 // Return NULL only if there was a problem with lookup (uninitialized class, etc.) 808 return NULL; 809 } 810 811 ciMethod* result = this; 812 if (m() != get_Method()) { 813 result = CURRENT_THREAD_ENV->get_method(m()); 814 } 815 816 // Don't return abstract methods because they aren't 817 // optimizable or interesting. 818 if (result->is_abstract()) { 819 return NULL; 820 } else { 821 return result; 822 } 823 } 824 825 // ------------------------------------------------------------------ 826 // ciMethod::resolve_vtable_index 827 // 828 // Given a known receiver klass, find the vtable index for the call. 829 // Return Method::invalid_vtable_index if the vtable_index is unknown. 830 int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) { 831 check_is_loaded(); 832 833 int vtable_index = Method::invalid_vtable_index; 834 // Only do lookup if receiver klass has been linked. Otherwise, 835 // the vtable has not been setup, and the LinkResolver will fail. 836 if (!receiver->is_interface() 837 && (!receiver->is_instance_klass() || 838 receiver->as_instance_klass()->is_linked())) { 839 VM_ENTRY_MARK; 840 841 KlassHandle caller_klass (THREAD, caller->get_Klass()); 842 KlassHandle h_recv (THREAD, receiver->get_Klass()); 843 Symbol* h_name = name()->get_symbol(); 844 Symbol* h_signature = signature()->get_symbol(); 845 846 LinkInfo link_info(h_recv, h_name, h_signature, caller_klass); 847 vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, link_info); 848 if (vtable_index == Method::nonvirtual_vtable_index) { 849 // A statically bound method. Return "no such index". 850 vtable_index = Method::invalid_vtable_index; 851 } 852 } 853 854 return vtable_index; 855 } 856 857 // ------------------------------------------------------------------ 858 // ciMethod::interpreter_call_site_count 859 int ciMethod::interpreter_call_site_count(int bci) { 860 if (method_data() != NULL) { 861 ResourceMark rm; 862 ciProfileData* data = method_data()->bci_to_data(bci); 863 if (data != NULL && data->is_CounterData()) { 864 return scale_count(data->as_CounterData()->count()); 865 } 866 } 867 return -1; // unknown | 765 // if the method in question is public, protected, or private. 766 // If the answer is not root_m, it is conservatively correct 767 // to return NULL, even if the CHA encountered irrelevant 768 // methods in other packages. 769 // %%% TO DO: Work out logic for package-private methods 770 // with the same name but different vtable indexes. 771 return NULL; 772 } 773 return CURRENT_THREAD_ENV->get_method(target()); 774 } 775 776 // ------------------------------------------------------------------ 777 // ciMethod::resolve_invoke 778 // 779 // Given a known receiver klass, find the target for the call. 780 // Return NULL if the call has no target or the target is abstract. 781 ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access) { 782 check_is_loaded(); 783 VM_ENTRY_MARK; 784 785 Klass* caller_klass = caller->get_Klass(); 786 Klass* recv = exact_receiver->get_Klass(); 787 Klass* resolved = holder()->get_Klass(); 788 Symbol* h_name = name()->get_symbol(); 789 Symbol* h_signature = signature()->get_symbol(); 790 791 LinkInfo link_info(resolved, h_name, h_signature, caller_klass, 792 check_access ? LinkInfo::needs_access_check : LinkInfo::skip_access_check); 793 methodHandle m; 794 // Only do exact lookup if receiver klass has been linked. Otherwise, 795 // the vtable has not been setup, and the LinkResolver will fail. 796 if (recv->is_array_klass() 797 || 798 InstanceKlass::cast(recv)->is_linked() && !exact_receiver->is_interface()) { 799 if (holder()->is_interface()) { 800 m = LinkResolver::resolve_interface_call_or_null(recv, link_info); 801 } else { 802 m = LinkResolver::resolve_virtual_call_or_null(recv, link_info); 803 } 804 } 805 806 if (m.is_null()) { 807 // Return NULL only if there was a problem with lookup (uninitialized class, etc.) 808 return NULL; 809 } 810 811 ciMethod* result = this; 812 if (m() != get_Method()) { 813 result = CURRENT_THREAD_ENV->get_method(m()); 814 } 815 816 // Don't return abstract methods because they aren't 817 // optimizable or interesting. 818 if (result->is_abstract()) { 819 return NULL; 820 } else { 821 return result; 822 } 823 } 824 825 // ------------------------------------------------------------------ 826 // ciMethod::resolve_vtable_index 827 // 828 // Given a known receiver klass, find the vtable index for the call. 829 // Return Method::invalid_vtable_index if the vtable_index is unknown. 830 int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) { 831 check_is_loaded(); 832 833 int vtable_index = Method::invalid_vtable_index; 834 // Only do lookup if receiver klass has been linked. Otherwise, 835 // the vtable has not been setup, and the LinkResolver will fail. 836 if (!receiver->is_interface() 837 && (!receiver->is_instance_klass() || 838 receiver->as_instance_klass()->is_linked())) { 839 VM_ENTRY_MARK; 840 841 Klass* caller_klass = caller->get_Klass(); 842 Klass* recv = receiver->get_Klass(); 843 Symbol* h_name = name()->get_symbol(); 844 Symbol* h_signature = signature()->get_symbol(); 845 846 LinkInfo link_info(recv, h_name, h_signature, caller_klass); 847 vtable_index = LinkResolver::resolve_virtual_vtable_index(recv, link_info); 848 if (vtable_index == Method::nonvirtual_vtable_index) { 849 // A statically bound method. Return "no such index". 850 vtable_index = Method::invalid_vtable_index; 851 } 852 } 853 854 return vtable_index; 855 } 856 857 // ------------------------------------------------------------------ 858 // ciMethod::interpreter_call_site_count 859 int ciMethod::interpreter_call_site_count(int bci) { 860 if (method_data() != NULL) { 861 ResourceMark rm; 862 ciProfileData* data = method_data()->bci_to_data(bci); 863 if (data != NULL && data->is_CounterData()) { 864 return scale_count(data->as_CounterData()->count()); 865 } 866 } 867 return -1; // unknown |