1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "src/allocation.h"
9 #include "src/handles.h"
10 #include "src/safepoint-table.h"
15 #if V8_TARGET_ARCH_ARM64
16 typedef uint64_t RegList;
18 typedef uint32_t RegList;
21 // Get the number of registers in a given register list.
22 int NumRegs(RegList list);
24 void SetUpJSCallerSavedCodeData();
26 // Return the code of the n-th saved register available to JavaScript.
27 int JSCallerSavedCode(int n);
30 // Forward declarations.
31 class ExternalCallbackScope;
32 class StackFrameIteratorBase;
36 class InnerPointerToCodeCache {
38 struct InnerPointerToCodeCacheEntry {
39 Address inner_pointer;
41 SafepointEntry safepoint_entry;
44 explicit InnerPointerToCodeCache(Isolate* isolate) : isolate_(isolate) {
48 Code* GcSafeFindCodeForInnerPointer(Address inner_pointer);
49 Code* GcSafeCastToCode(HeapObject* object, Address inner_pointer);
52 memset(&cache_[0], 0, sizeof(cache_));
55 InnerPointerToCodeCacheEntry* GetCacheEntry(Address inner_pointer);
58 InnerPointerToCodeCacheEntry* cache(int index) { return &cache_[index]; }
62 static const int kInnerPointerToCodeCacheSize = 1024;
63 InnerPointerToCodeCacheEntry cache_[kInnerPointerToCodeCacheSize];
65 DISALLOW_COPY_AND_ASSIGN(InnerPointerToCodeCache);
69 class StackHandlerConstants : public AllStatic {
71 static const int kNextOffset = 0 * kPointerSize;
72 static const int kCodeOffset = 1 * kPointerSize;
73 static const int kStateOffset = 2 * kPointerSize;
74 #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT
75 static const int kStateIntOffset = kStateOffset;
77 static const int kStateIntOffset = kStateOffset + kIntSize;
79 static const int kContextOffset = 3 * kPointerSize;
80 static const int kFPOffset = 4 * kPointerSize;
82 static const int kSize = kFPOffset + kFPOnStackSize;
83 static const int kSlotCount = kSize >> kPointerSizeLog2;
87 class StackHandler BASE_EMBEDDED {
96 static const int kKindWidth = 2;
97 STATIC_ASSERT(LAST_KIND < (1 << kKindWidth));
98 static const int kIndexWidth = 32 - kKindWidth;
99 class KindField: public BitField<StackHandler::Kind, 0, kKindWidth> {};
100 class IndexField: public BitField<unsigned, kKindWidth, kIndexWidth> {};
102 // Get the address of this stack handler.
103 inline Address address() const;
105 // Get the next stack handler in the chain.
106 inline StackHandler* next() const;
108 // Tells whether the given address is inside this handler.
109 inline bool includes(Address address) const;
111 // Garbage collection support.
112 inline void Iterate(ObjectVisitor* v, Code* holder) const;
114 // Conversion support.
115 static inline StackHandler* FromAddress(Address address);
118 inline bool is_js_entry() const;
119 inline bool is_catch() const;
120 inline bool is_finally() const;
122 // Generator support to preserve stack handlers.
123 void Unwind(Isolate* isolate, FixedArray* array, int offset,
124 int previous_handler_offset) const;
125 int Rewind(Isolate* isolate, FixedArray* array, int offset, Address fp);
129 inline Kind kind() const;
130 inline unsigned index() const;
132 inline Object** constant_pool_address() const;
133 inline Object** context_address() const;
134 inline Object** code_address() const;
135 inline void SetFp(Address slot, Address fp);
137 DISALLOW_IMPLICIT_CONSTRUCTORS(StackHandler);
141 #define STACK_FRAME_TYPE_LIST(V) \
142 V(ENTRY, EntryFrame) \
143 V(ENTRY_CONSTRUCT, EntryConstructFrame) \
145 V(JAVA_SCRIPT, JavaScriptFrame) \
146 V(OPTIMIZED, OptimizedFrame) \
148 V(STUB_FAILURE_TRAMPOLINE, StubFailureTrampolineFrame) \
149 V(INTERNAL, InternalFrame) \
150 V(CONSTRUCT, ConstructFrame) \
151 V(ARGUMENTS_ADAPTOR, ArgumentsAdaptorFrame)
154 class StandardFrameConstants : public AllStatic {
156 // Fixed part of the frame consists of return address, caller fp,
157 // constant pool (if FLAG_enable_ool_constant_pool), context, and function.
158 // StandardFrame::IterateExpressions assumes that kLastObjectOffset is the
159 // last object pointer.
160 static const int kCPSlotSize =
161 FLAG_enable_ool_constant_pool ? kPointerSize : 0;
162 static const int kFixedFrameSizeFromFp = 2 * kPointerSize + kCPSlotSize;
163 static const int kFixedFrameSize = kPCOnStackSize + kFPOnStackSize +
164 kFixedFrameSizeFromFp;
165 static const int kExpressionsOffset = -3 * kPointerSize - kCPSlotSize;
166 static const int kMarkerOffset = -2 * kPointerSize - kCPSlotSize;
167 static const int kContextOffset = -1 * kPointerSize - kCPSlotSize;
168 static const int kConstantPoolOffset = FLAG_enable_ool_constant_pool ?
169 -1 * kPointerSize : 0;
170 static const int kCallerFPOffset = 0 * kPointerSize;
171 static const int kCallerPCOffset = +1 * kFPOnStackSize;
172 static const int kCallerSPOffset = kCallerPCOffset + 1 * kPCOnStackSize;
174 static const int kLastObjectOffset = FLAG_enable_ool_constant_pool ?
175 kConstantPoolOffset : kContextOffset;
179 // Abstract base class for all stack frames.
180 class StackFrame BASE_EMBEDDED {
182 #define DECLARE_TYPE(type, ignore) type,
185 STACK_FRAME_TYPE_LIST(DECLARE_TYPE)
187 // Used by FrameScope to indicate that the stack frame is constructed
188 // manually and the FrameScope does not need to emit code.
193 // Opaque data type for identifying stack frames. Used extensively
195 // ID_MIN_VALUE and ID_MAX_VALUE are specified to ensure that enumeration type
196 // has correct value range (see Issue 830 for more details).
198 ID_MIN_VALUE = kMinInt,
199 ID_MAX_VALUE = kMaxInt,
203 // Used to mark the outermost JS entry frame.
205 INNER_JSENTRY_FRAME = 0,
206 OUTERMOST_JSENTRY_FRAME = 1
210 State() : sp(NULL), fp(NULL), pc_address(NULL),
211 constant_pool_address(NULL) { }
215 Address* constant_pool_address;
218 // Copy constructor; it breaks the connection to host iterator
219 // (as an iterator usually lives on stack).
220 StackFrame(const StackFrame& original) {
221 this->state_ = original.state_;
222 this->iterator_ = NULL;
223 this->isolate_ = original.isolate_;
227 bool is_entry() const { return type() == ENTRY; }
228 bool is_entry_construct() const { return type() == ENTRY_CONSTRUCT; }
229 bool is_exit() const { return type() == EXIT; }
230 bool is_optimized() const { return type() == OPTIMIZED; }
231 bool is_arguments_adaptor() const { return type() == ARGUMENTS_ADAPTOR; }
232 bool is_internal() const { return type() == INTERNAL; }
233 bool is_stub_failure_trampoline() const {
234 return type() == STUB_FAILURE_TRAMPOLINE;
236 bool is_construct() const { return type() == CONSTRUCT; }
237 virtual bool is_standard() const { return false; }
239 bool is_java_script() const {
240 Type type = this->type();
241 return (type == JAVA_SCRIPT) || (type == OPTIMIZED);
245 Address sp() const { return state_.sp; }
246 Address fp() const { return state_.fp; }
247 Address caller_sp() const { return GetCallerStackPointer(); }
249 // If this frame is optimized and was dynamically aligned return its old
250 // unaligned frame pointer. When the frame is deoptimized its FP will shift
251 // up one word and become unaligned.
252 Address UnpaddedFP() const;
254 Address pc() const { return *pc_address(); }
255 void set_pc(Address pc) { *pc_address() = pc; }
257 Address constant_pool() const { return *constant_pool_address(); }
258 void set_constant_pool(ConstantPoolArray* constant_pool) {
259 *constant_pool_address() = reinterpret_cast<Address>(constant_pool);
262 virtual void SetCallerFp(Address caller_fp) = 0;
264 // Manually changes value of fp in this object.
265 void UpdateFp(Address fp) { state_.fp = fp; }
267 Address* pc_address() const { return state_.pc_address; }
269 Address* constant_pool_address() const {
270 return state_.constant_pool_address;
273 // Get the id of this stack frame.
274 Id id() const { return static_cast<Id>(OffsetFrom(caller_sp())); }
276 // Checks if this frame includes any stack handlers.
277 bool HasHandler() const;
279 // Get the type of this frame.
280 virtual Type type() const = 0;
282 // Get the code associated with this frame.
283 // This method could be called during marking phase of GC.
284 virtual Code* unchecked_code() const = 0;
286 // Get the code associated with this frame.
287 inline Code* LookupCode() const;
289 // Get the code object that contains the given pc.
290 static inline Code* GetContainingCode(Isolate* isolate, Address pc);
292 // Get the code object containing the given pc and fill in the
293 // safepoint entry and the number of stack slots. The pc must be at
295 static Code* GetSafepointData(Isolate* isolate,
297 SafepointEntry* safepoint_entry,
298 unsigned* stack_slots);
300 virtual void Iterate(ObjectVisitor* v) const = 0;
301 static void IteratePc(ObjectVisitor* v, Address* pc_address, Code* holder);
303 // Sets a callback function for return-address rewriting profilers
304 // to resolve the location of a return address to the location of the
305 // profiler's stashed return address.
306 static void SetReturnAddressLocationResolver(
307 ReturnAddressLocationResolver resolver);
309 // Resolves pc_address through the resolution address function if one is set.
310 static inline Address* ResolveReturnAddressLocation(Address* pc_address);
314 enum PrintMode { OVERVIEW, DETAILS };
315 virtual void Print(StringStream* accumulator,
319 Isolate* isolate() const { return isolate_; }
322 inline explicit StackFrame(StackFrameIteratorBase* iterator);
323 virtual ~StackFrame() { }
325 // Compute the stack pointer for the calling frame.
326 virtual Address GetCallerStackPointer() const = 0;
329 static void PrintIndex(StringStream* accumulator,
333 // Get the top handler from the current stack iterator.
334 inline StackHandler* top_handler() const;
336 // Compute the stack frame type for the given state.
337 static Type ComputeType(const StackFrameIteratorBase* iterator, State* state);
340 bool can_access_heap_objects() const;
344 const StackFrameIteratorBase* iterator_;
348 static ReturnAddressLocationResolver return_address_location_resolver_;
350 // Fill in the state of the calling frame.
351 virtual void ComputeCallerState(State* state) const = 0;
353 // Get the type and the state of the calling frame.
354 virtual Type GetCallerState(State* state) const;
356 static const intptr_t kIsolateTag = 1;
358 friend class StackFrameIterator;
359 friend class StackFrameIteratorBase;
360 friend class StackHandlerIterator;
361 friend class SafeStackFrameIterator;
364 void operator=(const StackFrame& original);
368 // Entry frames are used to enter JavaScript execution from C.
369 class EntryFrame: public StackFrame {
371 virtual Type type() const { return ENTRY; }
373 virtual Code* unchecked_code() const;
375 // Garbage collection support.
376 virtual void Iterate(ObjectVisitor* v) const;
378 static EntryFrame* cast(StackFrame* frame) {
379 DCHECK(frame->is_entry());
380 return static_cast<EntryFrame*>(frame);
382 virtual void SetCallerFp(Address caller_fp);
385 inline explicit EntryFrame(StackFrameIteratorBase* iterator);
387 // The caller stack pointer for entry frames is always zero. The
388 // real information about the caller frame is available through the
389 // link to the top exit frame.
390 virtual Address GetCallerStackPointer() const { return 0; }
393 virtual void ComputeCallerState(State* state) const;
394 virtual Type GetCallerState(State* state) const;
396 friend class StackFrameIteratorBase;
400 class EntryConstructFrame: public EntryFrame {
402 virtual Type type() const { return ENTRY_CONSTRUCT; }
404 virtual Code* unchecked_code() const;
406 static EntryConstructFrame* cast(StackFrame* frame) {
407 DCHECK(frame->is_entry_construct());
408 return static_cast<EntryConstructFrame*>(frame);
412 inline explicit EntryConstructFrame(StackFrameIteratorBase* iterator);
415 friend class StackFrameIteratorBase;
419 // Exit frames are used to exit JavaScript execution and go to C.
420 class ExitFrame: public StackFrame {
422 virtual Type type() const { return EXIT; }
424 virtual Code* unchecked_code() const;
426 Object*& code_slot() const;
427 Object*& constant_pool_slot() const;
429 // Garbage collection support.
430 virtual void Iterate(ObjectVisitor* v) const;
432 virtual void SetCallerFp(Address caller_fp);
434 static ExitFrame* cast(StackFrame* frame) {
435 DCHECK(frame->is_exit());
436 return static_cast<ExitFrame*>(frame);
439 // Compute the state and type of an exit frame given a frame
440 // pointer. Used when constructing the first stack frame seen by an
441 // iterator and the frames following entry frames.
442 static Type GetStateForFramePointer(Address fp, State* state);
443 static Address ComputeStackPointer(Address fp);
444 static void FillState(Address fp, Address sp, State* state);
447 inline explicit ExitFrame(StackFrameIteratorBase* iterator);
449 virtual Address GetCallerStackPointer() const;
452 virtual void ComputeCallerState(State* state) const;
454 friend class StackFrameIteratorBase;
458 class StandardFrame: public StackFrame {
461 virtual bool is_standard() const { return true; }
464 inline Object* context() const;
466 // Access the expressions in the stack frame including locals.
467 inline Object* GetExpression(int index) const;
468 inline void SetExpression(int index, Object* value);
469 int ComputeExpressionsCount() const;
470 static Object* GetExpression(Address fp, int index);
472 virtual void SetCallerFp(Address caller_fp);
474 static StandardFrame* cast(StackFrame* frame) {
475 DCHECK(frame->is_standard());
476 return static_cast<StandardFrame*>(frame);
480 inline explicit StandardFrame(StackFrameIteratorBase* iterator);
482 virtual void ComputeCallerState(State* state) const;
485 inline Address caller_fp() const;
486 inline Address caller_pc() const;
488 // Computes the address of the PC field in the standard frame given
489 // by the provided frame pointer.
490 static inline Address ComputePCAddress(Address fp);
492 // Computes the address of the constant pool field in the standard
493 // frame given by the provided frame pointer.
494 static inline Address ComputeConstantPoolAddress(Address fp);
496 // Iterate over expression stack including stack handlers, locals,
497 // and parts of the fixed part including context and code fields.
498 void IterateExpressions(ObjectVisitor* v) const;
500 // Returns the address of the n'th expression stack element.
501 Address GetExpressionAddress(int n) const;
502 static Address GetExpressionAddress(Address fp, int n);
504 // Determines if the n'th expression stack element is in a stack
505 // handler or not. Requires traversing all handlers in this frame.
506 bool IsExpressionInsideHandler(int n) const;
508 // Determines if the standard frame for the given frame pointer is
509 // an arguments adaptor frame.
510 static inline bool IsArgumentsAdaptorFrame(Address fp);
512 // Determines if the standard frame for the given frame pointer is a
514 static inline bool IsConstructFrame(Address fp);
516 // Used by OptimizedFrames and StubFrames.
517 void IterateCompiledFrame(ObjectVisitor* v) const;
520 friend class StackFrame;
521 friend class SafeStackFrameIterator;
525 class FrameSummary BASE_EMBEDDED {
527 FrameSummary(Object* receiver,
528 JSFunction* function,
532 : receiver_(receiver, function->GetIsolate()),
536 is_constructor_(is_constructor) { }
537 Handle<Object> receiver() { return receiver_; }
538 Handle<JSFunction> function() { return function_; }
539 Handle<Code> code() { return code_; }
540 Address pc() { return code_->address() + offset_; }
541 int offset() { return offset_; }
542 bool is_constructor() { return is_constructor_; }
547 Handle<Object> receiver_;
548 Handle<JSFunction> function_;
551 bool is_constructor_;
555 class JavaScriptFrame: public StandardFrame {
557 virtual Type type() const { return JAVA_SCRIPT; }
560 inline JSFunction* function() const;
561 inline Object* receiver() const;
562 inline void set_receiver(Object* value);
564 // Access the parameters.
565 inline Address GetParameterSlot(int index) const;
566 inline Object* GetParameter(int index) const;
567 inline int ComputeParametersCount() const {
568 return GetNumberOfIncomingArguments();
571 // Access the operand stack.
572 inline Address GetOperandSlot(int index) const;
573 inline Object* GetOperand(int index) const;
574 inline int ComputeOperandsCount() const;
576 // Generator support to preserve operand stack and stack handlers.
577 void SaveOperandStack(FixedArray* store, int* stack_handler_index) const;
578 void RestoreOperandStack(FixedArray* store, int stack_handler_index);
581 void SetParameterValue(int index, Object* value) const;
583 // Check if this frame is a constructor frame invoked through 'new'.
584 bool IsConstructor() const;
586 // Check if this frame has "adapted" arguments in the sense that the
587 // actual passed arguments are available in an arguments adaptor
588 // frame below it on the stack.
589 inline bool has_adapted_arguments() const;
590 int GetArgumentsLength() const;
592 // Garbage collection support.
593 virtual void Iterate(ObjectVisitor* v) const;
596 virtual void Print(StringStream* accumulator,
600 // Determine the code for the frame.
601 virtual Code* unchecked_code() const;
603 // Returns the levels of inlining for this frame.
604 virtual int GetInlineCount() { return 1; }
606 // Return a list with JSFunctions of this frame.
607 virtual void GetFunctions(List<JSFunction*>* functions);
609 // Build a list with summaries for this frame including all inlined frames.
610 virtual void Summarize(List<FrameSummary>* frames);
612 // Architecture-specific register description.
613 static Register fp_register();
614 static Register context_register();
615 static Register constant_pool_pointer_register();
617 static JavaScriptFrame* cast(StackFrame* frame) {
618 DCHECK(frame->is_java_script());
619 return static_cast<JavaScriptFrame*>(frame);
622 static void PrintFunctionAndOffset(JSFunction* function, Code* code,
623 Address pc, FILE* file,
624 bool print_line_number);
626 static void PrintTop(Isolate* isolate, FILE* file, bool print_args,
627 bool print_line_number);
630 inline explicit JavaScriptFrame(StackFrameIteratorBase* iterator);
632 virtual Address GetCallerStackPointer() const;
634 virtual int GetNumberOfIncomingArguments() const;
636 // Garbage collection support. Iterates over incoming arguments,
637 // receiver, and any callee-saved registers.
638 void IterateArguments(ObjectVisitor* v) const;
641 inline Object* function_slot_object() const;
643 friend class StackFrameIteratorBase;
647 class StubFrame : public StandardFrame {
649 virtual Type type() const { return STUB; }
652 virtual void Iterate(ObjectVisitor* v) const;
654 // Determine the code for the frame.
655 virtual Code* unchecked_code() const;
658 inline explicit StubFrame(StackFrameIteratorBase* iterator);
660 virtual Address GetCallerStackPointer() const;
662 virtual int GetNumberOfIncomingArguments() const;
664 friend class StackFrameIteratorBase;
668 class OptimizedFrame : public JavaScriptFrame {
670 virtual Type type() const { return OPTIMIZED; }
673 virtual void Iterate(ObjectVisitor* v) const;
675 virtual int GetInlineCount();
677 // Return a list with JSFunctions of this frame.
678 // The functions are ordered bottom-to-top (i.e. functions.last()
679 // is the top-most activation)
680 virtual void GetFunctions(List<JSFunction*>* functions);
682 virtual void Summarize(List<FrameSummary>* frames);
684 DeoptimizationInputData* GetDeoptimizationData(int* deopt_index);
687 inline explicit OptimizedFrame(StackFrameIteratorBase* iterator);
690 JSFunction* LiteralAt(FixedArray* literal_array, int literal_id);
692 friend class StackFrameIteratorBase;
696 // Arguments adaptor frames are automatically inserted below
697 // JavaScript frames when the actual number of parameters does not
698 // match the formal number of parameters.
699 class ArgumentsAdaptorFrame: public JavaScriptFrame {
701 virtual Type type() const { return ARGUMENTS_ADAPTOR; }
703 // Determine the code for the frame.
704 virtual Code* unchecked_code() const;
706 static ArgumentsAdaptorFrame* cast(StackFrame* frame) {
707 DCHECK(frame->is_arguments_adaptor());
708 return static_cast<ArgumentsAdaptorFrame*>(frame);
712 virtual void Print(StringStream* accumulator,
717 inline explicit ArgumentsAdaptorFrame(StackFrameIteratorBase* iterator);
719 virtual int GetNumberOfIncomingArguments() const;
721 virtual Address GetCallerStackPointer() const;
724 friend class StackFrameIteratorBase;
728 class InternalFrame: public StandardFrame {
730 virtual Type type() const { return INTERNAL; }
732 // Garbage collection support.
733 virtual void Iterate(ObjectVisitor* v) const;
735 // Determine the code for the frame.
736 virtual Code* unchecked_code() const;
738 static InternalFrame* cast(StackFrame* frame) {
739 DCHECK(frame->is_internal());
740 return static_cast<InternalFrame*>(frame);
744 inline explicit InternalFrame(StackFrameIteratorBase* iterator);
746 virtual Address GetCallerStackPointer() const;
749 friend class StackFrameIteratorBase;
753 class StubFailureTrampolineFrame: public StandardFrame {
755 // sizeof(Arguments) - sizeof(Arguments*) is 3 * kPointerSize), but the
756 // presubmit script complains about using sizeof() on a type.
757 static const int kFirstRegisterParameterFrameOffset =
758 StandardFrameConstants::kMarkerOffset - 3 * kPointerSize;
760 static const int kCallerStackParameterCountFrameOffset =
761 StandardFrameConstants::kMarkerOffset - 2 * kPointerSize;
763 virtual Type type() const { return STUB_FAILURE_TRAMPOLINE; }
765 // Get the code associated with this frame.
766 // This method could be called during marking phase of GC.
767 virtual Code* unchecked_code() const;
769 virtual void Iterate(ObjectVisitor* v) const;
771 // Architecture-specific register description.
772 static Register fp_register();
773 static Register context_register();
774 static Register constant_pool_pointer_register();
777 inline explicit StubFailureTrampolineFrame(
778 StackFrameIteratorBase* iterator);
780 virtual Address GetCallerStackPointer() const;
783 friend class StackFrameIteratorBase;
787 // Construct frames are special trampoline frames introduced to handle
788 // function invocations through 'new'.
789 class ConstructFrame: public InternalFrame {
791 virtual Type type() const { return CONSTRUCT; }
793 static ConstructFrame* cast(StackFrame* frame) {
794 DCHECK(frame->is_construct());
795 return static_cast<ConstructFrame*>(frame);
799 inline explicit ConstructFrame(StackFrameIteratorBase* iterator);
802 friend class StackFrameIteratorBase;
806 class StackFrameIteratorBase BASE_EMBEDDED {
808 Isolate* isolate() const { return isolate_; }
810 bool done() const { return frame_ == NULL; }
813 // An iterator that iterates over a given thread's stack.
814 StackFrameIteratorBase(Isolate* isolate, bool can_access_heap_objects);
817 #define DECLARE_SINGLETON(ignore, type) type type##_;
818 STACK_FRAME_TYPE_LIST(DECLARE_SINGLETON)
819 #undef DECLARE_SINGLETON
821 StackHandler* handler_;
822 const bool can_access_heap_objects_;
824 StackHandler* handler() const {
829 // Get the type-specific frame singleton in a given state.
830 StackFrame* SingletonFor(StackFrame::Type type, StackFrame::State* state);
831 // A helper function, can return a NULL pointer.
832 StackFrame* SingletonFor(StackFrame::Type type);
835 friend class StackFrame;
836 DISALLOW_COPY_AND_ASSIGN(StackFrameIteratorBase);
840 class StackFrameIterator: public StackFrameIteratorBase {
842 // An iterator that iterates over the isolate's current thread's stack,
843 explicit StackFrameIterator(Isolate* isolate);
844 // An iterator that iterates over a given thread's stack.
845 StackFrameIterator(Isolate* isolate, ThreadLocalTop* t);
847 StackFrame* frame() const {
854 // Go back to the first frame.
855 void Reset(ThreadLocalTop* top);
857 DISALLOW_COPY_AND_ASSIGN(StackFrameIterator);
861 // Iterator that supports iterating through all JavaScript frames.
862 class JavaScriptFrameIterator BASE_EMBEDDED {
864 inline explicit JavaScriptFrameIterator(Isolate* isolate);
865 inline JavaScriptFrameIterator(Isolate* isolate, ThreadLocalTop* top);
866 // Skip frames until the frame with the given id is reached.
867 JavaScriptFrameIterator(Isolate* isolate, StackFrame::Id id);
869 inline JavaScriptFrame* frame() const;
871 bool done() const { return iterator_.done(); }
874 // Advance to the frame holding the arguments for the current
875 // frame. This only affects the current frame if it has adapted
877 void AdvanceToArgumentsFrame();
880 StackFrameIterator iterator_;
884 // NOTE: The stack trace frame iterator is an iterator that only
885 // traverse proper JavaScript frames; that is JavaScript frames that
886 // have proper JavaScript functions. This excludes the problematic
887 // functions in runtime.js.
888 class StackTraceFrameIterator: public JavaScriptFrameIterator {
890 explicit StackTraceFrameIterator(Isolate* isolate);
898 class SafeStackFrameIterator: public StackFrameIteratorBase {
900 SafeStackFrameIterator(Isolate* isolate,
901 Address fp, Address sp,
902 Address js_entry_sp);
904 inline StackFrame* frame() const;
907 StackFrame::Type top_frame_type() const { return top_frame_type_; }
910 void AdvanceOneFrame();
912 bool IsValidStackAddress(Address addr) const {
913 return low_bound_ <= addr && addr <= high_bound_;
915 bool IsValidFrame(StackFrame* frame) const;
916 bool IsValidCaller(StackFrame* frame);
917 bool IsValidExitFrame(Address fp) const;
918 bool IsValidTop(ThreadLocalTop* top) const;
920 const Address low_bound_;
921 const Address high_bound_;
922 StackFrame::Type top_frame_type_;
923 ExternalCallbackScope* external_callback_scope_;
927 class StackFrameLocator BASE_EMBEDDED {
929 explicit StackFrameLocator(Isolate* isolate) : iterator_(isolate) {}
931 // Find the nth JavaScript frame on the stack. The caller must
932 // guarantee that such a frame exists.
933 JavaScriptFrame* FindJavaScriptFrame(int n);
936 StackFrameIterator iterator_;
940 // Reads all frames on the current stack and copies them into the current
942 Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone);
944 } } // namespace v8::internal
946 #endif // V8_FRAMES_H_