From: mikhail.naganov@gmail.com Date: Mon, 5 Sep 2011 07:37:52 +0000 (+0000) Subject: A temporary workaround for huge heap snapshots problem. X-Git-Tag: upstream/4.7.83~18576 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e90df2aad9cd416111b5ebe776b50a514b0c41d;p=platform%2Fupstream%2Fv8.git A temporary workaround for huge heap snapshots problem. Do not try to serialize them into JSON to avoid crashing / hanging DevTools. R=sgjesse@chromium.org BUG=v8:1658,89268 TEST=none Review URL: http://codereview.chromium.org/7832003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9123 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/profile-generator.cc b/src/profile-generator.cc index db9f8928d..74dfbf445 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -1195,12 +1195,9 @@ void HeapSnapshot::AllocateEntries(int entries_count, int children_count, int retainers_count) { ASSERT(raw_entries_ == NULL); - raw_entries_ = NewArray( - HeapEntry::EntriesSize(entries_count, children_count, retainers_count)); -#ifdef DEBUG raw_entries_size_ = HeapEntry::EntriesSize(entries_count, children_count, retainers_count); -#endif + raw_entries_ = NewArray(raw_entries_size_); } @@ -2984,10 +2981,19 @@ class OutputStreamWriter { bool aborted_; }; +const int HeapSnapshotJSONSerializer::kMaxSerializableSnapshotRawSize = + 256 * MB; + void HeapSnapshotJSONSerializer::Serialize(v8::OutputStream* stream) { ASSERT(writer_ == NULL); writer_ = new OutputStreamWriter(stream); + HeapSnapshot* original_snapshot = NULL; + if (snapshot_->raw_entries_size() >= kMaxSerializableSnapshotRawSize) { + // The snapshot is too big. Serialize a fake snapshot. + original_snapshot = snapshot_; + snapshot_ = CreateFakeSnapshot(); + } // Since nodes graph is cyclic, we need the first pass to enumerate // them. Strings can be serialized in one pass. EnumerateNodes(); @@ -2995,6 +3001,26 @@ void HeapSnapshotJSONSerializer::Serialize(v8::OutputStream* stream) { delete writer_; writer_ = NULL; + + if (original_snapshot != NULL) { + delete snapshot_; + snapshot_ = original_snapshot; + } +} + + +HeapSnapshot* HeapSnapshotJSONSerializer::CreateFakeSnapshot() { + HeapSnapshot* result = new HeapSnapshot(snapshot_->collection(), + HeapSnapshot::kFull, + snapshot_->title(), + snapshot_->uid()); + result->AllocateEntries(2, 1, 0); + HeapEntry* root = result->AddRootEntry(1); + HeapEntry* message = result->AddEntry( + HeapEntry::kString, "The snapshot is too big", 0, 4, 0, 0); + root->SetUnidirElementReference(0, 1, message); + result->SetDominatorsToSelf(); + return result; } diff --git a/src/profile-generator.h b/src/profile-generator.h index 9ab44a1e2..6bada36d5 100644 --- a/src/profile-generator.h +++ b/src/profile-generator.h @@ -654,6 +654,7 @@ class HeapSnapshot { HeapEntry* gc_roots() { return gc_roots_entry_; } HeapEntry* natives_root() { return natives_root_entry_; } List* entries() { return &entries_; } + int raw_entries_size() { return raw_entries_size_; } void AllocateEntries( int entries_count, int children_count, int retainers_count); @@ -689,9 +690,7 @@ class HeapSnapshot { char* raw_entries_; List entries_; bool entries_sorted_; -#ifdef DEBUG int raw_entries_size_; -#endif friend class HeapSnapshotTester; @@ -1097,6 +1096,7 @@ class HeapSnapshotJSONSerializer { } void EnumerateNodes(); + HeapSnapshot* CreateFakeSnapshot(); int GetNodeId(HeapEntry* entry); int GetStringId(const char* s); void SerializeEdge(HeapGraphEdge* edge); @@ -1108,6 +1108,8 @@ class HeapSnapshotJSONSerializer { void SerializeStrings(); void SortHashMap(HashMap* map, List* sorted_entries); + static const int kMaxSerializableSnapshotRawSize; + HeapSnapshot* snapshot_; HashMap nodes_; HashMap strings_;