530 if (!MethodHandles::is_signature_polymorphic_static(iid)) expected_size_of_params += 1;
531 if (appendix.not_null()) expected_size_of_params += 1;
532 if (actual_size_of_params != expected_size_of_params) {
533 tty->print_cr("*** basic_signature=%s", basic_signature->as_C_string());
534 tty->print_cr("*** result for %s: ", vmIntrinsics::name_at(iid));
535 result->print();
536 }
537 assert(actual_size_of_params == expected_size_of_params,
538 "%d != %d", actual_size_of_params, expected_size_of_params);
539 #endif //ASSERT
540
541 assert(appendix_result_or_null != NULL, "");
542 (*appendix_result_or_null) = appendix;
543 }
544 return result;
545 }
546 }
547 return NULL;
548 }
549
550 void LinkResolver::check_method_accessability(Klass* ref_klass,
551 Klass* resolved_klass,
552 Klass* sel_klass,
553 const methodHandle& sel_method,
554 TRAPS) {
555
556 AccessFlags flags = sel_method->access_flags();
557
558 // Special case: arrays always override "clone". JVMS 2.15.
559 // If the resolved klass is an array class, and the declaring class
560 // is java.lang.Object and the method is "clone", set the flags
561 // to public.
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?");
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
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 ||
|
530 if (!MethodHandles::is_signature_polymorphic_static(iid)) expected_size_of_params += 1;
531 if (appendix.not_null()) expected_size_of_params += 1;
532 if (actual_size_of_params != expected_size_of_params) {
533 tty->print_cr("*** basic_signature=%s", basic_signature->as_C_string());
534 tty->print_cr("*** result for %s: ", vmIntrinsics::name_at(iid));
535 result->print();
536 }
537 assert(actual_size_of_params == expected_size_of_params,
538 "%d != %d", actual_size_of_params, expected_size_of_params);
539 #endif //ASSERT
540
541 assert(appendix_result_or_null != NULL, "");
542 (*appendix_result_or_null) = appendix;
543 }
544 return result;
545 }
546 }
547 return NULL;
548 }
549
550 static void print_nest_host_error_on(stringStream* ss, Klass* ref_klass, Klass* sel_klass, TRAPS) {
551 assert(ref_klass->is_instance_klass(), "must be");
552 assert(sel_klass->is_instance_klass(), "must be");
553 InstanceKlass* ref_ik = InstanceKlass::cast(ref_klass);
554 InstanceKlass* sel_ik = InstanceKlass::cast(sel_klass);
555 const char* nest_host_error_1 = ref_ik->nest_host_error(THREAD);
556 const char* nest_host_error_2 = sel_ik->nest_host_error(THREAD);
557 if (nest_host_error_1 != NULL || nest_host_error_2 != NULL) {
558 ss->print(", (%s%s%s)",
559 (nest_host_error_1 != NULL) ? nest_host_error_1 : "",
560 (nest_host_error_1 != NULL && nest_host_error_2 != NULL) ? ", " : "",
561 (nest_host_error_2 != NULL) ? nest_host_error_2 : "");
562 }
563 }
564
565 void LinkResolver::check_method_accessability(Klass* ref_klass,
566 Klass* resolved_klass,
567 Klass* sel_klass,
568 const methodHandle& sel_method,
569 TRAPS) {
570
571 AccessFlags flags = sel_method->access_flags();
572
573 // Special case: arrays always override "clone". JVMS 2.15.
574 // If the resolved klass is an array class, and the declaring class
575 // is java.lang.Object and the method is "clone", set the flags
576 // to public.
577 //
578 // We'll check for the method name first, as that's most likely
579 // to be false (so we'll short-circuit out of these tests).
580 if (sel_method->name() == vmSymbols::clone_name() &&
581 sel_klass == SystemDictionary::Object_klass() &&
582 resolved_klass->is_array_klass()) {
583 // We need to change "protected" to "public".
584 assert(flags.is_protected(), "clone not protected?");
597 // Any existing exceptions that may have been thrown
598 // have been allowed to propagate.
599 if (!can_access) {
600 ResourceMark rm(THREAD);
601 stringStream ss;
602 bool same_module = (sel_klass->module() == ref_klass->module());
603 ss.print("class %s tried to access %s%s%smethod '%s' (%s%s%s)",
604 ref_klass->external_name(),
605 sel_method->is_abstract() ? "abstract " : "",
606 sel_method->is_protected() ? "protected " : "",
607 sel_method->is_private() ? "private " : "",
608 sel_method->external_name(),
609 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
610 (same_module) ? "" : "; ",
611 (same_module) ? "" : sel_klass->class_in_module_of_loader()
612 );
613
614 // For private access check if there was a problem with nest host
615 // resolution, and if so report that as part of the message.
616 if (sel_method->is_private()) {
617 print_nest_host_error_on(&ss, ref_klass, sel_klass, THREAD);
618 }
619
620 Exceptions::fthrow(THREAD_AND_LOCATION,
621 vmSymbols::java_lang_IllegalAccessError(),
622 "%s",
623 ss.as_string()
624 );
625 return;
626 }
627 }
628
629 Method* LinkResolver::resolve_method_statically(Bytecodes::Code code,
630 const constantPoolHandle& pool, int index, TRAPS) {
631 // This method is used only
632 // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call),
633 // and
634 // (2) in Bytecode_invoke::static_target
635 // It appears to fail when applied to an invokeinterface call site.
636 // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
637 // resolve klass
937 true, false, CHECK);
938 // Any existing exceptions that may have been thrown, for example LinkageErrors
939 // from nest-host resolution, have been allowed to propagate.
940 if (!can_access) {
941 bool same_module = (sel_klass->module() == ref_klass->module());
942 ResourceMark rm(THREAD);
943 stringStream ss;
944 ss.print("class %s tried to access %s%sfield %s.%s (%s%s%s)",
945 ref_klass->external_name(),
946 fd.is_protected() ? "protected " : "",
947 fd.is_private() ? "private " : "",
948 sel_klass->external_name(),
949 fd.name()->as_C_string(),
950 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
951 (same_module) ? "" : "; ",
952 (same_module) ? "" : sel_klass->class_in_module_of_loader()
953 );
954 // For private access check if there was a problem with nest host
955 // resolution, and if so report that as part of the message.
956 if (fd.is_private()) {
957 print_nest_host_error_on(&ss, ref_klass, sel_klass, THREAD);
958 }
959 Exceptions::fthrow(THREAD_AND_LOCATION,
960 vmSymbols::java_lang_IllegalAccessError(),
961 "%s",
962 ss.as_string()
963 );
964 return;
965 }
966 }
967
968 void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) {
969 LinkInfo link_info(pool, index, method, CHECK);
970 resolve_field(fd, link_info, byte, true, CHECK);
971 }
972
973 void LinkResolver::resolve_field(fieldDescriptor& fd,
974 const LinkInfo& link_info,
975 Bytecodes::Code byte, bool initialize_class,
976 TRAPS) {
977 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic ||
|