Revision: 7202
Author: [email protected]
Date: Wed Mar 16 05:02:28 2011
Log: Introduce one way dependencies into object grouping.

Those are necessary to properly manage relationship between objects in cases
when they don't form proper tree structure.

Review URL: http://codereview.chromium.org/6686053
http://code.google.com/p/v8/source/detail?r=7202

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/global-handles.cc
 /branches/bleeding_edge/src/global-handles.h
 /branches/bleeding_edge/src/mark-compact.cc
 /branches/bleeding_edge/src/mark-compact.h
 /branches/bleeding_edge/test/cctest/test-api.cc
 /branches/bleeding_edge/test/cctest/test-mark-compact.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Thu Mar 10 04:05:31 2011
+++ /branches/bleeding_edge/include/v8.h        Wed Mar 16 05:02:28 2011
@@ -2717,6 +2717,17 @@
                              size_t length,
                              RetainedObjectInfo* info = NULL);

+  /**
+   * Allows the host application to declare implicit references between
+   * the objects: if |parent| is alive, all |children| are alive too.
+   * After each garbage collection, all implicit references
+ * are removed. It is intended to be used in the before-garbage-collection
+   * callback function.
+   */
+  static void AddImplicitReferences(Persistent<Object> parent,
+                                    Persistent<Value>* children,
+                                    size_t length);
+
   /**
    * Initializes from snapshot if possible. Otherwise, attempts to
    * initialize from scratch.  This function is called implicitly if
=======================================
--- /branches/bleeding_edge/src/api.cc  Thu Mar 10 05:58:20 2011
+++ /branches/bleeding_edge/src/api.cc  Wed Mar 16 05:02:28 2011
@@ -4126,9 +4126,20 @@
                         RetainedObjectInfo* info) {
   if (IsDeadCheck("v8::V8::AddObjectGroup()")) return;
   STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**));
-  i::GlobalHandles::AddGroup(
+  i::GlobalHandles::AddObjectGroup(
       reinterpret_cast<i::Object***>(objects), length, info);
 }
+
+
+void V8::AddImplicitReferences(Persistent<Object> parent,
+                               Persistent<Value>* children,
+                               size_t length) {
+  if (IsDeadCheck("v8::V8::AddImplicitReferences()")) return;
+  STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**));
+  i::GlobalHandles::AddImplicitReferences(
+      *Utils::OpenHandle(*parent),
+      reinterpret_cast<i::Object***>(children), length);
+}


 int V8::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) {
=======================================
--- /branches/bleeding_edge/src/global-handles.cc       Thu Mar 10 09:29:37 2011
+++ /branches/bleeding_edge/src/global-handles.cc       Wed Mar 16 05:02:28 2011
@@ -541,14 +541,34 @@
   return &groups;
 }

-void GlobalHandles::AddGroup(Object*** handles,
-                             size_t length,
-                             v8::RetainedObjectInfo* info) {
+
+void GlobalHandles::AddObjectGroup(Object*** handles,
+                                   size_t length,
+                                   v8::RetainedObjectInfo* info) {
   ObjectGroup* new_entry = new ObjectGroup(length, info);
-  for (size_t i = 0; i < length; ++i)
+  for (size_t i = 0; i < length; ++i) {
     new_entry->objects_.Add(handles[i]);
+  }
   ObjectGroups()->Add(new_entry);
 }
+
+
+List<ImplicitRefGroup*>* GlobalHandles::ImplicitRefGroups() {
+  // Lazily initialize the list to avoid startup time static constructors.
+  static List<ImplicitRefGroup*> groups(4);
+  return &groups;
+}
+
+
+void GlobalHandles::AddImplicitReferences(HeapObject* parent,
+                                          Object*** children,
+                                          size_t length) {
+  ImplicitRefGroup* new_entry = new ImplicitRefGroup(parent, length);
+  for (size_t i = 0; i < length; ++i) {
+    new_entry->children_.Add(children[i]);
+  }
+  ImplicitRefGroups()->Add(new_entry);
+}


 void GlobalHandles::RemoveObjectGroups() {
@@ -558,5 +578,15 @@
   }
   object_groups->Clear();
 }
+
+
+void GlobalHandles::RemoveImplicitRefGroups() {
+  List<ImplicitRefGroup*>* ref_groups = ImplicitRefGroups();
+  for (int i = 0; i< ref_groups->length(); i++) {
+    delete ref_groups->at(i);
+  }
+  ref_groups->Clear();
+}
+

 } }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/global-handles.h        Thu Mar 10 04:05:31 2011
+++ /branches/bleeding_edge/src/global-handles.h        Wed Mar 16 05:02:28 2011
@@ -39,9 +39,6 @@
 // At GC the destroyed global handles are removed from the free list
 // and deallocated.

-// Callback function on handling weak global handles.
-// typedef bool (*WeakSlotCallback)(Object** pointer);
-
 // An object group is treated like a single JS object: if one of object in
 // the group is alive, all objects in the same group are considered alive.
 // An object group is used to simulate object relationship in a DOM tree.
@@ -61,6 +58,24 @@
 };


+// An implicit references group consists of two parts: a parent object and
+// a list of children objects.  If the parent is alive, all the children
+// are alive too.
+class ImplicitRefGroup : public Malloced {
+ public:
+  ImplicitRefGroup() : children_(4) {}
+  ImplicitRefGroup(HeapObject* parent, size_t capacity)
+      : parent_(parent),
+        children_(static_cast<int>(capacity)) { }
+
+  HeapObject* parent_;
+  List<Object**> children_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(ImplicitRefGroup);
+};
+
+
 typedef void (*WeakReferenceGuest)(Object* object, void* parameter);

 class GlobalHandles : public AllStatic {
@@ -128,17 +143,28 @@
   static void IdentifyWeakHandles(WeakSlotCallback f);

   // Add an object group.
-  // Should only used in GC callback function before a collection.
+  // Should be only used in GC callback function before a collection.
   // All groups are destroyed after a mark-compact collection.
-  static void AddGroup(Object*** handles,
-                       size_t length,
-                       v8::RetainedObjectInfo* info);
+  static void AddObjectGroup(Object*** handles,
+                             size_t length,
+                             v8::RetainedObjectInfo* info);
+
+  // Add an implicit references' group.
+  // Should be only used in GC callback function before a collection.
+  // All groups are destroyed after a mark-compact collection.
+  static void AddImplicitReferences(HeapObject* parent,
+                                    Object*** children,
+                                    size_t length);

   // Returns the object groups.
   static List<ObjectGroup*>* ObjectGroups();

+  // Returns the implicit references' groups.
+  static List<ImplicitRefGroup*>* ImplicitRefGroups();
+
   // Remove bags, this should only happen after GC.
   static void RemoveObjectGroups();
+  static void RemoveImplicitRefGroups();

   // Tear down the global handle structure.
   static void TearDown();
=======================================
--- /branches/bleeding_edge/src/mark-compact.cc Thu Mar 10 04:00:27 2011
+++ /branches/bleeding_edge/src/mark-compact.cc Wed Mar 16 05:02:28 2011
@@ -1190,12 +1190,39 @@
         MarkObject(HeapObject::cast(*objects[j]));
       }
     }
+
     // Once the entire group has been colored gray, set the object group
     // to NULL so it won't be processed again.
-    delete object_groups->at(i);
+    delete entry;
     object_groups->at(i) = NULL;
   }
 }
+
+
+void MarkCompactCollector::MarkImplicitRefGroups() {
+  List<ImplicitRefGroup*>* ref_groups = GlobalHandles::ImplicitRefGroups();
+
+  for (int i = 0; i < ref_groups->length(); i++) {
+    ImplicitRefGroup* entry = ref_groups->at(i);
+    if (entry == NULL) continue;
+
+    if (!entry->parent_->IsMarked()) continue;
+
+    List<Object**>& children = entry->children_;
+    // A parent object is marked, so mark as gray all child white heap
+    // objects.
+    for (int j = 0; j < children.length(); ++j) {
+      if ((*children[j])->IsHeapObject()) {
+        MarkObject(HeapObject::cast(*children[j]));
+      }
+    }
+
+    // Once the entire group has been colored gray, set the  group
+    // to NULL so it won't be processed again.
+    delete entry;
+    ref_groups->at(i) = NULL;
+  }
+}


 // Mark all objects reachable from the objects on the marking stack.
@@ -1276,11 +1303,12 @@
 }


-void MarkCompactCollector::ProcessObjectGroups() {
+void MarkCompactCollector::ProcessExternalMarking() {
   bool work_to_do = true;
   ASSERT(marking_stack.is_empty());
   while (work_to_do) {
     MarkObjectGroups();
+    MarkImplicitRefGroups();
     work_to_do = !marking_stack.is_empty();
     ProcessMarkingStack();
   }
@@ -1311,10 +1339,9 @@
   MarkRoots(&root_visitor);

   // The objects reachable from the roots are marked, yet unreachable
-  // objects are unmarked.  Mark objects reachable from object groups
-  // containing at least one marked object, and continue until no new
-  // objects are reachable from the object groups.
-  ProcessObjectGroups();
+  // objects are unmarked.  Mark objects reachable due to host
+  // application specific logic.
+  ProcessExternalMarking();

   // The objects reachable from the roots or object groups are marked,
   // yet unreachable objects are unmarked.  Mark objects reachable
@@ -1330,9 +1357,9 @@
     EmptyMarkingStack();
   }

-  // Repeat the object groups to mark unmarked groups reachable from the
-  // weak roots.
-  ProcessObjectGroups();
+  // Repeat host application specific marking to mark unmarked objects
+  // reachable from the weak roots.
+  ProcessExternalMarking();

   // Prune the symbol table removing all symbols only pointed to by the
   // symbol table.  Cannot use symbol_table() here because the symbol
@@ -1350,6 +1377,7 @@

   // Remove object groups after marking phase.
   GlobalHandles::RemoveObjectGroups();
+  GlobalHandles::RemoveImplicitRefGroups();

   // Flush code from collected candidates.
   FlushCode::ProcessCandidates();
=======================================
--- /branches/bleeding_edge/src/mark-compact.h  Tue Dec  7 03:01:02 2010
+++ /branches/bleeding_edge/src/mark-compact.h  Wed Mar 16 05:02:28 2011
@@ -220,10 +220,13 @@
   // group marked.
   static void MarkObjectGroups();

-  // Mark all objects in an object group with at least one marked
-  // object, then all objects reachable from marked objects in object
-  // groups, and repeat.
-  static void ProcessObjectGroups();
+  // Mark objects in implicit references groups if their parent object
+  // is marked.
+  static void MarkImplicitRefGroups();
+
+  // Mark all objects which are reachable due to host application
+  // logic like object groups or implicit references' groups.
+  static void ProcessExternalMarking();

// Mark objects reachable (transitively) from objects in the marking stack
   // or overflowed in the heap.
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Tue Mar 15 02:16:12 2011
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Wed Mar 16 05:02:28 2011
@@ -50,15 +50,19 @@
 #endif
 }

-using ::v8::ObjectTemplate;
-using ::v8::Value;
+using ::v8::AccessorInfo;
 using ::v8::Context;
+using ::v8::Extension;
+using ::v8::Function;
+using ::v8::HandleScope;
 using ::v8::Local;
-using ::v8::String;
+using ::v8::Object;
+using ::v8::ObjectTemplate;
+using ::v8::Persistent;
 using ::v8::Script;
-using ::v8::Function;
-using ::v8::AccessorInfo;
-using ::v8::Extension;
+using ::v8::String;
+using ::v8::Value;
+using ::v8::V8;

 namespace i = ::i;

@@ -1787,6 +1791,180 @@
   CHECK_EQ(global->Length(), 3);
   global.Dispose();
 }
+
+
+static int NumberOfWeakCalls = 0;
+static void WeakPointerCallback(Persistent<Value> handle, void* id) {
+  CHECK_EQ(reinterpret_cast<void*>(1234), id);
+  NumberOfWeakCalls++;
+  handle.Dispose();
+}
+
+THREADED_TEST(ApiObjectGroups) {
+  HandleScope scope;
+  LocalContext env;
+
+  NumberOfWeakCalls = 0;
+
+  Persistent<Object> g1s1;
+  Persistent<Object> g1s2;
+  Persistent<Object> g1c1;
+  Persistent<Object> g2s1;
+  Persistent<Object> g2s2;
+  Persistent<Object> g2c1;
+
+  {
+    HandleScope scope;
+    g1s1 = Persistent<Object>::New(Object::New());
+    g1s2 = Persistent<Object>::New(Object::New());
+    g1c1 = Persistent<Object>::New(Object::New());
+    g1s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+    g1s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+    g1c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+
+    g2s1 = Persistent<Object>::New(Object::New());
+    g2s2 = Persistent<Object>::New(Object::New());
+    g2c1 = Persistent<Object>::New(Object::New());
+    g2s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+    g2s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+    g2c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+  }
+
+  Persistent<Object> root = Persistent<Object>::New(g1s1);  // make a root.
+
+  // Connect group 1 and 2, make a cycle.
+  CHECK(g1s2->Set(0, g2s2));
+  CHECK(g2s1->Set(0, g1s1));
+
+  {
+    Persistent<Value> g1_objects[] = { g1s1, g1s2 };
+    Persistent<Value> g1_children[] = { g1c1 };
+    Persistent<Value> g2_objects[] = { g2s1, g2s2 };
+    Persistent<Value> g2_children[] = { g2c1 };
+    V8::AddObjectGroup(g1_objects, 2);
+    V8::AddImplicitReferences(g1s1, g1_children, 1);
+    V8::AddObjectGroup(g2_objects, 2);
+    V8::AddImplicitReferences(g2s2, g2_children, 1);
+  }
+  // Do a full GC
+  i::Heap::CollectGarbage(i::OLD_POINTER_SPACE);
+
+  // All object should be alive.
+  CHECK_EQ(0, NumberOfWeakCalls);
+
+  // Weaken the root.
+  root.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+  // But make children strong roots---all the objects (except for children)
+  // should be collectable now.
+  g1c1.ClearWeak();
+  g2c1.ClearWeak();
+
+  // Groups are deleted, rebuild groups.
+  {
+    Persistent<Value> g1_objects[] = { g1s1, g1s2 };
+    Persistent<Value> g1_children[] = { g1c1 };
+    Persistent<Value> g2_objects[] = { g2s1, g2s2 };
+    Persistent<Value> g2_children[] = { g2c1 };
+    V8::AddObjectGroup(g1_objects, 2);
+    V8::AddImplicitReferences(g1s1, g1_children, 1);
+    V8::AddObjectGroup(g2_objects, 2);
+    V8::AddImplicitReferences(g2s2, g2_children, 1);
+  }
+
+  i::Heap::CollectGarbage(i::OLD_POINTER_SPACE);
+
+  // All objects should be gone. 5 global handles in total.
+  CHECK_EQ(5, NumberOfWeakCalls);
+
+  // And now make children weak again and collect them.
+  g1c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+  g2c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+
+  i::Heap::CollectGarbage(i::OLD_POINTER_SPACE);
+  CHECK_EQ(7, NumberOfWeakCalls);
+}
+
+
+THREADED_TEST(ApiObjectGroupsCycle) {
+  HandleScope scope;
+  LocalContext env;
+
+  NumberOfWeakCalls = 0;
+
+  Persistent<Object> g1s1;
+  Persistent<Object> g1s2;
+  Persistent<Object> g2s1;
+  Persistent<Object> g2s2;
+  Persistent<Object> g3s1;
+  Persistent<Object> g3s2;
+
+  {
+    HandleScope scope;
+    g1s1 = Persistent<Object>::New(Object::New());
+    g1s2 = Persistent<Object>::New(Object::New());
+    g1s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+    g1s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+
+    g2s1 = Persistent<Object>::New(Object::New());
+    g2s2 = Persistent<Object>::New(Object::New());
+    g2s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+    g2s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+
+    g3s1 = Persistent<Object>::New(Object::New());
+    g3s2 = Persistent<Object>::New(Object::New());
+    g3s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+    g3s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+  }
+
+  Persistent<Object> root = Persistent<Object>::New(g1s1);  // make a root.
+
+  // Connect groups.  We're building the following cycle:
+  // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
+  // groups.
+  {
+    Persistent<Value> g1_objects[] = { g1s1, g1s2 };
+    Persistent<Value> g1_children[] = { g2s1 };
+    Persistent<Value> g2_objects[] = { g2s1, g2s2 };
+    Persistent<Value> g2_children[] = { g3s1 };
+    Persistent<Value> g3_objects[] = { g3s1, g3s2 };
+    Persistent<Value> g3_children[] = { g1s1 };
+    V8::AddObjectGroup(g1_objects, 2);
+    V8::AddImplicitReferences(g1s1, g1_children, 1);
+    V8::AddObjectGroup(g2_objects, 2);
+    V8::AddImplicitReferences(g2s1, g2_children, 1);
+    V8::AddObjectGroup(g3_objects, 2);
+    V8::AddImplicitReferences(g3s1, g3_children, 1);
+  }
+  // Do a full GC
+  i::Heap::CollectGarbage(i::OLD_POINTER_SPACE);
+
+  // All object should be alive.
+  CHECK_EQ(0, NumberOfWeakCalls);
+
+  // Weaken the root.
+  root.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
+
+  // Groups are deleted, rebuild groups.
+  {
+    Persistent<Value> g1_objects[] = { g1s1, g1s2 };
+    Persistent<Value> g1_children[] = { g2s1 };
+    Persistent<Value> g2_objects[] = { g2s1, g2s2 };
+    Persistent<Value> g2_children[] = { g3s1 };
+    Persistent<Value> g3_objects[] = { g3s1, g3s2 };
+    Persistent<Value> g3_children[] = { g1s1 };
+    V8::AddObjectGroup(g1_objects, 2);
+    V8::AddImplicitReferences(g1s1, g1_children, 1);
+    V8::AddObjectGroup(g2_objects, 2);
+    V8::AddImplicitReferences(g2s1, g2_children, 1);
+    V8::AddObjectGroup(g3_objects, 2);
+    V8::AddImplicitReferences(g3s1, g3_children, 1);
+  }
+
+  i::Heap::CollectGarbage(i::OLD_POINTER_SPACE);
+
+  // All objects should be gone. 7 global handles in total.
+  CHECK_EQ(7, NumberOfWeakCalls);
+}


 THREADED_TEST(ScriptException) {
=======================================
--- /branches/bleeding_edge/test/cctest/test-mark-compact.cc Thu Mar 10 04:05:31 2011 +++ /branches/bleeding_edge/test/cctest/test-mark-compact.cc Wed Mar 16 05:02:28 2011
@@ -298,6 +298,7 @@

 static int NumberOfWeakCalls = 0;
static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) {
+  ASSERT(id == reinterpret_cast<void*>(1234));
   NumberOfWeakCalls++;
   handle.Dispose();
 }
@@ -311,6 +312,8 @@
   Handle<Object> g1s1 =
     GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
   Handle<Object> g1s2 =
+    GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
+  Handle<Object> g1c1 =
     GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
   GlobalHandles::MakeWeak(g1s1.location(),
                           reinterpret_cast<void*>(1234),
@@ -318,10 +321,15 @@
   GlobalHandles::MakeWeak(g1s2.location(),
                           reinterpret_cast<void*>(1234),
                           &WeakPointerCallback);
+  GlobalHandles::MakeWeak(g1c1.location(),
+                          reinterpret_cast<void*>(1234),
+                          &WeakPointerCallback);

   Handle<Object> g2s1 =
     GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
   Handle<Object> g2s2 =
+    GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
+  Handle<Object> g2c1 =
     GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
   GlobalHandles::MakeWeak(g2s1.location(),
                           reinterpret_cast<void*>(1234),
@@ -329,6 +337,9 @@
   GlobalHandles::MakeWeak(g2s2.location(),
                           reinterpret_cast<void*>(1234),
                           &WeakPointerCallback);
+  GlobalHandles::MakeWeak(g2c1.location(),
+                          reinterpret_cast<void*>(1234),
+                          &WeakPointerCallback);

   Handle<Object> root = GlobalHandles::Create(*g1s1);  // make a root.

@@ -338,9 +349,15 @@

   {
     Object** g1_objects[] = { g1s1.location(), g1s2.location() };
+    Object** g1_children[] = { g1c1.location() };
     Object** g2_objects[] = { g2s1.location(), g2s2.location() };
-    GlobalHandles::AddGroup(g1_objects, 2, NULL);
-    GlobalHandles::AddGroup(g2_objects, 2, NULL);
+    Object** g2_children[] = { g2c1.location() };
+    GlobalHandles::AddObjectGroup(g1_objects, 2, NULL);
+    GlobalHandles::AddImplicitReferences(HeapObject::cast(*g1s1),
+                                         g1_children, 1);
+    GlobalHandles::AddObjectGroup(g2_objects, 2, NULL);
+    GlobalHandles::AddImplicitReferences(HeapObject::cast(*g2s2),
+                                         g2_children, 1);
   }
   // Do a full GC
   Heap::CollectGarbage(OLD_POINTER_SPACE);
@@ -352,17 +369,38 @@
   GlobalHandles::MakeWeak(root.location(),
                           reinterpret_cast<void*>(1234),
                           &WeakPointerCallback);
+  // But make children strong roots---all the objects (except for children)
+  // should be collectable now.
+  GlobalHandles::ClearWeakness(g1c1.location());
+  GlobalHandles::ClearWeakness(g2c1.location());

   // Groups are deleted, rebuild groups.
   {
     Object** g1_objects[] = { g1s1.location(), g1s2.location() };
+    Object** g1_children[] = { g1c1.location() };
     Object** g2_objects[] = { g2s1.location(), g2s2.location() };
-    GlobalHandles::AddGroup(g1_objects, 2, NULL);
-    GlobalHandles::AddGroup(g2_objects, 2, NULL);
+    Object** g2_children[] = { g2c1.location() };
+    GlobalHandles::AddObjectGroup(g1_objects, 2, NULL);
+    GlobalHandles::AddImplicitReferences(HeapObject::cast(*g1s1),
+                                         g1_children, 1);
+    GlobalHandles::AddObjectGroup(g2_objects, 2, NULL);
+    GlobalHandles::AddImplicitReferences(HeapObject::cast(*g2s2),
+                                         g2_children, 1);
   }

   Heap::CollectGarbage(OLD_POINTER_SPACE);

   // All objects should be gone. 5 global handles in total.
   CHECK_EQ(5, NumberOfWeakCalls);
-}
+
+  // And now make children weak again and collect them.
+  GlobalHandles::MakeWeak(g1c1.location(),
+                          reinterpret_cast<void*>(1234),
+                          &WeakPointerCallback);
+  GlobalHandles::MakeWeak(g2c1.location(),
+                          reinterpret_cast<void*>(1234),
+                          &WeakPointerCallback);
+
+  Heap::CollectGarbage(OLD_POINTER_SPACE);
+  CHECK_EQ(7, NumberOfWeakCalls);
+}

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

Reply via email to