< prev index next >

src/hotspot/share/interpreter/linkResolver.hpp

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_INTERPRETER_LINKRESOLVER_HPP
  26 #define SHARE_INTERPRETER_LINKRESOLVER_HPP
  27 
  28 #include "interpreter/bootstrapInfo.hpp"
  29 #include "oops/method.hpp"
  30 
  31 // All the necessary definitions for run-time link resolution.
  32 
  33 // CallInfo provides all the information gathered for a particular
  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
  36 // that method. If the info is invalid, the link has not been resolved
  37 // successfully.
  38 
  39 class CallInfo : public StackObj {
  40  public:
  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,
  43   // and an invokeinterface instruction might be linked with any of the three options
  44   enum CallKind {
  45     direct_call,                        // jump into resolved_method (must be concrete)
  46     vtable_call,                        // select recv.klass.method_at_vtable(index)
  47     itable_call,                        // select recv.klass.method_at_itable(resolved_method.holder, index)
  48     unknown_kind = -1


  61   void set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS);
  62   void set_interface(Klass* resolved_klass, Klass* selected_klass,
  63                      const methodHandle& resolved_method,
  64                      const methodHandle& selected_method,
  65                      int itable_index, TRAPS);
  66   void set_virtual(Klass* resolved_klass, Klass* 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, TRAPS);
  72   void set_handle(Klass* resolved_klass,
  73                   const methodHandle& resolved_method,
  74                   Handle resolved_appendix, TRAPS);
  75   void set_common(Klass* resolved_klass, Klass* selected_klass,
  76                   const methodHandle& resolved_method,
  77                   const methodHandle& selected_method,
  78                   CallKind kind,
  79                   int index, TRAPS);
  80 
  81   friend class BootstrapInfo;
  82   friend class LinkResolver;
  83 
  84  public:
  85   CallInfo() {
  86 #ifndef PRODUCT
  87     _call_kind  = CallInfo::unknown_kind;
  88     _call_index = Method::garbage_vtable_index;
  89 #endif //PRODUCT
  90   }
  91 
  92   // utility to extract an effective CallInfo from a method and an optional receiver limit
  93   // does not queue the method for compilation.  This also creates a ResolvedMethodName
  94   // object for the resolved_method.
  95   CallInfo(Method* resolved_method, Klass* resolved_klass, TRAPS);
  96 
  97   Klass*  resolved_klass() const                 { return _resolved_klass; }
  98   Klass*  selected_klass() const                 { return _selected_klass; }
  99   methodHandle resolved_method() const           { return _resolved_method; }
 100   methodHandle selected_method() const           { return _selected_method; }
 101   Handle       resolved_appendix() const         { return _resolved_appendix; }


 167            AccessCheck check_access = needs_access_check,
 168            constantTag tag = JVM_CONSTANT_Invalid) :
 169     _name(name),
 170     _signature(signature), _resolved_klass(resolved_klass), _current_klass(current_method->method_holder()), _current_method(current_method),
 171     _check_access(check_access == needs_access_check), _tag(tag) {}
 172 
 173   // Case where we just find the method and don't check access against the current class
 174   LinkInfo(Klass* resolved_klass, Symbol*name, Symbol* signature) :
 175     _name(name),
 176     _signature(signature), _resolved_klass(resolved_klass), _current_klass(NULL), _current_method(methodHandle()),
 177     _check_access(false), _tag(JVM_CONSTANT_Invalid) {}
 178 
 179   // accessors
 180   Symbol* name() const               { return _name; }
 181   Symbol* signature() const          { return _signature; }
 182   Klass* resolved_klass() const      { return _resolved_klass; }
 183   Klass* current_klass() const       { return _current_klass; }
 184   methodHandle current_method() const { return _current_method; }
 185   constantTag tag() const            { return _tag; }
 186   bool check_access() const          { return _check_access; }

 187 
 188   void         print()  PRODUCT_RETURN;
 189 };
 190 
 191 // Link information for getfield/putfield & getstatic/putstatic bytecodes
 192 // is represented using a fieldDescriptor.
 193 
 194 // The LinkResolver is used to resolve constant-pool references at run-time.
 195 // It does all necessary link-time checks & throws exceptions if necessary.
 196 
 197 class LinkResolver: AllStatic {
 198   friend class klassVtable;
 199   friend class klassItable;
 200 
 201  private:
 202 
 203   static Method* lookup_method_in_klasses(const LinkInfo& link_info,
 204                                           bool checkpolymorphism,
 205                                           bool in_imethod_resolve);
 206   static Method* lookup_method_in_interfaces(const LinkInfo& link_info);


 296                                    Bytecodes::Code byte, TRAPS);
 297   static void resolve_field(fieldDescriptor& result, const LinkInfo& link_info,
 298                             Bytecodes::Code access_kind,
 299                             bool initialize_class, TRAPS);
 300 
 301   static void resolve_static_call   (CallInfo& result,
 302                                      const LinkInfo& link_info,
 303                                      bool initialize_klass, TRAPS);
 304   static void resolve_special_call  (CallInfo& result,
 305                                      Handle recv,
 306                                      const LinkInfo& link_info,
 307                                      TRAPS);
 308   static void resolve_virtual_call  (CallInfo& result, Handle recv, Klass* recv_klass,
 309                                      const LinkInfo& link_info,
 310                                      bool check_null_and_abstract, TRAPS);
 311   static void resolve_interface_call(CallInfo& result, Handle recv, Klass* recv_klass,
 312                                      const LinkInfo& link_info,
 313                                      bool check_null_and_abstract, TRAPS);
 314   static void resolve_handle_call   (CallInfo& result,
 315                                      const LinkInfo& link_info, TRAPS);
 316   static void resolve_dynamic_call  (CallInfo& result,
 317                                      BootstrapInfo& bootstrap_specifier, TRAPS);

 318 
 319   // same as above for compile-time resolution; but returns null handle instead of throwing
 320   // an exception on error also, does not initialize klass (i.e., no side effects)
 321   static methodHandle resolve_virtual_call_or_null  (Klass* receiver_klass,
 322                                                      const LinkInfo& link_info);
 323   static methodHandle resolve_interface_call_or_null(Klass* receiver_klass,
 324                                                      const LinkInfo& link_info);
 325   static methodHandle resolve_static_call_or_null   (const LinkInfo& link_info);
 326   static methodHandle resolve_special_call_or_null  (const LinkInfo& link_info);
 327 
 328   static int vtable_index_of_interface_method(Klass* klass, const methodHandle& resolved_method);
 329 
 330   // same as above for compile-time resolution; returns vtable_index if current_klass if linked
 331   static int resolve_virtual_vtable_index  (Klass* receiver_klass,
 332                                             const LinkInfo& link_info);
 333 
 334   // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
 335   static methodHandle linktime_resolve_virtual_method_or_null  (const LinkInfo& link_info);
 336   static methodHandle linktime_resolve_interface_method_or_null(const LinkInfo& link_info);
 337 




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_INTERPRETER_LINKRESOLVER_HPP
  26 #define SHARE_INTERPRETER_LINKRESOLVER_HPP
  27 

  28 #include "oops/method.hpp"
  29 
  30 // All the necessary definitions for run-time link resolution.
  31 
  32 // CallInfo provides all the information gathered for a particular
  33 // linked call site after resolving it. A link is any reference
  34 // made from within the bytecodes of a method to an object outside of
  35 // that method. If the info is invalid, the link has not been resolved
  36 // successfully.
  37 
  38 class CallInfo : public StackObj {
  39  public:
  40   // Ways that a method call might be selected (or not) based on receiver type.
  41   // Note that an invokevirtual instruction might be linked with no_dispatch,
  42   // and an invokeinterface instruction might be linked with any of the three options
  43   enum CallKind {
  44     direct_call,                        // jump into resolved_method (must be concrete)
  45     vtable_call,                        // select recv.klass.method_at_vtable(index)
  46     itable_call,                        // select recv.klass.method_at_itable(resolved_method.holder, index)
  47     unknown_kind = -1


  60   void set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS);
  61   void set_interface(Klass* resolved_klass, Klass* selected_klass,
  62                      const methodHandle& resolved_method,
  63                      const methodHandle& selected_method,
  64                      int itable_index, TRAPS);
  65   void set_virtual(Klass* resolved_klass, Klass* selected_klass,
  66                    const methodHandle& resolved_method,
  67                    const methodHandle& selected_method,
  68                    int vtable_index, TRAPS);
  69   void set_handle(const methodHandle& resolved_method,
  70                   Handle resolved_appendix, TRAPS);
  71   void set_handle(Klass* resolved_klass,
  72                   const methodHandle& resolved_method,
  73                   Handle resolved_appendix, TRAPS);
  74   void set_common(Klass* resolved_klass, Klass* selected_klass,
  75                   const methodHandle& resolved_method,
  76                   const methodHandle& selected_method,
  77                   CallKind kind,
  78                   int index, TRAPS);
  79 

  80   friend class LinkResolver;
  81 
  82  public:
  83   CallInfo() {
  84 #ifndef PRODUCT
  85     _call_kind  = CallInfo::unknown_kind;
  86     _call_index = Method::garbage_vtable_index;
  87 #endif //PRODUCT
  88   }
  89 
  90   // utility to extract an effective CallInfo from a method and an optional receiver limit
  91   // does not queue the method for compilation.  This also creates a ResolvedMethodName
  92   // object for the resolved_method.
  93   CallInfo(Method* resolved_method, Klass* resolved_klass, TRAPS);
  94 
  95   Klass*  resolved_klass() const                 { return _resolved_klass; }
  96   Klass*  selected_klass() const                 { return _selected_klass; }
  97   methodHandle resolved_method() const           { return _resolved_method; }
  98   methodHandle selected_method() const           { return _selected_method; }
  99   Handle       resolved_appendix() const         { return _resolved_appendix; }


 165            AccessCheck check_access = needs_access_check,
 166            constantTag tag = JVM_CONSTANT_Invalid) :
 167     _name(name),
 168     _signature(signature), _resolved_klass(resolved_klass), _current_klass(current_method->method_holder()), _current_method(current_method),
 169     _check_access(check_access == needs_access_check), _tag(tag) {}
 170 
 171   // Case where we just find the method and don't check access against the current class
 172   LinkInfo(Klass* resolved_klass, Symbol*name, Symbol* signature) :
 173     _name(name),
 174     _signature(signature), _resolved_klass(resolved_klass), _current_klass(NULL), _current_method(methodHandle()),
 175     _check_access(false), _tag(JVM_CONSTANT_Invalid) {}
 176 
 177   // accessors
 178   Symbol* name() const               { return _name; }
 179   Symbol* signature() const          { return _signature; }
 180   Klass* resolved_klass() const      { return _resolved_klass; }
 181   Klass* current_klass() const       { return _current_klass; }
 182   methodHandle current_method() const { return _current_method; }
 183   constantTag tag() const            { return _tag; }
 184   bool check_access() const          { return _check_access; }
 185   char* method_string() const;
 186 
 187   void         print()  PRODUCT_RETURN;
 188 };
 189 
 190 // Link information for getfield/putfield & getstatic/putstatic bytecodes
 191 // is represented using a fieldDescriptor.
 192 
 193 // The LinkResolver is used to resolve constant-pool references at run-time.
 194 // It does all necessary link-time checks & throws exceptions if necessary.
 195 
 196 class LinkResolver: AllStatic {
 197   friend class klassVtable;
 198   friend class klassItable;
 199 
 200  private:
 201 
 202   static Method* lookup_method_in_klasses(const LinkInfo& link_info,
 203                                           bool checkpolymorphism,
 204                                           bool in_imethod_resolve);
 205   static Method* lookup_method_in_interfaces(const LinkInfo& link_info);


 295                                    Bytecodes::Code byte, TRAPS);
 296   static void resolve_field(fieldDescriptor& result, const LinkInfo& link_info,
 297                             Bytecodes::Code access_kind,
 298                             bool initialize_class, TRAPS);
 299 
 300   static void resolve_static_call   (CallInfo& result,
 301                                      const LinkInfo& link_info,
 302                                      bool initialize_klass, TRAPS);
 303   static void resolve_special_call  (CallInfo& result,
 304                                      Handle recv,
 305                                      const LinkInfo& link_info,
 306                                      TRAPS);
 307   static void resolve_virtual_call  (CallInfo& result, Handle recv, Klass* recv_klass,
 308                                      const LinkInfo& link_info,
 309                                      bool check_null_and_abstract, TRAPS);
 310   static void resolve_interface_call(CallInfo& result, Handle recv, Klass* recv_klass,
 311                                      const LinkInfo& link_info,
 312                                      bool check_null_and_abstract, TRAPS);
 313   static void resolve_handle_call   (CallInfo& result,
 314                                      const LinkInfo& link_info, TRAPS);
 315   static void resolve_dynamic_call  (CallInfo& result, int pool_index, Handle bootstrap_specifier,
 316                                      Symbol* method_name, Symbol* method_signature,
 317                                      Klass* current_klass, TRAPS);
 318 
 319   // same as above for compile-time resolution; but returns null handle instead of throwing
 320   // an exception on error also, does not initialize klass (i.e., no side effects)
 321   static methodHandle resolve_virtual_call_or_null  (Klass* receiver_klass,
 322                                                      const LinkInfo& link_info);
 323   static methodHandle resolve_interface_call_or_null(Klass* receiver_klass,
 324                                                      const LinkInfo& link_info);
 325   static methodHandle resolve_static_call_or_null   (const LinkInfo& link_info);
 326   static methodHandle resolve_special_call_or_null  (const LinkInfo& link_info);
 327 
 328   static int vtable_index_of_interface_method(Klass* klass, const methodHandle& resolved_method);
 329 
 330   // same as above for compile-time resolution; returns vtable_index if current_klass if linked
 331   static int resolve_virtual_vtable_index  (Klass* receiver_klass,
 332                                             const LinkInfo& link_info);
 333 
 334   // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
 335   static methodHandle linktime_resolve_virtual_method_or_null  (const LinkInfo& link_info);
 336   static methodHandle linktime_resolve_interface_method_or_null(const LinkInfo& link_info);
 337 


< prev index next >