OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 | 551 |
552 Vector<HeapGraphEdge> children() { | 552 Vector<HeapGraphEdge> children() { |
553 return Vector<HeapGraphEdge>(children_arr(), children_count_); } | 553 return Vector<HeapGraphEdge>(children_arr(), children_count_); } |
554 Vector<HeapGraphEdge*> retainers() { | 554 Vector<HeapGraphEdge*> retainers() { |
555 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } | 555 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } |
556 HeapEntry* dominator() { return dominator_; } | 556 HeapEntry* dominator() { return dominator_; } |
557 void set_dominator(HeapEntry* entry) { | 557 void set_dominator(HeapEntry* entry) { |
558 ASSERT(entry != NULL); | 558 ASSERT(entry != NULL); |
559 dominator_ = entry; | 559 dominator_ = entry; |
560 } | 560 } |
561 | 561 void clear_paint() { painted_ = false; } |
562 void clear_paint() { painted_ = kUnpainted; } | 562 bool painted() { return painted_; } |
563 bool painted_reachable() { return painted_ == kPainted; } | 563 void paint() { |
564 void paint_reachable() { | 564 ASSERT(!painted_); |
565 ASSERT(painted_ == kUnpainted); | 565 painted_ = true; |
566 painted_ = kPainted; | |
567 } | 566 } |
568 bool not_painted_reachable_from_others() { | |
569 return painted_ != kPaintedReachableFromOthers; | |
570 } | |
571 void paint_reachable_from_others() { | |
572 painted_ = kPaintedReachableFromOthers; | |
573 } | |
574 template<class Visitor> | |
575 void ApplyAndPaintAllReachable(Visitor* visitor); | |
576 void PaintAllReachable(); | |
577 | 567 |
578 void SetIndexedReference(HeapGraphEdge::Type type, | 568 void SetIndexedReference(HeapGraphEdge::Type type, |
579 int child_index, | 569 int child_index, |
580 int index, | 570 int index, |
581 HeapEntry* entry, | 571 HeapEntry* entry, |
582 int retainer_index); | 572 int retainer_index); |
583 void SetNamedReference(HeapGraphEdge::Type type, | 573 void SetNamedReference(HeapGraphEdge::Type type, |
584 int child_index, | 574 int child_index, |
585 const char* name, | 575 const char* name, |
586 HeapEntry* entry, | 576 HeapEntry* entry, |
587 int retainer_index); | 577 int retainer_index); |
588 void SetUnidirElementReference(int child_index, int index, HeapEntry* entry); | 578 void SetUnidirElementReference(int child_index, int index, HeapEntry* entry); |
589 | 579 |
590 int EntrySize() { return EntriesSize(1, children_count_, retainers_count_); } | 580 int EntrySize() { return EntriesSize(1, children_count_, retainers_count_); } |
591 int RetainedSize(bool exact); | |
592 | 581 |
593 void Print( | 582 void Print( |
594 const char* prefix, const char* edge_name, int max_depth, int indent); | 583 const char* prefix, const char* edge_name, int max_depth, int indent); |
595 | 584 |
596 Handle<HeapObject> GetHeapObject(); | 585 Handle<HeapObject> GetHeapObject(); |
597 | 586 |
598 static int EntriesSize(int entries_count, | 587 static int EntriesSize(int entries_count, |
599 int children_count, | 588 int children_count, |
600 int retainers_count); | 589 int retainers_count); |
601 | 590 |
602 private: | 591 private: |
603 HeapGraphEdge* children_arr() { | 592 HeapGraphEdge* children_arr() { |
604 return reinterpret_cast<HeapGraphEdge*>(this + 1); | 593 return reinterpret_cast<HeapGraphEdge*>(this + 1); |
605 } | 594 } |
606 HeapGraphEdge** retainers_arr() { | 595 HeapGraphEdge** retainers_arr() { |
607 return reinterpret_cast<HeapGraphEdge**>(children_arr() + children_count_); | 596 return reinterpret_cast<HeapGraphEdge**>(children_arr() + children_count_); |
608 } | 597 } |
609 void CalculateExactRetainedSize(); | |
610 const char* TypeAsString(); | 598 const char* TypeAsString(); |
611 | 599 |
612 unsigned painted_: 2; | 600 unsigned painted_: 1; |
613 unsigned type_: 4; | 601 unsigned type_: 4; |
614 int children_count_: 26; | 602 int children_count_: 27; |
615 int retainers_count_; | 603 int retainers_count_; |
616 int self_size_; | 604 int self_size_; |
617 union { | 605 union { |
618 int ordered_index_; // Used during dominator tree building. | 606 int ordered_index_; // Used during dominator tree building. |
619 int retained_size_; // At that moment, there is no retained size yet. | 607 int retained_size_; // At that moment, there is no retained size yet. |
620 }; | 608 }; |
621 HeapEntry* dominator_; | 609 HeapEntry* dominator_; |
622 HeapSnapshot* snapshot_; | 610 HeapSnapshot* snapshot_; |
623 struct Id { | 611 struct Id { |
624 uint32_t id1_; | 612 uint32_t id1_; |
625 uint32_t id2_; | 613 uint32_t id2_; |
626 } id_; // This is to avoid extra padding of 64-bit value. | 614 } id_; // This is to avoid extra padding of 64-bit value. |
627 const char* name_; | 615 const char* name_; |
628 | 616 |
629 // Paints used for exact retained sizes calculation. | |
630 static const unsigned kUnpainted = 0; | |
631 static const unsigned kPainted = 1; | |
632 static const unsigned kPaintedReachableFromOthers = 2; | |
633 | |
634 static const int kExactRetainedSizeTag = 1; | |
635 | |
636 DISALLOW_COPY_AND_ASSIGN(HeapEntry); | 617 DISALLOW_COPY_AND_ASSIGN(HeapEntry); |
637 }; | 618 }; |
638 | 619 |
639 | 620 |
640 class HeapSnapshotsCollection; | 621 class HeapSnapshotsCollection; |
641 | 622 |
642 // HeapSnapshot represents a single heap snapshot. It is stored in | 623 // HeapSnapshot represents a single heap snapshot. It is stored in |
643 // HeapSnapshotsCollection, which is also a factory for | 624 // HeapSnapshotsCollection, which is also a factory for |
644 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap | 625 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap |
645 // to be able to return them even if they were collected. | 626 // to be able to return them even if they were collected. |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 }; | 1073 }; |
1093 | 1074 |
1094 | 1075 |
1095 class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface { | 1076 class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface { |
1096 public: | 1077 public: |
1097 HeapSnapshotGenerator(HeapSnapshot* snapshot, | 1078 HeapSnapshotGenerator(HeapSnapshot* snapshot, |
1098 v8::ActivityControl* control); | 1079 v8::ActivityControl* control); |
1099 bool GenerateSnapshot(); | 1080 bool GenerateSnapshot(); |
1100 | 1081 |
1101 private: | 1082 private: |
1102 bool ApproximateRetainedSizes(); | |
1103 bool BuildDominatorTree(const Vector<HeapEntry*>& entries, | 1083 bool BuildDominatorTree(const Vector<HeapEntry*>& entries, |
1104 Vector<int>* dominators); | 1084 Vector<int>* dominators); |
| 1085 bool CalculateRetainedSizes(); |
1105 bool CountEntriesAndReferences(); | 1086 bool CountEntriesAndReferences(); |
1106 bool FillReferences(); | 1087 bool FillReferences(); |
1107 void FillReversePostorderIndexes(Vector<HeapEntry*>* entries); | 1088 void FillReversePostorderIndexes(Vector<HeapEntry*>* entries); |
1108 void ProgressStep(); | 1089 void ProgressStep(); |
1109 bool ProgressReport(bool force = false); | 1090 bool ProgressReport(bool force = false); |
1110 bool SetEntriesDominators(); | 1091 bool SetEntriesDominators(); |
1111 void SetProgressTotal(int iterations_count); | 1092 void SetProgressTotal(int iterations_count); |
1112 | 1093 |
1113 HeapSnapshot* snapshot_; | 1094 HeapSnapshot* snapshot_; |
1114 v8::ActivityControl* control_; | 1095 v8::ActivityControl* control_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 | 1153 |
1173 friend class HeapSnapshotJSONSerializerEnumerator; | 1154 friend class HeapSnapshotJSONSerializerEnumerator; |
1174 friend class HeapSnapshotJSONSerializerIterator; | 1155 friend class HeapSnapshotJSONSerializerIterator; |
1175 | 1156 |
1176 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); | 1157 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); |
1177 }; | 1158 }; |
1178 | 1159 |
1179 } } // namespace v8::internal | 1160 } } // namespace v8::internal |
1180 | 1161 |
1181 #endif // V8_PROFILE_GENERATOR_H_ | 1162 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |