| 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 15 matching lines...) Expand all Loading... |
| 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_HEAP_SNAPSHOT_GENERATOR_H_ | 28 #ifndef V8_HEAP_SNAPSHOT_GENERATOR_H_ |
| 29 #define V8_HEAP_SNAPSHOT_GENERATOR_H_ | 29 #define V8_HEAP_SNAPSHOT_GENERATOR_H_ |
| 30 | 30 |
| 31 #include "profile-generator-inl.h" | 31 #include "profile-generator-inl.h" |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 class AllocationTracker; |
| 37 class AllocationTraceNode; |
| 36 class HeapEntry; | 38 class HeapEntry; |
| 37 class HeapSnapshot; | 39 class HeapSnapshot; |
| 38 | 40 |
| 39 class HeapGraphEdge BASE_EMBEDDED { | 41 class HeapGraphEdge BASE_EMBEDDED { |
| 40 public: | 42 public: |
| 41 enum Type { | 43 enum Type { |
| 42 kContextVariable = v8::HeapGraphEdge::kContextVariable, | 44 kContextVariable = v8::HeapGraphEdge::kContextVariable, |
| 43 kElement = v8::HeapGraphEdge::kElement, | 45 kElement = v8::HeapGraphEdge::kElement, |
| 44 kProperty = v8::HeapGraphEdge::kProperty, | 46 kProperty = v8::HeapGraphEdge::kProperty, |
| 45 kInternal = v8::HeapGraphEdge::kInternal, | 47 kInternal = v8::HeapGraphEdge::kInternal, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 222 |
| 221 | 223 |
| 222 class HeapObjectsMap { | 224 class HeapObjectsMap { |
| 223 public: | 225 public: |
| 224 explicit HeapObjectsMap(Heap* heap); | 226 explicit HeapObjectsMap(Heap* heap); |
| 225 | 227 |
| 226 Heap* heap() const { return heap_; } | 228 Heap* heap() const { return heap_; } |
| 227 | 229 |
| 228 void SnapshotGenerationFinished(); | 230 void SnapshotGenerationFinished(); |
| 229 SnapshotObjectId FindEntry(Address addr); | 231 SnapshotObjectId FindEntry(Address addr); |
| 230 SnapshotObjectId FindOrAddEntry(Address addr, unsigned int size); | 232 SnapshotObjectId FindOrAddEntry(Address addr, |
| 231 void MoveObject(Address from, Address to); | 233 unsigned int size, |
| 234 bool accessed = true); |
| 235 void MoveObject(Address from, Address to, int size); |
| 236 void NewObject(Address addr, int size); |
| 237 void UpdateObjectSize(Address addr, int size); |
| 232 SnapshotObjectId last_assigned_id() const { | 238 SnapshotObjectId last_assigned_id() const { |
| 233 return next_id_ - kObjectIdStep; | 239 return next_id_ - kObjectIdStep; |
| 234 } | 240 } |
| 235 | 241 |
| 236 void StopHeapObjectsTracking(); | 242 void StopHeapObjectsTracking(); |
| 237 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); | 243 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); |
| 238 size_t GetUsedMemorySize() const; | 244 size_t GetUsedMemorySize() const; |
| 239 | 245 |
| 240 static SnapshotObjectId GenerateId(Heap* heap, v8::RetainedObjectInfo* info); | 246 static SnapshotObjectId GenerateId(Heap* heap, v8::RetainedObjectInfo* info); |
| 241 static inline SnapshotObjectId GetNthGcSubrootId(int delta); | 247 static inline SnapshotObjectId GetNthGcSubrootId(int delta); |
| 242 | 248 |
| 243 static const int kObjectIdStep = 2; | 249 static const int kObjectIdStep = 2; |
| 244 static const SnapshotObjectId kInternalRootObjectId; | 250 static const SnapshotObjectId kInternalRootObjectId; |
| 245 static const SnapshotObjectId kGcRootsObjectId; | 251 static const SnapshotObjectId kGcRootsObjectId; |
| 246 static const SnapshotObjectId kNativesRootObjectId; | 252 static const SnapshotObjectId kNativesRootObjectId; |
| 247 static const SnapshotObjectId kGcRootsFirstSubrootId; | 253 static const SnapshotObjectId kGcRootsFirstSubrootId; |
| 248 static const SnapshotObjectId kFirstAvailableObjectId; | 254 static const SnapshotObjectId kFirstAvailableObjectId; |
| 249 | 255 |
| 256 int FindUntrackedObjects(); |
| 257 |
| 258 void UpdateHeapObjectsMap(); |
| 259 |
| 250 private: | 260 private: |
| 251 struct EntryInfo { | 261 struct EntryInfo { |
| 252 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size) | 262 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size) |
| 253 : id(id), addr(addr), size(size), accessed(true) { } | 263 : id(id), addr(addr), size(size), accessed(true) { } |
| 254 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size, bool accessed) | 264 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size, bool accessed) |
| 255 : id(id), addr(addr), size(size), accessed(accessed) { } | 265 : id(id), addr(addr), size(size), accessed(accessed) { } |
| 256 SnapshotObjectId id; | 266 SnapshotObjectId id; |
| 257 Address addr; | 267 Address addr; |
| 258 unsigned int size; | 268 unsigned int size; |
| 259 bool accessed; | 269 bool accessed; |
| 260 }; | 270 }; |
| 261 struct TimeInterval { | 271 struct TimeInterval { |
| 262 explicit TimeInterval(SnapshotObjectId id) : id(id), size(0), count(0) { } | 272 explicit TimeInterval(SnapshotObjectId id) : id(id), size(0), count(0) { } |
| 263 SnapshotObjectId id; | 273 SnapshotObjectId id; |
| 264 uint32_t size; | 274 uint32_t size; |
| 265 uint32_t count; | 275 uint32_t count; |
| 266 }; | 276 }; |
| 267 | 277 |
| 268 void UpdateHeapObjectsMap(); | |
| 269 void RemoveDeadEntries(); | 278 void RemoveDeadEntries(); |
| 270 | 279 |
| 271 SnapshotObjectId next_id_; | 280 SnapshotObjectId next_id_; |
| 272 HashMap entries_map_; | 281 HashMap entries_map_; |
| 273 List<EntryInfo> entries_; | 282 List<EntryInfo> entries_; |
| 274 List<TimeInterval> time_intervals_; | 283 List<TimeInterval> time_intervals_; |
| 275 Heap* heap_; | 284 Heap* heap_; |
| 276 | 285 |
| 277 DISALLOW_COPY_AND_ASSIGN(HeapObjectsMap); | 286 DISALLOW_COPY_AND_ASSIGN(HeapObjectsMap); |
| 278 }; | 287 }; |
| 279 | 288 |
| 280 | 289 |
| 281 class HeapSnapshotsCollection { | 290 class HeapSnapshotsCollection { |
| 282 public: | 291 public: |
| 283 explicit HeapSnapshotsCollection(Heap* heap); | 292 explicit HeapSnapshotsCollection(Heap* heap); |
| 284 ~HeapSnapshotsCollection(); | 293 ~HeapSnapshotsCollection(); |
| 285 | 294 |
| 286 Heap* heap() const { return ids_.heap(); } | 295 Heap* heap() const { return ids_.heap(); } |
| 287 | 296 |
| 288 bool is_tracking_objects() { return is_tracking_objects_; } | 297 bool is_tracking_objects() { return is_tracking_objects_; } |
| 289 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream) { | 298 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream) { |
| 290 return ids_.PushHeapObjectsStats(stream); | 299 return ids_.PushHeapObjectsStats(stream); |
| 291 } | 300 } |
| 292 void StartHeapObjectsTracking() { is_tracking_objects_ = true; } | 301 void StartHeapObjectsTracking(); |
| 293 void StopHeapObjectsTracking() { ids_.StopHeapObjectsTracking(); } | 302 void StopHeapObjectsTracking(); |
| 294 | 303 |
| 295 HeapSnapshot* NewSnapshot(const char* name, unsigned uid); | 304 HeapSnapshot* NewSnapshot(const char* name, unsigned uid); |
| 296 void SnapshotGenerationFinished(HeapSnapshot* snapshot); | 305 void SnapshotGenerationFinished(HeapSnapshot* snapshot); |
| 297 List<HeapSnapshot*>* snapshots() { return &snapshots_; } | 306 List<HeapSnapshot*>* snapshots() { return &snapshots_; } |
| 298 void RemoveSnapshot(HeapSnapshot* snapshot); | 307 void RemoveSnapshot(HeapSnapshot* snapshot); |
| 299 | 308 |
| 300 StringsStorage* names() { return &names_; } | 309 StringsStorage* names() { return &names_; } |
| 310 AllocationTracker* allocation_tracker() { return allocation_tracker_; } |
| 301 | 311 |
| 302 SnapshotObjectId FindObjectId(Address object_addr) { | 312 SnapshotObjectId FindObjectId(Address object_addr) { |
| 303 return ids_.FindEntry(object_addr); | 313 return ids_.FindEntry(object_addr); |
| 304 } | 314 } |
| 305 SnapshotObjectId GetObjectId(Address object_addr, int object_size) { | 315 SnapshotObjectId GetObjectId(Address object_addr, int object_size) { |
| 306 return ids_.FindOrAddEntry(object_addr, object_size); | 316 return ids_.FindOrAddEntry(object_addr, object_size); |
| 307 } | 317 } |
| 308 Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id); | 318 Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id); |
| 309 void ObjectMoveEvent(Address from, Address to) { ids_.MoveObject(from, to); } | 319 void ObjectMoveEvent(Address from, Address to, int size) { |
| 320 ids_.MoveObject(from, to, size); |
| 321 } |
| 322 void NewObjectEvent(Address addr, int size); |
| 323 void UpdateObjectSizeEvent(Address addr, int size) { |
| 324 ids_.UpdateObjectSize(addr, size); |
| 325 } |
| 310 SnapshotObjectId last_assigned_id() const { | 326 SnapshotObjectId last_assigned_id() const { |
| 311 return ids_.last_assigned_id(); | 327 return ids_.last_assigned_id(); |
| 312 } | 328 } |
| 313 size_t GetUsedMemorySize() const; | 329 size_t GetUsedMemorySize() const; |
| 314 | 330 |
| 331 int FindUntrackedObjects() { return ids_.FindUntrackedObjects(); } |
| 332 |
| 333 void UpdateHeapObjectsMap() { ids_.UpdateHeapObjectsMap(); } |
| 334 |
| 315 private: | 335 private: |
| 316 bool is_tracking_objects_; // Whether tracking object moves is needed. | 336 bool is_tracking_objects_; // Whether tracking object moves is needed. |
| 317 List<HeapSnapshot*> snapshots_; | 337 List<HeapSnapshot*> snapshots_; |
| 318 StringsStorage names_; | 338 StringsStorage names_; |
| 319 // Mapping from HeapObject addresses to objects' uids. | 339 // Mapping from HeapObject addresses to objects' uids. |
| 320 HeapObjectsMap ids_; | 340 HeapObjectsMap ids_; |
| 341 AllocationTracker* allocation_tracker_; |
| 321 | 342 |
| 322 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotsCollection); | 343 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotsCollection); |
| 323 }; | 344 }; |
| 324 | 345 |
| 325 | 346 |
| 326 // A typedef for referencing anything that can be snapshotted living | 347 // A typedef for referencing anything that can be snapshotted living |
| 327 // in any kind of heap memory. | 348 // in any kind of heap memory. |
| 328 typedef void* HeapThing; | 349 typedef void* HeapThing; |
| 329 | 350 |
| 330 | 351 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } | 670 } |
| 650 | 671 |
| 651 int GetStringId(const char* s); | 672 int GetStringId(const char* s); |
| 652 int entry_index(HeapEntry* e) { return e->index() * kNodeFieldsCount; } | 673 int entry_index(HeapEntry* e) { return e->index() * kNodeFieldsCount; } |
| 653 void SerializeEdge(HeapGraphEdge* edge, bool first_edge); | 674 void SerializeEdge(HeapGraphEdge* edge, bool first_edge); |
| 654 void SerializeEdges(); | 675 void SerializeEdges(); |
| 655 void SerializeImpl(); | 676 void SerializeImpl(); |
| 656 void SerializeNode(HeapEntry* entry); | 677 void SerializeNode(HeapEntry* entry); |
| 657 void SerializeNodes(); | 678 void SerializeNodes(); |
| 658 void SerializeSnapshot(); | 679 void SerializeSnapshot(); |
| 680 void SerializeTraceTree(); |
| 681 void SerializeTraceNode(AllocationTraceNode* node); |
| 682 void SerializeTraceNodeInfos(); |
| 659 void SerializeString(const unsigned char* s); | 683 void SerializeString(const unsigned char* s); |
| 660 void SerializeStrings(); | 684 void SerializeStrings(); |
| 661 | 685 |
| 662 static const int kEdgeFieldsCount; | 686 static const int kEdgeFieldsCount; |
| 663 static const int kNodeFieldsCount; | 687 static const int kNodeFieldsCount; |
| 664 | 688 |
| 665 HeapSnapshot* snapshot_; | 689 HeapSnapshot* snapshot_; |
| 666 HashMap strings_; | 690 HashMap strings_; |
| 667 int next_node_id_; | 691 int next_node_id_; |
| 668 int next_string_id_; | 692 int next_string_id_; |
| 669 OutputStreamWriter* writer_; | 693 OutputStreamWriter* writer_; |
| 670 | 694 |
| 671 friend class HeapSnapshotJSONSerializerEnumerator; | 695 friend class HeapSnapshotJSONSerializerEnumerator; |
| 672 friend class HeapSnapshotJSONSerializerIterator; | 696 friend class HeapSnapshotJSONSerializerIterator; |
| 673 | 697 |
| 674 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); | 698 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); |
| 675 }; | 699 }; |
| 676 | 700 |
| 677 | 701 |
| 678 } } // namespace v8::internal | 702 } } // namespace v8::internal |
| 679 | 703 |
| 680 #endif // V8_HEAP_SNAPSHOT_GENERATOR_H_ | 704 #endif // V8_HEAP_SNAPSHOT_GENERATOR_H_ |
| 681 | 705 |
| OLD | NEW |