Path: blob/master/src/hotspot/share/code/nmethod.hpp
40931 views
/*1* Copyright (c) 1997, 2020, 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_CODE_NMETHOD_HPP25#define SHARE_CODE_NMETHOD_HPP2627#include "code/compiledMethod.hpp"2829class DepChange;30class DirectiveSet;31class DebugInformationRecorder;32class JvmtiThreadState;3334// nmethods (native methods) are the compiled code versions of Java methods.35//36// An nmethod contains:37// - header (the nmethod structure)38// [Relocation]39// - relocation information40// - constant part (doubles, longs and floats used in nmethod)41// - oop table42// [Code]43// - code body44// - exception handler45// - stub code46// [Debugging information]47// - oop array48// - data array49// - pcs50// [Exception handler table]51// - handler entry point array52// [Implicit Null Pointer exception table]53// - implicit null table array54// [Speculations]55// - encoded speculations array56// [JVMCINMethodData]57// - meta data for JVMCI compiled nmethod5859#if INCLUDE_JVMCI60class FailedSpeculation;61class JVMCINMethodData;62#endif6364class nmethod : public CompiledMethod {65friend class VMStructs;66friend class JVMCIVMStructs;67friend class NMethodSweeper;68friend class CodeCache; // scavengable oops69friend class JVMCINMethodData;7071private:72// Shared fields for all nmethod's73int _entry_bci; // != InvocationEntryBci if this nmethod is an on-stack replacement method7475// To support simple linked-list chaining of nmethods:76nmethod* _osr_link; // from InstanceKlass::osr_nmethods_head7778// STW two-phase nmethod root processing helpers.79//80// When determining liveness of a given nmethod to do code cache unloading,81// some collectors need to do different things depending on whether the nmethods82// need to absolutely be kept alive during root processing; "strong"ly reachable83// nmethods are known to be kept alive at root processing, but the liveness of84// "weak"ly reachable ones is to be determined later.85//86// We want to allow strong and weak processing of nmethods by different threads87// at the same time without heavy synchronization. Additional constraints are88// to make sure that every nmethod is processed a minimal amount of time, and89// nmethods themselves are always iterated at most once at a particular time.90//91// Note that strong processing work must be a superset of weak processing work92// for this code to work.93//94// We store state and claim information in the _oops_do_mark_link member, using95// the two LSBs for the state and the remaining upper bits for linking together96// nmethods that were already visited.97// The last element is self-looped, i.e. points to itself to avoid some special98// "end-of-list" sentinel value.99//100// _oops_do_mark_link special values:101//102// _oops_do_mark_link == NULL: the nmethod has not been visited at all yet, i.e.103// is Unclaimed.104//105// For other values, its lowest two bits indicate the following states of the nmethod:106//107// weak_request (WR): the nmethod has been claimed by a thread for weak processing108// weak_done (WD): weak processing has been completed for this nmethod.109// strong_request (SR): the nmethod has been found to need strong processing while110// being weak processed.111// strong_done (SD): strong processing has been completed for this nmethod .112//113// The following shows the _only_ possible progressions of the _oops_do_mark_link114// pointer.115//116// Given117// N as the nmethod118// X the current next value of _oops_do_mark_link119//120// Unclaimed (C)-> N|WR (C)-> X|WD: the nmethod has been processed weakly by121// a single thread.122// Unclaimed (C)-> N|WR (C)-> X|WD (O)-> X|SD: after weak processing has been123// completed (as above) another thread found that the nmethod needs strong124// processing after all.125// Unclaimed (C)-> N|WR (O)-> N|SR (C)-> X|SD: during weak processing another126// thread finds that the nmethod needs strong processing, marks it as such and127// terminates. The original thread completes strong processing.128// Unclaimed (C)-> N|SD (C)-> X|SD: the nmethod has been processed strongly from129// the beginning by a single thread.130//131// "|" describes the concatentation of bits in _oops_do_mark_link.132//133// The diagram also describes the threads responsible for changing the nmethod to134// the next state by marking the _transition_ with (C) and (O), which mean "current"135// and "other" thread respectively.136//137struct oops_do_mark_link; // Opaque data type.138139// States used for claiming nmethods during root processing.140static const uint claim_weak_request_tag = 0;141static const uint claim_weak_done_tag = 1;142static const uint claim_strong_request_tag = 2;143static const uint claim_strong_done_tag = 3;144145static oops_do_mark_link* mark_link(nmethod* nm, uint tag) {146assert(tag <= claim_strong_done_tag, "invalid tag %u", tag);147assert(is_aligned(nm, 4), "nmethod pointer must have zero lower two LSB");148return (oops_do_mark_link*)(((uintptr_t)nm & ~0x3) | tag);149}150151static uint extract_state(oops_do_mark_link* link) {152return (uint)((uintptr_t)link & 0x3);153}154155static nmethod* extract_nmethod(oops_do_mark_link* link) {156return (nmethod*)((uintptr_t)link & ~0x3);157}158159void oops_do_log_change(const char* state);160161static bool oops_do_has_weak_request(oops_do_mark_link* next) {162return extract_state(next) == claim_weak_request_tag;163}164165static bool oops_do_has_any_strong_state(oops_do_mark_link* next) {166return extract_state(next) >= claim_strong_request_tag;167}168169// Attempt Unclaimed -> N|WR transition. Returns true if successful.170bool oops_do_try_claim_weak_request();171172// Attempt Unclaimed -> N|SD transition. Returns the current link.173oops_do_mark_link* oops_do_try_claim_strong_done();174// Attempt N|WR -> X|WD transition. Returns NULL if successful, X otherwise.175nmethod* oops_do_try_add_to_list_as_weak_done();176177// Attempt X|WD -> N|SR transition. Returns the current link.178oops_do_mark_link* oops_do_try_add_strong_request(oops_do_mark_link* next);179// Attempt X|WD -> X|SD transition. Returns true if successful.180bool oops_do_try_claim_weak_done_as_strong_done(oops_do_mark_link* next);181182// Do the N|SD -> X|SD transition.183void oops_do_add_to_list_as_strong_done();184185// Sets this nmethod as strongly claimed (as part of N|SD -> X|SD and N|SR -> X|SD186// transitions).187void oops_do_set_strong_done(nmethod* old_head);188189static nmethod* volatile _oops_do_mark_nmethods;190oops_do_mark_link* volatile _oops_do_mark_link;191192// offsets for entry points193address _entry_point; // entry point with class check194address _verified_entry_point; // entry point without class check195address _osr_entry_point; // entry point for on stack replacement196197// Offsets for different nmethod parts198int _exception_offset;199// Offset of the unwind handler if it exists200int _unwind_handler_offset;201202int _consts_offset;203int _stub_offset;204int _oops_offset; // offset to where embedded oop table begins (inside data)205int _metadata_offset; // embedded meta data table206int _scopes_data_offset;207int _scopes_pcs_offset;208int _dependencies_offset;209int _native_invokers_offset;210int _handler_table_offset;211int _nul_chk_table_offset;212#if INCLUDE_JVMCI213int _speculations_offset;214int _jvmci_data_offset;215#endif216int _nmethod_end_offset;217218int code_offset() const { return (address) code_begin() - header_begin(); }219220// location in frame (offset for sp) that deopt can store the original221// pc during a deopt.222int _orig_pc_offset;223224int _compile_id; // which compilation made this nmethod225int _comp_level; // compilation level226227// protected by CodeCache_lock228bool _has_flushed_dependencies; // Used for maintenance of dependencies (CodeCache_lock)229230// used by jvmti to track if an event has been posted for this nmethod.231bool _unload_reported;232bool _load_reported;233234// Protected by CompiledMethod_lock235volatile signed char _state; // {not_installed, in_use, not_entrant, zombie, unloaded}236237#ifdef ASSERT238bool _oops_are_stale; // indicates that it's no longer safe to access oops section239#endif240241#if INCLUDE_RTM_OPT242// RTM state at compile time. Used during deoptimization to decide243// whether to restart collecting RTM locking abort statistic again.244RTMState _rtm_state;245#endif246247// Nmethod Flushing lock. If non-zero, then the nmethod is not removed248// and is not made into a zombie. However, once the nmethod is made into249// a zombie, it will be locked one final time if CompiledMethodUnload250// event processing needs to be done.251volatile jint _lock_count;252253// not_entrant method removal. Each mark_sweep pass will update254// this mark to current sweep invocation count if it is seen on the255// stack. An not_entrant method can be removed when there are no256// more activations, i.e., when the _stack_traversal_mark is less than257// current sweep traversal index.258volatile long _stack_traversal_mark;259260// The _hotness_counter indicates the hotness of a method. The higher261// the value the hotter the method. The hotness counter of a nmethod is262// set to [(ReservedCodeCacheSize / (1024 * 1024)) * 2] each time the method263// is active while stack scanning (do_stack_scanning()). The hotness264// counter is decreased (by 1) while sweeping.265int _hotness_counter;266267// Local state used to keep track of whether unloading is happening or not268volatile uint8_t _is_unloading_state;269270// These are used for compiled synchronized native methods to271// locate the owner and stack slot for the BasicLock so that we can272// properly revoke the bias of the owner if necessary. They are273// needed because there is no debug information for compiled native274// wrappers and the oop maps are insufficient to allow275// frame::retrieve_receiver() to work. Currently they are expected276// to be byte offsets from the Java stack pointer for maximum code277// sharing between platforms. Note that currently biased locking278// will never cause Class instances to be biased but this code279// handles the static synchronized case as well.280// JVMTI's GetLocalInstance() also uses these offsets to find the receiver281// for non-static native wrapper frames.282ByteSize _native_receiver_sp_offset;283ByteSize _native_basic_lock_sp_offset;284285friend class nmethodLocker;286287// For native wrappers288nmethod(Method* method,289CompilerType type,290int nmethod_size,291int compile_id,292CodeOffsets* offsets,293CodeBuffer *code_buffer,294int frame_size,295ByteSize basic_lock_owner_sp_offset, /* synchronized natives only */296ByteSize basic_lock_sp_offset, /* synchronized natives only */297OopMapSet* oop_maps);298299// Creation support300nmethod(Method* method,301CompilerType type,302int nmethod_size,303int compile_id,304int entry_bci,305CodeOffsets* offsets,306int orig_pc_offset,307DebugInformationRecorder *recorder,308Dependencies* dependencies,309CodeBuffer *code_buffer,310int frame_size,311OopMapSet* oop_maps,312ExceptionHandlerTable* handler_table,313ImplicitExceptionTable* nul_chk_table,314AbstractCompiler* compiler,315int comp_level,316const GrowableArrayView<RuntimeStub*>& native_invokers317#if INCLUDE_JVMCI318, char* speculations,319int speculations_len,320int jvmci_data_size321#endif322);323324// helper methods325void* operator new(size_t size, int nmethod_size, int comp_level) throw();326327const char* reloc_string_for(u_char* begin, u_char* end);328329bool try_transition(int new_state);330331// Returns true if this thread changed the state of the nmethod or332// false if another thread performed the transition.333bool make_not_entrant_or_zombie(int state);334bool make_entrant() { Unimplemented(); return false; }335void inc_decompile_count();336337// Inform external interfaces that a compiled method has been unloaded338void post_compiled_method_unload();339340// Initailize fields to their default values341void init_defaults();342343// Offsets344int content_offset() const { return content_begin() - header_begin(); }345int data_offset() const { return _data_offset; }346347address header_end() const { return (address) header_begin() + header_size(); }348349public:350// create nmethod with entry_bci351static nmethod* new_nmethod(const methodHandle& method,352int compile_id,353int entry_bci,354CodeOffsets* offsets,355int orig_pc_offset,356DebugInformationRecorder* recorder,357Dependencies* dependencies,358CodeBuffer *code_buffer,359int frame_size,360OopMapSet* oop_maps,361ExceptionHandlerTable* handler_table,362ImplicitExceptionTable* nul_chk_table,363AbstractCompiler* compiler,364int comp_level,365const GrowableArrayView<RuntimeStub*>& native_invokers = GrowableArrayView<RuntimeStub*>::EMPTY366#if INCLUDE_JVMCI367, char* speculations = NULL,368int speculations_len = 0,369int nmethod_mirror_index = -1,370const char* nmethod_mirror_name = NULL,371FailedSpeculation** failed_speculations = NULL372#endif373);374375// Only used for unit tests.376nmethod()377: CompiledMethod(),378_is_unloading_state(0),379_native_receiver_sp_offset(in_ByteSize(-1)),380_native_basic_lock_sp_offset(in_ByteSize(-1)) {}381382383static nmethod* new_native_nmethod(const methodHandle& method,384int compile_id,385CodeBuffer *code_buffer,386int vep_offset,387int frame_complete,388int frame_size,389ByteSize receiver_sp_offset,390ByteSize basic_lock_sp_offset,391OopMapSet* oop_maps);392393// type info394bool is_nmethod() const { return true; }395bool is_osr_method() const { return _entry_bci != InvocationEntryBci; }396397// boundaries for different parts398address consts_begin () const { return header_begin() + _consts_offset ; }399address consts_end () const { return code_begin() ; }400address stub_begin () const { return header_begin() + _stub_offset ; }401address stub_end () const { return header_begin() + _oops_offset ; }402address exception_begin () const { return header_begin() + _exception_offset ; }403address unwind_handler_begin () const { return _unwind_handler_offset != -1 ? (header_begin() + _unwind_handler_offset) : NULL; }404oop* oops_begin () const { return (oop*) (header_begin() + _oops_offset) ; }405oop* oops_end () const { return (oop*) (header_begin() + _metadata_offset) ; }406407Metadata** metadata_begin () const { return (Metadata**) (header_begin() + _metadata_offset) ; }408Metadata** metadata_end () const { return (Metadata**) _scopes_data_begin; }409410address scopes_data_end () const { return header_begin() + _scopes_pcs_offset ; }411PcDesc* scopes_pcs_begin () const { return (PcDesc*)(header_begin() + _scopes_pcs_offset ); }412PcDesc* scopes_pcs_end () const { return (PcDesc*)(header_begin() + _dependencies_offset) ; }413address dependencies_begin () const { return header_begin() + _dependencies_offset ; }414address dependencies_end () const { return header_begin() + _native_invokers_offset ; }415RuntimeStub** native_invokers_begin() const { return (RuntimeStub**)(header_begin() + _native_invokers_offset) ; }416RuntimeStub** native_invokers_end () const { return (RuntimeStub**)(header_begin() + _handler_table_offset); }417address handler_table_begin () const { return header_begin() + _handler_table_offset ; }418address handler_table_end () const { return header_begin() + _nul_chk_table_offset ; }419address nul_chk_table_begin () const { return header_begin() + _nul_chk_table_offset ; }420#if INCLUDE_JVMCI421address nul_chk_table_end () const { return header_begin() + _speculations_offset ; }422address speculations_begin () const { return header_begin() + _speculations_offset ; }423address speculations_end () const { return header_begin() + _jvmci_data_offset ; }424address jvmci_data_begin () const { return header_begin() + _jvmci_data_offset ; }425address jvmci_data_end () const { return header_begin() + _nmethod_end_offset ; }426#else427address nul_chk_table_end () const { return header_begin() + _nmethod_end_offset ; }428#endif429430// Sizes431int oops_size () const { return (address) oops_end () - (address) oops_begin (); }432int metadata_size () const { return (address) metadata_end () - (address) metadata_begin (); }433int dependencies_size () const { return dependencies_end () - dependencies_begin (); }434#if INCLUDE_JVMCI435int speculations_size () const { return speculations_end () - speculations_begin (); }436int jvmci_data_size () const { return jvmci_data_end () - jvmci_data_begin (); }437#endif438439int oops_count() const { assert(oops_size() % oopSize == 0, ""); return (oops_size() / oopSize) + 1; }440int metadata_count() const { assert(metadata_size() % wordSize == 0, ""); return (metadata_size() / wordSize) + 1; }441442int total_size () const;443444void dec_hotness_counter() { _hotness_counter--; }445void set_hotness_counter(int val) { _hotness_counter = val; }446int hotness_counter() const { return _hotness_counter; }447448// Containment449bool oops_contains (oop* addr) const { return oops_begin () <= addr && addr < oops_end (); }450bool metadata_contains (Metadata** addr) const { return metadata_begin () <= addr && addr < metadata_end (); }451bool scopes_data_contains (address addr) const { return scopes_data_begin () <= addr && addr < scopes_data_end (); }452bool scopes_pcs_contains (PcDesc* addr) const { return scopes_pcs_begin () <= addr && addr < scopes_pcs_end (); }453454// entry points455address entry_point() const { return _entry_point; } // normal entry point456address verified_entry_point() const { return _verified_entry_point; } // if klass is correct457458// flag accessing and manipulation459bool is_not_installed() const { return _state == not_installed; }460bool is_in_use() const { return _state <= in_use; }461bool is_alive() const { return _state < unloaded; }462bool is_not_entrant() const { return _state == not_entrant; }463bool is_zombie() const { return _state == zombie; }464bool is_unloaded() const { return _state == unloaded; }465466void clear_unloading_state();467virtual bool is_unloading();468virtual void do_unloading(bool unloading_occurred);469470#if INCLUDE_RTM_OPT471// rtm state accessing and manipulating472RTMState rtm_state() const { return _rtm_state; }473void set_rtm_state(RTMState state) { _rtm_state = state; }474#endif475476bool make_in_use() {477return try_transition(in_use);478}479// Make the nmethod non entrant. The nmethod will continue to be480// alive. It is used when an uncommon trap happens. Returns true481// if this thread changed the state of the nmethod or false if482// another thread performed the transition.483bool make_not_entrant() {484assert(!method()->is_method_handle_intrinsic(), "Cannot make MH intrinsic not entrant");485return make_not_entrant_or_zombie(not_entrant);486}487bool make_not_used() { return make_not_entrant(); }488bool make_zombie() { return make_not_entrant_or_zombie(zombie); }489490int get_state() const {491return _state;492}493494void make_unloaded();495496bool has_dependencies() { return dependencies_size() != 0; }497void print_dependencies() PRODUCT_RETURN;498void flush_dependencies(bool delete_immediately);499bool has_flushed_dependencies() { return _has_flushed_dependencies; }500void set_has_flushed_dependencies() {501assert(!has_flushed_dependencies(), "should only happen once");502_has_flushed_dependencies = 1;503}504505int comp_level() const { return _comp_level; }506507void unlink_from_method();508509// Support for oops in scopes and relocs:510// Note: index 0 is reserved for null.511oop oop_at(int index) const;512oop oop_at_phantom(int index) const; // phantom reference513oop* oop_addr_at(int index) const { // for GC514// relocation indexes are biased by 1 (because 0 is reserved)515assert(index > 0 && index <= oops_count(), "must be a valid non-zero index");516assert(!_oops_are_stale, "oops are stale");517return &oops_begin()[index - 1];518}519520// Support for meta data in scopes and relocs:521// Note: index 0 is reserved for null.522Metadata* metadata_at(int index) const { return index == 0 ? NULL: *metadata_addr_at(index); }523Metadata** metadata_addr_at(int index) const { // for GC524// relocation indexes are biased by 1 (because 0 is reserved)525assert(index > 0 && index <= metadata_count(), "must be a valid non-zero index");526return &metadata_begin()[index - 1];527}528529void copy_values(GrowableArray<jobject>* oops);530void copy_values(GrowableArray<Metadata*>* metadata);531532void free_native_invokers();533534// Relocation support535private:536void fix_oop_relocations(address begin, address end, bool initialize_immediates);537inline void initialize_immediate_oop(oop* dest, jobject handle);538539public:540void fix_oop_relocations(address begin, address end) { fix_oop_relocations(begin, end, false); }541void fix_oop_relocations() { fix_oop_relocations(NULL, NULL, false); }542543// Sweeper support544long stack_traversal_mark() { return _stack_traversal_mark; }545void set_stack_traversal_mark(long l) { _stack_traversal_mark = l; }546547// On-stack replacement support548int osr_entry_bci() const { assert(is_osr_method(), "wrong kind of nmethod"); return _entry_bci; }549address osr_entry() const { assert(is_osr_method(), "wrong kind of nmethod"); return _osr_entry_point; }550void invalidate_osr_method();551nmethod* osr_link() const { return _osr_link; }552void set_osr_link(nmethod *n) { _osr_link = n; }553554// Verify calls to dead methods have been cleaned.555void verify_clean_inline_caches();556557// unlink and deallocate this nmethod558// Only NMethodSweeper class is expected to use this. NMethodSweeper is not559// expected to use any other private methods/data in this class.560561protected:562void flush();563564public:565// When true is returned, it is unsafe to remove this nmethod even if566// it is a zombie, since the VM or the ServiceThread might still be567// using it.568bool is_locked_by_vm() const { return _lock_count >0; }569570// See comment at definition of _last_seen_on_stack571void mark_as_seen_on_stack();572bool can_convert_to_zombie();573574// Evolution support. We make old (discarded) compiled methods point to new Method*s.575void set_method(Method* method) { _method = method; }576577#if INCLUDE_JVMCI578// Gets the JVMCI name of this nmethod.579const char* jvmci_name();580581// Records the pending failed speculation in the582// JVMCI speculation log associated with this nmethod.583void update_speculation(JavaThread* thread);584585// Gets the data specific to a JVMCI compiled method.586// This returns a non-NULL value iff this nmethod was587// compiled by the JVMCI compiler.588JVMCINMethodData* jvmci_nmethod_data() const {589return jvmci_data_size() == 0 ? NULL : (JVMCINMethodData*) jvmci_data_begin();590}591#endif592593public:594void oops_do(OopClosure* f) { oops_do(f, false); }595void oops_do(OopClosure* f, bool allow_dead);596597// All-in-one claiming of nmethods: returns true if the caller successfully claimed that598// nmethod.599bool oops_do_try_claim();600601// Class containing callbacks for the oops_do_process_weak/strong() methods602// below.603class OopsDoProcessor {604public:605// Process the oops of the given nmethod based on whether it has been called606// in a weak or strong processing context, i.e. apply either weak or strong607// work on it.608virtual void do_regular_processing(nmethod* nm) = 0;609// Assuming that the oops of the given nmethod has already been its weak610// processing applied, apply the remaining strong processing part.611virtual void do_remaining_strong_processing(nmethod* nm) = 0;612};613614// The following two methods do the work corresponding to weak/strong nmethod615// processing.616void oops_do_process_weak(OopsDoProcessor* p);617void oops_do_process_strong(OopsDoProcessor* p);618619static void oops_do_marking_prologue();620static void oops_do_marking_epilogue();621622private:623ScopeDesc* scope_desc_in(address begin, address end);624625address* orig_pc_addr(const frame* fr);626627// used by jvmti to track if the load and unload events has been reported628bool unload_reported() const { return _unload_reported; }629void set_unload_reported() { _unload_reported = true; }630bool load_reported() const { return _load_reported; }631void set_load_reported() { _load_reported = true; }632633public:634// copying of debugging information635void copy_scopes_pcs(PcDesc* pcs, int count);636void copy_scopes_data(address buffer, int size);637638// Accessor/mutator for the original pc of a frame before a frame was deopted.639address get_original_pc(const frame* fr) { return *orig_pc_addr(fr); }640void set_original_pc(const frame* fr, address pc) { *orig_pc_addr(fr) = pc; }641642// jvmti support:643void post_compiled_method_load_event(JvmtiThreadState* state = NULL);644645// verify operations646void verify();647void verify_scopes();648void verify_interrupt_point(address interrupt_point);649650// Disassemble this nmethod with additional debug information, e.g. information about blocks.651void decode2(outputStream* st) const;652void print_constant_pool(outputStream* st);653654// Avoid hiding of parent's 'decode(outputStream*)' method.655void decode(outputStream* st) const { decode2(st); } // just delegate here.656657// printing support658void print() const;659void print(outputStream* st) const;660void print_code();661662#if defined(SUPPORT_DATA_STRUCTS)663// print output in opt build for disassembler library664void print_relocations() PRODUCT_RETURN;665void print_pcs() { print_pcs_on(tty); }666void print_pcs_on(outputStream* st);667void print_scopes() { print_scopes_on(tty); }668void print_scopes_on(outputStream* st) PRODUCT_RETURN;669void print_value_on(outputStream* st) const;670void print_native_invokers();671void print_handler_table();672void print_nul_chk_table();673void print_recorded_oop(int log_n, int index);674void print_recorded_oops();675void print_recorded_metadata();676677void print_oops(outputStream* st); // oops from the underlying CodeBlob.678void print_metadata(outputStream* st); // metadata in metadata pool.679#else680// void print_pcs() PRODUCT_RETURN;681void print_pcs() { return; }682#endif683684void print_calls(outputStream* st) PRODUCT_RETURN;685static void print_statistics() PRODUCT_RETURN;686687void maybe_print_nmethod(DirectiveSet* directive);688void print_nmethod(bool print_code);689690// need to re-define this from CodeBlob else the overload hides it691virtual void print_on(outputStream* st) const { CodeBlob::print_on(st); }692void print_on(outputStream* st, const char* msg) const;693694// Logging695void log_identity(xmlStream* log) const;696void log_new_nmethod() const;697void log_state_change() const;698699// Prints block-level comments, including nmethod specific block labels:700virtual void print_block_comment(outputStream* stream, address block_begin) const {701#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)702print_nmethod_labels(stream, block_begin);703CodeBlob::print_block_comment(stream, block_begin);704#endif705}706707void print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;708const char* nmethod_section_label(address pos) const;709710// returns whether this nmethod has code comments.711bool has_code_comment(address begin, address end);712// Prints a comment for one native instruction (reloc info, pc desc)713void print_code_comment_on(outputStream* st, int column, address begin, address end);714715// Compiler task identification. Note that all OSR methods716// are numbered in an independent sequence if CICountOSR is true,717// and native method wrappers are also numbered independently if718// CICountNative is true.719virtual int compile_id() const { return _compile_id; }720const char* compile_kind() const;721722// tells if any of this method's dependencies have been invalidated723// (this is expensive!)724static void check_all_dependencies(DepChange& changes);725726// tells if this compiled method is dependent on the given changes,727// and the changes have invalidated it728bool check_dependency_on(DepChange& changes);729730// Fast breakpoint support. Tells if this compiled method is731// dependent on the given method. Returns true if this nmethod732// corresponds to the given method as well.733virtual bool is_dependent_on_method(Method* dependee);734735// is it ok to patch at address?736bool is_patchable_at(address instr_address);737738// UseBiasedLocking support739ByteSize native_receiver_sp_offset() {740return _native_receiver_sp_offset;741}742ByteSize native_basic_lock_sp_offset() {743return _native_basic_lock_sp_offset;744}745746// support for code generation747static int verified_entry_point_offset() { return offset_of(nmethod, _verified_entry_point); }748static int osr_entry_point_offset() { return offset_of(nmethod, _osr_entry_point); }749static int state_offset() { return offset_of(nmethod, _state); }750751virtual void metadata_do(MetadataClosure* f);752753NativeCallWrapper* call_wrapper_at(address call) const;754NativeCallWrapper* call_wrapper_before(address return_pc) const;755address call_instruction_address(address pc) const;756757virtual CompiledStaticCall* compiledStaticCall_at(Relocation* call_site) const;758virtual CompiledStaticCall* compiledStaticCall_at(address addr) const;759virtual CompiledStaticCall* compiledStaticCall_before(address addr) const;760};761762// Locks an nmethod so its code will not get removed and it will not763// be made into a zombie, even if it is a not_entrant method. After the764// nmethod becomes a zombie, if CompiledMethodUnload event processing765// needs to be done, then lock_nmethod() is used directly to keep the766// generated code from being reused too early.767class nmethodLocker : public StackObj {768CompiledMethod* _nm;769770public:771772// note: nm can be NULL773// Only JvmtiDeferredEvent::compiled_method_unload_event()774// should pass zombie_ok == true.775static void lock_nmethod(CompiledMethod* nm, bool zombie_ok = false);776static void unlock_nmethod(CompiledMethod* nm); // (ditto)777778nmethodLocker(address pc); // derive nm from pc779nmethodLocker(nmethod *nm) { _nm = nm; lock_nmethod(_nm); }780nmethodLocker(CompiledMethod *nm) {781_nm = nm;782lock(_nm);783}784785static void lock(CompiledMethod* method, bool zombie_ok = false) {786if (method == NULL) return;787lock_nmethod(method, zombie_ok);788}789790static void unlock(CompiledMethod* method) {791if (method == NULL) return;792unlock_nmethod(method);793}794795nmethodLocker() { _nm = NULL; }796~nmethodLocker() {797unlock(_nm);798}799800CompiledMethod* code() { return _nm; }801void set_code(CompiledMethod* new_nm, bool zombie_ok = false) {802unlock(_nm); // note: This works even if _nm==new_nm.803_nm = new_nm;804lock(_nm, zombie_ok);805}806};807808#endif // SHARE_CODE_NMETHOD_HPP809810811