| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 unsigned type_: 4; | 147 unsigned type_: 4; |
| 148 int children_count_: 28; | 148 int children_count_: 28; |
| 149 int children_index_; | 149 int children_index_; |
| 150 int self_size_; | 150 int self_size_; |
| 151 SnapshotObjectId id_; | 151 SnapshotObjectId id_; |
| 152 HeapSnapshot* snapshot_; | 152 HeapSnapshot* snapshot_; |
| 153 const char* name_; | 153 const char* name_; |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 | 156 |
| 157 class HeapSnapshotsCollection; | |
| 158 | |
| 159 // HeapSnapshot represents a single heap snapshot. It is stored in | 157 // HeapSnapshot represents a single heap snapshot. It is stored in |
| 160 // HeapSnapshotsCollection, which is also a factory for | 158 // HeapProfiler, which is also a factory for |
| 161 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap | 159 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap |
| 162 // to be able to return them even if they were collected. | 160 // to be able to return them even if they were collected. |
| 163 // HeapSnapshotGenerator fills in a HeapSnapshot. | 161 // HeapSnapshotGenerator fills in a HeapSnapshot. |
| 164 class HeapSnapshot { | 162 class HeapSnapshot { |
| 165 public: | 163 public: |
| 166 HeapSnapshot(HeapSnapshotsCollection* collection, | 164 HeapSnapshot(HeapProfiler* profiler, |
| 167 const char* title, | 165 const char* title, |
| 168 unsigned uid); | 166 unsigned uid); |
| 169 void Delete(); | 167 void Delete(); |
| 170 | 168 |
| 171 HeapSnapshotsCollection* collection() { return collection_; } | 169 HeapProfiler* profiler() { return profiler_; } |
| 172 const char* title() { return title_; } | 170 const char* title() { return title_; } |
| 173 unsigned uid() { return uid_; } | 171 unsigned uid() { return uid_; } |
| 174 size_t RawSnapshotSize() const; | 172 size_t RawSnapshotSize() const; |
| 175 HeapEntry* root() { return &entries_[root_index_]; } | 173 HeapEntry* root() { return &entries_[root_index_]; } |
| 176 HeapEntry* gc_roots() { return &entries_[gc_roots_index_]; } | 174 HeapEntry* gc_roots() { return &entries_[gc_roots_index_]; } |
| 177 HeapEntry* natives_root() { return &entries_[natives_root_index_]; } | 175 HeapEntry* natives_root() { return &entries_[natives_root_index_]; } |
| 178 HeapEntry* gc_subroot(int index) { | 176 HeapEntry* gc_subroot(int index) { |
| 179 return &entries_[gc_subroot_indexes_[index]]; | 177 return &entries_[gc_subroot_indexes_[index]]; |
| 180 } | 178 } |
| 181 List<HeapEntry>& entries() { return entries_; } | 179 List<HeapEntry>& entries() { return entries_; } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 195 HeapEntry* AddGcSubrootEntry(int tag); | 193 HeapEntry* AddGcSubrootEntry(int tag); |
| 196 HeapEntry* AddNativesRootEntry(); | 194 HeapEntry* AddNativesRootEntry(); |
| 197 HeapEntry* GetEntryById(SnapshotObjectId id); | 195 HeapEntry* GetEntryById(SnapshotObjectId id); |
| 198 List<HeapEntry*>* GetSortedEntriesList(); | 196 List<HeapEntry*>* GetSortedEntriesList(); |
| 199 void FillChildren(); | 197 void FillChildren(); |
| 200 | 198 |
| 201 void Print(int max_depth); | 199 void Print(int max_depth); |
| 202 void PrintEntriesSize(); | 200 void PrintEntriesSize(); |
| 203 | 201 |
| 204 private: | 202 private: |
| 205 HeapSnapshotsCollection* collection_; | 203 HeapProfiler* profiler_; |
| 206 const char* title_; | 204 const char* title_; |
| 207 unsigned uid_; | 205 unsigned uid_; |
| 208 int root_index_; | 206 int root_index_; |
| 209 int gc_roots_index_; | 207 int gc_roots_index_; |
| 210 int natives_root_index_; | 208 int natives_root_index_; |
| 211 int gc_subroot_indexes_[VisitorSynchronization::kNumberOfSyncTags]; | 209 int gc_subroot_indexes_[VisitorSynchronization::kNumberOfSyncTags]; |
| 212 List<HeapEntry> entries_; | 210 List<HeapEntry> entries_; |
| 213 List<HeapGraphEdge> edges_; | 211 List<HeapGraphEdge> edges_; |
| 214 List<HeapGraphEdge*> children_; | 212 List<HeapGraphEdge*> children_; |
| 215 List<HeapEntry*> sorted_entries_; | 213 List<HeapEntry*> sorted_entries_; |
| 216 SnapshotObjectId max_snapshot_js_object_id_; | 214 SnapshotObjectId max_snapshot_js_object_id_; |
| 217 | 215 |
| 218 friend class HeapSnapshotTester; | 216 friend class HeapSnapshotTester; |
| 219 | 217 |
| 220 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); | 218 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); |
| 221 }; | 219 }; |
| 222 | 220 |
| 223 | 221 |
| 224 class HeapObjectsMap { | 222 class HeapObjectsMap { |
| 225 public: | 223 public: |
| 226 explicit HeapObjectsMap(Heap* heap); | 224 explicit HeapObjectsMap(Heap* heap); |
| 227 | 225 |
| 228 Heap* heap() const { return heap_; } | 226 Heap* heap() const { return heap_; } |
| 229 | 227 |
| 230 void SnapshotGenerationFinished(); | |
| 231 SnapshotObjectId FindEntry(Address addr); | 228 SnapshotObjectId FindEntry(Address addr); |
| 232 SnapshotObjectId FindOrAddEntry(Address addr, | 229 SnapshotObjectId FindOrAddEntry(Address addr, |
| 233 unsigned int size, | 230 unsigned int size, |
| 234 bool accessed = true); | 231 bool accessed = true); |
| 235 void MoveObject(Address from, Address to, int size); | 232 void MoveObject(Address from, Address to, int size); |
| 236 void UpdateObjectSize(Address addr, int size); | 233 void UpdateObjectSize(Address addr, int size); |
| 237 SnapshotObjectId last_assigned_id() const { | 234 SnapshotObjectId last_assigned_id() const { |
| 238 return next_id_ - kObjectIdStep; | 235 return next_id_ - kObjectIdStep; |
| 239 } | 236 } |
| 240 | 237 |
| 241 void StopHeapObjectsTracking(); | 238 void StopHeapObjectsTracking(); |
| 242 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); | 239 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); |
| 243 size_t GetUsedMemorySize() const; | 240 size_t GetUsedMemorySize() const; |
| 244 | 241 |
| 245 static SnapshotObjectId GenerateId(Heap* heap, v8::RetainedObjectInfo* info); | 242 SnapshotObjectId GenerateId(v8::RetainedObjectInfo* info); |
| 246 static inline SnapshotObjectId GetNthGcSubrootId(int delta); | 243 static inline SnapshotObjectId GetNthGcSubrootId(int delta); |
| 247 | 244 |
| 248 static const int kObjectIdStep = 2; | 245 static const int kObjectIdStep = 2; |
| 249 static const SnapshotObjectId kInternalRootObjectId; | 246 static const SnapshotObjectId kInternalRootObjectId; |
| 250 static const SnapshotObjectId kGcRootsObjectId; | 247 static const SnapshotObjectId kGcRootsObjectId; |
| 251 static const SnapshotObjectId kNativesRootObjectId; | 248 static const SnapshotObjectId kNativesRootObjectId; |
| 252 static const SnapshotObjectId kGcRootsFirstSubrootId; | 249 static const SnapshotObjectId kGcRootsFirstSubrootId; |
| 253 static const SnapshotObjectId kFirstAvailableObjectId; | 250 static const SnapshotObjectId kFirstAvailableObjectId; |
| 254 | 251 |
| 255 int FindUntrackedObjects(); | 252 int FindUntrackedObjects(); |
| 256 | 253 |
| 257 void UpdateHeapObjectsMap(); | 254 void UpdateHeapObjectsMap(); |
| 255 void RemoveDeadEntries(); |
| 258 | 256 |
| 259 private: | 257 private: |
| 260 struct EntryInfo { | 258 struct EntryInfo { |
| 261 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size) | 259 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size) |
| 262 : id(id), addr(addr), size(size), accessed(true) { } | 260 : id(id), addr(addr), size(size), accessed(true) { } |
| 263 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size, bool accessed) | 261 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size, bool accessed) |
| 264 : id(id), addr(addr), size(size), accessed(accessed) { } | 262 : id(id), addr(addr), size(size), accessed(accessed) { } |
| 265 SnapshotObjectId id; | 263 SnapshotObjectId id; |
| 266 Address addr; | 264 Address addr; |
| 267 unsigned int size; | 265 unsigned int size; |
| 268 bool accessed; | 266 bool accessed; |
| 269 }; | 267 }; |
| 270 struct TimeInterval { | 268 struct TimeInterval { |
| 271 explicit TimeInterval(SnapshotObjectId id) : id(id), size(0), count(0) { } | 269 explicit TimeInterval(SnapshotObjectId id) : id(id), size(0), count(0) { } |
| 272 SnapshotObjectId id; | 270 SnapshotObjectId id; |
| 273 uint32_t size; | 271 uint32_t size; |
| 274 uint32_t count; | 272 uint32_t count; |
| 275 }; | 273 }; |
| 276 | 274 |
| 277 void RemoveDeadEntries(); | |
| 278 | |
| 279 SnapshotObjectId next_id_; | 275 SnapshotObjectId next_id_; |
| 280 HashMap entries_map_; | 276 HashMap entries_map_; |
| 281 List<EntryInfo> entries_; | 277 List<EntryInfo> entries_; |
| 282 List<TimeInterval> time_intervals_; | 278 List<TimeInterval> time_intervals_; |
| 283 Heap* heap_; | 279 Heap* heap_; |
| 284 | 280 |
| 285 DISALLOW_COPY_AND_ASSIGN(HeapObjectsMap); | 281 DISALLOW_COPY_AND_ASSIGN(HeapObjectsMap); |
| 286 }; | 282 }; |
| 287 | 283 |
| 288 | 284 |
| 289 class HeapSnapshotsCollection { | |
| 290 public: | |
| 291 explicit HeapSnapshotsCollection(Heap* heap); | |
| 292 ~HeapSnapshotsCollection(); | |
| 293 | |
| 294 Heap* heap() const { return ids_.heap(); } | |
| 295 | |
| 296 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream) { | |
| 297 return ids_.PushHeapObjectsStats(stream); | |
| 298 } | |
| 299 void StartHeapObjectsTracking(bool track_allocations); | |
| 300 void StopHeapObjectsTracking(); | |
| 301 | |
| 302 HeapSnapshot* NewSnapshot(const char* name, unsigned uid); | |
| 303 void SnapshotGenerationFinished(HeapSnapshot* snapshot); | |
| 304 List<HeapSnapshot*>* snapshots() { return &snapshots_; } | |
| 305 void RemoveSnapshot(HeapSnapshot* snapshot); | |
| 306 | |
| 307 StringsStorage* names() { return &names_; } | |
| 308 AllocationTracker* allocation_tracker() { return allocation_tracker_; } | |
| 309 | |
| 310 SnapshotObjectId FindObjectId(Address object_addr) { | |
| 311 return ids_.FindEntry(object_addr); | |
| 312 } | |
| 313 SnapshotObjectId GetObjectId(Address object_addr, int object_size) { | |
| 314 return ids_.FindOrAddEntry(object_addr, object_size); | |
| 315 } | |
| 316 Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id); | |
| 317 void ObjectMoveEvent(Address from, Address to, int size) { | |
| 318 ids_.MoveObject(from, to, size); | |
| 319 } | |
| 320 void AllocationEvent(Address addr, int size); | |
| 321 void UpdateObjectSizeEvent(Address addr, int size) { | |
| 322 ids_.UpdateObjectSize(addr, size); | |
| 323 } | |
| 324 SnapshotObjectId last_assigned_id() const { | |
| 325 return ids_.last_assigned_id(); | |
| 326 } | |
| 327 size_t GetUsedMemorySize() const; | |
| 328 | |
| 329 int FindUntrackedObjects() { return ids_.FindUntrackedObjects(); } | |
| 330 | |
| 331 private: | |
| 332 List<HeapSnapshot*> snapshots_; | |
| 333 StringsStorage names_; | |
| 334 // Mapping from HeapObject addresses to objects' uids. | |
| 335 HeapObjectsMap ids_; | |
| 336 AllocationTracker* allocation_tracker_; | |
| 337 | |
| 338 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotsCollection); | |
| 339 }; | |
| 340 | |
| 341 | |
| 342 // A typedef for referencing anything that can be snapshotted living | 285 // A typedef for referencing anything that can be snapshotted living |
| 343 // in any kind of heap memory. | 286 // in any kind of heap memory. |
| 344 typedef void* HeapThing; | 287 typedef void* HeapThing; |
| 345 | 288 |
| 346 | 289 |
| 347 // An interface that creates HeapEntries by HeapThings. | 290 // An interface that creates HeapEntries by HeapThings. |
| 348 class HeapEntriesAllocator { | 291 class HeapEntriesAllocator { |
| 349 public: | 292 public: |
| 350 virtual ~HeapEntriesAllocator() { } | 293 virtual ~HeapEntriesAllocator() { } |
| 351 virtual HeapEntry* AllocateEntry(HeapThing ptr) = 0; | 294 virtual HeapEntry* AllocateEntry(HeapThing ptr) = 0; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 const char* GetStrongGcSubrootName(Object* object); | 467 const char* GetStrongGcSubrootName(Object* object); |
| 525 void TagObject(Object* obj, const char* tag); | 468 void TagObject(Object* obj, const char* tag); |
| 526 | 469 |
| 527 HeapEntry* GetEntry(Object* obj); | 470 HeapEntry* GetEntry(Object* obj); |
| 528 | 471 |
| 529 static inline HeapObject* GetNthGcSubrootObject(int delta); | 472 static inline HeapObject* GetNthGcSubrootObject(int delta); |
| 530 static inline int GetGcSubrootOrder(HeapObject* subroot); | 473 static inline int GetGcSubrootOrder(HeapObject* subroot); |
| 531 | 474 |
| 532 Heap* heap_; | 475 Heap* heap_; |
| 533 HeapSnapshot* snapshot_; | 476 HeapSnapshot* snapshot_; |
| 534 HeapSnapshotsCollection* collection_; | 477 StringsStorage* names_; |
| 478 HeapObjectsMap* heap_object_map_; |
| 535 SnapshottingProgressReportingInterface* progress_; | 479 SnapshottingProgressReportingInterface* progress_; |
| 536 SnapshotFillerInterface* filler_; | 480 SnapshotFillerInterface* filler_; |
| 537 HeapObjectsSet objects_tags_; | 481 HeapObjectsSet objects_tags_; |
| 538 HeapObjectsSet strong_gc_subroot_names_; | 482 HeapObjectsSet strong_gc_subroot_names_; |
| 539 HeapObjectsSet user_roots_; | 483 HeapObjectsSet user_roots_; |
| 540 v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_; | 484 v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_; |
| 541 | 485 |
| 542 static HeapObject* const kGcRootsObject; | 486 static HeapObject* const kGcRootsObject; |
| 543 static HeapObject* const kFirstGcSubrootObject; | 487 static HeapObject* const kFirstGcSubrootObject; |
| 544 static HeapObject* const kLastGcSubrootObject; | 488 static HeapObject* const kLastGcSubrootObject; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 } | 529 } |
| 586 INLINE(static bool StringsMatch(void* key1, void* key2)) { | 530 INLINE(static bool StringsMatch(void* key1, void* key2)) { |
| 587 return strcmp(reinterpret_cast<char*>(key1), | 531 return strcmp(reinterpret_cast<char*>(key1), |
| 588 reinterpret_cast<char*>(key2)) == 0; | 532 reinterpret_cast<char*>(key2)) == 0; |
| 589 } | 533 } |
| 590 | 534 |
| 591 NativeGroupRetainedObjectInfo* FindOrAddGroupInfo(const char* label); | 535 NativeGroupRetainedObjectInfo* FindOrAddGroupInfo(const char* label); |
| 592 | 536 |
| 593 Isolate* isolate_; | 537 Isolate* isolate_; |
| 594 HeapSnapshot* snapshot_; | 538 HeapSnapshot* snapshot_; |
| 595 HeapSnapshotsCollection* collection_; | 539 StringsStorage* names_; |
| 596 SnapshottingProgressReportingInterface* progress_; | 540 SnapshottingProgressReportingInterface* progress_; |
| 597 bool embedder_queried_; | 541 bool embedder_queried_; |
| 598 HeapObjectsSet in_groups_; | 542 HeapObjectsSet in_groups_; |
| 599 // RetainedObjectInfo* -> List<HeapObject*>* | 543 // RetainedObjectInfo* -> List<HeapObject*>* |
| 600 HashMap objects_by_info_; | 544 HashMap objects_by_info_; |
| 601 HashMap native_groups_; | 545 HashMap native_groups_; |
| 602 HeapEntriesAllocator* synthetic_entries_allocator_; | 546 HeapEntriesAllocator* synthetic_entries_allocator_; |
| 603 HeapEntriesAllocator* native_entries_allocator_; | 547 HeapEntriesAllocator* native_entries_allocator_; |
| 604 // Used during references extraction. | 548 // Used during references extraction. |
| 605 SnapshotFillerInterface* filler_; | 549 SnapshotFillerInterface* filler_; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 friend class HeapSnapshotJSONSerializerEnumerator; | 636 friend class HeapSnapshotJSONSerializerEnumerator; |
| 693 friend class HeapSnapshotJSONSerializerIterator; | 637 friend class HeapSnapshotJSONSerializerIterator; |
| 694 | 638 |
| 695 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); | 639 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); |
| 696 }; | 640 }; |
| 697 | 641 |
| 698 | 642 |
| 699 } } // namespace v8::internal | 643 } } // namespace v8::internal |
| 700 | 644 |
| 701 #endif // V8_HEAP_SNAPSHOT_GENERATOR_H_ | 645 #endif // V8_HEAP_SNAPSHOT_GENERATOR_H_ |
| OLD | NEW |