562 // 563 // We'll check for the method name first, as that's most likely 564 // to be false (so we'll short-circuit out of these tests). 565 if (sel_method->name() == vmSymbols::clone_name() && 566 sel_klass == SystemDictionary::Object_klass() && 567 resolved_klass->is_array_klass()) { 568 // We need to change "protected" to "public". 569 assert(flags.is_protected(), "clone not protected?"); 570 jint new_flags = flags.as_int(); 571 new_flags = new_flags & (~JVM_ACC_PROTECTED); 572 new_flags = new_flags | JVM_ACC_PUBLIC; 573 flags.set_flags(new_flags); 574 } 575 // assert(extra_arg_result_or_null != NULL, "must be able to return extra argument"); 576 577 bool can_access = Reflection::verify_member_access(ref_klass, 578 resolved_klass, 579 sel_klass, 580 flags, 581 true, false, CHECK); 582 // Any existing exceptions that may have been thrown, for example LinkageErrors 583 // from nest-host resolution, have been allowed to propagate. 584 if (!can_access) { 585 ResourceMark rm(THREAD); 586 bool same_module = (sel_klass->module() == ref_klass->module()); 587 Exceptions::fthrow( 588 THREAD_AND_LOCATION, 589 vmSymbols::java_lang_IllegalAccessError(), 590 "class %s tried to access %s%s%smethod '%s' (%s%s%s)", 591 ref_klass->external_name(), 592 sel_method->is_abstract() ? "abstract " : "", 593 sel_method->is_protected() ? "protected " : "", 594 sel_method->is_private() ? "private " : "", 595 sel_method->external_name(), 596 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(), 597 (same_module) ? "" : "; ", 598 (same_module) ? "" : sel_klass->class_in_module_of_loader() 599 ); 600 return; 601 } 602 } 603 604 Method* LinkResolver::resolve_method_statically(Bytecodes::Code code, 605 const constantPoolHandle& pool, int index, TRAPS) { 606 // This method is used only 607 // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call), 608 // and 609 // (2) in Bytecode_invoke::static_target 610 // It appears to fail when applied to an invokeinterface call site. 611 // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points. 612 // resolve klass 613 if (code == Bytecodes::_invokedynamic) { 614 Klass* resolved_klass = SystemDictionary::MethodHandle_klass(); 615 Symbol* method_name = vmSymbols::invoke_name(); 616 Symbol* method_signature = pool->signature_ref_at(index); 617 Klass* current_klass = pool->pool_holder(); 618 LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass); 619 return resolve_method(link_info, code, THREAD); 898 } 899 900 //------------------------------------------------------------------------------------------------------------------------ 901 // Field resolution 902 903 void LinkResolver::check_field_accessability(Klass* ref_klass, 904 Klass* resolved_klass, 905 Klass* sel_klass, 906 const fieldDescriptor& fd, 907 TRAPS) { 908 bool can_access = Reflection::verify_member_access(ref_klass, 909 resolved_klass, 910 sel_klass, 911 fd.access_flags(), 912 true, false, CHECK); 913 // Any existing exceptions that may have been thrown, for example LinkageErrors 914 // from nest-host resolution, have been allowed to propagate. 915 if (!can_access) { 916 bool same_module = (sel_klass->module() == ref_klass->module()); 917 ResourceMark rm(THREAD); 918 Exceptions::fthrow( 919 THREAD_AND_LOCATION, 920 vmSymbols::java_lang_IllegalAccessError(), 921 "class %s tried to access %s%sfield %s.%s (%s%s%s)", 922 ref_klass->external_name(), 923 fd.is_protected() ? "protected " : "", 924 fd.is_private() ? "private " : "", 925 sel_klass->external_name(), 926 fd.name()->as_C_string(), 927 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(), 928 (same_module) ? "" : "; ", 929 (same_module) ? "" : sel_klass->class_in_module_of_loader() 930 ); 931 return; 932 } 933 } 934 935 void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) { 936 LinkInfo link_info(pool, index, method, CHECK); 937 resolve_field(fd, link_info, byte, true, CHECK); 938 } 939 940 void LinkResolver::resolve_field(fieldDescriptor& fd, 941 const LinkInfo& link_info, 942 Bytecodes::Code byte, bool initialize_class, 943 TRAPS) { 944 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || 945 byte == Bytecodes::_getfield || byte == Bytecodes::_putfield || 946 byte == Bytecodes::_nofast_getfield || byte == Bytecodes::_nofast_putfield || 947 (byte == Bytecodes::_nop && !link_info.check_access()), "bad field access bytecode"); 948 949 bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); 950 bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic || byte == Bytecodes::_nofast_putfield); | 562 // 563 // We'll check for the method name first, as that's most likely 564 // to be false (so we'll short-circuit out of these tests). 565 if (sel_method->name() == vmSymbols::clone_name() && 566 sel_klass == SystemDictionary::Object_klass() && 567 resolved_klass->is_array_klass()) { 568 // We need to change "protected" to "public". 569 assert(flags.is_protected(), "clone not protected?"); 570 jint new_flags = flags.as_int(); 571 new_flags = new_flags & (~JVM_ACC_PROTECTED); 572 new_flags = new_flags | JVM_ACC_PUBLIC; 573 flags.set_flags(new_flags); 574 } 575 // assert(extra_arg_result_or_null != NULL, "must be able to return extra argument"); 576 577 bool can_access = Reflection::verify_member_access(ref_klass, 578 resolved_klass, 579 sel_klass, 580 flags, 581 true, false, CHECK); 582 // Any existing exceptions that may have been thrown 583 // have been allowed to propagate. 584 if (!can_access) { 585 ResourceMark rm(THREAD); 586 stringStream ss; 587 bool same_module = (sel_klass->module() == ref_klass->module()); 588 ss.print("class %s tried to access %s%s%smethod '%s' (%s%s%s)", 589 ref_klass->external_name(), 590 sel_method->is_abstract() ? "abstract " : "", 591 sel_method->is_protected() ? "protected " : "", 592 sel_method->is_private() ? "private " : "", 593 sel_method->external_name(), 594 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(), 595 (same_module) ? "" : "; ", 596 (same_module) ? "" : sel_klass->class_in_module_of_loader() 597 ); 598 599 // For private access check if there was a problem with nest host 600 // resolution, and if so report that as part of the message. 601 if (sel_method->is_private()) { 602 assert(ref_klass->is_instance_klass(), "must be"); 603 assert(sel_klass->is_instance_klass(), "must be"); 604 InstanceKlass* ref_ik = InstanceKlass::cast(ref_klass); 605 InstanceKlass* sel_ik = InstanceKlass::cast(sel_klass); 606 const char* nest_host_error_1 = ref_ik->nest_host_resolution_error(); 607 const char* nest_host_error_2 = sel_ik->nest_host_resolution_error(); 608 if (nest_host_error_1 != NULL || nest_host_error_2 != NULL) { 609 ss.print("("); 610 if (nest_host_error_1 != NULL) { 611 ss.print("%s", nest_host_error_1); 612 if (nest_host_error_2 != NULL) { 613 ss.print(", %s", nest_host_error_2); 614 } 615 } else if (nest_host_error_2 != NULL) { 616 ss.print("%s", nest_host_error_2); 617 } 618 ss.print(")"); 619 } 620 } 621 622 Exceptions::fthrow(THREAD_AND_LOCATION, 623 vmSymbols::java_lang_IllegalAccessError(), 624 "%s", 625 ss.as_string() 626 ); 627 return; 628 } 629 } 630 631 Method* LinkResolver::resolve_method_statically(Bytecodes::Code code, 632 const constantPoolHandle& pool, int index, TRAPS) { 633 // This method is used only 634 // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call), 635 // and 636 // (2) in Bytecode_invoke::static_target 637 // It appears to fail when applied to an invokeinterface call site. 638 // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points. 639 // resolve klass 640 if (code == Bytecodes::_invokedynamic) { 641 Klass* resolved_klass = SystemDictionary::MethodHandle_klass(); 642 Symbol* method_name = vmSymbols::invoke_name(); 643 Symbol* method_signature = pool->signature_ref_at(index); 644 Klass* current_klass = pool->pool_holder(); 645 LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass); 646 return resolve_method(link_info, code, THREAD); 925 } 926 927 //------------------------------------------------------------------------------------------------------------------------ 928 // Field resolution 929 930 void LinkResolver::check_field_accessability(Klass* ref_klass, 931 Klass* resolved_klass, 932 Klass* sel_klass, 933 const fieldDescriptor& fd, 934 TRAPS) { 935 bool can_access = Reflection::verify_member_access(ref_klass, 936 resolved_klass, 937 sel_klass, 938 fd.access_flags(), 939 true, false, CHECK); 940 // Any existing exceptions that may have been thrown, for example LinkageErrors 941 // from nest-host resolution, have been allowed to propagate. 942 if (!can_access) { 943 bool same_module = (sel_klass->module() == ref_klass->module()); 944 ResourceMark rm(THREAD); 945 stringStream ss; 946 ss.print("class %s tried to access %s%sfield %s.%s (%s%s%s)", 947 ref_klass->external_name(), 948 fd.is_protected() ? "protected " : "", 949 fd.is_private() ? "private " : "", 950 sel_klass->external_name(), 951 fd.name()->as_C_string(), 952 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(), 953 (same_module) ? "" : "; ", 954 (same_module) ? "" : sel_klass->class_in_module_of_loader() 955 ); 956 // For private access check if there was a problem with nest host 957 // resolution, and if so report that as part of the message. 958 if (fd.is_private()) { 959 assert(ref_klass->is_instance_klass(), "must be"); 960 assert(sel_klass->is_instance_klass(), "must be"); 961 InstanceKlass* ref_ik = InstanceKlass::cast(ref_klass); 962 InstanceKlass* sel_ik = InstanceKlass::cast(sel_klass); 963 const char* nest_host_error_1 = ref_ik->nest_host_resolution_error(); 964 const char* nest_host_error_2 = sel_ik->nest_host_resolution_error(); 965 if (nest_host_error_1 != NULL || nest_host_error_2 != NULL) { 966 ss.print("("); 967 if (nest_host_error_1 != NULL) { 968 ss.print("%s", nest_host_error_1); 969 if (nest_host_error_2 != NULL) { 970 ss.print(", %s", nest_host_error_2); 971 } 972 } else if (nest_host_error_2 != NULL) { 973 ss.print("%s", nest_host_error_2); 974 } 975 ss.print(")"); 976 } 977 } 978 Exceptions::fthrow(THREAD_AND_LOCATION, 979 vmSymbols::java_lang_IllegalAccessError(), 980 "%s", 981 ss.as_string() 982 ); 983 return; 984 } 985 } 986 987 void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) { 988 LinkInfo link_info(pool, index, method, CHECK); 989 resolve_field(fd, link_info, byte, true, CHECK); 990 } 991 992 void LinkResolver::resolve_field(fieldDescriptor& fd, 993 const LinkInfo& link_info, 994 Bytecodes::Code byte, bool initialize_class, 995 TRAPS) { 996 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || 997 byte == Bytecodes::_getfield || byte == Bytecodes::_putfield || 998 byte == Bytecodes::_nofast_getfield || byte == Bytecodes::_nofast_putfield || 999 (byte == Bytecodes::_nop && !link_info.check_access()), "bad field access bytecode"); 1000 1001 bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); 1002 bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic || byte == Bytecodes::_nofast_putfield); |