< prev index next >

src/hotspot/share/code/nmethod.hpp

Print this page

  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/codeBlob.hpp"
  29 #include "code/pcDesc.hpp"

  30 #include "oops/metadata.hpp"
  31 #include "oops/method.hpp"
  32 #include "runtime/mutexLocker.hpp"
  33 
  34 class AbstractCompiler;
  35 class CompiledDirectCall;
  36 class CompiledIC;
  37 class CompiledICData;
  38 class CompileTask;
  39 class DepChange;
  40 class Dependencies;
  41 class DirectiveSet;
  42 class DebugInformationRecorder;
  43 class ExceptionHandlerTable;
  44 class ICacheInvalidationContext;
  45 class ImplicitExceptionTable;
  46 class JvmtiThreadState;
  47 class MetadataClosure;
  48 class NativeCallWrapper;
  49 class OopIterateClosure;

 191   };
 192 
 193   // nmethod's read-only data
 194   address _immutable_data;
 195 
 196   PcDescContainer* _pc_desc_container;
 197   ExceptionCache* volatile _exception_cache;
 198 
 199   void* _gc_data;
 200 
 201   struct oops_do_mark_link; // Opaque data type.
 202   static nmethod*    volatile _oops_do_mark_nmethods;
 203   oops_do_mark_link* volatile _oops_do_mark_link;
 204 
 205   CompiledICData* _compiled_ic_data;
 206 
 207   // offsets for entry points
 208   address  _osr_entry_point;       // entry point for on stack replacement
 209   uint16_t _entry_offset;          // entry point with class check
 210   uint16_t _verified_entry_offset; // entry point without class check



 211   int      _entry_bci;             // != InvocationEntryBci if this nmethod is an on-stack replacement method
 212   int      _immutable_data_size;
 213 
 214   // _consts_offset == _content_offset because SECT_CONSTS is first in code buffer
 215 
 216   int _skipped_instructions_size;
 217 
 218   int _stub_offset;
 219 
 220   // Offsets for different stubs section parts
 221   int _exception_offset;
 222   // All deoptee's will resume execution at this location described by
 223   // this offset.
 224   int _deopt_handler_entry_offset;
 225   // Offset (from insts_end) of the unwind handler if it exists
 226   int16_t  _unwind_handler_offset;
 227   // Number of arguments passed on the stack
 228   uint16_t _num_stack_arg_slots;
 229 
 230   // Offset in immutable data section

 657   int skipped_instructions_size () const { return _skipped_instructions_size; }
 658   int total_size() const;
 659 
 660   // Containment
 661   bool consts_contains         (address addr) const { return consts_begin       () <= addr && addr < consts_end       (); }
 662   // Returns true if a given address is in the 'insts' section. The method
 663   // insts_contains_inclusive() is end-inclusive.
 664   bool insts_contains          (address addr) const { return insts_begin        () <= addr && addr < insts_end        (); }
 665   bool insts_contains_inclusive(address addr) const { return insts_begin        () <= addr && addr <= insts_end       (); }
 666   bool stub_contains           (address addr) const { return stub_begin         () <= addr && addr < stub_end         (); }
 667   bool oops_contains           (oop*    addr) const { return oops_begin         () <= addr && addr < oops_end         (); }
 668   bool metadata_contains       (Metadata** addr) const { return metadata_begin  () <= addr && addr < metadata_end     (); }
 669   bool scopes_data_contains    (address addr) const { return scopes_data_begin  () <= addr && addr < scopes_data_end  (); }
 670   bool scopes_pcs_contains     (PcDesc* addr) const { return scopes_pcs_begin   () <= addr && addr < scopes_pcs_end   (); }
 671   bool handler_table_contains  (address addr) const { return handler_table_begin() <= addr && addr < handler_table_end(); }
 672   bool nul_chk_table_contains  (address addr) const { return nul_chk_table_begin() <= addr && addr < nul_chk_table_end(); }
 673 
 674   // entry points
 675   address entry_point() const          { return code_begin() + _entry_offset;          } // normal entry point
 676   address verified_entry_point() const { return code_begin() + _verified_entry_offset; } // if klass is correct



 677 
 678   enum : signed char { not_installed = -1, // in construction, only the owner doing the construction is
 679                                            // allowed to advance state
 680                        in_use        = 0,  // executable nmethod
 681                        not_entrant   = 1   // marked for deoptimization but activations may still exist
 682   };
 683 
 684   // flag accessing and manipulation
 685   bool is_not_installed() const        { return _state == not_installed; }
 686   bool is_in_use() const               { return _state <= in_use; }
 687   bool is_not_entrant() const          { return _state == not_entrant; }
 688   int  get_state() const               { return _state; }
 689 
 690   void clear_unloading_state();
 691   // Heuristically deduce an nmethod isn't worth keeping around
 692   bool is_cold();
 693   bool is_unloading();
 694   void do_unloading(bool unloading_occurred);
 695 
 696   bool make_in_use() {

 716   }
 717 
 718   // tells whether frames described by this nmethod can be deoptimized
 719   // note: native wrappers cannot be deoptimized.
 720   bool can_be_deoptimized() const { return is_java_method(); }
 721 
 722   bool has_dependencies()                         { return dependencies_size() != 0; }
 723   void print_dependencies_on(outputStream* out) PRODUCT_RETURN;
 724   void flush_dependencies();
 725 
 726   template<typename T>
 727   T* gc_data() const                              { return reinterpret_cast<T*>(_gc_data); }
 728   template<typename T>
 729   void set_gc_data(T* gc_data)                    { _gc_data = reinterpret_cast<void*>(gc_data); }
 730 
 731   bool  has_unsafe_access() const                 { return _flags.has_unsafe_access(); }
 732   bool  has_monitors() const                      { return _flags.has_monitors(); }
 733   bool  has_scoped_access() const                 { return _flags.has_scoped_access(); }
 734   bool  has_wide_vectors() const                  { return _flags.has_wide_vectors(); }
 735 










 736   bool  has_flushed_dependencies() const          { return _has_flushed_dependencies; }
 737   void  set_has_flushed_dependencies(bool z)      {
 738     assert(!has_flushed_dependencies(), "should only happen once");
 739     _has_flushed_dependencies = z;
 740   }
 741 
 742   bool  is_unlinked() const                       { return _is_unlinked; }
 743   void  set_is_unlinked()                         {
 744      assert(!_is_unlinked, "already unlinked");
 745       _is_unlinked = true;
 746   }
 747 
 748   int   comp_level() const                        { return _comp_level; }
 749 
 750   // Support for oops in scopes and relocs:
 751   // Note: index 0 is reserved for null.
 752   oop   oop_at(int index) const;
 753   oop   oop_at_phantom(int index) const; // phantom reference
 754   oop*  oop_addr_at(int index) const {  // for GC
 755     // relocation indexes are biased by 1 (because 0 is reserved)

 795   address handler_for_exception_and_pc(Handle exception, address pc);
 796   void add_handler_for_exception_and_pc(Handle exception, address pc, address handler);
 797   void clean_exception_cache();
 798 
 799   void add_exception_cache_entry(ExceptionCache* new_entry);
 800   ExceptionCache* exception_cache_entry_for_exception(Handle exception);
 801 
 802 
 803   // Deopt
 804   // Return true is the PC is one would expect if the frame is being deopted.
 805   inline bool is_deopt_pc(address pc);
 806   inline bool is_deopt_entry(address pc);
 807 
 808   // Accessor/mutator for the original pc of a frame before a frame was deopted.
 809   address get_original_pc(const frame* fr) { return *orig_pc_addr(fr); }
 810   void    set_original_pc(const frame* fr, address pc) { *orig_pc_addr(fr) = pc; }
 811 
 812   const char* state() const;
 813 
 814   bool inlinecache_check_contains(address addr) const {
 815     return (addr >= code_begin() && addr < verified_entry_point());
 816   }
 817 
 818   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f);
 819 
 820   // implicit exceptions support
 821   address continuation_for_implicit_exception(address pc);
 822 
 823   // Inline cache support for class unloading and nmethod unloading
 824  private:
 825   void cleanup_inline_caches_impl(bool unloading_occurred, bool clean_all);
 826 
 827  public:
 828   // Serial version used by whitebox test
 829   void cleanup_inline_caches_whitebox();
 830 
 831   void clear_inline_caches();
 832 
 833   // Execute nmethod barrier code, as if entering through nmethod call.
 834   void run_nmethod_entry_barrier();
 835 

1005 
1006   // Logging
1007   void log_identity(xmlStream* log) const;
1008   void log_new_nmethod() const;
1009   void log_relocated_nmethod(nmethod* original) const;
1010   void log_state_change(InvalidationReason invalidation_reason) const;
1011 
1012   // Prints block-level comments, including nmethod specific block labels:
1013   void print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;
1014   const char* nmethod_section_label(address pos) const;
1015 
1016   // returns whether this nmethod has code comments.
1017   bool has_code_comment(address begin, address end);
1018   // Prints a comment for one native instruction (reloc info, pc desc)
1019   void print_code_comment_on(outputStream* st, int column, address begin, address end);
1020 
1021   // tells if this compiled method is dependent on the given changes,
1022   // and the changes have invalidated it
1023   bool check_dependency_on(DepChange& changes);
1024 
1025   // Fast breakpoint support. Tells if this compiled method is
1026   // dependent on the given method. Returns true if this nmethod
1027   // corresponds to the given method as well.

1028   bool is_dependent_on_method(Method* dependee);
1029 
1030   // JVMTI's GetLocalInstance() support
1031   ByteSize native_receiver_sp_offset() {
1032     assert(is_native_method(), "sanity");
1033     return _native_receiver_sp_offset;
1034   }
1035   ByteSize native_basic_lock_sp_offset() {
1036     assert(is_native_method(), "sanity");
1037     return _native_basic_lock_sp_offset;
1038   }
1039 
1040   // support for code generation
1041   static ByteSize osr_entry_point_offset() { return byte_offset_of(nmethod, _osr_entry_point); }
1042   static ByteSize state_offset()           { return byte_offset_of(nmethod, _state); }
1043 
1044   void metadata_do(MetadataClosure* f);
1045 
1046   address call_instruction_address(address pc) const;
1047 

  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/codeBlob.hpp"
  29 #include "code/pcDesc.hpp"
  30 #include "compiler/compilerDefinitions.hpp"
  31 #include "oops/metadata.hpp"
  32 #include "oops/method.hpp"
  33 #include "runtime/mutexLocker.hpp"
  34 
  35 class AbstractCompiler;
  36 class CompiledDirectCall;
  37 class CompiledIC;
  38 class CompiledICData;
  39 class CompileTask;
  40 class DepChange;
  41 class Dependencies;
  42 class DirectiveSet;
  43 class DebugInformationRecorder;
  44 class ExceptionHandlerTable;
  45 class ICacheInvalidationContext;
  46 class ImplicitExceptionTable;
  47 class JvmtiThreadState;
  48 class MetadataClosure;
  49 class NativeCallWrapper;
  50 class OopIterateClosure;

 192   };
 193 
 194   // nmethod's read-only data
 195   address _immutable_data;
 196 
 197   PcDescContainer* _pc_desc_container;
 198   ExceptionCache* volatile _exception_cache;
 199 
 200   void* _gc_data;
 201 
 202   struct oops_do_mark_link; // Opaque data type.
 203   static nmethod*    volatile _oops_do_mark_nmethods;
 204   oops_do_mark_link* volatile _oops_do_mark_link;
 205 
 206   CompiledICData* _compiled_ic_data;
 207 
 208   // offsets for entry points
 209   address  _osr_entry_point;       // entry point for on stack replacement
 210   uint16_t _entry_offset;          // entry point with class check
 211   uint16_t _verified_entry_offset; // entry point without class check
 212   uint16_t _inline_entry_offset;             // inline type entry point (unpack all inline type args) with class check
 213   uint16_t _verified_inline_entry_offset;    // inline type entry point (unpack all inline type args) without class check
 214   uint16_t _verified_inline_ro_entry_offset; // inline type entry point (unpack receiver only) without class check
 215   int      _entry_bci;             // != InvocationEntryBci if this nmethod is an on-stack replacement method
 216   int      _immutable_data_size;
 217 
 218   // _consts_offset == _content_offset because SECT_CONSTS is first in code buffer
 219 
 220   int _skipped_instructions_size;
 221 
 222   int _stub_offset;
 223 
 224   // Offsets for different stubs section parts
 225   int _exception_offset;
 226   // All deoptee's will resume execution at this location described by
 227   // this offset.
 228   int _deopt_handler_entry_offset;
 229   // Offset (from insts_end) of the unwind handler if it exists
 230   int16_t  _unwind_handler_offset;
 231   // Number of arguments passed on the stack
 232   uint16_t _num_stack_arg_slots;
 233 
 234   // Offset in immutable data section

 661   int skipped_instructions_size () const { return _skipped_instructions_size; }
 662   int total_size() const;
 663 
 664   // Containment
 665   bool consts_contains         (address addr) const { return consts_begin       () <= addr && addr < consts_end       (); }
 666   // Returns true if a given address is in the 'insts' section. The method
 667   // insts_contains_inclusive() is end-inclusive.
 668   bool insts_contains          (address addr) const { return insts_begin        () <= addr && addr < insts_end        (); }
 669   bool insts_contains_inclusive(address addr) const { return insts_begin        () <= addr && addr <= insts_end       (); }
 670   bool stub_contains           (address addr) const { return stub_begin         () <= addr && addr < stub_end         (); }
 671   bool oops_contains           (oop*    addr) const { return oops_begin         () <= addr && addr < oops_end         (); }
 672   bool metadata_contains       (Metadata** addr) const { return metadata_begin  () <= addr && addr < metadata_end     (); }
 673   bool scopes_data_contains    (address addr) const { return scopes_data_begin  () <= addr && addr < scopes_data_end  (); }
 674   bool scopes_pcs_contains     (PcDesc* addr) const { return scopes_pcs_begin   () <= addr && addr < scopes_pcs_end   (); }
 675   bool handler_table_contains  (address addr) const { return handler_table_begin() <= addr && addr < handler_table_end(); }
 676   bool nul_chk_table_contains  (address addr) const { return nul_chk_table_begin() <= addr && addr < nul_chk_table_end(); }
 677 
 678   // entry points
 679   address entry_point() const          { return code_begin() + _entry_offset;          } // normal entry point
 680   address verified_entry_point() const { return code_begin() + _verified_entry_offset; } // if klass is correct
 681   address inline_entry_point() const              { return code_begin() + _inline_entry_offset; }             // inline type entry point (unpack all inline type args)
 682   address verified_inline_entry_point() const     { return code_begin() + _verified_inline_entry_offset; }    // inline type entry point (unpack all inline type args) without class check
 683   address verified_inline_ro_entry_point() const  { return code_begin() + _verified_inline_ro_entry_offset; } // inline type entry point (only unpack receiver) without class check
 684 
 685   enum : signed char { not_installed = -1, // in construction, only the owner doing the construction is
 686                                            // allowed to advance state
 687                        in_use        = 0,  // executable nmethod
 688                        not_entrant   = 1   // marked for deoptimization but activations may still exist
 689   };
 690 
 691   // flag accessing and manipulation
 692   bool is_not_installed() const        { return _state == not_installed; }
 693   bool is_in_use() const               { return _state <= in_use; }
 694   bool is_not_entrant() const          { return _state == not_entrant; }
 695   int  get_state() const               { return _state; }
 696 
 697   void clear_unloading_state();
 698   // Heuristically deduce an nmethod isn't worth keeping around
 699   bool is_cold();
 700   bool is_unloading();
 701   void do_unloading(bool unloading_occurred);
 702 
 703   bool make_in_use() {

 723   }
 724 
 725   // tells whether frames described by this nmethod can be deoptimized
 726   // note: native wrappers cannot be deoptimized.
 727   bool can_be_deoptimized() const { return is_java_method(); }
 728 
 729   bool has_dependencies()                         { return dependencies_size() != 0; }
 730   void print_dependencies_on(outputStream* out) PRODUCT_RETURN;
 731   void flush_dependencies();
 732 
 733   template<typename T>
 734   T* gc_data() const                              { return reinterpret_cast<T*>(_gc_data); }
 735   template<typename T>
 736   void set_gc_data(T* gc_data)                    { _gc_data = reinterpret_cast<void*>(gc_data); }
 737 
 738   bool  has_unsafe_access() const                 { return _flags.has_unsafe_access(); }
 739   bool  has_monitors() const                      { return _flags.has_monitors(); }
 740   bool  has_scoped_access() const                 { return _flags.has_scoped_access(); }
 741   bool  has_wide_vectors() const                  { return _flags.has_wide_vectors(); }
 742 
 743   bool  needs_stack_repair() const {
 744     if (is_compiled_by_c1()) {
 745       return method()->c1_needs_stack_repair();
 746     } else if (is_compiled_by_c2()) {
 747       return method()->c2_needs_stack_repair();
 748     } else {
 749       return false;
 750     }
 751   }
 752 
 753   bool  has_flushed_dependencies() const          { return _has_flushed_dependencies; }
 754   void  set_has_flushed_dependencies(bool z)      {
 755     assert(!has_flushed_dependencies(), "should only happen once");
 756     _has_flushed_dependencies = z;
 757   }
 758 
 759   bool  is_unlinked() const                       { return _is_unlinked; }
 760   void  set_is_unlinked()                         {
 761      assert(!_is_unlinked, "already unlinked");
 762       _is_unlinked = true;
 763   }
 764 
 765   int   comp_level() const                        { return _comp_level; }
 766 
 767   // Support for oops in scopes and relocs:
 768   // Note: index 0 is reserved for null.
 769   oop   oop_at(int index) const;
 770   oop   oop_at_phantom(int index) const; // phantom reference
 771   oop*  oop_addr_at(int index) const {  // for GC
 772     // relocation indexes are biased by 1 (because 0 is reserved)

 812   address handler_for_exception_and_pc(Handle exception, address pc);
 813   void add_handler_for_exception_and_pc(Handle exception, address pc, address handler);
 814   void clean_exception_cache();
 815 
 816   void add_exception_cache_entry(ExceptionCache* new_entry);
 817   ExceptionCache* exception_cache_entry_for_exception(Handle exception);
 818 
 819 
 820   // Deopt
 821   // Return true is the PC is one would expect if the frame is being deopted.
 822   inline bool is_deopt_pc(address pc);
 823   inline bool is_deopt_entry(address pc);
 824 
 825   // Accessor/mutator for the original pc of a frame before a frame was deopted.
 826   address get_original_pc(const frame* fr) { return *orig_pc_addr(fr); }
 827   void    set_original_pc(const frame* fr, address pc) { *orig_pc_addr(fr) = pc; }
 828 
 829   const char* state() const;
 830 
 831   bool inlinecache_check_contains(address addr) const {
 832     return (addr >= code_begin() && (addr < verified_entry_point() || addr < verified_inline_entry_point()));
 833   }
 834 
 835   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f);
 836 
 837   // implicit exceptions support
 838   address continuation_for_implicit_exception(address pc);
 839 
 840   // Inline cache support for class unloading and nmethod unloading
 841  private:
 842   void cleanup_inline_caches_impl(bool unloading_occurred, bool clean_all);
 843 
 844  public:
 845   // Serial version used by whitebox test
 846   void cleanup_inline_caches_whitebox();
 847 
 848   void clear_inline_caches();
 849 
 850   // Execute nmethod barrier code, as if entering through nmethod call.
 851   void run_nmethod_entry_barrier();
 852 

1022 
1023   // Logging
1024   void log_identity(xmlStream* log) const;
1025   void log_new_nmethod() const;
1026   void log_relocated_nmethod(nmethod* original) const;
1027   void log_state_change(InvalidationReason invalidation_reason) const;
1028 
1029   // Prints block-level comments, including nmethod specific block labels:
1030   void print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;
1031   const char* nmethod_section_label(address pos) const;
1032 
1033   // returns whether this nmethod has code comments.
1034   bool has_code_comment(address begin, address end);
1035   // Prints a comment for one native instruction (reloc info, pc desc)
1036   void print_code_comment_on(outputStream* st, int column, address begin, address end);
1037 
1038   // tells if this compiled method is dependent on the given changes,
1039   // and the changes have invalidated it
1040   bool check_dependency_on(DepChange& changes);
1041 
1042   // Tells if this compiled method is dependent on the given method.
1043   // Returns true if this nmethod corresponds to the given method as well.
1044   // It is used for fast breakpoint support and updating the calling convention
1045   // in case of mismatch.
1046   bool is_dependent_on_method(Method* dependee);
1047 
1048   // JVMTI's GetLocalInstance() support
1049   ByteSize native_receiver_sp_offset() {
1050     assert(is_native_method(), "sanity");
1051     return _native_receiver_sp_offset;
1052   }
1053   ByteSize native_basic_lock_sp_offset() {
1054     assert(is_native_method(), "sanity");
1055     return _native_basic_lock_sp_offset;
1056   }
1057 
1058   // support for code generation
1059   static ByteSize osr_entry_point_offset() { return byte_offset_of(nmethod, _osr_entry_point); }
1060   static ByteSize state_offset()           { return byte_offset_of(nmethod, _state); }
1061 
1062   void metadata_do(MetadataClosure* f);
1063 
1064   address call_instruction_address(address pc) const;
1065 
< prev index next >