Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/linkResolver.hpp
32285 views
/*1* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_INTERPRETER_LINKRESOLVER_HPP25#define SHARE_VM_INTERPRETER_LINKRESOLVER_HPP2627#include "oops/method.hpp"28#include "utilities/top.hpp"2930// All the necessary definitions for run-time link resolution.3132// CallInfo provides all the information gathered for a particular33// linked call site after resolving it. A link is any reference34// made from within the bytecodes of a method to an object outside of35// that method. If the info is invalid, the link has not been resolved36// successfully.3738class CallInfo VALUE_OBJ_CLASS_SPEC {39public: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 options43enum CallKind {44direct_call, // jump into resolved_method (must be concrete)45vtable_call, // select recv.klass.method_at_vtable(index)46itable_call, // select recv.klass.method_at_itable(resolved_method.holder, index)47unknown_kind = -148};49private:50KlassHandle _resolved_klass; // static receiver klass, resolved from a symbolic reference51KlassHandle _selected_klass; // dynamic receiver class (same as static, or subklass)52methodHandle _resolved_method; // static target method53methodHandle _selected_method; // dynamic (actual) target method54CallKind _call_kind; // kind of call (static(=bytecode static/special +55// others inferred), vtable, itable)56int _call_index; // vtable or itable index of selected class method (if any)57Handle _resolved_appendix; // extra argument in constant pool (if CPCE::has_appendix)58Handle _resolved_method_type; // MethodType (for invokedynamic and invokehandle call sites)5960void set_static( KlassHandle resolved_klass, methodHandle resolved_method , TRAPS);61void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index , TRAPS);62void set_virtual( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index , TRAPS);63void set_handle( methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS);64void set_common( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, CallKind kind, int index, TRAPS);6566friend class LinkResolver;6768public:69CallInfo() {70#ifndef PRODUCT71_call_kind = CallInfo::unknown_kind;72_call_index = Method::garbage_vtable_index;73#endif //PRODUCT74}7576// utility to extract an effective CallInfo from a method and an optional receiver limit77// does not queue the method for compilation78CallInfo(Method* resolved_method, Klass* resolved_klass = NULL);7980KlassHandle resolved_klass() const { return _resolved_klass; }81KlassHandle selected_klass() const { return _selected_klass; }82methodHandle resolved_method() const { return _resolved_method; }83methodHandle selected_method() const { return _selected_method; }84Handle resolved_appendix() const { return _resolved_appendix; }85Handle resolved_method_type() const { return _resolved_method_type; }8687BasicType result_type() const { return selected_method()->result_type(); }88CallKind call_kind() const { return _call_kind; }89int call_index() const { return _call_index; }90int vtable_index() const {91// Even for interface calls the vtable index could be non-negative.92// See CallInfo::set_interface.93assert(has_vtable_index() || is_statically_bound(), "");94assert(call_kind() == vtable_call || call_kind() == direct_call, "");95// The returned value is < 0 if the call is statically bound.96// But, the returned value may be >= 0 even if the kind is direct_call.97// It is up to the caller to decide which way to go.98return _call_index;99}100int itable_index() const {101assert(call_kind() == itable_call, "");102// The returned value is always >= 0, a valid itable index.103return _call_index;104}105106// debugging107#ifdef ASSERT108bool has_vtable_index() const { return _call_index >= 0 && _call_kind != CallInfo::itable_call; }109bool is_statically_bound() const { return _call_index == Method::nonvirtual_vtable_index; }110#endif //ASSERT111void verify() PRODUCT_RETURN;112void print() PRODUCT_RETURN;113};114115// Link information for getfield/putfield & getstatic/putstatic bytecodes116// is represented using a fieldDescriptor.117118// The LinkResolver is used to resolve constant-pool references at run-time.119// It does all necessary link-time checks & throws exceptions if necessary.120121class LinkResolver: AllStatic {122friend class klassVtable;123friend class klassItable;124125private:126static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, bool checkpolymorphism, bool in_imethod_resolve, TRAPS);127static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);128static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);129static void lookup_polymorphic_method (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature,130KlassHandle current_klass, Handle *appendix_result_or_null, Handle *method_type_result, TRAPS);131132static void resolve_klass (KlassHandle& result, constantPoolHandle pool, int index, TRAPS);133134static void resolve_pool (KlassHandle& resolved_klass, Symbol*& method_name, Symbol*& method_signature, KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS);135136static 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);137static void check_method_loader_constraints(methodHandle& resolved_method, KlassHandle resolved_klass,138Symbol* method_name, Symbol* method_signature,139KlassHandle current_klass, const char* method_type, TRAPS);140static 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);141142static void linktime_resolve_static_method (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);143static void linktime_resolve_special_method (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);144static void linktime_resolve_virtual_method (methodHandle &resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature,KlassHandle current_klass, bool check_access, TRAPS);145static void linktime_resolve_interface_method (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);146147static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, Handle recv, bool check_access, TRAPS);148static void runtime_resolve_virtual_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS);149static void runtime_resolve_interface_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS);150151static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);152static void check_method_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, methodHandle sel_method, TRAPS);153154public:155// constant pool resolving156static void check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS);157158// static resolving calls (will not run any Java code); used only from Bytecode_invoke::static_target159static void resolve_method_statically(methodHandle& method_result, KlassHandle& klass_result,160Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS);161162// runtime/static resolving for fields163static void resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS);164static void resolve_field(fieldDescriptor& result, KlassHandle resolved_klass, Symbol* field_name, Symbol* field_signature,165KlassHandle current_klass, Bytecodes::Code access_kind, bool check_access, bool initialize_class, TRAPS);166167// source of access_kind codes:168static Bytecodes::Code field_access_kind(bool is_static, bool is_put) {169return (is_static170? (is_put ? Bytecodes::_putstatic : Bytecodes::_getstatic)171: (is_put ? Bytecodes::_putfield : Bytecodes::_getfield ));172}173174// runtime resolving:175// resolved_klass = specified class (i.e., static receiver class)176// current_klass = sending method holder (i.e., class containing the method containing the call being resolved)177static 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);178static void resolve_special_call (CallInfo& result, Handle recv, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS);179static 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);180static 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);181static void resolve_handle_call (CallInfo& result, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, TRAPS);182static void resolve_dynamic_call (CallInfo& result, Handle bootstrap_specifier, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, TRAPS);183184// same as above for compile-time resolution; but returns null handle instead of throwing an exception on error185// also, does not initialize klass (i.e., no side effects)186static 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);187static 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);188static methodHandle resolve_static_call_or_null (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access = true);189static methodHandle resolve_special_call_or_null (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access = true);190static int vtable_index_of_interface_method(KlassHandle klass, methodHandle resolved_method);191192// same as above for compile-time resolution; returns vtable_index if current_klass if linked193static int resolve_virtual_vtable_index (KlassHandle receiver_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass);194195// static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)196static methodHandle linktime_resolve_virtual_method_or_null (KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access);197static methodHandle linktime_resolve_interface_method_or_null(KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access);198199// runtime resolving from constant pool200static void resolve_invokestatic (CallInfo& result, constantPoolHandle pool, int index, TRAPS);201static void resolve_invokespecial (CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);202static void resolve_invokevirtual (CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);203static void resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS);204static void resolve_invokedynamic (CallInfo& result, constantPoolHandle pool, int index, TRAPS);205static void resolve_invokehandle (CallInfo& result, constantPoolHandle pool, int index, TRAPS);206207static void resolve_invoke (CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS);208};209210#endif // SHARE_VM_INTERPRETER_LINKRESOLVER_HPP211212213