Reviewers: bak,

Description:
Add an explicit API entry to notify V8 that one or more
contexts have been disposed.

Please review this at http://codereview.chromium.org/661173

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     include/v8.h
  M     src/api.cc
  M     src/heap.h
  M     src/heap.cc


Index: include/v8.h
===================================================================
--- include/v8.h        (revision 3959)
+++ include/v8.h        (working copy)
@@ -2473,6 +2473,13 @@
    */
   static void LowMemoryNotification();

+  /**
+   * Optional notification that one or more context have been
+   * disposed. V8 may choose to collect garbage to get rid of any
+   * external memory associated with the disposed contexts.
+   */
+  static void ContextDisposedNotification();
+
  private:
   V8();

Index: src/api.cc
===================================================================
--- src/api.cc  (revision 3959)
+++ src/api.cc  (working copy)
@@ -2821,6 +2821,12 @@
 }


+void v8::V8::ContextDisposedNotification() {
+  if (!i::V8::IsRunning()) return;
+  i::Heap::CollectAllGarbageIfContextDisposed(true);
+}
+
+
 const char* v8::V8::GetVersion() {
   static v8::internal::EmbeddedVector<char, 128> buffer;
   v8::internal::Version::GetString(buffer);
@@ -2857,7 +2863,7 @@
     // decide when should make a full GC.
 #else
     // Give the heap a chance to cleanup if we've disposed contexts.
-    i::Heap::CollectAllGarbageIfContextDisposed();
+    i::Heap::CollectAllGarbageIfContextDisposed(false);
 #endif
     v8::Handle<ObjectTemplate> proxy_template = global_template;
     i::Handle<i::FunctionTemplateInfo> proxy_constructor;
Index: src/heap.cc
===================================================================
--- src/heap.cc (revision 3960)
+++ src/heap.cc (working copy)
@@ -371,7 +371,15 @@
 }


-void Heap::CollectAllGarbageIfContextDisposed() {
+void Heap::CollectAllGarbageIfContextDisposed(bool notified) {
+  // If the request has ever been the result of an explicit
+  // notification, we ignore non-notified requests. This is a
+  // temporary solution to let the two ways of achieving GC at
+  // context disposal time co-exist.
+  static bool ever_notified = false;
+  if (notified) ever_notified = true;
+  if (ever_notified && !notified) return;
+
   // If the garbage collector interface is exposed through the global
   // gc() function, we avoid being clever about forcing GCs when
   // contexts are disposed and leave it to the embedder to make
Index: src/heap.h
===================================================================
--- src/heap.h  (revision 3960)
+++ src/heap.h  (working copy)
@@ -634,7 +634,7 @@

   // Performs a full garbage collection if a context has been disposed
   // since the last time the check was performed.
-  static void CollectAllGarbageIfContextDisposed();
+  static void CollectAllGarbageIfContextDisposed(bool notified);

   // Notify the heap that a context has been disposed.
   static void NotifyContextDisposed();


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

Reply via email to