| OLD | NEW |
| 1 // Copyright 2009-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2009-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 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 String* constructor = GetConstructorNameForHeapProfile( | 911 String* constructor = GetConstructorNameForHeapProfile( |
| 912 JSObject::cast(js_obj)); | 912 JSObject::cast(js_obj)); |
| 913 return JSObjectsCluster(constructor, object); | 913 return JSObjectsCluster(constructor, object); |
| 914 } | 914 } |
| 915 } | 915 } |
| 916 | 916 |
| 917 | 917 |
| 918 class CountingRetainersIterator { | 918 class CountingRetainersIterator { |
| 919 public: | 919 public: |
| 920 CountingRetainersIterator(const JSObjectsCluster& child_cluster, | 920 CountingRetainersIterator(const JSObjectsCluster& child_cluster, |
| 921 HeapEntriesAllocator* allocator, |
| 921 HeapEntriesMap* map) | 922 HeapEntriesMap* map) |
| 922 : child_(ClusterAsHeapObject(child_cluster)), map_(map) { | 923 : child_(ClusterAsHeapObject(child_cluster)), |
| 924 allocator_(allocator), |
| 925 map_(map) { |
| 923 if (map_->Map(child_) == NULL) | 926 if (map_->Map(child_) == NULL) |
| 924 map_->Pair(child_, HeapEntriesMap::kHeapEntryPlaceholder); | 927 map_->Pair(child_, allocator_, HeapEntriesMap::kHeapEntryPlaceholder); |
| 925 } | 928 } |
| 926 | 929 |
| 927 void Call(const JSObjectsCluster& cluster, | 930 void Call(const JSObjectsCluster& cluster, |
| 928 const NumberAndSizeInfo& number_and_size) { | 931 const NumberAndSizeInfo& number_and_size) { |
| 929 if (map_->Map(ClusterAsHeapObject(cluster)) == NULL) | 932 if (map_->Map(ClusterAsHeapObject(cluster)) == NULL) |
| 930 map_->Pair(ClusterAsHeapObject(cluster), | 933 map_->Pair(ClusterAsHeapObject(cluster), |
| 934 allocator_, |
| 931 HeapEntriesMap::kHeapEntryPlaceholder); | 935 HeapEntriesMap::kHeapEntryPlaceholder); |
| 932 map_->CountReference(ClusterAsHeapObject(cluster), child_); | 936 map_->CountReference(ClusterAsHeapObject(cluster), child_); |
| 933 } | 937 } |
| 934 | 938 |
| 935 private: | 939 private: |
| 936 HeapObject* child_; | 940 HeapObject* child_; |
| 941 HeapEntriesAllocator* allocator_; |
| 937 HeapEntriesMap* map_; | 942 HeapEntriesMap* map_; |
| 938 }; | 943 }; |
| 939 | 944 |
| 940 | 945 |
| 941 class AllocatingRetainersIterator { | 946 class AllocatingRetainersIterator { |
| 942 public: | 947 public: |
| 943 AllocatingRetainersIterator(const JSObjectsCluster& child_cluster, | 948 AllocatingRetainersIterator(const JSObjectsCluster& child_cluster, |
| 949 HeapEntriesAllocator*, |
| 944 HeapEntriesMap* map) | 950 HeapEntriesMap* map) |
| 945 : child_(ClusterAsHeapObject(child_cluster)), map_(map) { | 951 : child_(ClusterAsHeapObject(child_cluster)), map_(map) { |
| 946 child_entry_ = map_->Map(child_); | 952 child_entry_ = map_->Map(child_); |
| 947 ASSERT(child_entry_ != NULL); | 953 ASSERT(child_entry_ != NULL); |
| 948 } | 954 } |
| 949 | 955 |
| 950 void Call(const JSObjectsCluster& cluster, | 956 void Call(const JSObjectsCluster& cluster, |
| 951 const NumberAndSizeInfo& number_and_size) { | 957 const NumberAndSizeInfo& number_and_size) { |
| 952 int child_index, retainer_index; | 958 int child_index, retainer_index; |
| 953 map_->CountReference(ClusterAsHeapObject(cluster), | 959 map_->CountReference(ClusterAsHeapObject(cluster), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 966 HeapObject* child_; | 972 HeapObject* child_; |
| 967 HeapEntriesMap* map_; | 973 HeapEntriesMap* map_; |
| 968 HeapEntry* child_entry_; | 974 HeapEntry* child_entry_; |
| 969 }; | 975 }; |
| 970 | 976 |
| 971 | 977 |
| 972 template<class RetainersIterator> | 978 template<class RetainersIterator> |
| 973 class AggregatingRetainerTreeIterator { | 979 class AggregatingRetainerTreeIterator { |
| 974 public: | 980 public: |
| 975 explicit AggregatingRetainerTreeIterator(ClustersCoarser* coarser, | 981 explicit AggregatingRetainerTreeIterator(ClustersCoarser* coarser, |
| 982 HeapEntriesAllocator* allocator, |
| 976 HeapEntriesMap* map) | 983 HeapEntriesMap* map) |
| 977 : coarser_(coarser), map_(map) { | 984 : coarser_(coarser), allocator_(allocator), map_(map) { |
| 978 } | 985 } |
| 979 | 986 |
| 980 void Call(const JSObjectsCluster& cluster, JSObjectsClusterTree* tree) { | 987 void Call(const JSObjectsCluster& cluster, JSObjectsClusterTree* tree) { |
| 981 if (coarser_ != NULL && | 988 if (coarser_ != NULL && |
| 982 !coarser_->GetCoarseEquivalent(cluster).is_null()) return; | 989 !coarser_->GetCoarseEquivalent(cluster).is_null()) return; |
| 983 JSObjectsClusterTree* tree_to_iterate = tree; | 990 JSObjectsClusterTree* tree_to_iterate = tree; |
| 984 ZoneScope zs(DELETE_ON_EXIT); | 991 ZoneScope zs(DELETE_ON_EXIT); |
| 985 JSObjectsClusterTree dest_tree_; | 992 JSObjectsClusterTree dest_tree_; |
| 986 if (coarser_ != NULL) { | 993 if (coarser_ != NULL) { |
| 987 RetainersAggregator retainers_aggregator(coarser_, &dest_tree_); | 994 RetainersAggregator retainers_aggregator(coarser_, &dest_tree_); |
| 988 tree->ForEach(&retainers_aggregator); | 995 tree->ForEach(&retainers_aggregator); |
| 989 tree_to_iterate = &dest_tree_; | 996 tree_to_iterate = &dest_tree_; |
| 990 } | 997 } |
| 991 RetainersIterator iterator(cluster, map_); | 998 RetainersIterator iterator(cluster, allocator_, map_); |
| 992 tree_to_iterate->ForEach(&iterator); | 999 tree_to_iterate->ForEach(&iterator); |
| 993 } | 1000 } |
| 994 | 1001 |
| 995 private: | 1002 private: |
| 996 ClustersCoarser* coarser_; | 1003 ClustersCoarser* coarser_; |
| 1004 HeapEntriesAllocator* allocator_; |
| 997 HeapEntriesMap* map_; | 1005 HeapEntriesMap* map_; |
| 998 }; | 1006 }; |
| 999 | 1007 |
| 1000 | 1008 |
| 1001 class AggregatedRetainerTreeAllocator { | 1009 class AggregatedRetainerTreeAllocator : public HeapEntriesAllocator { |
| 1002 public: | 1010 public: |
| 1003 AggregatedRetainerTreeAllocator(HeapSnapshot* snapshot, | 1011 AggregatedRetainerTreeAllocator(HeapSnapshot* snapshot, |
| 1004 int* root_child_index) | 1012 int* root_child_index) |
| 1005 : snapshot_(snapshot), root_child_index_(root_child_index) { | 1013 : snapshot_(snapshot), root_child_index_(root_child_index) { |
| 1006 } | 1014 } |
| 1015 ~AggregatedRetainerTreeAllocator() { } |
| 1007 | 1016 |
| 1008 HeapEntry* GetEntry( | 1017 HeapEntry* AllocateEntry( |
| 1009 HeapObject* obj, int children_count, int retainers_count) { | 1018 HeapThing ptr, int children_count, int retainers_count) { |
| 1019 HeapObject* obj = reinterpret_cast<HeapObject*>(ptr); |
| 1010 JSObjectsCluster cluster = HeapObjectAsCluster(obj); | 1020 JSObjectsCluster cluster = HeapObjectAsCluster(obj); |
| 1011 const char* name = cluster.GetSpecialCaseName(); | 1021 const char* name = cluster.GetSpecialCaseName(); |
| 1012 if (name == NULL) { | 1022 if (name == NULL) { |
| 1013 name = snapshot_->collection()->GetFunctionName(cluster.constructor()); | 1023 name = snapshot_->collection()->GetFunctionName(cluster.constructor()); |
| 1014 } | 1024 } |
| 1015 return AddEntryFromAggregatedSnapshot( | 1025 return AddEntryFromAggregatedSnapshot( |
| 1016 snapshot_, root_child_index_, HeapEntry::kObject, name, | 1026 snapshot_, root_child_index_, HeapEntry::kObject, name, |
| 1017 0, 0, children_count, retainers_count); | 1027 0, 0, children_count, retainers_count); |
| 1018 } | 1028 } |
| 1019 | 1029 |
| 1020 private: | 1030 private: |
| 1021 HeapSnapshot* snapshot_; | 1031 HeapSnapshot* snapshot_; |
| 1022 int* root_child_index_; | 1032 int* root_child_index_; |
| 1023 }; | 1033 }; |
| 1024 | 1034 |
| 1025 | 1035 |
| 1026 template<class Iterator> | 1036 template<class Iterator> |
| 1027 void AggregatedHeapSnapshotGenerator::IterateRetainers( | 1037 void AggregatedHeapSnapshotGenerator::IterateRetainers( |
| 1028 HeapEntriesMap* entries_map) { | 1038 HeapEntriesAllocator* allocator, HeapEntriesMap* entries_map) { |
| 1029 RetainerHeapProfile* p = agg_snapshot_->js_retainer_profile(); | 1039 RetainerHeapProfile* p = agg_snapshot_->js_retainer_profile(); |
| 1030 AggregatingRetainerTreeIterator<Iterator> agg_ret_iter_1( | 1040 AggregatingRetainerTreeIterator<Iterator> agg_ret_iter_1( |
| 1031 p->coarser(), entries_map); | 1041 p->coarser(), allocator, entries_map); |
| 1032 p->retainers_tree()->ForEach(&agg_ret_iter_1); | 1042 p->retainers_tree()->ForEach(&agg_ret_iter_1); |
| 1033 AggregatingRetainerTreeIterator<Iterator> agg_ret_iter_2(NULL, entries_map); | 1043 AggregatingRetainerTreeIterator<Iterator> agg_ret_iter_2( |
| 1044 NULL, allocator, entries_map); |
| 1034 p->aggregator()->output_tree().ForEach(&agg_ret_iter_2); | 1045 p->aggregator()->output_tree().ForEach(&agg_ret_iter_2); |
| 1035 } | 1046 } |
| 1036 | 1047 |
| 1037 | 1048 |
| 1038 void AggregatedHeapSnapshotGenerator::FillHeapSnapshot(HeapSnapshot* snapshot) { | 1049 void AggregatedHeapSnapshotGenerator::FillHeapSnapshot(HeapSnapshot* snapshot) { |
| 1039 // Count the number of entities. | 1050 // Count the number of entities. |
| 1040 int histogram_entities_count = 0; | 1051 int histogram_entities_count = 0; |
| 1041 int histogram_children_count = 0; | 1052 int histogram_children_count = 0; |
| 1042 int histogram_retainers_count = 0; | 1053 int histogram_retainers_count = 0; |
| 1043 for (int i = FIRST_NONSTRING_TYPE; i <= kAllStringsType; ++i) { | 1054 for (int i = FIRST_NONSTRING_TYPE; i <= kAllStringsType; ++i) { |
| 1044 if (agg_snapshot_->info()[i].bytes() > 0) { | 1055 if (agg_snapshot_->info()[i].bytes() > 0) { |
| 1045 ++histogram_entities_count; | 1056 ++histogram_entities_count; |
| 1046 } | 1057 } |
| 1047 } | 1058 } |
| 1048 CountingConstructorHeapProfileIterator counting_cons_iter; | 1059 CountingConstructorHeapProfileIterator counting_cons_iter; |
| 1049 agg_snapshot_->js_cons_profile()->ForEach(&counting_cons_iter); | 1060 agg_snapshot_->js_cons_profile()->ForEach(&counting_cons_iter); |
| 1050 histogram_entities_count += counting_cons_iter.entities_count(); | 1061 histogram_entities_count += counting_cons_iter.entities_count(); |
| 1051 HeapEntriesMap entries_map; | 1062 HeapEntriesMap entries_map; |
| 1052 IterateRetainers<CountingRetainersIterator>(&entries_map); | 1063 int root_child_index = 0; |
| 1064 AggregatedRetainerTreeAllocator allocator(snapshot, &root_child_index); |
| 1065 IterateRetainers<CountingRetainersIterator>(&allocator, &entries_map); |
| 1053 histogram_entities_count += entries_map.entries_count(); | 1066 histogram_entities_count += entries_map.entries_count(); |
| 1054 histogram_children_count += entries_map.total_children_count(); | 1067 histogram_children_count += entries_map.total_children_count(); |
| 1055 histogram_retainers_count += entries_map.total_retainers_count(); | 1068 histogram_retainers_count += entries_map.total_retainers_count(); |
| 1056 | 1069 |
| 1057 // Root entry references all other entries. | 1070 // Root entry references all other entries. |
| 1058 histogram_children_count += histogram_entities_count; | 1071 histogram_children_count += histogram_entities_count; |
| 1059 int root_children_count = histogram_entities_count; | 1072 int root_children_count = histogram_entities_count; |
| 1060 ++histogram_entities_count; | 1073 ++histogram_entities_count; |
| 1061 | 1074 |
| 1062 // Allocate and fill entries in the snapshot, allocate references. | 1075 // Allocate and fill entries in the snapshot, allocate references. |
| 1063 snapshot->AllocateEntries(histogram_entities_count, | 1076 snapshot->AllocateEntries(histogram_entities_count, |
| 1064 histogram_children_count, | 1077 histogram_children_count, |
| 1065 histogram_retainers_count); | 1078 histogram_retainers_count); |
| 1066 snapshot->AddEntry(HeapSnapshot::kInternalRootObject, | 1079 snapshot->AddRootEntry(root_children_count); |
| 1067 root_children_count, | |
| 1068 0); | |
| 1069 int root_child_index = 0; | |
| 1070 for (int i = FIRST_NONSTRING_TYPE; i <= kAllStringsType; ++i) { | 1080 for (int i = FIRST_NONSTRING_TYPE; i <= kAllStringsType; ++i) { |
| 1071 if (agg_snapshot_->info()[i].bytes() > 0) { | 1081 if (agg_snapshot_->info()[i].bytes() > 0) { |
| 1072 AddEntryFromAggregatedSnapshot(snapshot, | 1082 AddEntryFromAggregatedSnapshot(snapshot, |
| 1073 &root_child_index, | 1083 &root_child_index, |
| 1074 HeapEntry::kHidden, | 1084 HeapEntry::kHidden, |
| 1075 agg_snapshot_->info()[i].name(), | 1085 agg_snapshot_->info()[i].name(), |
| 1076 agg_snapshot_->info()[i].number(), | 1086 agg_snapshot_->info()[i].number(), |
| 1077 agg_snapshot_->info()[i].bytes(), | 1087 agg_snapshot_->info()[i].bytes(), |
| 1078 0, | 1088 0, |
| 1079 0); | 1089 0); |
| 1080 } | 1090 } |
| 1081 } | 1091 } |
| 1082 AllocatingConstructorHeapProfileIterator alloc_cons_iter( | 1092 AllocatingConstructorHeapProfileIterator alloc_cons_iter( |
| 1083 snapshot, &root_child_index); | 1093 snapshot, &root_child_index); |
| 1084 agg_snapshot_->js_cons_profile()->ForEach(&alloc_cons_iter); | 1094 agg_snapshot_->js_cons_profile()->ForEach(&alloc_cons_iter); |
| 1085 AggregatedRetainerTreeAllocator allocator(snapshot, &root_child_index); | 1095 entries_map.AllocateEntries(); |
| 1086 entries_map.UpdateEntries(&allocator); | |
| 1087 | 1096 |
| 1088 // Fill up references. | 1097 // Fill up references. |
| 1089 IterateRetainers<AllocatingRetainersIterator>(&entries_map); | 1098 IterateRetainers<AllocatingRetainersIterator>(&allocator, &entries_map); |
| 1090 | 1099 |
| 1091 snapshot->SetDominatorsToSelf(); | 1100 snapshot->SetDominatorsToSelf(); |
| 1092 } | 1101 } |
| 1093 | 1102 |
| 1094 | 1103 |
| 1095 void ProducerHeapProfile::Setup() { | 1104 void ProducerHeapProfile::Setup() { |
| 1096 can_log_ = true; | 1105 can_log_ = true; |
| 1097 } | 1106 } |
| 1098 | 1107 |
| 1099 void ProducerHeapProfile::DoRecordJSObjectAllocation(Object* obj) { | 1108 void ProducerHeapProfile::DoRecordJSObjectAllocation(Object* obj) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1115 isolate_->global_handles()->MakeWeak(handle.location(), | 1124 isolate_->global_handles()->MakeWeak(handle.location(), |
| 1116 static_cast<void*>(stack.start()), | 1125 static_cast<void*>(stack.start()), |
| 1117 StackWeakReferenceCallback); | 1126 StackWeakReferenceCallback); |
| 1118 } | 1127 } |
| 1119 | 1128 |
| 1120 | 1129 |
| 1121 #endif // ENABLE_LOGGING_AND_PROFILING | 1130 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1122 | 1131 |
| 1123 | 1132 |
| 1124 } } // namespace v8::internal | 1133 } } // namespace v8::internal |
| OLD | NEW |