src/share/vm/interpreter/linkResolver.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/interpreter

src/share/vm/interpreter/linkResolver.cpp

Print this page




  81     THROW_MSG(vmSymbols::java_lang_InternalError(), "resolved method is null");
  82   }
  83   KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass();
  84   assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic ||
  85          resolved_method->is_compiled_lambda_form(),
  86          "linkMethod must return one of these");
  87   int vtable_index = Method::nonvirtual_vtable_index;
  88   assert(!resolved_method->has_vtable_index(), "");
  89   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
  90   _resolved_appendix    = resolved_appendix;
  91   _resolved_method_type = resolved_method_type;
  92 }
  93 
  94 void CallInfo::set_common(KlassHandle resolved_klass,
  95                           KlassHandle selected_klass,
  96                           methodHandle resolved_method,
  97                           methodHandle selected_method,
  98                           CallKind kind,
  99                           int index,
 100                           TRAPS) {
 101   assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond");
 102   _resolved_klass  = resolved_klass;
 103   _selected_klass  = selected_klass;
 104   _resolved_method = resolved_method;
 105   _selected_method = selected_method;
 106   _call_kind       = kind;
 107   _call_index      = index;
 108   _resolved_appendix = Handle();
 109   DEBUG_ONLY(verify());  // verify before making side effects
 110 
 111   if (CompilationPolicy::must_be_compiled(selected_method)) {
 112     // This path is unusual, mostly used by the '-Xcomp' stress test mode.
 113 
 114     // Note: with several active threads, the must_be_compiled may be true
 115     //       while can_be_compiled is false; remove assert
 116     // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile");
 117     if (THREAD->is_Compiler_thread()) {
 118       // don't force compilation, resolve was on behalf of compiler
 119       return;
 120     }
 121     if (selected_method->method_holder()->is_not_initialized()) {


 151     kind = CallInfo::direct_call;
 152   } else if (!resolved_method_holder->is_interface()) {
 153     // Could be an Object method inherited into an interface, but still a vtable call.
 154     kind = CallInfo::vtable_call;
 155   } else if (!resolved_klass->is_interface()) {
 156     // A default or miranda method.  Compute the vtable index.
 157     ResourceMark rm;
 158     klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable();
 159     index = LinkResolver::vtable_index_of_interface_method(resolved_klass,
 160                            resolved_method);
 161     assert(index >= 0 , "we should have valid vtable index at this point");
 162 
 163     kind = CallInfo::vtable_call;
 164   } else if (resolved_method->has_vtable_index()) {
 165     // Can occur if an interface redeclares a method of Object.
 166 
 167 #ifdef ASSERT
 168     // Ensure that this is really the case.
 169     KlassHandle object_klass = SystemDictionary::Object_klass();
 170     Method * object_resolved_method = object_klass()->vtable()->method_at(index);
 171     assert(object_resolved_method->name() == resolved_method->name(),
 172       err_msg("Object and interface method names should match at vtable index %d, %s != %s",
 173       index, object_resolved_method->name()->as_C_string(), resolved_method->name()->as_C_string()));
 174     assert(object_resolved_method->signature() == resolved_method->signature(),
 175       err_msg("Object and interface method signatures should match at vtable index %d, %s != %s",
 176       index, object_resolved_method->signature()->as_C_string(), resolved_method->signature()->as_C_string()));
 177 #endif // ASSERT
 178 
 179     kind = CallInfo::vtable_call;
 180   } else {
 181     // A regular interface call.
 182     kind = CallInfo::itable_call;
 183     index = resolved_method->itable_index();
 184   }
 185   assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index));
 186   _call_kind  = kind;
 187   _call_index = index;
 188   _resolved_appendix = Handle();
 189   DEBUG_ONLY(verify());
 190 }
 191 
 192 #ifdef ASSERT
 193 void CallInfo::verify() {
 194   switch (call_kind()) {  // the meaning and allowed value of index depends on kind


 445       }
 446     }
 447   }
 448 }
 449 
 450 void LinkResolver::check_method_accessability(KlassHandle ref_klass,
 451                                               KlassHandle resolved_klass,
 452                                               KlassHandle sel_klass,
 453                                               methodHandle sel_method,
 454                                               TRAPS) {
 455 
 456   AccessFlags flags = sel_method->access_flags();
 457 
 458   // Special case:  arrays always override "clone". JVMS 2.15.
 459   // If the resolved klass is an array class, and the declaring class
 460   // is java.lang.Object and the method is "clone", set the flags
 461   // to public.
 462   //
 463   // We'll check for the method name first, as that's most likely
 464   // to be false (so we'll short-circuit out of these tests).
 465   if (sel_method->name() == vmSymbols::clone_name() &&
 466       sel_klass() == SystemDictionary::Object_klass() &&
 467       resolved_klass->oop_is_array()) {
 468     // We need to change "protected" to "public".
 469     assert(flags.is_protected(), "clone not protected?");
 470     jint new_flags = flags.as_int();
 471     new_flags = new_flags & (~JVM_ACC_PROTECTED);
 472     new_flags = new_flags | JVM_ACC_PUBLIC;
 473     flags.set_flags(new_flags);
 474   }
 475 //  assert(extra_arg_result_or_null != NULL, "must be able to return extra argument");
 476 
 477   if (!Reflection::verify_field_access(ref_klass(),
 478                                        resolved_klass(),
 479                                        sel_klass(),
 480                                        flags,
 481                                        true)) {
 482     ResourceMark rm(THREAD);
 483     Exceptions::fthrow(
 484       THREAD_AND_LOCATION,
 485       vmSymbols::java_lang_IllegalAccessError(),


 883   // Initialize klass (this should only happen if everything is ok)
 884   if (initialize_class && resolved_klass->should_be_initialized()) {
 885     resolved_klass->initialize(CHECK);
 886     linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
 887   }
 888 
 889   // setup result
 890   result.set_static(resolved_klass, resolved_method, CHECK);
 891 }
 892 
 893 // throws linktime exceptions
 894 void LinkResolver::linktime_resolve_static_method(methodHandle& resolved_method, KlassHandle resolved_klass,
 895                                                   Symbol* method_name, Symbol* method_signature,
 896                                                   KlassHandle current_klass, bool check_access, TRAPS) {
 897 
 898   if (!resolved_klass->is_interface()) {
 899     resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, false, CHECK);
 900   } else {
 901     resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, false, CHECK);
 902   }
 903   assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier");
 904 
 905   // check if static
 906   if (!resolved_method->is_static()) {
 907     ResourceMark rm(THREAD);
 908     char buf[200];
 909     jio_snprintf(buf, sizeof(buf), "Expected static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
 910                                                       resolved_method->name(),
 911                                                       resolved_method->signature()));
 912     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 913   }
 914 }
 915 
 916 
 917 void LinkResolver::resolve_special_call(CallInfo& result, KlassHandle resolved_klass, Symbol* method_name,
 918                                         Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS) {
 919   methodHandle resolved_method;
 920   linktime_resolve_special_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
 921   runtime_resolve_special_method(result, resolved_method, resolved_klass, current_klass, check_access, CHECK);
 922 }
 923 
 924 // throws linktime exceptions
 925 void LinkResolver::linktime_resolve_special_method(methodHandle& resolved_method, KlassHandle resolved_klass,
 926                                                    Symbol* method_name, Symbol* method_signature,
 927                                                    KlassHandle current_klass, bool check_access, TRAPS) {
 928 
 929   // Invokespecial is called for multiple special reasons:
 930   // <init>
 931   // local private method invocation, for classes and interfaces
 932   // superclass.method, which can also resolve to a default method
 933   // and the selected method is recalculated relative to the direct superclass
 934   // superinterface.method, which explicitly does not check shadowing
 935 
 936   if (!resolved_klass->is_interface()) {
 937     resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, false, CHECK);
 938   } else {
 939     resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, true, CHECK);
 940   }
 941 
 942   // check if method name is <init>, that it is found in same klass as static type
 943   if (resolved_method->name() == vmSymbols::object_initializer_name() &&
 944       resolved_method->method_holder() != resolved_klass()) {
 945     ResourceMark rm(THREAD);
 946     Exceptions::fthrow(
 947       THREAD_AND_LOCATION,
 948       vmSymbols::java_lang_NoSuchMethodError(),
 949       "%s: method %s%s not found",
 950       resolved_klass->external_name(),
 951       resolved_method->name()->as_C_string(),
 952       resolved_method->signature()->as_C_string()
 953     );
 954     return;
 955   }
 956 
 957   // check if invokespecial's interface method reference is in an indirect superinterface
 958   if (!current_klass.is_null() && resolved_klass->is_interface()) {
 959     Klass *klass_to_check = !InstanceKlass::cast(current_klass())->is_anonymous() ?
 960                                   current_klass() :
 961                                   InstanceKlass::cast(current_klass())->host_klass();
 962     // Disable verification for the dynamically-generated reflection bytecodes.
 963     bool is_reflect = klass_to_check->is_subclass_of(


1017   // resolved method is selected method unless we have an old-style lookup
1018   // for a superclass method
1019   // Invokespecial for a superinterface, resolved method is selected method,
1020   // no checks for shadowing
1021   methodHandle sel_method(THREAD, resolved_method());
1022 
1023   // check if this is an old-style super call and do a new lookup if so
1024   { KlassHandle method_klass  = KlassHandle(THREAD,
1025                                             resolved_method->method_holder());
1026 
1027     if (check_access &&
1028         // a) check if ACC_SUPER flag is set for the current class
1029         (current_klass->is_super() || !AllowNonVirtualCalls) &&
1030         // b) check if the class of the resolved_klass is a superclass
1031         // (not supertype in order to exclude interface classes) of the current class.
1032         // This check is not performed for super.invoke for interface methods
1033         // in super interfaces.
1034         current_klass->is_subclass_of(resolved_klass()) &&
1035         current_klass() != resolved_klass() &&
1036         // c) check if the method is not <init>
1037         resolved_method->name() != vmSymbols::object_initializer_name()) {
1038       // Lookup super method
1039       KlassHandle super_klass(THREAD, current_klass->super());
1040       lookup_instance_method_in_klasses(sel_method, super_klass,
1041                            resolved_method->name(),
1042                            resolved_method->signature(), CHECK);
1043       // check if found
1044       if (sel_method.is_null()) {
1045         ResourceMark rm(THREAD);
1046         THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1047                   Method::name_and_sig_as_C_string(resolved_klass(),
1048                                             resolved_method->name(),
1049                                             resolved_method->signature()));
1050       }
1051     }
1052   }
1053 
1054   // check if not static
1055   if (sel_method->is_static()) {
1056     ResourceMark rm(THREAD);
1057     char buf[200];


1091 
1092   // setup result
1093   result.set_static(resolved_klass, sel_method, CHECK);
1094 }
1095 
1096 void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, KlassHandle resolved_klass,
1097                                         Symbol* method_name, Symbol* method_signature, KlassHandle current_klass,
1098                                         bool check_access, bool check_null_and_abstract, TRAPS) {
1099   methodHandle resolved_method;
1100   linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
1101   runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
1102 }
1103 
1104 // throws linktime exceptions
1105 void LinkResolver::linktime_resolve_virtual_method(methodHandle &resolved_method, KlassHandle resolved_klass,
1106                                                    Symbol* method_name, Symbol* method_signature,
1107                                                    KlassHandle current_klass, bool check_access, TRAPS) {
1108   // normal method resolution
1109   resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, true, CHECK);
1110 
1111   assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier");
1112   assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier");
1113 
1114   // check if private interface method
1115   if (resolved_klass->is_interface() && resolved_method->is_private()) {
1116     ResourceMark rm(THREAD);
1117     char buf[200];
1118     jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokevirtual: method %s, caller-class:%s",
1119                  Method::name_and_sig_as_C_string(resolved_klass(),
1120                                                   resolved_method->name(),
1121                                                   resolved_method->signature()),
1122                    (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()));
1123     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1124   }
1125 
1126   // check if not static
1127   if (resolved_method->is_static()) {
1128     ResourceMark rm(THREAD);
1129     char buf[200];
1130     jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
1131                                                                                                              resolved_method->name(),
1132                                                                                                              resolved_method->signature()));


1247     tty->cr();
1248   }
1249   // setup result
1250   result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK);
1251 }
1252 
1253 void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass,
1254                                           Symbol* method_name, Symbol* method_signature, KlassHandle current_klass,
1255                                           bool check_access, bool check_null_and_abstract, TRAPS) {
1256   methodHandle resolved_method;
1257   linktime_resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
1258   runtime_resolve_interface_method(result, resolved_method, resolved_klass, recv, recv_klass, check_null_and_abstract, CHECK);
1259 }
1260 
1261 // throws linktime exceptions
1262 void LinkResolver::linktime_resolve_interface_method(methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name,
1263                                                      Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS) {
1264   // normal interface method resolution
1265   resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, true, CHECK);
1266 
1267   assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier");
1268   assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier");
1269 }
1270 
1271 // throws runtime exceptions
1272 void LinkResolver::runtime_resolve_interface_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass,
1273                                                     Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS) {
1274   // check if receiver exists
1275   if (check_null_and_abstract && recv.is_null()) {
1276     THROW(vmSymbols::java_lang_NullPointerException());
1277   }
1278 
1279   // check if private interface method
1280   if (resolved_klass->is_interface() && resolved_method->is_private()) {
1281     ResourceMark rm(THREAD);
1282     char buf[200];
1283     jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s",
1284                  Method::name_and_sig_as_C_string(resolved_klass(),
1285                                                   resolved_method->name(),
1286                                                   resolved_method->signature()));
1287     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1288   }




  81     THROW_MSG(vmSymbols::java_lang_InternalError(), "resolved method is null");
  82   }
  83   KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass();
  84   assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic ||
  85          resolved_method->is_compiled_lambda_form(),
  86          "linkMethod must return one of these");
  87   int vtable_index = Method::nonvirtual_vtable_index;
  88   assert(!resolved_method->has_vtable_index(), "");
  89   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
  90   _resolved_appendix    = resolved_appendix;
  91   _resolved_method_type = resolved_method_type;
  92 }
  93 
  94 void CallInfo::set_common(KlassHandle resolved_klass,
  95                           KlassHandle selected_klass,
  96                           methodHandle resolved_method,
  97                           methodHandle selected_method,
  98                           CallKind kind,
  99                           int index,
 100                           TRAPS) {
 101   assert(resolved_method->signature()->equals(selected_method->signature()), "signatures must correspond");
 102   _resolved_klass  = resolved_klass;
 103   _selected_klass  = selected_klass;
 104   _resolved_method = resolved_method;
 105   _selected_method = selected_method;
 106   _call_kind       = kind;
 107   _call_index      = index;
 108   _resolved_appendix = Handle();
 109   DEBUG_ONLY(verify());  // verify before making side effects
 110 
 111   if (CompilationPolicy::must_be_compiled(selected_method)) {
 112     // This path is unusual, mostly used by the '-Xcomp' stress test mode.
 113 
 114     // Note: with several active threads, the must_be_compiled may be true
 115     //       while can_be_compiled is false; remove assert
 116     // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile");
 117     if (THREAD->is_Compiler_thread()) {
 118       // don't force compilation, resolve was on behalf of compiler
 119       return;
 120     }
 121     if (selected_method->method_holder()->is_not_initialized()) {


 151     kind = CallInfo::direct_call;
 152   } else if (!resolved_method_holder->is_interface()) {
 153     // Could be an Object method inherited into an interface, but still a vtable call.
 154     kind = CallInfo::vtable_call;
 155   } else if (!resolved_klass->is_interface()) {
 156     // A default or miranda method.  Compute the vtable index.
 157     ResourceMark rm;
 158     klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable();
 159     index = LinkResolver::vtable_index_of_interface_method(resolved_klass,
 160                            resolved_method);
 161     assert(index >= 0 , "we should have valid vtable index at this point");
 162 
 163     kind = CallInfo::vtable_call;
 164   } else if (resolved_method->has_vtable_index()) {
 165     // Can occur if an interface redeclares a method of Object.
 166 
 167 #ifdef ASSERT
 168     // Ensure that this is really the case.
 169     KlassHandle object_klass = SystemDictionary::Object_klass();
 170     Method * object_resolved_method = object_klass()->vtable()->method_at(index);
 171     assert(object_resolved_method->name()->equals(resolved_method->name()),
 172       err_msg("Object and interface method names should match at vtable index %d, %s != %s",
 173       index, object_resolved_method->name()->as_C_string(), resolved_method->name()->as_C_string()));
 174     assert(object_resolved_method->signature()->equals(resolved_method->signature()),
 175       err_msg("Object and interface method signatures should match at vtable index %d, %s != %s",
 176       index, object_resolved_method->signature()->as_C_string(), resolved_method->signature()->as_C_string()));
 177 #endif // ASSERT
 178 
 179     kind = CallInfo::vtable_call;
 180   } else {
 181     // A regular interface call.
 182     kind = CallInfo::itable_call;
 183     index = resolved_method->itable_index();
 184   }
 185   assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index));
 186   _call_kind  = kind;
 187   _call_index = index;
 188   _resolved_appendix = Handle();
 189   DEBUG_ONLY(verify());
 190 }
 191 
 192 #ifdef ASSERT
 193 void CallInfo::verify() {
 194   switch (call_kind()) {  // the meaning and allowed value of index depends on kind


 445       }
 446     }
 447   }
 448 }
 449 
 450 void LinkResolver::check_method_accessability(KlassHandle ref_klass,
 451                                               KlassHandle resolved_klass,
 452                                               KlassHandle sel_klass,
 453                                               methodHandle sel_method,
 454                                               TRAPS) {
 455 
 456   AccessFlags flags = sel_method->access_flags();
 457 
 458   // Special case:  arrays always override "clone". JVMS 2.15.
 459   // If the resolved klass is an array class, and the declaring class
 460   // is java.lang.Object and the method is "clone", set the flags
 461   // to public.
 462   //
 463   // We'll check for the method name first, as that's most likely
 464   // to be false (so we'll short-circuit out of these tests).
 465   if (sel_method->name()->equals(vmSymbols::clone_name()) &&
 466       sel_klass() == SystemDictionary::Object_klass() &&
 467       resolved_klass->oop_is_array()) {
 468     // We need to change "protected" to "public".
 469     assert(flags.is_protected(), "clone not protected?");
 470     jint new_flags = flags.as_int();
 471     new_flags = new_flags & (~JVM_ACC_PROTECTED);
 472     new_flags = new_flags | JVM_ACC_PUBLIC;
 473     flags.set_flags(new_flags);
 474   }
 475 //  assert(extra_arg_result_or_null != NULL, "must be able to return extra argument");
 476 
 477   if (!Reflection::verify_field_access(ref_klass(),
 478                                        resolved_klass(),
 479                                        sel_klass(),
 480                                        flags,
 481                                        true)) {
 482     ResourceMark rm(THREAD);
 483     Exceptions::fthrow(
 484       THREAD_AND_LOCATION,
 485       vmSymbols::java_lang_IllegalAccessError(),


 883   // Initialize klass (this should only happen if everything is ok)
 884   if (initialize_class && resolved_klass->should_be_initialized()) {
 885     resolved_klass->initialize(CHECK);
 886     linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
 887   }
 888 
 889   // setup result
 890   result.set_static(resolved_klass, resolved_method, CHECK);
 891 }
 892 
 893 // throws linktime exceptions
 894 void LinkResolver::linktime_resolve_static_method(methodHandle& resolved_method, KlassHandle resolved_klass,
 895                                                   Symbol* method_name, Symbol* method_signature,
 896                                                   KlassHandle current_klass, bool check_access, TRAPS) {
 897 
 898   if (!resolved_klass->is_interface()) {
 899     resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, false, CHECK);
 900   } else {
 901     resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, false, CHECK);
 902   }
 903   assert(resolved_method->name()->not_equals(vmSymbols::class_initializer_name()), "should have been checked in verifier");
 904 
 905   // check if static
 906   if (!resolved_method->is_static()) {
 907     ResourceMark rm(THREAD);
 908     char buf[200];
 909     jio_snprintf(buf, sizeof(buf), "Expected static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
 910                                                       resolved_method->name(),
 911                                                       resolved_method->signature()));
 912     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 913   }
 914 }
 915 
 916 
 917 void LinkResolver::resolve_special_call(CallInfo& result, KlassHandle resolved_klass, Symbol* method_name,
 918                                         Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS) {
 919   methodHandle resolved_method;
 920   linktime_resolve_special_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
 921   runtime_resolve_special_method(result, resolved_method, resolved_klass, current_klass, check_access, CHECK);
 922 }
 923 
 924 // throws linktime exceptions
 925 void LinkResolver::linktime_resolve_special_method(methodHandle& resolved_method, KlassHandle resolved_klass,
 926                                                    Symbol* method_name, Symbol* method_signature,
 927                                                    KlassHandle current_klass, bool check_access, TRAPS) {
 928 
 929   // Invokespecial is called for multiple special reasons:
 930   // <init>
 931   // local private method invocation, for classes and interfaces
 932   // superclass.method, which can also resolve to a default method
 933   // and the selected method is recalculated relative to the direct superclass
 934   // superinterface.method, which explicitly does not check shadowing
 935 
 936   if (!resolved_klass->is_interface()) {
 937     resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, false, CHECK);
 938   } else {
 939     resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, true, CHECK);
 940   }
 941 
 942   // check if method name is <init>, that it is found in same klass as static type
 943   if (resolved_method->name()->equals(vmSymbols::object_initializer_name()) &&
 944       resolved_method->method_holder() != resolved_klass()) {
 945     ResourceMark rm(THREAD);
 946     Exceptions::fthrow(
 947       THREAD_AND_LOCATION,
 948       vmSymbols::java_lang_NoSuchMethodError(),
 949       "%s: method %s%s not found",
 950       resolved_klass->external_name(),
 951       resolved_method->name()->as_C_string(),
 952       resolved_method->signature()->as_C_string()
 953     );
 954     return;
 955   }
 956 
 957   // check if invokespecial's interface method reference is in an indirect superinterface
 958   if (!current_klass.is_null() && resolved_klass->is_interface()) {
 959     Klass *klass_to_check = !InstanceKlass::cast(current_klass())->is_anonymous() ?
 960                                   current_klass() :
 961                                   InstanceKlass::cast(current_klass())->host_klass();
 962     // Disable verification for the dynamically-generated reflection bytecodes.
 963     bool is_reflect = klass_to_check->is_subclass_of(


1017   // resolved method is selected method unless we have an old-style lookup
1018   // for a superclass method
1019   // Invokespecial for a superinterface, resolved method is selected method,
1020   // no checks for shadowing
1021   methodHandle sel_method(THREAD, resolved_method());
1022 
1023   // check if this is an old-style super call and do a new lookup if so
1024   { KlassHandle method_klass  = KlassHandle(THREAD,
1025                                             resolved_method->method_holder());
1026 
1027     if (check_access &&
1028         // a) check if ACC_SUPER flag is set for the current class
1029         (current_klass->is_super() || !AllowNonVirtualCalls) &&
1030         // b) check if the class of the resolved_klass is a superclass
1031         // (not supertype in order to exclude interface classes) of the current class.
1032         // This check is not performed for super.invoke for interface methods
1033         // in super interfaces.
1034         current_klass->is_subclass_of(resolved_klass()) &&
1035         current_klass() != resolved_klass() &&
1036         // c) check if the method is not <init>
1037         resolved_method->name()->not_equals(vmSymbols::object_initializer_name())) {
1038       // Lookup super method
1039       KlassHandle super_klass(THREAD, current_klass->super());
1040       lookup_instance_method_in_klasses(sel_method, super_klass,
1041                            resolved_method->name(),
1042                            resolved_method->signature(), CHECK);
1043       // check if found
1044       if (sel_method.is_null()) {
1045         ResourceMark rm(THREAD);
1046         THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1047                   Method::name_and_sig_as_C_string(resolved_klass(),
1048                                             resolved_method->name(),
1049                                             resolved_method->signature()));
1050       }
1051     }
1052   }
1053 
1054   // check if not static
1055   if (sel_method->is_static()) {
1056     ResourceMark rm(THREAD);
1057     char buf[200];


1091 
1092   // setup result
1093   result.set_static(resolved_klass, sel_method, CHECK);
1094 }
1095 
1096 void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, KlassHandle resolved_klass,
1097                                         Symbol* method_name, Symbol* method_signature, KlassHandle current_klass,
1098                                         bool check_access, bool check_null_and_abstract, TRAPS) {
1099   methodHandle resolved_method;
1100   linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
1101   runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
1102 }
1103 
1104 // throws linktime exceptions
1105 void LinkResolver::linktime_resolve_virtual_method(methodHandle &resolved_method, KlassHandle resolved_klass,
1106                                                    Symbol* method_name, Symbol* method_signature,
1107                                                    KlassHandle current_klass, bool check_access, TRAPS) {
1108   // normal method resolution
1109   resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, true, CHECK);
1110 
1111   assert(resolved_method->name()->not_equals(vmSymbols::object_initializer_name()), "should have been checked in verifier");
1112   assert(resolved_method->name()->not_equals(vmSymbols::class_initializer_name ()), "should have been checked in verifier");
1113 
1114   // check if private interface method
1115   if (resolved_klass->is_interface() && resolved_method->is_private()) {
1116     ResourceMark rm(THREAD);
1117     char buf[200];
1118     jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokevirtual: method %s, caller-class:%s",
1119                  Method::name_and_sig_as_C_string(resolved_klass(),
1120                                                   resolved_method->name(),
1121                                                   resolved_method->signature()),
1122                    (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()));
1123     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1124   }
1125 
1126   // check if not static
1127   if (resolved_method->is_static()) {
1128     ResourceMark rm(THREAD);
1129     char buf[200];
1130     jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
1131                                                                                                              resolved_method->name(),
1132                                                                                                              resolved_method->signature()));


1247     tty->cr();
1248   }
1249   // setup result
1250   result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK);
1251 }
1252 
1253 void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass,
1254                                           Symbol* method_name, Symbol* method_signature, KlassHandle current_klass,
1255                                           bool check_access, bool check_null_and_abstract, TRAPS) {
1256   methodHandle resolved_method;
1257   linktime_resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
1258   runtime_resolve_interface_method(result, resolved_method, resolved_klass, recv, recv_klass, check_null_and_abstract, CHECK);
1259 }
1260 
1261 // throws linktime exceptions
1262 void LinkResolver::linktime_resolve_interface_method(methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name,
1263                                                      Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS) {
1264   // normal interface method resolution
1265   resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, true, CHECK);
1266 
1267   assert(resolved_method->name()->not_equals(vmSymbols::object_initializer_name()), "should have been checked in verifier");
1268   assert(resolved_method->name()->not_equals(vmSymbols::class_initializer_name ()), "should have been checked in verifier");
1269 }
1270 
1271 // throws runtime exceptions
1272 void LinkResolver::runtime_resolve_interface_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass,
1273                                                     Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS) {
1274   // check if receiver exists
1275   if (check_null_and_abstract && recv.is_null()) {
1276     THROW(vmSymbols::java_lang_NullPointerException());
1277   }
1278 
1279   // check if private interface method
1280   if (resolved_klass->is_interface() && resolved_method->is_private()) {
1281     ResourceMark rm(THREAD);
1282     char buf[200];
1283     jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s",
1284                  Method::name_and_sig_as_C_string(resolved_klass(),
1285                                                   resolved_method->name(),
1286                                                   resolved_method->signature()));
1287     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1288   }


src/share/vm/interpreter/linkResolver.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File