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