duke@435: /* never@2462: * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_CI_CIMETHOD_HPP stefank@2314: #define SHARE_VM_CI_CIMETHOD_HPP stefank@2314: stefank@2314: #include "ci/ciFlags.hpp" stefank@2314: #include "ci/ciInstanceKlass.hpp" stefank@2314: #include "ci/ciObject.hpp" stefank@2314: #include "ci/ciSignature.hpp" stefank@2314: #include "compiler/methodLiveness.hpp" stefank@2314: #include "prims/methodHandles.hpp" stefank@2314: #include "utilities/bitMap.hpp" stefank@2314: duke@435: class ciMethodBlocks; duke@435: class MethodLiveness; duke@435: class BitMap; duke@435: class Arena; duke@435: class BCEscapeAnalyzer; duke@435: duke@435: duke@435: // ciMethod duke@435: // duke@435: // This class represents a methodOop in the HotSpot virtual duke@435: // machine. duke@435: class ciMethod : public ciObject { duke@435: friend class CompileBroker; duke@435: CI_PACKAGE_ACCESS duke@435: friend class ciEnv; duke@435: friend class ciExceptionHandlerStream; twisti@1573: friend class ciBytecodeStream; twisti@1573: friend class ciMethodHandle; duke@435: duke@435: private: duke@435: // General method information. duke@435: ciFlags _flags; duke@435: ciSymbol* _name; duke@435: ciInstanceKlass* _holder; duke@435: ciSignature* _signature; duke@435: ciMethodData* _method_data; duke@435: ciMethodBlocks* _method_blocks; duke@435: duke@435: // Code attributes. duke@435: int _code_size; duke@435: int _max_stack; duke@435: int _max_locals; duke@435: vmIntrinsics::ID _intrinsic_id; duke@435: int _handler_count; duke@435: int _interpreter_invocation_count; duke@435: int _interpreter_throwout_count; duke@435: duke@435: bool _uses_monitors; duke@435: bool _balanced_monitors; iveresov@2138: bool _is_c1_compilable; iveresov@2138: bool _is_c2_compilable; duke@435: bool _can_be_statically_bound; duke@435: duke@435: // Lazy fields, filled in on demand duke@435: address _code; duke@435: ciExceptionHandler** _exception_handlers; duke@435: duke@435: // Optional liveness analyzer. duke@435: MethodLiveness* _liveness; twisti@2047: #if defined(COMPILER2) || defined(SHARK) kvn@2003: ciTypeFlow* _flow; kvn@2003: BCEscapeAnalyzer* _bcea; duke@435: #endif duke@435: duke@435: ciMethod(methodHandle h_m); twisti@3197: ciMethod(ciInstanceKlass* holder, ciSymbol* name, ciSymbol* signature, ciInstanceKlass* accessor); duke@435: duke@435: methodOop get_methodOop() const { duke@435: methodOop m = (methodOop)get_oop(); duke@435: assert(m != NULL, "illegal use of unloaded method"); duke@435: return m; duke@435: } duke@435: duke@435: oop loader() const { return _holder->loader(); } duke@435: duke@435: const char* type_string() { return "ciMethod"; } duke@435: duke@435: void print_impl(outputStream* st); duke@435: duke@435: void load_code(); duke@435: duke@435: void check_is_loaded() const { assert(is_loaded(), "not loaded"); } duke@435: iveresov@2349: bool ensure_method_data(methodHandle h_m); duke@435: duke@435: void code_at_put(int bci, Bytecodes::Code code) { duke@435: Bytecodes::check(code); duke@435: assert(0 <= bci && bci < code_size(), "valid bci"); duke@435: address bcp = _code + bci; duke@435: *bcp = code; duke@435: } duke@435: duke@435: public: duke@435: // Basic method information. duke@435: ciFlags flags() const { check_is_loaded(); return _flags; } duke@435: ciSymbol* name() const { return _name; } duke@435: ciInstanceKlass* holder() const { return _holder; } duke@435: ciMethodData* method_data(); iveresov@2349: ciMethodData* method_data_or_null(); duke@435: duke@435: // Signature information. duke@435: ciSignature* signature() const { return _signature; } duke@435: ciType* return_type() const { return _signature->return_type(); } duke@435: int arg_size_no_receiver() const { return _signature->size(); } never@2812: // Can only be used on loaded ciMethods never@2812: int arg_size() const { never@2812: check_is_loaded(); never@2812: return _signature->size() + (_flags.is_static() ? 0 : 1); never@2812: } never@2812: // Report the number of elements on stack when invoking this method. never@2812: // This is different than the regular arg_size because invokdynamic never@2812: // has an implicit receiver. never@2812: int invoke_arg_size(Bytecodes::Code code) const { never@2812: int arg_size = _signature->size(); never@2812: // Add a receiver argument, maybe: never@2812: if (code != Bytecodes::_invokestatic && never@2812: code != Bytecodes::_invokedynamic) { never@2812: arg_size++; never@2812: } never@2812: return arg_size; never@2812: } never@2812: duke@435: duke@435: // Method code and related information. duke@435: address code() { if (_code == NULL) load_code(); return _code; } duke@435: int code_size() const { check_is_loaded(); return _code_size; } duke@435: int max_stack() const { check_is_loaded(); return _max_stack; } duke@435: int max_locals() const { check_is_loaded(); return _max_locals; } duke@435: vmIntrinsics::ID intrinsic_id() const { check_is_loaded(); return _intrinsic_id; } duke@435: bool has_exception_handlers() const { check_is_loaded(); return _handler_count > 0; } duke@435: int exception_table_length() const { check_is_loaded(); return _handler_count; } duke@435: int interpreter_invocation_count() const { check_is_loaded(); return _interpreter_invocation_count; } duke@435: int interpreter_throwout_count() const { check_is_loaded(); return _interpreter_throwout_count; } duke@435: twisti@3097: // Code size for inlining decisions. twisti@3097: int code_size_for_inlining(); twisti@3097: iveresov@2138: int comp_level(); iveresov@2988: int highest_osr_comp_level(); iveresov@2138: duke@435: Bytecodes::Code java_code_at_bci(int bci) { duke@435: address bcp = code() + bci; never@2462: return Bytecodes::java_code_at(NULL, bcp); duke@435: } duke@435: BCEscapeAnalyzer *get_bcea(); duke@435: ciMethodBlocks *get_method_blocks(); duke@435: duke@435: bool has_linenumber_table() const; // length unknown until decompression duke@435: u_char* compressed_linenumber_table() const; // not preserved by gc duke@435: duke@435: int line_number_from_bci(int bci) const; duke@435: duke@435: // Runtime information. duke@435: int vtable_index(); twisti@2047: #ifdef SHARK twisti@2047: int itable_index(); twisti@2047: #endif // SHARK duke@435: address native_entry(); duke@435: address interpreter_entry(); duke@435: duke@435: // Analysis and profiling. duke@435: // duke@435: // Usage note: liveness_at_bci and init_vars should be wrapped in ResourceMarks. duke@435: bool uses_monitors() const { return _uses_monitors; } // this one should go away, it has a misleading name duke@435: bool has_monitor_bytecodes() const { return _uses_monitors; } duke@435: bool has_balanced_monitors(); duke@435: never@1426: // Returns a bitmap indicating which locals are required to be never@1426: // maintained as live for deopt. raw_liveness_at_bci is always the never@1426: // direct output of the liveness computation while liveness_at_bci never@1426: // may mark all locals as live to improve support for debugging Java never@1426: // code by maintaining the state of as many locals as possible. never@1426: MethodLivenessResult raw_liveness_at_bci(int bci); duke@435: MethodLivenessResult liveness_at_bci(int bci); duke@435: duke@435: // Get the interpreters viewpoint on oop liveness. MethodLiveness is duke@435: // conservative in the sense that it may consider locals to be live which duke@435: // cannot be live, like in the case where a local could contain an oop or duke@435: // a primitive along different paths. In that case the local must be duke@435: // dead when those paths merge. Since the interpreter's viewpoint is duke@435: // used when gc'ing an interpreter frame we need to use its viewpoint duke@435: // during OSR when loading the locals. duke@435: duke@435: BitMap live_local_oops_at_bci(int bci); duke@435: duke@435: #ifdef COMPILER1 duke@435: const BitMap bci_block_start(); duke@435: #endif duke@435: duke@435: ciTypeFlow* get_flow_analysis(); duke@435: ciTypeFlow* get_osr_flow_analysis(int osr_bci); // alternate entry point duke@435: ciCallProfile call_profile_at_bci(int bci); duke@435: int interpreter_call_site_count(int bci); duke@435: duke@435: // Given a certain calling environment, find the monomorphic target duke@435: // for the call. Return NULL if the call is not monomorphic in duke@435: // its calling environment. duke@435: ciMethod* find_monomorphic_target(ciInstanceKlass* caller, duke@435: ciInstanceKlass* callee_holder, duke@435: ciInstanceKlass* actual_receiver); duke@435: duke@435: // Given a known receiver klass, find the target for the call. duke@435: // Return NULL if the call has no target or is abstract. duke@435: ciMethod* resolve_invoke(ciKlass* caller, ciKlass* exact_receiver); duke@435: duke@435: // Find the proper vtable index to invoke this method. duke@435: int resolve_vtable_index(ciKlass* caller, ciKlass* receiver); duke@435: duke@435: // Compilation directives duke@435: bool will_link(ciKlass* accessing_klass, duke@435: ciKlass* declared_method_holder, duke@435: Bytecodes::Code bc); duke@435: bool should_exclude(); duke@435: bool should_inline(); duke@435: bool should_not_inline(); duke@435: bool should_print_assembly(); duke@435: bool break_at_execute(); duke@435: bool has_option(const char *option); duke@435: bool can_be_compiled(); duke@435: bool can_be_osr_compiled(int entry_bci); duke@435: void set_not_compilable(); duke@435: bool has_compiled_code(); iveresov@2138: int instructions_size(int comp_level = CompLevel_any); duke@435: void log_nmethod_identity(xmlStream* log); duke@435: bool is_not_reached(int bci); duke@435: bool was_executed_more_than(int times); duke@435: bool has_unloaded_classes_in_signature(); duke@435: bool is_klass_loaded(int refinfo_index, bool must_be_resolved) const; duke@435: bool check_call(int refinfo_index, bool is_static) const; iveresov@2349: bool ensure_method_data(); // make sure it exists in the VM also duke@435: int scale_count(int count, float prof_factor = 1.); // make MDO count commensurate with IIC twisti@1587: twisti@1587: // JSR 292 support twisti@1587: bool is_method_handle_invoke() const; twisti@1587: bool is_method_handle_adapter() const; jrose@1145: ciInstance* method_handle_type(); duke@435: duke@435: // What kind of ciObject is this? duke@435: bool is_method() { return true; } duke@435: duke@435: // Java access flags duke@435: bool is_public () const { return flags().is_public(); } duke@435: bool is_private () const { return flags().is_private(); } duke@435: bool is_protected () const { return flags().is_protected(); } duke@435: bool is_static () const { return flags().is_static(); } duke@435: bool is_final () const { return flags().is_final(); } duke@435: bool is_synchronized() const { return flags().is_synchronized(); } duke@435: bool is_native () const { return flags().is_native(); } duke@435: bool is_interface () const { return flags().is_interface(); } duke@435: bool is_abstract () const { return flags().is_abstract(); } duke@435: bool is_strict () const { return flags().is_strict(); } duke@435: duke@435: // Other flags duke@435: bool is_empty_method() const; duke@435: bool is_vanilla_constructor() const; duke@435: bool is_final_method() const { return is_final() || holder()->is_final(); } duke@435: bool has_loops () const; duke@435: bool has_jsrs () const; duke@435: bool is_accessor () const; duke@435: bool is_initializer () const; duke@435: bool can_be_statically_bound() const { return _can_be_statically_bound; } duke@435: duke@435: // Print the bytecodes of this method. duke@435: void print_codes_on(outputStream* st); duke@435: void print_codes() { duke@435: print_codes_on(tty); duke@435: } duke@435: void print_codes_on(int from, int to, outputStream* st); duke@435: duke@435: // Print the name of this method in various incarnations. duke@435: void print_name(outputStream* st = tty); duke@435: void print_short_name(outputStream* st = tty); twisti@1573: twisti@1573: methodOop get_method_handle_target() { twisti@2806: KlassHandle receiver_limit; int flags = 0; twisti@2806: methodHandle m = MethodHandles::decode_method(get_oop(), receiver_limit, flags); twisti@2806: return m(); twisti@1573: } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_CI_CIMETHOD_HPP