Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/heap-profiler.cc

Issue 6697023: Merge 6800:7180 from the bleeding edge branch to the experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap-profiler.h ('k') | src/hydrogen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 357
358 358
359 HeapSnapshot* HeapProfiler::TakeSnapshot(String* name, 359 HeapSnapshot* HeapProfiler::TakeSnapshot(String* name,
360 int type, 360 int type,
361 v8::ActivityControl* control) { 361 v8::ActivityControl* control) {
362 ASSERT(singleton_ != NULL); 362 ASSERT(singleton_ != NULL);
363 return singleton_->TakeSnapshotImpl(name, type, control); 363 return singleton_->TakeSnapshotImpl(name, type, control);
364 } 364 }
365 365
366 366
367 void HeapProfiler::DefineWrapperClass(
368 uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) {
369 ASSERT(singleton_ != NULL);
370 ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId);
371 if (singleton_->wrapper_callbacks_.length() <= class_id) {
372 singleton_->wrapper_callbacks_.AddBlock(
373 NULL, class_id - singleton_->wrapper_callbacks_.length() + 1);
374 }
375 singleton_->wrapper_callbacks_[class_id] = callback;
376 }
377
378
379 v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback(
380 uint16_t class_id, Object** wrapper) {
381 ASSERT(singleton_ != NULL);
382 if (singleton_->wrapper_callbacks_.length() <= class_id) return NULL;
383 return singleton_->wrapper_callbacks_[class_id](
384 class_id, Utils::ToLocal(Handle<Object>(wrapper)));
385 }
386
387
367 HeapSnapshot* HeapProfiler::TakeSnapshotImpl(const char* name, 388 HeapSnapshot* HeapProfiler::TakeSnapshotImpl(const char* name,
368 int type, 389 int type,
369 v8::ActivityControl* control) { 390 v8::ActivityControl* control) {
370 HeapSnapshot::Type s_type = static_cast<HeapSnapshot::Type>(type); 391 HeapSnapshot::Type s_type = static_cast<HeapSnapshot::Type>(type);
371 HeapSnapshot* result = 392 HeapSnapshot* result =
372 snapshots_->NewSnapshot(s_type, name, next_snapshot_uid_++); 393 snapshots_->NewSnapshot(s_type, name, next_snapshot_uid_++);
373 bool generation_completed = true; 394 bool generation_completed = true;
374 switch (s_type) { 395 switch (s_type) {
375 case HeapSnapshot::kFull: { 396 case HeapSnapshot::kFull: {
376 Heap::CollectAllGarbage(true); 397 Heap::CollectAllGarbage(true);
(...skipping 17 matching lines...) Expand all
394 result = NULL; 415 result = NULL;
395 } 416 }
396 snapshots_->SnapshotGenerationFinished(result); 417 snapshots_->SnapshotGenerationFinished(result);
397 return result; 418 return result;
398 } 419 }
399 420
400 421
401 HeapSnapshot* HeapProfiler::TakeSnapshotImpl(String* name, 422 HeapSnapshot* HeapProfiler::TakeSnapshotImpl(String* name,
402 int type, 423 int type,
403 v8::ActivityControl* control) { 424 v8::ActivityControl* control) {
404 return TakeSnapshotImpl(snapshots_->GetName(name), type, control); 425 return TakeSnapshotImpl(snapshots_->names()->GetName(name), type, control);
405 } 426 }
406 427
407 428
408 int HeapProfiler::GetSnapshotsCount() { 429 int HeapProfiler::GetSnapshotsCount() {
409 ASSERT(singleton_ != NULL); 430 ASSERT(singleton_ != NULL);
410 return singleton_->snapshots_->snapshots()->length(); 431 return singleton_->snapshots_->snapshots()->length();
411 } 432 }
412 433
413 434
414 HeapSnapshot* HeapProfiler::GetSnapshot(int index) { 435 HeapSnapshot* HeapProfiler::GetSnapshot(int index) {
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 AllocatingConstructorHeapProfileIterator(HeapSnapshot* snapshot, 886 AllocatingConstructorHeapProfileIterator(HeapSnapshot* snapshot,
866 int* root_child_index) 887 int* root_child_index)
867 : snapshot_(snapshot), 888 : snapshot_(snapshot),
868 root_child_index_(root_child_index) { 889 root_child_index_(root_child_index) {
869 } 890 }
870 891
871 void Call(const JSObjectsCluster& cluster, 892 void Call(const JSObjectsCluster& cluster,
872 const NumberAndSizeInfo& number_and_size) { 893 const NumberAndSizeInfo& number_and_size) {
873 const char* name = cluster.GetSpecialCaseName(); 894 const char* name = cluster.GetSpecialCaseName();
874 if (name == NULL) { 895 if (name == NULL) {
875 name = snapshot_->collection()->GetFunctionName(cluster.constructor()); 896 name = snapshot_->collection()->names()->GetFunctionName(
897 cluster.constructor());
876 } 898 }
877 AddEntryFromAggregatedSnapshot(snapshot_, 899 AddEntryFromAggregatedSnapshot(snapshot_,
878 root_child_index_, 900 root_child_index_,
879 HeapEntry::kObject, 901 HeapEntry::kObject,
880 name, 902 name,
881 number_and_size.number(), 903 number_and_size.number(),
882 number_and_size.bytes(), 904 number_and_size.bytes(),
883 0, 905 0,
884 0); 906 0);
885 } 907 }
(...skipping 18 matching lines...) Expand all
904 String* constructor = GetConstructorNameForHeapProfile( 926 String* constructor = GetConstructorNameForHeapProfile(
905 JSObject::cast(js_obj)); 927 JSObject::cast(js_obj));
906 return JSObjectsCluster(constructor, object); 928 return JSObjectsCluster(constructor, object);
907 } 929 }
908 } 930 }
909 931
910 932
911 class CountingRetainersIterator { 933 class CountingRetainersIterator {
912 public: 934 public:
913 CountingRetainersIterator(const JSObjectsCluster& child_cluster, 935 CountingRetainersIterator(const JSObjectsCluster& child_cluster,
936 HeapEntriesAllocator* allocator,
914 HeapEntriesMap* map) 937 HeapEntriesMap* map)
915 : child_(ClusterAsHeapObject(child_cluster)), map_(map) { 938 : child_(ClusterAsHeapObject(child_cluster)),
939 allocator_(allocator),
940 map_(map) {
916 if (map_->Map(child_) == NULL) 941 if (map_->Map(child_) == NULL)
917 map_->Pair(child_, HeapEntriesMap::kHeapEntryPlaceholder); 942 map_->Pair(child_, allocator_, HeapEntriesMap::kHeapEntryPlaceholder);
918 } 943 }
919 944
920 void Call(const JSObjectsCluster& cluster, 945 void Call(const JSObjectsCluster& cluster,
921 const NumberAndSizeInfo& number_and_size) { 946 const NumberAndSizeInfo& number_and_size) {
922 if (map_->Map(ClusterAsHeapObject(cluster)) == NULL) 947 if (map_->Map(ClusterAsHeapObject(cluster)) == NULL)
923 map_->Pair(ClusterAsHeapObject(cluster), 948 map_->Pair(ClusterAsHeapObject(cluster),
949 allocator_,
924 HeapEntriesMap::kHeapEntryPlaceholder); 950 HeapEntriesMap::kHeapEntryPlaceholder);
925 map_->CountReference(ClusterAsHeapObject(cluster), child_); 951 map_->CountReference(ClusterAsHeapObject(cluster), child_);
926 } 952 }
927 953
928 private: 954 private:
929 HeapObject* child_; 955 HeapObject* child_;
956 HeapEntriesAllocator* allocator_;
930 HeapEntriesMap* map_; 957 HeapEntriesMap* map_;
931 }; 958 };
932 959
933 960
934 class AllocatingRetainersIterator { 961 class AllocatingRetainersIterator {
935 public: 962 public:
936 AllocatingRetainersIterator(const JSObjectsCluster& child_cluster, 963 AllocatingRetainersIterator(const JSObjectsCluster& child_cluster,
964 HeapEntriesAllocator*,
937 HeapEntriesMap* map) 965 HeapEntriesMap* map)
938 : child_(ClusterAsHeapObject(child_cluster)), map_(map) { 966 : child_(ClusterAsHeapObject(child_cluster)), map_(map) {
939 child_entry_ = map_->Map(child_); 967 child_entry_ = map_->Map(child_);
940 ASSERT(child_entry_ != NULL); 968 ASSERT(child_entry_ != NULL);
941 } 969 }
942 970
943 void Call(const JSObjectsCluster& cluster, 971 void Call(const JSObjectsCluster& cluster,
944 const NumberAndSizeInfo& number_and_size) { 972 const NumberAndSizeInfo& number_and_size) {
945 int child_index, retainer_index; 973 int child_index, retainer_index;
946 map_->CountReference(ClusterAsHeapObject(cluster), 974 map_->CountReference(ClusterAsHeapObject(cluster),
(...skipping 12 matching lines...) Expand all
959 HeapObject* child_; 987 HeapObject* child_;
960 HeapEntriesMap* map_; 988 HeapEntriesMap* map_;
961 HeapEntry* child_entry_; 989 HeapEntry* child_entry_;
962 }; 990 };
963 991
964 992
965 template<class RetainersIterator> 993 template<class RetainersIterator>
966 class AggregatingRetainerTreeIterator { 994 class AggregatingRetainerTreeIterator {
967 public: 995 public:
968 explicit AggregatingRetainerTreeIterator(ClustersCoarser* coarser, 996 explicit AggregatingRetainerTreeIterator(ClustersCoarser* coarser,
997 HeapEntriesAllocator* allocator,
969 HeapEntriesMap* map) 998 HeapEntriesMap* map)
970 : coarser_(coarser), map_(map) { 999 : coarser_(coarser), allocator_(allocator), map_(map) {
971 } 1000 }
972 1001
973 void Call(const JSObjectsCluster& cluster, JSObjectsClusterTree* tree) { 1002 void Call(const JSObjectsCluster& cluster, JSObjectsClusterTree* tree) {
974 if (coarser_ != NULL && 1003 if (coarser_ != NULL &&
975 !coarser_->GetCoarseEquivalent(cluster).is_null()) return; 1004 !coarser_->GetCoarseEquivalent(cluster).is_null()) return;
976 JSObjectsClusterTree* tree_to_iterate = tree; 1005 JSObjectsClusterTree* tree_to_iterate = tree;
977 ZoneScope zs(DELETE_ON_EXIT); 1006 ZoneScope zs(DELETE_ON_EXIT);
978 JSObjectsClusterTree dest_tree_; 1007 JSObjectsClusterTree dest_tree_;
979 if (coarser_ != NULL) { 1008 if (coarser_ != NULL) {
980 RetainersAggregator retainers_aggregator(coarser_, &dest_tree_); 1009 RetainersAggregator retainers_aggregator(coarser_, &dest_tree_);
981 tree->ForEach(&retainers_aggregator); 1010 tree->ForEach(&retainers_aggregator);
982 tree_to_iterate = &dest_tree_; 1011 tree_to_iterate = &dest_tree_;
983 } 1012 }
984 RetainersIterator iterator(cluster, map_); 1013 RetainersIterator iterator(cluster, allocator_, map_);
985 tree_to_iterate->ForEach(&iterator); 1014 tree_to_iterate->ForEach(&iterator);
986 } 1015 }
987 1016
988 private: 1017 private:
989 ClustersCoarser* coarser_; 1018 ClustersCoarser* coarser_;
1019 HeapEntriesAllocator* allocator_;
990 HeapEntriesMap* map_; 1020 HeapEntriesMap* map_;
991 }; 1021 };
992 1022
993 1023
994 class AggregatedRetainerTreeAllocator { 1024 class AggregatedRetainerTreeAllocator : public HeapEntriesAllocator {
995 public: 1025 public:
996 AggregatedRetainerTreeAllocator(HeapSnapshot* snapshot, 1026 AggregatedRetainerTreeAllocator(HeapSnapshot* snapshot,
997 int* root_child_index) 1027 int* root_child_index)
998 : snapshot_(snapshot), root_child_index_(root_child_index) { 1028 : snapshot_(snapshot), root_child_index_(root_child_index) {
999 } 1029 }
1030 ~AggregatedRetainerTreeAllocator() { }
1000 1031
1001 HeapEntry* GetEntry( 1032 HeapEntry* AllocateEntry(
1002 HeapObject* obj, int children_count, int retainers_count) { 1033 HeapThing ptr, int children_count, int retainers_count) {
1034 HeapObject* obj = reinterpret_cast<HeapObject*>(ptr);
1003 JSObjectsCluster cluster = HeapObjectAsCluster(obj); 1035 JSObjectsCluster cluster = HeapObjectAsCluster(obj);
1004 const char* name = cluster.GetSpecialCaseName(); 1036 const char* name = cluster.GetSpecialCaseName();
1005 if (name == NULL) { 1037 if (name == NULL) {
1006 name = snapshot_->collection()->GetFunctionName(cluster.constructor()); 1038 name = snapshot_->collection()->names()->GetFunctionName(
1039 cluster.constructor());
1007 } 1040 }
1008 return AddEntryFromAggregatedSnapshot( 1041 return AddEntryFromAggregatedSnapshot(
1009 snapshot_, root_child_index_, HeapEntry::kObject, name, 1042 snapshot_, root_child_index_, HeapEntry::kObject, name,
1010 0, 0, children_count, retainers_count); 1043 0, 0, children_count, retainers_count);
1011 } 1044 }
1012 1045
1013 private: 1046 private:
1014 HeapSnapshot* snapshot_; 1047 HeapSnapshot* snapshot_;
1015 int* root_child_index_; 1048 int* root_child_index_;
1016 }; 1049 };
1017 1050
1018 1051
1019 template<class Iterator> 1052 template<class Iterator>
1020 void AggregatedHeapSnapshotGenerator::IterateRetainers( 1053 void AggregatedHeapSnapshotGenerator::IterateRetainers(
1021 HeapEntriesMap* entries_map) { 1054 HeapEntriesAllocator* allocator, HeapEntriesMap* entries_map) {
1022 RetainerHeapProfile* p = agg_snapshot_->js_retainer_profile(); 1055 RetainerHeapProfile* p = agg_snapshot_->js_retainer_profile();
1023 AggregatingRetainerTreeIterator<Iterator> agg_ret_iter_1( 1056 AggregatingRetainerTreeIterator<Iterator> agg_ret_iter_1(
1024 p->coarser(), entries_map); 1057 p->coarser(), allocator, entries_map);
1025 p->retainers_tree()->ForEach(&agg_ret_iter_1); 1058 p->retainers_tree()->ForEach(&agg_ret_iter_1);
1026 AggregatingRetainerTreeIterator<Iterator> agg_ret_iter_2(NULL, entries_map); 1059 AggregatingRetainerTreeIterator<Iterator> agg_ret_iter_2(
1060 NULL, allocator, entries_map);
1027 p->aggregator()->output_tree().ForEach(&agg_ret_iter_2); 1061 p->aggregator()->output_tree().ForEach(&agg_ret_iter_2);
1028 } 1062 }
1029 1063
1030 1064
1031 void AggregatedHeapSnapshotGenerator::FillHeapSnapshot(HeapSnapshot* snapshot) { 1065 void AggregatedHeapSnapshotGenerator::FillHeapSnapshot(HeapSnapshot* snapshot) {
1032 // Count the number of entities. 1066 // Count the number of entities.
1033 int histogram_entities_count = 0; 1067 int histogram_entities_count = 0;
1034 int histogram_children_count = 0; 1068 int histogram_children_count = 0;
1035 int histogram_retainers_count = 0; 1069 int histogram_retainers_count = 0;
1036 for (int i = FIRST_NONSTRING_TYPE; i <= kAllStringsType; ++i) { 1070 for (int i = FIRST_NONSTRING_TYPE; i <= kAllStringsType; ++i) {
1037 if (agg_snapshot_->info()[i].bytes() > 0) { 1071 if (agg_snapshot_->info()[i].bytes() > 0) {
1038 ++histogram_entities_count; 1072 ++histogram_entities_count;
1039 } 1073 }
1040 } 1074 }
1041 CountingConstructorHeapProfileIterator counting_cons_iter; 1075 CountingConstructorHeapProfileIterator counting_cons_iter;
1042 agg_snapshot_->js_cons_profile()->ForEach(&counting_cons_iter); 1076 agg_snapshot_->js_cons_profile()->ForEach(&counting_cons_iter);
1043 histogram_entities_count += counting_cons_iter.entities_count(); 1077 histogram_entities_count += counting_cons_iter.entities_count();
1044 HeapEntriesMap entries_map; 1078 HeapEntriesMap entries_map;
1045 IterateRetainers<CountingRetainersIterator>(&entries_map); 1079 int root_child_index = 0;
1080 AggregatedRetainerTreeAllocator allocator(snapshot, &root_child_index);
1081 IterateRetainers<CountingRetainersIterator>(&allocator, &entries_map);
1046 histogram_entities_count += entries_map.entries_count(); 1082 histogram_entities_count += entries_map.entries_count();
1047 histogram_children_count += entries_map.total_children_count(); 1083 histogram_children_count += entries_map.total_children_count();
1048 histogram_retainers_count += entries_map.total_retainers_count(); 1084 histogram_retainers_count += entries_map.total_retainers_count();
1049 1085
1050 // Root entry references all other entries. 1086 // Root entry references all other entries.
1051 histogram_children_count += histogram_entities_count; 1087 histogram_children_count += histogram_entities_count;
1052 int root_children_count = histogram_entities_count; 1088 int root_children_count = histogram_entities_count;
1053 ++histogram_entities_count; 1089 ++histogram_entities_count;
1054 1090
1055 // Allocate and fill entries in the snapshot, allocate references. 1091 // Allocate and fill entries in the snapshot, allocate references.
1056 snapshot->AllocateEntries(histogram_entities_count, 1092 snapshot->AllocateEntries(histogram_entities_count,
1057 histogram_children_count, 1093 histogram_children_count,
1058 histogram_retainers_count); 1094 histogram_retainers_count);
1059 snapshot->AddEntry(HeapSnapshot::kInternalRootObject, 1095 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) { 1096 for (int i = FIRST_NONSTRING_TYPE; i <= kAllStringsType; ++i) {
1064 if (agg_snapshot_->info()[i].bytes() > 0) { 1097 if (agg_snapshot_->info()[i].bytes() > 0) {
1065 AddEntryFromAggregatedSnapshot(snapshot, 1098 AddEntryFromAggregatedSnapshot(snapshot,
1066 &root_child_index, 1099 &root_child_index,
1067 HeapEntry::kHidden, 1100 HeapEntry::kHidden,
1068 agg_snapshot_->info()[i].name(), 1101 agg_snapshot_->info()[i].name(),
1069 agg_snapshot_->info()[i].number(), 1102 agg_snapshot_->info()[i].number(),
1070 agg_snapshot_->info()[i].bytes(), 1103 agg_snapshot_->info()[i].bytes(),
1071 0, 1104 0,
1072 0); 1105 0);
1073 } 1106 }
1074 } 1107 }
1075 AllocatingConstructorHeapProfileIterator alloc_cons_iter( 1108 AllocatingConstructorHeapProfileIterator alloc_cons_iter(
1076 snapshot, &root_child_index); 1109 snapshot, &root_child_index);
1077 agg_snapshot_->js_cons_profile()->ForEach(&alloc_cons_iter); 1110 agg_snapshot_->js_cons_profile()->ForEach(&alloc_cons_iter);
1078 AggregatedRetainerTreeAllocator allocator(snapshot, &root_child_index); 1111 entries_map.AllocateEntries();
1079 entries_map.UpdateEntries(&allocator);
1080 1112
1081 // Fill up references. 1113 // Fill up references.
1082 IterateRetainers<AllocatingRetainersIterator>(&entries_map); 1114 IterateRetainers<AllocatingRetainersIterator>(&allocator, &entries_map);
1083 1115
1084 snapshot->SetDominatorsToSelf(); 1116 snapshot->SetDominatorsToSelf();
1085 } 1117 }
1086 1118
1087 1119
1088 bool ProducerHeapProfile::can_log_ = false; 1120 bool ProducerHeapProfile::can_log_ = false;
1089 1121
1090 void ProducerHeapProfile::Setup() { 1122 void ProducerHeapProfile::Setup() {
1091 can_log_ = true; 1123 can_log_ = true;
1092 } 1124 }
(...skipping 17 matching lines...) Expand all
1110 GlobalHandles::MakeWeak(handle.location(), 1142 GlobalHandles::MakeWeak(handle.location(),
1111 static_cast<void*>(stack.start()), 1143 static_cast<void*>(stack.start()),
1112 StackWeakReferenceCallback); 1144 StackWeakReferenceCallback);
1113 } 1145 }
1114 1146
1115 1147
1116 #endif // ENABLE_LOGGING_AND_PROFILING 1148 #endif // ENABLE_LOGGING_AND_PROFILING
1117 1149
1118 1150
1119 } } // namespace v8::internal 1151 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap-profiler.h ('k') | src/hydrogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698