| 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 432 |
| 433 | 433 |
| 434 class HeapEntry; | 434 class HeapEntry; |
| 435 | 435 |
| 436 class HeapGraphEdge BASE_EMBEDDED { | 436 class HeapGraphEdge BASE_EMBEDDED { |
| 437 public: | 437 public: |
| 438 enum Type { | 438 enum Type { |
| 439 kContextVariable = v8::HeapGraphEdge::kContextVariable, | 439 kContextVariable = v8::HeapGraphEdge::kContextVariable, |
| 440 kElement = v8::HeapGraphEdge::kElement, | 440 kElement = v8::HeapGraphEdge::kElement, |
| 441 kProperty = v8::HeapGraphEdge::kProperty, | 441 kProperty = v8::HeapGraphEdge::kProperty, |
| 442 kInternal = v8::HeapGraphEdge::kInternal | 442 kInternal = v8::HeapGraphEdge::kInternal, |
| 443 kHidden = v8::HeapGraphEdge::kHidden, |
| 444 kShortcut = v8::HeapGraphEdge::kShortcut |
| 443 }; | 445 }; |
| 444 | 446 |
| 445 HeapGraphEdge() { } | 447 HeapGraphEdge() { } |
| 446 void Init(int child_index, Type type, const char* name, HeapEntry* to); | 448 void Init(int child_index, Type type, const char* name, HeapEntry* to); |
| 449 void Init(int child_index, Type type, int index, HeapEntry* to); |
| 447 void Init(int child_index, int index, HeapEntry* to); | 450 void Init(int child_index, int index, HeapEntry* to); |
| 448 | 451 |
| 449 Type type() { return static_cast<Type>(type_); } | 452 Type type() { return static_cast<Type>(type_); } |
| 450 int index() { | 453 int index() { |
| 451 ASSERT(type_ == kElement); | 454 ASSERT(type_ == kElement || type_ == kHidden); |
| 452 return index_; | 455 return index_; |
| 453 } | 456 } |
| 454 const char* name() { | 457 const char* name() { |
| 455 ASSERT(type_ == kContextVariable | 458 ASSERT(type_ == kContextVariable |
| 456 || type_ == kProperty | 459 || type_ == kProperty |
| 457 || type_ == kInternal); | 460 || type_ == kInternal |
| 461 || type_ == kShortcut); |
| 458 return name_; | 462 return name_; |
| 459 } | 463 } |
| 460 HeapEntry* to() { return to_; } | 464 HeapEntry* to() { return to_; } |
| 461 | 465 |
| 462 HeapEntry* From(); | 466 HeapEntry* From(); |
| 463 | 467 |
| 464 private: | 468 private: |
| 465 int child_index_ : 30; | 469 int child_index_ : 29; |
| 466 unsigned type_ : 2; | 470 unsigned type_ : 3; |
| 467 union { | 471 union { |
| 468 int index_; | 472 int index_; |
| 469 const char* name_; | 473 const char* name_; |
| 470 }; | 474 }; |
| 471 HeapEntry* to_; | 475 HeapEntry* to_; |
| 472 | 476 |
| 473 DISALLOW_COPY_AND_ASSIGN(HeapGraphEdge); | 477 DISALLOW_COPY_AND_ASSIGN(HeapGraphEdge); |
| 474 }; | 478 }; |
| 475 | 479 |
| 476 | 480 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 493 // ... } retainers_count | 497 // ... } retainers_count |
| 494 // HeapGraphEdge* | | 498 // HeapGraphEdge* | |
| 495 // +-----------------+ | 499 // +-----------------+ |
| 496 // | 500 // |
| 497 // In a HeapSnapshot, all entries are hand-allocated in a continuous array | 501 // In a HeapSnapshot, all entries are hand-allocated in a continuous array |
| 498 // of raw bytes. | 502 // of raw bytes. |
| 499 // | 503 // |
| 500 class HeapEntry BASE_EMBEDDED { | 504 class HeapEntry BASE_EMBEDDED { |
| 501 public: | 505 public: |
| 502 enum Type { | 506 enum Type { |
| 503 kInternal = v8::HeapGraphNode::kInternal, | 507 kHidden = v8::HeapGraphNode::kHidden, |
| 504 kArray = v8::HeapGraphNode::kArray, | 508 kArray = v8::HeapGraphNode::kArray, |
| 505 kString = v8::HeapGraphNode::kString, | 509 kString = v8::HeapGraphNode::kString, |
| 506 kObject = v8::HeapGraphNode::kObject, | 510 kObject = v8::HeapGraphNode::kObject, |
| 507 kCode = v8::HeapGraphNode::kCode, | 511 kCode = v8::HeapGraphNode::kCode, |
| 508 kClosure = v8::HeapGraphNode::kClosure, | 512 kClosure = v8::HeapGraphNode::kClosure, |
| 509 kRegExp = v8::HeapGraphNode::kRegExp, | 513 kRegExp = v8::HeapGraphNode::kRegExp, |
| 510 kHeapNumber = v8::HeapGraphNode::kHeapNumber | 514 kHeapNumber = v8::HeapGraphNode::kHeapNumber |
| 511 }; | 515 }; |
| 512 | 516 |
| 513 HeapEntry() { } | 517 HeapEntry() { } |
| 514 void Init(HeapSnapshot* snapshot, | 518 void Init(HeapSnapshot* snapshot, |
| 515 Type type, | 519 Type type, |
| 516 const char* name, | 520 const char* name, |
| 517 uint64_t id, | 521 uint64_t id, |
| 518 int self_size, | 522 int self_size, |
| 519 int children_count, | 523 int children_count, |
| 520 int retainers_count); | 524 int retainers_count); |
| 521 | 525 |
| 522 HeapSnapshot* snapshot() { return snapshot_; } | 526 HeapSnapshot* snapshot() { return snapshot_; } |
| 523 Type type() { return static_cast<Type>(type_); } | 527 Type type() { return static_cast<Type>(type_); } |
| 524 const char* name() { return name_; } | 528 const char* name() { return name_; } |
| 525 uint64_t id() { return id_; } | 529 uint64_t id(); |
| 526 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; } |
| 527 | 536 |
| 528 Vector<HeapGraphEdge> children() { | 537 Vector<HeapGraphEdge> children() { |
| 529 return Vector<HeapGraphEdge>(children_arr(), children_count_); } | 538 return Vector<HeapGraphEdge>(children_arr(), children_count_); } |
| 530 Vector<HeapGraphEdge*> retainers() { | 539 Vector<HeapGraphEdge*> retainers() { |
| 531 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } | 540 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } |
| 532 List<HeapGraphPath*>* GetRetainingPaths(); | 541 List<HeapGraphPath*>* GetRetainingPaths(); |
| 542 HeapEntry* dominator() { return dominator_; } |
| 543 void set_dominator(HeapEntry* entry) { dominator_ = entry; } |
| 533 | 544 |
| 534 void clear_paint() { painted_ = kUnpainted; } | 545 void clear_paint() { painted_ = kUnpainted; } |
| 535 bool painted_reachable() { return painted_ == kPainted; } | 546 bool painted_reachable() { return painted_ == kPainted; } |
| 536 void paint_reachable() { | 547 void paint_reachable() { |
| 537 ASSERT(painted_ == kUnpainted); | 548 ASSERT(painted_ == kUnpainted); |
| 538 painted_ = kPainted; | 549 painted_ = kPainted; |
| 539 } | 550 } |
| 540 bool not_painted_reachable_from_others() { | 551 bool not_painted_reachable_from_others() { |
| 541 return painted_ != kPaintedReachableFromOthers; | 552 return painted_ != kPaintedReachableFromOthers; |
| 542 } | 553 } |
| 543 void paint_reachable_from_others() { | 554 void paint_reachable_from_others() { |
| 544 painted_ = kPaintedReachableFromOthers; | 555 painted_ = kPaintedReachableFromOthers; |
| 545 } | 556 } |
| 546 template<class Visitor> | 557 template<class Visitor> |
| 547 void ApplyAndPaintAllReachable(Visitor* visitor); | 558 void ApplyAndPaintAllReachable(Visitor* visitor); |
| 548 void PaintAllReachable(); | 559 void PaintAllReachable(); |
| 549 | 560 |
| 550 void SetElementReference( | 561 bool is_leaf() { return painted_ == kLeaf; } |
| 551 int child_index, int index, HeapEntry* entry, int retainer_index); | 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 |
| 568 void SetIndexedReference(HeapGraphEdge::Type type, |
| 569 int child_index, |
| 570 int index, |
| 571 HeapEntry* entry, |
| 572 int retainer_index); |
| 552 void SetNamedReference(HeapGraphEdge::Type type, | 573 void SetNamedReference(HeapGraphEdge::Type type, |
| 553 int child_index, | 574 int child_index, |
| 554 const char* name, | 575 const char* name, |
| 555 HeapEntry* entry, | 576 HeapEntry* entry, |
| 556 int retainer_index); | 577 int retainer_index); |
| 557 void SetUnidirElementReference(int child_index, int index, HeapEntry* entry); | 578 void SetUnidirElementReference(int child_index, int index, HeapEntry* entry); |
| 558 | 579 |
| 559 int EntrySize() { return EntriesSize(1, children_count_, retainers_count_); } | 580 int EntrySize() { return EntriesSize(1, children_count_, retainers_count_); } |
| 560 int ReachableSize(); | 581 int RetainedSize(bool exact); |
| 561 int RetainedSize(); | 582 List<HeapGraphPath*>* CalculateRetainingPaths(); |
| 562 | 583 |
| 563 void Print(int max_depth, int indent); | 584 void Print(int max_depth, int indent); |
| 564 | 585 |
| 565 static int EntriesSize(int entries_count, | 586 static int EntriesSize(int entries_count, |
| 566 int children_count, | 587 int children_count, |
| 567 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; } |
| 568 | 594 |
| 569 private: | 595 private: |
| 570 HeapGraphEdge* children_arr() { | 596 HeapGraphEdge* children_arr() { |
| 571 return reinterpret_cast<HeapGraphEdge*>(this + 1); | 597 return reinterpret_cast<HeapGraphEdge*>(this + 1); |
| 572 } | 598 } |
| 573 HeapGraphEdge** retainers_arr() { | 599 HeapGraphEdge** retainers_arr() { |
| 574 return reinterpret_cast<HeapGraphEdge**>(children_arr() + children_count_); | 600 return reinterpret_cast<HeapGraphEdge**>(children_arr() + children_count_); |
| 575 } | 601 } |
| 602 void CalculateExactRetainedSize(); |
| 603 void FindRetainingPaths(CachedHeapGraphPath* prev_path, |
| 604 List<HeapGraphPath*>* retaining_paths); |
| 576 const char* TypeAsString(); | 605 const char* TypeAsString(); |
| 577 | 606 |
| 578 unsigned painted_: 2; | 607 unsigned painted_: 2; |
| 579 unsigned type_: 3; | 608 unsigned type_: 3; |
| 580 // The calculated data is stored in HeapSnapshot in HeapEntryCalculatedData | 609 int children_count_: 27; |
| 581 // entries. See AddCalculatedData and GetCalculatedData. | 610 int retainers_count_; |
| 582 int calculated_data_index_: 27; | |
| 583 int self_size_; | 611 int self_size_; |
| 584 int children_count_; | 612 union { |
| 585 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_; |
| 586 HeapSnapshot* snapshot_; | 617 HeapSnapshot* snapshot_; |
| 618 struct Id { |
| 619 uint32_t id1_; |
| 620 uint32_t id2_; |
| 621 } id_; // This is to avoid extra padding of 64-bit value. |
| 587 const char* name_; | 622 const char* name_; |
| 588 uint64_t id_; | |
| 589 | 623 |
| 624 // Paints used for exact retained sizes calculation. |
| 590 static const unsigned kUnpainted = 0; | 625 static const unsigned kUnpainted = 0; |
| 591 static const unsigned kPainted = 1; | 626 static const unsigned kPainted = 1; |
| 592 static const unsigned kPaintedReachableFromOthers = 2; | 627 static const unsigned kPaintedReachableFromOthers = 2; |
| 593 static const int kNoCalculatedData = -1; | 628 // Paints used for approximate retained sizes calculation. |
| 629 static const unsigned kLeaf = 0; |
| 630 static const unsigned kNonLeaf = 1; |
| 631 static const unsigned kProcessed = 2; |
| 632 |
| 633 static const int kExactRetainedSizeTag = 1; |
| 594 | 634 |
| 595 DISALLOW_COPY_AND_ASSIGN(HeapEntry); | 635 DISALLOW_COPY_AND_ASSIGN(HeapEntry); |
| 596 }; | 636 }; |
| 597 | 637 |
| 598 | 638 |
| 599 class HeapEntryCalculatedData { | |
| 600 public: | |
| 601 HeapEntryCalculatedData() | |
| 602 : retaining_paths_(NULL), | |
| 603 reachable_size_(kUnknownSize), | |
| 604 retained_size_(kUnknownSize) { | |
| 605 } | |
| 606 void Dispose(); | |
| 607 | |
| 608 List<HeapGraphPath*>* GetRetainingPaths(HeapEntry* entry); | |
| 609 int ReachableSize(HeapEntry* entry); | |
| 610 int RetainedSize(HeapEntry* entry); | |
| 611 | |
| 612 private: | |
| 613 void CalculateSizes(HeapEntry* entry); | |
| 614 void FindRetainingPaths(HeapEntry* entry, CachedHeapGraphPath* prev_path); | |
| 615 | |
| 616 List<HeapGraphPath*>* retaining_paths_; | |
| 617 int reachable_size_; | |
| 618 int retained_size_; | |
| 619 | |
| 620 static const int kUnknownSize = -1; | |
| 621 | |
| 622 // Allow generated copy constructor and assignment operator. | |
| 623 }; | |
| 624 | |
| 625 | |
| 626 class HeapGraphPath { | 639 class HeapGraphPath { |
| 627 public: | 640 public: |
| 628 HeapGraphPath() | 641 HeapGraphPath() |
| 629 : path_(8) { } | 642 : path_(8) { } |
| 630 explicit HeapGraphPath(const List<HeapGraphEdge*>& path); | 643 explicit HeapGraphPath(const List<HeapGraphEdge*>& path); |
| 631 | 644 |
| 632 void Add(HeapGraphEdge* edge) { path_.Add(edge); } | 645 void Add(HeapGraphEdge* edge) { path_.Add(edge); } |
| 633 void Set(int index, HeapGraphEdge* edge) { path_[index] = edge; } | 646 void Set(int index, HeapGraphEdge* edge) { path_[index] = edge; } |
| 634 const List<HeapGraphEdge*>* path() { return &path_; } | 647 const List<HeapGraphEdge*>* path() { return &path_; } |
| 635 | 648 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 661 Type type, | 674 Type type, |
| 662 const char* title, | 675 const char* title, |
| 663 unsigned uid); | 676 unsigned uid); |
| 664 ~HeapSnapshot(); | 677 ~HeapSnapshot(); |
| 665 | 678 |
| 666 HeapSnapshotsCollection* collection() { return collection_; } | 679 HeapSnapshotsCollection* collection() { return collection_; } |
| 667 Type type() { return type_; } | 680 Type type() { return type_; } |
| 668 const char* title() { return title_; } | 681 const char* title() { return title_; } |
| 669 unsigned uid() { return uid_; } | 682 unsigned uid() { return uid_; } |
| 670 HeapEntry* root() { return root_entry_; } | 683 HeapEntry* root() { return root_entry_; } |
| 684 HeapEntry* gc_roots() { return gc_roots_entry_; } |
| 671 | 685 |
| 672 void AllocateEntries( | 686 void AllocateEntries( |
| 673 int entries_count, int children_count, int retainers_count); | 687 int entries_count, int children_count, int retainers_count); |
| 674 HeapEntry* AddEntry( | 688 HeapEntry* AddEntry( |
| 675 HeapObject* object, int children_count, int retainers_count); | 689 HeapObject* object, int children_count, int retainers_count); |
| 676 bool WillAddEntry(HeapObject* object); | |
| 677 HeapEntry* AddEntry(HeapEntry::Type type, | 690 HeapEntry* AddEntry(HeapEntry::Type type, |
| 678 const char* name, | 691 const char* name, |
| 679 uint64_t id, | 692 uint64_t id, |
| 680 int size, | 693 int size, |
| 681 int children_count, | 694 int children_count, |
| 682 int retainers_count); | 695 int retainers_count); |
| 683 int AddCalculatedData(); | 696 void ApproximateRetainedSizes(); |
| 684 HeapEntryCalculatedData& GetCalculatedData(int index) { | |
| 685 return calculated_data_[index]; | |
| 686 } | |
| 687 void ClearPaint(); | 697 void ClearPaint(); |
| 688 HeapSnapshotsDiff* CompareWith(HeapSnapshot* snapshot); | 698 HeapSnapshotsDiff* CompareWith(HeapSnapshot* snapshot); |
| 699 List<HeapGraphPath*>* GetRetainingPaths(HeapEntry* entry); |
| 689 List<HeapEntry*>* GetSortedEntriesList(); | 700 List<HeapEntry*>* GetSortedEntriesList(); |
| 690 template<class Visitor> | 701 template<class Visitor> |
| 691 void IterateEntries(Visitor* visitor) { entries_.Iterate(visitor); } | 702 void IterateEntries(Visitor* visitor) { entries_.Iterate(visitor); } |
| 692 | 703 |
| 693 void Print(int max_depth); | 704 void Print(int max_depth); |
| 694 void PrintEntriesSize(); | 705 void PrintEntriesSize(); |
| 695 | 706 |
| 696 static HeapObject *const kInternalRootObject; | 707 static HeapObject* const kInternalRootObject; |
| 708 static HeapObject* const kGcRootsObject; |
| 697 | 709 |
| 698 private: | 710 private: |
| 699 HeapEntry* AddEntry(HeapObject* object, | 711 HeapEntry* AddEntry(HeapObject* object, |
| 700 HeapEntry::Type type, | 712 HeapEntry::Type type, |
| 701 const char* name, | 713 const char* name, |
| 702 int children_count, | 714 int children_count, |
| 703 int retainers_count); | 715 int retainers_count); |
| 704 HeapEntry* GetNextEntryToInit(); | 716 HeapEntry* GetNextEntryToInit(); |
| 705 static int GetObjectSize(HeapObject* obj); | 717 void BuildDominatorTree(const Vector<HeapEntry*>& entries, |
| 706 static int CalculateNetworkSize(JSObject* obj); | 718 Vector<HeapEntry*>* dominators); |
| 719 void FillReversePostorderIndexes(Vector<HeapEntry*>* entries); |
| 720 void SetEntriesDominators(); |
| 707 | 721 |
| 708 HeapSnapshotsCollection* collection_; | 722 HeapSnapshotsCollection* collection_; |
| 709 Type type_; | 723 Type type_; |
| 710 const char* title_; | 724 const char* title_; |
| 711 unsigned uid_; | 725 unsigned uid_; |
| 712 HeapEntry* root_entry_; | 726 HeapEntry* root_entry_; |
| 727 HeapEntry* gc_roots_entry_; |
| 713 char* raw_entries_; | 728 char* raw_entries_; |
| 714 List<HeapEntry*> entries_; | 729 List<HeapEntry*> entries_; |
| 715 bool entries_sorted_; | 730 bool entries_sorted_; |
| 716 List<HeapEntryCalculatedData> calculated_data_; | 731 HashMap retaining_paths_; |
| 717 #ifdef DEBUG | 732 #ifdef DEBUG |
| 718 int raw_entries_size_; | 733 int raw_entries_size_; |
| 719 #endif | 734 #endif |
| 720 | 735 |
| 721 friend class HeapSnapshotTester; | 736 friend class HeapSnapshotTester; |
| 722 | 737 |
| 723 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); | 738 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); |
| 724 }; | 739 }; |
| 725 | 740 |
| 726 | 741 |
| 727 class HeapObjectsMap { | 742 class HeapObjectsMap { |
| 728 public: | 743 public: |
| 729 HeapObjectsMap(); | 744 HeapObjectsMap(); |
| 730 ~HeapObjectsMap(); | 745 ~HeapObjectsMap(); |
| 731 | 746 |
| 732 void SnapshotGenerationFinished(); | 747 void SnapshotGenerationFinished(); |
| 733 uint64_t FindObject(Address addr); | 748 uint64_t FindObject(Address addr); |
| 734 void MoveObject(Address from, Address to); | 749 void MoveObject(Address from, Address to); |
| 735 | 750 |
| 751 static const uint64_t kInternalRootObjectId; |
| 752 static const uint64_t kGcRootsObjectId; |
| 753 static const uint64_t kFirstAvailableObjectId; |
| 754 |
| 736 private: | 755 private: |
| 737 struct EntryInfo { | 756 struct EntryInfo { |
| 738 explicit EntryInfo(uint64_t id) : id(id), accessed(true) { } | 757 explicit EntryInfo(uint64_t id) : id(id), accessed(true) { } |
| 739 EntryInfo(uint64_t id, bool accessed) : id(id), accessed(accessed) { } | 758 EntryInfo(uint64_t id, bool accessed) : id(id), accessed(accessed) { } |
| 740 uint64_t id; | 759 uint64_t id; |
| 741 bool accessed; | 760 bool accessed; |
| 742 }; | 761 }; |
| 743 | 762 |
| 744 void AddEntry(Address addr, uint64_t id); | 763 void AddEntry(Address addr, uint64_t id); |
| 745 uint64_t FindEntry(Address addr); | 764 uint64_t FindEntry(Address addr); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 }; | 880 }; |
| 862 | 881 |
| 863 | 882 |
| 864 // The HeapEntriesMap instance is used to track a mapping between | 883 // The HeapEntriesMap instance is used to track a mapping between |
| 865 // real heap objects and their representations in heap snapshots. | 884 // real heap objects and their representations in heap snapshots. |
| 866 class HeapEntriesMap { | 885 class HeapEntriesMap { |
| 867 public: | 886 public: |
| 868 HeapEntriesMap(); | 887 HeapEntriesMap(); |
| 869 ~HeapEntriesMap(); | 888 ~HeapEntriesMap(); |
| 870 | 889 |
| 871 // Aliasing is used for skipping intermediate proxy objects, like | |
| 872 // JSGlobalPropertyCell. | |
| 873 void Alias(HeapObject* from, HeapObject* to); | |
| 874 HeapEntry* Map(HeapObject* object); | 890 HeapEntry* Map(HeapObject* object); |
| 875 void Pair(HeapObject* object, HeapEntry* entry); | 891 void Pair(HeapObject* object, HeapEntry* entry); |
| 876 void CountReference(HeapObject* from, HeapObject* to, | 892 void CountReference(HeapObject* from, HeapObject* to, |
| 877 int* prev_children_count = NULL, | 893 int* prev_children_count = NULL, |
| 878 int* prev_retainers_count = NULL); | 894 int* prev_retainers_count = NULL); |
| 879 template<class Visitor> | 895 template<class Visitor> |
| 880 void UpdateEntries(Visitor* visitor); | 896 void UpdateEntries(Visitor* visitor); |
| 881 | 897 |
| 882 int entries_count() { return entries_count_; } | 898 int entries_count() { return entries_count_; } |
| 883 int total_children_count() { return total_children_count_; } | 899 int total_children_count() { return total_children_count_; } |
| 884 int total_retainers_count() { return total_retainers_count_; } | 900 int total_retainers_count() { return total_retainers_count_; } |
| 885 | 901 |
| 886 static HeapEntry *const kHeapEntryPlaceholder; | 902 static HeapEntry *const kHeapEntryPlaceholder; |
| 887 | 903 |
| 888 private: | 904 private: |
| 889 struct EntryInfo { | 905 struct EntryInfo { |
| 890 explicit EntryInfo(HeapEntry* entry) | 906 explicit EntryInfo(HeapEntry* entry) |
| 891 : entry(entry), children_count(0), retainers_count(0) { } | 907 : entry(entry), children_count(0), retainers_count(0) { } |
| 892 HeapEntry* entry; | 908 HeapEntry* entry; |
| 893 int children_count; | 909 int children_count; |
| 894 int retainers_count; | 910 int retainers_count; |
| 895 }; | 911 }; |
| 896 | 912 |
| 897 uint32_t Hash(HeapObject* object) { | 913 static uint32_t Hash(HeapObject* object) { |
| 898 return ComputeIntegerHash( | 914 return ComputeIntegerHash( |
| 899 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(object))); | 915 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(object))); |
| 900 } | 916 } |
| 901 static bool HeapObjectsMatch(void* key1, void* key2) { return key1 == key2; } | 917 static bool HeapObjectsMatch(void* key1, void* key2) { return key1 == key2; } |
| 902 | 918 |
| 903 bool IsAlias(void* ptr) { | |
| 904 return reinterpret_cast<intptr_t>(ptr) & kAliasTag; | |
| 905 } | |
| 906 void* MakeAlias(void* ptr) { | |
| 907 return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(ptr) | kAliasTag); | |
| 908 } | |
| 909 void* Unalias(void* ptr) { | |
| 910 return reinterpret_cast<void*>( | |
| 911 reinterpret_cast<intptr_t>(ptr) & (~kAliasTag)); | |
| 912 } | |
| 913 | |
| 914 HashMap entries_; | 919 HashMap entries_; |
| 915 int entries_count_; | 920 int entries_count_; |
| 916 int total_children_count_; | 921 int total_children_count_; |
| 917 int total_retainers_count_; | 922 int total_retainers_count_; |
| 918 | 923 |
| 919 static const intptr_t kAliasTag = 1; | 924 friend class HeapObjectsSet; |
| 920 | 925 |
| 921 DISALLOW_COPY_AND_ASSIGN(HeapEntriesMap); | 926 DISALLOW_COPY_AND_ASSIGN(HeapEntriesMap); |
| 922 }; | 927 }; |
| 923 | 928 |
| 924 | 929 |
| 930 class HeapObjectsSet { |
| 931 public: |
| 932 HeapObjectsSet(); |
| 933 void Clear(); |
| 934 bool Contains(Object* object); |
| 935 void Insert(Object* obj); |
| 936 |
| 937 private: |
| 938 HashMap entries_; |
| 939 |
| 940 DISALLOW_COPY_AND_ASSIGN(HeapObjectsSet); |
| 941 }; |
| 942 |
| 943 |
| 925 class HeapSnapshotGenerator { | 944 class HeapSnapshotGenerator { |
| 926 public: | 945 public: |
| 927 class SnapshotFillerInterface { | 946 class SnapshotFillerInterface { |
| 928 public: | 947 public: |
| 929 virtual ~SnapshotFillerInterface() { } | 948 virtual ~SnapshotFillerInterface() { } |
| 930 virtual HeapEntry* AddEntry(HeapObject* obj) = 0; | 949 virtual HeapEntry* AddEntry(HeapObject* obj) = 0; |
| 931 virtual void SetElementReference(HeapObject* parent_obj, | 950 virtual void SetIndexedReference(HeapGraphEdge::Type type, |
| 951 HeapObject* parent_obj, |
| 932 HeapEntry* parent_entry, | 952 HeapEntry* parent_entry, |
| 933 int index, | 953 int index, |
| 934 Object* child_obj, | 954 Object* child_obj, |
| 935 HeapEntry* child_entry) = 0; | 955 HeapEntry* child_entry) = 0; |
| 936 virtual void SetNamedReference(HeapGraphEdge::Type type, | 956 virtual void SetNamedReference(HeapGraphEdge::Type type, |
| 937 HeapObject* parent_obj, | 957 HeapObject* parent_obj, |
| 938 HeapEntry* parent_entry, | 958 HeapEntry* parent_entry, |
| 939 const char* reference_name, | 959 const char* reference_name, |
| 940 Object* child_obj, | 960 Object* child_obj, |
| 941 HeapEntry* child_entry) = 0; | 961 HeapEntry* child_entry) = 0; |
| 942 virtual void SetRootReference(Object* child_obj, | 962 virtual void SetRootGcRootsReference() = 0; |
| 943 HeapEntry* child_entry) = 0; | 963 virtual void SetRootShortcutReference(Object* child_obj, |
| 964 HeapEntry* child_entry) = 0; |
| 965 virtual void SetStrongRootReference(Object* child_obj, |
| 966 HeapEntry* child_entry) = 0; |
| 944 }; | 967 }; |
| 945 | 968 |
| 946 explicit HeapSnapshotGenerator(HeapSnapshot* snapshot); | 969 explicit HeapSnapshotGenerator(HeapSnapshot* snapshot); |
| 947 void GenerateSnapshot(); | 970 void GenerateSnapshot(); |
| 948 | 971 |
| 949 private: | 972 private: |
| 950 HeapEntry* GetEntry(Object* obj); | 973 HeapEntry* GetEntry(Object* obj); |
| 951 void ExtractReferences(HeapObject* obj); | 974 void ExtractReferences(HeapObject* obj); |
| 952 void ExtractClosureReferences(JSObject* js_obj, HeapEntry* entry); | 975 void ExtractClosureReferences(JSObject* js_obj, HeapEntry* entry); |
| 953 void ExtractPropertyReferences(JSObject* js_obj, HeapEntry* entry); | 976 void ExtractPropertyReferences(JSObject* js_obj, HeapEntry* entry); |
| 954 void ExtractElementReferences(JSObject* js_obj, HeapEntry* entry); | 977 void ExtractElementReferences(JSObject* js_obj, HeapEntry* entry); |
| 955 void ExtractInternalReferences(JSObject* js_obj, HeapEntry* entry); | 978 void ExtractInternalReferences(JSObject* js_obj, HeapEntry* entry); |
| 956 void SetClosureReference(HeapObject* parent_obj, | 979 void SetClosureReference(HeapObject* parent_obj, |
| 957 HeapEntry* parent, | 980 HeapEntry* parent, |
| 958 String* reference_name, | 981 String* reference_name, |
| 959 Object* child); | 982 Object* child); |
| 960 void SetElementReference(HeapObject* parent_obj, | 983 void SetElementReference(HeapObject* parent_obj, |
| 961 HeapEntry* parent, | 984 HeapEntry* parent, |
| 962 int index, | 985 int index, |
| 963 Object* child); | 986 Object* child); |
| 964 void SetInternalReference(HeapObject* parent_obj, | 987 void SetInternalReference(HeapObject* parent_obj, |
| 965 HeapEntry* parent, | 988 HeapEntry* parent, |
| 966 const char* reference_name, | 989 const char* reference_name, |
| 967 Object* child); | 990 Object* child); |
| 968 void SetInternalReference(HeapObject* parent_obj, | 991 void SetInternalReference(HeapObject* parent_obj, |
| 969 HeapEntry* parent, | 992 HeapEntry* parent, |
| 970 int index, | 993 int index, |
| 971 Object* child); | 994 Object* child); |
| 995 void SetHiddenReference(HeapObject* parent_obj, |
| 996 HeapEntry* parent, |
| 997 int index, |
| 998 Object* child); |
| 972 void SetPropertyReference(HeapObject* parent_obj, | 999 void SetPropertyReference(HeapObject* parent_obj, |
| 973 HeapEntry* parent, | 1000 HeapEntry* parent, |
| 974 String* reference_name, | 1001 String* reference_name, |
| 975 Object* child); | 1002 Object* child); |
| 976 void SetRootReference(Object* child); | 1003 void SetPropertyShortcutReference(HeapObject* parent_obj, |
| 1004 HeapEntry* parent, |
| 1005 String* reference_name, |
| 1006 Object* child); |
| 1007 void SetRootShortcutReference(Object* child); |
| 1008 void SetRootGcRootsReference(); |
| 1009 void SetGcRootsReference(Object* child); |
| 977 | 1010 |
| 978 HeapSnapshot* snapshot_; | 1011 HeapSnapshot* snapshot_; |
| 979 HeapSnapshotsCollection* collection_; | 1012 HeapSnapshotsCollection* collection_; |
| 980 // Mapping from HeapObject* pointers to HeapEntry* pointers. | 1013 // Mapping from HeapObject* pointers to HeapEntry* pointers. |
| 981 HeapEntriesMap entries_; | 1014 HeapEntriesMap entries_; |
| 982 SnapshotFillerInterface* filler_; | 1015 SnapshotFillerInterface* filler_; |
| 1016 // Used during references extraction to mark heap objects that |
| 1017 // are references via non-hidden properties. |
| 1018 HeapObjectsSet known_references_; |
| 983 | 1019 |
| 984 friend class IndexedReferencesExtractor; | 1020 friend class IndexedReferencesExtractor; |
| 1021 friend class RootsReferencesExtractor; |
| 985 | 1022 |
| 986 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotGenerator); | 1023 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotGenerator); |
| 987 }; | 1024 }; |
| 988 | 1025 |
| 989 class OutputStreamWriter; | 1026 class OutputStreamWriter; |
| 990 | 1027 |
| 991 class HeapSnapshotJSONSerializer { | 1028 class HeapSnapshotJSONSerializer { |
| 992 public: | 1029 public: |
| 993 explicit HeapSnapshotJSONSerializer(HeapSnapshot* snapshot) | 1030 explicit HeapSnapshotJSONSerializer(HeapSnapshot* snapshot) |
| 994 : snapshot_(snapshot), | 1031 : snapshot_(snapshot), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 friend class HeapSnapshotJSONSerializerIterator; | 1070 friend class HeapSnapshotJSONSerializerIterator; |
| 1034 | 1071 |
| 1035 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); | 1072 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); |
| 1036 }; | 1073 }; |
| 1037 | 1074 |
| 1038 } } // namespace v8::internal | 1075 } } // namespace v8::internal |
| 1039 | 1076 |
| 1040 #endif // ENABLE_LOGGING_AND_PROFILING | 1077 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1041 | 1078 |
| 1042 #endif // V8_PROFILE_GENERATOR_H_ | 1079 #endif // V8_PROFILE_GENERATOR_H_ |
| OLD | NEW |