hotspot/src/share/vm/interpreter/linkResolver.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 2534 08dac9ce0cd7
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// All the necessary definitions for run-time link resolution.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// LinkInfo & its subclasses provide all the information gathered
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// for a particular link after resolving it. A link is any reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// made from within the bytecodes of a method to an object outside of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// that method. If the info is invalid, the link has not been resolved
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// successfully.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class LinkInfo VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Link information for getfield/putfield & getstatic/putstatic bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class FieldAccessInfo: public LinkInfo {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  KlassHandle  _klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  symbolHandle _name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  AccessFlags  _access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  int          _field_index;  // original index in the klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  int          _field_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  BasicType    _field_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  void         set(KlassHandle klass, symbolHandle name, int field_index, int field_offset,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                 BasicType field_type, AccessFlags access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  KlassHandle  klass() const                     { return _klass; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  symbolHandle name() const                      { return _name; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  int          field_index() const               { return _field_index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  int          field_offset() const              { return _field_offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  BasicType    field_type() const                { return _field_type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  AccessFlags  access_flags() const              { return _access_flags; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  void print()  PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// Link information for all calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
class CallInfo: public LinkInfo {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  KlassHandle  _resolved_klass;         // static receiver klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  KlassHandle  _selected_klass;         // dynamic receiver class (same as static, or subklass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  methodHandle _resolved_method;        // static target method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  methodHandle _selected_method;        // dynamic (actual) target method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  int          _vtable_index;           // vtable index of selected method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  void         set_static(   KlassHandle resolved_klass,                             methodHandle resolved_method                                                , TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  void         set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method                  , TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  void         set_virtual(  KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  void         set_common(   KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  friend class LinkResolver;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  KlassHandle  resolved_klass() const            { return _resolved_klass; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  KlassHandle  selected_klass() const            { return _selected_klass; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  methodHandle resolved_method() const           { return _resolved_method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  methodHandle selected_method() const           { return _selected_method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  BasicType    result_type() const               { return selected_method()->result_type(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  bool         has_vtable_index() const          { return _vtable_index >= 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  bool         is_statically_bound() const       { return _vtable_index == methodOopDesc::nonvirtual_vtable_index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  int          vtable_index() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    // Even for interface calls the vtable index could be non-negative.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    // See CallInfo::set_interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    assert(has_vtable_index() || is_statically_bound(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    return _vtable_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// The LinkResolver is used to resolve constant-pool references at run-time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
// It does all necessary link-time checks & throws exceptions if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
class LinkResolver: AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  static void lookup_method_in_klasses          (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  static void lookup_method_in_interfaces       (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  static int vtable_index_of_miranda_method(KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  static void resolve_klass           (KlassHandle& result, constantPoolHandle  pool, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  static void resolve_klass_no_update (KlassHandle& result, constantPoolHandle pool, int index, TRAPS); // no update of constantPool entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  static void resolve_pool  (KlassHandle& resolved_klass, symbolHandle& method_name, symbolHandle& method_signature, KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  static void resolve_interface_method(methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  static void resolve_method          (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  static void linktime_resolve_static_method    (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  static void linktime_resolve_special_method   (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  static void linktime_resolve_virtual_method   (methodHandle &resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature,KlassHandle current_klass, bool check_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  static void linktime_resolve_interface_method (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  static void runtime_resolve_special_method    (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  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);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  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);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static void check_field_accessability   (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  static void check_method_accessability  (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, methodHandle sel_method, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // constant pool resolving
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  static void check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // static resolving for all calls except interface calls
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  static void resolve_method          (methodHandle& method_result, KlassHandle& klass_result, constantPoolHandle pool, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  static void resolve_interface_method(methodHandle& method_result, KlassHandle& klass_result, constantPoolHandle pool, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // runtime/static resolving for fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  static void resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // takes an extra bool argument "update_pool" to decide whether to update the constantPool during klass resolution.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static void resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // runtime resolving:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  //   resolved_klass = specified class (i.e., static receiver class)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  //   current_klass  = sending method holder (i.e., class containing the method containing the call being resolved)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  static void resolve_static_call   (CallInfo& result,              KlassHandle& resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, bool initialize_klass, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static void resolve_special_call  (CallInfo& result,              KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  static void resolve_virtual_call  (CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, bool check_null_and_abstract, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  static void resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, bool check_null_and_abstract, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // same as above for compile-time resolution; but returns null handle instead of throwing an exception on error
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // also, does not initialize klass (i.e., no side effects)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  static methodHandle resolve_virtual_call_or_null  (KlassHandle receiver_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static methodHandle resolve_interface_call_or_null(KlassHandle receiver_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  static methodHandle resolve_static_call_or_null   (KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  static methodHandle resolve_special_call_or_null  (KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // same as above for compile-time resolution; returns vtable_index if current_klass if linked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  static int resolve_virtual_vtable_index  (KlassHandle receiver_klass, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  static methodHandle linktime_resolve_virtual_method_or_null  (KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  static methodHandle linktime_resolve_interface_method_or_null(KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // runtime resolving from constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  static void resolve_invokestatic   (CallInfo& result,              constantPoolHandle pool, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  static void resolve_invokespecial  (CallInfo& result,              constantPoolHandle pool, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  static void resolve_invokevirtual  (CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  static void resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  static void resolve_invoke         (CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
};