< prev index next >

src/hotspot/share/interpreter/linkResolver.cpp

Print this page

  29 #include "classfile/javaClasses.hpp"
  30 #include "classfile/resolutionErrors.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #include "classfile/vmClasses.hpp"
  34 #include "classfile/vmSymbols.hpp"
  35 #include "compiler/compilationPolicy.hpp"
  36 #include "compiler/compileBroker.hpp"
  37 #include "gc/shared/collectedHeap.inline.hpp"
  38 #include "interpreter/bootstrapInfo.hpp"
  39 #include "interpreter/bytecode.hpp"
  40 #include "interpreter/interpreterRuntime.hpp"
  41 #include "interpreter/linkResolver.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logStream.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "oops/constantPool.hpp"
  46 #include "oops/cpCache.inline.hpp"
  47 #include "oops/instanceKlass.inline.hpp"
  48 #include "oops/klass.inline.hpp"
  49 #include "oops/method.hpp"
  50 #include "oops/objArrayKlass.hpp"
  51 #include "oops/objArrayOop.hpp"
  52 #include "oops/oop.inline.hpp"
  53 #include "prims/methodHandles.hpp"
  54 #include "runtime/fieldDescriptor.inline.hpp"
  55 #include "runtime/frame.inline.hpp"
  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/reflection.hpp"
  58 #include "runtime/safepointVerifiers.hpp"
  59 #include "runtime/signature.hpp"

  60 #include "runtime/thread.inline.hpp"
  61 #include "runtime/vmThread.hpp"
  62 
  63 //------------------------------------------------------------------------------------------------------------------------
  64 // Implementation of CallInfo
  65 
  66 
  67 void CallInfo::set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS) {
  68   int vtable_index = Method::nonvirtual_vtable_index;
  69   set_common(resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
  70 }
  71 
  72 
  73 void CallInfo::set_interface(Klass* resolved_klass,
  74                              const methodHandle& resolved_method,
  75                              const methodHandle& selected_method,
  76                              int itable_index, TRAPS) {
  77   // This is only called for interface methods. If the resolved_method
  78   // comes from java/lang/Object, it can be the subject of a virtual call, so
  79   // we should pick the vtable index from the resolved method.

 582              (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
 583              (same_module) ? "" : "; ",
 584              (same_module) ? "" : sel_klass->class_in_module_of_loader()
 585              );
 586 
 587     // For private access see if there was a problem with nest host
 588     // resolution, and if so report that as part of the message.
 589     if (sel_method->is_private()) {
 590       print_nest_host_error_on(&ss, ref_klass, sel_klass);
 591     }
 592 
 593     Exceptions::fthrow(THREAD_AND_LOCATION,
 594                        vmSymbols::java_lang_IllegalAccessError(),
 595                        "%s",
 596                        ss.as_string()
 597                        );
 598     return;
 599   }
 600 }
 601 










 602 Method* LinkResolver::resolve_method_statically(Bytecodes::Code code,
 603                                                 const constantPoolHandle& pool, int index, TRAPS) {
 604   // This method is used only
 605   // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call),
 606   // and
 607   // (2) in Bytecode_invoke::static_target
 608   // It appears to fail when applied to an invokeinterface call site.
 609   // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
 610   // resolve klass
 611   if (code == Bytecodes::_invokedynamic) {
 612     Klass* resolved_klass = vmClasses::MethodHandle_klass();
 613     Symbol* method_name = vmSymbols::invoke_name();
 614     Symbol* method_signature = pool->signature_ref_at(index);
 615     Klass*  current_klass = pool->pool_holder();
 616     LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass);
 617     return resolve_method(link_info, code, THREAD);
 618   }
 619 
 620   LinkInfo link_info(pool, index, methodHandle(), CHECK_NULL);
 621   Klass* resolved_klass = link_info.resolved_klass();

1061 
1062 void LinkResolver::resolve_static_call(CallInfo& result,
1063                                        const LinkInfo& link_info,
1064                                        bool initialize_class, TRAPS) {
1065   Method* resolved_method = linktime_resolve_static_method(link_info, CHECK);
1066 
1067   // The resolved class can change as a result of this resolution.
1068   Klass* resolved_klass = resolved_method->method_holder();
1069 
1070   // Initialize klass (this should only happen if everything is ok)
1071   if (initialize_class && resolved_klass->should_be_initialized()) {
1072     resolved_klass->initialize(CHECK);
1073     // Use updated LinkInfo to reresolve with resolved method holder
1074     LinkInfo new_info(resolved_klass, link_info.name(), link_info.signature(),
1075                       link_info.current_klass(),
1076                       link_info.check_access() ? LinkInfo::AccessCheck::required : LinkInfo::AccessCheck::skip,
1077                       link_info.check_loader_constraints() ? LinkInfo::LoaderConstraintCheck::required : LinkInfo::LoaderConstraintCheck::skip);
1078     resolved_method = linktime_resolve_static_method(new_info, CHECK);
1079   }
1080 








1081   // setup result
1082   result.set_static(resolved_klass, methodHandle(THREAD, resolved_method), CHECK);
1083 }
1084 
1085 // throws linktime exceptions
1086 Method* LinkResolver::linktime_resolve_static_method(const LinkInfo& link_info, TRAPS) {
1087 
1088   Klass* resolved_klass = link_info.resolved_klass();
1089   Method* resolved_method;
1090   if (!resolved_klass->is_interface()) {
1091     resolved_method = resolve_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
1092   } else {
1093     resolved_method = resolve_interface_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
1094   }
1095   assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier");
1096 
1097   // check if static
1098   if (!resolved_method->is_static()) {
1099     ResourceMark rm(THREAD);
1100     stringStream ss;

  29 #include "classfile/javaClasses.hpp"
  30 #include "classfile/resolutionErrors.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #include "classfile/vmClasses.hpp"
  34 #include "classfile/vmSymbols.hpp"
  35 #include "compiler/compilationPolicy.hpp"
  36 #include "compiler/compileBroker.hpp"
  37 #include "gc/shared/collectedHeap.inline.hpp"
  38 #include "interpreter/bootstrapInfo.hpp"
  39 #include "interpreter/bytecode.hpp"
  40 #include "interpreter/interpreterRuntime.hpp"
  41 #include "interpreter/linkResolver.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logStream.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "oops/constantPool.hpp"
  46 #include "oops/cpCache.inline.hpp"
  47 #include "oops/instanceKlass.inline.hpp"
  48 #include "oops/klass.inline.hpp"
  49 #include "oops/method.inline.hpp"
  50 #include "oops/objArrayKlass.hpp"
  51 #include "oops/objArrayOop.hpp"
  52 #include "oops/oop.inline.hpp"
  53 #include "prims/methodHandles.hpp"
  54 #include "runtime/fieldDescriptor.inline.hpp"
  55 #include "runtime/frame.inline.hpp"
  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/reflection.hpp"
  58 #include "runtime/safepointVerifiers.hpp"
  59 #include "runtime/signature.hpp"
  60 #include "runtime/sharedRuntime.hpp"
  61 #include "runtime/thread.inline.hpp"
  62 #include "runtime/vmThread.hpp"
  63 
  64 //------------------------------------------------------------------------------------------------------------------------
  65 // Implementation of CallInfo
  66 
  67 
  68 void CallInfo::set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS) {
  69   int vtable_index = Method::nonvirtual_vtable_index;
  70   set_common(resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
  71 }
  72 
  73 
  74 void CallInfo::set_interface(Klass* resolved_klass,
  75                              const methodHandle& resolved_method,
  76                              const methodHandle& selected_method,
  77                              int itable_index, TRAPS) {
  78   // This is only called for interface methods. If the resolved_method
  79   // comes from java/lang/Object, it can be the subject of a virtual call, so
  80   // we should pick the vtable index from the resolved method.

 583              (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
 584              (same_module) ? "" : "; ",
 585              (same_module) ? "" : sel_klass->class_in_module_of_loader()
 586              );
 587 
 588     // For private access see if there was a problem with nest host
 589     // resolution, and if so report that as part of the message.
 590     if (sel_method->is_private()) {
 591       print_nest_host_error_on(&ss, ref_klass, sel_klass);
 592     }
 593 
 594     Exceptions::fthrow(THREAD_AND_LOCATION,
 595                        vmSymbols::java_lang_IllegalAccessError(),
 596                        "%s",
 597                        ss.as_string()
 598                        );
 599     return;
 600   }
 601 }
 602 
 603 void LinkResolver::resolve_continuation_enter(CallInfo& callinfo, TRAPS) {
 604   Klass* resolved_klass = vmClasses::Continuation_klass();
 605   Symbol* method_name = vmSymbols::enter_name();
 606   Symbol* method_signature = vmSymbols::continuationEnter_signature();
 607   Klass*  current_klass = resolved_klass;
 608   LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass);
 609   Method* resolved_method = resolve_method(link_info, Bytecodes::_invokestatic, CHECK);
 610   callinfo.set_static(resolved_klass, methodHandle(THREAD, resolved_method), CHECK);
 611 }
 612 
 613 Method* LinkResolver::resolve_method_statically(Bytecodes::Code code,
 614                                                 const constantPoolHandle& pool, int index, TRAPS) {
 615   // This method is used only
 616   // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call),
 617   // and
 618   // (2) in Bytecode_invoke::static_target
 619   // It appears to fail when applied to an invokeinterface call site.
 620   // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
 621   // resolve klass
 622   if (code == Bytecodes::_invokedynamic) {
 623     Klass* resolved_klass = vmClasses::MethodHandle_klass();
 624     Symbol* method_name = vmSymbols::invoke_name();
 625     Symbol* method_signature = pool->signature_ref_at(index);
 626     Klass*  current_klass = pool->pool_holder();
 627     LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass);
 628     return resolve_method(link_info, code, THREAD);
 629   }
 630 
 631   LinkInfo link_info(pool, index, methodHandle(), CHECK_NULL);
 632   Klass* resolved_klass = link_info.resolved_klass();

1072 
1073 void LinkResolver::resolve_static_call(CallInfo& result,
1074                                        const LinkInfo& link_info,
1075                                        bool initialize_class, TRAPS) {
1076   Method* resolved_method = linktime_resolve_static_method(link_info, CHECK);
1077 
1078   // The resolved class can change as a result of this resolution.
1079   Klass* resolved_klass = resolved_method->method_holder();
1080 
1081   // Initialize klass (this should only happen if everything is ok)
1082   if (initialize_class && resolved_klass->should_be_initialized()) {
1083     resolved_klass->initialize(CHECK);
1084     // Use updated LinkInfo to reresolve with resolved method holder
1085     LinkInfo new_info(resolved_klass, link_info.name(), link_info.signature(),
1086                       link_info.current_klass(),
1087                       link_info.check_access() ? LinkInfo::AccessCheck::required : LinkInfo::AccessCheck::skip,
1088                       link_info.check_loader_constraints() ? LinkInfo::LoaderConstraintCheck::required : LinkInfo::LoaderConstraintCheck::skip);
1089     resolved_method = linktime_resolve_static_method(new_info, CHECK);
1090   }
1091 
1092   if (resolved_method->is_continuation_enter_intrinsic()) {
1093     if (!resolved_method->has_compiled_code()) {
1094       methodHandle mh(THREAD, resolved_method);
1095       // Generate a compiled form of the enterSpecial intrinsic.
1096       AdapterHandlerLibrary::create_native_wrapper(mh);
1097     }
1098   }
1099 
1100   // setup result
1101   result.set_static(resolved_klass, methodHandle(THREAD, resolved_method), CHECK);
1102 }
1103 
1104 // throws linktime exceptions
1105 Method* LinkResolver::linktime_resolve_static_method(const LinkInfo& link_info, TRAPS) {
1106 
1107   Klass* resolved_klass = link_info.resolved_klass();
1108   Method* resolved_method;
1109   if (!resolved_klass->is_interface()) {
1110     resolved_method = resolve_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
1111   } else {
1112     resolved_method = resolve_interface_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
1113   }
1114   assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier");
1115 
1116   // check if static
1117   if (!resolved_method->is_static()) {
1118     ResourceMark rm(THREAD);
1119     stringStream ss;
< prev index next >