< prev index next >

src/hotspot/share/code/nmethod.hpp

Print this page




  46 //  - oop array
  47 //  - data array
  48 //  - pcs
  49 //  [Exception handler table]
  50 //  - handler entry point array
  51 //  [Implicit Null Pointer exception table]
  52 //  - implicit null table array
  53 
  54 class nmethod : public CompiledMethod {
  55   friend class VMStructs;
  56   friend class JVMCIVMStructs;
  57   friend class NMethodSweeper;
  58   friend class CodeCache;  // scavengable oops
  59  private:
  60 
  61   // Shared fields for all nmethod's
  62   int       _entry_bci;        // != InvocationEntryBci if this nmethod is an on-stack replacement method
  63   jmethodID _jmethod_id;       // Cache of method()->jmethod_id()
  64 
  65 #if INCLUDE_JVMCI
  66   // Needed to keep nmethods alive that are not the default nmethod for the associated Method.
  67   oop       _jvmci_installed_code;
  68   oop       _speculation_log;













  69 #endif
  70 
  71   // To support simple linked-list chaining of nmethods:
  72   nmethod*  _osr_link;         // from InstanceKlass::osr_nmethods_head
  73 
  74   static nmethod* volatile _oops_do_mark_nmethods;
  75   nmethod*        volatile _oops_do_mark_link;
  76 
  77   // offsets for entry points
  78   address _entry_point;                      // entry point with class check
  79   address _verified_entry_point;             // entry point without class check
  80   address _osr_entry_point;                  // entry point for on stack replacement
  81 
  82   // Offsets for different nmethod parts
  83   int  _exception_offset;
  84   // Offset of the unwind handler if it exists
  85   int _unwind_handler_offset;
  86 
  87   int _consts_offset;
  88   int _stub_offset;


 175           OopMapSet* oop_maps);
 176 
 177   // Creation support
 178   nmethod(Method* method,
 179           CompilerType type,
 180           int nmethod_size,
 181           int compile_id,
 182           int entry_bci,
 183           CodeOffsets* offsets,
 184           int orig_pc_offset,
 185           DebugInformationRecorder *recorder,
 186           Dependencies* dependencies,
 187           CodeBuffer *code_buffer,
 188           int frame_size,
 189           OopMapSet* oop_maps,
 190           ExceptionHandlerTable* handler_table,
 191           ImplicitExceptionTable* nul_chk_table,
 192           AbstractCompiler* compiler,
 193           int comp_level
 194 #if INCLUDE_JVMCI
 195           , Handle installed_code,
 196           Handle speculation_log
 197 #endif
 198           );
 199 
 200   // helper methods
 201   void* operator new(size_t size, int nmethod_size, int comp_level) throw();
 202 
 203   const char* reloc_string_for(u_char* begin, u_char* end);
 204   // Returns true if this thread changed the state of the nmethod or
 205   // false if another thread performed the transition.
 206   bool make_not_entrant_or_zombie(unsigned int state);
 207   bool make_entrant() { Unimplemented(); return false; }
 208   void inc_decompile_count();
 209 
 210   // Inform external interfaces that a compiled method has been unloaded
 211   void post_compiled_method_unload();
 212 
 213   // Initailize fields to their default values
 214   void init_defaults();
 215 
 216   // Offsets


 219 
 220   address header_end() const                  { return (address)    header_begin() + header_size(); }
 221 
 222  public:
 223   // create nmethod with entry_bci
 224   static nmethod* new_nmethod(const methodHandle& method,
 225                               int compile_id,
 226                               int entry_bci,
 227                               CodeOffsets* offsets,
 228                               int orig_pc_offset,
 229                               DebugInformationRecorder* recorder,
 230                               Dependencies* dependencies,
 231                               CodeBuffer *code_buffer,
 232                               int frame_size,
 233                               OopMapSet* oop_maps,
 234                               ExceptionHandlerTable* handler_table,
 235                               ImplicitExceptionTable* nul_chk_table,
 236                               AbstractCompiler* compiler,
 237                               int comp_level
 238 #if INCLUDE_JVMCI
 239                               , Handle installed_code = Handle(),
 240                               Handle speculation_log = Handle()
 241 #endif
 242   );
 243 
 244   static nmethod* new_native_nmethod(const methodHandle& method,
 245                                      int compile_id,
 246                                      CodeBuffer *code_buffer,
 247                                      int vep_offset,
 248                                      int frame_complete,
 249                                      int frame_size,
 250                                      ByteSize receiver_sp_offset,
 251                                      ByteSize basic_lock_sp_offset,
 252                                      OopMapSet* oop_maps);
 253 
 254   // type info
 255   bool is_nmethod() const                         { return true; }
 256   bool is_osr_method() const                      { return _entry_bci != InvocationEntryBci; }
 257 
 258   // boundaries for different parts
 259   address consts_begin          () const          { return           header_begin() + _consts_offset        ; }
 260   address consts_end            () const          { return           code_begin()                           ; }


 416   // Only NMethodSweeper class is expected to use this. NMethodSweeper is not
 417   // expected to use any other private methods/data in this class.
 418 
 419  protected:
 420   void flush();
 421 
 422  public:
 423   // When true is returned, it is unsafe to remove this nmethod even if
 424   // it is a zombie, since the VM or the ServiceThread might still be
 425   // using it.
 426   bool is_locked_by_vm() const                    { return _lock_count >0; }
 427 
 428   // See comment at definition of _last_seen_on_stack
 429   void mark_as_seen_on_stack();
 430   bool can_convert_to_zombie();
 431 
 432   // Evolution support. We make old (discarded) compiled methods point to new Method*s.
 433   void set_method(Method* method) { _method = method; }
 434 
 435 #if INCLUDE_JVMCI
 436   oop jvmci_installed_code() { return _jvmci_installed_code ; }







 437   char* jvmci_installed_code_name(char* buf, size_t buflen);
 438 
 439   // Update the state of any InstalledCode instance associated with
 440   // this nmethod based on the current value of _state.
 441   void maybe_invalidate_installed_code();
 442 
 443   // Helper function to invalidate InstalledCode instances

 444   static void invalidate_installed_code(Handle installed_code, TRAPS);
 445 
 446   oop speculation_log() { return _speculation_log ; }



 447 
 448  private:


 449   void clear_jvmci_installed_code();
 450 




 451  public:
 452 #endif
 453 
 454  protected:
 455   virtual bool do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred);
 456 #if INCLUDE_JVMCI


 457   virtual bool do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred);
 458 #endif
 459 
 460  private:
 461   bool do_unloading_scopes(BoolObjectClosure* is_alive, bool unloading_occurred);
 462   //  Unload a nmethod if the *root object is dead.
 463   bool can_unload(BoolObjectClosure* is_alive, oop* root, bool unloading_occurred);
 464   bool unload_if_dead_at(RelocIterator *iter_at_oop, BoolObjectClosure* is_alive, bool unloading_occurred);
 465 
 466  public:
 467   void oops_do(OopClosure* f) { oops_do(f, false); }
 468   void oops_do(OopClosure* f, bool allow_zombie);
 469   bool detect_scavenge_root_oops();
 470   void verify_scavenge_root_oops() PRODUCT_RETURN;
 471 
 472   bool test_set_oops_do_mark();
 473   static void oops_do_marking_prologue();
 474   static void oops_do_marking_epilogue();
 475   static bool oops_do_marking_is_active() { return _oops_do_mark_nmethods != NULL; }
 476   bool test_oops_do_mark() { return _oops_do_mark_link != NULL; }




  46 //  - oop array
  47 //  - data array
  48 //  - pcs
  49 //  [Exception handler table]
  50 //  - handler entry point array
  51 //  [Implicit Null Pointer exception table]
  52 //  - implicit null table array
  53 
  54 class nmethod : public CompiledMethod {
  55   friend class VMStructs;
  56   friend class JVMCIVMStructs;
  57   friend class NMethodSweeper;
  58   friend class CodeCache;  // scavengable oops
  59  private:
  60 
  61   // Shared fields for all nmethod's
  62   int       _entry_bci;        // != InvocationEntryBci if this nmethod is an on-stack replacement method
  63   jmethodID _jmethod_id;       // Cache of method()->jmethod_id()
  64 
  65 #if INCLUDE_JVMCI
  66   // A weak reference to an InstalledCode object associated with
  67   // this nmethod.
  68   jweak     _jvmci_installed_code;
  69 
  70   // A weak reference to a SpeculationLog object associated with
  71   // this nmethod.
  72   jweak     _speculation_log;
  73 
  74   // Determines whether this nmethod is unloaded when the
  75   // referent in _jvmci_installed_code is cleared. This
  76   // will be false if the referent is initialized to a
  77   // HotSpotNMethod object whose isDefault field is true.
  78   // That is, installed code other than a "default"
  79   // HotSpotNMethod causes nmethod unloading.
  80   // This field is ignored once _jvmci_installed_code is NULL.
  81   bool _jvmci_installed_code_triggers_unloading;
  82 #endif
  83 
  84   // To support simple linked-list chaining of nmethods:
  85   nmethod*  _osr_link;         // from InstanceKlass::osr_nmethods_head
  86 
  87   static nmethod* volatile _oops_do_mark_nmethods;
  88   nmethod*        volatile _oops_do_mark_link;
  89 
  90   // offsets for entry points
  91   address _entry_point;                      // entry point with class check
  92   address _verified_entry_point;             // entry point without class check
  93   address _osr_entry_point;                  // entry point for on stack replacement
  94 
  95   // Offsets for different nmethod parts
  96   int  _exception_offset;
  97   // Offset of the unwind handler if it exists
  98   int _unwind_handler_offset;
  99 
 100   int _consts_offset;
 101   int _stub_offset;


 188           OopMapSet* oop_maps);
 189 
 190   // Creation support
 191   nmethod(Method* method,
 192           CompilerType type,
 193           int nmethod_size,
 194           int compile_id,
 195           int entry_bci,
 196           CodeOffsets* offsets,
 197           int orig_pc_offset,
 198           DebugInformationRecorder *recorder,
 199           Dependencies* dependencies,
 200           CodeBuffer *code_buffer,
 201           int frame_size,
 202           OopMapSet* oop_maps,
 203           ExceptionHandlerTable* handler_table,
 204           ImplicitExceptionTable* nul_chk_table,
 205           AbstractCompiler* compiler,
 206           int comp_level
 207 #if INCLUDE_JVMCI
 208           , jweak installed_code,
 209           jweak speculation_log
 210 #endif
 211           );
 212 
 213   // helper methods
 214   void* operator new(size_t size, int nmethod_size, int comp_level) throw();
 215 
 216   const char* reloc_string_for(u_char* begin, u_char* end);
 217   // Returns true if this thread changed the state of the nmethod or
 218   // false if another thread performed the transition.
 219   bool make_not_entrant_or_zombie(unsigned int state);
 220   bool make_entrant() { Unimplemented(); return false; }
 221   void inc_decompile_count();
 222 
 223   // Inform external interfaces that a compiled method has been unloaded
 224   void post_compiled_method_unload();
 225 
 226   // Initailize fields to their default values
 227   void init_defaults();
 228 
 229   // Offsets


 232 
 233   address header_end() const                  { return (address)    header_begin() + header_size(); }
 234 
 235  public:
 236   // create nmethod with entry_bci
 237   static nmethod* new_nmethod(const methodHandle& method,
 238                               int compile_id,
 239                               int entry_bci,
 240                               CodeOffsets* offsets,
 241                               int orig_pc_offset,
 242                               DebugInformationRecorder* recorder,
 243                               Dependencies* dependencies,
 244                               CodeBuffer *code_buffer,
 245                               int frame_size,
 246                               OopMapSet* oop_maps,
 247                               ExceptionHandlerTable* handler_table,
 248                               ImplicitExceptionTable* nul_chk_table,
 249                               AbstractCompiler* compiler,
 250                               int comp_level
 251 #if INCLUDE_JVMCI
 252                               , jweak installed_code = NULL,
 253                               jweak speculation_log = NULL
 254 #endif
 255   );
 256 
 257   static nmethod* new_native_nmethod(const methodHandle& method,
 258                                      int compile_id,
 259                                      CodeBuffer *code_buffer,
 260                                      int vep_offset,
 261                                      int frame_complete,
 262                                      int frame_size,
 263                                      ByteSize receiver_sp_offset,
 264                                      ByteSize basic_lock_sp_offset,
 265                                      OopMapSet* oop_maps);
 266 
 267   // type info
 268   bool is_nmethod() const                         { return true; }
 269   bool is_osr_method() const                      { return _entry_bci != InvocationEntryBci; }
 270 
 271   // boundaries for different parts
 272   address consts_begin          () const          { return           header_begin() + _consts_offset        ; }
 273   address consts_end            () const          { return           code_begin()                           ; }


 429   // Only NMethodSweeper class is expected to use this. NMethodSweeper is not
 430   // expected to use any other private methods/data in this class.
 431 
 432  protected:
 433   void flush();
 434 
 435  public:
 436   // When true is returned, it is unsafe to remove this nmethod even if
 437   // it is a zombie, since the VM or the ServiceThread might still be
 438   // using it.
 439   bool is_locked_by_vm() const                    { return _lock_count >0; }
 440 
 441   // See comment at definition of _last_seen_on_stack
 442   void mark_as_seen_on_stack();
 443   bool can_convert_to_zombie();
 444 
 445   // Evolution support. We make old (discarded) compiled methods point to new Method*s.
 446   void set_method(Method* method) { _method = method; }
 447 
 448 #if INCLUDE_JVMCI
 449   // Gets the InstalledCode object associated with this nmethod
 450   // which may be NULL if this nmethod was not compiled by JVMCI
 451   // or the weak reference has been cleared.
 452   oop jvmci_installed_code();
 453 
 454   // Copies the value of the name field in the InstalledCode
 455   // object (if any) associated with this nmethod into buf.
 456   // Returns the value of buf if it was updated otherwise NULL.
 457   char* jvmci_installed_code_name(char* buf, size_t buflen);
 458 
 459   // Updates the state of the InstalledCode (if any) associated with
 460   // this nmethod based on the current value of _state.
 461   void maybe_invalidate_installed_code();
 462 
 463   // Deoptimizes the nmethod (if any) in the address field of a given
 464   // InstalledCode object. The address field is zeroed upon return.
 465   static void invalidate_installed_code(Handle installed_code, TRAPS);
 466 
 467   // Gets the SpeculationLog object associated with this nmethod
 468   // which may be NULL if this nmethod was not compiled by JVMCI
 469   // or the weak reference has been cleared.
 470   oop speculation_log();
 471 
 472  private:
 473   // Deletes the weak reference (if any) to the InstalledCode object
 474   // associated with this nmethod.
 475   void clear_jvmci_installed_code();
 476 
 477   // Deletes the weak reference (if any) to the SpeculationLog object
 478   // associated with this nmethod.
 479   void clear_speculation_log();
 480 
 481  public:
 482 #endif
 483 
 484  protected:
 485   virtual bool do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred);
 486 #if INCLUDE_JVMCI
 487   // See comment for _jvmci_installed_code_triggers_unloading field.
 488   // Returns whether this nmethod was unloaded.
 489   virtual bool do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred);
 490 #endif
 491 
 492  private:
 493   bool do_unloading_scopes(BoolObjectClosure* is_alive, bool unloading_occurred);
 494   //  Unload a nmethod if the *root object is dead.
 495   bool can_unload(BoolObjectClosure* is_alive, oop* root, bool unloading_occurred);
 496   bool unload_if_dead_at(RelocIterator *iter_at_oop, BoolObjectClosure* is_alive, bool unloading_occurred);
 497 
 498  public:
 499   void oops_do(OopClosure* f) { oops_do(f, false); }
 500   void oops_do(OopClosure* f, bool allow_zombie);
 501   bool detect_scavenge_root_oops();
 502   void verify_scavenge_root_oops() PRODUCT_RETURN;
 503 
 504   bool test_set_oops_do_mark();
 505   static void oops_do_marking_prologue();
 506   static void oops_do_marking_epilogue();
 507   static bool oops_do_marking_is_active() { return _oops_do_mark_nmethods != NULL; }
 508   bool test_oops_do_mark() { return _oops_do_mark_link != NULL; }


< prev index next >