| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_ALLOCATION_TRACKER_H_ | 28 #ifndef V8_ALLOCATION_TRACKER_H_ |
| 29 #define V8_ALLOCATION_TRACKER_H_ | 29 #define V8_ALLOCATION_TRACKER_H_ |
| 30 | 30 |
| 31 #include <map> |
| 32 |
| 31 namespace v8 { | 33 namespace v8 { |
| 32 namespace internal { | 34 namespace internal { |
| 33 | 35 |
| 34 class HeapObjectsMap; | 36 class HeapObjectsMap; |
| 35 | 37 |
| 36 class AllocationTraceTree; | 38 class AllocationTraceTree; |
| 37 | 39 |
| 38 class AllocationTraceNode { | 40 class AllocationTraceNode { |
| 39 public: | 41 public: |
| 40 AllocationTraceNode(AllocationTraceTree* tree, | 42 AllocationTraceNode(AllocationTraceTree* tree, |
| 41 SnapshotObjectId shared_function_info_id); | 43 unsigned function_info_index); |
| 42 ~AllocationTraceNode(); | 44 ~AllocationTraceNode(); |
| 43 AllocationTraceNode* FindChild(SnapshotObjectId shared_function_info_id); | 45 AllocationTraceNode* FindChild(unsigned function_info_index); |
| 44 AllocationTraceNode* FindOrAddChild(SnapshotObjectId shared_function_info_id); | 46 AllocationTraceNode* FindOrAddChild(unsigned function_info_index); |
| 45 void AddAllocation(unsigned size); | 47 void AddAllocation(unsigned size); |
| 46 | 48 |
| 47 SnapshotObjectId function_id() const { return function_id_; } | 49 unsigned function_info_index() const { return function_info_index_; } |
| 48 unsigned allocation_size() const { return total_size_; } | 50 unsigned allocation_size() const { return total_size_; } |
| 49 unsigned allocation_count() const { return allocation_count_; } | 51 unsigned allocation_count() const { return allocation_count_; } |
| 50 unsigned id() const { return id_; } | 52 unsigned id() const { return id_; } |
| 51 Vector<AllocationTraceNode*> children() const { return children_.ToVector(); } | 53 Vector<AllocationTraceNode*> children() const { return children_.ToVector(); } |
| 52 | 54 |
| 53 void Print(int indent, AllocationTracker* tracker); | 55 void Print(int indent, AllocationTracker* tracker); |
| 54 | 56 |
| 55 private: | 57 private: |
| 56 AllocationTraceTree* tree_; | 58 AllocationTraceTree* tree_; |
| 57 SnapshotObjectId function_id_; | 59 unsigned function_info_index_; |
| 58 unsigned total_size_; | 60 unsigned total_size_; |
| 59 unsigned allocation_count_; | 61 unsigned allocation_count_; |
| 60 unsigned id_; | 62 unsigned id_; |
| 61 List<AllocationTraceNode*> children_; | 63 List<AllocationTraceNode*> children_; |
| 62 | 64 |
| 63 DISALLOW_COPY_AND_ASSIGN(AllocationTraceNode); | 65 DISALLOW_COPY_AND_ASSIGN(AllocationTraceNode); |
| 64 }; | 66 }; |
| 65 | 67 |
| 66 | 68 |
| 67 class AllocationTraceTree { | 69 class AllocationTraceTree { |
| 68 public: | 70 public: |
| 69 AllocationTraceTree(); | 71 AllocationTraceTree(); |
| 70 ~AllocationTraceTree(); | 72 ~AllocationTraceTree(); |
| 71 AllocationTraceNode* AddPathFromEnd(const Vector<SnapshotObjectId>& path); | 73 AllocationTraceNode* AddPathFromEnd(const Vector<unsigned>& path); |
| 72 AllocationTraceNode* root() { return &root_; } | 74 AllocationTraceNode* root() { return &root_; } |
| 73 unsigned next_node_id() { return next_node_id_++; } | 75 unsigned next_node_id() { return next_node_id_++; } |
| 74 void Print(AllocationTracker* tracker); | 76 void Print(AllocationTracker* tracker); |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 unsigned next_node_id_; | 79 unsigned next_node_id_; |
| 78 AllocationTraceNode root_; | 80 AllocationTraceNode root_; |
| 79 | 81 |
| 80 DISALLOW_COPY_AND_ASSIGN(AllocationTraceTree); | 82 DISALLOW_COPY_AND_ASSIGN(AllocationTraceTree); |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 | 85 |
| 86 class AddressToTraceMap { |
| 87 public: |
| 88 void AddRange(Address addr, int size, unsigned node_id); |
| 89 unsigned GetTraceNodeId(Address addr); |
| 90 void MoveObject(Address from, Address to, int size); |
| 91 void Clear(); |
| 92 size_t size() { return ranges_.size(); } |
| 93 void Print(); |
| 94 |
| 95 private: |
| 96 struct RangeStack { |
| 97 RangeStack(Address start, unsigned node_id) |
| 98 : start(start), trace_node_id(node_id) {} |
| 99 Address start; |
| 100 unsigned trace_node_id; |
| 101 }; |
| 102 // [start, end) -> trace |
| 103 typedef std::map<Address, RangeStack> RangeMap; |
| 104 |
| 105 void RemoveRange(Address start, Address end); |
| 106 |
| 107 RangeMap ranges_; |
| 108 }; |
| 109 |
| 84 class AllocationTracker { | 110 class AllocationTracker { |
| 85 public: | 111 public: |
| 86 struct FunctionInfo { | 112 struct FunctionInfo { |
| 87 FunctionInfo(); | 113 FunctionInfo(); |
| 88 const char* name; | 114 const char* name; |
| 115 SnapshotObjectId function_id; |
| 89 const char* script_name; | 116 const char* script_name; |
| 90 int script_id; | 117 int script_id; |
| 91 int line; | 118 int line; |
| 92 int column; | 119 int column; |
| 93 }; | 120 }; |
| 94 | 121 |
| 95 AllocationTracker(HeapObjectsMap* ids, StringsStorage* names); | 122 AllocationTracker(HeapObjectsMap* ids, StringsStorage* names); |
| 96 ~AllocationTracker(); | 123 ~AllocationTracker(); |
| 97 | 124 |
| 98 void PrepareForSerialization(); | 125 void PrepareForSerialization(); |
| 99 void AllocationEvent(Address addr, int size); | 126 void AllocationEvent(Address addr, int size); |
| 100 | 127 |
| 101 AllocationTraceTree* trace_tree() { return &trace_tree_; } | 128 AllocationTraceTree* trace_tree() { return &trace_tree_; } |
| 102 HashMap* id_to_function_info() { return &id_to_function_info_; } | 129 const List<FunctionInfo*>& function_info_list() const { |
| 103 FunctionInfo* GetFunctionInfo(SnapshotObjectId id); | 130 return function_info_list_; |
| 131 } |
| 132 AddressToTraceMap* address_to_trace() { return &address_to_trace_; } |
| 104 | 133 |
| 105 private: | 134 private: |
| 106 void AddFunctionInfo(SharedFunctionInfo* info, SnapshotObjectId id); | 135 unsigned AddFunctionInfo(SharedFunctionInfo* info, SnapshotObjectId id); |
| 136 static void DeleteFunctionInfo(FunctionInfo** info); |
| 137 unsigned functionInfoIndexForVMState(StateTag state); |
| 107 | 138 |
| 108 class UnresolvedLocation { | 139 class UnresolvedLocation { |
| 109 public: | 140 public: |
| 110 UnresolvedLocation(Script* script, int start, FunctionInfo* info); | 141 UnresolvedLocation(Script* script, int start, FunctionInfo* info); |
| 111 ~UnresolvedLocation(); | 142 ~UnresolvedLocation(); |
| 112 void Resolve(); | 143 void Resolve(); |
| 113 | 144 |
| 114 private: | 145 private: |
| 115 static void HandleWeakScript( | 146 static void HandleWeakScript( |
| 116 const v8::WeakCallbackData<v8::Value, void>& data); | 147 const v8::WeakCallbackData<v8::Value, void>& data); |
| 117 | 148 |
| 118 Handle<Script> script_; | 149 Handle<Script> script_; |
| 119 int start_position_; | 150 int start_position_; |
| 120 FunctionInfo* info_; | 151 FunctionInfo* info_; |
| 121 }; | 152 }; |
| 122 static void DeleteUnresolvedLocation(UnresolvedLocation** location); | 153 static void DeleteUnresolvedLocation(UnresolvedLocation** location); |
| 123 | 154 |
| 124 static const int kMaxAllocationTraceLength = 64; | 155 static const int kMaxAllocationTraceLength = 64; |
| 125 HeapObjectsMap* ids_; | 156 HeapObjectsMap* ids_; |
| 126 StringsStorage* names_; | 157 StringsStorage* names_; |
| 127 AllocationTraceTree trace_tree_; | 158 AllocationTraceTree trace_tree_; |
| 128 SnapshotObjectId allocation_trace_buffer_[kMaxAllocationTraceLength]; | 159 unsigned allocation_trace_buffer_[kMaxAllocationTraceLength]; |
| 129 HashMap id_to_function_info_; | 160 List<FunctionInfo*> function_info_list_; |
| 161 HashMap id_to_function_info_index_; |
| 130 List<UnresolvedLocation*> unresolved_locations_; | 162 List<UnresolvedLocation*> unresolved_locations_; |
| 163 unsigned info_index_for_other_state_; |
| 164 AddressToTraceMap address_to_trace_; |
| 131 | 165 |
| 132 DISALLOW_COPY_AND_ASSIGN(AllocationTracker); | 166 DISALLOW_COPY_AND_ASSIGN(AllocationTracker); |
| 133 }; | 167 }; |
| 134 | 168 |
| 135 } } // namespace v8::internal | 169 } } // namespace v8::internal |
| 136 | 170 |
| 137 #endif // V8_ALLOCATION_TRACKER_H_ | 171 #endif // V8_ALLOCATION_TRACKER_H_ |
| OLD | NEW |