| 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 20 matching lines...) Expand all Loading... |
| 31 namespace v8 { | 31 namespace v8 { |
| 32 namespace internal { | 32 namespace internal { |
| 33 | 33 |
| 34 class HeapObjectsMap; | 34 class HeapObjectsMap; |
| 35 | 35 |
| 36 class AllocationTraceTree; | 36 class AllocationTraceTree; |
| 37 | 37 |
| 38 class AllocationTraceNode { | 38 class AllocationTraceNode { |
| 39 public: | 39 public: |
| 40 AllocationTraceNode(AllocationTraceTree* tree, | 40 AllocationTraceNode(AllocationTraceTree* tree, |
| 41 SnapshotObjectId shared_function_info_id); | 41 unsigned function_info_index); |
| 42 ~AllocationTraceNode(); | 42 ~AllocationTraceNode(); |
| 43 AllocationTraceNode* FindChild(SnapshotObjectId shared_function_info_id); | 43 AllocationTraceNode* FindChild(unsigned function_info_index); |
| 44 AllocationTraceNode* FindOrAddChild(SnapshotObjectId shared_function_info_id); | 44 AllocationTraceNode* FindOrAddChild(unsigned function_info_index); |
| 45 void AddAllocation(unsigned size); | 45 void AddAllocation(unsigned size); |
| 46 | 46 |
| 47 SnapshotObjectId function_id() const { return function_id_; } | 47 unsigned function_info_index() const { return function_info_index_; } |
| 48 unsigned allocation_size() const { return total_size_; } | 48 unsigned allocation_size() const { return total_size_; } |
| 49 unsigned allocation_count() const { return allocation_count_; } | 49 unsigned allocation_count() const { return allocation_count_; } |
| 50 unsigned id() const { return id_; } | 50 unsigned id() const { return id_; } |
| 51 Vector<AllocationTraceNode*> children() const { return children_.ToVector(); } | 51 Vector<AllocationTraceNode*> children() const { return children_.ToVector(); } |
| 52 | 52 |
| 53 void Print(int indent, AllocationTracker* tracker); | 53 void Print(int indent, AllocationTracker* tracker); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 AllocationTraceTree* tree_; | 56 AllocationTraceTree* tree_; |
| 57 SnapshotObjectId function_id_; | 57 unsigned function_info_index_; |
| 58 unsigned total_size_; | 58 unsigned total_size_; |
| 59 unsigned allocation_count_; | 59 unsigned allocation_count_; |
| 60 unsigned id_; | 60 unsigned id_; |
| 61 List<AllocationTraceNode*> children_; | 61 List<AllocationTraceNode*> children_; |
| 62 | 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(AllocationTraceNode); | 63 DISALLOW_COPY_AND_ASSIGN(AllocationTraceNode); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 | 66 |
| 67 class AllocationTraceTree { | 67 class AllocationTraceTree { |
| 68 public: | 68 public: |
| 69 AllocationTraceTree(); | 69 AllocationTraceTree(); |
| 70 ~AllocationTraceTree(); | 70 ~AllocationTraceTree(); |
| 71 AllocationTraceNode* AddPathFromEnd(const Vector<SnapshotObjectId>& path); | 71 AllocationTraceNode* AddPathFromEnd(const Vector<unsigned>& path); |
| 72 AllocationTraceNode* root() { return &root_; } | 72 AllocationTraceNode* root() { return &root_; } |
| 73 unsigned next_node_id() { return next_node_id_++; } | 73 unsigned next_node_id() { return next_node_id_++; } |
| 74 void Print(AllocationTracker* tracker); | 74 void Print(AllocationTracker* tracker); |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 unsigned next_node_id_; | 77 unsigned next_node_id_; |
| 78 AllocationTraceNode root_; | 78 AllocationTraceNode root_; |
| 79 | 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(AllocationTraceTree); | 80 DISALLOW_COPY_AND_ASSIGN(AllocationTraceTree); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 | 83 |
| 84 class AllocationTracker { | 84 class AllocationTracker { |
| 85 public: | 85 public: |
| 86 struct FunctionInfo { | 86 struct FunctionInfo { |
| 87 FunctionInfo(); | 87 FunctionInfo(); |
| 88 const char* name; | 88 const char* name; |
| 89 SnapshotObjectId function_id; |
| 89 const char* script_name; | 90 const char* script_name; |
| 90 int script_id; | 91 int script_id; |
| 91 int line; | 92 int line; |
| 92 int column; | 93 int column; |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 AllocationTracker(HeapObjectsMap* ids, StringsStorage* names); | 96 AllocationTracker(HeapObjectsMap* ids, StringsStorage* names); |
| 96 ~AllocationTracker(); | 97 ~AllocationTracker(); |
| 97 | 98 |
| 98 void PrepareForSerialization(); | 99 void PrepareForSerialization(); |
| 99 void AllocationEvent(Address addr, int size); | 100 void AllocationEvent(Address addr, int size); |
| 100 | 101 |
| 101 AllocationTraceTree* trace_tree() { return &trace_tree_; } | 102 AllocationTraceTree* trace_tree() { return &trace_tree_; } |
| 102 HashMap* id_to_function_info() { return &id_to_function_info_; } | 103 const List<FunctionInfo*>& function_info_list() const { |
| 103 FunctionInfo* GetFunctionInfo(SnapshotObjectId id); | 104 return function_info_list_; |
| 105 } |
| 104 | 106 |
| 105 private: | 107 private: |
| 106 void AddFunctionInfo(SharedFunctionInfo* info, SnapshotObjectId id); | 108 unsigned AddFunctionInfo(SharedFunctionInfo* info, SnapshotObjectId id); |
| 109 static void DeleteFunctionInfo(FunctionInfo** info); |
| 110 unsigned functionInfoIndexForVMState(StateTag state); |
| 107 | 111 |
| 108 class UnresolvedLocation { | 112 class UnresolvedLocation { |
| 109 public: | 113 public: |
| 110 UnresolvedLocation(Script* script, int start, FunctionInfo* info); | 114 UnresolvedLocation(Script* script, int start, FunctionInfo* info); |
| 111 ~UnresolvedLocation(); | 115 ~UnresolvedLocation(); |
| 112 void Resolve(); | 116 void Resolve(); |
| 113 | 117 |
| 114 private: | 118 private: |
| 115 static void HandleWeakScript( | 119 static void HandleWeakScript( |
| 116 const v8::WeakCallbackData<v8::Value, void>& data); | 120 const v8::WeakCallbackData<v8::Value, void>& data); |
| 117 | 121 |
| 118 Handle<Script> script_; | 122 Handle<Script> script_; |
| 119 int start_position_; | 123 int start_position_; |
| 120 FunctionInfo* info_; | 124 FunctionInfo* info_; |
| 121 }; | 125 }; |
| 122 static void DeleteUnresolvedLocation(UnresolvedLocation** location); | 126 static void DeleteUnresolvedLocation(UnresolvedLocation** location); |
| 123 | 127 |
| 124 static const int kMaxAllocationTraceLength = 64; | 128 static const int kMaxAllocationTraceLength = 64; |
| 125 HeapObjectsMap* ids_; | 129 HeapObjectsMap* ids_; |
| 126 StringsStorage* names_; | 130 StringsStorage* names_; |
| 127 AllocationTraceTree trace_tree_; | 131 AllocationTraceTree trace_tree_; |
| 128 SnapshotObjectId allocation_trace_buffer_[kMaxAllocationTraceLength]; | 132 unsigned allocation_trace_buffer_[kMaxAllocationTraceLength]; |
| 129 HashMap id_to_function_info_; | 133 List<FunctionInfo*> function_info_list_; |
| 134 HashMap id_to_function_info_index_; |
| 130 List<UnresolvedLocation*> unresolved_locations_; | 135 List<UnresolvedLocation*> unresolved_locations_; |
| 136 unsigned info_index_for_other_state_; |
| 131 | 137 |
| 132 DISALLOW_COPY_AND_ASSIGN(AllocationTracker); | 138 DISALLOW_COPY_AND_ASSIGN(AllocationTracker); |
| 133 }; | 139 }; |
| 134 | 140 |
| 135 } } // namespace v8::internal | 141 } } // namespace v8::internal |
| 136 | 142 |
| 137 #endif // V8_ALLOCATION_TRACKER_H_ | 143 #endif // V8_ALLOCATION_TRACKER_H_ |
| OLD | NEW |