hotspot/src/share/vm/interpreter/linkResolver.cpp
changeset 20017 81eba62e9048
parent 17024 49cbeca23983
child 20282 7f9cbdf89af2
equal deleted inserted replaced
20014:b34a9fa1931a 20017:81eba62e9048
    44 #include "runtime/reflection.hpp"
    44 #include "runtime/reflection.hpp"
    45 #include "runtime/signature.hpp"
    45 #include "runtime/signature.hpp"
    46 #include "runtime/thread.inline.hpp"
    46 #include "runtime/thread.inline.hpp"
    47 #include "runtime/vmThread.hpp"
    47 #include "runtime/vmThread.hpp"
    48 
    48 
    49 //------------------------------------------------------------------------------------------------------------------------
       
    50 // Implementation of FieldAccessInfo
       
    51 
       
    52 void FieldAccessInfo::set(KlassHandle klass, Symbol* name, int field_index, int field_offset,
       
    53 BasicType field_type, AccessFlags access_flags) {
       
    54   _klass        = klass;
       
    55   _name         = name;
       
    56   _field_index  = field_index;
       
    57   _field_offset = field_offset;
       
    58   _field_type   = field_type;
       
    59   _access_flags = access_flags;
       
    60 }
       
    61 
       
    62 
    49 
    63 //------------------------------------------------------------------------------------------------------------------------
    50 //------------------------------------------------------------------------------------------------------------------------
    64 // Implementation of CallInfo
    51 // Implementation of CallInfo
    65 
    52 
    66 
    53 
    67 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) {
    54 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) {
    68   int vtable_index = Method::nonvirtual_vtable_index;
    55   int vtable_index = Method::nonvirtual_vtable_index;
    69   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK);
    56   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
    70 }
    57 }
    71 
    58 
    72 
    59 
    73 void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) {
    60 void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index, TRAPS) {
    74   // This is only called for interface methods. If the resolved_method
    61   // This is only called for interface methods. If the resolved_method
    75   // comes from java/lang/Object, it can be the subject of a virtual call, so
    62   // comes from java/lang/Object, it can be the subject of a virtual call, so
    76   // we should pick the vtable index from the resolved method.
    63   // we should pick the vtable index from the resolved method.
    77   // Other than that case, there is no valid vtable index to specify.
    64   // In that case, the caller must call set_virtual instead of set_interface.
    78   int vtable_index = Method::invalid_vtable_index;
    65   assert(resolved_method->method_holder()->is_interface(), "");
    79   if (resolved_method->method_holder() == SystemDictionary::Object_klass()) {
    66   assert(itable_index == resolved_method()->itable_index(), "");
    80     assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check");
    67   set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK);
    81     vtable_index = resolved_method->vtable_index();
       
    82   }
       
    83   set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK);
       
    84 }
    68 }
    85 
    69 
    86 void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) {
    70 void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) {
    87   assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index");
    71   assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index");
    88   set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK);
    72   assert(vtable_index < 0 || !resolved_method->has_vtable_index() || vtable_index == resolved_method->vtable_index(), "");
       
    73   CallKind kind = (vtable_index >= 0 && !resolved_method->can_be_statically_bound() ? CallInfo::vtable_call : CallInfo::direct_call);
       
    74   set_common(resolved_klass, selected_klass, resolved_method, selected_method, kind, vtable_index, CHECK);
    89   assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call");
    75   assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call");
    90 }
    76 }
    91 
    77 
    92 void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) {
    78 void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) {
    93   if (resolved_method.is_null()) {
    79   if (resolved_method.is_null()) {
    96   KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass();
    82   KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass();
    97   assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic ||
    83   assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic ||
    98          resolved_method->is_compiled_lambda_form(),
    84          resolved_method->is_compiled_lambda_form(),
    99          "linkMethod must return one of these");
    85          "linkMethod must return one of these");
   100   int vtable_index = Method::nonvirtual_vtable_index;
    86   int vtable_index = Method::nonvirtual_vtable_index;
   101   assert(resolved_method->vtable_index() == vtable_index, "");
    87   assert(!resolved_method->has_vtable_index(), "");
   102   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK);
    88   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
   103   _resolved_appendix    = resolved_appendix;
    89   _resolved_appendix    = resolved_appendix;
   104   _resolved_method_type = resolved_method_type;
    90   _resolved_method_type = resolved_method_type;
   105 }
    91 }
   106 
    92 
   107 void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) {
    93 void CallInfo::set_common(KlassHandle resolved_klass,
       
    94                           KlassHandle selected_klass,
       
    95                           methodHandle resolved_method,
       
    96                           methodHandle selected_method,
       
    97                           CallKind kind,
       
    98                           int index,
       
    99                           TRAPS) {
   108   assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond");
   100   assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond");
   109   _resolved_klass  = resolved_klass;
   101   _resolved_klass  = resolved_klass;
   110   _selected_klass  = selected_klass;
   102   _selected_klass  = selected_klass;
   111   _resolved_method = resolved_method;
   103   _resolved_method = resolved_method;
   112   _selected_method = selected_method;
   104   _selected_method = selected_method;
   113   _vtable_index    = vtable_index;
   105   _call_kind       = kind;
       
   106   _call_index      = index;
   114   _resolved_appendix = Handle();
   107   _resolved_appendix = Handle();
       
   108   DEBUG_ONLY(verify());  // verify before making side effects
       
   109 
   115   if (CompilationPolicy::must_be_compiled(selected_method)) {
   110   if (CompilationPolicy::must_be_compiled(selected_method)) {
   116     // This path is unusual, mostly used by the '-Xcomp' stress test mode.
   111     // This path is unusual, mostly used by the '-Xcomp' stress test mode.
   117 
   112 
   118     // Note: with several active threads, the must_be_compiled may be true
   113     // Note: with several active threads, the must_be_compiled may be true
   119     //       while can_be_compiled is false; remove assert
   114     //       while can_be_compiled is false; remove assert
   136                                   CompilationPolicy::policy()->initial_compile_level(),
   131                                   CompilationPolicy::policy()->initial_compile_level(),
   137                                   methodHandle(), 0, "must_be_compiled", CHECK);
   132                                   methodHandle(), 0, "must_be_compiled", CHECK);
   138   }
   133   }
   139 }
   134 }
   140 
   135 
       
   136 // utility query for unreflecting a method
       
   137 CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass) {
       
   138   Klass* resolved_method_holder = resolved_method->method_holder();
       
   139   if (resolved_klass == NULL) { // 2nd argument defaults to holder of 1st
       
   140     resolved_klass = resolved_method_holder;
       
   141   }
       
   142   _resolved_klass  = resolved_klass;
       
   143   _selected_klass  = resolved_klass;
       
   144   _resolved_method = resolved_method;
       
   145   _selected_method = resolved_method;
       
   146   // classify:
       
   147   CallKind kind = CallInfo::unknown_kind;
       
   148   int index = resolved_method->vtable_index();
       
   149   if (resolved_method->can_be_statically_bound()) {
       
   150     kind = CallInfo::direct_call;
       
   151   } else if (!resolved_method_holder->is_interface()) {
       
   152     // Could be an Object method inherited into an interface, but still a vtable call.
       
   153     kind = CallInfo::vtable_call;
       
   154   } else if (!resolved_klass->is_interface()) {
       
   155     // A miranda method.  Compute the vtable index.
       
   156     ResourceMark rm;
       
   157     klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable();
       
   158     index = vt->index_of_miranda(resolved_method->name(),
       
   159                                  resolved_method->signature());
       
   160     kind = CallInfo::vtable_call;
       
   161   } else {
       
   162     // A regular interface call.
       
   163     kind = CallInfo::itable_call;
       
   164     index = resolved_method->itable_index();
       
   165   }
       
   166   assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index));
       
   167   _call_kind  = kind;
       
   168   _call_index = index;
       
   169   _resolved_appendix = Handle();
       
   170   DEBUG_ONLY(verify());
       
   171 }
       
   172 
       
   173 #ifdef ASSERT
       
   174 void CallInfo::verify() {
       
   175   switch (call_kind()) {  // the meaning and allowed value of index depends on kind
       
   176   case CallInfo::direct_call:
       
   177     if (_call_index == Method::nonvirtual_vtable_index)  break;
       
   178     // else fall through to check vtable index:
       
   179   case CallInfo::vtable_call:
       
   180     assert(resolved_klass()->verify_vtable_index(_call_index), "");
       
   181     break;
       
   182   case CallInfo::itable_call:
       
   183     assert(resolved_method()->method_holder()->verify_itable_index(_call_index), "");
       
   184     break;
       
   185   case CallInfo::unknown_kind:
       
   186     assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set");
       
   187     break;
       
   188   default:
       
   189     fatal(err_msg_res("Unexpected call kind %d", call_kind()));
       
   190   }
       
   191 }
       
   192 #endif //ASSERT
       
   193 
       
   194 
   141 
   195 
   142 //------------------------------------------------------------------------------------------------------------------------
   196 //------------------------------------------------------------------------------------------------------------------------
   143 // Klass resolution
   197 // Klass resolution
   144 
   198 
   145 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
   199 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
   160 
   214 
   161 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) {
   215 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) {
   162   Klass* result_oop = pool->klass_ref_at(index, CHECK);
   216   Klass* result_oop = pool->klass_ref_at(index, CHECK);
   163   result = KlassHandle(THREAD, result_oop);
   217   result = KlassHandle(THREAD, result_oop);
   164 }
   218 }
   165 
       
   166 void LinkResolver::resolve_klass_no_update(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) {
       
   167   Klass* result_oop =
       
   168          ConstantPool::klass_ref_at_if_loaded_check(pool, index, CHECK);
       
   169   result = KlassHandle(THREAD, result_oop);
       
   170 }
       
   171 
       
   172 
   219 
   173 //------------------------------------------------------------------------------------------------------------------------
   220 //------------------------------------------------------------------------------------------------------------------------
   174 // Method resolution
   221 // Method resolution
   175 //
   222 //
   176 // According to JVM spec. $5.4.3c & $5.4.3d
   223 // According to JVM spec. $5.4.3c & $5.4.3d
   358   }
   405   }
   359 }
   406 }
   360 
   407 
   361 void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass,
   408 void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass,
   362                                              Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) {
   409                                              Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) {
   363 
   410   // This method is used only
       
   411   // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call),
       
   412   // and
       
   413   // (2) in Bytecode_invoke::static_target
       
   414   // It appears to fail when applied to an invokeinterface call site.
       
   415   // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
   364   // resolve klass
   416   // resolve klass
   365   if (code == Bytecodes::_invokedynamic) {
   417   if (code == Bytecodes::_invokedynamic) {
   366     resolved_klass = SystemDictionary::MethodHandle_klass();
   418     resolved_klass = SystemDictionary::MethodHandle_klass();
   367     Symbol* method_name = vmSymbols::invoke_name();
   419     Symbol* method_name = vmSymbols::invoke_name();
   368     Symbol* method_signature = pool->signature_ref_at(index);
   420     Symbol* method_signature = pool->signature_ref_at(index);
   578     );
   630     );
   579     return;
   631     return;
   580   }
   632   }
   581 }
   633 }
   582 
   634 
   583 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS) {
   635 void LinkResolver::resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) {
   584   resolve_field(result, pool, index, byte, check_only, true, CHECK);
       
   585 }
       
   586 
       
   587 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS) {
       
   588   assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic ||
       
   589          byte == Bytecodes::_getfield  || byte == Bytecodes::_putfield, "bad bytecode");
       
   590 
       
   591   bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
       
   592   bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic);
       
   593 
       
   594   // resolve specified klass
       
   595   KlassHandle resolved_klass;
       
   596   if (update_pool) {
       
   597     resolve_klass(resolved_klass, pool, index, CHECK);
       
   598   } else {
       
   599     resolve_klass_no_update(resolved_klass, pool, index, CHECK);
       
   600   }
       
   601   // Load these early in case the resolve of the containing klass fails
   636   // Load these early in case the resolve of the containing klass fails
   602   Symbol* field = pool->name_ref_at(index);
   637   Symbol* field = pool->name_ref_at(index);
   603   Symbol* sig   = pool->signature_ref_at(index);
   638   Symbol* sig   = pool->signature_ref_at(index);
       
   639 
       
   640   // resolve specified klass
       
   641   KlassHandle resolved_klass;
       
   642   resolve_klass(resolved_klass, pool, index, CHECK);
       
   643 
       
   644   KlassHandle  current_klass(THREAD, pool->pool_holder());
       
   645   resolve_field(result, resolved_klass, field, sig, current_klass, byte, true, true, CHECK);
       
   646 }
       
   647 
       
   648 void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass, Symbol* field, Symbol* sig,
       
   649                                  KlassHandle current_klass, Bytecodes::Code byte, bool check_access, bool initialize_class,
       
   650                                  TRAPS) {
       
   651   assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic ||
       
   652          byte == Bytecodes::_getfield  || byte == Bytecodes::_putfield  ||
       
   653          (byte == Bytecodes::_nop && !check_access), "bad field access bytecode");
       
   654 
       
   655   bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
       
   656   bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic);
       
   657 
   604   // Check if there's a resolved klass containing the field
   658   // Check if there's a resolved klass containing the field
   605   if( resolved_klass.is_null() ) {
   659   if (resolved_klass.is_null()) {
   606     ResourceMark rm(THREAD);
   660     ResourceMark rm(THREAD);
   607     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
   661     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
   608   }
   662   }
   609 
   663 
   610   // Resolve instance field
   664   // Resolve instance field
   611   fieldDescriptor fd; // find_field initializes fd if found
       
   612   KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
   665   KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
   613   // check if field exists; i.e., if a klass containing the field def has been selected
   666   // check if field exists; i.e., if a klass containing the field def has been selected
   614   if (sel_klass.is_null()){
   667   if (sel_klass.is_null()) {
   615     ResourceMark rm(THREAD);
   668     ResourceMark rm(THREAD);
   616     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
   669     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
   617   }
   670   }
   618 
   671 
       
   672   if (!check_access)
       
   673     // Access checking may be turned off when calling from within the VM.
       
   674     return;
       
   675 
   619   // check access
   676   // check access
   620   KlassHandle ref_klass(THREAD, pool->pool_holder());
   677   check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK);
   621   check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
       
   622 
   678 
   623   // check for errors
   679   // check for errors
   624   if (is_static != fd.is_static()) {
   680   if (is_static != fd.is_static()) {
   625     ResourceMark rm(THREAD);
   681     ResourceMark rm(THREAD);
   626     char msg[200];
   682     char msg[200];
   627     jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string());
   683     jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string());
   628     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
   684     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
   629   }
   685   }
   630 
   686 
   631   // Final fields can only be accessed from its own class.
   687   // Final fields can only be accessed from its own class.
   632   if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
   688   if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
   633     THROW(vmSymbols::java_lang_IllegalAccessError());
   689     THROW(vmSymbols::java_lang_IllegalAccessError());
   634   }
   690   }
   635 
   691 
   636   // initialize resolved_klass if necessary
   692   // initialize resolved_klass if necessary
   637   // note 1: the klass which declared the field must be initialized (i.e, sel_klass)
   693   // note 1: the klass which declared the field must be initialized (i.e, sel_klass)
   638   //         according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99)
   694   //         according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99)
   639   //
   695   //
   640   // note 2: we don't want to force initialization if we are just checking
   696   // note 2: we don't want to force initialization if we are just checking
   641   //         if the field access is legal; e.g., during compilation
   697   //         if the field access is legal; e.g., during compilation
   642   if (is_static && !check_only) {
   698   if (is_static && initialize_class) {
   643     sel_klass->initialize(CHECK);
   699     sel_klass->initialize(CHECK);
   644   }
   700   }
   645 
   701 
   646   {
   702   if (sel_klass() != current_klass()) {
   647     HandleMark hm(THREAD);
   703     HandleMark hm(THREAD);
   648     Handle ref_loader (THREAD, InstanceKlass::cast(ref_klass())->class_loader());
   704     Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader());
   649     Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader());
   705     Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader());
   650     Symbol*  signature_ref  = pool->signature_ref_at(index);
       
   651     {
   706     {
   652       ResourceMark rm(THREAD);
   707       ResourceMark rm(THREAD);
   653       Symbol* failed_type_symbol =
   708       Symbol* failed_type_symbol =
   654         SystemDictionary::check_signature_loaders(signature_ref,
   709         SystemDictionary::check_signature_loaders(sig,
   655                                                   ref_loader, sel_loader,
   710                                                   ref_loader, sel_loader,
   656                                                   false,
   711                                                   false,
   657                                                   CHECK);
   712                                                   CHECK);
   658       if (failed_type_symbol != NULL) {
   713       if (failed_type_symbol != NULL) {
   659         const char* msg = "loader constraint violation: when resolving field"
   714         const char* msg = "loader constraint violation: when resolving field"
   675     }
   730     }
   676   }
   731   }
   677 
   732 
   678   // return information. note that the klass is set to the actual klass containing the
   733   // return information. note that the klass is set to the actual klass containing the
   679   // field, otherwise access of static fields in superclasses will not work.
   734   // field, otherwise access of static fields in superclasses will not work.
   680   KlassHandle holder (THREAD, fd.field_holder());
       
   681   Symbol*  name   = fd.name();
       
   682   result.set(holder, name, fd.index(), fd.offset(), fd.field_type(), fd.access_flags());
       
   683 }
   735 }
   684 
   736 
   685 
   737 
   686 //------------------------------------------------------------------------------------------------------------------------
   738 //------------------------------------------------------------------------------------------------------------------------
   687 // Invoke resolution
   739 // Invoke resolution
   905   if (check_null_and_abstract && recv.is_null()) { // check if receiver exists
   957   if (check_null_and_abstract && recv.is_null()) { // check if receiver exists
   906     THROW(vmSymbols::java_lang_NullPointerException());
   958     THROW(vmSymbols::java_lang_NullPointerException());
   907   }
   959   }
   908 
   960 
   909   // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
   961   // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
   910   // has not been rewritten, and the vtable initialized.
       
   911   assert(resolved_method->method_holder()->is_linked(), "must be linked");
       
   912 
       
   913   // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
       
   914   // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since
   962   // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since
   915   // a missing receiver might result in a bogus lookup.
   963   // a missing receiver might result in a bogus lookup.
   916   assert(resolved_method->method_holder()->is_linked(), "must be linked");
   964   assert(resolved_method->method_holder()->is_linked(), "must be linked");
   917 
   965 
   918   // do lookup based on receiver klass using the vtable index
   966   // do lookup based on receiver klass using the vtable index
   919   if (resolved_method->method_holder()->is_interface()) { // miranda method
   967   if (resolved_method->method_holder()->is_interface()) { // miranda method
   920     vtable_index = vtable_index_of_miranda_method(resolved_klass,
   968     vtable_index = vtable_index_of_miranda_method(resolved_klass,
   921                            resolved_method->name(),
   969                            resolved_method->name(),
   922                            resolved_method->signature(), CHECK);
   970                            resolved_method->signature(), CHECK);
       
   971 
   923     assert(vtable_index >= 0 , "we should have valid vtable index at this point");
   972     assert(vtable_index >= 0 , "we should have valid vtable index at this point");
   924 
   973 
   925     InstanceKlass* inst = InstanceKlass::cast(recv_klass());
   974     InstanceKlass* inst = InstanceKlass::cast(recv_klass());
   926     selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
   975     selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
   927   } else {
   976   } else {
   928     // at this point we are sure that resolved_method is virtual and not
   977     // at this point we are sure that resolved_method is virtual and not
   929     // a miranda method; therefore, it must have a valid vtable index.
   978     // a miranda method; therefore, it must have a valid vtable index.
       
   979     assert(!resolved_method->has_itable_index(), "");
   930     vtable_index = resolved_method->vtable_index();
   980     vtable_index = resolved_method->vtable_index();
   931     // We could get a negative vtable_index for final methods,
   981     // We could get a negative vtable_index for final methods,
   932     // because as an optimization they are they are never put in the vtable,
   982     // because as an optimization they are they are never put in the vtable,
   933     // unless they override an existing method.
   983     // unless they override an existing method.
   934     // If we do get a negative, it means the resolved method is the the selected
   984     // If we do get a negative, it means the resolved method is the the selected
  1004   // do lookup based on receiver klass
  1054   // do lookup based on receiver klass
  1005   methodHandle sel_method;
  1055   methodHandle sel_method;
  1006   lookup_instance_method_in_klasses(sel_method, recv_klass,
  1056   lookup_instance_method_in_klasses(sel_method, recv_klass,
  1007             resolved_method->name(),
  1057             resolved_method->name(),
  1008             resolved_method->signature(), CHECK);
  1058             resolved_method->signature(), CHECK);
       
  1059   if (sel_method.is_null() && !check_null_and_abstract) {
       
  1060     // In theory this is a harmless placeholder value, but
       
  1061     // in practice leaving in null affects the nsk default method tests.
       
  1062     // This needs further study.
       
  1063     sel_method = resolved_method;
       
  1064   }
  1009   // check if method exists
  1065   // check if method exists
  1010   if (sel_method.is_null()) {
  1066   if (sel_method.is_null()) {
  1011     ResourceMark rm(THREAD);
  1067     ResourceMark rm(THREAD);
  1012     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
  1068     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
  1013               Method::name_and_sig_as_C_string(recv_klass(),
  1069               Method::name_and_sig_as_C_string(recv_klass(),
  1044               Method::name_and_sig_as_C_string(recv_klass(),
  1100               Method::name_and_sig_as_C_string(recv_klass(),
  1045                                                       sel_method->name(),
  1101                                                       sel_method->name(),
  1046                                                       sel_method->signature()));
  1102                                                       sel_method->signature()));
  1047   }
  1103   }
  1048   // setup result
  1104   // setup result
  1049   result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK);
  1105   if (!resolved_method->has_itable_index()) {
       
  1106     int vtable_index = resolved_method->vtable_index();
       
  1107     assert(vtable_index == sel_method->vtable_index(), "sanity check");
       
  1108     result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK);
       
  1109     return;
       
  1110   }
       
  1111   int itable_index = resolved_method()->itable_index();
       
  1112   result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK);
  1050 }
  1113 }
  1051 
  1114 
  1052 
  1115 
  1053 methodHandle LinkResolver::linktime_resolve_interface_method_or_null(
  1116 methodHandle LinkResolver::linktime_resolve_interface_method_or_null(
  1054                                                  KlassHandle resolved_klass,
  1117                                                  KlassHandle resolved_klass,
  1291     result.set_handle(method, appendix, method_type, CHECK);
  1354     result.set_handle(method, appendix, method_type, CHECK);
  1292     return;
  1355     return;
  1293   }
  1356   }
  1294 
  1357 
  1295   if (TraceMethodHandles) {
  1358   if (TraceMethodHandles) {
  1296     tty->print_cr("resolve_invokedynamic #%d %s %s",
  1359       ResourceMark rm(THREAD);
       
  1360       tty->print_cr("resolve_invokedynamic #%d %s %s",
  1297                   ConstantPool::decode_invokedynamic_index(index),
  1361                   ConstantPool::decode_invokedynamic_index(index),
  1298                   method_name->as_C_string(), method_signature->as_C_string());
  1362                   method_name->as_C_string(), method_signature->as_C_string());
  1299     tty->print("  BSM info: "); bootstrap_specifier->print();
  1363     tty->print("  BSM info: "); bootstrap_specifier->print();
  1300   }
  1364   }
  1301 
  1365 
  1340 }
  1404 }
  1341 
  1405 
  1342 //------------------------------------------------------------------------------------------------------------------------
  1406 //------------------------------------------------------------------------------------------------------------------------
  1343 #ifndef PRODUCT
  1407 #ifndef PRODUCT
  1344 
  1408 
  1345 void FieldAccessInfo::print() {
  1409 void CallInfo::print() {
  1346   ResourceMark rm;
  1410   ResourceMark rm;
  1347   tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset());
  1411   const char* kindstr = "unknown";
       
  1412   switch (_call_kind) {
       
  1413   case direct_call: kindstr = "direct"; break;
       
  1414   case vtable_call: kindstr = "vtable"; break;
       
  1415   case itable_call: kindstr = "itable"; break;
       
  1416   }
       
  1417   tty->print_cr("Call %s@%d %s", kindstr, _call_index,
       
  1418                 _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string());
  1348 }
  1419 }
  1349 
  1420 
  1350 #endif
  1421 #endif