Path: blob/master/src/hotspot/share/ci/ciMethod.hpp
40930 views
/*1* Copyright (c) 1999, 2021, 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_CI_CIMETHOD_HPP25#define SHARE_CI_CIMETHOD_HPP2627#include "ci/ciFlags.hpp"28#include "ci/ciInstanceKlass.hpp"29#include "ci/ciObject.hpp"30#include "ci/ciSignature.hpp"31#include "classfile/vmIntrinsics.hpp"32#include "compiler/methodLiveness.hpp"33#include "compiler/compilerOracle.hpp"34#include "oops/method.hpp"35#include "runtime/handles.hpp"36#include "utilities/bitMap.hpp"3738class ciMethodBlocks;39class MethodLiveness;40class Arena;41class BCEscapeAnalyzer;42class InlineTree;43class xmlStream;4445// Whether profiling found an oop to be always, never or sometimes46// null47enum ProfilePtrKind {48ProfileAlwaysNull,49ProfileNeverNull,50ProfileMaybeNull51};5253// ciMethod54//55// This class represents a Method* in the HotSpot virtual56// machine.57class ciMethod : public ciMetadata {58friend class CompileBroker;59CI_PACKAGE_ACCESS60friend class ciEnv;61friend class ciExceptionHandlerStream;62friend class ciBytecodeStream;63friend class ciMethodHandle;64friend class ciReplay;65friend class InlineTree;6667private:68// General method information.69ciFlags _flags;70ciSymbol* _name;71ciInstanceKlass* _holder;72ciSignature* _signature;73ciMethodData* _method_data;74ciMethodBlocks* _method_blocks;7576// Code attributes.77int _code_size;78int _max_stack;79int _max_locals;80vmIntrinsicID _intrinsic_id;81int _handler_count;82int _nmethod_age;83int _interpreter_invocation_count;84int _interpreter_throwout_count;85int _instructions_size;86int _size_of_parameters;8788bool _uses_monitors;89bool _balanced_monitors;90bool _is_c1_compilable;91bool _is_c2_compilable;92bool _can_be_parsed;93bool _can_be_statically_bound;94bool _has_reserved_stack_access;95bool _is_overpass;9697// Lazy fields, filled in on demand98address _code;99ciExceptionHandler** _exception_handlers;100101// Optional liveness analyzer.102MethodLiveness* _liveness;103#if defined(COMPILER2)104ciTypeFlow* _flow;105BCEscapeAnalyzer* _bcea;106#endif107108ciMethod(const methodHandle& h_m, ciInstanceKlass* holder);109ciMethod(ciInstanceKlass* holder, ciSymbol* name, ciSymbol* signature, ciInstanceKlass* accessor);110111oop loader() const { return _holder->loader(); }112113const char* type_string() { return "ciMethod"; }114115void print_impl(outputStream* st);116117void load_code();118119bool ensure_method_data(const methodHandle& h_m);120121void code_at_put(int bci, Bytecodes::Code code) {122Bytecodes::check(code);123assert(0 <= bci && bci < code_size(), "valid bci");124address bcp = _code + bci;125*bcp = code;126}127128// Check bytecode and profile data collected are compatible129void assert_virtual_call_type_ok(int bci);130void assert_call_type_ok(int bci);131132// Check and update the profile counter in case of overflow133static int check_overflow(int c, Bytecodes::Code code);134135public:136void check_is_loaded() const { assert(is_loaded(), "not loaded"); }137138// Basic method information.139ciFlags flags() const { check_is_loaded(); return _flags; }140ciSymbol* name() const { return _name; }141ciInstanceKlass* holder() const { return _holder; }142ciMethodData* method_data();143ciMethodData* method_data_or_null();144145// Signature information.146ciSignature* signature() const { return _signature; }147ciType* return_type() const { return _signature->return_type(); }148int arg_size_no_receiver() const { return _signature->size(); }149// Can only be used on loaded ciMethods150int arg_size() const {151check_is_loaded();152return _signature->size() + (_flags.is_static() ? 0 : 1);153}154// Report the number of elements on stack when invoking the current method.155// If the method is loaded, arg_size() gives precise information about the156// number of stack elements (using the method's signature and its flags).157// However, if the method is not loaded, the number of stack elements must158// be determined differently, as the method's flags are not yet available.159// The invoke_arg_size() method assumes in that case that all bytecodes except160// invokestatic and invokedynamic have a receiver that is also pushed onto the161// stack by the caller of the current method.162int invoke_arg_size(Bytecodes::Code code) const {163if (is_loaded()) {164return arg_size();165} else {166int arg_size = _signature->size();167if (code != Bytecodes::_invokestatic &&168code != Bytecodes::_invokedynamic) {169arg_size++;170}171return arg_size;172}173}174175Method* get_Method() const {176Method* m = (Method*)_metadata;177assert(m != NULL, "illegal use of unloaded method");178return m;179}180181// Method code and related information.182address code() { if (_code == NULL) load_code(); return _code; }183int code_size() const { check_is_loaded(); return _code_size; }184int max_stack() const { check_is_loaded(); return _max_stack; }185int max_locals() const { check_is_loaded(); return _max_locals; }186vmIntrinsicID intrinsic_id() const { check_is_loaded(); return _intrinsic_id; }187bool has_exception_handlers() const { check_is_loaded(); return _handler_count > 0; }188int exception_table_length() const { check_is_loaded(); return _handler_count; }189int interpreter_invocation_count() const { check_is_loaded(); return _interpreter_invocation_count; }190int interpreter_throwout_count() const { check_is_loaded(); return _interpreter_throwout_count; }191int size_of_parameters() const { check_is_loaded(); return _size_of_parameters; }192int nmethod_age() const { check_is_loaded(); return _nmethod_age; }193194// Should the method be compiled with an age counter?195bool profile_aging() const;196197// Code size for inlining decisions.198int code_size_for_inlining();199200bool caller_sensitive() const { return get_Method()->caller_sensitive(); }201bool force_inline() const { return get_Method()->force_inline(); }202bool dont_inline() const { return get_Method()->dont_inline(); }203bool intrinsic_candidate() const { return get_Method()->intrinsic_candidate(); }204bool is_static_initializer() const { return get_Method()->is_static_initializer(); }205206bool check_intrinsic_candidate() const {207if (intrinsic_id() == vmIntrinsics::_blackhole) {208// This is the intrinsic without an associated method, so no intrinsic_candidate209// flag is set. The intrinsic is still correct.210return true;211}212return (CheckIntrinsics ? intrinsic_candidate() : true);213}214215int highest_osr_comp_level();216217Bytecodes::Code java_code_at_bci(int bci) {218address bcp = code() + bci;219return Bytecodes::java_code_at(NULL, bcp);220}221Bytecodes::Code raw_code_at_bci(int bci) {222address bcp = code() + bci;223return Bytecodes::code_at(NULL, bcp);224}225BCEscapeAnalyzer *get_bcea();226ciMethodBlocks *get_method_blocks();227228bool has_linenumber_table() const; // length unknown until decompression229230int line_number_from_bci(int bci) const;231232// Runtime information.233int vtable_index();234235// Analysis and profiling.236//237// Usage note: liveness_at_bci and init_vars should be wrapped in ResourceMarks.238bool has_monitor_bytecodes() const { return _uses_monitors; }239bool has_balanced_monitors();240241// Returns a bitmap indicating which locals are required to be242// maintained as live for deopt. raw_liveness_at_bci is always the243// direct output of the liveness computation while liveness_at_bci244// may mark all locals as live to improve support for debugging Java245// code by maintaining the state of as many locals as possible.246MethodLivenessResult raw_liveness_at_bci(int bci);247MethodLivenessResult liveness_at_bci(int bci);248249// Get the interpreters viewpoint on oop liveness. MethodLiveness is250// conservative in the sense that it may consider locals to be live which251// cannot be live, like in the case where a local could contain an oop or252// a primitive along different paths. In that case the local must be253// dead when those paths merge. Since the interpreter's viewpoint is254// used when gc'ing an interpreter frame we need to use its viewpoint255// during OSR when loading the locals.256257ResourceBitMap live_local_oops_at_bci(int bci);258259bool needs_clinit_barrier() const;260261#ifdef COMPILER1262const BitMap& bci_block_start();263#endif264265ciTypeFlow* get_flow_analysis();266ciTypeFlow* get_osr_flow_analysis(int osr_bci); // alternate entry point267ciCallProfile call_profile_at_bci(int bci);268269// Does type profiling provide any useful information at this point?270bool argument_profiled_type(int bci, int i, ciKlass*& type, ProfilePtrKind& ptr_kind);271bool parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind);272bool return_profiled_type(int bci, ciKlass*& type, ProfilePtrKind& ptr_kind);273274ciField* get_field_at_bci( int bci, bool &will_link);275ciMethod* get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature);276ciMethod* get_method_at_bci(int bci) {277bool ignored_will_link;278ciSignature* ignored_declared_signature;279return get_method_at_bci(bci, ignored_will_link, &ignored_declared_signature);280}281282ciKlass* get_declared_method_holder_at_bci(int bci);283284ciSignature* get_declared_signature_at_bci(int bci) {285bool ignored_will_link;286ciSignature* declared_signature;287get_method_at_bci(bci, ignored_will_link, &declared_signature);288assert(declared_signature != NULL, "cannot be null");289return declared_signature;290}291292// Given a certain calling environment, find the monomorphic target293// for the call. Return NULL if the call is not monomorphic in294// its calling environment.295ciMethod* find_monomorphic_target(ciInstanceKlass* caller,296ciInstanceKlass* callee_holder,297ciInstanceKlass* actual_receiver,298bool check_access = true);299300// Given a known receiver klass, find the target for the call.301// Return NULL if the call has no target or is abstract.302ciMethod* resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access = true, bool allow_abstract = false);303304// Find the proper vtable index to invoke this method.305int resolve_vtable_index(ciKlass* caller, ciKlass* receiver);306307bool has_option(enum CompileCommand option);308bool has_option_value(enum CompileCommand option, double& value);309bool can_be_compiled();310bool can_be_parsed() const { return _can_be_parsed; }311bool has_compiled_code();312void log_nmethod_identity(xmlStream* log);313bool is_not_reached(int bci);314bool was_executed_more_than(int times);315bool has_unloaded_classes_in_signature();316bool is_klass_loaded(int refinfo_index, bool must_be_resolved) const;317bool check_call(int refinfo_index, bool is_static) const;318bool ensure_method_data(); // make sure it exists in the VM also319MethodCounters* ensure_method_counters();320int instructions_size();321int scale_count(int count, float prof_factor = 1.); // make MDO count commensurate with IIC322323// Stack walking support324bool is_ignored_by_security_stack_walk() const;325326// JSR 292 support327bool is_method_handle_intrinsic() const;328bool is_compiled_lambda_form() const;329bool has_member_arg() const;330331// What kind of ciObject is this?332bool is_method() const { return true; }333334// Java access flags335bool is_public () const { return flags().is_public(); }336bool is_private () const { return flags().is_private(); }337bool is_protected () const { return flags().is_protected(); }338bool is_static () const { return flags().is_static(); }339bool is_final () const { return flags().is_final(); }340bool is_synchronized() const { return flags().is_synchronized(); }341bool is_native () const { return flags().is_native(); }342bool is_interface () const { return flags().is_interface(); }343bool is_abstract () const { return flags().is_abstract(); }344345// Other flags346bool is_final_method() const { return is_final() || holder()->is_final(); }347bool is_default_method() const { return !is_abstract() && !is_private() &&348holder()->is_interface(); }349bool is_overpass () const { check_is_loaded(); return _is_overpass; }350bool has_loops () const;351bool has_jsrs () const;352bool is_getter () const;353bool is_setter () const;354bool is_accessor () const;355bool is_initializer () const;356bool is_empty () const;357bool can_be_statically_bound() const { return _can_be_statically_bound; }358bool has_reserved_stack_access() const { return _has_reserved_stack_access; }359bool is_boxing_method() const;360bool is_unboxing_method() const;361bool is_vector_method() const;362bool is_object_initializer() const;363364bool can_be_statically_bound(ciInstanceKlass* context) const;365366// Replay data methods367void dump_name_as_ascii(outputStream* st);368void dump_replay_data(outputStream* st);369370// Print the bytecodes of this method.371void print_codes_on(outputStream* st);372void print_codes() {373print_codes_on(tty);374}375void print_codes_on(int from, int to, outputStream* st);376377// Print the name of this method in various incarnations.378void print_name(outputStream* st = tty);379void print_short_name(outputStream* st = tty);380381static bool is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method);382};383384#endif // SHARE_CI_CIMETHOD_HPP385386387