< prev index next >

src/hotspot/share/runtime/frame.hpp

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_RUNTIME_FRAME_HPP
  26 #define SHARE_RUNTIME_FRAME_HPP
  27 
  28 #include "oops/method.hpp"
  29 #include "runtime/basicLock.hpp"
  30 #include "runtime/monitorChunk.hpp"
  31 #include "runtime/registerMap.hpp"
  32 #include "utilities/macros.hpp"
  33 #ifdef ZERO
  34 # include "stack_zero.hpp"
  35 #endif
  36 
  37 typedef class BytecodeInterpreter* interpreterState;
  38 
  39 class CodeBlob;

  40 class FrameValues;
  41 class vframeArray;
  42 class JavaCallWrapper;
  43 
  44 
  45 // A frame represents a physical stack frame (an activation).  Frames
  46 // can be C or Java frames, and the Java frames can be interpreted or
  47 // compiled.  In contrast, vframes represent source-level activations,
  48 // so that one physical frame can correspond to multiple source level
  49 // frames because of inlining.
  50 
  51 class frame {
  52  private:
  53   // Instance variables:
  54   intptr_t* _sp; // stack pointer (from Thread::last_Java_sp)






  55   address   _pc; // program counter (the next instruction after the call)
  56 
  57   CodeBlob* _cb; // CodeBlob that "owns" pc
  58   enum deopt_state {
  59     not_deoptimized,
  60     is_deoptimized,
  61     unknown
  62   };
  63 
  64   deopt_state _deopt_state;
  65 
  66  public:
  67   // Constructors
  68   frame();
  69 
  70 #ifndef PRODUCT
  71   // This is a generic constructor which is only used by pns() in debug.cpp.
  72   // pns (i.e. print native stack) uses this constructor to create a starting
  73   // frame for stack walking. The implementation of this constructor is platform
  74   // dependent (i.e. SPARC doesn't need an 'fp' argument an will ignore it) but
  75   // we want to keep the signature generic because pns() is shared code.
  76   frame(void* sp, void* fp, void* pc);
  77 #endif
  78 
  79   // Accessors
  80 
  81   // pc: Returns the pc at which this frame will continue normally.
  82   // It must point at the beginning of the next instruction to execute.
  83   address pc() const             { return _pc; }
  84 
  85   // This returns the pc that if you were in the debugger you'd see. Not
  86   // the idealized value in the frame object. This undoes the magic conversion
  87   // that happens for deoptimized frames. In addition it makes the value the
  88   // hardware would want to see in the native frame. The only user (at this point)
  89   // is deoptimization. It likely no one else should ever use it.
  90   address raw_pc() const;
  91 
  92   void set_pc( address   newpc );


  93 
  94   intptr_t* sp() const           { return _sp; }
  95   void set_sp( intptr_t* newsp ) { _sp = newsp; }
  96 



  97 
  98   CodeBlob* cb() const           { return _cb; }









  99 
 100   // patching operations
 101   void   patch_pc(Thread* thread, address pc);
 102 
 103   // Every frame needs to return a unique id which distinguishes it from all other frames.
 104   // For sparc and ia32 use sp. ia64 can have memory frames that are empty so multiple frames
 105   // will have identical sp values. For ia64 the bsp (fp) value will serve. No real frame
 106   // should have an id() of NULL so it is a distinguishing value for an unmatchable frame.
 107   // We also have relationals which allow comparing a frame to anoth frame's id() allow
 108   // us to distinguish younger (more recent activation) from older (less recent activations)
 109   // A NULL id is only valid when comparing for equality.
 110 
 111   intptr_t* id(void) const;
 112   bool is_younger(intptr_t* id) const;
 113   bool is_older(intptr_t* id) const;
 114 
 115   // testers
 116 
 117   // Compares for strict equality. Rarely used or needed.
 118   // It can return a different result than f1.id() == f2.id()
 119   bool equal(frame other) const;
 120 
 121   // type testers

 122   bool is_interpreted_frame()    const;
 123   bool is_java_frame()           const;
 124   bool is_entry_frame()          const;             // Java frame called from C?
 125   bool is_stub_frame()           const;
 126   bool is_ignored_frame()        const;
 127   bool is_native_frame()         const;
 128   bool is_runtime_frame()        const;
 129   bool is_compiled_frame()       const;
 130   bool is_safepoint_blob_frame() const;
 131   bool is_deoptimized_frame()    const;
 132 
 133   // testers
 134   bool is_first_frame() const; // oldest frame? (has no sender)
 135   bool is_first_java_frame() const;              // same for Java frame
 136 
 137   bool is_interpreted_frame_valid(JavaThread* thread) const;       // performs sanity checks on interpreted frames.
 138 
 139   // tells whether this frame is marked for deoptimization
 140   bool should_be_deoptimized() const;
 141 
 142   // tells whether this frame can be deoptimized
 143   bool can_be_deoptimized() const;
 144 
 145   // returns the frame size in stack slots
 146   int frame_size(RegisterMap* map) const;
 147 
 148   // returns the sending frame
 149   frame sender(RegisterMap* map) const;
 150 



 151   bool safe_for_sender(JavaThread *thread);
 152 
 153   // returns the sender, but skips conversion frames
 154   frame real_sender(RegisterMap* map) const;
 155 
 156   // returns the the sending Java frame, skipping any intermediate C frames
 157   // NB: receiver must not be first frame
 158   frame java_sender() const;
 159 
 160  private:
 161   // Helper methods for better factored code in frame::sender

 162   frame sender_for_compiled_frame(RegisterMap* map) const;
 163   frame sender_for_entry_frame(RegisterMap* map) const;
 164   frame sender_for_interpreter_frame(RegisterMap* map) const;
 165   frame sender_for_native_frame(RegisterMap* map) const;
 166 
 167   bool is_entry_frame_valid(JavaThread* thread) const;
 168 
 169   // All frames:
 170 
 171   // A low-level interface for vframes:
 172 
 173  public:
 174 
 175   intptr_t* addr_at(int index) const             { return &fp()[index];    }
 176   intptr_t  at(int index) const                  { return *addr_at(index); }
 177 
 178   // accessors for locals
 179   oop obj_at(int offset) const                   { return *obj_at_addr(offset);  }
 180   void obj_at_put(int offset, oop value)         { *obj_at_addr(offset) = value; }
 181 


 338 
 339  public:
 340   oop saved_oop_result(RegisterMap* map) const;
 341   void set_saved_oop_result(RegisterMap* map, oop obj);
 342 
 343   // For debugging
 344  private:
 345   const char* print_name() const;
 346 
 347   void describe_pd(FrameValues& values, int frame_no);
 348 
 349  public:
 350   void print_value() const { print_value_on(tty,NULL); }
 351   void print_value_on(outputStream* st, JavaThread *thread) const;
 352   void print_on(outputStream* st) const;
 353   void interpreter_frame_print_on(outputStream* st) const;
 354   void print_on_error(outputStream* st, char* buf, int buflen, bool verbose = false) const;
 355   static void print_C_frame(outputStream* st, char* buf, int buflen, address pc);
 356 
 357   // Add annotated descriptions of memory locations belonging to this frame to values
 358   void describe(FrameValues& values, int frame_no);
 359 
 360   // Conversion from a VMReg to physical stack location
 361   oop* oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const;

 362 
 363   // Oops-do's
 364   void oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix, const RegisterMap* reg_map, OopClosure* f);
 365   void oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache = true);

 366 
 367  private:
 368   void oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f);

 369 
 370   // Iteration of oops
 371   void oops_do_internal(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache);
 372   void oops_entry_do(OopClosure* f, const RegisterMap* map);
 373   void oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* map);
 374   int adjust_offset(Method* method, int index); // helper for above fn
 375  public:
 376   // Memory management
 377   void oops_do(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map) { oops_do_internal(f, cf, map, true); }

 378   void nmethods_do(CodeBlobClosure* cf);
 379 
 380   // RedefineClasses support for finding live interpreted methods on the stack
 381   void metadata_do(MetadataClosure* f);
 382 
 383   // Verification
 384   void verify(const RegisterMap* map);
 385   static bool verify_return_pc(address x);
 386   // Usage:
 387   // assert(frame::verify_return_pc(return_address), "must be a return pc");
 388 
 389   NOT_PRODUCT(void pd_ps();)  // platform dependent frame printing
 390 
 391 #include CPU_HEADER(frame)
 392 
 393 };
 394 
 395 #ifndef PRODUCT
 396 // A simple class to describe a location on the stack
 397 class FrameValue {


 439 #endif
 440 
 441 //
 442 // StackFrameStream iterates through the frames of a thread starting from
 443 // top most frame. It automatically takes care of updating the location of
 444 // all (callee-saved) registers. Notice: If a thread is stopped at
 445 // a safepoint, all registers are saved, not only the callee-saved ones.
 446 //
 447 // Use:
 448 //
 449 //   for(StackFrameStream fst(thread); !fst.is_done(); fst.next()) {
 450 //     ...
 451 //   }
 452 //
 453 class StackFrameStream : public StackObj {
 454  private:
 455   frame       _fr;
 456   RegisterMap _reg_map;
 457   bool        _is_done;
 458  public:
 459    StackFrameStream(JavaThread *thread, bool update = true);
 460 
 461   // Iteration
 462   inline bool is_done();
 463   void next()                     { if (!_is_done) _fr = _fr.sender(&_reg_map); }
 464 
 465   // Query
 466   frame *current()                { return &_fr; }
 467   RegisterMap* register_map()     { return &_reg_map; }
 468 };
 469 
 470 #endif // SHARE_RUNTIME_FRAME_HPP


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_RUNTIME_FRAME_HPP
  26 #define SHARE_RUNTIME_FRAME_HPP
  27 
  28 #include "oops/method.hpp"
  29 #include "runtime/basicLock.hpp"
  30 #include "runtime/monitorChunk.hpp"
  31 #include "runtime/registerMap.hpp"
  32 #include "utilities/macros.hpp"
  33 #ifdef ZERO
  34 # include "stack_zero.hpp"
  35 #endif
  36 
  37 typedef class BytecodeInterpreter* interpreterState;
  38 
  39 class CodeBlob;
  40 class CodeBlobLookup;
  41 class FrameValues;
  42 class vframeArray;
  43 class JavaCallWrapper;
  44 
  45 
  46 // A frame represents a physical stack frame (an activation).  Frames
  47 // can be C or Java frames, and the Java frames can be interpreted or
  48 // compiled.  In contrast, vframes represent source-level activations,
  49 // so that one physical frame can correspond to multiple source level
  50 // frames because of inlining.
  51 
  52 class frame {
  53  private:
  54   // Instance variables:
  55   union {
  56     intptr_t* _sp; // stack pointer (from Thread::last_Java_sp)
  57     struct {
  58       int _sp;
  59       int _ref_sp;
  60     } _cont_sp;
  61   };
  62   address   _pc; // program counter (the next instruction after the call)
  63   mutable CodeBlob* _cb; // CodeBlob that "owns" pc
  64   mutable const ImmutableOopMap* _oop_map; // oop map, for compiled/stubs frames only
  65   enum deopt_state {
  66     not_deoptimized,
  67     is_deoptimized,
  68     unknown
  69   };
  70 
  71   deopt_state _deopt_state;
  72 
  73  public:
  74   // Constructors
  75   frame();
  76 
  77 #ifndef PRODUCT
  78   // This is a generic constructor which is only used by pns() in debug.cpp.
  79   // pns (i.e. print native stack) uses this constructor to create a starting
  80   // frame for stack walking. The implementation of this constructor is platform
  81   // dependent (i.e. SPARC doesn't need an 'fp' argument an will ignore it) but
  82   // we want to keep the signature generic because pns() is shared code.
  83   frame(void* sp, void* fp, void* pc);
  84 #endif
  85 
  86   // Accessors
  87 
  88   // pc: Returns the pc at which this frame will continue normally.
  89   // It must point at the beginning of the next instruction to execute.
  90   address pc() const             { return _pc; }
  91 
  92   // This returns the pc that if you were in the debugger you'd see. Not
  93   // the idealized value in the frame object. This undoes the magic conversion
  94   // that happens for deoptimized frames. In addition it makes the value the
  95   // hardware would want to see in the native frame. The only user (at this point)
  96   // is deoptimization. It likely no one else should ever use it.
  97   address raw_pc() const;
  98 
  99   void set_pc( address   newpc );
 100   void set_pc_preserve_deopt( address   newpc );
 101   void set_pc_preserve_deopt(address newpc, CodeBlob* cb);
 102 
 103   intptr_t* sp() const           { return _sp; }
 104   void set_sp( intptr_t* newsp ) { _sp = newsp; }
 105 
 106   int cont_sp()     const { return _cont_sp._sp; }
 107   int cont_ref_sp() const { return _cont_sp._ref_sp; }
 108   int cont_unextended_sp() const;
 109 
 110   CodeBlob* cb() const           { return _cb; }
 111   inline CodeBlob* get_cb() const;
 112   // inline void set_cb(CodeBlob* cb);
 113 
 114   const ImmutableOopMap* oop_map() const {
 115     if (_oop_map == NULL) {
 116       _oop_map = get_oop_map();
 117     }
 118     return _oop_map;
 119   }
 120 
 121   // patching operations
 122   void   patch_pc(Thread* thread, address pc);
 123 
 124   // Every frame needs to return a unique id which distinguishes it from all other frames.
 125   // For sparc and ia32 use sp. ia64 can have memory frames that are empty so multiple frames
 126   // will have identical sp values. For ia64 the bsp (fp) value will serve. No real frame
 127   // should have an id() of NULL so it is a distinguishing value for an unmatchable frame.
 128   // We also have relationals which allow comparing a frame to anoth frame's id() allow
 129   // us to distinguish younger (more recent activation) from older (less recent activations)
 130   // A NULL id is only valid when comparing for equality.
 131 
 132   intptr_t* id(void) const;
 133   bool is_younger(intptr_t* id) const;
 134   bool is_older(intptr_t* id) const;
 135 
 136   // testers
 137 
 138   // Compares for strict equality. Rarely used or needed.
 139   // It can return a different result than f1.id() == f2.id()
 140   bool equal(frame other) const;
 141 
 142   // type testers
 143   bool is_empty()                const { return _pc == NULL; }
 144   bool is_interpreted_frame()    const;
 145   bool is_java_frame()           const;
 146   bool is_entry_frame()          const;             // Java frame called from C?
 147   bool is_stub_frame()           const;
 148   bool is_ignored_frame()        const;
 149   bool is_native_frame()         const;
 150   bool is_runtime_frame()        const;
 151   bool is_compiled_frame()       const;
 152   bool is_safepoint_blob_frame() const;
 153   bool is_deoptimized_frame()    const;
 154 
 155   // testers
 156   bool is_first_frame() const; // oldest frame? (has no sender)
 157   bool is_first_java_frame() const;              // same for Java frame
 158 
 159   bool is_interpreted_frame_valid(JavaThread* thread) const;       // performs sanity checks on interpreted frames.
 160 
 161   // tells whether this frame is marked for deoptimization
 162   bool should_be_deoptimized() const;
 163 
 164   // tells whether this frame can be deoptimized
 165   bool can_be_deoptimized() const;
 166 
 167   // returns the frame size in stack slots
 168   int frame_size(RegisterMap* map) const;
 169 
 170   // returns the sending frame
 171   frame sender(RegisterMap* map) const;
 172 
 173   template<typename LOOKUP> // LOOKUP is CodeCache or ContinuationCodeBlobLookup (requires: static CodeBlob* find_blob(address pc))
 174   frame frame_sender(RegisterMap* map) const;
 175 
 176   bool safe_for_sender(JavaThread *thread);
 177 
 178   // returns the sender, but skips conversion frames
 179   frame real_sender(RegisterMap* map) const;
 180 
 181   // returns the the sending Java frame, skipping any intermediate C frames
 182   // NB: receiver must not be first frame
 183   frame java_sender() const;
 184 
 185  private:
 186   // Helper methods for better factored code in frame::sender
 187   template <typename LOOKUP, bool stub>
 188   frame sender_for_compiled_frame(RegisterMap* map) const;
 189   frame sender_for_entry_frame(RegisterMap* map) const;
 190   frame sender_for_interpreter_frame(RegisterMap* map) const;
 191   frame sender_for_native_frame(RegisterMap* map) const;
 192 
 193   bool is_entry_frame_valid(JavaThread* thread) const;
 194 
 195   // All frames:
 196 
 197   // A low-level interface for vframes:
 198 
 199  public:
 200 
 201   intptr_t* addr_at(int index) const             { return &fp()[index];    }
 202   intptr_t  at(int index) const                  { return *addr_at(index); }
 203 
 204   // accessors for locals
 205   oop obj_at(int offset) const                   { return *obj_at_addr(offset);  }
 206   void obj_at_put(int offset, oop value)         { *obj_at_addr(offset) = value; }
 207 


 364 
 365  public:
 366   oop saved_oop_result(RegisterMap* map) const;
 367   void set_saved_oop_result(RegisterMap* map, oop obj);
 368 
 369   // For debugging
 370  private:
 371   const char* print_name() const;
 372 
 373   void describe_pd(FrameValues& values, int frame_no);
 374 
 375  public:
 376   void print_value() const { print_value_on(tty,NULL); }
 377   void print_value_on(outputStream* st, JavaThread *thread) const;
 378   void print_on(outputStream* st) const;
 379   void interpreter_frame_print_on(outputStream* st) const;
 380   void print_on_error(outputStream* st, char* buf, int buflen, bool verbose = false) const;
 381   static void print_C_frame(outputStream* st, char* buf, int buflen, address pc);
 382 
 383   // Add annotated descriptions of memory locations belonging to this frame to values
 384   void describe(FrameValues& values, int frame_no, const RegisterMap* reg_map=NULL);
 385 
 386   // Conversion from a VMReg to physical stack location
 387   template <typename RegisterMapT>
 388   oop* oopmapreg_to_location(VMReg reg, const RegisterMapT* reg_map) const;
 389 
 390   // Oops-do's
 391   void oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix, const RegisterMap* reg_map, OopClosure* f);
 392   void oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache = true);
 393   void oops_interpreted_do(OopClosure* f, const RegisterMap* map, const InterpreterOopMap& mask);
 394 
 395  private:
 396   void oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f);
 397   void oops_interpreted_do0(OopClosure* f, const RegisterMap* map, methodHandle m, jint bci, const InterpreterOopMap& mask);
 398 
 399   // Iteration of oops
 400   void oops_do_internal(OopClosure* f, CodeBlobClosure* cf, DerivedOopClosure* df, const RegisterMap* map, bool use_interpreter_oop_map_cache);
 401   void oops_entry_do(OopClosure* f, const RegisterMap* map);
 402   void oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, DerivedOopClosure* df, const RegisterMap* map);
 403   int adjust_offset(Method* method, int index); // helper for above fn
 404  public:
 405   // Memory management
 406   void oops_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* map) { oops_do_internal(f, cf, NULL, map, true); }
 407   void oops_do(OopClosure* f, CodeBlobClosure* cf, DerivedOopClosure* df, const RegisterMap* map) { oops_do_internal(f, cf, df, map, true); }
 408   void nmethods_do(CodeBlobClosure* cf);
 409 
 410   // RedefineClasses support for finding live interpreted methods on the stack
 411   void metadata_do(MetadataClosure* f);
 412 
 413   // Verification
 414   void verify(const RegisterMap* map);
 415   static bool verify_return_pc(address x);
 416   // Usage:
 417   // assert(frame::verify_return_pc(return_address), "must be a return pc");
 418 
 419   NOT_PRODUCT(void pd_ps();)  // platform dependent frame printing
 420 
 421 #include CPU_HEADER(frame)
 422 
 423 };
 424 
 425 #ifndef PRODUCT
 426 // A simple class to describe a location on the stack
 427 class FrameValue {


 469 #endif
 470 
 471 //
 472 // StackFrameStream iterates through the frames of a thread starting from
 473 // top most frame. It automatically takes care of updating the location of
 474 // all (callee-saved) registers. Notice: If a thread is stopped at
 475 // a safepoint, all registers are saved, not only the callee-saved ones.
 476 //
 477 // Use:
 478 //
 479 //   for(StackFrameStream fst(thread); !fst.is_done(); fst.next()) {
 480 //     ...
 481 //   }
 482 //
 483 class StackFrameStream : public StackObj {
 484  private:
 485   frame       _fr;
 486   RegisterMap _reg_map;
 487   bool        _is_done;
 488  public:
 489    StackFrameStream(JavaThread *thread, bool update = true, bool allow_missing_reg = false);
 490 
 491   // Iteration
 492   inline bool is_done();
 493   void next()                     { if (!_is_done) _fr = _fr.sender(&_reg_map); }
 494 
 495   // Query
 496   frame *current()                { return &_fr; }
 497   RegisterMap* register_map()     { return &_reg_map; }
 498 };
 499 
 500 #endif // SHARE_RUNTIME_FRAME_HPP
< prev index next >