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
parent 5bfbeddf
......@@ -1064,6 +1064,8 @@ void AggregatedHeapSnapshotGenerator::FillHeapSnapshot(HeapSnapshot* snapshot) {
// Fill up references.
IterateRetainers<AllocatingRetainersIterator>(&entries_map);
snapshot->SetDominatorsToSelf();
}
......
......@@ -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();
}
......
......@@ -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();
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment