< prev index next >

src/hotspot/share/runtime/vframe.hpp

Print this page




  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_VM_RUNTIME_VFRAME_HPP
  26 #define SHARE_VM_RUNTIME_VFRAME_HPP
  27 
  28 #include "code/debugInfo.hpp"
  29 #include "code/debugInfoRec.hpp"
  30 #include "code/location.hpp"
  31 #include "oops/oop.hpp"
  32 #include "runtime/frame.hpp"
  33 #include "runtime/frame.inline.hpp"
  34 #include "runtime/stackValue.hpp"
  35 #include "runtime/stackValueCollection.hpp"
  36 #include "utilities/growableArray.hpp"
  37 
  38 // vframes are virtual stack frames representing source level activations.
  39 // A single frame may hold several source level activations in the case of
  40 // optimized code. The debugging stored with the optimized code enables
  41 // us to unfold a frame as a stack of vframes.
  42 // A cVFrame represents an activation of a non-java method.
  43 
  44 // The vframe inheritance hierarchy:
  45 // - vframe
  46 //   - javaVFrame
  47 //     - interpretedVFrame
  48 //     - compiledVFrame     ; (used for both compiled Java methods and native stubs)
  49 //   - externalVFrame
  50 //     - entryVFrame        ; special frame created when calling Java from C
  51 
  52 // - BasicLock
  53 


 290   Method* _method;
 291   int       _bci;
 292 
 293   // Should VM activations be ignored or not
 294   bool _stop_at_java_call_stub;
 295 
 296   bool fill_in_compiled_inlined_sender();
 297   void fill_from_compiled_frame(int decode_offset);
 298   void fill_from_compiled_native_frame();
 299 
 300   void fill_from_interpreter_frame();
 301   bool fill_from_frame();
 302 
 303   // Helper routine for security_get_caller_frame
 304   void skip_prefixed_method_and_wrappers();
 305 
 306   DEBUG_ONLY(void found_bad_method_frame() const;)
 307 
 308  public:
 309   // Constructor
 310   vframeStreamCommon(JavaThread* thread) : _reg_map(thread, false) {
 311     _thread = thread;
 312   }
 313 
 314   // Accessors
 315   Method* method() const { return _method; }
 316   int bci() const { return _bci; }
 317   intptr_t* frame_id() const { return _frame.id(); }
 318   address frame_pc() const { return _frame.pc(); }
 319 
 320   CodeBlob*          cb()         const { return _frame.cb();  }
 321   CompiledMethod*   nm()         const {
 322       assert( cb() != NULL && cb()->is_compiled(), "usage");
 323       return (CompiledMethod*) cb();
 324   }
 325 
 326   // Frame type
 327   bool is_interpreted_frame() const { return _frame.is_interpreted_frame(); }
 328   bool is_entry_frame() const       { return _frame.is_entry_frame(); }
 329 
 330   // Iteration
 331   void next() {
 332     // handle frames with inlining
 333     if (_mode == compiled_mode    && fill_in_compiled_inlined_sender()) return;
 334 
 335     // handle general case
 336     do {
 337       _frame = _frame.sender(&_reg_map);
 338     } while (!fill_from_frame());
 339   }
 340   void security_next();
 341 
 342   bool at_end() const { return _mode == at_end_mode; }
 343 
 344   // Implements security traversal. Skips depth no. of frame including
 345   // special security frames and prefixed native methods
 346   void security_get_caller_frame(int depth);
 347 
 348   // Helper routine for JVM_LatestUserDefinedLoader -- needed for 1.4
 349   // reflection implementation
 350   void skip_reflection_related_frames();
 351 };
 352 
 353 class vframeStream : public vframeStreamCommon {
 354  public:
 355   // Constructors
 356   vframeStream(JavaThread* thread, bool stop_at_java_call_stub = false)
 357     : vframeStreamCommon(thread) {
 358     _stop_at_java_call_stub = stop_at_java_call_stub;
 359 
 360     if (!thread->has_last_Java_frame()) {
 361       _mode = at_end_mode;
 362       return;
 363     }
 364 
 365     _frame = _thread->last_frame();
 366     while (!fill_from_frame()) {
 367       _frame = _frame.sender(&_reg_map);
 368     }
 369   }
 370 
 371   // top_frame may not be at safepoint, start with sender
 372   vframeStream(JavaThread* thread, frame top_frame, bool stop_at_java_call_stub = false);
 373 };
 374 
 375 
 376 inline bool vframeStreamCommon::fill_in_compiled_inlined_sender() {
 377   if (_sender_decode_offset == DebugInformationRecorder::serialized_null) {
 378     return false;
 379   }
 380   fill_from_compiled_frame(_sender_decode_offset);
 381   return true;
 382 }
 383 
 384 
 385 inline void vframeStreamCommon::fill_from_compiled_frame(int decode_offset) {
 386   _mode = compiled_mode;
 387 
 388   // Range check to detect ridiculous offsets.
 389   if (decode_offset == DebugInformationRecorder::serialized_null ||
 390       decode_offset < 0 ||
 391       decode_offset >= nm()->scopes_data_size()) {
 392     // 6379830 AsyncGetCallTrace sometimes feeds us wild frames.
 393     // If we read nmethod::scopes_data at serialized_null (== 0)
 394     // or if read some at other invalid offset, invalid values will be decoded.
 395     // Based on these values, invalid heap locations could be referenced
 396     // that could lead to crashes in product mode.
 397     // Therefore, do not use the decode offset if invalid, but fill the frame
 398     // as it were a native compiled frame (no Java-level assumptions).
 399 #ifdef ASSERT
 400     if (WizardMode) {
 401       ttyLocker ttyl;
 402       tty->print_cr("Error in fill_from_frame: pc_desc for "
 403                     INTPTR_FORMAT " not found or invalid at %d",
 404                     p2i(_frame.pc()), decode_offset);
 405       nm()->print();
 406       nm()->method()->print_codes();
 407       nm()->print_code();
 408       nm()->print_pcs();
 409     }
 410     found_bad_method_frame();
 411 #endif
 412     // Provide a cheap fallback in product mode.  (See comment above.)
 413     fill_from_compiled_native_frame();
 414     return;
 415   }
 416 
 417   // Decode first part of scopeDesc
 418   DebugInfoReadStream buffer(nm(), decode_offset);
 419   _sender_decode_offset = buffer.read_int();
 420   _method               = buffer.read_method();
 421   _bci                  = buffer.read_bci();
 422 
 423   assert(_method->is_method(), "checking type of decoded method");
 424 }
 425 
 426 // The native frames are handled specially. We do not rely on ScopeDesc info
 427 // since the pc might not be exact due to the _last_native_pc trick.
 428 inline void vframeStreamCommon::fill_from_compiled_native_frame() {
 429   _mode = compiled_mode;
 430   _sender_decode_offset = DebugInformationRecorder::serialized_null;
 431   _method = nm()->method();
 432   _bci = 0;
 433 }
 434 
 435 inline bool vframeStreamCommon::fill_from_frame() {
 436   // Interpreted frame
 437   if (_frame.is_interpreted_frame()) {
 438     fill_from_interpreter_frame();
 439     return true;
 440   }
 441 
 442   // Compiled frame
 443 
 444   if (cb() != NULL && cb()->is_compiled()) {
 445     if (nm()->is_native_method()) {
 446       // Do not rely on scopeDesc since the pc might be unprecise due to the _last_native_pc trick.
 447       fill_from_compiled_native_frame();
 448     } else {
 449       PcDesc* pc_desc = nm()->pc_desc_at(_frame.pc());
 450       int decode_offset;
 451       if (pc_desc == NULL) {
 452         // Should not happen, but let fill_from_compiled_frame handle it.
 453 
 454         // If we are trying to walk the stack of a thread that is not
 455         // at a safepoint (like AsyncGetCallTrace would do) then this is an
 456         // acceptable result. [ This is assuming that safe_for_sender
 457         // is so bullet proof that we can trust the frames it produced. ]
 458         //
 459         // So if we see that the thread is not safepoint safe
 460         // then simply produce the method and a bci of zero
 461         // and skip the possibility of decoding any inlining that
 462         // may be present. That is far better than simply stopping (or
 463         // asserting. If however the thread is safepoint safe this
 464         // is the sign of a compiler bug  and we'll let
 465         // fill_from_compiled_frame handle it.
 466 
 467 
 468         JavaThreadState state = _thread->thread_state();
 469 
 470         // in_Java should be good enough to test safepoint safety
 471         // if state were say in_Java_trans then we'd expect that
 472         // the pc would have already been slightly adjusted to
 473         // one that would produce a pcDesc since the trans state
 474         // would be one that might in fact anticipate a safepoint
 475 
 476         if (state == _thread_in_Java ) {
 477           // This will get a method a zero bci and no inlining.
 478           // Might be nice to have a unique bci to signify this
 479           // particular case but for now zero will do.
 480 
 481           fill_from_compiled_native_frame();
 482 
 483           // There is something to be said for setting the mode to
 484           // at_end_mode to prevent trying to walk further up the
 485           // stack. There is evidence that if we walk any further
 486           // that we could produce a bad stack chain. However until
 487           // we see evidence that allowing this causes us to find
 488           // frames bad enough to cause segv's or assertion failures
 489           // we don't do it as while we may get a bad call chain the
 490           // probability is much higher (several magnitudes) that we
 491           // get good data.
 492 
 493           return true;
 494         }
 495         decode_offset = DebugInformationRecorder::serialized_null;
 496       } else {
 497         decode_offset = pc_desc->scope_decode_offset();
 498       }
 499       fill_from_compiled_frame(decode_offset);
 500     }
 501     return true;
 502   }
 503 
 504   // End of stack?
 505   if (_frame.is_first_frame() || (_stop_at_java_call_stub && _frame.is_entry_frame())) {
 506     _mode = at_end_mode;
 507     return true;
 508   }
 509 
 510   return false;
 511 }
 512 
 513 
 514 inline void vframeStreamCommon::fill_from_interpreter_frame() {
 515   Method* method = _frame.interpreter_frame_method();
 516   address   bcp    = _frame.interpreter_frame_bcp();
 517   int       bci    = method->validate_bci_from_bcp(bcp);
 518   // 6379830 AsyncGetCallTrace sometimes feeds us wild frames.
 519   // AsyncGetCallTrace interrupts the VM asynchronously. As a result
 520   // it is possible to access an interpreter frame for which
 521   // no Java-level information is yet available (e.g., becasue
 522   // the frame was being created when the VM interrupted it).
 523   // In this scenario, pretend that the interpreter is at the point
 524   // of entering the method.
 525   if (bci < 0) {
 526     DEBUG_ONLY(found_bad_method_frame();)
 527     bci = 0;
 528   }
 529   _mode   = interpreted_mode;
 530   _method = method;
 531   _bci    = bci;
 532 }
 533 
 534 #endif // SHARE_VM_RUNTIME_VFRAME_HPP


  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_VM_RUNTIME_VFRAME_HPP
  26 #define SHARE_VM_RUNTIME_VFRAME_HPP
  27 
  28 #include "code/debugInfo.hpp"
  29 #include "code/debugInfoRec.hpp"
  30 #include "code/location.hpp"
  31 #include "oops/oop.hpp"
  32 #include "runtime/frame.hpp"

  33 #include "runtime/stackValue.hpp"
  34 #include "runtime/stackValueCollection.hpp"
  35 #include "utilities/growableArray.hpp"
  36 
  37 // vframes are virtual stack frames representing source level activations.
  38 // A single frame may hold several source level activations in the case of
  39 // optimized code. The debugging stored with the optimized code enables
  40 // us to unfold a frame as a stack of vframes.
  41 // A cVFrame represents an activation of a non-java method.
  42 
  43 // The vframe inheritance hierarchy:
  44 // - vframe
  45 //   - javaVFrame
  46 //     - interpretedVFrame
  47 //     - compiledVFrame     ; (used for both compiled Java methods and native stubs)
  48 //   - externalVFrame
  49 //     - entryVFrame        ; special frame created when calling Java from C
  50 
  51 // - BasicLock
  52 


 289   Method* _method;
 290   int       _bci;
 291 
 292   // Should VM activations be ignored or not
 293   bool _stop_at_java_call_stub;
 294 
 295   bool fill_in_compiled_inlined_sender();
 296   void fill_from_compiled_frame(int decode_offset);
 297   void fill_from_compiled_native_frame();
 298 
 299   void fill_from_interpreter_frame();
 300   bool fill_from_frame();
 301 
 302   // Helper routine for security_get_caller_frame
 303   void skip_prefixed_method_and_wrappers();
 304 
 305   DEBUG_ONLY(void found_bad_method_frame() const;)
 306 
 307  public:
 308   // Constructor
 309   vframeStreamCommon(JavaThread* thread);


 310 
 311   // Accessors
 312   Method* method() const { return _method; }
 313   int bci() const { return _bci; }
 314   intptr_t* frame_id() const;
 315   address frame_pc() const { return _frame.pc(); }
 316 
 317   CodeBlob*          cb()         const { return _frame.cb();  }
 318   CompiledMethod*   nm()         const {
 319       assert( cb() != NULL && cb()->is_compiled(), "usage");
 320       return (CompiledMethod*) cb();
 321   }
 322 
 323   // Frame type
 324   bool is_interpreted_frame() const;
 325   bool is_entry_frame() const;
 326 
 327   // Iteration
 328   void next();








 329   void security_next();
 330 
 331   bool at_end() const { return _mode == at_end_mode; }
 332 
 333   // Implements security traversal. Skips depth no. of frame including
 334   // special security frames and prefixed native methods
 335   void security_get_caller_frame(int depth);
 336 
 337   // Helper routine for JVM_LatestUserDefinedLoader -- needed for 1.4
 338   // reflection implementation
 339   void skip_reflection_related_frames();
 340 };
 341 
 342 class vframeStream : public vframeStreamCommon {
 343  public:
 344   // Constructors
 345   vframeStream(JavaThread* thread, bool stop_at_java_call_stub = false);













 346 
 347   // top_frame may not be at safepoint, start with sender
 348   vframeStream(JavaThread* thread, frame top_frame, bool stop_at_java_call_stub = false);
 349 };































































































































































 350 
 351 #endif // SHARE_VM_RUNTIME_VFRAME_HPP
< prev index next >