Reviewers: Hannes Payer,

Description:
Serializer: canonicalize cleared weak cells.



[email protected]
BUG=v8:4050
LOG=N

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

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

Affected files (+25, -1 lines):
  M src/heap/heap.h
  M src/heap/heap.cc
  M src/objects.h
  M src/objects-inl.h
  M src/snapshot/serialize.h
  M src/snapshot/serialize.cc


Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 2f3a1a8c1c7d300e892223b0a9d40a3aad530e49..cff796ab4a9730e8ad3869d764cdee2e4e08186e 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -3108,6 +3108,9 @@ void Heap::CreateInitialObjects() {
       *factory->NewFixedArray(kAllocationSiteScratchpadSize, TENURED));
   InitializeAllocationSitesScratchpad();

+  set_cleared_weak_cell(*factory->NewWeakCell(factory->undefined_value()));
+  cleared_weak_cell()->unchecked_clear();
+
   // Initialize keyed lookup cache.
   isolate_->keyed_lookup_cache()->Clear();

Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index 9dd4b1466272b534b98c2f10d97a8855c749dd77..5ac70f872a3c9297bac5c50d539f1a9ed61353e2 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -185,7 +185,8 @@ namespace internal {
V(FixedArray, keyed_load_dummy_vector, KeyedLoadDummyVector) \ V(FixedArray, detached_contexts, DetachedContexts) \ V(ArrayList, retained_maps, RetainedMaps) \
-  V(WeakHashTable, weak_object_to_code_table, WeakObjectToCodeTable)
+ V(WeakHashTable, weak_object_to_code_table, WeakObjectToCodeTable) \
+  V(WeakCell, cleared_weak_cell, ClearedWeakCell)

 // Entries in this list are limited to Smis and are not visited during GC.
#define SMI_ROOT_LIST(V) \
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 5f3d0747e6a5b4c5aa337c01d89fc72ca86e21c2..d8e1f579a75ff9f2b033ba218fe28e69f8a64266 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -1909,6 +1909,11 @@ void WeakCell::clear() {
 }


+void WeakCell::unchecked_clear() {
+  WRITE_FIELD(this, kValueOffset, Smi::FromInt(0));
+}
+
+
 void WeakCell::initialize(HeapObject* val) {
   WRITE_FIELD(this, kValueOffset, val);
   WRITE_BARRIER(GetHeap(), this, kValueOffset, val);
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 0b85008b032e78809e526aa1a007eb6c0b548ddb..8b9883a61750cb7beb1c3bea4e3a034b7b0be121 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -9866,6 +9866,8 @@ class WeakCell : public HeapObject {
   // This should not be called by anyone except GC.
   inline void clear();

+  inline void unchecked_clear();
+
   // This should not be called by anyone except allocator.
   inline void initialize(HeapObject* value);

Index: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index b7c7dc1dd1c012264705860fd832e087910fc67e..713f245f668fb507e8ae5788c5ecfabe31619084 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -1092,6 +1092,12 @@ void Deserializer::ReadData(Object** current, Object** limit, int source_space,
         break;
       }

+      case kClearedWeakCell: {
+        Object* cleared_weak_cell = isolate_->heap()->cleared_weak_cell();
+        UnalignedCopy(current++, &cleared_weak_cell);
+        break;
+      }
+
       case kSynchronize:
// If we get here then that indicates that you have a mismatch between
         // the number of GC roots when serializing and deserializing.
@@ -1462,6 +1468,11 @@ bool Serializer::BackReferenceIsAlreadyAllocated(BackReference reference) {

bool Serializer::SerializeKnownObject(HeapObject* obj, HowToCode how_to_code, WhereToPoint where_to_point, int skip) {
+  if (obj->IsWeakCell() && WeakCell::cast(obj)->cleared()) {
+    FlushSkip(skip);
+    sink_->Put(kClearedWeakCell, "ClearedWeakCell");
+    return true;
+  }
   if (how_to_code == kPlain && where_to_point == kStartOfObject) {
     // Encode a reference to a hot object by its index in the working set.
     int index = hot_objects_.Find(obj);
Index: src/snapshot/serialize.h
diff --git a/src/snapshot/serialize.h b/src/snapshot/serialize.h
index 36514e13d391927aa247a4714ff519194effacad..f6a88f05436fb753435061d1a538754106eb5e48 100644
--- a/src/snapshot/serialize.h
+++ b/src/snapshot/serialize.h
@@ -373,6 +373,8 @@ class SerializerDeserializer: public ObjectVisitor {
   static const int kNop = 0x3d;
   // Move to next reserved chunk.
   static const int kNextChunk = 0x3e;
+  // Canonical cleared weak cell.
+  static const int kClearedWeakCell = 0x3f;
// A tag emitted at strategic points in the snapshot to delineate sections. // If the deserializer does not find these at the expected moments then it
   // is an indication that the snapshot and the VM do not fit together.


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