Compact weak fixed arrays before serializing.
authoryangguo <yangguo@chromium.org>
Wed, 22 Apr 2015 07:40:05 +0000 (00:40 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 22 Apr 2015 07:39:52 +0000 (07:39 +0000)
R=ulan@chromium.org
BUG=v8:4050
LOG=N

Review URL: https://codereview.chromium.org/1099103003

Cr-Commit-Position: refs/heads/master@{#27988}

src/objects.cc
src/objects.h
src/snapshot/serialize.cc

index f57c569..c3fb054 100644 (file)
@@ -8295,6 +8295,20 @@ Handle<WeakFixedArray> WeakFixedArray::Add(
 }
 
 
+void WeakFixedArray::Compact() {
+  FixedArray* array = FixedArray::cast(this);
+  int new_length = kFirstIndex;
+  for (int i = kFirstIndex; i < array->length(); i++) {
+    Object* element = array->get(i);
+    if (element->IsSmi()) continue;
+    if (WeakCell::cast(element)->cleared()) continue;
+    array->set(new_length++, element);
+  }
+  array->Shrink(new_length);
+  set_last_used_index(0);
+}
+
+
 void WeakFixedArray::Remove(Handle<HeapObject> value) {
   // Optimize for the most recently added element to be removed again.
   int first_index = last_used_index();
index fd9e8f4..e0c7a43 100644 (file)
@@ -2625,6 +2625,8 @@ class WeakFixedArray : public FixedArray {
 
   void Remove(Handle<HeapObject> value);
 
+  void Compact();
+
   inline Object* Get(int index) const;
   inline int Length() const;
 
index b7c7dc1..bf0a4eb 100644 (file)
@@ -1779,6 +1779,13 @@ void Serializer::ObjectSerializer::Serialize() {
   // We cannot serialize typed array objects correctly.
   DCHECK(!object_->IsJSTypedArray());
 
+  if (object_->IsPrototypeInfo()) {
+    Object* prototype_users = PrototypeInfo::cast(object_)->prototype_users();
+    if (prototype_users->IsWeakFixedArray()) {
+      WeakFixedArray::cast(prototype_users)->Compact();
+    }
+  }
+
   if (object_->IsScript()) {
     // Clear cached line ends.
     Object* undefined = serializer_->isolate()->heap()->undefined_value();