2769 2770 if (opcode == Bytecodes::_invokedynamic) { 2771 address bcp = bcs->bcp(); 2772 if (*(bcp+3) != 0 || *(bcp+4) != 0) { 2773 verify_error(ErrorContext::bad_code(bci), 2774 "Third and fourth operand bytes of invokedynamic must be zero"); 2775 return; 2776 } 2777 } 2778 2779 if (method_name->byte_at(0) == '<') { 2780 // Make sure <init> can only be invoked by invokespecial 2781 if (opcode != Bytecodes::_invokespecial || 2782 method_name != vmSymbols::object_initializer_name()) { 2783 verify_error(ErrorContext::bad_code(bci), 2784 "Illegal call to internal method"); 2785 return; 2786 } 2787 } else if (opcode == Bytecodes::_invokespecial 2788 && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type) 2789 && !ref_class_type.equals(VerificationType::reference_type(current_class()->super()->name()))) { 2790 bool subtype = false; 2791 bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref; 2792 if (!current_class()->is_anonymous()) { 2793 subtype = ref_class_type.is_assignable_from(current_type(), this, false, CHECK_VERIFY(this)); 2794 } else { 2795 VerificationType host_klass_type = 2796 VerificationType::reference_type(current_class()->host_klass()->name()); 2797 subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this)); 2798 2799 // If invokespecial of IMR, need to recheck for same or 2800 // direct interface relative to the host class 2801 have_imr_indirect = (have_imr_indirect && 2802 !is_same_or_direct_interface(current_class()->host_klass(), 2803 host_klass_type, ref_class_type)); 2804 } 2805 if (!subtype) { 2806 verify_error(ErrorContext::bad_code(bci), 2807 "Bad invokespecial instruction: " 2808 "current class isn't assignable to reference class."); 2809 return; 2810 } else if (have_imr_indirect) { 2811 verify_error(ErrorContext::bad_code(bci), 2812 "Bad invokespecial instruction: " 2813 "interface method reference is in an indirect superinterface."); 2814 return; 2815 } 2816 } 2817 2818 // Match method descriptor with operand stack 2819 for (int i = nargs - 1; i >= 0; i--) { // Run backwards 2820 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this)); 2821 } 2822 // Check objectref on operand stack 2823 if (opcode != Bytecodes::_invokestatic && 2824 opcode != Bytecodes::_invokedynamic) { 2825 if (method_name == vmSymbols::object_initializer_name()) { // <init> method 2826 verify_invoke_init(bcs, index, ref_class_type, current_frame, 2827 code_length, in_try_block, this_uninit, cp, stackmap_table, 2828 CHECK_VERIFY(this)); 2829 if (was_recursively_verified()) return; 2830 } else { // other methods 2831 // Ensures that target class is assignable to current class (4.9.2) 2832 if (opcode == Bytecodes::_invokespecial) { 2833 if (!current_class()->is_anonymous()) { 2834 current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); 2835 } else { 2836 // anonymous class invokespecial calls: check if the 2837 // objectref is a subtype of the host_klass of the current class 2838 // to allow an anonymous class to reference methods in the host_klass 2839 VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this)); 2840 VerificationType hosttype = 2841 VerificationType::reference_type(current_class()->host_klass()->name()); 2842 bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this)); 2843 if (!subtype) { 2844 verify_error(ErrorContext::bad_type(current_frame->offset(), 2845 current_frame->stack_top_ctx(), 2846 TypeOrigin::implicit(top)), 2847 "Bad type on operand stack"); 2848 return; 2849 } 2850 } 2851 } else if (opcode == Bytecodes::_invokevirtual) { 2852 VerificationType stack_object_type = 2853 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); 2854 if (current_type() != stack_object_type) { 2855 if (was_recursively_verified()) return; 2856 assert(cp->cache() == NULL, "not rewritten yet"); 2857 Symbol* ref_class_name = 2858 cp->klass_name_at(cp->klass_ref_index_at(index)); 2859 // See the comments in verify_field_instructions() for 2860 // the rationale behind this. 2861 if (name_in_supers(ref_class_name, current_class())) { 2862 Klass* ref_class = load_class(ref_class_name, CHECK); 2863 if (is_protected_access( 2864 _klass, ref_class, method_name, method_sig, true)) { | 2769 2770 if (opcode == Bytecodes::_invokedynamic) { 2771 address bcp = bcs->bcp(); 2772 if (*(bcp+3) != 0 || *(bcp+4) != 0) { 2773 verify_error(ErrorContext::bad_code(bci), 2774 "Third and fourth operand bytes of invokedynamic must be zero"); 2775 return; 2776 } 2777 } 2778 2779 if (method_name->byte_at(0) == '<') { 2780 // Make sure <init> can only be invoked by invokespecial 2781 if (opcode != Bytecodes::_invokespecial || 2782 method_name != vmSymbols::object_initializer_name()) { 2783 verify_error(ErrorContext::bad_code(bci), 2784 "Illegal call to internal method"); 2785 return; 2786 } 2787 } else if (opcode == Bytecodes::_invokespecial 2788 && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type) 2789 && !ref_class_type.equals(VerificationType::reference_type( 2790 current_class()->super()->name()))) { 2791 bool subtype = false; 2792 bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref; 2793 if (!current_class()->is_anonymous()) { 2794 subtype = ref_class_type.is_assignable_from( 2795 current_type(), this, false, CHECK_VERIFY(this)); 2796 } else { 2797 VerificationType host_klass_type = 2798 VerificationType::reference_type(current_class()->host_klass()->name()); 2799 subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this)); 2800 2801 // If invokespecial of IMR, need to recheck for same or 2802 // direct interface relative to the host class 2803 have_imr_indirect = (have_imr_indirect && 2804 !is_same_or_direct_interface( 2805 current_class()->host_klass(), 2806 host_klass_type, ref_class_type)); 2807 } 2808 if (!subtype) { 2809 verify_error(ErrorContext::bad_code(bci), 2810 "Bad invokespecial instruction: " 2811 "current class isn't assignable to reference class."); 2812 return; 2813 } else if (have_imr_indirect) { 2814 verify_error(ErrorContext::bad_code(bci), 2815 "Bad invokespecial instruction: " 2816 "interface method reference is in an indirect superinterface."); 2817 return; 2818 } 2819 2820 } 2821 // Match method descriptor with operand stack 2822 for (int i = nargs - 1; i >= 0; i--) { // Run backwards 2823 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this)); 2824 } 2825 // Check objectref on operand stack 2826 if (opcode != Bytecodes::_invokestatic && 2827 opcode != Bytecodes::_invokedynamic) { 2828 if (method_name == vmSymbols::object_initializer_name()) { // <init> method 2829 verify_invoke_init(bcs, index, ref_class_type, current_frame, 2830 code_length, in_try_block, this_uninit, cp, stackmap_table, 2831 CHECK_VERIFY(this)); 2832 if (was_recursively_verified()) return; 2833 } else { // other methods 2834 // Ensures that target class is assignable to method class. 2835 if (opcode == Bytecodes::_invokespecial) { 2836 if (!current_class()->is_anonymous()) { 2837 current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); 2838 } else { 2839 // anonymous class invokespecial calls: check if the 2840 // objectref is a subtype of the host_klass of the current class 2841 // to allow an anonymous class to reference methods in the host_klass 2842 VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this)); 2843 VerificationType hosttype = 2844 VerificationType::reference_type(current_class()->host_klass()->name()); 2845 bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this)); 2846 if (!subtype) { 2847 verify_error( ErrorContext::bad_type(current_frame->offset(), 2848 current_frame->stack_top_ctx(), 2849 TypeOrigin::implicit(top)), 2850 "Bad type on operand stack"); 2851 return; 2852 } 2853 } 2854 } else if (opcode == Bytecodes::_invokevirtual) { 2855 VerificationType stack_object_type = 2856 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); 2857 if (current_type() != stack_object_type) { 2858 if (was_recursively_verified()) return; 2859 assert(cp->cache() == NULL, "not rewritten yet"); 2860 Symbol* ref_class_name = 2861 cp->klass_name_at(cp->klass_ref_index_at(index)); 2862 // See the comments in verify_field_instructions() for 2863 // the rationale behind this. 2864 if (name_in_supers(ref_class_name, current_class())) { 2865 Klass* ref_class = load_class(ref_class_name, CHECK); 2866 if (is_protected_access( 2867 _klass, ref_class, method_name, method_sig, true)) { |