New Heap profiler: fix JSON serialization of aggregated profiles.
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 24 Nov 2010 10:47:18 +0000 (10:47 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 24 Nov 2010 10:47:18 +0000 (10:47 +0000)
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
src/profile-generator.cc
src/profile-generator.h
test/cctest/test-heap-profiler.cc

index 3fb1ec1..73a2fc5 100644 (file)
@@ -1064,6 +1064,8 @@ void AggregatedHeapSnapshotGenerator::FillHeapSnapshot(HeapSnapshot* snapshot) {
 
   // Fill up references.
   IterateRetainers<AllocatingRetainersIterator>(&entries_map);
+
+  snapshot->SetDominatorsToSelf();
 }
 
 
index e0b63f9..33e3527 100644 (file)
@@ -1462,6 +1462,14 @@ void HeapSnapshot::BuildDominatorTree(const Vector<HeapEntry*>& 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<HeapEntry*> 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();
 }
 
 
index 30d70a2..d5f139f 100644 (file)
@@ -700,6 +700,7 @@ class HeapSnapshot {
   List<HeapEntry*>* GetSortedEntriesList();
   template<class Visitor>
   void IterateEntries(Visitor* visitor) { entries_.Iterate(visitor); }
+  void SetDominatorsToSelf();
 
   void Print(int max_depth);
   void PrintEntriesSize();
index 4dd7fe8..95314d7 100644 (file)
@@ -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