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

src/share/vm/interpreter/linkResolver.cpp

Print this page




  29 #include "compiler/compileBroker.hpp"
  30 #include "gc_interface/collectedHeap.inline.hpp"
  31 #include "interpreter/bytecode.hpp"
  32 #include "interpreter/interpreterRuntime.hpp"
  33 #include "interpreter/linkResolver.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "memory/universe.inline.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/objArrayOop.hpp"
  38 #include "prims/methodHandles.hpp"
  39 #include "prims/nativeLookup.hpp"
  40 #include "runtime/compilationPolicy.hpp"
  41 #include "runtime/fieldDescriptor.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/handles.inline.hpp"
  44 #include "runtime/reflection.hpp"
  45 #include "runtime/signature.hpp"
  46 #include "runtime/thread.inline.hpp"
  47 #include "runtime/vmThread.hpp"
  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 
  63 //------------------------------------------------------------------------------------------------------------------------
  64 // Implementation of CallInfo
  65 
  66 
  67 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) {
  68   int vtable_index = Method::nonvirtual_vtable_index;
  69   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK);
  70 }
  71 
  72 
  73 void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) {
  74   // 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
  76   // we should pick the vtable index from the resolved method.
  77   // Other than that case, there is no valid vtable index to specify.
  78   int vtable_index = Method::invalid_vtable_index;
  79   if (resolved_method->method_holder() == SystemDictionary::Object_klass()) {
  80     assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check");
  81     vtable_index = resolved_method->vtable_index();
  82   }
  83   set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK);
  84 }
  85 
  86 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");
  88   set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK);


  89   assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call");
  90 }
  91 
  92 void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) {
  93   if (resolved_method.is_null()) {
  94     THROW_MSG(vmSymbols::java_lang_InternalError(), "resolved method is null");
  95   }
  96   KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass();
  97   assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic ||
  98          resolved_method->is_compiled_lambda_form(),
  99          "linkMethod must return one of these");
 100   int vtable_index = Method::nonvirtual_vtable_index;
 101   assert(resolved_method->vtable_index() == vtable_index, "");
 102   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK);
 103   _resolved_appendix    = resolved_appendix;
 104   _resolved_method_type = resolved_method_type;
 105 }
 106 
 107 void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) {






 108   assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond");
 109   _resolved_klass  = resolved_klass;
 110   _selected_klass  = selected_klass;
 111   _resolved_method = resolved_method;
 112   _selected_method = selected_method;
 113   _vtable_index    = vtable_index;

 114   _resolved_appendix = Handle();


 115   if (CompilationPolicy::must_be_compiled(selected_method)) {
 116     // This path is unusual, mostly used by the '-Xcomp' stress test mode.
 117 
 118     // Note: with several active threads, the must_be_compiled may be true
 119     //       while can_be_compiled is false; remove assert
 120     // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile");
 121     if (THREAD->is_Compiler_thread()) {
 122       // don't force compilation, resolve was on behalf of compiler
 123       return;
 124     }
 125     if (selected_method->method_holder()->is_not_initialized()) {
 126       // 'is_not_initialized' means not only '!is_initialized', but also that
 127       // initialization has not been started yet ('!being_initialized')
 128       // Do not force compilation of methods in uninitialized classes.
 129       // Note that doing this would throw an assert later,
 130       // in CompileBroker::compile_method.
 131       // We sometimes use the link resolver to do reflective lookups
 132       // even before classes are initialized.
 133       return;
 134     }
 135     CompileBroker::compile_method(selected_method, InvocationEntryBci,
 136                                   CompilationPolicy::policy()->initial_compile_level(),
 137                                   methodHandle(), 0, "must_be_compiled", CHECK);
 138   }
 139 }
 140 



























































 141 
 142 //------------------------------------------------------------------------------------------------------------------------
 143 // Klass resolution
 144 
 145 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
 146   if (!Reflection::verify_class_access(ref_klass(),
 147                                        sel_klass(),
 148                                        true)) {
 149     ResourceMark rm(THREAD);
 150     Exceptions::fthrow(
 151       THREAD_AND_LOCATION,
 152       vmSymbols::java_lang_IllegalAccessError(),
 153       "tried to access class %s from class %s",
 154       sel_klass->external_name(),
 155       ref_klass->external_name()
 156     );
 157     return;
 158   }
 159 }
 160 
 161 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) {
 162   Klass* result_oop = pool->klass_ref_at(index, CHECK);
 163   result = KlassHandle(THREAD, result_oop);
 164 }
 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 
 173 //------------------------------------------------------------------------------------------------------------------------
 174 // Method resolution
 175 //
 176 // According to JVM spec. $5.4.3c & $5.4.3d
 177 
 178 void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
 179   Method* result_oop = klass->uncached_lookup_method(name, signature);
 180   if (EnableInvokeDynamic && result_oop != NULL) {
 181     vmIntrinsics::ID iid = result_oop->intrinsic_id();
 182     if (MethodHandles::is_signature_polymorphic(iid)) {
 183       // Do not link directly to these.  The VM must produce a synthetic one using lookup_polymorphic_method.
 184       return;
 185     }
 186   }
 187   result = methodHandle(THREAD, result_oop);
 188 }
 189 
 190 // returns first instance method
 191 void LinkResolver::lookup_instance_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
 192   Method* result_oop = klass->uncached_lookup_method(name, signature);


 343                                        resolved_klass(),
 344                                        sel_klass(),
 345                                        flags,
 346                                        true)) {
 347     ResourceMark rm(THREAD);
 348     Exceptions::fthrow(
 349       THREAD_AND_LOCATION,
 350       vmSymbols::java_lang_IllegalAccessError(),
 351       "tried to access method %s.%s%s from class %s",
 352       sel_klass->external_name(),
 353       sel_method->name()->as_C_string(),
 354       sel_method->signature()->as_C_string(),
 355       ref_klass->external_name()
 356     );
 357     return;
 358   }
 359 }
 360 
 361 void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass,
 362                                              Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) {




 363 
 364   // resolve klass
 365   if (code == Bytecodes::_invokedynamic) {
 366     resolved_klass = SystemDictionary::MethodHandle_klass();
 367     Symbol* method_name = vmSymbols::invoke_name();
 368     Symbol* method_signature = pool->signature_ref_at(index);
 369     KlassHandle  current_klass(THREAD, pool->pool_holder());
 370     resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK);
 371     return;
 372   }
 373 
 374   resolve_klass(resolved_klass, pool, index, CHECK);
 375 
 376   Symbol*  method_name       = pool->name_ref_at(index);
 377   Symbol*  method_signature  = pool->signature_ref_at(index);
 378   KlassHandle  current_klass(THREAD, pool->pool_holder());
 379 
 380   if (pool->has_preresolution()
 381       || (resolved_klass() == SystemDictionary::MethodHandle_klass() &&
 382           MethodHandles::is_signature_polymorphic_name(resolved_klass(), method_name))) {


 563                                              fieldDescriptor& fd,
 564                                              TRAPS) {
 565   if (!Reflection::verify_field_access(ref_klass(),
 566                                        resolved_klass(),
 567                                        sel_klass(),
 568                                        fd.access_flags(),
 569                                        true)) {
 570     ResourceMark rm(THREAD);
 571     Exceptions::fthrow(
 572       THREAD_AND_LOCATION,
 573       vmSymbols::java_lang_IllegalAccessError(),
 574       "tried to access field %s.%s from class %s",
 575       sel_klass->external_name(),
 576       fd.name()->as_C_string(),
 577       ref_klass->external_name()
 578     );
 579     return;
 580   }
 581 }
 582 
 583 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, 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
 602   Symbol* field = pool->name_ref_at(index);
 603   Symbol* sig   = pool->signature_ref_at(index);
 604   // Check if there's a resolved klass containing the field
 605   if( resolved_klass.is_null() ) {
 606     ResourceMark rm(THREAD);
 607     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
 608   }
 609 
 610   // 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));
 613   // check if field exists; i.e., if a klass containing the field def has been selected
 614   if (sel_klass.is_null()){
 615     ResourceMark rm(THREAD);
 616     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
 617   }
 618 




 619   // check access
 620   KlassHandle ref_klass(THREAD, pool->pool_holder());
 621   check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
 622 
 623   // check for errors
 624   if (is_static != fd.is_static()) {
 625     ResourceMark rm(THREAD);
 626     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());
 628     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
 629   }
 630 
 631   // Final fields can only be accessed from its own class.
 632   if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
 633     THROW(vmSymbols::java_lang_IllegalAccessError());
 634   }
 635 
 636   // initialize resolved_klass if necessary
 637   // 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)
 639   //
 640   // 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
 642   if (is_static && !check_only) {
 643     sel_klass->initialize(CHECK);
 644   }
 645 
 646   {
 647     HandleMark hm(THREAD);
 648     Handle ref_loader (THREAD, InstanceKlass::cast(ref_klass())->class_loader());
 649     Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader());
 650     Symbol*  signature_ref  = pool->signature_ref_at(index);
 651     {
 652       ResourceMark rm(THREAD);
 653       Symbol* failed_type_symbol =
 654         SystemDictionary::check_signature_loaders(signature_ref,
 655                                                   ref_loader, sel_loader,
 656                                                   false,
 657                                                   CHECK);
 658       if (failed_type_symbol != NULL) {
 659         const char* msg = "loader constraint violation: when resolving field"
 660           " \"%s\" the class loader (instance of %s) of the referring class, "
 661           "%s, and the class loader (instance of %s) for the field's resolved "
 662           "type, %s, have different Class objects for that type";
 663         char* field_name = field->as_C_string();
 664         const char* loader1 = SystemDictionary::loader_name(ref_loader());
 665         char* sel = InstanceKlass::cast(sel_klass())->name()->as_C_string();
 666         const char* loader2 = SystemDictionary::loader_name(sel_loader());
 667         char* failed_type_name = failed_type_symbol->as_C_string();
 668         size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1) +
 669           strlen(sel) + strlen(loader2) + strlen(failed_type_name) + 1;
 670         char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
 671         jio_snprintf(buf, buflen, msg, field_name, loader1, sel, loader2,
 672                      failed_type_name);
 673         THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
 674       }
 675     }
 676   }
 677 
 678   // 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.
 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 }
 684 
 685 
 686 //------------------------------------------------------------------------------------------------------------------------
 687 // Invoke resolution
 688 //
 689 // Naming conventions:
 690 //
 691 // resolved_method    the specified method (i.e., static receiver specified via constant pool index)
 692 // sel_method         the selected method  (selected via run-time lookup; e.g., based on dynamic receiver class)
 693 // resolved_klass     the specified klass  (i.e., specified via constant pool index)
 694 // recv_klass         the receiver klass
 695 
 696 
 697 void LinkResolver::resolve_static_call(CallInfo& result, KlassHandle& resolved_klass, Symbol* method_name,
 698                                        Symbol* method_signature, KlassHandle current_klass,
 699                                        bool check_access, bool initialize_class, TRAPS) {
 700   methodHandle resolved_method;
 701   linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
 702   resolved_klass = KlassHandle(THREAD, resolved_method->method_holder());


 890 void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
 891                                                   methodHandle resolved_method,
 892                                                   KlassHandle resolved_klass,
 893                                                   Handle recv,
 894                                                   KlassHandle recv_klass,
 895                                                   bool check_null_and_abstract,
 896                                                   TRAPS) {
 897 
 898   // setup default return values
 899   int vtable_index = Method::invalid_vtable_index;
 900   methodHandle selected_method;
 901 
 902   assert(recv.is_null() || recv->is_oop(), "receiver is not an oop");
 903 
 904   // runtime method resolution
 905   if (check_null_and_abstract && recv.is_null()) { // check if receiver exists
 906     THROW(vmSymbols::java_lang_NullPointerException());
 907   }
 908 
 909   // 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
 915   // a missing receiver might result in a bogus lookup.
 916   assert(resolved_method->method_holder()->is_linked(), "must be linked");
 917 
 918   // do lookup based on receiver klass using the vtable index
 919   if (resolved_method->method_holder()->is_interface()) { // miranda method
 920     vtable_index = vtable_index_of_miranda_method(resolved_klass,
 921                            resolved_method->name(),
 922                            resolved_method->signature(), CHECK);

 923     assert(vtable_index >= 0 , "we should have valid vtable index at this point");
 924 
 925     InstanceKlass* inst = InstanceKlass::cast(recv_klass());
 926     selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
 927   } else {
 928     // 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.

 930     vtable_index = resolved_method->vtable_index();
 931     // We could get a negative vtable_index for final methods,
 932     // because as an optimization they are they are never put in the vtable,
 933     // unless they override an existing method.
 934     // If we do get a negative, it means the resolved method is the the selected
 935     // method, and it can never be changed by an override.
 936     if (vtable_index == Method::nonvirtual_vtable_index) {
 937       assert(resolved_method->can_be_statically_bound(), "cannot override this method");
 938       selected_method = resolved_method;
 939     } else {
 940       // recv_klass might be an arrayKlassOop but all vtables start at
 941       // the same place. The cast is to avoid virtual call and assertion.
 942       InstanceKlass* inst = (InstanceKlass*)recv_klass();
 943       selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
 944     }
 945   }



 946 
 947   // check if method exists
 948   if (selected_method.is_null()) {
 949     ResourceMark rm(THREAD);
 950     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
 951               Method::name_and_sig_as_C_string(resolved_klass(),
 952                                                       resolved_method->name(),
 953                                                       resolved_method->signature()));
 954   }
 955 
 956   // check if abstract
 957   if (check_null_and_abstract && selected_method->is_abstract()) {
 958     ResourceMark rm(THREAD);
 959     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
 960               Method::name_and_sig_as_C_string(resolved_klass(),
 961                                                       selected_method->name(),
 962                                                       selected_method->signature()));
 963   }
 964 
 965   // setup result


 989                                                     Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS) {
 990   // check if receiver exists
 991   if (check_null_and_abstract && recv.is_null()) {
 992     THROW(vmSymbols::java_lang_NullPointerException());
 993   }
 994 
 995   // check if receiver klass implements the resolved interface
 996   if (!recv_klass->is_subtype_of(resolved_klass())) {
 997     ResourceMark rm(THREAD);
 998     char buf[200];
 999     jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
1000                  recv_klass()->external_name(),
1001                  resolved_klass()->external_name());
1002     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1003   }
1004   // do lookup based on receiver klass
1005   methodHandle sel_method;
1006   lookup_instance_method_in_klasses(sel_method, recv_klass,
1007             resolved_method->name(),
1008             resolved_method->signature(), CHECK);



1009   // check if method exists
1010   if (sel_method.is_null()) {
1011     ResourceMark rm(THREAD);
1012     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1013               Method::name_and_sig_as_C_string(recv_klass(),
1014                                                       resolved_method->name(),
1015                                                       resolved_method->signature()));
1016   }
1017   // check access
1018   if (sel_method->method_holder()->is_interface()) {
1019     // Method holder is an interface. Throw Illegal Access Error if sel_method
1020     // is neither public nor private.
1021     if (!(sel_method->is_public() || sel_method->is_private())) {
1022       ResourceMark rm(THREAD);
1023       THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
1024                 Method::name_and_sig_as_C_string(recv_klass(),
1025                                                  sel_method->name(),
1026                                                  sel_method->signature()));
1027     }
1028   }
1029   else {
1030     // Method holder is a class. Throw Illegal Access Error if sel_method
1031     // is not public.
1032     if (!sel_method->is_public()) {
1033       ResourceMark rm(THREAD);
1034       THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
1035                 Method::name_and_sig_as_C_string(recv_klass(),
1036                                                  sel_method->name(),
1037                                                  sel_method->signature()));
1038     }
1039   }
1040   // check if abstract
1041   if (check_null_and_abstract && sel_method->is_abstract()) {
1042     ResourceMark rm(THREAD);
1043     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1044               Method::name_and_sig_as_C_string(recv_klass(),
1045                                                       sel_method->name(),
1046                                                       sel_method->signature()));
1047   }
1048   // setup result
1049   result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK);







1050 }
1051 
1052 
1053 methodHandle LinkResolver::linktime_resolve_interface_method_or_null(
1054                                                  KlassHandle resolved_klass,
1055                                                  Symbol* method_name,
1056                                                  Symbol* method_signature,
1057                                                  KlassHandle current_klass,
1058                                                  bool check_access) {
1059   EXCEPTION_MARK;
1060   methodHandle method_result;
1061   linktime_resolve_interface_method(method_result, resolved_klass, method_name, method_signature, current_klass, check_access, THREAD);
1062   if (HAS_PENDING_EXCEPTION) {
1063     CLEAR_PENDING_EXCEPTION;
1064     return methodHandle();
1065   } else {
1066     return method_result;
1067   }
1068 }
1069 


1325     }
1326     if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) {
1327       // throw these guys, since they are already wrapped
1328       return;
1329     }
1330     if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
1331       // intercept only LinkageErrors which might have failed to wrap
1332       return;
1333     }
1334     // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS.
1335     Handle nested_exception(THREAD, PENDING_EXCEPTION);
1336     CLEAR_PENDING_EXCEPTION;
1337     THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
1338   }
1339   result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK);
1340 }
1341 
1342 //------------------------------------------------------------------------------------------------------------------------
1343 #ifndef PRODUCT
1344 
1345 void FieldAccessInfo::print() {
1346   ResourceMark rm;
1347   tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset());







1348 }
1349 
1350 #endif


  29 #include "compiler/compileBroker.hpp"
  30 #include "gc_interface/collectedHeap.inline.hpp"
  31 #include "interpreter/bytecode.hpp"
  32 #include "interpreter/interpreterRuntime.hpp"
  33 #include "interpreter/linkResolver.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "memory/universe.inline.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/objArrayOop.hpp"
  38 #include "prims/methodHandles.hpp"
  39 #include "prims/nativeLookup.hpp"
  40 #include "runtime/compilationPolicy.hpp"
  41 #include "runtime/fieldDescriptor.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/handles.inline.hpp"
  44 #include "runtime/reflection.hpp"
  45 #include "runtime/signature.hpp"
  46 #include "runtime/thread.inline.hpp"
  47 #include "runtime/vmThread.hpp"
  48 













  49 
  50 //------------------------------------------------------------------------------------------------------------------------
  51 // Implementation of CallInfo
  52 
  53 
  54 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) {
  55   int vtable_index = Method::nonvirtual_vtable_index;
  56   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
  57 }
  58 
  59 
  60 void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index, TRAPS) {
  61   // This is only called for interface methods. If the resolved_method
  62   // comes from java/lang/Object, it can be the subject of a virtual call, so
  63   // we should pick the vtable index from the resolved method.
  64   // In that case, the caller must call set_virtual instead of set_interface.
  65   assert(resolved_method->method_holder()->is_interface(), "");
  66   assert(itable_index == resolved_method()->itable_index(), "");
  67   set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK);



  68 }
  69 
  70 void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) {
  71   assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index");
  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);
  75   assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call");
  76 }
  77 
  78 void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) {
  79   if (resolved_method.is_null()) {
  80     THROW_MSG(vmSymbols::java_lang_InternalError(), "resolved method is null");
  81   }
  82   KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass();
  83   assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic ||
  84          resolved_method->is_compiled_lambda_form(),
  85          "linkMethod must return one of these");
  86   int vtable_index = Method::nonvirtual_vtable_index;
  87   assert(!resolved_method->has_vtable_index(), "");
  88   set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
  89   _resolved_appendix    = resolved_appendix;
  90   _resolved_method_type = resolved_method_type;
  91 }
  92 
  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) {
 100   assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond");
 101   _resolved_klass  = resolved_klass;
 102   _selected_klass  = selected_klass;
 103   _resolved_method = resolved_method;
 104   _selected_method = selected_method;
 105   _call_kind       = kind;
 106   _call_index      = index;
 107   _resolved_appendix = Handle();
 108   DEBUG_ONLY(verify());  // verify before making side effects
 109 
 110   if (CompilationPolicy::must_be_compiled(selected_method)) {
 111     // This path is unusual, mostly used by the '-Xcomp' stress test mode.
 112 
 113     // Note: with several active threads, the must_be_compiled may be true
 114     //       while can_be_compiled is false; remove assert
 115     // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile");
 116     if (THREAD->is_Compiler_thread()) {
 117       // don't force compilation, resolve was on behalf of compiler
 118       return;
 119     }
 120     if (selected_method->method_holder()->is_not_initialized()) {
 121       // 'is_not_initialized' means not only '!is_initialized', but also that
 122       // initialization has not been started yet ('!being_initialized')
 123       // Do not force compilation of methods in uninitialized classes.
 124       // Note that doing this would throw an assert later,
 125       // in CompileBroker::compile_method.
 126       // We sometimes use the link resolver to do reflective lookups
 127       // even before classes are initialized.
 128       return;
 129     }
 130     CompileBroker::compile_method(selected_method, InvocationEntryBci,
 131                                   CompilationPolicy::policy()->initial_compile_level(),
 132                                   methodHandle(), 0, "must_be_compiled", CHECK);
 133   }
 134 }
 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 
 195 
 196 //------------------------------------------------------------------------------------------------------------------------
 197 // Klass resolution
 198 
 199 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
 200   if (!Reflection::verify_class_access(ref_klass(),
 201                                        sel_klass(),
 202                                        true)) {
 203     ResourceMark rm(THREAD);
 204     Exceptions::fthrow(
 205       THREAD_AND_LOCATION,
 206       vmSymbols::java_lang_IllegalAccessError(),
 207       "tried to access class %s from class %s",
 208       sel_klass->external_name(),
 209       ref_klass->external_name()
 210     );
 211     return;
 212   }
 213 }
 214 
 215 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) {
 216   Klass* result_oop = pool->klass_ref_at(index, CHECK);
 217   result = KlassHandle(THREAD, result_oop);
 218 }
 219 







 220 //------------------------------------------------------------------------------------------------------------------------
 221 // Method resolution
 222 //
 223 // According to JVM spec. $5.4.3c & $5.4.3d
 224 
 225 void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
 226   Method* result_oop = klass->uncached_lookup_method(name, signature);
 227   if (EnableInvokeDynamic && result_oop != NULL) {
 228     vmIntrinsics::ID iid = result_oop->intrinsic_id();
 229     if (MethodHandles::is_signature_polymorphic(iid)) {
 230       // Do not link directly to these.  The VM must produce a synthetic one using lookup_polymorphic_method.
 231       return;
 232     }
 233   }
 234   result = methodHandle(THREAD, result_oop);
 235 }
 236 
 237 // returns first instance method
 238 void LinkResolver::lookup_instance_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
 239   Method* result_oop = klass->uncached_lookup_method(name, signature);


 390                                        resolved_klass(),
 391                                        sel_klass(),
 392                                        flags,
 393                                        true)) {
 394     ResourceMark rm(THREAD);
 395     Exceptions::fthrow(
 396       THREAD_AND_LOCATION,
 397       vmSymbols::java_lang_IllegalAccessError(),
 398       "tried to access method %s.%s%s from class %s",
 399       sel_klass->external_name(),
 400       sel_method->name()->as_C_string(),
 401       sel_method->signature()->as_C_string(),
 402       ref_klass->external_name()
 403     );
 404     return;
 405   }
 406 }
 407 
 408 void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass,
 409                                              Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) {
 410   // This method is used only in C2 from InlineTree::ok_to_inline (via ciMethod::check_call),
 411   // and is only used under -Xcomp or -XX:CompileTheWorld.
 412   // It appears to fail when applied to an invokeinterface call site.
 413   // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
 414 
 415   // resolve klass
 416   if (code == Bytecodes::_invokedynamic) {
 417     resolved_klass = SystemDictionary::MethodHandle_klass();
 418     Symbol* method_name = vmSymbols::invoke_name();
 419     Symbol* method_signature = pool->signature_ref_at(index);
 420     KlassHandle  current_klass(THREAD, pool->pool_holder());
 421     resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK);
 422     return;
 423   }
 424 
 425   resolve_klass(resolved_klass, pool, index, CHECK);
 426 
 427   Symbol*  method_name       = pool->name_ref_at(index);
 428   Symbol*  method_signature  = pool->signature_ref_at(index);
 429   KlassHandle  current_klass(THREAD, pool->pool_holder());
 430 
 431   if (pool->has_preresolution()
 432       || (resolved_klass() == SystemDictionary::MethodHandle_klass() &&
 433           MethodHandles::is_signature_polymorphic_name(resolved_klass(), method_name))) {


 614                                              fieldDescriptor& fd,
 615                                              TRAPS) {
 616   if (!Reflection::verify_field_access(ref_klass(),
 617                                        resolved_klass(),
 618                                        sel_klass(),
 619                                        fd.access_flags(),
 620                                        true)) {
 621     ResourceMark rm(THREAD);
 622     Exceptions::fthrow(
 623       THREAD_AND_LOCATION,
 624       vmSymbols::java_lang_IllegalAccessError(),
 625       "tried to access field %s.%s from class %s",
 626       sel_klass->external_name(),
 627       fd.name()->as_C_string(),
 628       ref_klass->external_name()
 629     );
 630     return;
 631   }
 632 }
 633 
 634 void LinkResolver::resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) {
 635   // Load these early in case the resolve of the containing klass fails
 636   Symbol* field = pool->name_ref_at(index);
 637   Symbol* sig   = pool->signature_ref_at(index);
 638 
 639   // resolve specified klass
 640   KlassHandle resolved_klass;
 641   resolve_klass(resolved_klass, pool, index, CHECK);
 642 
 643   KlassHandle  current_klass(THREAD, pool->pool_holder());
 644   resolve_field(result, resolved_klass, field, sig, current_klass, byte, true, true, CHECK);
 645 }
 646 
 647 void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass, Symbol* field, Symbol* sig,
 648                                  KlassHandle current_klass, Bytecodes::Code byte, bool check_access, bool initialize_class,
 649                                  TRAPS) {
 650   assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic ||
 651          byte == Bytecodes::_getfield  || byte == Bytecodes::_putfield  ||
 652          (byte == Bytecodes::_nop && !check_access), "bad field access bytecode");
 653 
 654   bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
 655   bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic);
 656 










 657   // Check if there's a resolved klass containing the field
 658   if (resolved_klass.is_null()) {
 659     ResourceMark rm(THREAD);
 660     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
 661   }
 662 
 663   // Resolve instance field

 664   KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
 665   // check if field exists; i.e., if a klass containing the field def has been selected
 666   if (sel_klass.is_null()) {
 667     ResourceMark rm(THREAD);
 668     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
 669   }
 670 
 671   if (!check_access)
 672     // Access checking may be turned off when calling from within the VM.
 673     return;
 674 
 675   // check access
 676   check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK);

 677 
 678   // check for errors
 679   if (is_static != fd.is_static()) {
 680     ResourceMark rm(THREAD);
 681     char msg[200];
 682     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     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
 684   }
 685 
 686   // Final fields can only be accessed from its own class.
 687   if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
 688     THROW(vmSymbols::java_lang_IllegalAccessError());
 689   }
 690 
 691   // initialize resolved_klass if necessary
 692   // note 1: the klass which declared the field must be initialized (i.e, sel_klass)
 693   //         according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99)
 694   //
 695   // note 2: we don't want to force initialization if we are just checking
 696   //         if the field access is legal; e.g., during compilation
 697   if (is_static && initialize_class) {
 698     sel_klass->initialize(CHECK);
 699   }
 700 
 701   if (sel_klass() != current_klass()) {
 702     HandleMark hm(THREAD);
 703     Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader());
 704     Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader());

 705     {
 706       ResourceMark rm(THREAD);
 707       Symbol* failed_type_symbol =
 708         SystemDictionary::check_signature_loaders(sig,
 709                                                   ref_loader, sel_loader,
 710                                                   false,
 711                                                   CHECK);
 712       if (failed_type_symbol != NULL) {
 713         const char* msg = "loader constraint violation: when resolving field"
 714           " \"%s\" the class loader (instance of %s) of the referring class, "
 715           "%s, and the class loader (instance of %s) for the field's resolved "
 716           "type, %s, have different Class objects for that type";
 717         char* field_name = field->as_C_string();
 718         const char* loader1 = SystemDictionary::loader_name(ref_loader());
 719         char* sel = InstanceKlass::cast(sel_klass())->name()->as_C_string();
 720         const char* loader2 = SystemDictionary::loader_name(sel_loader());
 721         char* failed_type_name = failed_type_symbol->as_C_string();
 722         size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1) +
 723           strlen(sel) + strlen(loader2) + strlen(failed_type_name) + 1;
 724         char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
 725         jio_snprintf(buf, buflen, msg, field_name, loader1, sel, loader2,
 726                      failed_type_name);
 727         THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
 728       }
 729     }
 730   }
 731 
 732   // return information. note that the klass is set to the actual klass containing the
 733   // field, otherwise access of static fields in superclasses will not work.



 734 }
 735 
 736 
 737 //------------------------------------------------------------------------------------------------------------------------
 738 // Invoke resolution
 739 //
 740 // Naming conventions:
 741 //
 742 // resolved_method    the specified method (i.e., static receiver specified via constant pool index)
 743 // sel_method         the selected method  (selected via run-time lookup; e.g., based on dynamic receiver class)
 744 // resolved_klass     the specified klass  (i.e., specified via constant pool index)
 745 // recv_klass         the receiver klass
 746 
 747 
 748 void LinkResolver::resolve_static_call(CallInfo& result, KlassHandle& resolved_klass, Symbol* method_name,
 749                                        Symbol* method_signature, KlassHandle current_klass,
 750                                        bool check_access, bool initialize_class, TRAPS) {
 751   methodHandle resolved_method;
 752   linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
 753   resolved_klass = KlassHandle(THREAD, resolved_method->method_holder());


 941 void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
 942                                                   methodHandle resolved_method,
 943                                                   KlassHandle resolved_klass,
 944                                                   Handle recv,
 945                                                   KlassHandle recv_klass,
 946                                                   bool check_null_and_abstract,
 947                                                   TRAPS) {
 948 
 949   // setup default return values
 950   int vtable_index = Method::invalid_vtable_index;
 951   methodHandle selected_method;
 952 
 953   assert(recv.is_null() || recv->is_oop(), "receiver is not an oop");
 954 
 955   // runtime method resolution
 956   if (check_null_and_abstract && recv.is_null()) { // check if receiver exists
 957     THROW(vmSymbols::java_lang_NullPointerException());
 958   }
 959 
 960   // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s




 961   // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since
 962   // a missing receiver might result in a bogus lookup.
 963   assert(resolved_method->method_holder()->is_linked(), "must be linked");
 964 
 965   // do lookup based on receiver klass using the vtable index
 966   if (resolved_method->method_holder()->is_interface()) { // miranda method
 967     vtable_index = vtable_index_of_miranda_method(resolved_klass,
 968                            resolved_method->name(),
 969                            resolved_method->signature(), CHECK);
 970 
 971     assert(vtable_index >= 0 , "we should have valid vtable index at this point");
 972 
 973     InstanceKlass* inst = InstanceKlass::cast(recv_klass());
 974     selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
 975   } else {
 976     // at this point we are sure that resolved_method is virtual and not
 977     // a miranda method; therefore, it must have a valid vtable index.
 978     assert(!resolved_method->has_itable_index(), "");
 979     vtable_index = resolved_method->vtable_index();
 980     // We could get a negative vtable_index for final methods,
 981     // because as an optimization they are they are never put in the vtable,
 982     // unless they override an existing method.
 983     // If we do get a negative, it means the resolved method is the the selected
 984     // method, and it can never be changed by an override.
 985     if (vtable_index == Method::nonvirtual_vtable_index) {
 986       assert(resolved_method->can_be_statically_bound(), "cannot override this method");
 987       selected_method = resolved_method;
 988     } else {
 989       // recv_klass might be an arrayKlassOop but all vtables start at
 990       // the same place. The cast is to avoid virtual call and assertion.
 991       InstanceKlass* inst = (InstanceKlass*)recv_klass();
 992       selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
 993     }
 994   }
 995   if (selected_method.is_null() && !check_null_and_abstract) {
 996     selected_method = resolved_method;  // use a non-null placeholder
 997   }
 998 
 999   // check if method exists
1000   if (selected_method.is_null()) {
1001     ResourceMark rm(THREAD);
1002     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1003               Method::name_and_sig_as_C_string(resolved_klass(),
1004                                                       resolved_method->name(),
1005                                                       resolved_method->signature()));
1006   }
1007 
1008   // check if abstract
1009   if (check_null_and_abstract && selected_method->is_abstract()) {
1010     ResourceMark rm(THREAD);
1011     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1012               Method::name_and_sig_as_C_string(resolved_klass(),
1013                                                       selected_method->name(),
1014                                                       selected_method->signature()));
1015   }
1016 
1017   // setup result


1041                                                     Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS) {
1042   // check if receiver exists
1043   if (check_null_and_abstract && recv.is_null()) {
1044     THROW(vmSymbols::java_lang_NullPointerException());
1045   }
1046 
1047   // check if receiver klass implements the resolved interface
1048   if (!recv_klass->is_subtype_of(resolved_klass())) {
1049     ResourceMark rm(THREAD);
1050     char buf[200];
1051     jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
1052                  recv_klass()->external_name(),
1053                  resolved_klass()->external_name());
1054     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1055   }
1056   // do lookup based on receiver klass
1057   methodHandle sel_method;
1058   lookup_instance_method_in_klasses(sel_method, recv_klass,
1059             resolved_method->name(),
1060             resolved_method->signature(), CHECK);
1061   if (sel_method.is_null() && !check_null_and_abstract) {
1062     sel_method = resolved_method;  // use a non-null placeholder
1063   }
1064   // check if method exists
1065   if (sel_method.is_null()) {
1066     ResourceMark rm(THREAD);
1067     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1068               Method::name_and_sig_as_C_string(recv_klass(),
1069                                                       resolved_method->name(),
1070                                                       resolved_method->signature()));
1071   }
1072   // check access
1073   if (sel_method->method_holder()->is_interface()) {
1074     // Method holder is an interface. Throw Illegal Access Error if sel_method
1075     // is neither public nor private.
1076     if (!(sel_method->is_public() || sel_method->is_private())) {
1077       ResourceMark rm(THREAD);
1078       THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
1079                 Method::name_and_sig_as_C_string(recv_klass(),
1080                                                  sel_method->name(),
1081                                                  sel_method->signature()));
1082     }
1083   }
1084   else {
1085     // Method holder is a class. Throw Illegal Access Error if sel_method
1086     // is not public.
1087     if (!sel_method->is_public()) {
1088       ResourceMark rm(THREAD);
1089       THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
1090                 Method::name_and_sig_as_C_string(recv_klass(),
1091                                                  sel_method->name(),
1092                                                  sel_method->signature()));
1093     }
1094   }
1095   // check if abstract
1096   if (check_null_and_abstract && sel_method->is_abstract()) {
1097     ResourceMark rm(THREAD);
1098     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1099               Method::name_and_sig_as_C_string(recv_klass(),
1100                                                       sel_method->name(),
1101                                                       sel_method->signature()));
1102   }
1103   // setup result
1104   if (!resolved_method->has_itable_index()) {
1105     int vtable_index = resolved_method->vtable_index();
1106     assert(vtable_index == sel_method->vtable_index(), "sanity check");
1107     result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK);
1108     return;
1109   }
1110   int itable_index = resolved_method()->itable_index();
1111   result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK);
1112 }
1113 
1114 
1115 methodHandle LinkResolver::linktime_resolve_interface_method_or_null(
1116                                                  KlassHandle resolved_klass,
1117                                                  Symbol* method_name,
1118                                                  Symbol* method_signature,
1119                                                  KlassHandle current_klass,
1120                                                  bool check_access) {
1121   EXCEPTION_MARK;
1122   methodHandle method_result;
1123   linktime_resolve_interface_method(method_result, resolved_klass, method_name, method_signature, current_klass, check_access, THREAD);
1124   if (HAS_PENDING_EXCEPTION) {
1125     CLEAR_PENDING_EXCEPTION;
1126     return methodHandle();
1127   } else {
1128     return method_result;
1129   }
1130 }
1131 


1387     }
1388     if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) {
1389       // throw these guys, since they are already wrapped
1390       return;
1391     }
1392     if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
1393       // intercept only LinkageErrors which might have failed to wrap
1394       return;
1395     }
1396     // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS.
1397     Handle nested_exception(THREAD, PENDING_EXCEPTION);
1398     CLEAR_PENDING_EXCEPTION;
1399     THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
1400   }
1401   result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK);
1402 }
1403 
1404 //------------------------------------------------------------------------------------------------------------------------
1405 #ifndef PRODUCT
1406 
1407 void CallInfo::print() {
1408   ResourceMark rm;
1409   const char* kindstr = "unknown";
1410   switch (_call_kind) {
1411   case direct_call: kindstr = "direct"; break;
1412   case vtable_call: kindstr = "vtable"; break;
1413   case itable_call: kindstr = "itable"; break;
1414   }
1415   tty->print_cr("Call %s@%d %s", kindstr, _call_index,
1416                 _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string());
1417 }
1418 
1419 #endif
src/share/vm/interpreter/linkResolver.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File