v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
frames.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_FRAMES_H_
29 #define V8_FRAMES_H_
30 
31 #include "allocation.h"
32 #include "handles.h"
33 #include "safepoint-table.h"
34 
35 namespace v8 {
36 namespace internal {
37 
38 #if V8_TARGET_ARCH_ARM64
39 typedef uint64_t RegList;
40 #else
41 typedef uint32_t RegList;
42 #endif
43 
44 // Get the number of registers in a given register list.
45 int NumRegs(RegList list);
46 
48 
49 // Return the code of the n-th saved register available to JavaScript.
50 int JSCallerSavedCode(int n);
51 
52 
53 // Forward declarations.
54 class ExternalCallbackScope;
55 class StackFrameIteratorBase;
56 class ThreadLocalTop;
57 class Isolate;
58 
60  public:
64  SafepointEntry safepoint_entry;
65  };
66 
67  explicit InnerPointerToCodeCache(Isolate* isolate) : isolate_(isolate) {
68  Flush();
69  }
70 
72  Code* GcSafeCastToCode(HeapObject* object, Address inner_pointer);
73 
74  void Flush() {
75  memset(&cache_[0], 0, sizeof(cache_));
76  }
77 
78  InnerPointerToCodeCacheEntry* GetCacheEntry(Address inner_pointer);
79 
80  private:
81  InnerPointerToCodeCacheEntry* cache(int index) { return &cache_[index]; }
82 
83  Isolate* isolate_;
84 
85  static const int kInnerPointerToCodeCacheSize = 1024;
86  InnerPointerToCodeCacheEntry cache_[kInnerPointerToCodeCacheSize];
87 
88  DISALLOW_COPY_AND_ASSIGN(InnerPointerToCodeCache);
89 };
90 
91 
93  public:
94  static const int kNextOffset = 0 * kPointerSize;
95  static const int kCodeOffset = 1 * kPointerSize;
96  static const int kStateOffset = 2 * kPointerSize;
97  static const int kContextOffset = 3 * kPointerSize;
98  static const int kFPOffset = 4 * kPointerSize;
99 
100  static const int kSize = kFPOffset + kFPOnStackSize;
101  static const int kSlotCount = kSize >> kPointerSizeLog2;
102 };
103 
104 
105 class StackHandler BASE_EMBEDDED {
106  public:
107  enum Kind {
111  LAST_KIND = FINALLY
112  };
113 
114  static const int kKindWidth = 2;
115  STATIC_ASSERT(LAST_KIND < (1 << kKindWidth));
116  static const int kIndexWidth = 32 - kKindWidth;
117  class KindField: public BitField<StackHandler::Kind, 0, kKindWidth> {};
118  class IndexField: public BitField<unsigned, kKindWidth, kIndexWidth> {};
119 
120  // Get the address of this stack handler.
121  inline Address address() const;
122 
123  // Get the next stack handler in the chain.
124  inline StackHandler* next() const;
125 
126  // Tells whether the given address is inside this handler.
127  inline bool includes(Address address) const;
128 
129  // Garbage collection support.
130  inline void Iterate(ObjectVisitor* v, Code* holder) const;
131 
132  // Conversion support.
133  static inline StackHandler* FromAddress(Address address);
134 
135  // Testers
136  inline bool is_js_entry() const;
137  inline bool is_catch() const;
138  inline bool is_finally() const;
139 
140  // Generator support to preserve stack handlers.
141  void Unwind(Isolate* isolate, FixedArray* array, int offset,
142  int previous_handler_offset) const;
143  int Rewind(Isolate* isolate, FixedArray* array, int offset, Address fp);
144 
145  private:
146  // Accessors.
147  inline Kind kind() const;
148  inline unsigned index() const;
149 
150  inline Object** constant_pool_address() const;
151  inline Object** context_address() const;
152  inline Object** code_address() const;
153  inline void SetFp(Address slot, Address fp);
154 
155  DISALLOW_IMPLICIT_CONSTRUCTORS(StackHandler);
156 };
157 
158 
159 #define STACK_FRAME_TYPE_LIST(V) \
160  V(ENTRY, EntryFrame) \
161  V(ENTRY_CONSTRUCT, EntryConstructFrame) \
162  V(EXIT, ExitFrame) \
163  V(JAVA_SCRIPT, JavaScriptFrame) \
164  V(OPTIMIZED, OptimizedFrame) \
165  V(STUB, StubFrame) \
166  V(STUB_FAILURE_TRAMPOLINE, StubFailureTrampolineFrame) \
167  V(INTERNAL, InternalFrame) \
168  V(CONSTRUCT, ConstructFrame) \
169  V(ARGUMENTS_ADAPTOR, ArgumentsAdaptorFrame)
170 
171 
173  public:
174  // Fixed part of the frame consists of return address, caller fp,
175  // constant pool (if FLAG_enable_ool_constant_pool), context, and function.
176  // StandardFrame::IterateExpressions assumes that kLastObjectOffset is the
177  // last object pointer.
178  static const int kCPSlotSize =
179  FLAG_enable_ool_constant_pool ? kPointerSize : 0;
183  static const int kExpressionsOffset = -3 * kPointerSize - kCPSlotSize;
184  static const int kMarkerOffset = -2 * kPointerSize - kCPSlotSize;
185  static const int kContextOffset = -1 * kPointerSize - kCPSlotSize;
186  static const int kConstantPoolOffset = FLAG_enable_ool_constant_pool ?
187  -1 * kPointerSize : 0;
188  static const int kCallerFPOffset = 0 * kPointerSize;
189  static const int kCallerPCOffset = +1 * kFPOnStackSize;
191 
192  static const int kLastObjectOffset = FLAG_enable_ool_constant_pool ?
194 };
195 
196 
197 // Abstract base class for all stack frames.
199  public:
200 #define DECLARE_TYPE(type, ignore) type,
201  enum Type {
202  NONE = 0,
204  NUMBER_OF_TYPES,
205  // Used by FrameScope to indicate that the stack frame is constructed
206  // manually and the FrameScope does not need to emit code.
207  MANUAL
208  };
209 #undef DECLARE_TYPE
210 
211  // Opaque data type for identifying stack frames. Used extensively
212  // by the debugger.
213  // ID_MIN_VALUE and ID_MAX_VALUE are specified to ensure that enumeration type
214  // has correct value range (see Issue 830 for more details).
215  enum Id {
216  ID_MIN_VALUE = kMinInt,
217  ID_MAX_VALUE = kMaxInt,
218  NO_ID = 0
219  };
220 
221  // Used to mark the outermost JS entry frame.
223  INNER_JSENTRY_FRAME = 0,
224  OUTERMOST_JSENTRY_FRAME = 1
225  };
226 
227  struct State {
228  State() : sp(NULL), fp(NULL), pc_address(NULL),
229  constant_pool_address(NULL) { }
234  };
235 
236  // Copy constructor; it breaks the connection to host iterator
237  // (as an iterator usually lives on stack).
238  StackFrame(const StackFrame& original) {
239  this->state_ = original.state_;
240  this->iterator_ = NULL;
241  this->isolate_ = original.isolate_;
242  }
243 
244  // Type testers.
245  bool is_entry() const { return type() == ENTRY; }
246  bool is_entry_construct() const { return type() == ENTRY_CONSTRUCT; }
247  bool is_exit() const { return type() == EXIT; }
248  bool is_optimized() const { return type() == OPTIMIZED; }
249  bool is_arguments_adaptor() const { return type() == ARGUMENTS_ADAPTOR; }
250  bool is_internal() const { return type() == INTERNAL; }
252  return type() == STUB_FAILURE_TRAMPOLINE;
253  }
254  bool is_construct() const { return type() == CONSTRUCT; }
255  virtual bool is_standard() const { return false; }
256 
257  bool is_java_script() const {
258  Type type = this->type();
259  return (type == JAVA_SCRIPT) || (type == OPTIMIZED);
260  }
261 
262  // Accessors.
263  Address sp() const { return state_.sp; }
264  Address fp() const { return state_.fp; }
265  Address caller_sp() const { return GetCallerStackPointer(); }
266 
267  // If this frame is optimized and was dynamically aligned return its old
268  // unaligned frame pointer. When the frame is deoptimized its FP will shift
269  // up one word and become unaligned.
270  Address UnpaddedFP() const;
271 
272  Address pc() const { return *pc_address(); }
273  void set_pc(Address pc) { *pc_address() = pc; }
274 
275  Address constant_pool() const { return *constant_pool_address(); }
276  void set_constant_pool(ConstantPoolArray* constant_pool) {
277  *constant_pool_address() = reinterpret_cast<Address>(constant_pool);
278  }
279 
280  virtual void SetCallerFp(Address caller_fp) = 0;
281 
282  // Manually changes value of fp in this object.
283  void UpdateFp(Address fp) { state_.fp = fp; }
284 
285  Address* pc_address() const { return state_.pc_address; }
286 
288  return state_.constant_pool_address;
289  }
290 
291  // Get the id of this stack frame.
292  Id id() const { return static_cast<Id>(OffsetFrom(caller_sp())); }
293 
294  // Checks if this frame includes any stack handlers.
295  bool HasHandler() const;
296 
297  // Get the type of this frame.
298  virtual Type type() const = 0;
299 
300  // Get the code associated with this frame.
301  // This method could be called during marking phase of GC.
302  virtual Code* unchecked_code() const = 0;
303 
304  // Get the code associated with this frame.
305  inline Code* LookupCode() const;
306 
307  // Get the code object that contains the given pc.
308  static inline Code* GetContainingCode(Isolate* isolate, Address pc);
309 
310  // Get the code object containing the given pc and fill in the
311  // safepoint entry and the number of stack slots. The pc must be at
312  // a safepoint.
313  static Code* GetSafepointData(Isolate* isolate,
314  Address pc,
315  SafepointEntry* safepoint_entry,
316  unsigned* stack_slots);
317 
318  virtual void Iterate(ObjectVisitor* v) const = 0;
319  static void IteratePc(ObjectVisitor* v, Address* pc_address, Code* holder);
320 
321  // Sets a callback function for return-address rewriting profilers
322  // to resolve the location of a return address to the location of the
323  // profiler's stashed return address.
324  static void SetReturnAddressLocationResolver(
326 
327  // Resolves pc_address through the resolution address function if one is set.
328  static inline Address* ResolveReturnAddressLocation(Address* pc_address);
329 
330 
331  // Printing support.
332  enum PrintMode { OVERVIEW, DETAILS };
333  virtual void Print(StringStream* accumulator,
334  PrintMode mode,
335  int index) const { }
336 
337  Isolate* isolate() const { return isolate_; }
338 
339  protected:
340  inline explicit StackFrame(StackFrameIteratorBase* iterator);
341  virtual ~StackFrame() { }
342 
343  // Compute the stack pointer for the calling frame.
344  virtual Address GetCallerStackPointer() const = 0;
345 
346  // Printing support.
347  static void PrintIndex(StringStream* accumulator,
348  PrintMode mode,
349  int index);
350 
351  // Get the top handler from the current stack iterator.
352  inline StackHandler* top_handler() const;
353 
354  // Compute the stack frame type for the given state.
355  static Type ComputeType(const StackFrameIteratorBase* iterator, State* state);
356 
357 #ifdef DEBUG
358  bool can_access_heap_objects() const;
359 #endif
360 
361  private:
362  const StackFrameIteratorBase* iterator_;
363  Isolate* isolate_;
364  State state_;
365 
366  static ReturnAddressLocationResolver return_address_location_resolver_;
367 
368  // Fill in the state of the calling frame.
369  virtual void ComputeCallerState(State* state) const = 0;
370 
371  // Get the type and the state of the calling frame.
372  virtual Type GetCallerState(State* state) const;
373 
374  static const intptr_t kIsolateTag = 1;
375 
376  friend class StackFrameIterator;
377  friend class StackFrameIteratorBase;
378  friend class StackHandlerIterator;
380 
381  private:
382  void operator=(const StackFrame& original);
383 };
384 
385 
386 // Entry frames are used to enter JavaScript execution from C.
387 class EntryFrame: public StackFrame {
388  public:
389  virtual Type type() const { return ENTRY; }
390 
391  virtual Code* unchecked_code() const;
392 
393  // Garbage collection support.
394  virtual void Iterate(ObjectVisitor* v) const;
395 
396  static EntryFrame* cast(StackFrame* frame) {
397  ASSERT(frame->is_entry());
398  return static_cast<EntryFrame*>(frame);
399  }
400  virtual void SetCallerFp(Address caller_fp);
401 
402  protected:
403  inline explicit EntryFrame(StackFrameIteratorBase* iterator);
404 
405  // The caller stack pointer for entry frames is always zero. The
406  // real information about the caller frame is available through the
407  // link to the top exit frame.
408  virtual Address GetCallerStackPointer() const { return 0; }
409 
410  private:
411  virtual void ComputeCallerState(State* state) const;
412  virtual Type GetCallerState(State* state) const;
413 
414  friend class StackFrameIteratorBase;
415 };
416 
417 
419  public:
420  virtual Type type() const { return ENTRY_CONSTRUCT; }
421 
422  virtual Code* unchecked_code() const;
423 
425  ASSERT(frame->is_entry_construct());
426  return static_cast<EntryConstructFrame*>(frame);
427  }
428 
429  protected:
430  inline explicit EntryConstructFrame(StackFrameIteratorBase* iterator);
431 
432  private:
433  friend class StackFrameIteratorBase;
434 };
435 
436 
437 // Exit frames are used to exit JavaScript execution and go to C.
438 class ExitFrame: public StackFrame {
439  public:
440  virtual Type type() const { return EXIT; }
441 
442  virtual Code* unchecked_code() const;
443 
444  Object*& code_slot() const;
445  Object*& constant_pool_slot() const;
446 
447  // Garbage collection support.
448  virtual void Iterate(ObjectVisitor* v) const;
449 
450  virtual void SetCallerFp(Address caller_fp);
451 
452  static ExitFrame* cast(StackFrame* frame) {
453  ASSERT(frame->is_exit());
454  return static_cast<ExitFrame*>(frame);
455  }
456 
457  // Compute the state and type of an exit frame given a frame
458  // pointer. Used when constructing the first stack frame seen by an
459  // iterator and the frames following entry frames.
460  static Type GetStateForFramePointer(Address fp, State* state);
461  static Address ComputeStackPointer(Address fp);
462  static void FillState(Address fp, Address sp, State* state);
463 
464  protected:
465  inline explicit ExitFrame(StackFrameIteratorBase* iterator);
466 
467  virtual Address GetCallerStackPointer() const;
468 
469  private:
470  virtual void ComputeCallerState(State* state) const;
471 
472  friend class StackFrameIteratorBase;
473 };
474 
475 
476 class StandardFrame: public StackFrame {
477  public:
478  // Testers.
479  virtual bool is_standard() const { return true; }
480 
481  // Accessors.
482  inline Object* context() const;
483 
484  // Access the expressions in the stack frame including locals.
485  inline Object* GetExpression(int index) const;
486  inline void SetExpression(int index, Object* value);
487  int ComputeExpressionsCount() const;
488  static Object* GetExpression(Address fp, int index);
489 
490  virtual void SetCallerFp(Address caller_fp);
491 
492  static StandardFrame* cast(StackFrame* frame) {
493  ASSERT(frame->is_standard());
494  return static_cast<StandardFrame*>(frame);
495  }
496 
497  protected:
498  inline explicit StandardFrame(StackFrameIteratorBase* iterator);
499 
500  virtual void ComputeCallerState(State* state) const;
501 
502  // Accessors.
503  inline Address caller_fp() const;
504  inline Address caller_pc() const;
505 
506  // Computes the address of the PC field in the standard frame given
507  // by the provided frame pointer.
508  static inline Address ComputePCAddress(Address fp);
509 
510  // Computes the address of the constant pool field in the standard
511  // frame given by the provided frame pointer.
512  static inline Address ComputeConstantPoolAddress(Address fp);
513 
514  // Iterate over expression stack including stack handlers, locals,
515  // and parts of the fixed part including context and code fields.
516  void IterateExpressions(ObjectVisitor* v) const;
517 
518  // Returns the address of the n'th expression stack element.
519  Address GetExpressionAddress(int n) const;
520  static Address GetExpressionAddress(Address fp, int n);
521 
522  // Determines if the n'th expression stack element is in a stack
523  // handler or not. Requires traversing all handlers in this frame.
524  bool IsExpressionInsideHandler(int n) const;
525 
526  // Determines if the standard frame for the given frame pointer is
527  // an arguments adaptor frame.
528  static inline bool IsArgumentsAdaptorFrame(Address fp);
529 
530  // Determines if the standard frame for the given frame pointer is a
531  // construct frame.
532  static inline bool IsConstructFrame(Address fp);
533 
534  // Used by OptimizedFrames and StubFrames.
535  void IterateCompiledFrame(ObjectVisitor* v) const;
536 
537  private:
538  friend class StackFrame;
540 };
541 
542 
543 class FrameSummary BASE_EMBEDDED {
544  public:
545  FrameSummary(Object* receiver,
546  JSFunction* function,
547  Code* code,
548  int offset,
549  bool is_constructor)
550  : receiver_(receiver, function->GetIsolate()),
551  function_(function),
552  code_(code),
553  offset_(offset),
554  is_constructor_(is_constructor) { }
555  Handle<Object> receiver() { return receiver_; }
556  Handle<JSFunction> function() { return function_; }
557  Handle<Code> code() { return code_; }
558  Address pc() { return code_->address() + offset_; }
559  int offset() { return offset_; }
560  bool is_constructor() { return is_constructor_; }
561 
562  void Print();
563 
564  private:
565  Handle<Object> receiver_;
566  Handle<JSFunction> function_;
567  Handle<Code> code_;
568  int offset_;
569  bool is_constructor_;
570 };
571 
572 
574  public:
575  virtual Type type() const { return JAVA_SCRIPT; }
576 
577  // Accessors.
578  inline JSFunction* function() const;
579  inline Object* receiver() const;
580  inline void set_receiver(Object* value);
581 
582  // Access the parameters.
583  inline Address GetParameterSlot(int index) const;
584  inline Object* GetParameter(int index) const;
585  inline int ComputeParametersCount() const {
586  return GetNumberOfIncomingArguments();
587  }
588 
589  // Access the operand stack.
590  inline Address GetOperandSlot(int index) const;
591  inline Object* GetOperand(int index) const;
592  inline int ComputeOperandsCount() const;
593 
594  // Generator support to preserve operand stack and stack handlers.
595  void SaveOperandStack(FixedArray* store, int* stack_handler_index) const;
596  void RestoreOperandStack(FixedArray* store, int stack_handler_index);
597 
598  // Debugger access.
599  void SetParameterValue(int index, Object* value) const;
600 
601  // Check if this frame is a constructor frame invoked through 'new'.
602  bool IsConstructor() const;
603 
604  // Check if this frame has "adapted" arguments in the sense that the
605  // actual passed arguments are available in an arguments adaptor
606  // frame below it on the stack.
607  inline bool has_adapted_arguments() const;
608  int GetArgumentsLength() const;
609 
610  // Garbage collection support.
611  virtual void Iterate(ObjectVisitor* v) const;
612 
613  // Printing support.
614  virtual void Print(StringStream* accumulator,
615  PrintMode mode,
616  int index) const;
617 
618  // Determine the code for the frame.
619  virtual Code* unchecked_code() const;
620 
621  // Returns the levels of inlining for this frame.
622  virtual int GetInlineCount() { return 1; }
623 
624  // Return a list with JSFunctions of this frame.
625  virtual void GetFunctions(List<JSFunction*>* functions);
626 
627  // Build a list with summaries for this frame including all inlined frames.
628  virtual void Summarize(List<FrameSummary>* frames);
629 
630  // Architecture-specific register description.
631  static Register fp_register();
632  static Register context_register();
633  static Register constant_pool_pointer_register();
634 
635  static JavaScriptFrame* cast(StackFrame* frame) {
636  ASSERT(frame->is_java_script());
637  return static_cast<JavaScriptFrame*>(frame);
638  }
639 
640  static void PrintTop(Isolate* isolate,
641  FILE* file,
642  bool print_args,
643  bool print_line_number);
644 
645  protected:
646  inline explicit JavaScriptFrame(StackFrameIteratorBase* iterator);
647 
648  virtual Address GetCallerStackPointer() const;
649 
650  virtual int GetNumberOfIncomingArguments() const;
651 
652  // Garbage collection support. Iterates over incoming arguments,
653  // receiver, and any callee-saved registers.
654  void IterateArguments(ObjectVisitor* v) const;
655 
656  private:
657  inline Object* function_slot_object() const;
658 
659  friend class StackFrameIteratorBase;
660 };
661 
662 
663 class StubFrame : public StandardFrame {
664  public:
665  virtual Type type() const { return STUB; }
666 
667  // GC support.
668  virtual void Iterate(ObjectVisitor* v) const;
669 
670  // Determine the code for the frame.
671  virtual Code* unchecked_code() const;
672 
673  protected:
674  inline explicit StubFrame(StackFrameIteratorBase* iterator);
675 
676  virtual Address GetCallerStackPointer() const;
677 
678  virtual int GetNumberOfIncomingArguments() const;
679 
680  friend class StackFrameIteratorBase;
681 };
682 
683 
685  public:
686  virtual Type type() const { return OPTIMIZED; }
687 
688  // GC support.
689  virtual void Iterate(ObjectVisitor* v) const;
690 
691  virtual int GetInlineCount();
692 
693  // Return a list with JSFunctions of this frame.
694  // The functions are ordered bottom-to-top (i.e. functions.last()
695  // is the top-most activation)
696  virtual void GetFunctions(List<JSFunction*>* functions);
697 
698  virtual void Summarize(List<FrameSummary>* frames);
699 
700  DeoptimizationInputData* GetDeoptimizationData(int* deopt_index);
701 
702  protected:
703  inline explicit OptimizedFrame(StackFrameIteratorBase* iterator);
704 
705  private:
706  JSFunction* LiteralAt(FixedArray* literal_array, int literal_id);
707 
708  friend class StackFrameIteratorBase;
709 };
710 
711 
712 // Arguments adaptor frames are automatically inserted below
713 // JavaScript frames when the actual number of parameters does not
714 // match the formal number of parameters.
716  public:
717  virtual Type type() const { return ARGUMENTS_ADAPTOR; }
718 
719  // Determine the code for the frame.
720  virtual Code* unchecked_code() const;
721 
723  ASSERT(frame->is_arguments_adaptor());
724  return static_cast<ArgumentsAdaptorFrame*>(frame);
725  }
726 
727  // Printing support.
728  virtual void Print(StringStream* accumulator,
729  PrintMode mode,
730  int index) const;
731 
732  protected:
733  inline explicit ArgumentsAdaptorFrame(StackFrameIteratorBase* iterator);
734 
735  virtual int GetNumberOfIncomingArguments() const;
736 
737  virtual Address GetCallerStackPointer() const;
738 
739  private:
740  friend class StackFrameIteratorBase;
741 };
742 
743 
745  public:
746  virtual Type type() const { return INTERNAL; }
747 
748  // Garbage collection support.
749  virtual void Iterate(ObjectVisitor* v) const;
750 
751  // Determine the code for the frame.
752  virtual Code* unchecked_code() const;
753 
754  static InternalFrame* cast(StackFrame* frame) {
755  ASSERT(frame->is_internal());
756  return static_cast<InternalFrame*>(frame);
757  }
758 
759  protected:
760  inline explicit InternalFrame(StackFrameIteratorBase* iterator);
761 
762  virtual Address GetCallerStackPointer() const;
763 
764  private:
765  friend class StackFrameIteratorBase;
766 };
767 
768 
770  public:
771  // sizeof(Arguments) - sizeof(Arguments*) is 3 * kPointerSize), but the
772  // presubmit script complains about using sizeof() on a type.
773  static const int kFirstRegisterParameterFrameOffset =
775 
776  static const int kCallerStackParameterCountFrameOffset =
778 
779  virtual Type type() const { return STUB_FAILURE_TRAMPOLINE; }
780 
781  // Get the code associated with this frame.
782  // This method could be called during marking phase of GC.
783  virtual Code* unchecked_code() const;
784 
785  virtual void Iterate(ObjectVisitor* v) const;
786 
787  // Architecture-specific register description.
788  static Register fp_register();
789  static Register context_register();
790  static Register constant_pool_pointer_register();
791 
792  protected:
793  inline explicit StubFailureTrampolineFrame(
794  StackFrameIteratorBase* iterator);
795 
796  virtual Address GetCallerStackPointer() const;
797 
798  private:
799  friend class StackFrameIteratorBase;
800 };
801 
802 
803 // Construct frames are special trampoline frames introduced to handle
804 // function invocations through 'new'.
806  public:
807  virtual Type type() const { return CONSTRUCT; }
808 
809  static ConstructFrame* cast(StackFrame* frame) {
810  ASSERT(frame->is_construct());
811  return static_cast<ConstructFrame*>(frame);
812  }
813 
814  protected:
815  inline explicit ConstructFrame(StackFrameIteratorBase* iterator);
816 
817  private:
818  friend class StackFrameIteratorBase;
819 };
820 
821 
822 class StackFrameIteratorBase BASE_EMBEDDED {
823  public:
824  Isolate* isolate() const { return isolate_; }
825 
826  bool done() const { return frame_ == NULL; }
827 
828  protected:
829  // An iterator that iterates over a given thread's stack.
830  StackFrameIteratorBase(Isolate* isolate, bool can_access_heap_objects);
831 
832  Isolate* isolate_;
833 #define DECLARE_SINGLETON(ignore, type) type type##_;
835 #undef DECLARE_SINGLETON
837  StackHandler* handler_;
839 
840  StackHandler* handler() const {
841  ASSERT(!done());
842  return handler_;
843  }
844 
845  // Get the type-specific frame singleton in a given state.
846  StackFrame* SingletonFor(StackFrame::Type type, StackFrame::State* state);
847  // A helper function, can return a NULL pointer.
848  StackFrame* SingletonFor(StackFrame::Type type);
849 
850  private:
851  friend class StackFrame;
852  DISALLOW_COPY_AND_ASSIGN(StackFrameIteratorBase);
853 };
854 
855 
856 class StackFrameIterator: public StackFrameIteratorBase {
857  public:
858  // An iterator that iterates over the isolate's current thread's stack,
859  explicit StackFrameIterator(Isolate* isolate);
860  // An iterator that iterates over a given thread's stack.
861  StackFrameIterator(Isolate* isolate, ThreadLocalTop* t);
862 
863  StackFrame* frame() const {
864  ASSERT(!done());
865  return frame_;
866  }
867  void Advance();
868 
869  private:
870  // Go back to the first frame.
871  void Reset(ThreadLocalTop* top);
872 
874 };
875 
876 
877 // Iterator that supports iterating through all JavaScript frames.
878 class JavaScriptFrameIterator BASE_EMBEDDED {
879  public:
880  inline explicit JavaScriptFrameIterator(Isolate* isolate);
881  inline JavaScriptFrameIterator(Isolate* isolate, ThreadLocalTop* top);
882  // Skip frames until the frame with the given id is reached.
883  JavaScriptFrameIterator(Isolate* isolate, StackFrame::Id id);
884 
885  inline JavaScriptFrame* frame() const;
886 
887  bool done() const { return iterator_.done(); }
888  void Advance();
889 
890  // Advance to the frame holding the arguments for the current
891  // frame. This only affects the current frame if it has adapted
892  // arguments.
893  void AdvanceToArgumentsFrame();
894 
895  private:
896  StackFrameIterator iterator_;
897 };
898 
899 
900 // NOTE: The stack trace frame iterator is an iterator that only
901 // traverse proper JavaScript frames; that is JavaScript frames that
902 // have proper JavaScript functions. This excludes the problematic
903 // functions in runtime.js.
904 class StackTraceFrameIterator: public JavaScriptFrameIterator {
905  public:
906  explicit StackTraceFrameIterator(Isolate* isolate);
907  void Advance();
908 
909  private:
910  bool IsValidFrame();
911 };
912 
913 
914 class SafeStackFrameIterator: public StackFrameIteratorBase {
915  public:
917  Address fp, Address sp,
918  Address js_entry_sp);
919 
920  inline StackFrame* frame() const;
921  void Advance();
922 
923  StackFrame::Type top_frame_type() const { return top_frame_type_; }
924 
925  private:
926  void AdvanceOneFrame();
927 
928  bool IsValidStackAddress(Address addr) const {
929  return low_bound_ <= addr && addr <= high_bound_;
930  }
931  bool IsValidFrame(StackFrame* frame) const;
932  bool IsValidCaller(StackFrame* frame);
933  bool IsValidExitFrame(Address fp) const;
934  bool IsValidTop(ThreadLocalTop* top) const;
935 
936  const Address low_bound_;
937  const Address high_bound_;
938  StackFrame::Type top_frame_type_;
939  ExternalCallbackScope* external_callback_scope_;
940 };
941 
942 
943 class StackFrameLocator BASE_EMBEDDED {
944  public:
945  explicit StackFrameLocator(Isolate* isolate) : iterator_(isolate) {}
946 
947  // Find the nth JavaScript frame on the stack. The caller must
948  // guarantee that such a frame exists.
949  JavaScriptFrame* FindJavaScriptFrame(int n);
950 
951  private:
952  StackFrameIterator iterator_;
953 };
954 
955 
956 // Used specify the type of prologue to generate.
960 };
961 
962 
963 // Reads all frames on the current stack and copies them into the current
964 // zone memory.
965 Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone);
966 
967 } } // namespace v8::internal
968 
969 #endif // V8_FRAMES_H_
byte * Address
Definition: globals.h:186
virtual Type type() const
Definition: frames.h:807
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
const int kMinInt
Definition: globals.h:249
static const int kFPOffset
Definition: frames.h:98
Definition: frames.h:61
static const int kStateOffset
Definition: frames.h:96
Code * GcSafeCastToCode(HeapObject *object, Address inner_pointer)
Definition: frames.cc:1467
StackFrame::Type top_frame_type() const
Definition: frames.h:923
static const int kCodeOffset
Definition: frames.h:95
static const int kFixedFrameSize
Definition: frames.h:181
static EntryFrame * cast(StackFrame *frame)
Definition: frames.h:396
int NumRegs(RegList reglist)
Definition: frames.cc:1589
bool done() const
Definition: frames.h:826
virtual bool is_standard() const
Definition: frames.h:255
void UpdateFp(Address fp)
Definition: frames.h:283
Address * constant_pool_address() const
Definition: frames.h:287
static StandardFrame * cast(StackFrame *frame)
Definition: frames.h:492
TypeImpl< ZoneTypeConfig > Type
Vector< StackFrame * > CreateStackMap(Isolate *isolate, Zone *zone)
Definition: frames.cc:1643
uint32_t RegList
Definition: frames.h:41
const int kMaxInt
Definition: globals.h:248
InnerPointerToCodeCache(Isolate *isolate)
Definition: frames.h:67
#define ASSERT(condition)
Definition: checks.h:329
static ConstructFrame * cast(StackFrame *frame)
Definition: frames.h:809
static const int kContextOffset
Definition: frames.h:185
const int kPointerSizeLog2
Definition: globals.h:281
Address fp() const
Definition: frames.h:264
static const int kNextOffset
Definition: frames.h:94
static InternalFrame * cast(StackFrame *frame)
Definition: frames.h:754
bool is_stub_failure_trampoline() const
Definition: frames.h:251
static const int kCallerFPOffset
Definition: frames.h:188
bool is_optimized() const
Definition: frames.h:248
int ComputeParametersCount() const
Definition: frames.h:585
Address sp() const
Definition: frames.h:263
bool is_internal() const
Definition: frames.h:250
virtual Type type() const
Definition: frames.h:717
bool is_construct() const
Definition: frames.h:254
#define STACK_FRAME_TYPE_LIST(V)
Definition: frames.h:159
#define DECLARE_TYPE(type, ignore)
Definition: frames.h:200
Handle< Object > receiver()
Definition: frames.h:555
int JSCallerSavedCode(int n)
Definition: frames.cc:1610
virtual Type type() const
Definition: frames.h:686
const Register sp
HANDLE HANDLE LPSTACKFRAME64 StackFrame
Address pc() const
Definition: frames.h:272
#define DECLARE_SINGLETON(ignore, type)
Definition: frames.h:833
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_string(expose_natives_as
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
const bool can_access_heap_objects_
Definition: frames.h:838
StackFrame * frame() const
Definition: frames.h:863
StackHandler * handler() const
Definition: frames.h:840
PrologueFrameMode
Definition: frames.h:957
virtual void Print(StringStream *accumulator, PrintMode mode, int index) const
Definition: frames.h:333
bool is_exit() const
Definition: frames.h:247
Address * pc_address() const
Definition: frames.h:285
const int kPointerSize
Definition: globals.h:268
intptr_t OffsetFrom(T x)
Definition: utils.h:120
bool is_arguments_adaptor() const
Definition: frames.h:249
uintptr_t(* ReturnAddressLocationResolver)(uintptr_t return_addr_location)
Definition: v8.h:4494
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition: globals.h:370
static const int kConstantPoolOffset
Definition: frames.h:186
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
const int kFPOnStackSize
Definition: globals.h:271
static const int kCallerSPOffset
Definition: frames.h:190
FrameSummary(Object *receiver, JSFunction *function, Code *code, int offset, bool is_constructor)
Definition: frames.h:545
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:359
const Register pc
static const int kCallerPCOffset
Definition: frames.h:189
Code * code
Definition: frames.h:63
static const int kMarkerOffset
Definition: frames.h:184
virtual Type type() const
Definition: frames.h:420
static const int kLastObjectOffset
Definition: frames.h:192
virtual Type type() const
Definition: frames.h:440
static const int kExpressionsOffset
Definition: frames.h:183
void set_pc(Address pc)
Definition: frames.h:273
virtual Type type() const
Definition: frames.h:746
static JavaScriptFrame * cast(StackFrame *frame)
Definition: frames.h:635
#define BASE_EMBEDDED
Definition: allocation.h:68
bool is_entry() const
Definition: frames.h:245
static ExitFrame * cast(StackFrame *frame)
Definition: frames.h:452
Address caller_sp() const
Definition: frames.h:265
Isolate * isolate() const
Definition: frames.h:337
static const int kFixedFrameSizeFromFp
Definition: frames.h:180
void SetUpJSCallerSavedCodeData()
Definition: frames.cc:1600
InnerPointerToCodeCacheEntry * GetCacheEntry(Address inner_pointer)
Definition: frames.cc:1509
Definition: frames.h:418
static const int kContextOffset
Definition: frames.h:97
Address constant_pool() const
Definition: frames.h:275
virtual Type type() const
Definition: frames.h:665
StackFrameLocator(Isolate *isolate)
Definition: frames.h:945
Handle< Code > code()
Definition: frames.h:557
bool is_java_script() const
Definition: frames.h:257
void Print(const v8::FunctionCallbackInfo< v8::Value > &args)
Address inner_pointer
Definition: frames.h:62
virtual Type type() const
Definition: frames.h:575
SafepointEntry safepoint_entry
Definition: frames.h:64
virtual bool is_standard() const
Definition: frames.h:479
bool is_entry_construct() const
Definition: frames.h:246
const Register fp
const int kPCOnStackSize
Definition: globals.h:270
StackFrame(const StackFrame &original)
Definition: frames.h:238
Code * GcSafeFindCodeForInnerPointer(Address inner_pointer)
Definition: frames.cc:1475
static EntryConstructFrame * cast(StackFrame *frame)
Definition: frames.h:424
virtual int GetInlineCount()
Definition: frames.h:622
static ArgumentsAdaptorFrame * cast(StackFrame *frame)
Definition: frames.h:722
Definition: frames.h:387
void set_constant_pool(ConstantPoolArray *constant_pool)
Definition: frames.h:276
virtual Address GetCallerStackPointer() const
Definition: frames.h:408
virtual Type type() const
Definition: frames.h:389