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 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 switch (type()) { | 1124 switch (type()) { |
1125 case kHidden: return "/hidden/"; | 1125 case kHidden: return "/hidden/"; |
1126 case kObject: return "/object/"; | 1126 case kObject: return "/object/"; |
1127 case kClosure: return "/closure/"; | 1127 case kClosure: return "/closure/"; |
1128 case kString: return "/string/"; | 1128 case kString: return "/string/"; |
1129 case kCode: return "/code/"; | 1129 case kCode: return "/code/"; |
1130 case kArray: return "/array/"; | 1130 case kArray: return "/array/"; |
1131 case kRegExp: return "/regexp/"; | 1131 case kRegExp: return "/regexp/"; |
1132 case kHeapNumber: return "/number/"; | 1132 case kHeapNumber: return "/number/"; |
1133 case kNative: return "/native/"; | 1133 case kNative: return "/native/"; |
| 1134 case kSynthetic: return "/synthetic/"; |
1134 default: return "???"; | 1135 default: return "???"; |
1135 } | 1136 } |
1136 } | 1137 } |
1137 | 1138 |
1138 | 1139 |
1139 int HeapEntry::EntriesSize(int entries_count, | 1140 int HeapEntry::EntriesSize(int entries_count, |
1140 int children_count, | 1141 int children_count, |
1141 int retainers_count) { | 1142 int retainers_count) { |
1142 return sizeof(HeapEntry) * entries_count // NOLINT | 1143 return sizeof(HeapEntry) * entries_count // NOLINT |
1143 + sizeof(HeapGraphEdge) * children_count // NOLINT | 1144 + sizeof(HeapGraphEdge) * children_count // NOLINT |
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2691 virtual void VisitPointers(Object** start, Object** end) { | 2692 virtual void VisitPointers(Object** start, Object** end) { |
2692 UNREACHABLE(); | 2693 UNREACHABLE(); |
2693 } | 2694 } |
2694 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) { | 2695 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) { |
2695 explorer_->VisitSubtreeWrapper(p, class_id); | 2696 explorer_->VisitSubtreeWrapper(p, class_id); |
2696 } | 2697 } |
2697 private: | 2698 private: |
2698 NativeObjectsExplorer* explorer_; | 2699 NativeObjectsExplorer* explorer_; |
2699 }; | 2700 }; |
2700 | 2701 |
| 2702 |
| 2703 class BasicHeapEntriesAllocator : public HeapEntriesAllocator { |
| 2704 public: |
| 2705 BasicHeapEntriesAllocator( |
| 2706 HeapSnapshot* snapshot, |
| 2707 HeapEntry::Type entries_type) |
| 2708 : snapshot_(snapshot), |
| 2709 collection_(snapshot_->collection()), |
| 2710 entries_type_(entries_type) { |
| 2711 } |
| 2712 virtual HeapEntry* AllocateEntry( |
| 2713 HeapThing ptr, int children_count, int retainers_count); |
| 2714 private: |
| 2715 HeapSnapshot* snapshot_; |
| 2716 HeapSnapshotsCollection* collection_; |
| 2717 HeapEntry::Type entries_type_; |
| 2718 }; |
| 2719 |
| 2720 |
| 2721 HeapEntry* BasicHeapEntriesAllocator::AllocateEntry( |
| 2722 HeapThing ptr, int children_count, int retainers_count) { |
| 2723 v8::RetainedObjectInfo* info = reinterpret_cast<v8::RetainedObjectInfo*>(ptr); |
| 2724 intptr_t elements = info->GetElementCount(); |
| 2725 intptr_t size = info->GetSizeInBytes(); |
| 2726 return snapshot_->AddEntry( |
| 2727 entries_type_, |
| 2728 elements != -1 ? |
| 2729 collection_->names()->GetFormatted( |
| 2730 "%s / %" V8_PTR_PREFIX "d entries", |
| 2731 info->GetLabel(), |
| 2732 info->GetElementCount()) : |
| 2733 collection_->names()->GetCopy(info->GetLabel()), |
| 2734 HeapObjectsMap::GenerateId(info), |
| 2735 size != -1 ? static_cast<int>(size) : 0, |
| 2736 children_count, |
| 2737 retainers_count); |
| 2738 } |
| 2739 |
| 2740 |
2701 NativeObjectsExplorer::NativeObjectsExplorer( | 2741 NativeObjectsExplorer::NativeObjectsExplorer( |
2702 HeapSnapshot* snapshot, SnapshottingProgressReportingInterface* progress) | 2742 HeapSnapshot* snapshot, SnapshottingProgressReportingInterface* progress) |
2703 : snapshot_(snapshot), | 2743 : snapshot_(snapshot), |
2704 collection_(snapshot_->collection()), | 2744 collection_(snapshot_->collection()), |
2705 progress_(progress), | 2745 progress_(progress), |
2706 embedder_queried_(false), | 2746 embedder_queried_(false), |
2707 objects_by_info_(RetainedInfosMatch), | 2747 objects_by_info_(RetainedInfosMatch), |
2708 native_groups_(StringsMatch), | 2748 native_groups_(StringsMatch), |
2709 filler_(NULL) { | 2749 filler_(NULL) { |
| 2750 synthetic_entries_allocator_ = |
| 2751 new BasicHeapEntriesAllocator(snapshot, HeapEntry::kSynthetic); |
| 2752 native_entries_allocator_ = |
| 2753 new BasicHeapEntriesAllocator(snapshot, HeapEntry::kNative); |
2710 } | 2754 } |
2711 | 2755 |
2712 | 2756 |
2713 NativeObjectsExplorer::~NativeObjectsExplorer() { | 2757 NativeObjectsExplorer::~NativeObjectsExplorer() { |
2714 for (HashMap::Entry* p = objects_by_info_.Start(); | 2758 for (HashMap::Entry* p = objects_by_info_.Start(); |
2715 p != NULL; | 2759 p != NULL; |
2716 p = objects_by_info_.Next(p)) { | 2760 p = objects_by_info_.Next(p)) { |
2717 v8::RetainedObjectInfo* info = | 2761 v8::RetainedObjectInfo* info = |
2718 reinterpret_cast<v8::RetainedObjectInfo*>(p->key); | 2762 reinterpret_cast<v8::RetainedObjectInfo*>(p->key); |
2719 info->Dispose(); | 2763 info->Dispose(); |
2720 List<HeapObject*>* objects = | 2764 List<HeapObject*>* objects = |
2721 reinterpret_cast<List<HeapObject*>* >(p->value); | 2765 reinterpret_cast<List<HeapObject*>* >(p->value); |
2722 delete objects; | 2766 delete objects; |
2723 } | 2767 } |
2724 for (HashMap::Entry* p = native_groups_.Start(); | 2768 for (HashMap::Entry* p = native_groups_.Start(); |
2725 p != NULL; | 2769 p != NULL; |
2726 p = native_groups_.Next(p)) { | 2770 p = native_groups_.Next(p)) { |
2727 v8::RetainedObjectInfo* info = | 2771 v8::RetainedObjectInfo* info = |
2728 reinterpret_cast<v8::RetainedObjectInfo*>(p->value); | 2772 reinterpret_cast<v8::RetainedObjectInfo*>(p->value); |
2729 info->Dispose(); | 2773 info->Dispose(); |
2730 } | 2774 } |
| 2775 delete synthetic_entries_allocator_; |
| 2776 delete native_entries_allocator_; |
2731 } | 2777 } |
2732 | 2778 |
2733 | 2779 |
2734 HeapEntry* NativeObjectsExplorer::AllocateEntry( | |
2735 HeapThing ptr, int children_count, int retainers_count) { | |
2736 v8::RetainedObjectInfo* info = | |
2737 reinterpret_cast<v8::RetainedObjectInfo*>(ptr); | |
2738 intptr_t elements = info->GetElementCount(); | |
2739 intptr_t size = info->GetSizeInBytes(); | |
2740 return snapshot_->AddEntry( | |
2741 HeapEntry::kNative, | |
2742 elements != -1 ? | |
2743 collection_->names()->GetFormatted( | |
2744 "%s / %" V8_PTR_PREFIX "d entries", | |
2745 info->GetLabel(), | |
2746 info->GetElementCount()) : | |
2747 collection_->names()->GetCopy(info->GetLabel()), | |
2748 HeapObjectsMap::GenerateId(info), | |
2749 size != -1 ? static_cast<int>(size) : 0, | |
2750 children_count, | |
2751 retainers_count); | |
2752 } | |
2753 | |
2754 | |
2755 int NativeObjectsExplorer::EstimateObjectsCount() { | 2780 int NativeObjectsExplorer::EstimateObjectsCount() { |
2756 FillRetainedObjects(); | 2781 FillRetainedObjects(); |
2757 return objects_by_info_.occupancy(); | 2782 return objects_by_info_.occupancy(); |
2758 } | 2783 } |
2759 | 2784 |
2760 | 2785 |
2761 void NativeObjectsExplorer::FillRetainedObjects() { | 2786 void NativeObjectsExplorer::FillRetainedObjects() { |
2762 if (embedder_queried_) return; | 2787 if (embedder_queried_) return; |
2763 Isolate* isolate = Isolate::Current(); | 2788 Isolate* isolate = Isolate::Current(); |
2764 // Record objects that are joined into ObjectGroups. | 2789 // Record objects that are joined into ObjectGroups. |
(...skipping 18 matching lines...) Expand all Loading... |
2783 embedder_queried_ = true; | 2808 embedder_queried_ = true; |
2784 } | 2809 } |
2785 | 2810 |
2786 void NativeObjectsExplorer::FillImplicitReferences() { | 2811 void NativeObjectsExplorer::FillImplicitReferences() { |
2787 Isolate* isolate = Isolate::Current(); | 2812 Isolate* isolate = Isolate::Current(); |
2788 List<ImplicitRefGroup*>* groups = | 2813 List<ImplicitRefGroup*>* groups = |
2789 isolate->global_handles()->implicit_ref_groups(); | 2814 isolate->global_handles()->implicit_ref_groups(); |
2790 for (int i = 0; i < groups->length(); ++i) { | 2815 for (int i = 0; i < groups->length(); ++i) { |
2791 ImplicitRefGroup* group = groups->at(i); | 2816 ImplicitRefGroup* group = groups->at(i); |
2792 HeapObject* parent = *group->parent_; | 2817 HeapObject* parent = *group->parent_; |
2793 HeapEntry* parent_entry = filler_->FindOrAddEntry(parent, this); | 2818 HeapEntry* parent_entry = |
| 2819 filler_->FindOrAddEntry(parent, native_entries_allocator_); |
2794 ASSERT(parent_entry != NULL); | 2820 ASSERT(parent_entry != NULL); |
2795 Object*** children = group->children_; | 2821 Object*** children = group->children_; |
2796 for (size_t j = 0; j < group->length_; ++j) { | 2822 for (size_t j = 0; j < group->length_; ++j) { |
2797 Object* child = *children[j]; | 2823 Object* child = *children[j]; |
2798 HeapEntry* child_entry = filler_->FindOrAddEntry(child, this); | 2824 HeapEntry* child_entry = |
| 2825 filler_->FindOrAddEntry(child, native_entries_allocator_); |
2799 filler_->SetNamedReference( | 2826 filler_->SetNamedReference( |
2800 HeapGraphEdge::kInternal, | 2827 HeapGraphEdge::kInternal, |
2801 parent, parent_entry, | 2828 parent, parent_entry, |
2802 "native", | 2829 "native", |
2803 child, child_entry); | 2830 child, child_entry); |
2804 } | 2831 } |
2805 } | 2832 } |
2806 } | 2833 } |
2807 | 2834 |
2808 List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo( | 2835 List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2879 HashMap::Entry* entry = native_groups_.Lookup(const_cast<char*>(label_copy), | 2906 HashMap::Entry* entry = native_groups_.Lookup(const_cast<char*>(label_copy), |
2880 hash, true); | 2907 hash, true); |
2881 if (entry->value == NULL) | 2908 if (entry->value == NULL) |
2882 entry->value = new NativeGroupRetainedObjectInfo(label); | 2909 entry->value = new NativeGroupRetainedObjectInfo(label); |
2883 return static_cast<NativeGroupRetainedObjectInfo*>(entry->value); | 2910 return static_cast<NativeGroupRetainedObjectInfo*>(entry->value); |
2884 } | 2911 } |
2885 | 2912 |
2886 | 2913 |
2887 void NativeObjectsExplorer::SetNativeRootReference( | 2914 void NativeObjectsExplorer::SetNativeRootReference( |
2888 v8::RetainedObjectInfo* info) { | 2915 v8::RetainedObjectInfo* info) { |
2889 HeapEntry* child_entry = filler_->FindOrAddEntry(info, this); | 2916 HeapEntry* child_entry = |
| 2917 filler_->FindOrAddEntry(info, native_entries_allocator_); |
2890 ASSERT(child_entry != NULL); | 2918 ASSERT(child_entry != NULL); |
2891 NativeGroupRetainedObjectInfo* group_info = | 2919 NativeGroupRetainedObjectInfo* group_info = |
2892 FindOrAddGroupInfo(info->GetGroupLabel()); | 2920 FindOrAddGroupInfo(info->GetGroupLabel()); |
2893 HeapEntry* group_entry = filler_->FindOrAddEntry(group_info, this); | 2921 HeapEntry* group_entry = |
| 2922 filler_->FindOrAddEntry(group_info, synthetic_entries_allocator_); |
2894 filler_->SetNamedAutoIndexReference( | 2923 filler_->SetNamedAutoIndexReference( |
2895 HeapGraphEdge::kInternal, | 2924 HeapGraphEdge::kInternal, |
2896 group_info, group_entry, | 2925 group_info, group_entry, |
2897 info, child_entry); | 2926 info, child_entry); |
2898 } | 2927 } |
2899 | 2928 |
2900 | 2929 |
2901 void NativeObjectsExplorer::SetWrapperNativeReferences( | 2930 void NativeObjectsExplorer::SetWrapperNativeReferences( |
2902 HeapObject* wrapper, v8::RetainedObjectInfo* info) { | 2931 HeapObject* wrapper, v8::RetainedObjectInfo* info) { |
2903 HeapEntry* wrapper_entry = filler_->FindEntry(wrapper); | 2932 HeapEntry* wrapper_entry = filler_->FindEntry(wrapper); |
2904 ASSERT(wrapper_entry != NULL); | 2933 ASSERT(wrapper_entry != NULL); |
2905 HeapEntry* info_entry = filler_->FindOrAddEntry(info, this); | 2934 HeapEntry* info_entry = |
| 2935 filler_->FindOrAddEntry(info, native_entries_allocator_); |
2906 ASSERT(info_entry != NULL); | 2936 ASSERT(info_entry != NULL); |
2907 filler_->SetNamedReference(HeapGraphEdge::kInternal, | 2937 filler_->SetNamedReference(HeapGraphEdge::kInternal, |
2908 wrapper, wrapper_entry, | 2938 wrapper, wrapper_entry, |
2909 "native", | 2939 "native", |
2910 info, info_entry); | 2940 info, info_entry); |
2911 filler_->SetIndexedAutoIndexReference(HeapGraphEdge::kElement, | 2941 filler_->SetIndexedAutoIndexReference(HeapGraphEdge::kElement, |
2912 info, info_entry, | 2942 info, info_entry, |
2913 wrapper, wrapper_entry); | 2943 wrapper, wrapper_entry); |
2914 } | 2944 } |
2915 | 2945 |
2916 | 2946 |
2917 void NativeObjectsExplorer::SetRootNativeRootsReference() { | 2947 void NativeObjectsExplorer::SetRootNativeRootsReference() { |
2918 for (HashMap::Entry* entry = native_groups_.Start(); | 2948 for (HashMap::Entry* entry = native_groups_.Start(); |
2919 entry; | 2949 entry; |
2920 entry = native_groups_.Next(entry)) { | 2950 entry = native_groups_.Next(entry)) { |
2921 NativeGroupRetainedObjectInfo* group_info = | 2951 NativeGroupRetainedObjectInfo* group_info = |
2922 static_cast<NativeGroupRetainedObjectInfo*>(entry->value); | 2952 static_cast<NativeGroupRetainedObjectInfo*>(entry->value); |
2923 HeapEntry* group_entry = filler_->FindOrAddEntry(group_info, this); | 2953 HeapEntry* group_entry = |
| 2954 filler_->FindOrAddEntry(group_info, native_entries_allocator_); |
2924 ASSERT(group_entry != NULL); | 2955 ASSERT(group_entry != NULL); |
2925 filler_->SetIndexedAutoIndexReference( | 2956 filler_->SetIndexedAutoIndexReference( |
2926 HeapGraphEdge::kElement, | 2957 HeapGraphEdge::kElement, |
2927 V8HeapExplorer::kInternalRootObject, snapshot_->root(), | 2958 V8HeapExplorer::kInternalRootObject, snapshot_->root(), |
2928 group_info, group_entry); | 2959 group_info, group_entry); |
2929 } | 2960 } |
2930 } | 2961 } |
2931 | 2962 |
2932 | 2963 |
2933 void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) { | 2964 void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) { |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3540 "," JSON_S("types") ":" JSON_A( | 3571 "," JSON_S("types") ":" JSON_A( |
3541 JSON_A( | 3572 JSON_A( |
3542 JSON_S("hidden") | 3573 JSON_S("hidden") |
3543 "," JSON_S("array") | 3574 "," JSON_S("array") |
3544 "," JSON_S("string") | 3575 "," JSON_S("string") |
3545 "," JSON_S("object") | 3576 "," JSON_S("object") |
3546 "," JSON_S("code") | 3577 "," JSON_S("code") |
3547 "," JSON_S("closure") | 3578 "," JSON_S("closure") |
3548 "," JSON_S("regexp") | 3579 "," JSON_S("regexp") |
3549 "," JSON_S("number") | 3580 "," JSON_S("number") |
3550 "," JSON_S("native")) | 3581 "," JSON_S("native") |
| 3582 "," JSON_S("synthetic")) |
3551 "," JSON_S("string") | 3583 "," JSON_S("string") |
3552 "," JSON_S("number") | 3584 "," JSON_S("number") |
3553 "," JSON_S("number") | 3585 "," JSON_S("number") |
3554 "," JSON_S("number") | 3586 "," JSON_S("number") |
3555 "," JSON_S("number") | 3587 "," JSON_S("number") |
3556 "," JSON_S("number") | 3588 "," JSON_S("number") |
3557 "," JSON_O( | 3589 "," JSON_O( |
3558 JSON_S("fields") ":" JSON_A( | 3590 JSON_S("fields") ":" JSON_A( |
3559 JSON_S("type") | 3591 JSON_S("type") |
3560 "," JSON_S("name_or_index") | 3592 "," JSON_S("name_or_index") |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3695 | 3727 |
3696 | 3728 |
3697 void HeapSnapshotJSONSerializer::SortHashMap( | 3729 void HeapSnapshotJSONSerializer::SortHashMap( |
3698 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3730 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
3699 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3731 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
3700 sorted_entries->Add(p); | 3732 sorted_entries->Add(p); |
3701 sorted_entries->Sort(SortUsingEntryValue); | 3733 sorted_entries->Sort(SortUsingEntryValue); |
3702 } | 3734 } |
3703 | 3735 |
3704 } } // namespace v8::internal | 3736 } } // namespace v8::internal |
OLD | NEW |