From 0634c50950a9e94f0615f6e43b0907341923458a Mon Sep 17 00:00:00 2001 From: "mikhail.naganov@gmail.com" Date: Wed, 24 Nov 2010 10:47:18 +0000 Subject: [PATCH] New Heap profiler: fix JSON serialization of aggregated profiles. Serialization was failing due to unset dominator pointers. TEST=test-heap-snapshot/AggregatedHeapSnapshotJSONSerialization Review URL: http://codereview.chromium.org/5314003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5888 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/heap-profiler.cc | 2 ++ src/profile-generator.cc | 13 +++++++++---- src/profile-generator.h | 1 + test/cctest/test-heap-profiler.cc | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/heap-profiler.cc b/src/heap-profiler.cc index 3fb1ec1..73a2fc5 100644 --- a/src/heap-profiler.cc +++ b/src/heap-profiler.cc @@ -1064,6 +1064,8 @@ void AggregatedHeapSnapshotGenerator::FillHeapSnapshot(HeapSnapshot* snapshot) { // Fill up references. IterateRetainers(&entries_map); + + snapshot->SetDominatorsToSelf(); } diff --git a/src/profile-generator.cc b/src/profile-generator.cc index e0b63f9..33e3527 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -1462,6 +1462,14 @@ void HeapSnapshot::BuildDominatorTree(const Vector& entries, } +void HeapSnapshot::SetDominatorsToSelf() { + for (int i = 0; i < entries_.length(); ++i) { + HeapEntry* entry = entries_[i]; + if (entry->dominator() == NULL) entry->set_dominator(entry); + } +} + + void HeapSnapshot::SetEntriesDominators() { // This array is used for maintaining reverse postorder of nodes. ScopedVector ordered_entries(entries_.length()); @@ -1473,10 +1481,7 @@ void HeapSnapshot::SetEntriesDominators() { ordered_entries[i]->set_dominator(dominators[i]); } // For nodes unreachable from root, set dominator to itself. - for (int i = 0; i < entries_.length(); ++i) { - HeapEntry* entry = entries_[i]; - if (entry->dominator() == NULL) entry->set_dominator(entry); - } + SetDominatorsToSelf(); } diff --git a/src/profile-generator.h b/src/profile-generator.h index 30d70a2..d5f139f 100644 --- a/src/profile-generator.h +++ b/src/profile-generator.h @@ -700,6 +700,7 @@ class HeapSnapshot { List* GetSortedEntriesList(); template void IterateEntries(Visitor* visitor) { entries_.Iterate(visitor); } + void SetDominatorsToSelf(); void Print(int max_depth); void PrintEntriesSize(); diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 4dd7fe8..95314d7 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -1178,4 +1178,19 @@ TEST(HeapSnapshotJSONSerializationAborting) { CHECK_EQ(0, stream.eos_signaled()); } + +// Must not crash in debug mode. +TEST(AggregatedHeapSnapshotJSONSerialization) { + v8::HandleScope scope; + LocalContext env; + + const v8::HeapSnapshot* snapshot = + v8::HeapProfiler::TakeSnapshot( + v8::String::New("agg"), v8::HeapSnapshot::kAggregated); + TestJSONStream stream; + snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); + CHECK_GT(stream.size(), 0); + CHECK_EQ(1, stream.eos_signaled()); +} + #endif // ENABLE_LOGGING_AND_PROFILING -- 2.7.4