Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: src/frames.h

Issue 16917004: Simplify stack iterators implementation (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use iterator_.frame() instead of frame() to avoid assertion failure Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/frames.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 StackFrame* frame() const { 790 StackFrame* frame() const {
791 ASSERT(!done()); 791 ASSERT(!done());
792 return frame_; 792 return frame_;
793 } 793 }
794 794
795 Isolate* isolate() const { return isolate_; } 795 Isolate* isolate() const { return isolate_; }
796 796
797 bool done() const { return frame_ == NULL; } 797 bool done() const { return frame_ == NULL; }
798 void Advance() { (this->*advance_)(); } 798 void Advance() { (this->*advance_)(); }
799 799
800 private:
800 // Go back to the first frame. 801 // Go back to the first frame.
801 void Reset(); 802 void Reset();
802 803
803 private:
804 Isolate* isolate_; 804 Isolate* isolate_;
805 #define DECLARE_SINGLETON(ignore, type) type type##_; 805 #define DECLARE_SINGLETON(ignore, type) type type##_;
806 STACK_FRAME_TYPE_LIST(DECLARE_SINGLETON) 806 STACK_FRAME_TYPE_LIST(DECLARE_SINGLETON)
807 #undef DECLARE_SINGLETON 807 #undef DECLARE_SINGLETON
808 StackFrame* frame_; 808 StackFrame* frame_;
809 StackHandler* handler_; 809 StackHandler* handler_;
810 ThreadLocalTop* thread_; 810 ThreadLocalTop* thread_;
811 Address fp_; 811 Address fp_;
812 Address sp_; 812 Address sp_;
813 void (StackFrameIterator::*advance_)(); 813 void (StackFrameIterator::*advance_)();
(...skipping 11 matching lines...) Expand all
825 void AdvanceWithHandler(); 825 void AdvanceWithHandler();
826 void AdvanceWithoutHandler(); 826 void AdvanceWithoutHandler();
827 827
828 friend class StackFrame; 828 friend class StackFrame;
829 friend class SafeStackFrameIterator; 829 friend class SafeStackFrameIterator;
830 DISALLOW_COPY_AND_ASSIGN(StackFrameIterator); 830 DISALLOW_COPY_AND_ASSIGN(StackFrameIterator);
831 }; 831 };
832 832
833 833
834 // Iterator that supports iterating through all JavaScript frames. 834 // Iterator that supports iterating through all JavaScript frames.
835 template<typename Iterator> 835 class JavaScriptFrameIterator BASE_EMBEDDED {
836 class JavaScriptFrameIteratorTemp BASE_EMBEDDED {
837 public: 836 public:
838 inline explicit JavaScriptFrameIteratorTemp(Isolate* isolate); 837 inline explicit JavaScriptFrameIterator(Isolate* isolate);
839 838 inline JavaScriptFrameIterator(Isolate* isolate, ThreadLocalTop* top);
840 inline JavaScriptFrameIteratorTemp(Isolate* isolate, ThreadLocalTop* top);
841
842 // Skip frames until the frame with the given id is reached. 839 // Skip frames until the frame with the given id is reached.
843 explicit JavaScriptFrameIteratorTemp(StackFrame::Id id) { AdvanceToId(id); } 840 JavaScriptFrameIterator(Isolate* isolate, StackFrame::Id id);
844
845 inline JavaScriptFrameIteratorTemp(Isolate* isolate, StackFrame::Id id);
846
847 JavaScriptFrameIteratorTemp(Address fp,
848 Address sp,
849 Address low_bound,
850 Address high_bound) :
851 iterator_(fp, sp, low_bound, high_bound) {
852 if (!done()) Advance();
853 }
854
855 JavaScriptFrameIteratorTemp(Isolate* isolate,
856 Address fp,
857 Address sp,
858 Address low_bound,
859 Address high_bound) :
860 iterator_(isolate, fp, sp, low_bound, high_bound) {
861 if (!done()) Advance();
862 }
863 841
864 inline JavaScriptFrame* frame() const; 842 inline JavaScriptFrame* frame() const;
865 843
866 bool done() const { return iterator_.done(); } 844 bool done() const { return iterator_.done(); }
867 void Advance(); 845 void Advance();
868 846
869 // Advance to the frame holding the arguments for the current 847 // Advance to the frame holding the arguments for the current
870 // frame. This only affects the current frame if it has adapted 848 // frame. This only affects the current frame if it has adapted
871 // arguments. 849 // arguments.
872 void AdvanceToArgumentsFrame(); 850 void AdvanceToArgumentsFrame();
873 851
874 // Go back to the first frame.
875 void Reset();
876
877 private: 852 private:
878 inline void AdvanceToId(StackFrame::Id id); 853 StackFrameIterator iterator_;
879
880 Iterator iterator_;
881 }; 854 };
882 855
883 856
884 typedef JavaScriptFrameIteratorTemp<StackFrameIterator> JavaScriptFrameIterator;
885
886
887 // NOTE: The stack trace frame iterator is an iterator that only 857 // NOTE: The stack trace frame iterator is an iterator that only
888 // traverse proper JavaScript frames; that is JavaScript frames that 858 // traverse proper JavaScript frames; that is JavaScript frames that
889 // have proper JavaScript functions. This excludes the problematic 859 // have proper JavaScript functions. This excludes the problematic
890 // functions in runtime.js. 860 // functions in runtime.js.
891 class StackTraceFrameIterator: public JavaScriptFrameIterator { 861 class StackTraceFrameIterator: public JavaScriptFrameIterator {
892 public: 862 public:
893 StackTraceFrameIterator(); 863 StackTraceFrameIterator();
894 explicit StackTraceFrameIterator(Isolate* isolate); 864 explicit StackTraceFrameIterator(Isolate* isolate);
895 void Advance(); 865 void Advance();
896 866
897 private: 867 private:
898 bool IsValidFrame(); 868 bool IsValidFrame();
899 }; 869 };
900 870
901 871
902 class SafeStackFrameIterator BASE_EMBEDDED { 872 class SafeStackFrameIterator BASE_EMBEDDED {
903 public: 873 public:
904 SafeStackFrameIterator(Isolate* isolate, 874 SafeStackFrameIterator(Isolate* isolate,
905 Address fp, Address sp, 875 Address fp, Address sp,
906 Address low_bound, Address high_bound); 876 Address low_bound, Address high_bound);
907 877
908 StackFrame* frame() const { 878 StackFrame* frame() const {
909 ASSERT(is_working_iterator_); 879 ASSERT(is_working_iterator_);
910 return iterator_.frame(); 880 return iterator_.frame();
911 } 881 }
912 882
913 bool done() const { return iteration_done_ ? true : iterator_.done(); } 883 bool done() const { return iteration_done_ ? true : iterator_.done(); }
914 884
915 void Advance(); 885 void Advance();
916 void Reset();
917 886
918 static bool is_active(Isolate* isolate); 887 static bool is_active(Isolate* isolate);
919 888
920 static bool IsWithinBounds( 889 static bool IsWithinBounds(
921 Address low_bound, Address high_bound, Address addr) { 890 Address low_bound, Address high_bound, Address addr) {
922 return low_bound <= addr && addr <= high_bound; 891 return low_bound <= addr && addr <= high_bound;
923 } 892 }
924 893
925 private: 894 private:
926 class StackAddressValidator { 895 class StackAddressValidator {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 ActiveCountMaintainer maintainer_; 940 ActiveCountMaintainer maintainer_;
972 StackAddressValidator stack_validator_; 941 StackAddressValidator stack_validator_;
973 const bool is_valid_top_; 942 const bool is_valid_top_;
974 const bool is_valid_fp_; 943 const bool is_valid_fp_;
975 const bool is_working_iterator_; 944 const bool is_working_iterator_;
976 bool iteration_done_; 945 bool iteration_done_;
977 StackFrameIterator iterator_; 946 StackFrameIterator iterator_;
978 }; 947 };
979 948
980 949
981 typedef JavaScriptFrameIteratorTemp<SafeStackFrameIterator> 950 class SafeStackTraceFrameIterator BASE_EMBEDDED {
982 SafeJavaScriptFrameIterator; 951 public:
952 SafeStackTraceFrameIterator(Isolate* isolate,
953 Address fp,
954 Address sp,
955 Address low_bound,
956 Address high_bound);
983 957
958 inline JavaScriptFrame* frame() const;
984 959
985 class SafeStackTraceFrameIterator: public SafeJavaScriptFrameIterator { 960 bool done() const { return iterator_.done(); }
986 public:
987 explicit SafeStackTraceFrameIterator(Isolate* isolate,
988 Address fp, Address sp,
989 Address low_bound, Address high_bound);
990 void Advance(); 961 void Advance();
962
963 private:
964 SafeStackFrameIterator iterator_;
991 }; 965 };
992 966
993 967
994 class StackFrameLocator BASE_EMBEDDED { 968 class StackFrameLocator BASE_EMBEDDED {
995 public: 969 public:
996 explicit StackFrameLocator(Isolate* isolate) : iterator_(isolate) {} 970 explicit StackFrameLocator(Isolate* isolate) : iterator_(isolate) {}
997 971
998 // Find the nth JavaScript frame on the stack. The caller must 972 // Find the nth JavaScript frame on the stack. The caller must
999 // guarantee that such a frame exists. 973 // guarantee that such a frame exists.
1000 JavaScriptFrame* FindJavaScriptFrame(int n); 974 JavaScriptFrame* FindJavaScriptFrame(int n);
1001 975
1002 private: 976 private:
1003 StackFrameIterator iterator_; 977 StackFrameIterator iterator_;
1004 }; 978 };
1005 979
1006 980
1007 // Reads all frames on the current stack and copies them into the current 981 // Reads all frames on the current stack and copies them into the current
1008 // zone memory. 982 // zone memory.
1009 Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone); 983 Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone);
1010 984
1011 } } // namespace v8::internal 985 } } // namespace v8::internal
1012 986
1013 #endif // V8_FRAMES_H_ 987 #endif // V8_FRAMES_H_
OLDNEW
« no previous file with comments | « no previous file | src/frames.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698