Revision: 9128
Author:   [email protected]
Date:     Mon Sep  5 02:55:55 2011
Log: Merge r9123 into 3.5 branch. This fixes DevTools crash on large heap snapshots.

BUG=crbug/89268
Review URL: http://codereview.chromium.org/7737021
http://code.google.com/p/v8/source/detail?r=9128

Modified:
 /branches/3.5/src/profile-generator.cc
 /branches/3.5/src/profile-generator.h
 /branches/3.5/src/version.cc

=======================================
--- /branches/3.5/src/profile-generator.cc      Wed Aug 24 05:02:41 2011
+++ /branches/3.5/src/profile-generator.cc      Mon Sep  5 02:55:55 2011
@@ -1195,12 +1195,9 @@
                                    int children_count,
                                    int retainers_count) {
   ASSERT(raw_entries_ == NULL);
-  raw_entries_ = NewArray<char>(
- 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<char>(raw_entries_size_);
 }


@@ -2984,10 +2981,19 @@
   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 @@

   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;
 }


=======================================
--- /branches/3.5/src/profile-generator.h       Wed Aug 24 05:02:41 2011
+++ /branches/3.5/src/profile-generator.h       Mon Sep  5 02:55:55 2011
@@ -654,6 +654,7 @@
   HeapEntry* gc_roots() { return gc_roots_entry_; }
   HeapEntry* natives_root() { return natives_root_entry_; }
   List<HeapEntry*>* 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 @@
   char* raw_entries_;
   List<HeapEntry*> entries_;
   bool entries_sorted_;
-#ifdef DEBUG
   int raw_entries_size_;
-#endif

   friend class HeapSnapshotTester;

@@ -1097,6 +1096,7 @@
   }

   void EnumerateNodes();
+  HeapSnapshot* CreateFakeSnapshot();
   int GetNodeId(HeapEntry* entry);
   int GetStringId(const char* s);
   void SerializeEdge(HeapGraphEdge* edge);
@@ -1108,6 +1108,8 @@
   void SerializeStrings();
   void SortHashMap(HashMap* map, List<HashMap::Entry*>* sorted_entries);

+  static const int kMaxSerializableSnapshotRawSize;
+
   HeapSnapshot* snapshot_;
   HashMap nodes_;
   HashMap strings_;
=======================================
--- /branches/3.5/src/version.cc        Thu Sep  1 05:40:13 2011
+++ /branches/3.5/src/version.cc        Mon Sep  5 02:55:55 2011
@@ -35,7 +35,7 @@
 #define MAJOR_VERSION     3
 #define MINOR_VERSION     5
 #define BUILD_NUMBER      10
-#define PATCH_LEVEL       1
+#define PATCH_LEVEL       2
 // Use 1 for candidates and 0 otherwise.
 // (Boolean macro values are not supported by all preprocessors.)
 #define IS_CANDIDATE_VERSION 0

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to