| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_FRAMES_H_ | 5 #ifndef V8_FRAMES_H_ |
| 6 #define V8_FRAMES_H_ | 6 #define V8_FRAMES_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/handles.h" | 9 #include "src/handles.h" |
| 10 #include "src/safepoint-table.h" | 10 #include "src/safepoint-table.h" |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 | 741 |
| 742 class FrameSummary BASE_EMBEDDED { | 742 class FrameSummary BASE_EMBEDDED { |
| 743 public: | 743 public: |
| 744 // Mode for JavaScriptFrame::Summarize. Exact summary is required to produce | 744 // Mode for JavaScriptFrame::Summarize. Exact summary is required to produce |
| 745 // an exact stack trace. It will trigger an assertion failure if that is not | 745 // an exact stack trace. It will trigger an assertion failure if that is not |
| 746 // possible, e.g., because of missing deoptimization information. The | 746 // possible, e.g., because of missing deoptimization information. The |
| 747 // approximate mode should produce a summary even without deoptimization | 747 // approximate mode should produce a summary even without deoptimization |
| 748 // information, but it might miss frames. | 748 // information, but it might miss frames. |
| 749 enum Mode { kExactSummary, kApproximateSummary }; | 749 enum Mode { kExactSummary, kApproximateSummary }; |
| 750 | 750 |
| 751 FrameSummary(Object* receiver, JSFunction* function, | 751 // Subclasses for the different summary kinds: |
| 752 AbstractCode* abstract_code, int code_offset, | 752 #define FRAME_SUMMARY_VARIANTS(F) \ |
| 753 bool is_constructor, Mode mode = kExactSummary); | 753 F(JAVA_SCRIPT, JavaScriptFrameSummary, java_script_summary_, JavaScript) \ |
| 754 F(WASM_COMPILED, WasmCompiledFrameSummary, wasm_compiled_summary_, \ |
| 755 WasmCompiled) \ |
| 756 F(WASM_INTERPRETED, WasmInterpretedFrameSummary, wasm_interpreted_summary_, \ |
| 757 WasmInterpreted) |
| 754 | 758 |
| 755 static FrameSummary GetFirst(StandardFrame* frame); | 759 #define FRAME_SUMMARY_KIND(kind, type, field, desc) kind, |
| 760 enum Kind { FRAME_SUMMARY_VARIANTS(FRAME_SUMMARY_KIND) }; |
| 761 #undef FRAME_SUMMARY_KIND |
| 756 | 762 |
| 757 Handle<Object> receiver() const { return receiver_; } | 763 class FrameSummaryBase { |
| 758 Handle<JSFunction> function() const { return function_; } | 764 public: |
| 759 Handle<AbstractCode> abstract_code() const { return abstract_code_; } | 765 FrameSummaryBase(Isolate* isolate, Kind kind) |
| 760 int code_offset() const { return code_offset_; } | 766 : isolate_(isolate), kind_(kind) {} |
| 761 bool is_constructor() const { return is_constructor_; } | 767 Isolate* isolate() const { return isolate_; } |
| 768 Kind kind() const { return kind_; } |
| 762 | 769 |
| 763 void Print(); | 770 private: |
| 771 Isolate* isolate_; |
| 772 Kind kind_; |
| 773 }; |
| 774 |
| 775 class JavaScriptFrameSummary : public FrameSummaryBase { |
| 776 public: |
| 777 JavaScriptFrameSummary(Isolate* isolate, Object* receiver, |
| 778 JSFunction* function, AbstractCode* abstract_code, |
| 779 int code_offset, bool is_constructor, |
| 780 Mode mode = kExactSummary); |
| 781 |
| 782 Handle<Object> receiver() const { return receiver_; } |
| 783 Handle<JSFunction> function() const { return function_; } |
| 784 Handle<AbstractCode> abstract_code() const { return abstract_code_; } |
| 785 int code_offset() const { return code_offset_; } |
| 786 bool is_constructor() const { return is_constructor_; } |
| 787 bool is_subject_to_debugging() const; |
| 788 int SourcePosition() const; |
| 789 int SourceStatementPosition() const; |
| 790 Handle<Object> script() const; |
| 791 Handle<String> FunctionName() const; |
| 792 Handle<Context> native_context() const; |
| 793 |
| 794 private: |
| 795 Handle<Object> receiver_; |
| 796 Handle<JSFunction> function_; |
| 797 Handle<AbstractCode> abstract_code_; |
| 798 int code_offset_; |
| 799 bool is_constructor_; |
| 800 }; |
| 801 |
| 802 class WasmFrameSummary : public FrameSummaryBase { |
| 803 protected: |
| 804 WasmFrameSummary(Isolate*, Kind, Handle<WasmInstanceObject>, |
| 805 bool at_to_number_conversion); |
| 806 |
| 807 public: |
| 808 Handle<Object> receiver() const; |
| 809 uint32_t function_index() const; |
| 810 int byte_offset() const; |
| 811 bool is_constructor() const { return false; } |
| 812 bool is_subject_to_debugging() const { return true; } |
| 813 int SourcePosition() const; |
| 814 int SourceStatementPosition() const { return SourcePosition(); } |
| 815 Handle<Script> script() const; |
| 816 Handle<WasmInstanceObject> wasm_instance() const { return wasm_instance_; } |
| 817 Handle<String> FunctionName() const; |
| 818 Handle<Context> native_context() const; |
| 819 bool at_to_number_conversion() const { return at_to_number_conversion_; } |
| 820 |
| 821 private: |
| 822 Handle<WasmInstanceObject> wasm_instance_; |
| 823 bool at_to_number_conversion_; |
| 824 }; |
| 825 |
| 826 class WasmCompiledFrameSummary : public WasmFrameSummary { |
| 827 public: |
| 828 WasmCompiledFrameSummary(Isolate*, Handle<WasmInstanceObject>, Handle<Code>, |
| 829 int code_offset, bool at_to_number_conversion); |
| 830 uint32_t function_index() const; |
| 831 Handle<Code> code() const { return code_; } |
| 832 int code_offset() const { return code_offset_; } |
| 833 int byte_offset() const; |
| 834 |
| 835 private: |
| 836 Handle<Code> code_; |
| 837 int code_offset_; |
| 838 }; |
| 839 |
| 840 class WasmInterpretedFrameSummary : public WasmFrameSummary { |
| 841 public: |
| 842 WasmInterpretedFrameSummary(Isolate*, Handle<WasmInstanceObject>, |
| 843 uint32_t function_index, int byte_offset); |
| 844 uint32_t function_index() const { return function_index_; } |
| 845 int code_offset() const { return byte_offset_; } |
| 846 int byte_offset() const { return byte_offset_; } |
| 847 |
| 848 private: |
| 849 uint32_t function_index_; |
| 850 int byte_offset_; |
| 851 }; |
| 852 |
| 853 #undef FRAME_SUMMARY_FIELD |
| 854 #define FRAME_SUMMARY_CONS(kind, type, field, desc) \ |
| 855 FrameSummary(type summ) : field(summ) {} // NOLINT |
| 856 FRAME_SUMMARY_VARIANTS(FRAME_SUMMARY_CONS) |
| 857 #undef FRAME_SUMMARY_CONS |
| 858 |
| 859 ~FrameSummary(); |
| 860 |
| 861 static inline FrameSummary GetFirst(const StandardFrame* frame) { |
| 862 return Get(frame, 0); |
| 863 } |
| 864 static FrameSummary Get(const StandardFrame* frame, int index); |
| 865 static FrameSummary GetSingle(const StandardFrame* frame); |
| 866 |
| 867 // Dispatched accessors. |
| 868 Handle<Object> receiver() const; |
| 869 int code_offset() const; |
| 870 bool is_constructor() const; |
| 871 bool is_subject_to_debugging() const; |
| 872 Handle<Object> script() const; |
| 873 int SourcePosition() const; |
| 874 int SourceStatementPosition() const; |
| 875 Handle<String> FunctionName() const; |
| 876 Handle<Context> native_context() const; |
| 877 |
| 878 #define FRAME_SUMMARY_CAST(kind_, type, field, desc) \ |
| 879 bool Is##desc() const { return base_.kind() == kind_; } \ |
| 880 const type& As##desc() const { \ |
| 881 DCHECK_EQ(base_.kind(), kind_); \ |
| 882 return field; \ |
| 883 } |
| 884 FRAME_SUMMARY_VARIANTS(FRAME_SUMMARY_CAST) |
| 885 #undef FRAME_SUMMARY_CAST |
| 886 |
| 887 bool IsWasm() const { return IsWasmCompiled() || IsWasmInterpreted(); } |
| 888 const WasmFrameSummary& AsWasm() const { |
| 889 if (IsWasmCompiled()) return AsWasmCompiled(); |
| 890 return AsWasmInterpreted(); |
| 891 } |
| 764 | 892 |
| 765 private: | 893 private: |
| 766 Handle<Object> receiver_; | 894 #define FRAME_SUMMARY_FIELD(kind, type, field, desc) type field; |
| 767 Handle<JSFunction> function_; | 895 union { |
| 768 Handle<AbstractCode> abstract_code_; | 896 FrameSummaryBase base_; |
| 769 int code_offset_; | 897 FRAME_SUMMARY_VARIANTS(FRAME_SUMMARY_FIELD) |
| 770 bool is_constructor_; | 898 }; |
| 771 }; | 899 }; |
| 772 | 900 |
| 773 class StandardFrame : public StackFrame { | 901 class StandardFrame : public StackFrame { |
| 774 public: | 902 public: |
| 775 // Testers. | 903 // Testers. |
| 776 bool is_standard() const override { return true; } | 904 bool is_standard() const override { return true; } |
| 777 | 905 |
| 778 // Accessors. | 906 // Accessors. |
| 779 virtual Object* receiver() const; | 907 virtual Object* receiver() const; |
| 780 virtual Script* script() const; | 908 virtual Script* script() const; |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 explicit StackTraceFrameIterator(Isolate* isolate); | 1486 explicit StackTraceFrameIterator(Isolate* isolate); |
| 1359 StackTraceFrameIterator(Isolate* isolate, StackFrame::Id id); | 1487 StackTraceFrameIterator(Isolate* isolate, StackFrame::Id id); |
| 1360 bool done() const { return iterator_.done(); } | 1488 bool done() const { return iterator_.done(); } |
| 1361 void Advance(); | 1489 void Advance(); |
| 1362 | 1490 |
| 1363 inline StandardFrame* frame() const; | 1491 inline StandardFrame* frame() const; |
| 1364 | 1492 |
| 1365 inline bool is_javascript() const; | 1493 inline bool is_javascript() const; |
| 1366 inline bool is_wasm() const; | 1494 inline bool is_wasm() const; |
| 1367 inline JavaScriptFrame* javascript_frame() const; | 1495 inline JavaScriptFrame* javascript_frame() const; |
| 1368 // TODO(clemensh): Remove / refactor this for general wasm frames | |
| 1369 // (compiled/interpreted). | |
| 1370 inline WasmCompiledFrame* wasm_compiled_frame() const; | |
| 1371 | 1496 |
| 1372 // Advance to the frame holding the arguments for the current | 1497 // Advance to the frame holding the arguments for the current |
| 1373 // frame. This only affects the current frame if it is a javascript frame and | 1498 // frame. This only affects the current frame if it is a javascript frame and |
| 1374 // has adapted arguments. | 1499 // has adapted arguments. |
| 1375 void AdvanceToArgumentsFrame(); | 1500 void AdvanceToArgumentsFrame(); |
| 1376 | 1501 |
| 1377 private: | 1502 private: |
| 1378 StackFrameIterator iterator_; | 1503 StackFrameIterator iterator_; |
| 1379 bool IsValidFrame(StackFrame* frame) const; | 1504 bool IsValidFrame(StackFrame* frame) const; |
| 1380 }; | 1505 }; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 | 1548 |
| 1424 | 1549 |
| 1425 // Reads all frames on the current stack and copies them into the current | 1550 // Reads all frames on the current stack and copies them into the current |
| 1426 // zone memory. | 1551 // zone memory. |
| 1427 Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone); | 1552 Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone); |
| 1428 | 1553 |
| 1429 } // namespace internal | 1554 } // namespace internal |
| 1430 } // namespace v8 | 1555 } // namespace v8 |
| 1431 | 1556 |
| 1432 #endif // V8_FRAMES_H_ | 1557 #endif // V8_FRAMES_H_ |
| OLD | NEW |