1 /*
  2  * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_CODE_NMETHOD_HPP
 26 #define SHARE_CODE_NMETHOD_HPP
 27 
 28 #include "code/compiledMethod.hpp"
 29 
 30 class CompileTask;
 31 class DepChange;
 32 class DirectiveSet;
 33 class DebugInformationRecorder;
 34 class JvmtiThreadState;
 35 class OopIterateClosure;
 36 
 37 // nmethods (native methods) are the compiled code versions of Java methods.
 38 //
 39 // An nmethod contains:
 40 //  - header                 (the nmethod structure)
 41 //  [Relocation]
 42 //  - relocation information
 43 //  - constant part          (doubles, longs and floats used in nmethod)
 44 //  - oop table
 45 //  [Code]
 46 //  - code body
 47 //  - exception handler
 48 //  - stub code
 49 //  [Debugging information]
 50 //  - oop array
 51 //  - data array
 52 //  - pcs
 53 //  [Exception handler table]
 54 //  - handler entry point array
 55 //  [Implicit Null Pointer exception table]
 56 //  - implicit null table array
 57 //  [Speculations]
 58 //  - encoded speculations array
 59 //  [JVMCINMethodData]
 60 //  - meta data for JVMCI compiled nmethod
 61 
 62 #if INCLUDE_JVMCI
 63 class FailedSpeculation;
 64 class JVMCINMethodData;
 65 #endif
 66 
 67 class nmethod : public CompiledMethod {
 68   friend class VMStructs;
 69   friend class JVMCIVMStructs;
 70   friend class CodeCache;  // scavengable oops
 71   friend class JVMCINMethodData;
 72 
 73  private:
 74 
 75   uint64_t  _gc_epoch;
 76 
 77   // To support simple linked-list chaining of nmethods:
 78   nmethod*  _osr_link;         // from InstanceKlass::osr_nmethods_head
 79 
 80   // STW two-phase nmethod root processing helpers.
 81   //
 82   // When determining liveness of a given nmethod to do code cache unloading,
 83   // some collectors need to do different things depending on whether the nmethods
 84   // need to absolutely be kept alive during root processing; "strong"ly reachable
 85   // nmethods are known to be kept alive at root processing, but the liveness of
 86   // "weak"ly reachable ones is to be determined later.
 87   //
 88   // We want to allow strong and weak processing of nmethods by different threads
 89   // at the same time without heavy synchronization. Additional constraints are
 90   // to make sure that every nmethod is processed a minimal amount of time, and
 91   // nmethods themselves are always iterated at most once at a particular time.
 92   //
 93   // Note that strong processing work must be a superset of weak processing work
 94   // for this code to work.
 95   //
 96   // We store state and claim information in the _oops_do_mark_link member, using
 97   // the two LSBs for the state and the remaining upper bits for linking together
 98   // nmethods that were already visited.
 99   // The last element is self-looped, i.e. points to itself to avoid some special
100   // "end-of-list" sentinel value.
101   //
102   // _oops_do_mark_link special values:
103   //
104   //   _oops_do_mark_link == NULL: the nmethod has not been visited at all yet, i.e.
105   //      is Unclaimed.
106   //
107   // For other values, its lowest two bits indicate the following states of the nmethod:
108   //
109   //   weak_request (WR): the nmethod has been claimed by a thread for weak processing
110   //   weak_done (WD): weak processing has been completed for this nmethod.
111   //   strong_request (SR): the nmethod has been found to need strong processing while
112   //       being weak processed.
113   //   strong_done (SD): strong processing has been completed for this nmethod .
114   //
115   // The following shows the _only_ possible progressions of the _oops_do_mark_link
116   // pointer.
117   //
118   // Given
119   //   N as the nmethod
120   //   X the current next value of _oops_do_mark_link
121   //
122   // Unclaimed (C)-> N|WR (C)-> X|WD: the nmethod has been processed weakly by
123   //   a single thread.
124   // Unclaimed (C)-> N|WR (C)-> X|WD (O)-> X|SD: after weak processing has been
125   //   completed (as above) another thread found that the nmethod needs strong
126   //   processing after all.
127   // Unclaimed (C)-> N|WR (O)-> N|SR (C)-> X|SD: during weak processing another
128   //   thread finds that the nmethod needs strong processing, marks it as such and
129   //   terminates. The original thread completes strong processing.
130   // Unclaimed (C)-> N|SD (C)-> X|SD: the nmethod has been processed strongly from
131   //   the beginning by a single thread.
132   //
133   // "|" describes the concatenation of bits in _oops_do_mark_link.
134   //
135   // The diagram also describes the threads responsible for changing the nmethod to
136   // the next state by marking the _transition_ with (C) and (O), which mean "current"
137   // and "other" thread respectively.
138   //
139   struct oops_do_mark_link; // Opaque data type.
140 
141   // States used for claiming nmethods during root processing.
142   static const uint claim_weak_request_tag = 0;
143   static const uint claim_weak_done_tag = 1;
144   static const uint claim_strong_request_tag = 2;
145   static const uint claim_strong_done_tag = 3;
146 
147   static oops_do_mark_link* mark_link(nmethod* nm, uint tag) {
148     assert(tag <= claim_strong_done_tag, "invalid tag %u", tag);
149     assert(is_aligned(nm, 4), "nmethod pointer must have zero lower two LSB");
150     return (oops_do_mark_link*)(((uintptr_t)nm & ~0x3) | tag);
151   }
152 
153   static uint extract_state(oops_do_mark_link* link) {
154     return (uint)((uintptr_t)link & 0x3);
155   }
156 
157   static nmethod* extract_nmethod(oops_do_mark_link* link) {
158     return (nmethod*)((uintptr_t)link & ~0x3);
159   }
160 
161   void oops_do_log_change(const char* state);
162 
163   static bool oops_do_has_weak_request(oops_do_mark_link* next) {
164     return extract_state(next) == claim_weak_request_tag;
165   }
166 
167   static bool oops_do_has_any_strong_state(oops_do_mark_link* next) {
168     return extract_state(next) >= claim_strong_request_tag;
169   }
170 
171   // Attempt Unclaimed -> N|WR transition. Returns true if successful.
172   bool oops_do_try_claim_weak_request();
173 
174   // Attempt Unclaimed -> N|SD transition. Returns the current link.
175   oops_do_mark_link* oops_do_try_claim_strong_done();
176   // Attempt N|WR -> X|WD transition. Returns NULL if successful, X otherwise.
177   nmethod* oops_do_try_add_to_list_as_weak_done();
178 
179   // Attempt X|WD -> N|SR transition. Returns the current link.
180   oops_do_mark_link* oops_do_try_add_strong_request(oops_do_mark_link* next);
181   // Attempt X|WD -> X|SD transition. Returns true if successful.
182   bool oops_do_try_claim_weak_done_as_strong_done(oops_do_mark_link* next);
183 
184   // Do the N|SD -> X|SD transition.
185   void oops_do_add_to_list_as_strong_done();
186 
187   // Sets this nmethod as strongly claimed (as part of N|SD -> X|SD and N|SR -> X|SD
188   // transitions).
189   void oops_do_set_strong_done(nmethod* old_head);
190 
191   static nmethod* volatile _oops_do_mark_nmethods;
192   oops_do_mark_link* volatile _oops_do_mark_link;
193 
194   // offsets for entry points
195   address _entry_point;                      // entry point with class check
196   address _verified_entry_point;             // entry point without class check
197   address _osr_entry_point;                  // entry point for on stack replacement
198 
199   nmethod* _unlinked_next;
200 
201   // Shared fields for all nmethod's
202   int _entry_bci;      // != InvocationEntryBci if this nmethod is an on-stack replacement method
203 
204   // Offsets for different nmethod parts
205   int  _exception_offset;
206   // Offset of the unwind handler if it exists
207   int _unwind_handler_offset;
208 
209   int _consts_offset;
210   int _stub_offset;
211   int _oops_offset;                       // offset to where embedded oop table begins (inside data)
212   int _metadata_offset;                   // embedded meta data table
213   int _scopes_data_offset;
214   int _scopes_pcs_offset;
215   int _dependencies_offset;
216   int _handler_table_offset;
217   int _nul_chk_table_offset;
218 #if INCLUDE_JVMCI
219   int _speculations_offset;
220   int _jvmci_data_offset;
221 #endif
222   int _nmethod_end_offset;
223 
224   int code_offset() const { return (address) code_begin() - header_begin(); }
225 
226   // location in frame (offset for sp) that deopt can store the original
227   // pc during a deopt.
228   int _orig_pc_offset;
229 
230   int _compile_id;                           // which compilation made this nmethod
231 
232 #if INCLUDE_RTM_OPT
233   // RTM state at compile time. Used during deoptimization to decide
234   // whether to restart collecting RTM locking abort statistic again.
235   RTMState _rtm_state;
236 #endif
237 
238   // These are used for compiled synchronized native methods to
239   // locate the owner and stack slot for the BasicLock. They are
240   // needed because there is no debug information for compiled native
241   // wrappers and the oop maps are insufficient to allow
242   // frame::retrieve_receiver() to work. Currently they are expected
243   // to be byte offsets from the Java stack pointer for maximum code
244   // sharing between platforms. JVMTI's GetLocalInstance() uses these
245   // offsets to find the receiver for non-static native wrapper frames.
246   ByteSize _native_receiver_sp_offset;
247   ByteSize _native_basic_lock_sp_offset;
248 
249   CompLevel _comp_level;               // compilation level
250 
251   // Local state used to keep track of whether unloading is happening or not
252   volatile uint8_t _is_unloading_state;
253 
254   // protected by CodeCache_lock
255   bool _has_flushed_dependencies;      // Used for maintenance of dependencies (CodeCache_lock)
256 
257   // used by jvmti to track if an event has been posted for this nmethod.
258   bool _load_reported;
259 
260   // Protected by CompiledMethod_lock
261   volatile signed char _state;         // {not_installed, in_use, not_used, not_entrant}
262 
263   // For native wrappers
264   nmethod(Method* method,
265           CompilerType type,
266           int nmethod_size,
267           int compile_id,
268           CodeOffsets* offsets,
269           CodeBuffer *code_buffer,
270           int frame_size,
271           ByteSize basic_lock_owner_sp_offset, /* synchronized natives only */
272           ByteSize basic_lock_sp_offset,       /* synchronized natives only */
273           OopMapSet* oop_maps);
274 
275   // Creation support
276   nmethod(Method* method,
277           CompilerType type,
278           int nmethod_size,
279           int compile_id,
280           int entry_bci,
281           CodeOffsets* offsets,
282           int orig_pc_offset,
283           DebugInformationRecorder *recorder,
284           Dependencies* dependencies,
285           CodeBuffer *code_buffer,
286           int frame_size,
287           OopMapSet* oop_maps,
288           ExceptionHandlerTable* handler_table,
289           ImplicitExceptionTable* nul_chk_table,
290           AbstractCompiler* compiler,
291           CompLevel comp_level
292 #if INCLUDE_JVMCI
293           , char* speculations,
294           int speculations_len,
295           int jvmci_data_size
296 #endif
297           );
298 
299   // helper methods
300   void* operator new(size_t size, int nmethod_size, int comp_level) throw();
301 
302   const char* reloc_string_for(u_char* begin, u_char* end);
303 
304   bool try_transition(int new_state);
305 
306   // Returns true if this thread changed the state of the nmethod or
307   // false if another thread performed the transition.
308   bool make_entrant() { Unimplemented(); return false; }
309   void inc_decompile_count();
310 
311   // Inform external interfaces that a compiled method has been unloaded
312   void post_compiled_method_unload();
313 
314   // Initialize fields to their default values
315   void init_defaults();
316 
317   // Offsets
318   int content_offset() const                  { return content_begin() - header_begin(); }
319   int data_offset() const                     { return _data_offset; }
320 
321   address header_end() const                  { return (address)    header_begin() + header_size(); }
322 
323  public:
324   // create nmethod with entry_bci
325   static nmethod* new_nmethod(const methodHandle& method,
326                               int compile_id,
327                               int entry_bci,
328                               CodeOffsets* offsets,
329                               int orig_pc_offset,
330                               DebugInformationRecorder* recorder,
331                               Dependencies* dependencies,
332                               CodeBuffer *code_buffer,
333                               int frame_size,
334                               OopMapSet* oop_maps,
335                               ExceptionHandlerTable* handler_table,
336                               ImplicitExceptionTable* nul_chk_table,
337                               AbstractCompiler* compiler,
338                               CompLevel comp_level
339 #if INCLUDE_JVMCI
340                               , char* speculations = NULL,
341                               int speculations_len = 0,
342                               int nmethod_mirror_index = -1,
343                               const char* nmethod_mirror_name = NULL,
344                               FailedSpeculation** failed_speculations = NULL
345 #endif
346   );
347 
348   // Only used for unit tests.
349   nmethod()
350     : CompiledMethod(),
351       _native_receiver_sp_offset(in_ByteSize(-1)),
352       _native_basic_lock_sp_offset(in_ByteSize(-1)),
353       _is_unloading_state(0) {}
354 
355 
356   static nmethod* new_native_nmethod(const methodHandle& method,
357                                      int compile_id,
358                                      CodeBuffer *code_buffer,
359                                      int vep_offset,
360                                      int frame_complete,
361                                      int frame_size,
362                                      ByteSize receiver_sp_offset,
363                                      ByteSize basic_lock_sp_offset,
364                                      OopMapSet* oop_maps,
365                                      int exception_handler = -1);
366 
367   // type info
368   bool is_nmethod() const                         { return true; }
369   bool is_osr_method() const                      { return _entry_bci != InvocationEntryBci; }
370 
371   // boundaries for different parts
372   address consts_begin          () const          { return           header_begin() + _consts_offset        ; }
373   address consts_end            () const          { return           code_begin()                           ; }
374   address stub_begin            () const          { return           header_begin() + _stub_offset          ; }
375   address stub_end              () const          { return           header_begin() + _oops_offset          ; }
376   address exception_begin       () const          { return           header_begin() + _exception_offset     ; }
377   address unwind_handler_begin  () const          { return _unwind_handler_offset != -1 ? (header_begin() + _unwind_handler_offset) : NULL; }
378   oop*    oops_begin            () const          { return (oop*)   (header_begin() + _oops_offset)         ; }
379   oop*    oops_end              () const          { return (oop*)   (header_begin() + _metadata_offset)     ; }
380 
381   Metadata** metadata_begin   () const            { return (Metadata**)  (header_begin() + _metadata_offset)     ; }
382   Metadata** metadata_end     () const            { return (Metadata**)  _scopes_data_begin; }
383 
384   address scopes_data_end       () const          { return           header_begin() + _scopes_pcs_offset    ; }
385   PcDesc* scopes_pcs_begin      () const          { return (PcDesc*)(header_begin() + _scopes_pcs_offset   ); }
386   PcDesc* scopes_pcs_end        () const          { return (PcDesc*)(header_begin() + _dependencies_offset) ; }
387   address dependencies_begin    () const          { return           header_begin() + _dependencies_offset  ; }
388   address dependencies_end      () const          { return           header_begin() + _handler_table_offset ; }
389   address handler_table_begin   () const          { return           header_begin() + _handler_table_offset ; }
390   address handler_table_end     () const          { return           header_begin() + _nul_chk_table_offset ; }
391   address nul_chk_table_begin   () const          { return           header_begin() + _nul_chk_table_offset ; }
392 #if INCLUDE_JVMCI
393   address nul_chk_table_end     () const          { return           header_begin() + _speculations_offset  ; }
394   address speculations_begin    () const          { return           header_begin() + _speculations_offset  ; }
395   address speculations_end      () const          { return           header_begin() + _jvmci_data_offset   ; }
396   address jvmci_data_begin      () const          { return           header_begin() + _jvmci_data_offset    ; }
397   address jvmci_data_end        () const          { return           header_begin() + _nmethod_end_offset   ; }
398 #else
399   address nul_chk_table_end     () const          { return           header_begin() + _nmethod_end_offset   ; }
400 #endif
401 
402   // Sizes
403   int oops_size         () const                  { return (address)  oops_end         () - (address)  oops_begin         (); }
404   int metadata_size     () const                  { return (address)  metadata_end     () - (address)  metadata_begin     (); }
405   int dependencies_size () const                  { return            dependencies_end () -            dependencies_begin (); }
406 #if INCLUDE_JVMCI
407   int speculations_size () const                  { return            speculations_end () -            speculations_begin (); }
408   int jvmci_data_size   () const                  { return            jvmci_data_end   () -            jvmci_data_begin   (); }
409 #endif
410 
411   int     oops_count() const { assert(oops_size() % oopSize == 0, "");  return (oops_size() / oopSize) + 1; }
412   int metadata_count() const { assert(metadata_size() % wordSize == 0, ""); return (metadata_size() / wordSize) + 1; }
413 
414   int total_size        () const;
415 
416   // Containment
417   bool oops_contains         (oop*    addr) const { return oops_begin         () <= addr && addr < oops_end         (); }
418   bool metadata_contains     (Metadata** addr) const   { return metadata_begin     () <= addr && addr < metadata_end     (); }
419   bool scopes_data_contains  (address addr) const { return scopes_data_begin  () <= addr && addr < scopes_data_end  (); }
420   bool scopes_pcs_contains   (PcDesc* addr) const { return scopes_pcs_begin   () <= addr && addr < scopes_pcs_end   (); }
421 
422   // entry points
423   address entry_point() const                     { return _entry_point;             } // normal entry point
424   address verified_entry_point() const            { return _verified_entry_point;    } // if klass is correct
425 
426   // flag accessing and manipulation
427   bool  is_not_installed() const                  { return _state == not_installed; }
428   bool  is_in_use() const                         { return _state <= in_use; }
429   bool  is_not_entrant() const                    { return _state == not_entrant; }
430 
431   void clear_unloading_state();
432   // Heuristically deduce an nmethod isn't worth keeping around
433   bool is_cold();
434   virtual bool is_unloading();
435   virtual void do_unloading(bool unloading_occurred);
436 
437   nmethod* unlinked_next() const                  { return _unlinked_next; }
438   void set_unlinked_next(nmethod* next)           { _unlinked_next = next; }
439 
440 #if INCLUDE_RTM_OPT
441   // rtm state accessing and manipulating
442   RTMState  rtm_state() const                     { return _rtm_state; }
443   void set_rtm_state(RTMState state)              { _rtm_state = state; }
444 #endif
445 
446   bool make_in_use() {
447     return try_transition(in_use);
448   }
449   // Make the nmethod non entrant. The nmethod will continue to be
450   // alive.  It is used when an uncommon trap happens.  Returns true
451   // if this thread changed the state of the nmethod or false if
452   // another thread performed the transition.
453   bool  make_not_entrant();
454   bool  make_not_used()    { return make_not_entrant(); }
455 
456   int get_state() const {
457     return _state;
458   }
459 
460   bool has_dependencies()                         { return dependencies_size() != 0; }
461   void print_dependencies()                       PRODUCT_RETURN;
462   void flush_dependencies();
463   bool has_flushed_dependencies()                 { return _has_flushed_dependencies; }
464   void set_has_flushed_dependencies()             {
465     assert(!has_flushed_dependencies(), "should only happen once");
466     _has_flushed_dependencies = 1;
467   }
468 
469   int   comp_level() const                        { return _comp_level; }
470 
471   void unlink_from_method();
472 
473   // Support for oops in scopes and relocs:
474   // Note: index 0 is reserved for null.
475   oop   oop_at(int index) const;
476   oop   oop_at_phantom(int index) const; // phantom reference
477   oop*  oop_addr_at(int index) const {  // for GC
478     // relocation indexes are biased by 1 (because 0 is reserved)
479     assert(index > 0 && index <= oops_count(), "must be a valid non-zero index");
480     return &oops_begin()[index - 1];
481   }
482 
483   // Support for meta data in scopes and relocs:
484   // Note: index 0 is reserved for null.
485   Metadata*     metadata_at(int index) const      { return index == 0 ? NULL: *metadata_addr_at(index); }
486   Metadata**  metadata_addr_at(int index) const {  // for GC
487     // relocation indexes are biased by 1 (because 0 is reserved)
488     assert(index > 0 && index <= metadata_count(), "must be a valid non-zero index");
489     return &metadata_begin()[index - 1];
490   }
491 
492   void copy_values(GrowableArray<jobject>* oops);
493   void copy_values(GrowableArray<Metadata*>* metadata);
494 
495   // Relocation support
496 private:
497   void fix_oop_relocations(address begin, address end, bool initialize_immediates);
498   inline void initialize_immediate_oop(oop* dest, jobject handle);
499 
500 public:
501   void fix_oop_relocations(address begin, address end) { fix_oop_relocations(begin, end, false); }
502   void fix_oop_relocations()                           { fix_oop_relocations(NULL, NULL, false); }
503 
504   // On-stack replacement support
505   int   osr_entry_bci() const                     { assert(is_osr_method(), "wrong kind of nmethod"); return _entry_bci; }
506   address  osr_entry() const                      { assert(is_osr_method(), "wrong kind of nmethod"); return _osr_entry_point; }
507   void  invalidate_osr_method();
508   nmethod* osr_link() const                       { return _osr_link; }
509   void     set_osr_link(nmethod *n)               { _osr_link = n; }
510 
511   // Verify calls to dead methods have been cleaned.
512   void verify_clean_inline_caches();
513 
514   // Unlink this nmethod from the system
515   void unlink();
516 
517   // Deallocate this nmethod - called by the GC
518   void flush();
519 
520   // See comment at definition of _last_seen_on_stack
521   void mark_as_maybe_on_stack();
522   bool is_maybe_on_stack();
523 
524   // Evolution support. We make old (discarded) compiled methods point to new Method*s.
525   void set_method(Method* method) { _method = method; }
526 
527 #if INCLUDE_JVMCI
528   // Gets the JVMCI name of this nmethod.
529   const char* jvmci_name();
530 
531   // Records the pending failed speculation in the
532   // JVMCI speculation log associated with this nmethod.
533   void update_speculation(JavaThread* thread);
534 
535   // Gets the data specific to a JVMCI compiled method.
536   // This returns a non-NULL value iff this nmethod was
537   // compiled by the JVMCI compiler.
538   JVMCINMethodData* jvmci_nmethod_data() const {
539     return jvmci_data_size() == 0 ? NULL : (JVMCINMethodData*) jvmci_data_begin();
540   }
541 #endif
542 
543  public:
544   void oops_do(OopClosure* f) { oops_do(f, false); }
545   void oops_do(OopClosure* f, bool allow_dead);
546 
547   // All-in-one claiming of nmethods: returns true if the caller successfully claimed that
548   // nmethod.
549   bool oops_do_try_claim();
550 
551   // Loom support for following nmethods on the stack
552   void follow_nmethod(OopIterateClosure* cl);
553 
554   // Class containing callbacks for the oops_do_process_weak/strong() methods
555   // below.
556   class OopsDoProcessor {
557   public:
558     // Process the oops of the given nmethod based on whether it has been called
559     // in a weak or strong processing context, i.e. apply either weak or strong
560     // work on it.
561     virtual void do_regular_processing(nmethod* nm) = 0;
562     // Assuming that the oops of the given nmethod has already been its weak
563     // processing applied, apply the remaining strong processing part.
564     virtual void do_remaining_strong_processing(nmethod* nm) = 0;
565   };
566 
567   // The following two methods do the work corresponding to weak/strong nmethod
568   // processing.
569   void oops_do_process_weak(OopsDoProcessor* p);
570   void oops_do_process_strong(OopsDoProcessor* p);
571 
572   static void oops_do_marking_prologue();
573   static void oops_do_marking_epilogue();
574 
575  private:
576   ScopeDesc* scope_desc_in(address begin, address end);
577 
578   address* orig_pc_addr(const frame* fr);
579 
580   // used by jvmti to track if the load events has been reported
581   bool  load_reported() const                     { return _load_reported; }
582   void  set_load_reported()                       { _load_reported = true; }
583 
584  public:
585   // copying of debugging information
586   void copy_scopes_pcs(PcDesc* pcs, int count);
587   void copy_scopes_data(address buffer, int size);
588 
589   int orig_pc_offset() { return _orig_pc_offset; }
590 
591   // Post successful compilation
592   void post_compiled_method(CompileTask* task);
593 
594   // jvmti support:
595   void post_compiled_method_load_event(JvmtiThreadState* state = NULL);
596 
597   // verify operations
598   void verify();
599   void verify_scopes();
600   void verify_interrupt_point(address interrupt_point);
601 
602   // Disassemble this nmethod with additional debug information, e.g. information about blocks.
603   void decode2(outputStream* st) const;
604   void print_constant_pool(outputStream* st);
605 
606   // Avoid hiding of parent's 'decode(outputStream*)' method.
607   void decode(outputStream* st) const { decode2(st); } // just delegate here.
608 
609   // printing support
610   void print()                          const;
611   void print(outputStream* st)          const;
612   void print_code();
613 
614 #if defined(SUPPORT_DATA_STRUCTS)
615   // print output in opt build for disassembler library
616   void print_relocations()                        PRODUCT_RETURN;
617   void print_pcs() { print_pcs_on(tty); }
618   void print_pcs_on(outputStream* st);
619   void print_scopes() { print_scopes_on(tty); }
620   void print_scopes_on(outputStream* st)          PRODUCT_RETURN;
621   void print_value_on(outputStream* st) const;
622   void print_handler_table();
623   void print_nul_chk_table();
624   void print_recorded_oop(int log_n, int index);
625   void print_recorded_oops();
626   void print_recorded_metadata();
627 
628   void print_oops(outputStream* st);     // oops from the underlying CodeBlob.
629   void print_metadata(outputStream* st); // metadata in metadata pool.
630 #else
631   // void print_pcs()                             PRODUCT_RETURN;
632   void print_pcs()                                { return; }
633 #endif
634 
635   void print_calls(outputStream* st)              PRODUCT_RETURN;
636   static void print_statistics()                  PRODUCT_RETURN;
637 
638   void maybe_print_nmethod(const DirectiveSet* directive);
639   void print_nmethod(bool print_code);
640 
641   // need to re-define this from CodeBlob else the overload hides it
642   virtual void print_on(outputStream* st) const { CodeBlob::print_on(st); }
643   void print_on(outputStream* st, const char* msg) const;
644 
645   // Logging
646   void log_identity(xmlStream* log) const;
647   void log_new_nmethod() const;
648   void log_state_change() const;
649 
650   // Prints block-level comments, including nmethod specific block labels:
651   virtual void print_block_comment(outputStream* stream, address block_begin) const {
652 #if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
653     print_nmethod_labels(stream, block_begin);
654     CodeBlob::print_block_comment(stream, block_begin);
655 #endif
656   }
657 
658   void print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;
659   const char* nmethod_section_label(address pos) const;
660 
661   // returns whether this nmethod has code comments.
662   bool has_code_comment(address begin, address end);
663   // Prints a comment for one native instruction (reloc info, pc desc)
664   void print_code_comment_on(outputStream* st, int column, address begin, address end);
665 
666   // Compiler task identification.  Note that all OSR methods
667   // are numbered in an independent sequence if CICountOSR is true,
668   // and native method wrappers are also numbered independently if
669   // CICountNative is true.
670   virtual int compile_id() const { return _compile_id; }
671   const char* compile_kind() const;
672 
673   // tells if any of this method's dependencies have been invalidated
674   // (this is expensive!)
675   static void check_all_dependencies(DepChange& changes);
676 
677   // tells if this compiled method is dependent on the given changes,
678   // and the changes have invalidated it
679   bool check_dependency_on(DepChange& changes);
680 
681   // Fast breakpoint support. Tells if this compiled method is
682   // dependent on the given method. Returns true if this nmethod
683   // corresponds to the given method as well.
684   virtual bool is_dependent_on_method(Method* dependee);
685 
686   // JVMTI's GetLocalInstance() support
687   ByteSize native_receiver_sp_offset() {
688     return _native_receiver_sp_offset;
689   }
690   ByteSize native_basic_lock_sp_offset() {
691     return _native_basic_lock_sp_offset;
692   }
693 
694   // support for code generation
695   static int verified_entry_point_offset()        { return offset_of(nmethod, _verified_entry_point); }
696   static int osr_entry_point_offset()             { return offset_of(nmethod, _osr_entry_point); }
697   static int state_offset()                       { return offset_of(nmethod, _state); }
698 
699   virtual void metadata_do(MetadataClosure* f);
700 
701   NativeCallWrapper* call_wrapper_at(address call) const;
702   NativeCallWrapper* call_wrapper_before(address return_pc) const;
703   address call_instruction_address(address pc) const;
704 
705   virtual CompiledStaticCall* compiledStaticCall_at(Relocation* call_site) const;
706   virtual CompiledStaticCall* compiledStaticCall_at(address addr) const;
707   virtual CompiledStaticCall* compiledStaticCall_before(address addr) const;
708 
709   virtual void  make_deoptimized();
710   void finalize_relocations();
711 };
712 
713 #endif // SHARE_CODE_NMETHOD_HPP