< prev index next >

src/hotspot/share/interpreter/linkResolver.cpp

Print this page
rev 59277 : [mq]: v3


 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(", (%s%s%s)",
 610                  (nest_host_error_1 != NULL) ? nest_host_error_1 : "",
 611                  (nest_host_error_1 != NULL && nest_host_error_2 != NULL) ? ", " : "",
 612                  (nest_host_error_2 != NULL) ? nest_host_error_2 : "");
 613       }
 614     }
 615 
 616     Exceptions::fthrow(THREAD_AND_LOCATION,
 617                        vmSymbols::java_lang_IllegalAccessError(),
 618                        "%s",
 619                        ss.as_string()
 620                        );
 621     return;
 622   }
 623 }
 624 
 625 Method* LinkResolver::resolve_method_statically(Bytecodes::Code code,
 626                                                 const constantPoolHandle& pool, int index, TRAPS) {
 627   // This method is used only
 628   // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call),
 629   // and
 630   // (2) in Bytecode_invoke::static_target
 631   // It appears to fail when applied to an invokeinterface call site.
 632   // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
 633   // resolve klass
 634   if (code == Bytecodes::_invokedynamic) {
 635     Klass* resolved_klass = SystemDictionary::MethodHandle_klass();
 636     Symbol* method_name = vmSymbols::invoke_name();
 637     Symbol* method_signature = pool->signature_ref_at(index);
 638     Klass*  current_klass = pool->pool_holder();
 639     LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass);
 640     return resolve_method(link_info, code, THREAD);


 919 }
 920 
 921 //------------------------------------------------------------------------------------------------------------------------
 922 // Field resolution
 923 
 924 void LinkResolver::check_field_accessability(Klass* ref_klass,
 925                                              Klass* resolved_klass,
 926                                              Klass* sel_klass,
 927                                              const fieldDescriptor& fd,
 928                                              TRAPS) {
 929   bool can_access = Reflection::verify_member_access(ref_klass,
 930                                                      resolved_klass,
 931                                                      sel_klass,
 932                                                      fd.access_flags(),
 933                                                      true, false, CHECK);
 934   // Any existing exceptions that may have been thrown, for example LinkageErrors
 935   // from nest-host resolution, have been allowed to propagate.
 936   if (!can_access) {
 937     bool same_module = (sel_klass->module() == ref_klass->module());
 938     ResourceMark rm(THREAD);
 939     stringStream ss;
 940     ss.print("class %s tried to access %s%sfield %s.%s (%s%s%s)",


 941              ref_klass->external_name(),
 942              fd.is_protected() ? "protected " : "",
 943              fd.is_private()   ? "private "   : "",
 944              sel_klass->external_name(),
 945              fd.name()->as_C_string(),
 946              (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
 947              (same_module) ? "" : "; ",
 948              (same_module) ? "" : sel_klass->class_in_module_of_loader()
 949              );
 950     // For private access check if there was a problem with nest host
 951     // resolution, and if so report that as part of the message.
 952     if (fd.is_private()) {
 953       assert(ref_klass->is_instance_klass(), "must be");
 954       assert(sel_klass->is_instance_klass(), "must be");
 955       InstanceKlass* ref_ik = InstanceKlass::cast(ref_klass);
 956       InstanceKlass* sel_ik = InstanceKlass::cast(sel_klass);
 957       const char* nest_host_error_1 = ref_ik->nest_host_resolution_error();
 958       const char* nest_host_error_2 = sel_ik->nest_host_resolution_error();
 959       if (nest_host_error_1 != NULL || nest_host_error_2 != NULL) {
 960         ss.print(", (%s%s%s)",
 961                  (nest_host_error_1 != NULL) ? nest_host_error_1 : "",
 962                  (nest_host_error_1 != NULL && nest_host_error_2 != NULL) ? ", " : "",
 963                  (nest_host_error_2 != NULL) ? nest_host_error_2 : "");
 964       }
 965     }
 966     Exceptions::fthrow(THREAD_AND_LOCATION,
 967                        vmSymbols::java_lang_IllegalAccessError(),
 968                        "%s",
 969                        ss.as_string()
 970                        );
 971     return;
 972   }
 973 }
 974 
 975 void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) {
 976   LinkInfo link_info(pool, index, method, CHECK);
 977   resolve_field(fd, link_info, byte, true, CHECK);
 978 }
 979 
 980 void LinkResolver::resolve_field(fieldDescriptor& fd,
 981                                  const LinkInfo& link_info,
 982                                  Bytecodes::Code byte, bool initialize_class,
 983                                  TRAPS) {
 984   assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic ||
 985          byte == Bytecodes::_getfield  || byte == Bytecodes::_putfield  ||
 986          byte == Bytecodes::_nofast_getfield  || byte == Bytecodes::_nofast_putfield  ||
 987          (byte == Bytecodes::_nop && !link_info.check_access()), "bad field access bytecode");
 988 
 989   bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
 990   bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic || byte == Bytecodes::_nofast_putfield);


< prev index next >