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