src/share/vm/interpreter/linkResolver.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_INTERPRETER_LINKRESOLVER_HPP
aoqi@0 26 #define SHARE_VM_INTERPRETER_LINKRESOLVER_HPP
aoqi@0 27
aoqi@0 28 #include "oops/method.hpp"
aoqi@0 29 #include "utilities/top.hpp"
aoqi@0 30
aoqi@0 31 // All the necessary definitions for run-time link resolution.
aoqi@0 32
aoqi@0 33 // CallInfo provides all the information gathered for a particular
aoqi@0 34 // linked call site after resolving it. A link is any reference
aoqi@0 35 // made from within the bytecodes of a method to an object outside of
aoqi@0 36 // that method. If the info is invalid, the link has not been resolved
aoqi@0 37 // successfully.
aoqi@0 38
aoqi@0 39 class CallInfo VALUE_OBJ_CLASS_SPEC {
aoqi@0 40 public:
aoqi@0 41 // Ways that a method call might be selected (or not) based on receiver type.
aoqi@0 42 // Note that an invokevirtual instruction might be linked with no_dispatch,
aoqi@0 43 // and an invokeinterface instruction might be linked with any of the three options
aoqi@0 44 enum CallKind {
aoqi@0 45 direct_call, // jump into resolved_method (must be concrete)
aoqi@0 46 vtable_call, // select recv.klass.method_at_vtable(index)
aoqi@0 47 itable_call, // select recv.klass.method_at_itable(resolved_method.holder, index)
aoqi@0 48 unknown_kind = -1
aoqi@0 49 };
aoqi@0 50 private:
aoqi@0 51 KlassHandle _resolved_klass; // static receiver klass, resolved from a symbolic reference
aoqi@0 52 KlassHandle _selected_klass; // dynamic receiver class (same as static, or subklass)
aoqi@0 53 methodHandle _resolved_method; // static target method
aoqi@0 54 methodHandle _selected_method; // dynamic (actual) target method
aoqi@0 55 CallKind _call_kind; // kind of call (static(=bytecode static/special +
aoqi@0 56 // others inferred), vtable, itable)
aoqi@0 57 int _call_index; // vtable or itable index of selected class method (if any)
aoqi@0 58 Handle _resolved_appendix; // extra argument in constant pool (if CPCE::has_appendix)
aoqi@0 59 Handle _resolved_method_type; // MethodType (for invokedynamic and invokehandle call sites)
aoqi@0 60
aoqi@0 61 void set_static( KlassHandle resolved_klass, methodHandle resolved_method , TRAPS);
aoqi@0 62 void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index , TRAPS);
aoqi@0 63 void set_virtual( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index , TRAPS);
aoqi@0 64 void set_handle( methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS);
aoqi@0 65 void set_common( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, CallKind kind, int index, TRAPS);
aoqi@0 66
aoqi@0 67 friend class LinkResolver;
aoqi@0 68
aoqi@0 69 public:
aoqi@0 70 CallInfo() {
aoqi@0 71 #ifndef PRODUCT
aoqi@0 72 _call_kind = CallInfo::unknown_kind;
aoqi@0 73 _call_index = Method::garbage_vtable_index;
aoqi@0 74 #endif //PRODUCT
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 // utility to extract an effective CallInfo from a method and an optional receiver limit
aoqi@0 78 // does not queue the method for compilation
aoqi@0 79 CallInfo(Method* resolved_method, Klass* resolved_klass = NULL);
aoqi@0 80
aoqi@0 81 KlassHandle resolved_klass() const { return _resolved_klass; }
aoqi@0 82 KlassHandle selected_klass() const { return _selected_klass; }
aoqi@0 83 methodHandle resolved_method() const { return _resolved_method; }
aoqi@0 84 methodHandle selected_method() const { return _selected_method; }
aoqi@0 85 Handle resolved_appendix() const { return _resolved_appendix; }
aoqi@0 86 Handle resolved_method_type() const { return _resolved_method_type; }
aoqi@0 87
aoqi@0 88 BasicType result_type() const { return selected_method()->result_type(); }
aoqi@0 89 CallKind call_kind() const { return _call_kind; }
aoqi@0 90 int call_index() const { return _call_index; }
aoqi@0 91 int vtable_index() const {
aoqi@0 92 // Even for interface calls the vtable index could be non-negative.
aoqi@0 93 // See CallInfo::set_interface.
aoqi@0 94 assert(has_vtable_index() || is_statically_bound(), "");
aoqi@0 95 assert(call_kind() == vtable_call || call_kind() == direct_call, "");
aoqi@0 96 // The returned value is < 0 if the call is statically bound.
aoqi@0 97 // But, the returned value may be >= 0 even if the kind is direct_call.
aoqi@0 98 // It is up to the caller to decide which way to go.
aoqi@0 99 return _call_index;
aoqi@0 100 }
aoqi@0 101 int itable_index() const {
aoqi@0 102 assert(call_kind() == itable_call, "");
aoqi@0 103 // The returned value is always >= 0, a valid itable index.
aoqi@0 104 return _call_index;
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 // debugging
aoqi@0 108 #ifdef ASSERT
aoqi@0 109 bool has_vtable_index() const { return _call_index >= 0 && _call_kind != CallInfo::itable_call; }
aoqi@0 110 bool is_statically_bound() const { return _call_index == Method::nonvirtual_vtable_index; }
aoqi@0 111 #endif //ASSERT
aoqi@0 112 void verify() PRODUCT_RETURN;
aoqi@0 113 void print() PRODUCT_RETURN;
aoqi@0 114 };
aoqi@0 115
aoqi@0 116 // Link information for getfield/putfield & getstatic/putstatic bytecodes
aoqi@0 117 // is represented using a fieldDescriptor.
aoqi@0 118
aoqi@0 119 // The LinkResolver is used to resolve constant-pool references at run-time.
aoqi@0 120 // It does all necessary link-time checks & throws exceptions if necessary.
aoqi@0 121
aoqi@0 122 class LinkResolver: AllStatic {
aoqi@0 123 friend class klassVtable;
aoqi@0 124 friend class klassItable;
aoqi@0 125
aoqi@0 126 private:
aoqi@0 127 static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, bool checkpolymorphism, bool in_imethod_resolve, TRAPS);
aoqi@0 128 static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
aoqi@0 129 static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
aoqi@0 130 static void lookup_polymorphic_method (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature,
aoqi@0 131 KlassHandle current_klass, Handle *appendix_result_or_null, Handle *method_type_result, TRAPS);
aoqi@0 132
aoqi@0 133 static void resolve_klass (KlassHandle& result, constantPoolHandle pool, int index, TRAPS);
aoqi@0 134
aoqi@0 135 static void resolve_pool (KlassHandle& resolved_klass, Symbol*& method_name, Symbol*& method_signature, KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS);
aoqi@0 136
aoqi@0 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);
aoqi@0 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);
aoqi@0 139
aoqi@0 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);
aoqi@0 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);
aoqi@0 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);
aoqi@0 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);
aoqi@0 144
aoqi@0 145 static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
aoqi@0 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);
aoqi@0 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);
aoqi@0 148
aoqi@0 149 static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
aoqi@0 150 static void check_method_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, methodHandle sel_method, TRAPS);
aoqi@0 151
aoqi@0 152 public:
aoqi@0 153 // constant pool resolving
aoqi@0 154 static void check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS);
aoqi@0 155
aoqi@0 156 // static resolving calls (will not run any Java code); used only from Bytecode_invoke::static_target
aoqi@0 157 static void resolve_method_statically(methodHandle& method_result, KlassHandle& klass_result,
aoqi@0 158 Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS);
aoqi@0 159
aoqi@0 160 // runtime/static resolving for fields
aoqi@0 161 static void resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS);
aoqi@0 162 static void resolve_field(fieldDescriptor& result, KlassHandle resolved_klass, Symbol* field_name, Symbol* field_signature,
aoqi@0 163 KlassHandle current_klass, Bytecodes::Code access_kind, bool check_access, bool initialize_class, TRAPS);
aoqi@0 164
aoqi@0 165 // source of access_kind codes:
aoqi@0 166 static Bytecodes::Code field_access_kind(bool is_static, bool is_put) {
aoqi@0 167 return (is_static
aoqi@0 168 ? (is_put ? Bytecodes::_putstatic : Bytecodes::_getstatic)
aoqi@0 169 : (is_put ? Bytecodes::_putfield : Bytecodes::_getfield ));
aoqi@0 170 }
aoqi@0 171
aoqi@0 172 // runtime resolving:
aoqi@0 173 // resolved_klass = specified class (i.e., static receiver class)
aoqi@0 174 // current_klass = sending method holder (i.e., class containing the method containing the call being resolved)
aoqi@0 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);
aoqi@0 176 static void resolve_special_call (CallInfo& result, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);
aoqi@0 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);
aoqi@0 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);
aoqi@0 179 static void resolve_handle_call (CallInfo& result, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, TRAPS);
aoqi@0 180 static void resolve_dynamic_call (CallInfo& result, Handle bootstrap_specifier, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, TRAPS);
aoqi@0 181
aoqi@0 182 // same as above for compile-time resolution; but returns null handle instead of throwing an exception on error
aoqi@0 183 // also, does not initialize klass (i.e., no side effects)
aoqi@0 184 static methodHandle resolve_virtual_call_or_null (KlassHandle receiver_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass);
aoqi@0 185 static methodHandle resolve_interface_call_or_null(KlassHandle receiver_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass);
aoqi@0 186 static methodHandle resolve_static_call_or_null (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass);
aoqi@0 187 static methodHandle resolve_special_call_or_null (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass);
aoqi@0 188 static int vtable_index_of_interface_method(KlassHandle klass, methodHandle resolved_method);
aoqi@0 189
aoqi@0 190 // same as above for compile-time resolution; returns vtable_index if current_klass if linked
aoqi@0 191 static int resolve_virtual_vtable_index (KlassHandle receiver_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass);
aoqi@0 192
aoqi@0 193 // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
aoqi@0 194 static methodHandle linktime_resolve_virtual_method_or_null (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access);
aoqi@0 195 static methodHandle linktime_resolve_interface_method_or_null(KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access);
aoqi@0 196
aoqi@0 197 // runtime resolving from constant pool
aoqi@0 198 static void resolve_invokestatic (CallInfo& result, constantPoolHandle pool, int index, TRAPS);
aoqi@0 199 static void resolve_invokespecial (CallInfo& result, constantPoolHandle pool, int index, TRAPS);
aoqi@0 200 static void resolve_invokevirtual (CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);
aoqi@0 201 static void resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);
aoqi@0 202 static void resolve_invokedynamic (CallInfo& result, constantPoolHandle pool, int index, TRAPS);
aoqi@0 203 static void resolve_invokehandle (CallInfo& result, constantPoolHandle pool, int index, TRAPS);
aoqi@0 204
aoqi@0 205 static void resolve_invoke (CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS);
aoqi@0 206 };
aoqi@0 207
aoqi@0 208 #endif // SHARE_VM_INTERPRETER_LINKRESOLVER_HPP

mercurial