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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 CodeMap code_map_; | 439 CodeMap code_map_; |
440 CodeEntry* program_entry_; | 440 CodeEntry* program_entry_; |
441 CodeEntry* gc_entry_; | 441 CodeEntry* gc_entry_; |
442 SampleRateCalculator sample_rate_calc_; | 442 SampleRateCalculator sample_rate_calc_; |
443 | 443 |
444 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 444 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
445 }; | 445 }; |
446 | 446 |
447 | 447 |
448 class HeapEntry; | 448 class HeapEntry; |
449 class HeapSnapshot; | |
449 | 450 |
450 class HeapGraphEdge BASE_EMBEDDED { | 451 class HeapGraphEdge BASE_EMBEDDED { |
451 public: | 452 public: |
452 enum Type { | 453 enum Type { |
453 kContextVariable = v8::HeapGraphEdge::kContextVariable, | 454 kContextVariable = v8::HeapGraphEdge::kContextVariable, |
454 kElement = v8::HeapGraphEdge::kElement, | 455 kElement = v8::HeapGraphEdge::kElement, |
455 kProperty = v8::HeapGraphEdge::kProperty, | 456 kProperty = v8::HeapGraphEdge::kProperty, |
456 kInternal = v8::HeapGraphEdge::kInternal, | 457 kInternal = v8::HeapGraphEdge::kInternal, |
457 kHidden = v8::HeapGraphEdge::kHidden, | 458 kHidden = v8::HeapGraphEdge::kHidden, |
458 kShortcut = v8::HeapGraphEdge::kShortcut, | 459 kShortcut = v8::HeapGraphEdge::kShortcut, |
459 kWeak = v8::HeapGraphEdge::kWeak | 460 kWeak = v8::HeapGraphEdge::kWeak |
460 }; | 461 }; |
461 | 462 |
462 HeapGraphEdge() { } | 463 HeapGraphEdge() { } |
463 void Init(int child_index, Type type, const char* name, HeapEntry* to); | 464 HeapGraphEdge(Type type, const char* name, int from, int to); |
464 void Init(int child_index, Type type, int index, HeapEntry* to); | 465 HeapGraphEdge(Type type, int index, int from, int to); |
465 void Init(int child_index, int index, HeapEntry* to); | 466 void ReplaceToIndexWithEntry(HeapSnapshot* snapshot); |
466 | 467 |
467 Type type() const { return static_cast<Type>(type_); } | 468 Type type() const { return static_cast<Type>(type_); } |
468 int index() const { | 469 int index() const { |
469 ASSERT(type_ == kElement || type_ == kHidden || type_ == kWeak); | 470 ASSERT(type_ == kElement || type_ == kHidden || type_ == kWeak); |
470 return index_; | 471 return index_; |
471 } | 472 } |
472 const char* name() const { | 473 const char* name() const { |
473 ASSERT(type_ == kContextVariable | 474 ASSERT(type_ == kContextVariable |
474 || type_ == kProperty | 475 || type_ == kProperty |
475 || type_ == kInternal | 476 || type_ == kInternal |
476 || type_ == kShortcut); | 477 || type_ == kShortcut); |
477 return name_; | 478 return name_; |
478 } | 479 } |
479 HeapEntry* to() const { return to_; } | |
480 INLINE(HeapEntry* from() const); | 480 INLINE(HeapEntry* from() const); |
481 HeapEntry* to() const { return to_entry_; } | |
481 | 482 |
482 private: | 483 private: |
483 int child_index_ : 29; | 484 INLINE(HeapSnapshot* snapshot() const); |
485 | |
484 unsigned type_ : 3; | 486 unsigned type_ : 3; |
487 int from_index_ : 29; | |
488 union { | |
489 // During entries population |to_| is used for storing the index, | |
mnaganov (inactive)
2012/05/08 12:05:20
nit: |to_| -> |to_index_|
alexeif
2012/05/09 12:38:07
Done.
| |
490 // afterwards it is replaced with a pointer to the entry. | |
491 int to_index_; | |
492 HeapEntry* to_entry_; | |
493 }; | |
485 union { | 494 union { |
486 int index_; | 495 int index_; |
487 const char* name_; | 496 const char* name_; |
488 }; | 497 }; |
489 HeapEntry* to_; | |
490 | |
491 DISALLOW_COPY_AND_ASSIGN(HeapGraphEdge); | |
492 }; | 498 }; |
493 | 499 |
494 | 500 |
495 class HeapSnapshot; | |
496 | |
497 // HeapEntry instances represent an entity from the heap (or a special | 501 // HeapEntry instances represent an entity from the heap (or a special |
498 // virtual node, e.g. root). To make heap snapshots more compact, | 502 // virtual node, e.g. root). |
499 // HeapEntries has a special memory layout (no Vectors or Lists used): | |
500 // | |
501 // +-----------------+ | |
502 // HeapEntry | |
503 // +-----------------+ | |
504 // HeapGraphEdge | | |
505 // ... } children_count | |
506 // HeapGraphEdge | | |
507 // +-----------------+ | |
508 // HeapGraphEdge* | | |
509 // ... } retainers_count | |
510 // HeapGraphEdge* | | |
511 // +-----------------+ | |
512 // | |
513 // In a HeapSnapshot, all entries are hand-allocated in a continuous array | |
514 // of raw bytes. | |
515 // | |
516 class HeapEntry BASE_EMBEDDED { | 503 class HeapEntry BASE_EMBEDDED { |
517 public: | 504 public: |
518 enum Type { | 505 enum Type { |
519 kHidden = v8::HeapGraphNode::kHidden, | 506 kHidden = v8::HeapGraphNode::kHidden, |
520 kArray = v8::HeapGraphNode::kArray, | 507 kArray = v8::HeapGraphNode::kArray, |
521 kString = v8::HeapGraphNode::kString, | 508 kString = v8::HeapGraphNode::kString, |
522 kObject = v8::HeapGraphNode::kObject, | 509 kObject = v8::HeapGraphNode::kObject, |
523 kCode = v8::HeapGraphNode::kCode, | 510 kCode = v8::HeapGraphNode::kCode, |
524 kClosure = v8::HeapGraphNode::kClosure, | 511 kClosure = v8::HeapGraphNode::kClosure, |
525 kRegExp = v8::HeapGraphNode::kRegExp, | 512 kRegExp = v8::HeapGraphNode::kRegExp, |
526 kHeapNumber = v8::HeapGraphNode::kHeapNumber, | 513 kHeapNumber = v8::HeapGraphNode::kHeapNumber, |
527 kNative = v8::HeapGraphNode::kNative, | 514 kNative = v8::HeapGraphNode::kNative, |
528 kSynthetic = v8::HeapGraphNode::kSynthetic | 515 kSynthetic = v8::HeapGraphNode::kSynthetic |
529 }; | 516 }; |
517 static const int kNoEntry; | |
530 | 518 |
531 HeapEntry() { } | 519 HeapEntry() { } |
532 void Init(HeapSnapshot* snapshot, | 520 HeapEntry(HeapSnapshot* snapshot, |
533 Type type, | 521 Type type, |
534 const char* name, | 522 const char* name, |
535 SnapshotObjectId id, | 523 SnapshotObjectId id, |
536 int self_size, | 524 int self_size); |
537 int children_count, | |
538 int retainers_count); | |
539 | 525 |
540 HeapSnapshot* snapshot() { return snapshot_; } | 526 HeapSnapshot* snapshot() { return snapshot_; } |
541 Type type() { return static_cast<Type>(type_); } | 527 Type type() { return static_cast<Type>(type_); } |
542 const char* name() { return name_; } | 528 const char* name() { return name_; } |
543 void set_name(const char* name) { name_ = name; } | 529 void set_name(const char* name) { name_ = name; } |
544 inline SnapshotObjectId id() { return id_; } | 530 inline SnapshotObjectId id() { return id_; } |
545 int self_size() { return self_size_; } | 531 int self_size() { return self_size_; } |
546 int retained_size() { return retained_size_; } | 532 int retained_size() { return retained_size_; } |
547 void add_retained_size(int size) { retained_size_ += size; } | 533 void add_retained_size(int size) { retained_size_ += size; } |
548 void set_retained_size(int value) { retained_size_ = value; } | 534 void set_retained_size(int size) { retained_size_ = size; } |
549 int ordered_index() { return ordered_index_; } | 535 INLINE(int index() const); |
550 void set_ordered_index(int value) { ordered_index_ = value; } | 536 int postorder_index() { return postorder_index_; } |
551 int entry_index() { return entry_index_; } | 537 void set_postorder_index(int value) { postorder_index_ = value; } |
552 void set_entry_index(int value) { entry_index_ = value; } | 538 int children_count() const { return children_count_; } |
553 | 539 INLINE(int set_children_index(int index)); |
554 Vector<HeapGraphEdge> children() { | 540 INLINE(int set_retainers_index(int index)); |
555 return Vector<HeapGraphEdge>(children_arr(), children_count_); } | 541 void add_child(HeapGraphEdge* edge) { |
542 children_arr()[children_count_++] = edge; | |
543 } | |
544 void add_retainer(HeapGraphEdge* edge) { | |
545 retainers_arr()[retainers_count_++] = edge; | |
546 } | |
547 Vector<HeapGraphEdge*> children() { | |
548 return Vector<HeapGraphEdge*>(children_arr(), children_count_); } | |
556 Vector<HeapGraphEdge*> retainers() { | 549 Vector<HeapGraphEdge*> retainers() { |
557 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } | 550 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } |
558 HeapEntry* dominator() { return dominator_; } | 551 INLINE(HeapEntry* dominator() const); |
559 void set_dominator(HeapEntry* entry) { | 552 void set_dominator(HeapEntry* entry) { |
560 ASSERT(entry != NULL); | 553 ASSERT(entry != NULL); |
561 dominator_ = entry; | 554 dominator_ = entry->index(); |
562 } | 555 } |
563 void clear_paint() { painted_ = false; } | 556 void clear_paint() { painted_ = false; } |
564 bool painted() { return painted_; } | 557 bool painted() { return painted_; } |
565 void paint() { painted_ = true; } | 558 void paint() { painted_ = true; } |
566 bool user_reachable() { return user_reachable_; } | 559 bool user_reachable() { return user_reachable_; } |
567 void set_user_reachable() { user_reachable_ = true; } | 560 void set_user_reachable() { user_reachable_ = true; } |
568 | 561 |
569 void SetIndexedReference(HeapGraphEdge::Type type, | 562 void SetIndexedReference( |
570 int child_index, | 563 HeapGraphEdge::Type type, int index, HeapEntry* entry); |
571 int index, | 564 void SetNamedReference( |
572 HeapEntry* entry, | 565 HeapGraphEdge::Type type, const char* name, HeapEntry* entry); |
573 int retainer_index); | |
574 void SetNamedReference(HeapGraphEdge::Type type, | |
575 int child_index, | |
576 const char* name, | |
577 HeapEntry* entry, | |
578 int retainer_index); | |
579 void SetUnidirElementReference(int child_index, int index, HeapEntry* entry); | |
580 | |
581 size_t EntrySize() { | |
582 return EntriesSize(1, children_count_, retainers_count_); | |
583 } | |
584 | 566 |
585 void Print( | 567 void Print( |
586 const char* prefix, const char* edge_name, int max_depth, int indent); | 568 const char* prefix, const char* edge_name, int max_depth, int indent); |
587 | 569 |
588 Handle<HeapObject> GetHeapObject(); | 570 Handle<HeapObject> GetHeapObject(); |
589 | 571 |
590 static size_t EntriesSize(int entries_count, | |
591 int children_count, | |
592 int retainers_count); | |
593 | |
594 private: | 572 private: |
595 HeapGraphEdge* children_arr() { | 573 INLINE(HeapGraphEdge** children_arr()); |
596 return reinterpret_cast<HeapGraphEdge*>(this + 1); | 574 INLINE(HeapGraphEdge** retainers_arr()); |
597 } | |
598 HeapGraphEdge** retainers_arr() { | |
599 return reinterpret_cast<HeapGraphEdge**>(children_arr() + children_count_); | |
600 } | |
601 const char* TypeAsString(); | 575 const char* TypeAsString(); |
602 | 576 |
603 unsigned painted_: 1; | 577 unsigned painted_: 1; |
604 unsigned user_reachable_: 1; | 578 unsigned user_reachable_: 1; |
579 int dominator_: 30; | |
605 unsigned type_: 4; | 580 unsigned type_: 4; |
606 int children_count_: 26; | 581 int retainers_count_: 28; |
607 int retainers_count_; | 582 int retainers_index_; |
583 int children_count_; | |
584 int children_index_; | |
608 int self_size_; | 585 int self_size_; |
609 union { | 586 union { |
610 int ordered_index_; // Used during dominator tree building. | 587 int postorder_index_; // Used during dominator tree building. |
611 int retained_size_; // At that moment, there is no retained size yet. | 588 int retained_size_; // At that moment, there is no retained size yet. |
612 }; | 589 }; |
613 int entry_index_; | |
614 SnapshotObjectId id_; | 590 SnapshotObjectId id_; |
615 HeapEntry* dominator_; | |
616 HeapSnapshot* snapshot_; | 591 HeapSnapshot* snapshot_; |
617 const char* name_; | 592 const char* name_; |
618 | |
619 DISALLOW_COPY_AND_ASSIGN(HeapEntry); | |
620 }; | 593 }; |
621 | 594 |
622 | 595 |
623 class HeapSnapshotsCollection; | 596 class HeapSnapshotsCollection; |
624 | 597 |
625 // HeapSnapshot represents a single heap snapshot. It is stored in | 598 // HeapSnapshot represents a single heap snapshot. It is stored in |
626 // HeapSnapshotsCollection, which is also a factory for | 599 // HeapSnapshotsCollection, which is also a factory for |
627 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap | 600 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap |
628 // to be able to return them even if they were collected. | 601 // to be able to return them even if they were collected. |
629 // HeapSnapshotGenerator fills in a HeapSnapshot. | 602 // HeapSnapshotGenerator fills in a HeapSnapshot. |
630 class HeapSnapshot { | 603 class HeapSnapshot { |
631 public: | 604 public: |
632 enum Type { | 605 enum Type { |
633 kFull = v8::HeapSnapshot::kFull | 606 kFull = v8::HeapSnapshot::kFull |
634 }; | 607 }; |
635 | 608 |
636 HeapSnapshot(HeapSnapshotsCollection* collection, | 609 HeapSnapshot(HeapSnapshotsCollection* collection, |
637 Type type, | 610 Type type, |
638 const char* title, | 611 const char* title, |
639 unsigned uid); | 612 unsigned uid); |
640 ~HeapSnapshot(); | |
641 void Delete(); | 613 void Delete(); |
642 | 614 |
643 HeapSnapshotsCollection* collection() { return collection_; } | 615 HeapSnapshotsCollection* collection() { return collection_; } |
644 Type type() { return type_; } | 616 Type type() { return type_; } |
645 const char* title() { return title_; } | 617 const char* title() { return title_; } |
646 unsigned uid() { return uid_; } | 618 unsigned uid() { return uid_; } |
647 HeapEntry* root() { return root_entry_; } | 619 size_t RawSnapshotSize() const; |
648 HeapEntry* gc_roots() { return gc_roots_entry_; } | 620 HeapEntry* root() { return &entries_[root_entry_]; } |
649 HeapEntry* natives_root() { return natives_root_entry_; } | 621 HeapEntry* gc_roots() { return &entries_[gc_roots_entry_]; } |
650 HeapEntry* gc_subroot(int index) { return gc_subroot_entries_[index]; } | 622 HeapEntry* natives_root() { return &entries_[natives_root_entry_]; } |
651 List<HeapEntry*>* entries() { return &entries_; } | 623 HeapEntry* gc_subroot(int index) { |
652 size_t raw_entries_size() { return raw_entries_size_; } | 624 return &entries_[gc_subroot_entries_[index]]; |
653 int number_of_edges() { return number_of_edges_; } | 625 } |
626 List<HeapEntry>& entries() { return entries_; } | |
627 List<HeapGraphEdge>& edges() { return edges_; } | |
628 List<HeapGraphEdge*>& children() { return children_; } | |
629 List<HeapGraphEdge*>& retainers() { return retainers_; } | |
654 void RememberLastJSObjectId(); | 630 void RememberLastJSObjectId(); |
655 SnapshotObjectId max_snapshot_js_object_id() const { | 631 SnapshotObjectId max_snapshot_js_object_id() const { |
656 return max_snapshot_js_object_id_; | 632 return max_snapshot_js_object_id_; |
657 } | 633 } |
658 | 634 |
659 void AllocateEntries( | |
660 int entries_count, int children_count, int retainers_count); | |
661 HeapEntry* AddEntry(HeapEntry::Type type, | 635 HeapEntry* AddEntry(HeapEntry::Type type, |
662 const char* name, | 636 const char* name, |
663 SnapshotObjectId id, | 637 SnapshotObjectId id, |
664 int size, | 638 int size); |
665 int children_count, | 639 HeapEntry* AddRootEntry(); |
666 int retainers_count); | 640 HeapEntry* AddGcRootsEntry(); |
667 HeapEntry* AddRootEntry(int children_count); | 641 HeapEntry* AddGcSubrootEntry(int tag); |
668 HeapEntry* AddGcRootsEntry(int children_count, int retainers_count); | 642 HeapEntry* AddNativesRootEntry(); |
669 HeapEntry* AddGcSubrootEntry(int tag, | |
670 int children_count, | |
671 int retainers_count); | |
672 HeapEntry* AddNativesRootEntry(int children_count, int retainers_count); | |
673 void ClearPaint(); | 643 void ClearPaint(); |
674 HeapEntry* GetEntryById(SnapshotObjectId id); | 644 HeapEntry* GetEntryById(SnapshotObjectId id); |
675 List<HeapEntry*>* GetSortedEntriesList(); | 645 List<HeapEntry*>* GetSortedEntriesList(); |
676 void SetDominatorsToSelf(); | 646 void SetDominatorsToSelf(); |
647 void FillChildrenAndRetainers(); | |
677 | 648 |
678 void Print(int max_depth); | 649 void Print(int max_depth); |
679 void PrintEntriesSize(); | 650 void PrintEntriesSize(); |
680 | 651 |
681 private: | 652 private: |
682 HeapEntry* GetNextEntryToInit(); | |
683 | |
684 HeapSnapshotsCollection* collection_; | 653 HeapSnapshotsCollection* collection_; |
685 Type type_; | 654 Type type_; |
686 const char* title_; | 655 const char* title_; |
687 unsigned uid_; | 656 unsigned uid_; |
688 HeapEntry* root_entry_; | 657 int root_entry_; |
yurys
2012/05/08 14:55:59
I'd rename these fields from *_entry_ to *_index_
alexeif
2012/05/09 12:38:07
Done.
| |
689 HeapEntry* gc_roots_entry_; | 658 int gc_roots_entry_; |
690 HeapEntry* natives_root_entry_; | 659 int natives_root_entry_; |
691 HeapEntry* gc_subroot_entries_[VisitorSynchronization::kNumberOfSyncTags]; | 660 int gc_subroot_entries_[VisitorSynchronization::kNumberOfSyncTags]; |
692 char* raw_entries_; | 661 List<HeapEntry> entries_; |
693 List<HeapEntry*> entries_; | 662 List<HeapGraphEdge> edges_; |
663 List<HeapGraphEdge*> children_; | |
664 List<HeapGraphEdge*> retainers_; | |
694 List<HeapEntry*> sorted_entries_; | 665 List<HeapEntry*> sorted_entries_; |
695 size_t raw_entries_size_; | |
696 int number_of_edges_; | |
697 SnapshotObjectId max_snapshot_js_object_id_; | 666 SnapshotObjectId max_snapshot_js_object_id_; |
698 | 667 |
699 friend class HeapSnapshotTester; | 668 friend class HeapSnapshotTester; |
700 | 669 |
701 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); | 670 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); |
702 }; | 671 }; |
703 | 672 |
704 | 673 |
705 class HeapObjectsMap { | 674 class HeapObjectsMap { |
706 public: | 675 public: |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 | 790 |
822 // A typedef for referencing anything that can be snapshotted living | 791 // A typedef for referencing anything that can be snapshotted living |
823 // in any kind of heap memory. | 792 // in any kind of heap memory. |
824 typedef void* HeapThing; | 793 typedef void* HeapThing; |
825 | 794 |
826 | 795 |
827 // An interface that creates HeapEntries by HeapThings. | 796 // An interface that creates HeapEntries by HeapThings. |
828 class HeapEntriesAllocator { | 797 class HeapEntriesAllocator { |
829 public: | 798 public: |
830 virtual ~HeapEntriesAllocator() { } | 799 virtual ~HeapEntriesAllocator() { } |
831 virtual HeapEntry* AllocateEntry( | 800 virtual HeapEntry* AllocateEntry(HeapThing ptr) = 0; |
832 HeapThing ptr, int children_count, int retainers_count) = 0; | |
833 }; | 801 }; |
834 | 802 |
835 | 803 |
836 // The HeapEntriesMap instance is used to track a mapping between | 804 // The HeapEntriesMap instance is used to track a mapping between |
837 // real heap objects and their representations in heap snapshots. | 805 // real heap objects and their representations in heap snapshots. |
838 class HeapEntriesMap { | 806 class HeapEntriesMap { |
839 public: | 807 public: |
840 HeapEntriesMap(); | 808 HeapEntriesMap(); |
841 ~HeapEntriesMap(); | |
842 | 809 |
843 void AllocateEntries(HeapThing root_object); | 810 int Map(HeapThing thing); |
844 HeapEntry* Map(HeapThing thing); | 811 void Pair(HeapThing thing, int entry); |
845 void Pair(HeapThing thing, HeapEntriesAllocator* allocator, HeapEntry* entry); | |
846 void CountReference(HeapThing from, HeapThing to, | |
847 int* prev_children_count = NULL, | |
848 int* prev_retainers_count = NULL); | |
849 | |
850 int entries_count() { return entries_count_; } | |
851 int total_children_count() { return total_children_count_; } | |
852 int total_retainers_count() { return total_retainers_count_; } | |
853 | |
854 static HeapEntry* const kHeapEntryPlaceholder; | |
855 | 812 |
856 private: | 813 private: |
857 struct EntryInfo { | |
858 EntryInfo(HeapEntry* entry, HeapEntriesAllocator* allocator) | |
859 : entry(entry), | |
860 allocator(allocator), | |
861 children_count(0), | |
862 retainers_count(0) { | |
863 } | |
864 HeapEntry* entry; | |
865 HeapEntriesAllocator* allocator; | |
866 int children_count; | |
867 int retainers_count; | |
868 }; | |
869 | |
870 static inline void AllocateHeapEntryForMapEntry(HashMap::Entry* map_entry); | |
871 | |
872 static uint32_t Hash(HeapThing thing) { | 814 static uint32_t Hash(HeapThing thing) { |
873 return ComputeIntegerHash( | 815 return ComputeIntegerHash( |
874 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(thing)), | 816 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(thing)), |
875 v8::internal::kZeroHashSeed); | 817 v8::internal::kZeroHashSeed); |
876 } | 818 } |
877 static bool HeapThingsMatch(HeapThing key1, HeapThing key2) { | 819 static bool HeapThingsMatch(HeapThing key1, HeapThing key2) { |
878 return key1 == key2; | 820 return key1 == key2; |
879 } | 821 } |
880 | 822 |
881 HashMap entries_; | 823 HashMap entries_; |
882 int entries_count_; | |
883 int total_children_count_; | |
884 int total_retainers_count_; | |
885 | 824 |
886 friend class HeapObjectsSet; | 825 friend class HeapObjectsSet; |
887 | 826 |
888 DISALLOW_COPY_AND_ASSIGN(HeapEntriesMap); | 827 DISALLOW_COPY_AND_ASSIGN(HeapEntriesMap); |
889 }; | 828 }; |
890 | 829 |
891 | 830 |
892 class HeapObjectsSet { | 831 class HeapObjectsSet { |
893 public: | 832 public: |
894 HeapObjectsSet(); | 833 HeapObjectsSet(); |
(...skipping 14 matching lines...) Expand all Loading... | |
909 // An interface used to populate a snapshot with nodes and edges. | 848 // An interface used to populate a snapshot with nodes and edges. |
910 class SnapshotFillerInterface { | 849 class SnapshotFillerInterface { |
911 public: | 850 public: |
912 virtual ~SnapshotFillerInterface() { } | 851 virtual ~SnapshotFillerInterface() { } |
913 virtual HeapEntry* AddEntry(HeapThing ptr, | 852 virtual HeapEntry* AddEntry(HeapThing ptr, |
914 HeapEntriesAllocator* allocator) = 0; | 853 HeapEntriesAllocator* allocator) = 0; |
915 virtual HeapEntry* FindEntry(HeapThing ptr) = 0; | 854 virtual HeapEntry* FindEntry(HeapThing ptr) = 0; |
916 virtual HeapEntry* FindOrAddEntry(HeapThing ptr, | 855 virtual HeapEntry* FindOrAddEntry(HeapThing ptr, |
917 HeapEntriesAllocator* allocator) = 0; | 856 HeapEntriesAllocator* allocator) = 0; |
918 virtual void SetIndexedReference(HeapGraphEdge::Type type, | 857 virtual void SetIndexedReference(HeapGraphEdge::Type type, |
919 HeapThing parent_ptr, | 858 int parent_entry, |
920 HeapEntry* parent_entry, | |
921 int index, | 859 int index, |
922 HeapThing child_ptr, | |
923 HeapEntry* child_entry) = 0; | 860 HeapEntry* child_entry) = 0; |
924 virtual void SetIndexedAutoIndexReference(HeapGraphEdge::Type type, | 861 virtual void SetIndexedAutoIndexReference(HeapGraphEdge::Type type, |
925 HeapThing parent_ptr, | 862 int parent_entry, |
926 HeapEntry* parent_entry, | |
927 HeapThing child_ptr, | |
928 HeapEntry* child_entry) = 0; | 863 HeapEntry* child_entry) = 0; |
929 virtual void SetNamedReference(HeapGraphEdge::Type type, | 864 virtual void SetNamedReference(HeapGraphEdge::Type type, |
930 HeapThing parent_ptr, | 865 int parent_entry, |
931 HeapEntry* parent_entry, | |
932 const char* reference_name, | 866 const char* reference_name, |
933 HeapThing child_ptr, | |
934 HeapEntry* child_entry) = 0; | 867 HeapEntry* child_entry) = 0; |
935 virtual void SetNamedAutoIndexReference(HeapGraphEdge::Type type, | 868 virtual void SetNamedAutoIndexReference(HeapGraphEdge::Type type, |
936 HeapThing parent_ptr, | 869 int parent_entry, |
937 HeapEntry* parent_entry, | |
938 HeapThing child_ptr, | |
939 HeapEntry* child_entry) = 0; | 870 HeapEntry* child_entry) = 0; |
940 }; | 871 }; |
941 | 872 |
942 | 873 |
943 class SnapshottingProgressReportingInterface { | 874 class SnapshottingProgressReportingInterface { |
944 public: | 875 public: |
945 virtual ~SnapshottingProgressReportingInterface() { } | 876 virtual ~SnapshottingProgressReportingInterface() { } |
946 virtual void ProgressStep() = 0; | 877 virtual void ProgressStep() = 0; |
947 virtual bool ProgressReport(bool force) = 0; | 878 virtual bool ProgressReport(bool force) = 0; |
948 }; | 879 }; |
949 | 880 |
950 | 881 |
951 // An implementation of V8 heap graph extractor. | 882 // An implementation of V8 heap graph extractor. |
952 class V8HeapExplorer : public HeapEntriesAllocator { | 883 class V8HeapExplorer : public HeapEntriesAllocator { |
953 public: | 884 public: |
954 V8HeapExplorer(HeapSnapshot* snapshot, | 885 V8HeapExplorer(HeapSnapshot* snapshot, |
955 SnapshottingProgressReportingInterface* progress); | 886 SnapshottingProgressReportingInterface* progress); |
956 virtual ~V8HeapExplorer(); | 887 virtual ~V8HeapExplorer(); |
957 virtual HeapEntry* AllocateEntry( | 888 virtual HeapEntry* AllocateEntry(HeapThing ptr); |
958 HeapThing ptr, int children_count, int retainers_count); | |
959 void AddRootEntries(SnapshotFillerInterface* filler); | 889 void AddRootEntries(SnapshotFillerInterface* filler); |
960 int EstimateObjectsCount(HeapIterator* iterator); | 890 int EstimateObjectsCount(HeapIterator* iterator); |
961 bool IterateAndExtractReferences(SnapshotFillerInterface* filler); | 891 bool IterateAndExtractReferences(SnapshotFillerInterface* filler); |
962 bool IterateAndSetObjectNames(SnapshotFillerInterface* filler); | 892 bool IterateAndSetObjectNames(SnapshotFillerInterface* filler); |
963 void TagGlobalObjects(); | 893 void TagGlobalObjects(); |
964 | 894 |
965 static String* GetConstructorName(JSObject* object); | 895 static String* GetConstructorName(JSObject* object); |
966 | 896 |
967 static HeapObject* const kInternalRootObject; | 897 static HeapObject* const kInternalRootObject; |
968 | 898 |
969 private: | 899 private: |
970 HeapEntry* AddEntry( | 900 HeapEntry* AddEntry(HeapObject* object); |
971 HeapObject* object, int children_count, int retainers_count); | |
972 HeapEntry* AddEntry(HeapObject* object, | 901 HeapEntry* AddEntry(HeapObject* object, |
973 HeapEntry::Type type, | 902 HeapEntry::Type type, |
974 const char* name, | 903 const char* name); |
975 int children_count, | |
976 int retainers_count); | |
977 const char* GetSystemEntryName(HeapObject* object); | 904 const char* GetSystemEntryName(HeapObject* object); |
978 | 905 |
979 void ExtractReferences(HeapObject* obj); | 906 void ExtractReferences(HeapObject* obj); |
980 void ExtractJSGlobalProxyReferences(JSGlobalProxy* proxy); | 907 void ExtractJSGlobalProxyReferences(JSGlobalProxy* proxy); |
981 void ExtractJSObjectReferences(HeapEntry* entry, JSObject* js_obj); | 908 void ExtractJSObjectReferences(int entry, JSObject* js_obj); |
982 void ExtractStringReferences(HeapEntry* entry, String* obj); | 909 void ExtractStringReferences(int entry, String* obj); |
983 void ExtractContextReferences(HeapEntry* entry, Context* context); | 910 void ExtractContextReferences(int entry, Context* context); |
984 void ExtractMapReferences(HeapEntry* entry, Map* map); | 911 void ExtractMapReferences(int entry, Map* map); |
985 void ExtractSharedFunctionInfoReferences(HeapEntry* entry, | 912 void ExtractSharedFunctionInfoReferences(int entry, |
986 SharedFunctionInfo* shared); | 913 SharedFunctionInfo* shared); |
987 void ExtractScriptReferences(HeapEntry* entry, Script* script); | 914 void ExtractScriptReferences(int entry, Script* script); |
988 void ExtractCodeCacheReferences(HeapEntry* entry, CodeCache* code_cache); | 915 void ExtractCodeCacheReferences(int entry, CodeCache* code_cache); |
989 void ExtractCodeReferences(HeapEntry* entry, Code* code); | 916 void ExtractCodeReferences(int entry, Code* code); |
990 void ExtractJSGlobalPropertyCellReferences(HeapEntry* entry, | 917 void ExtractJSGlobalPropertyCellReferences(int entry, |
991 JSGlobalPropertyCell* cell); | 918 JSGlobalPropertyCell* cell); |
992 void ExtractClosureReferences(JSObject* js_obj, HeapEntry* entry); | 919 void ExtractClosureReferences(JSObject* js_obj, int entry); |
993 void ExtractPropertyReferences(JSObject* js_obj, HeapEntry* entry); | 920 void ExtractPropertyReferences(JSObject* js_obj, int entry); |
994 void ExtractElementReferences(JSObject* js_obj, HeapEntry* entry); | 921 void ExtractElementReferences(JSObject* js_obj, int entry); |
995 void ExtractInternalReferences(JSObject* js_obj, HeapEntry* entry); | 922 void ExtractInternalReferences(JSObject* js_obj, int entry); |
996 bool IsEssentialObject(Object* object); | 923 bool IsEssentialObject(Object* object); |
997 void SetClosureReference(HeapObject* parent_obj, | 924 void SetClosureReference(HeapObject* parent_obj, |
998 HeapEntry* parent, | 925 int parent, |
999 String* reference_name, | 926 String* reference_name, |
1000 Object* child); | 927 Object* child); |
1001 void SetNativeBindReference(HeapObject* parent_obj, | 928 void SetNativeBindReference(HeapObject* parent_obj, |
1002 HeapEntry* parent, | 929 int parent, |
1003 const char* reference_name, | 930 const char* reference_name, |
1004 Object* child); | 931 Object* child); |
1005 void SetElementReference(HeapObject* parent_obj, | 932 void SetElementReference(HeapObject* parent_obj, |
1006 HeapEntry* parent, | 933 int parent, |
1007 int index, | 934 int index, |
1008 Object* child); | 935 Object* child); |
1009 void SetInternalReference(HeapObject* parent_obj, | 936 void SetInternalReference(HeapObject* parent_obj, |
1010 HeapEntry* parent, | 937 int parent, |
1011 const char* reference_name, | 938 const char* reference_name, |
1012 Object* child, | 939 Object* child, |
1013 int field_offset = -1); | 940 int field_offset = -1); |
1014 void SetInternalReference(HeapObject* parent_obj, | 941 void SetInternalReference(HeapObject* parent_obj, |
1015 HeapEntry* parent, | 942 int parent, |
1016 int index, | 943 int index, |
1017 Object* child, | 944 Object* child, |
1018 int field_offset = -1); | 945 int field_offset = -1); |
1019 void SetHiddenReference(HeapObject* parent_obj, | 946 void SetHiddenReference(HeapObject* parent_obj, |
1020 HeapEntry* parent, | 947 int parent, |
1021 int index, | 948 int index, |
1022 Object* child); | 949 Object* child); |
1023 void SetWeakReference(HeapObject* parent_obj, | 950 void SetWeakReference(HeapObject* parent_obj, |
1024 HeapEntry* parent_entry, | 951 int parent, |
1025 int index, | 952 int index, |
1026 Object* child_obj, | 953 Object* child_obj, |
1027 int field_offset); | 954 int field_offset); |
1028 void SetPropertyReference(HeapObject* parent_obj, | 955 void SetPropertyReference(HeapObject* parent_obj, |
1029 HeapEntry* parent, | 956 int parent, |
1030 String* reference_name, | 957 String* reference_name, |
1031 Object* child, | 958 Object* child, |
1032 const char* name_format_string = NULL, | 959 const char* name_format_string = NULL, |
1033 int field_offset = -1); | 960 int field_offset = -1); |
1034 void SetPropertyShortcutReference(HeapObject* parent_obj, | 961 void SetPropertyShortcutReference(HeapObject* parent_obj, |
1035 HeapEntry* parent, | 962 int parent, |
1036 String* reference_name, | 963 String* reference_name, |
1037 Object* child); | 964 Object* child); |
1038 void SetUserGlobalReference(Object* window); | 965 void SetUserGlobalReference(Object* user_global); |
1039 void SetRootGcRootsReference(); | 966 void SetRootGcRootsReference(); |
1040 void SetGcRootsReference(VisitorSynchronization::SyncTag tag); | 967 void SetGcRootsReference(VisitorSynchronization::SyncTag tag); |
1041 void SetGcSubrootReference( | 968 void SetGcSubrootReference( |
1042 VisitorSynchronization::SyncTag tag, bool is_weak, Object* child); | 969 VisitorSynchronization::SyncTag tag, bool is_weak, Object* child); |
1043 const char* GetStrongGcSubrootName(Object* object); | 970 const char* GetStrongGcSubrootName(Object* object); |
1044 void SetObjectName(HeapObject* object); | 971 void SetObjectName(HeapObject* object); |
1045 void TagObject(Object* obj, const char* tag); | 972 void TagObject(Object* obj, const char* tag); |
1046 | 973 |
1047 HeapEntry* GetEntry(Object* obj); | 974 HeapEntry* GetEntry(Object* obj); |
1048 | 975 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1132 class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface { | 1059 class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface { |
1133 public: | 1060 public: |
1134 HeapSnapshotGenerator(HeapSnapshot* snapshot, | 1061 HeapSnapshotGenerator(HeapSnapshot* snapshot, |
1135 v8::ActivityControl* control); | 1062 v8::ActivityControl* control); |
1136 bool GenerateSnapshot(); | 1063 bool GenerateSnapshot(); |
1137 | 1064 |
1138 private: | 1065 private: |
1139 bool BuildDominatorTree(const Vector<HeapEntry*>& entries, | 1066 bool BuildDominatorTree(const Vector<HeapEntry*>& entries, |
1140 Vector<int>* dominators); | 1067 Vector<int>* dominators); |
1141 bool CalculateRetainedSizes(); | 1068 bool CalculateRetainedSizes(); |
1142 bool CountEntriesAndReferences(); | |
1143 bool FillReferences(); | 1069 bool FillReferences(); |
1144 void FillPostorderIndexes(Vector<HeapEntry*>* entries); | 1070 void FillPostorderIndexes(Vector<HeapEntry*>* entries); |
1145 bool IsUserGlobalReference(const HeapGraphEdge& edge); | 1071 bool IsUserGlobalReference(const HeapGraphEdge* edge); |
1146 void MarkUserReachableObjects(); | 1072 void MarkUserReachableObjects(); |
1147 void ProgressStep(); | 1073 void ProgressStep(); |
1148 bool ProgressReport(bool force = false); | 1074 bool ProgressReport(bool force = false); |
1149 bool SetEntriesDominators(); | 1075 bool SetEntriesDominators(); |
1150 void SetProgressTotal(int iterations_count); | 1076 void SetProgressTotal(int iterations_count); |
1151 | 1077 |
1152 HeapSnapshot* snapshot_; | 1078 HeapSnapshot* snapshot_; |
1153 v8::ActivityControl* control_; | 1079 v8::ActivityControl* control_; |
1154 V8HeapExplorer v8_heap_explorer_; | 1080 V8HeapExplorer v8_heap_explorer_; |
1155 NativeObjectsExplorer dom_explorer_; | 1081 NativeObjectsExplorer dom_explorer_; |
(...skipping 23 matching lines...) Expand all Loading... | |
1179 INLINE(static bool ObjectsMatch(void* key1, void* key2)) { | 1105 INLINE(static bool ObjectsMatch(void* key1, void* key2)) { |
1180 return key1 == key2; | 1106 return key1 == key2; |
1181 } | 1107 } |
1182 | 1108 |
1183 INLINE(static uint32_t ObjectHash(const void* key)) { | 1109 INLINE(static uint32_t ObjectHash(const void* key)) { |
1184 return ComputeIntegerHash( | 1110 return ComputeIntegerHash( |
1185 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key)), | 1111 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key)), |
1186 v8::internal::kZeroHashSeed); | 1112 v8::internal::kZeroHashSeed); |
1187 } | 1113 } |
1188 | 1114 |
1189 void CalculateNodeIndexes(const List<HeapEntry*>& nodes); | |
1190 HeapSnapshot* CreateFakeSnapshot(); | 1115 HeapSnapshot* CreateFakeSnapshot(); |
1191 int GetStringId(const char* s); | 1116 int GetStringId(const char* s); |
1117 int entry_index(HeapEntry* e) { return e->index() * kNodeFieldsCount; } | |
1192 void SerializeEdge(HeapGraphEdge* edge, bool first_edge); | 1118 void SerializeEdge(HeapGraphEdge* edge, bool first_edge); |
1193 void SerializeEdges(const List<HeapEntry*>& nodes); | 1119 void SerializeEdges(const List<HeapEntry>& nodes); |
1194 void SerializeImpl(); | 1120 void SerializeImpl(); |
1195 void SerializeNode(HeapEntry* entry, int edges_index); | 1121 void SerializeNode(HeapEntry* entry, int edges_index); |
1196 void SerializeNodes(const List<HeapEntry*>& nodes); | 1122 void SerializeNodes(const List<HeapEntry>& nodes); |
1197 void SerializeSnapshot(); | 1123 void SerializeSnapshot(); |
1198 void SerializeString(const unsigned char* s); | 1124 void SerializeString(const unsigned char* s); |
1199 void SerializeStrings(); | 1125 void SerializeStrings(); |
1200 void SortHashMap(HashMap* map, List<HashMap::Entry*>* sorted_entries); | 1126 void SortHashMap(HashMap* map, List<HashMap::Entry*>* sorted_entries); |
1201 | 1127 |
1202 static const int kMaxSerializableSnapshotRawSize; | 1128 static const int kEdgeFieldsCount; |
1129 static const int kNodeFieldsCount; | |
1203 | 1130 |
1204 HeapSnapshot* snapshot_; | 1131 HeapSnapshot* snapshot_; |
1205 HashMap strings_; | 1132 HashMap strings_; |
1206 int next_node_id_; | 1133 int next_node_id_; |
1207 int next_string_id_; | 1134 int next_string_id_; |
1208 OutputStreamWriter* writer_; | 1135 OutputStreamWriter* writer_; |
1209 | 1136 |
1210 friend class HeapSnapshotJSONSerializerEnumerator; | 1137 friend class HeapSnapshotJSONSerializerEnumerator; |
1211 friend class HeapSnapshotJSONSerializerIterator; | 1138 friend class HeapSnapshotJSONSerializerIterator; |
1212 | 1139 |
1213 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); | 1140 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); |
1214 }; | 1141 }; |
1215 | 1142 |
1216 } } // namespace v8::internal | 1143 } } // namespace v8::internal |
1217 | 1144 |
1218 #endif // V8_PROFILE_GENERATOR_H_ | 1145 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |