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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 CpuProfilesCollection* profiles_; | 416 CpuProfilesCollection* profiles_; |
417 CodeMap code_map_; | 417 CodeMap code_map_; |
418 CodeEntry* program_entry_; | 418 CodeEntry* program_entry_; |
419 CodeEntry* gc_entry_; | 419 CodeEntry* gc_entry_; |
420 SampleRateCalculator sample_rate_calc_; | 420 SampleRateCalculator sample_rate_calc_; |
421 | 421 |
422 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 422 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
423 }; | 423 }; |
424 | 424 |
425 | 425 |
426 class HeapSnapshot; | |
427 class HeapEntry; | 426 class HeapEntry; |
428 | 427 |
429 | 428 class HeapGraphEdge BASE_EMBEDDED { |
430 class HeapGraphEdge { | |
431 public: | 429 public: |
432 enum Type { | 430 enum Type { |
433 CONTEXT_VARIABLE = v8::HeapGraphEdge::CONTEXT_VARIABLE, | 431 kContextVariable = v8::HeapGraphEdge::kContextVariable, |
434 ELEMENT = v8::HeapGraphEdge::ELEMENT, | 432 kElement = v8::HeapGraphEdge::kElement, |
435 PROPERTY = v8::HeapGraphEdge::PROPERTY, | 433 kProperty = v8::HeapGraphEdge::kProperty, |
436 INTERNAL = v8::HeapGraphEdge::INTERNAL | 434 kInternal = v8::HeapGraphEdge::kInternal |
437 }; | 435 }; |
438 | 436 |
439 HeapGraphEdge(Type type, const char* name, HeapEntry* from, HeapEntry* to); | 437 HeapGraphEdge() { } |
440 HeapGraphEdge(int index, HeapEntry* from, HeapEntry* to); | 438 void Init(int child_index, Type type, const char* name, HeapEntry* to); |
| 439 void Init(int child_index, int index, HeapEntry* to); |
441 | 440 |
442 Type type() const { return type_; } | 441 Type type() { return type_; } |
443 int index() const { | 442 int index() { |
444 ASSERT(type_ == ELEMENT); | 443 ASSERT(type_ == kElement); |
445 return index_; | 444 return index_; |
446 } | 445 } |
447 const char* name() const { | 446 const char* name() { |
448 ASSERT(type_ == CONTEXT_VARIABLE || type_ == PROPERTY || type_ == INTERNAL); | 447 ASSERT(type_ == kContextVariable |
| 448 || type_ == kProperty |
| 449 || type_ == kInternal); |
449 return name_; | 450 return name_; |
450 } | 451 } |
451 HeapEntry* from() const { return from_; } | 452 HeapEntry* to() { return to_; } |
452 HeapEntry* to() const { return to_; } | 453 |
| 454 HeapEntry* From(); |
453 | 455 |
454 private: | 456 private: |
455 Type type_; | 457 int child_index_ : 30; |
| 458 Type type_ : 2; |
456 union { | 459 union { |
457 int index_; | 460 int index_; |
458 const char* name_; | 461 const char* name_; |
459 }; | 462 }; |
460 HeapEntry* from_; | |
461 HeapEntry* to_; | 463 HeapEntry* to_; |
462 | 464 |
463 DISALLOW_COPY_AND_ASSIGN(HeapGraphEdge); | 465 DISALLOW_COPY_AND_ASSIGN(HeapGraphEdge); |
464 }; | 466 }; |
465 | 467 |
466 | 468 |
| 469 class CachedHeapGraphPath; |
467 class HeapGraphPath; | 470 class HeapGraphPath; |
468 class CachedHeapGraphPath; | 471 class HeapSnapshot; |
469 | 472 |
470 class HeapEntry { | 473 // HeapEntry instances represent an entity from the heap (or a special |
| 474 // virtual node, e.g. root). To make heap snapshots more compact, |
| 475 // HeapEntries has a special memory layout (no Vectors or Lists used): |
| 476 // |
| 477 // +-----------------+ |
| 478 // HeapEntry |
| 479 // +-----------------+ |
| 480 // HeapGraphEdge | |
| 481 // ... } children_count |
| 482 // HeapGraphEdge | |
| 483 // +-----------------+ |
| 484 // HeapGraphEdge* | |
| 485 // ... } retainers_count |
| 486 // HeapGraphEdge* | |
| 487 // +-----------------+ |
| 488 // |
| 489 // In a HeapSnapshot, all entries are hand-allocated in a continuous array |
| 490 // of raw bytes. |
| 491 // |
| 492 class HeapEntry BASE_EMBEDDED { |
471 public: | 493 public: |
472 enum Type { | 494 enum Type { |
473 INTERNAL = v8::HeapGraphNode::INTERNAL, | 495 kInternal = v8::HeapGraphNode::kInternal, |
474 ARRAY = v8::HeapGraphNode::ARRAY, | 496 kArray = v8::HeapGraphNode::kArray, |
475 STRING = v8::HeapGraphNode::STRING, | 497 kString = v8::HeapGraphNode::kString, |
476 OBJECT = v8::HeapGraphNode::OBJECT, | 498 kObject = v8::HeapGraphNode::kObject, |
477 CODE = v8::HeapGraphNode::CODE, | 499 kCode = v8::HeapGraphNode::kCode, |
478 CLOSURE = v8::HeapGraphNode::CLOSURE | 500 kClosure = v8::HeapGraphNode::kClosure |
479 }; | 501 }; |
480 | 502 |
481 explicit HeapEntry(HeapSnapshot* snapshot) | 503 HeapEntry() { } |
482 : snapshot_(snapshot), | 504 void Init(HeapSnapshot* snapshot, int children_count, int retainers_count); |
483 visited_(false), | 505 void Init(HeapSnapshot* snapshot, |
484 type_(INTERNAL), | |
485 name_(""), | |
486 id_(0), | |
487 next_auto_index_(0), | |
488 self_size_(0), | |
489 security_token_id_(TokenEnumerator::kNoSecurityToken), | |
490 children_(1), | |
491 retainers_(0), | |
492 retaining_paths_(0), | |
493 total_size_(kUnknownSize), | |
494 non_shared_total_size_(kUnknownSize), | |
495 painted_(kUnpainted) { } | |
496 HeapEntry(HeapSnapshot* snapshot, | |
497 Type type, | 506 Type type, |
498 const char* name, | 507 const char* name, |
499 uint64_t id, | 508 uint64_t id, |
500 int self_size, | 509 int self_size, |
501 int security_token_id) | 510 int children_count, |
502 : snapshot_(snapshot), | 511 int retainers_count); |
503 visited_(false), | |
504 type_(type), | |
505 name_(name), | |
506 id_(id), | |
507 next_auto_index_(1), | |
508 self_size_(self_size), | |
509 security_token_id_(security_token_id), | |
510 children_(4), | |
511 retainers_(4), | |
512 retaining_paths_(4), | |
513 total_size_(kUnknownSize), | |
514 non_shared_total_size_(kUnknownSize), | |
515 painted_(kUnpainted) { } | |
516 ~HeapEntry(); | |
517 | 512 |
518 bool visited() const { return visited_; } | 513 HeapSnapshot* snapshot() { return snapshot_; } |
519 Type type() const { return type_; } | 514 Type type() { return type_; } |
520 const char* name() const { return name_; } | 515 const char* name() { return name_; } |
521 uint64_t id() const { return id_; } | 516 uint64_t id() { return id_; } |
522 int self_size() const { return self_size_; } | 517 int self_size() { return self_size_; } |
523 int security_token_id() const { return security_token_id_; } | 518 |
524 bool painted_reachable() { return painted_ == kPaintReachable; } | 519 Vector<HeapGraphEdge> children() { |
| 520 return Vector<HeapGraphEdge>(children_arr(), children_count_); } |
| 521 Vector<HeapGraphEdge*> retainers() { |
| 522 return Vector<HeapGraphEdge*>(retainers_arr(), retainers_count_); } |
| 523 List<HeapGraphPath*>* GetRetainingPaths(); |
| 524 |
| 525 void clear_paint() { painted_ = kUnpainted; } |
| 526 bool painted_reachable() { return painted_ == kPainted; } |
| 527 void paint_reachable() { |
| 528 ASSERT(painted_ == kUnpainted); |
| 529 painted_ = kPainted; |
| 530 } |
525 bool not_painted_reachable_from_others() { | 531 bool not_painted_reachable_from_others() { |
526 return painted_ != kPaintReachableFromOthers; | 532 return painted_ != kPaintedReachableFromOthers; |
527 } | 533 } |
528 const List<HeapGraphEdge*>* children() const { return &children_; } | 534 void paint_reachable_from_others() { |
529 const List<HeapGraphEdge*>* retainers() const { return &retainers_; } | 535 painted_ = kPaintedReachableFromOthers; |
530 const List<HeapGraphPath*>* GetRetainingPaths(); | 536 } |
531 | |
532 template<class Visitor> | 537 template<class Visitor> |
533 void ApplyAndPaintAllReachable(Visitor* visitor); | 538 void ApplyAndPaintAllReachable(Visitor* visitor); |
| 539 void PaintAllReachable(); |
534 | 540 |
535 void ClearPaint() { painted_ = kUnpainted; } | 541 void SetElementReference( |
536 void CutEdges(); | 542 int child_index, int index, HeapEntry* entry, int retainer_index); |
537 void MarkAsVisited() { visited_ = true; } | 543 void SetNamedReference(HeapGraphEdge::Type type, |
538 void PaintAllReachable(); | 544 int child_index, |
539 void PaintReachable() { | 545 const char* name, |
540 ASSERT(painted_ == kUnpainted); | 546 HeapEntry* entry, |
541 painted_ = kPaintReachable; | 547 int retainer_index); |
542 } | 548 void SetUnidirElementReference(int child_index, int index, HeapEntry* entry); |
543 void PaintReachableFromOthers() { painted_ = kPaintReachableFromOthers; } | |
544 void SetClosureReference(const char* name, HeapEntry* entry); | |
545 void SetElementReference(int index, HeapEntry* entry); | |
546 void SetInternalReference(const char* name, HeapEntry* entry); | |
547 void SetPropertyReference(const char* name, HeapEntry* entry); | |
548 void SetAutoIndexReference(HeapEntry* entry); | |
549 void SetUnidirAutoIndexReference(HeapEntry* entry); | |
550 | 549 |
551 int TotalSize(); | 550 int EntrySize() { return EntriesSize(1, children_count_, retainers_count_); } |
552 int NonSharedTotalSize(); | 551 int ReachableSize(); |
| 552 int RetainedSize(); |
553 | 553 |
554 void Print(int max_depth, int indent); | 554 void Print(int max_depth, int indent); |
555 | 555 |
| 556 static int EntriesSize(int entries_count, |
| 557 int children_count, |
| 558 int retainers_count); |
| 559 |
556 private: | 560 private: |
557 void AddEdge(HeapGraphEdge* edge); | 561 HeapGraphEdge* children_arr() { |
558 int CalculateTotalSize(); | 562 return reinterpret_cast<HeapGraphEdge*>(this + 1); |
559 int CalculateNonSharedTotalSize(); | 563 } |
560 void FindRetainingPaths(HeapEntry* node, CachedHeapGraphPath* prev_path); | 564 HeapGraphEdge** retainers_arr() { |
561 void RemoveChild(HeapGraphEdge* edge); | 565 return reinterpret_cast<HeapGraphEdge**>(children_arr() + children_count_); |
562 void RemoveRetainer(HeapGraphEdge* edge); | 566 } |
563 | |
564 const char* TypeAsString(); | 567 const char* TypeAsString(); |
565 | 568 |
566 HeapSnapshot* snapshot_; | 569 HeapSnapshot* snapshot_; |
567 bool visited_; | 570 unsigned painted_: 2; |
568 Type type_; | 571 Type type_: 3; |
| 572 // The calculated data is stored in HeapSnapshot in HeapEntryCalculatedData |
| 573 // entries. See AddCalculatedData and GetCalculatedData. |
| 574 int calculated_data_index_: 27; |
569 const char* name_; | 575 const char* name_; |
570 uint64_t id_; | 576 uint64_t id_; |
571 int next_auto_index_; | |
572 int self_size_; | 577 int self_size_; |
573 int security_token_id_; | 578 int children_count_; |
574 List<HeapGraphEdge*> children_; | 579 int retainers_count_; |
575 List<HeapGraphEdge*> retainers_; | |
576 List<HeapGraphPath*> retaining_paths_; | |
577 int total_size_; | |
578 int non_shared_total_size_; | |
579 int painted_; | |
580 | 580 |
581 static const int kUnknownSize = -1; | 581 static const unsigned kUnpainted = 0; |
582 static const int kUnpainted = 0; | 582 static const unsigned kPainted = 1; |
583 static const int kPaintReachable = 1; | 583 static const unsigned kPaintedReachableFromOthers = 2; |
584 static const int kPaintReachableFromOthers = 2; | 584 static const int kNoCalculatedData = -1; |
585 | 585 |
586 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapEntry); | 586 DISALLOW_COPY_AND_ASSIGN(HeapEntry); |
587 }; | 587 }; |
588 | 588 |
589 | 589 |
| 590 class HeapEntryCalculatedData { |
| 591 public: |
| 592 HeapEntryCalculatedData() |
| 593 : retaining_paths_(NULL), |
| 594 reachable_size_(kUnknownSize), |
| 595 retained_size_(kUnknownSize) { |
| 596 } |
| 597 void Dispose(); |
| 598 |
| 599 List<HeapGraphPath*>* GetRetainingPaths(HeapEntry* entry); |
| 600 int ReachableSize(HeapEntry* entry); |
| 601 int RetainedSize(HeapEntry* entry); |
| 602 |
| 603 private: |
| 604 void CalculateSizes(HeapEntry* entry); |
| 605 void FindRetainingPaths(HeapEntry* entry, CachedHeapGraphPath* prev_path); |
| 606 |
| 607 List<HeapGraphPath*>* retaining_paths_; |
| 608 int reachable_size_; |
| 609 int retained_size_; |
| 610 |
| 611 static const int kUnknownSize = -1; |
| 612 |
| 613 // Allow generated copy constructor and assignment operator. |
| 614 }; |
| 615 |
| 616 |
590 class HeapGraphPath { | 617 class HeapGraphPath { |
591 public: | 618 public: |
592 HeapGraphPath() | 619 HeapGraphPath() |
593 : path_(8) { } | 620 : path_(8) { } |
594 explicit HeapGraphPath(const List<HeapGraphEdge*>& path); | 621 explicit HeapGraphPath(const List<HeapGraphEdge*>& path); |
595 | 622 |
596 void Add(HeapGraphEdge* edge) { path_.Add(edge); } | 623 void Add(HeapGraphEdge* edge) { path_.Add(edge); } |
597 void Set(int index, HeapGraphEdge* edge) { path_[index] = edge; } | 624 void Set(int index, HeapGraphEdge* edge) { path_[index] = edge; } |
598 const List<HeapGraphEdge*>* path() const { return &path_; } | 625 const List<HeapGraphEdge*>* path() { return &path_; } |
599 | 626 |
600 void Print(); | 627 void Print(); |
601 | 628 |
602 private: | 629 private: |
603 List<HeapGraphEdge*> path_; | 630 List<HeapGraphEdge*> path_; |
604 | 631 |
605 DISALLOW_COPY_AND_ASSIGN(HeapGraphPath); | 632 DISALLOW_COPY_AND_ASSIGN(HeapGraphPath); |
606 }; | 633 }; |
607 | 634 |
608 | 635 |
609 class HeapEntriesMap { | |
610 public: | |
611 HeapEntriesMap(); | |
612 ~HeapEntriesMap(); | |
613 | |
614 void Alias(HeapObject* object, HeapEntry* entry); | |
615 void Apply(void (HeapEntry::*Func)(void)); | |
616 template<class Visitor> | |
617 void Apply(Visitor* visitor); | |
618 HeapEntry* Map(HeapObject* object); | |
619 void Pair(HeapObject* object, HeapEntry* entry); | |
620 | |
621 uint32_t capacity() { return entries_.capacity(); } | |
622 | |
623 private: | |
624 INLINE(uint32_t Hash(HeapObject* object)) { | |
625 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(object)); | |
626 } | |
627 INLINE(static bool HeapObjectsMatch(void* key1, void* key2)) { | |
628 return key1 == key2; | |
629 } | |
630 INLINE(bool IsAlias(void* ptr)) { | |
631 return reinterpret_cast<intptr_t>(ptr) & kAliasTag; | |
632 } | |
633 | |
634 static const intptr_t kAliasTag = 1; | |
635 | |
636 HashMap entries_; | |
637 | |
638 DISALLOW_COPY_AND_ASSIGN(HeapEntriesMap); | |
639 }; | |
640 | |
641 | |
642 class HeapSnapshotsCollection; | 636 class HeapSnapshotsCollection; |
643 class HeapSnapshotsDiff; | 637 class HeapSnapshotsDiff; |
644 | 638 |
645 // HeapSnapshot represents a single heap snapshot. It is stored in | 639 // HeapSnapshot represents a single heap snapshot. It is stored in |
646 // HeapSnapshotsCollection, which is also a factory for | 640 // HeapSnapshotsCollection, which is also a factory for |
647 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap | 641 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap |
648 // to be able to return them even if they were collected. | 642 // to be able to return them even if they were collected. |
649 // HeapSnapshotGenerator fills in a HeapSnapshot. | 643 // HeapSnapshotGenerator fills in a HeapSnapshot. |
650 class HeapSnapshot { | 644 class HeapSnapshot { |
651 public: | 645 public: |
652 HeapSnapshot(HeapSnapshotsCollection* collection, | 646 HeapSnapshot(HeapSnapshotsCollection* collection, |
653 const char* title, | 647 const char* title, |
654 unsigned uid); | 648 unsigned uid); |
655 ~HeapSnapshot(); | 649 ~HeapSnapshot(); |
| 650 |
| 651 HeapSnapshotsCollection* collection() { return collection_; } |
| 652 const char* title() { return title_; } |
| 653 unsigned uid() { return uid_; } |
| 654 HeapEntry* root() { return entries_[root_entry_index_]; } |
| 655 |
| 656 void AllocateEntries( |
| 657 int entries_count, int children_count, int retainers_count); |
| 658 HeapEntry* AddEntry( |
| 659 HeapObject* object, int children_count, int retainers_count); |
| 660 bool WillAddEntry(HeapObject* object); |
| 661 int AddCalculatedData(); |
| 662 HeapEntryCalculatedData& GetCalculatedData(int index) { |
| 663 return calculated_data_[index]; |
| 664 } |
656 void ClearPaint(); | 665 void ClearPaint(); |
657 void CutObjectsFromForeignSecurityContexts(); | 666 HeapSnapshotsDiff* CompareWith(HeapSnapshot* snapshot); |
658 HeapEntry* GetEntry(Object* object); | 667 List<HeapEntry*>* GetSortedEntriesList(); |
659 void SetClosureReference( | |
660 HeapEntry* parent, String* reference_name, Object* child); | |
661 void SetElementReference(HeapEntry* parent, int index, Object* child); | |
662 void SetInternalReference( | |
663 HeapEntry* parent, const char* reference_name, Object* child); | |
664 void SetPropertyReference( | |
665 HeapEntry* parent, String* reference_name, Object* child); | |
666 | |
667 INLINE(const char* title() const) { return title_; } | |
668 INLINE(unsigned uid() const) { return uid_; } | |
669 const HeapEntry* const_root() const { return &root_; } | |
670 HeapEntry* root() { return &root_; } | |
671 template<class Visitor> | 668 template<class Visitor> |
672 void IterateEntries(Visitor* visitor) { entries_.Apply(visitor); } | 669 void IterateEntries(Visitor* visitor) { entries_.Iterate(visitor); } |
673 List<HeapEntry*>* GetSortedEntriesList(); | |
674 HeapSnapshotsDiff* CompareWith(HeapSnapshot* snapshot); | |
675 | 670 |
676 void Print(int max_depth); | 671 void Print(int max_depth); |
| 672 void PrintEntriesSize(); |
| 673 |
| 674 static HeapObject *const kInternalRootObject; |
677 | 675 |
678 private: | 676 private: |
679 HeapEntry* AddEntry(HeapObject* object, HeapEntry::Type type) { | 677 HeapEntry* AddEntry(HeapObject* object, |
680 return AddEntry(object, type, ""); | 678 HeapEntry::Type type, |
681 } | 679 const char* name, |
682 HeapEntry* AddEntry( | 680 int children_count, |
683 HeapObject* object, HeapEntry::Type type, const char* name); | 681 int retainers_count); |
684 void AddEntryAlias(HeapObject* object, HeapEntry* entry) { | 682 HeapEntry* GetNextEntryToInit(); |
685 entries_.Alias(object, entry); | |
686 } | |
687 HeapEntry* FindEntry(HeapObject* object) { | |
688 return entries_.Map(object); | |
689 } | |
690 int GetGlobalSecurityToken(); | |
691 int GetObjectSecurityToken(HeapObject* obj); | |
692 static int GetObjectSize(HeapObject* obj); | 683 static int GetObjectSize(HeapObject* obj); |
693 static int CalculateNetworkSize(JSObject* obj); | 684 static int CalculateNetworkSize(JSObject* obj); |
694 | 685 |
695 HeapSnapshotsCollection* collection_; | 686 HeapSnapshotsCollection* collection_; |
696 const char* title_; | 687 const char* title_; |
697 unsigned uid_; | 688 unsigned uid_; |
698 HeapEntry root_; | 689 int root_entry_index_; |
699 // Mapping from HeapObject* pointers to HeapEntry* pointers. | 690 char* raw_entries_; |
700 HeapEntriesMap entries_; | 691 List<HeapEntry*> entries_; |
701 // Entries sorted by id. | 692 bool entries_sorted_; |
702 List<HeapEntry*>* sorted_entries_; | 693 List<HeapEntryCalculatedData> calculated_data_; |
703 | 694 |
704 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); | 695 DISALLOW_COPY_AND_ASSIGN(HeapSnapshot); |
705 }; | 696 }; |
706 | 697 |
707 | 698 |
708 class HeapObjectsMap { | 699 class HeapObjectsMap { |
709 public: | 700 public: |
710 HeapObjectsMap(); | 701 HeapObjectsMap(); |
711 ~HeapObjectsMap(); | 702 ~HeapObjectsMap(); |
712 | 703 |
(...skipping 28 matching lines...) Expand all Loading... |
741 | 732 |
742 DISALLOW_COPY_AND_ASSIGN(HeapObjectsMap); | 733 DISALLOW_COPY_AND_ASSIGN(HeapObjectsMap); |
743 }; | 734 }; |
744 | 735 |
745 | 736 |
746 class HeapSnapshotsDiff { | 737 class HeapSnapshotsDiff { |
747 public: | 738 public: |
748 HeapSnapshotsDiff(HeapSnapshot* snapshot1, HeapSnapshot* snapshot2) | 739 HeapSnapshotsDiff(HeapSnapshot* snapshot1, HeapSnapshot* snapshot2) |
749 : snapshot1_(snapshot1), | 740 : snapshot1_(snapshot1), |
750 snapshot2_(snapshot2), | 741 snapshot2_(snapshot2), |
751 additions_root_(new HeapEntry(snapshot2)), | 742 raw_additions_root_(NULL), |
752 deletions_root_(new HeapEntry(snapshot1)) { } | 743 raw_deletions_root_(NULL) { } |
753 | 744 |
754 ~HeapSnapshotsDiff() { | 745 ~HeapSnapshotsDiff() { |
755 delete deletions_root_; | 746 DeleteArray(raw_deletions_root_); |
756 delete additions_root_; | 747 DeleteArray(raw_additions_root_); |
757 } | 748 } |
758 | 749 |
759 void AddAddedEntry(HeapEntry* entry) { | 750 void AddAddedEntry(int child_index, int index, HeapEntry* entry) { |
760 additions_root_->SetUnidirAutoIndexReference(entry); | 751 additions_root()->SetUnidirElementReference(child_index, index, entry); |
761 } | 752 } |
762 | 753 |
763 void AddDeletedEntry(HeapEntry* entry) { | 754 void AddDeletedEntry(int child_index, int index, HeapEntry* entry) { |
764 deletions_root_->SetUnidirAutoIndexReference(entry); | 755 deletions_root()->SetUnidirElementReference(child_index, index, entry); |
765 } | 756 } |
766 | 757 |
767 const HeapEntry* additions_root() const { return additions_root_; } | 758 void CreateRoots(int additions_count, int deletions_count); |
768 const HeapEntry* deletions_root() const { return deletions_root_; } | 759 |
| 760 HeapEntry* additions_root() { |
| 761 return reinterpret_cast<HeapEntry*>(raw_additions_root_); |
| 762 } |
| 763 HeapEntry* deletions_root() { |
| 764 return reinterpret_cast<HeapEntry*>(raw_deletions_root_); |
| 765 } |
769 | 766 |
770 private: | 767 private: |
771 HeapSnapshot* snapshot1_; | 768 HeapSnapshot* snapshot1_; |
772 HeapSnapshot* snapshot2_; | 769 HeapSnapshot* snapshot2_; |
773 HeapEntry* additions_root_; | 770 char* raw_additions_root_; |
774 HeapEntry* deletions_root_; | 771 char* raw_deletions_root_; |
775 | 772 |
776 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotsDiff); | 773 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotsDiff); |
777 }; | 774 }; |
778 | 775 |
779 | 776 |
780 class HeapSnapshotsComparator { | 777 class HeapSnapshotsComparator { |
781 public: | 778 public: |
782 HeapSnapshotsComparator() { } | 779 HeapSnapshotsComparator() { } |
783 ~HeapSnapshotsComparator(); | 780 ~HeapSnapshotsComparator(); |
784 HeapSnapshotsDiff* Compare(HeapSnapshot* snapshot1, HeapSnapshot* snapshot2); | 781 HeapSnapshotsDiff* Compare(HeapSnapshot* snapshot1, HeapSnapshot* snapshot2); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 StringsStorage names_; | 820 StringsStorage names_; |
824 TokenEnumerator* token_enumerator_; | 821 TokenEnumerator* token_enumerator_; |
825 // Mapping from HeapObject addresses to objects' uids. | 822 // Mapping from HeapObject addresses to objects' uids. |
826 HeapObjectsMap ids_; | 823 HeapObjectsMap ids_; |
827 HeapSnapshotsComparator comparator_; | 824 HeapSnapshotsComparator comparator_; |
828 | 825 |
829 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotsCollection); | 826 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotsCollection); |
830 }; | 827 }; |
831 | 828 |
832 | 829 |
| 830 // The HeapEntriesMap instance is used to track a mapping between |
| 831 // real heap objects and their representations in heap snapshots. |
| 832 class HeapEntriesMap { |
| 833 public: |
| 834 HeapEntriesMap(); |
| 835 ~HeapEntriesMap(); |
| 836 |
| 837 // Aliasing is used for skipping intermediate proxy objects, like |
| 838 // JSGlobalPropertyCell. |
| 839 void Alias(HeapObject* from, HeapObject* to); |
| 840 HeapEntry* Map(HeapObject* object); |
| 841 void Pair(HeapObject* object, HeapEntry* entry); |
| 842 void CountReference(HeapObject* from, HeapObject* to, |
| 843 int* prev_children_count = NULL, |
| 844 int* prev_retainers_count = NULL); |
| 845 template<class Visitor> |
| 846 void UpdateEntries(Visitor* visitor); |
| 847 |
| 848 int entries_count() { return entries_count_; } |
| 849 int total_children_count() { return total_children_count_; } |
| 850 int total_retainers_count() { return total_retainers_count_; } |
| 851 |
| 852 private: |
| 853 struct EntryInfo { |
| 854 explicit EntryInfo(HeapEntry* entry) |
| 855 : entry(entry), children_count(0), retainers_count(0) { } |
| 856 HeapEntry* entry; |
| 857 int children_count; |
| 858 int retainers_count; |
| 859 }; |
| 860 |
| 861 uint32_t Hash(HeapObject* object) { |
| 862 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(object)); |
| 863 } |
| 864 static bool HeapObjectsMatch(void* key1, void* key2) { return key1 == key2; } |
| 865 |
| 866 bool IsAlias(void* ptr) { |
| 867 return reinterpret_cast<intptr_t>(ptr) & kAliasTag; |
| 868 } |
| 869 void* MakeAlias(void* ptr) { |
| 870 return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(ptr) | kAliasTag); |
| 871 } |
| 872 void* Unalias(void* ptr) { |
| 873 return reinterpret_cast<void*>( |
| 874 reinterpret_cast<intptr_t>(ptr) & (~kAliasTag)); |
| 875 } |
| 876 |
| 877 HashMap entries_; |
| 878 int entries_count_; |
| 879 int total_children_count_; |
| 880 int total_retainers_count_; |
| 881 |
| 882 static const intptr_t kAliasTag = 1; |
| 883 |
| 884 DISALLOW_COPY_AND_ASSIGN(HeapEntriesMap); |
| 885 }; |
| 886 |
| 887 |
833 class HeapSnapshotGenerator { | 888 class HeapSnapshotGenerator { |
834 public: | 889 public: |
| 890 class SnapshotFillerInterface { |
| 891 public: |
| 892 virtual ~SnapshotFillerInterface() { } |
| 893 virtual HeapEntry* AddEntry(HeapObject* obj) = 0; |
| 894 virtual void SetElementReference(HeapObject* parent_obj, |
| 895 HeapEntry* parent_entry, |
| 896 int index, |
| 897 Object* child_obj, |
| 898 HeapEntry* child_entry) = 0; |
| 899 virtual void SetNamedReference(HeapGraphEdge::Type type, |
| 900 HeapObject* parent_obj, |
| 901 HeapEntry* parent_entry, |
| 902 const char* reference_name, |
| 903 Object* child_obj, |
| 904 HeapEntry* child_entry) = 0; |
| 905 virtual void SetRootReference(Object* child_obj, |
| 906 HeapEntry* child_entry) = 0; |
| 907 |
| 908 static HeapEntry *const kHeapEntryPlaceholder; |
| 909 }; |
| 910 |
835 explicit HeapSnapshotGenerator(HeapSnapshot* snapshot); | 911 explicit HeapSnapshotGenerator(HeapSnapshot* snapshot); |
836 void GenerateSnapshot(); | 912 void GenerateSnapshot(); |
837 | 913 |
838 private: | 914 private: |
| 915 HeapEntry* GetEntry(Object* obj); |
| 916 int GetGlobalSecurityToken(); |
| 917 int GetObjectSecurityToken(HeapObject* obj); |
839 void ExtractReferences(HeapObject* obj); | 918 void ExtractReferences(HeapObject* obj); |
840 void ExtractClosureReferences(JSObject* js_obj, HeapEntry* entry); | 919 void ExtractClosureReferences(JSObject* js_obj, HeapEntry* entry); |
841 void ExtractPropertyReferences(JSObject* js_obj, HeapEntry* entry); | 920 void ExtractPropertyReferences(JSObject* js_obj, HeapEntry* entry); |
842 void ExtractElementReferences(JSObject* js_obj, HeapEntry* entry); | 921 void ExtractElementReferences(JSObject* js_obj, HeapEntry* entry); |
| 922 void SetClosureReference(HeapObject* parent_obj, |
| 923 HeapEntry* parent, |
| 924 String* reference_name, |
| 925 Object* child); |
| 926 void SetElementReference(HeapObject* parent_obj, |
| 927 HeapEntry* parent, |
| 928 int index, |
| 929 Object* child); |
| 930 void SetInternalReference(HeapObject* parent_obj, |
| 931 HeapEntry* parent, |
| 932 const char* reference_name, |
| 933 Object* child); |
| 934 void SetPropertyReference(HeapObject* parent_obj, |
| 935 HeapEntry* parent, |
| 936 String* reference_name, |
| 937 Object* child); |
| 938 void SetRootReference(Object* child); |
843 | 939 |
844 HeapSnapshot* snapshot_; | 940 HeapSnapshot* snapshot_; |
| 941 HeapSnapshotsCollection* collection_; |
| 942 // Mapping from HeapObject* pointers to HeapEntry* pointers. |
| 943 HeapEntriesMap entries_; |
| 944 SnapshotFillerInterface* filler_; |
| 945 |
| 946 friend class IndexedReferencesExtractor; |
845 | 947 |
846 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotGenerator); | 948 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotGenerator); |
847 }; | 949 }; |
848 | 950 |
849 } } // namespace v8::internal | 951 } } // namespace v8::internal |
850 | 952 |
851 #endif // ENABLE_LOGGING_AND_PROFILING | 953 #endif // ENABLE_LOGGING_AND_PROFILING |
852 | 954 |
853 #endif // V8_PROFILE_GENERATOR_H_ | 955 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |