Reviewers: Mads Ager, iposva,

Description:
Experimental (somewhat): Force GCs when disposing contexts.

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

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

Affected files:
   M     src/api.cc
   M     src/v8-counters.h


Index: src/api.cc
===================================================================
--- src/api.cc  (revision 1364)
+++ src/api.cc  (working copy)
@@ -376,7 +376,16 @@
  void V8::DisposeGlobal(void** obj) {
    LOG_API("DisposeGlobal");
    if (has_shut_down) return;
-  i::GlobalHandles::Destroy(reinterpret_cast<i::Object**>(obj));
+  i::Object** ptr = reinterpret_cast<i::Object**>(obj);
+  // When disposing contexts we force a GC to allow timely cleanup of
+  // the global object and external resources like DOM trees. Make
+  // sure to do the GC after the handle is destroyed.
+  bool do_gc = (*ptr)->IsGlobalContext();
+  i::GlobalHandles::Destroy(ptr);
+  if (do_gc) {
+    i::StatsRateScope scope(&i::Counters::gc_context);
+    i::Heap::CollectAllGarbage();
+  }
  }

  // --- H a n d l e s ---
Index: src/v8-counters.h
===================================================================
--- src/v8-counters.h   (revision 1363)
+++ src/v8-counters.h   (working copy)
@@ -32,14 +32,15 @@

  namespace v8 { namespace internal {

-#define STATS_RATE_LIST(SR)                                \
-  SR(gc_compactor, V8.GCCompactor) /* GC Compactor time */ \
-  SR(gc_scavenger, V8.GCScavenger) /* GC Scavenger time */ \
-  SR(compile, V8.Compile)          /* Compile time*/       \
-  SR(compile_eval, V8.CompileEval) /* Eval compile time */ \
-  SR(compile_lazy, V8.CompileLazy) /* Lazy compile time */ \
-  SR(parse, V8.Parse)              /* Parse time */        \
-  SR(parse_lazy, V8.ParseLazy)     /* Lazy parse time */   \
+#define STATS_RATE_LIST(SR)                                             \
+  SR(gc_compactor, V8.GCCompactor) /* GC Compactor time */              \
+  SR(gc_scavenger, V8.GCScavenger) /* GC Scavenger time */              \
+  SR(gc_context, V8.GCContext)     /* GC context cleanup time */        \
+  SR(compile, V8.Compile)          /* Compile time*/                    \
+  SR(compile_eval, V8.CompileEval) /* Eval compile time */              \
+  SR(compile_lazy, V8.CompileLazy) /* Lazy compile time */              \
+  SR(parse, V8.Parse)              /* Parse time */                     \
+  SR(parse_lazy, V8.ParseLazy)     /* Lazy parse time */                \
    SR(pre_parse, V8.PreParse)       /* Pre-parse time */

  // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC



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

Reply via email to