OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 uint64_t id, | 521 uint64_t id, |
522 int self_size, | 522 int self_size, |
523 int children_count, | 523 int children_count, |
524 int retainers_count); | 524 int retainers_count); |
525 | 525 |
526 HeapSnapshot* snapshot() { return snapshot_; } | 526 HeapSnapshot* snapshot() { return snapshot_; } |
527 Type type() { return static_cast<Type>(type_); } | 527 Type type() { return static_cast<Type>(type_); } |
528 const char* name() { return name_; } | 528 const char* name() { return name_; } |
529 uint64_t id() { return id_; } | 529 uint64_t id() { return id_; } |
530 int self_size() { return self_size_; } | 530 int self_size() { return self_size_; } |
| 531 int retained_size() { return retained_size_; } |
| 532 void add_retained_size(int size) { retained_size_ += size; } |
| 533 void set_retained_size(int value) { retained_size_ = value; } |
| 534 int ordered_index() { return ordered_index_; } |
| 535 void set_ordered_index(int value) { ordered_index_ = value; } |
531 | 536 |
532 Vector<HeapGraphEdge> children() { | 537 Vector<HeapGraphEdge> children() { |
533 return Vector<HeapGraphEdge>(children_arr(), children_count_); } | 538 return Vector<HeapGraphEdge>(children_arr(), children_count_); } |
534 Vector<HeapGraphEdge*> retainers() { | 539 Vector<HeapGraphEdge*> retainers() { |
535 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } | 540 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } |
536 List<HeapGraphPath*>* GetRetainingPaths(); | 541 List<HeapGraphPath*>* GetRetainingPaths(); |
| 542 HeapEntry* dominator() { return dominator_; } |
| 543 void set_dominator(HeapEntry* entry) { dominator_ = entry; } |
537 | 544 |
538 void clear_paint() { painted_ = kUnpainted; } | 545 void clear_paint() { painted_ = kUnpainted; } |
539 bool painted_reachable() { return painted_ == kPainted; } | 546 bool painted_reachable() { return painted_ == kPainted; } |
540 void paint_reachable() { | 547 void paint_reachable() { |
541 ASSERT(painted_ == kUnpainted); | 548 ASSERT(painted_ == kUnpainted); |
542 painted_ = kPainted; | 549 painted_ = kPainted; |
543 } | 550 } |
544 bool not_painted_reachable_from_others() { | 551 bool not_painted_reachable_from_others() { |
545 return painted_ != kPaintedReachableFromOthers; | 552 return painted_ != kPaintedReachableFromOthers; |
546 } | 553 } |
547 void paint_reachable_from_others() { | 554 void paint_reachable_from_others() { |
548 painted_ = kPaintedReachableFromOthers; | 555 painted_ = kPaintedReachableFromOthers; |
549 } | 556 } |
550 template<class Visitor> | 557 template<class Visitor> |
551 void ApplyAndPaintAllReachable(Visitor* visitor); | 558 void ApplyAndPaintAllReachable(Visitor* visitor); |
552 void PaintAllReachable(); | 559 void PaintAllReachable(); |
553 | 560 |
| 561 bool is_leaf() { return painted_ == kLeaf; } |
| 562 void set_leaf() { painted_ = kLeaf; } |
| 563 bool is_non_leaf() { return painted_ == kNonLeaf; } |
| 564 void set_non_leaf() { painted_ = kNonLeaf; } |
| 565 bool is_processed() { return painted_ == kProcessed; } |
| 566 void set_processed() { painted_ = kProcessed; } |
| 567 |
554 void SetIndexedReference(HeapGraphEdge::Type type, | 568 void SetIndexedReference(HeapGraphEdge::Type type, |
555 int child_index, | 569 int child_index, |
556 int index, | 570 int index, |
557 HeapEntry* entry, | 571 HeapEntry* entry, |
558 int retainer_index); | 572 int retainer_index); |
559 void SetNamedReference(HeapGraphEdge::Type type, | 573 void SetNamedReference(HeapGraphEdge::Type type, |
560 int child_index, | 574 int child_index, |
561 const char* name, | 575 const char* name, |
562 HeapEntry* entry, | 576 HeapEntry* entry, |
563 int retainer_index); | 577 int retainer_index); |
564 void SetUnidirElementReference(int child_index, int index, HeapEntry* entry); | 578 void SetUnidirElementReference(int child_index, int index, HeapEntry* entry); |
565 | 579 |
566 int EntrySize() { return EntriesSize(1, children_count_, retainers_count_); } | 580 int EntrySize() { return EntriesSize(1, children_count_, retainers_count_); } |
567 int ReachableSize(); | 581 int RetainedSize(bool exact); |
568 int RetainedSize(); | 582 List<HeapGraphPath*>* CalculateRetainingPaths(); |
569 | 583 |
570 void Print(int max_depth, int indent); | 584 void Print(int max_depth, int indent); |
571 | 585 |
572 static int EntriesSize(int entries_count, | 586 static int EntriesSize(int entries_count, |
573 int children_count, | 587 int children_count, |
574 int retainers_count); | 588 int retainers_count); |
| 589 static uint32_t Hash(HeapEntry* entry) { |
| 590 return ComputeIntegerHash( |
| 591 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(entry))); |
| 592 } |
| 593 static bool Match(void* entry1, void* entry2) { return entry1 == entry2; } |
575 | 594 |
576 private: | 595 private: |
577 HeapGraphEdge* children_arr() { | 596 HeapGraphEdge* children_arr() { |
578 return reinterpret_cast<HeapGraphEdge*>(this + 1); | 597 return reinterpret_cast<HeapGraphEdge*>(this + 1); |
579 } | 598 } |
580 HeapGraphEdge** retainers_arr() { | 599 HeapGraphEdge** retainers_arr() { |
581 return reinterpret_cast<HeapGraphEdge**>(children_arr() + children_count_); | 600 return reinterpret_cast<HeapGraphEdge**>(children_arr() + children_count_); |
582 } | 601 } |
| 602 void CalculateExactRetainedSize(); |
| 603 void FindRetainingPaths(CachedHeapGraphPath* prev_path, |
| 604 List<HeapGraphPath*>* retaining_paths); |
583 const char* TypeAsString(); | 605 const char* TypeAsString(); |
584 | 606 |
585 unsigned painted_: 2; | 607 unsigned painted_: 2; |
586 unsigned type_: 3; | 608 unsigned type_: 3; |
587 // The calculated data is stored in HeapSnapshot in HeapEntryCalculatedData | 609 int children_count_: 27; |
588 // entries. See AddCalculatedData and GetCalculatedData. | 610 int retainers_count_; |
589 int calculated_data_index_: 27; | |
590 int self_size_; | 611 int self_size_; |
591 int children_count_; | 612 union { |
592 int retainers_count_; | 613 int ordered_index_; // Used during dominator tree building. |
| 614 int retained_size_; // At that moment, there is no retained size yet. |
| 615 }; |
| 616 HeapEntry* dominator_; |
593 HeapSnapshot* snapshot_; | 617 HeapSnapshot* snapshot_; |
594 const char* name_; | 618 const char* name_; |
595 uint64_t id_; | 619 uint64_t id_; |
596 | 620 |
| 621 // Paints used for exact retained sizes calculation. |
597 static const unsigned kUnpainted = 0; | 622 static const unsigned kUnpainted = 0; |
598 static const unsigned kPainted = 1; | 623 static const unsigned kPainted = 1; |
599 static const unsigned kPaintedReachableFromOthers = 2; | 624 static const unsigned kPaintedReachableFromOthers = 2; |
600 static const int kNoCalculatedData = -1; | 625 // Paints used for approximate retained sizes calculation. |
| 626 static const unsigned kLeaf = 0; |
| 627 static const unsigned kNonLeaf = 1; |
| 628 static const unsigned kProcessed = 2; |
| 629 |
| 630 static const int kExactRetainedSizeTag = 1; |
601 | 631 |
602 DISALLOW_COPY_AND_ASSIGN(HeapEntry); | 632 DISALLOW_COPY_AND_ASSIGN(HeapEntry); |
603 }; | 633 }; |
604 | 634 |
605 | 635 |
606 class HeapEntryCalculatedData { | |
607 public: | |
608 HeapEntryCalculatedData() | |
609 : retaining_paths_(NULL), | |
610 reachable_size_(kUnknownSize), | |
611 retained_size_(kUnknownSize) { | |
612 } | |
613 void Dispose(); | |
614 | |
615 List<HeapGraphPath*>* GetRetainingPaths(HeapEntry* entry); | |
616 int ReachableSize(HeapEntry* entry); | |
617 int RetainedSize(HeapEntry* entry); | |
618 | |
619 private: | |
620 void CalculateSizes(HeapEntry* entry); | |
621 void FindRetainingPaths(HeapEntry* entry, CachedHeapGraphPath* prev_path); | |
622 | |
623 List<HeapGraphPath*>* retaining_paths_; | |
624 int reachable_size_; | |
625 int retained_size_; | |
626 | |
627 static const int kUnknownSize = -1; | |
628 | |
629 // Allow generated copy constructor and assignment operator. | |
630 }; | |
631 | |
632 | |
633 class HeapGraphPath { | 636 class HeapGraphPath { |
634 public: | 637 public: |
635 HeapGraphPath() | 638 HeapGraphPath() |
636 : path_(8) { } | 639 : path_(8) { } |
637 explicit HeapGraphPath(const List<HeapGraphEdge*>& path); | 640 explicit HeapGraphPath(const List<HeapGraphEdge*>& path); |
638 | 641 |
639 void Add(HeapGraphEdge* edge) { path_.Add(edge); } | 642 void Add(HeapGraphEdge* edge) { path_.Add(edge); } |
640 void Set(int index, HeapGraphEdge* edge) { path_[index] = edge; } | 643 void Set(int index, HeapGraphEdge* edge) { path_[index] = edge; } |
641 const List<HeapGraphEdge*>* path() { return &path_; } | 644 const List<HeapGraphEdge*>* path() { return &path_; } |
642 | 645 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 void AllocateEntries( | 683 void AllocateEntries( |
681 int entries_count, int children_count, int retainers_count); | 684 int entries_count, int children_count, int retainers_count); |
682 HeapEntry* AddEntry( | 685 HeapEntry* AddEntry( |
683 HeapObject* object, int children_count, int retainers_count); | 686 HeapObject* object, int children_count, int retainers_count); |
684 HeapEntry* AddEntry(HeapEntry::Type type, | 687 HeapEntry* AddEntry(HeapEntry::Type type, |
685 const char* name, | 688 const char* name, |
686 uint64_t id, | 689 uint64_t id, |
687 int size, | 690 int size, |
688 int children_count, | 691 int children_count, |
689 int retainers_count); | 692 int retainers_count); |
690 int AddCalculatedData(); | 693 void ApproximateRetainedSizes(); |
691 HeapEntryCalculatedData& GetCalculatedData(int index) { | |
692 return calculated_data_[index]; | |
693 } | |
694 void ClearPaint(); | 694 void ClearPaint(); |
695 HeapSnapshotsDiff* CompareWith(HeapSnapshot* snapshot); | 695 HeapSnapshotsDiff* CompareWith(HeapSnapshot* snapshot); |
| 696 List<HeapGraphPath*>* GetRetainingPaths(HeapEntry* entry); |
696 List<HeapEntry*>* GetSortedEntriesList(); | 697 List<HeapEntry*>* GetSortedEntriesList(); |
697 template<class Visitor> | 698 template<class Visitor> |
698 void IterateEntries(Visitor* visitor) { entries_.Iterate(visitor); } | 699 void IterateEntries(Visitor* visitor) { entries_.Iterate(visitor); } |
699 | 700 |
700 void Print(int max_depth); | 701 void Print(int max_depth); |
701 void PrintEntriesSize(); | 702 void PrintEntriesSize(); |
702 | 703 |
703 static HeapObject* const kInternalRootObject; | 704 static HeapObject* const kInternalRootObject; |
704 static HeapObject* const kGcRootsObject; | 705 static HeapObject* const kGcRootsObject; |
705 | 706 |
706 private: | 707 private: |
707 HeapEntry* AddEntry(HeapObject* object, | 708 HeapEntry* AddEntry(HeapObject* object, |
708 HeapEntry::Type type, | 709 HeapEntry::Type type, |
709 const char* name, | 710 const char* name, |
710 int children_count, | 711 int children_count, |
711 int retainers_count); | 712 int retainers_count); |
712 HeapEntry* GetNextEntryToInit(); | 713 HeapEntry* GetNextEntryToInit(); |
| 714 void BuildDominatorTree(const Vector<HeapEntry*>& entries, |
| 715 Vector<HeapEntry*>* dominators); |
| 716 void FillReversePostorderIndexes(Vector<HeapEntry*>* entries); |
| 717 void SetEntriesDominators(); |
713 | 718 |
714 HeapSnapshotsCollection* collection_; | 719 HeapSnapshotsCollection* collection_; |
715 Type type_; | 720 Type type_; |
716 const char* title_; | 721 const char* title_; |
717 unsigned uid_; | 722 unsigned uid_; |
718 HeapEntry* root_entry_; | 723 HeapEntry* root_entry_; |
719 HeapEntry* gc_roots_entry_; | 724 HeapEntry* gc_roots_entry_; |
720 char* raw_entries_; | 725 char* raw_entries_; |
721 List<HeapEntry*> entries_; | 726 List<HeapEntry*> entries_; |
722 bool entries_sorted_; | 727 bool entries_sorted_; |
723 List<HeapEntryCalculatedData> calculated_data_; | 728 HashMap retaining_paths_; |
724 #ifdef DEBUG | 729 #ifdef DEBUG |
725 int raw_entries_size_; | 730 int raw_entries_size_; |
726 #endif | 731 #endif |
727 | 732 |
728 friend class HeapSnapshotTester; | 733 friend class HeapSnapshotTester; |
729 | 734 |
730 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); | 735 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); |
731 }; | 736 }; |
732 | 737 |
733 | 738 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 friend class HeapSnapshotJSONSerializerIterator; | 1067 friend class HeapSnapshotJSONSerializerIterator; |
1063 | 1068 |
1064 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); | 1069 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); |
1065 }; | 1070 }; |
1066 | 1071 |
1067 } } // namespace v8::internal | 1072 } } // namespace v8::internal |
1068 | 1073 |
1069 #endif // ENABLE_LOGGING_AND_PROFILING | 1074 #endif // ENABLE_LOGGING_AND_PROFILING |
1070 | 1075 |
1071 #endif // V8_PROFILE_GENERATOR_H_ | 1076 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |