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   _resolved_klass  = resolved_klass;
 142   _selected_klass  = resolved_klass;
 143   _resolved_method = resolved_method;
 144   _selected_method = resolved_method;
 145   // classify:
 146   CallKind kind = CallInfo::unknown_kind;
 147   int index = resolved_method->vtable_index();
 148   if (resolved_method->can_be_statically_bound()) {
 149     kind = CallInfo::direct_call;
 150   } else if (!resolved_method_holder->is_interface()) {
 151     // Could be an Object method inherited into an interface, but still a vtable call.
 152     kind = CallInfo::vtable_call;
 153   } else if (!resolved_klass->is_interface()) {
 154     // A miranda method.  Compute the vtable index.
 155     ResourceMark rm;
 156     klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable();
 157     index = vt->index_of_miranda(resolved_method->name(),
 158                                  resolved_method->signature());
 159     kind = CallInfo::vtable_call;
 160   } else {
 161     // A regular interface call.
 162     kind = CallInfo::itable_call;
 163     index = resolved_method->itable_index();
 164   }
 165   assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index));
 166   _call_kind  = kind;
 167   _call_index = index;
 168   _resolved_appendix = Handle();
 169   debug_only(verify());
 170 }
 171 
 172 #ifdef ASSERT
 173 void CallInfo::verify() {
 174   switch (call_kind()) {  // the meaning and allowed value of index depends on kind
 175   case CallInfo::direct_call:
 176     if (_call_index == Method::nonvirtual_vtable_index)  break;
 177     // else fall through to check vtable index:
 178   case CallInfo::vtable_call:
 179     assert(resolved_klass()->verify_vtable_index(_call_index), "");
 180     break;
 181   case CallInfo::itable_call:
 182     assert(resolved_method()->method_holder()->verify_itable_index(_call_index), "");
 183     break;
 184   case CallInfo::unknown_kind:
 185     assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set");
 186     break;
 187   default:
 188     ShouldNotReachHere();  // C++ constructor failure
 189   }
 190 }
 191 #endif //ASSERT
 192 
 193 
 194 
 195 //------------------------------------------------------------------------------------------------------------------------
 196 // Klass resolution
 197 
 198 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
 199   if (!Reflection::verify_class_access(ref_klass(),
 200                                        sel_klass(),
 201                                        true)) {
 202     ResourceMark rm(THREAD);
 203     Exceptions::fthrow(
 204       THREAD_AND_LOCATION,
 205       vmSymbols::java_lang_IllegalAccessError(),
 206       "tried to access class %s from class %s",
 207       sel_klass->external_name(),
 208       ref_klass->external_name()
 209     );
 210     return;
 211   }
 212 }
 213 
 214 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) {
 215   Klass* result_oop = pool->klass_ref_at(index, CHECK);
 216   result = KlassHandle(THREAD, result_oop);
 217 }
 218 







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


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


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










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

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

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

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



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


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




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


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


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