Reviewers: ulan,

Description:
Compact weak fixed arrays before serializing.

[email protected]

Please review this at https://codereview.chromium.org/1099103003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+22, -0 lines):
  M src/objects.h
  M src/objects.cc
  M src/snapshot/serialize.cc


Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index f57c569d09b36bf08bcdab3288dd552b85b960c6..9f2df206d86e2bffb5893c17529187dbfe636371 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -8295,6 +8295,19 @@ Handle<WeakFixedArray> WeakFixedArray::Add(
 }


+void WeakFixedArray::Compact() {
+  FixedArray* array = FixedArray::cast(this);
+  int w = 0;
+  for (int r = 0; r < array->length(); r++) {
+    Object* item = array->get(r);
+    if (item->IsSmi()) continue;
+    if (WeakCell::cast(item)->cleared()) continue;
+    array->set(w++, item);
+  }
+  array->Shrink(w);
+}
+
+
 void WeakFixedArray::Remove(Handle<HeapObject> value) {
   // Optimize for the most recently added element to be removed again.
   int first_index = last_used_index();
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 0b85008b032e78809e526aa1a007eb6c0b548ddb..010afb4cf7e2bc18c3b935a0ad17212f0f4562bb 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -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: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index b7c7dc1dd1c012264705860fd832e087910fc67e..bf0a4eb347b26bd5468d7370b0cb1cde10f39a24 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -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();


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to