hotspot/src/share/vm/interpreter/linkResolver.hpp
changeset 31019 d05fcdd70109
parent 30223 82ab7b6b4927
child 33160 c59f1676d27e
equal deleted inserted replaced
30886:d2a0ec86d6ef 31019:d05fcdd70109
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    34 // linked call site after resolving it. A link is any reference
    34 // linked call site after resolving it. A link is any reference
    35 // made from within the bytecodes of a method to an object outside of
    35 // made from within the bytecodes of a method to an object outside of
    36 // that method. If the info is invalid, the link has not been resolved
    36 // that method. If the info is invalid, the link has not been resolved
    37 // successfully.
    37 // successfully.
    38 
    38 
    39 class CallInfo VALUE_OBJ_CLASS_SPEC {
    39 class CallInfo : public StackObj {
    40  public:
    40  public:
    41   // Ways that a method call might be selected (or not) based on receiver type.
    41   // Ways that a method call might be selected (or not) based on receiver type.
    42   // Note that an invokevirtual instruction might be linked with no_dispatch,
    42   // Note that an invokevirtual instruction might be linked with no_dispatch,
    43   // and an invokeinterface instruction might be linked with any of the three options
    43   // and an invokeinterface instruction might be linked with any of the three options
    44   enum CallKind {
    44   enum CallKind {
    56                                         //               others inferred), vtable, itable)
    56                                         //               others inferred), vtable, itable)
    57   int          _call_index;             // vtable or itable index of selected class method (if any)
    57   int          _call_index;             // vtable or itable index of selected class method (if any)
    58   Handle       _resolved_appendix;      // extra argument in constant pool (if CPCE::has_appendix)
    58   Handle       _resolved_appendix;      // extra argument in constant pool (if CPCE::has_appendix)
    59   Handle       _resolved_method_type;   // MethodType (for invokedynamic and invokehandle call sites)
    59   Handle       _resolved_method_type;   // MethodType (for invokedynamic and invokehandle call sites)
    60 
    60 
    61   void         set_static(   KlassHandle resolved_klass,                             methodHandle resolved_method                                                       , TRAPS);
    61   void set_static(KlassHandle resolved_klass, const methodHandle& resolved_method, TRAPS);
    62   void         set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index       , TRAPS);
    62   void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass,
    63   void         set_virtual(  KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index       , TRAPS);
    63                      const methodHandle& resolved_method,
    64   void         set_handle(                                                           methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS);
    64                      const methodHandle& selected_method,
    65   void         set_common(   KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, CallKind kind, int index, TRAPS);
    65                      int itable_index, TRAPS);
       
    66   void set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass,
       
    67                    const methodHandle& resolved_method,
       
    68                    const methodHandle& selected_method,
       
    69                    int vtable_index, TRAPS);
       
    70   void set_handle(const methodHandle& resolved_method,
       
    71                   Handle resolved_appendix, Handle resolved_method_type, TRAPS);
       
    72   void set_common(KlassHandle resolved_klass, KlassHandle selected_klass,
       
    73                   const methodHandle& resolved_method,
       
    74                   const methodHandle& selected_method,
       
    75                   CallKind kind,
       
    76                   int index, TRAPS);
    66 
    77 
    67   friend class LinkResolver;
    78   friend class LinkResolver;
    68 
    79 
    69  public:
    80  public:
    70   CallInfo() {
    81   CallInfo() {
   111 #endif //ASSERT
   122 #endif //ASSERT
   112   void         verify() PRODUCT_RETURN;
   123   void         verify() PRODUCT_RETURN;
   113   void         print()  PRODUCT_RETURN;
   124   void         print()  PRODUCT_RETURN;
   114 };
   125 };
   115 
   126 
       
   127 
       
   128 // Condensed information from constant pool to use to resolve the method or field.
       
   129 //   resolved_klass = specified class (i.e., static receiver class)
       
   130 //   current_klass  = sending method holder (i.e., class containing the method
       
   131 //                    containing the call being resolved)
       
   132 class LinkInfo : public StackObj {
       
   133   Symbol*     _name;            // extracted from JVM_CONSTANT_NameAndType
       
   134   Symbol*     _signature;
       
   135   KlassHandle _resolved_klass;  // class that the constant pool entry points to
       
   136   KlassHandle _current_klass;   // class that owns the constant pool
       
   137   bool        _check_access;
       
   138  public:
       
   139   LinkInfo(constantPoolHandle pool, int index, TRAPS);
       
   140   // Condensed information from other call sites within the vm.
       
   141   LinkInfo(KlassHandle resolved_klass, Symbol* name, Symbol* signature,
       
   142            KlassHandle current_klass, bool check_access = true) :
       
   143     _resolved_klass(resolved_klass),
       
   144     _name(name), _signature(signature), _current_klass(current_klass),
       
   145     _check_access(check_access) {}
       
   146 
       
   147   // accessors
       
   148   Symbol* name() const               { return _name; }
       
   149   Symbol* signature() const          { return _signature; }
       
   150   KlassHandle resolved_klass() const { return _resolved_klass; }
       
   151   KlassHandle current_klass() const  { return _current_klass; }
       
   152   bool check_access() const          { return _check_access; }
       
   153   char* method_string() const;
       
   154 
       
   155   void         print()  PRODUCT_RETURN;
       
   156 };
       
   157 
   116 // Link information for getfield/putfield & getstatic/putstatic bytecodes
   158 // Link information for getfield/putfield & getstatic/putstatic bytecodes
   117 // is represented using a fieldDescriptor.
   159 // is represented using a fieldDescriptor.
   118 
   160 
   119 // The LinkResolver is used to resolve constant-pool references at run-time.
   161 // The LinkResolver is used to resolve constant-pool references at run-time.
   120 // It does all necessary link-time checks & throws exceptions if necessary.
   162 // It does all necessary link-time checks & throws exceptions if necessary.
   122 class LinkResolver: AllStatic {
   164 class LinkResolver: AllStatic {
   123   friend class klassVtable;
   165   friend class klassVtable;
   124   friend class klassItable;
   166   friend class klassItable;
   125 
   167 
   126  private:
   168  private:
   127   static void lookup_method_in_klasses          (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, bool checkpolymorphism, bool in_imethod_resolve, TRAPS);
   169 
   128   static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
   170   static methodHandle lookup_method_in_klasses(const LinkInfo& link_info,
   129   static void lookup_method_in_interfaces       (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
   171                                                bool checkpolymorphism,
   130   static void lookup_polymorphic_method         (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature,
   172                                                bool in_imethod_resolve, TRAPS);
   131                                                  KlassHandle current_klass, Handle *appendix_result_or_null, Handle *method_type_result, TRAPS);
   173   static methodHandle lookup_method_in_interfaces(const LinkInfo& link_info, TRAPS);
   132 
   174   static methodHandle lookup_polymorphic_method(const LinkInfo& link_info,
   133   static void resolve_klass           (KlassHandle& result, constantPoolHandle  pool, int index, TRAPS);
   175                                                 Handle *appendix_result_or_null,
   134 
   176                                                 Handle *method_type_result, TRAPS);
   135   static void resolve_pool  (KlassHandle& resolved_klass, Symbol*& method_name, Symbol*& method_signature, KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS);
   177   // Not Linktime so doesn't take LinkInfo
   136 
   178   static methodHandle lookup_instance_method_in_klasses (
   137   static void resolve_interface_method(methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, bool nostatics, TRAPS);
   179                                        KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
   138   static void resolve_method          (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, bool require_methodref, TRAPS);
   180 
   139 
   181   // Similar loader constraint checking functions that throw
   140   static void linktime_resolve_static_method    (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);
   182   // LinkageError with descriptive message.
   141   static void linktime_resolve_special_method   (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);
   183   static void check_method_loader_constraints(const LinkInfo& link_info,
   142   static void linktime_resolve_virtual_method   (methodHandle &resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature,KlassHandle current_klass, bool check_access, TRAPS);
   184                                               const methodHandle& resolved_method,
   143   static void linktime_resolve_interface_method (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);
   185                                               const char* method_type, TRAPS);
   144 
   186   static void check_field_loader_constraints(Symbol* field, Symbol* sig,
   145   static void runtime_resolve_special_method    (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
   187                                              KlassHandle current_klass,
   146   static void runtime_resolve_virtual_method    (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS);
   188                                              KlassHandle sel_klass, TRAPS);
   147   static void runtime_resolve_interface_method  (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS);
   189 
   148 
   190   static methodHandle resolve_interface_method(const LinkInfo& link_info, bool nostatics, TRAPS);
   149   static void check_field_accessability   (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
   191   static methodHandle resolve_method          (const LinkInfo& link_info, bool require_methodref, TRAPS);
   150   static void check_method_accessability  (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, methodHandle sel_method, TRAPS);
   192 
   151 
   193   static methodHandle linktime_resolve_static_method    (const LinkInfo& link_info, TRAPS);
       
   194   static methodHandle linktime_resolve_special_method   (const LinkInfo& link_info, TRAPS);
       
   195   static methodHandle linktime_resolve_virtual_method   (const LinkInfo& link_info, TRAPS);
       
   196   static methodHandle linktime_resolve_interface_method (const LinkInfo& link_info, TRAPS);
       
   197 
       
   198   static void runtime_resolve_special_method    (CallInfo& result,
       
   199                                                  const methodHandle& resolved_method,
       
   200                                                  KlassHandle resolved_klass,
       
   201                                                  KlassHandle current_klass,
       
   202                                                  bool check_access, TRAPS);
       
   203   static void runtime_resolve_virtual_method    (CallInfo& result,
       
   204                                                  const methodHandle& resolved_method,
       
   205                                                  KlassHandle resolved_klass,
       
   206                                                  Handle recv,
       
   207                                                  KlassHandle recv_klass,
       
   208                                                  bool check_null_and_abstract, TRAPS);
       
   209   static void runtime_resolve_interface_method  (CallInfo& result,
       
   210                                                  const methodHandle& resolved_method,
       
   211                                                  KlassHandle resolved_klass,
       
   212                                                  Handle recv,
       
   213                                                  KlassHandle recv_klass,
       
   214                                                  bool check_null_and_abstract, TRAPS);
       
   215 
       
   216   static void check_field_accessability(KlassHandle ref_klass,
       
   217                                         KlassHandle resolved_klass,
       
   218                                         KlassHandle sel_klass,
       
   219                                         const fieldDescriptor& fd, TRAPS);
       
   220   static void check_method_accessability(KlassHandle ref_klass,
       
   221                                          KlassHandle resolved_klass,
       
   222                                          KlassHandle sel_klass,
       
   223                                          const methodHandle& sel_method, TRAPS);
       
   224 
       
   225   // runtime resolving from constant pool
       
   226   static void resolve_invokestatic   (CallInfo& result,
       
   227                                       constantPoolHandle pool, int index, TRAPS);
       
   228   static void resolve_invokespecial  (CallInfo& result,
       
   229                                       constantPoolHandle pool, int index, TRAPS);
       
   230   static void resolve_invokevirtual  (CallInfo& result, Handle recv,
       
   231                                       constantPoolHandle pool, int index, TRAPS);
       
   232   static void resolve_invokeinterface(CallInfo& result, Handle recv,
       
   233                                       constantPoolHandle pool, int index, TRAPS);
       
   234   static void resolve_invokedynamic  (CallInfo& result,
       
   235                                       constantPoolHandle pool, int index, TRAPS);
       
   236   static void resolve_invokehandle   (CallInfo& result,
       
   237                                       constantPoolHandle pool, int index, TRAPS);
   152  public:
   238  public:
   153   // constant pool resolving
   239   // constant pool resolving
   154   static void check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS);
   240   static void check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS);
   155 
   241 
   156   // static resolving calls (will not run any Java code); used only from Bytecode_invoke::static_target
   242   // static resolving calls (will not run any Java code);
   157   static void resolve_method_statically(methodHandle& method_result, KlassHandle& klass_result,
   243   // used only from Bytecode_invoke::static_target
   158                                         Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS);
   244   static methodHandle resolve_method_statically(Bytecodes::Code code,
   159 
   245                                                 constantPoolHandle pool,
   160   // runtime/static resolving for fields
   246                                                 int index, TRAPS);
   161   static void resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS);
   247 
   162   static void resolve_field(fieldDescriptor& result, KlassHandle resolved_klass, Symbol* field_name, Symbol* field_signature,
   248   static void resolve_field_access(fieldDescriptor& result,
   163                             KlassHandle current_klass, Bytecodes::Code access_kind, bool check_access, bool initialize_class, TRAPS);
   249                                    constantPoolHandle pool,
   164 
   250                                    int index, Bytecodes::Code byte, TRAPS);
   165   // source of access_kind codes:
   251   static void resolve_field(fieldDescriptor& result, const LinkInfo& link_info,
   166   static Bytecodes::Code field_access_kind(bool is_static, bool is_put) {
   252                             Bytecodes::Code access_kind,
   167     return (is_static
   253                             bool initialize_class, TRAPS);
   168             ? (is_put ? Bytecodes::_putstatic : Bytecodes::_getstatic)
   254 
   169             : (is_put ? Bytecodes::_putfield  : Bytecodes::_getfield ));
   255   static void resolve_static_call   (CallInfo& result,
   170   }
   256                                      const LinkInfo& link_info,
   171 
   257                                      bool initialize_klass, TRAPS);
   172   // runtime resolving:
   258   static void resolve_special_call  (CallInfo& result,
   173   //   resolved_klass = specified class (i.e., static receiver class)
   259                                      const LinkInfo& link_info,
   174   //   current_klass  = sending method holder (i.e., class containing the method containing the call being resolved)
   260                                      TRAPS);
   175   static void resolve_static_call   (CallInfo& result,              KlassHandle& resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, bool initialize_klass, TRAPS);
   261   static void resolve_virtual_call  (CallInfo& result, Handle recv, KlassHandle recv_klass,
   176   static void resolve_special_call  (CallInfo& result,              KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);
   262                                      const LinkInfo& link_info,
   177   static void resolve_virtual_call  (CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, bool check_null_and_abstract, TRAPS);
   263                                      bool check_null_and_abstract, TRAPS);
   178   static void resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, bool check_null_and_abstract, TRAPS);
   264   static void resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass,
   179   static void resolve_handle_call   (CallInfo& result,                                      KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, TRAPS);
   265                                      const LinkInfo& link_info,
   180   static void resolve_dynamic_call  (CallInfo& result,                                      Handle bootstrap_specifier, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, TRAPS);
   266                                      bool check_null_and_abstract, TRAPS);
   181 
   267   static void resolve_handle_call   (CallInfo& result,
   182   // same as above for compile-time resolution; but returns null handle instead of throwing an exception on error
   268                                      const LinkInfo& link_info, TRAPS);
   183   // also, does not initialize klass (i.e., no side effects)
   269   static void resolve_dynamic_call  (CallInfo& result, Handle bootstrap_specifier,
   184   static methodHandle resolve_virtual_call_or_null  (KlassHandle receiver_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access = true);
   270                                      Symbol* method_name, Symbol* method_signature,
   185   static methodHandle resolve_interface_call_or_null(KlassHandle receiver_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access = true);
   271                                      KlassHandle current_klass, TRAPS);
   186   static methodHandle resolve_static_call_or_null   (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access = true);
   272 
   187   static methodHandle resolve_special_call_or_null  (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access = true);
   273   // same as above for compile-time resolution; but returns null handle instead of throwing
   188   static int vtable_index_of_interface_method(KlassHandle klass, methodHandle resolved_method);
   274   // an exception on error also, does not initialize klass (i.e., no side effects)
       
   275   static methodHandle resolve_virtual_call_or_null  (KlassHandle receiver_klass,
       
   276                                                      const LinkInfo& link_info);
       
   277   static methodHandle resolve_interface_call_or_null(KlassHandle receiver_klass,
       
   278                                                      const LinkInfo& link_info);
       
   279   static methodHandle resolve_static_call_or_null   (const LinkInfo& link_info);
       
   280   static methodHandle resolve_special_call_or_null  (const LinkInfo& link_info);
       
   281 
       
   282   static int vtable_index_of_interface_method(KlassHandle klass, const methodHandle& resolved_method);
   189 
   283 
   190   // same as above for compile-time resolution; returns vtable_index if current_klass if linked
   284   // same as above for compile-time resolution; returns vtable_index if current_klass if linked
   191   static int resolve_virtual_vtable_index  (KlassHandle receiver_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass);
   285   static int resolve_virtual_vtable_index  (KlassHandle receiver_klass,
       
   286                                             const LinkInfo& link_info);
   192 
   287 
   193   // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
   288   // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
   194   static methodHandle linktime_resolve_virtual_method_or_null  (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access);
   289   static methodHandle linktime_resolve_virtual_method_or_null  (const LinkInfo& link_info);
   195   static methodHandle linktime_resolve_interface_method_or_null(KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access);
   290   static methodHandle linktime_resolve_interface_method_or_null(const LinkInfo& link_info);
   196 
   291 
   197   // runtime resolving from constant pool
   292   // runtime resolving from constant pool
   198   static void resolve_invokestatic   (CallInfo& result,              constantPoolHandle pool, int index, TRAPS);
   293   static void resolve_invoke(CallInfo& result, Handle recv,
   199   static void resolve_invokespecial  (CallInfo& result,              constantPoolHandle pool, int index, TRAPS);
   294                              constantPoolHandle pool, int index,
   200   static void resolve_invokevirtual  (CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);
   295                              Bytecodes::Code byte, TRAPS);
   201   static void resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);
   296  private:
   202   static void resolve_invokedynamic  (CallInfo& result,              constantPoolHandle pool, int index, TRAPS);
   297   static void trace_method_resolution(const char* prefix, KlassHandle klass,
   203   static void resolve_invokehandle   (CallInfo& result,              constantPoolHandle pool, int index, TRAPS);
   298                                       KlassHandle resolved_klass,
   204 
   299                                       const methodHandle& method) PRODUCT_RETURN;
   205   static void resolve_invoke         (CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS);
       
   206 };
   300 };
   207 
       
   208 #endif // SHARE_VM_INTERPRETER_LINKRESOLVER_HPP
   301 #endif // SHARE_VM_INTERPRETER_LINKRESOLVER_HPP