Author: [email protected]
Date: Thu Feb 26 04:40:50 2009
New Revision: 1375

Modified:
    branches/bleeding_edge/src/api.cc
    branches/bleeding_edge/src/heap.cc
    branches/bleeding_edge/src/heap.h
    branches/bleeding_edge/src/v8-counters.h

Log:
Experimental (somewhat): Force GCs when disposing contexts, but
make sure not to do it repeatedly for bursts of context
disposals.
Review URL: http://codereview.chromium.org/27201

Modified: branches/bleeding_edge/src/api.cc
==============================================================================
--- branches/bleeding_edge/src/api.cc   (original)
+++ branches/bleeding_edge/src/api.cc   Thu Feb 26 04:40:50 2009
@@ -376,7 +376,9 @@
  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);
+  if ((*ptr)->IsGlobalContext()) i::Heap::NotifyContextDisposed();
+  i::GlobalHandles::Destroy(ptr);
  }

  // --- H a n d l e s ---
@@ -2206,6 +2208,9 @@
    EnsureInitialized("v8::Context::New()");
    LOG_API("Context::New");
    ON_BAILOUT("v8::Context::New()", return Persistent<Context>());
+
+  // Give the heap a chance to cleanup if we've disposed contexts.
+  i::Heap::CollectAllGarbageIfContextDisposed();

    v8::Handle<ObjectTemplate> proxy_template = global_template;
    i::Handle<i::FunctionTemplateInfo> proxy_constructor;

Modified: branches/bleeding_edge/src/heap.cc
==============================================================================
--- branches/bleeding_edge/src/heap.cc  (original)
+++ branches/bleeding_edge/src/heap.cc  Thu Feb 26 04:40:50 2009
@@ -97,6 +97,7 @@
  int Heap::gc_count_ = 0;

  int Heap::always_allocate_scope_depth_ = 0;
+bool Heap::context_disposed_pending_ = false;

  #ifdef DEBUG
  bool Heap::allocation_allowed_ = true;
@@ -293,6 +294,20 @@
  }


+void Heap::CollectAllGarbageIfContextDisposed() {
+  if (context_disposed_pending_) {
+    StatsRateScope scope(&Counters::gc_context);
+    CollectAllGarbage();
+    context_disposed_pending_ = false;
+  }
+}
+
+
+void Heap::NotifyContextDisposed() {
+  context_disposed_pending_ = true;
+}
+
+
  bool Heap::CollectGarbage(int requested_size, AllocationSpace space) {
    // The VM is in the GC state until exiting this function.
    VMState state(GC);
@@ -436,6 +451,7 @@
    Shrink();

    Counters::objs_since_last_full.Set(0);
+  context_disposed_pending_ = false;
  }



Modified: branches/bleeding_edge/src/heap.h
==============================================================================
--- branches/bleeding_edge/src/heap.h   (original)
+++ branches/bleeding_edge/src/heap.h   Thu Feb 26 04:40:50 2009
@@ -606,6 +606,13 @@
    // Performs a full garbage collection.
    static void CollectAllGarbage();

+  // Performs a full garbage collection if a context has been disposed
+  // since the last time the check was performed.
+  static void CollectAllGarbageIfContextDisposed();
+
+  // Notify the heap that a context has been disposed.
+  static void NotifyContextDisposed();
+
    // Utility to invoke the scavenger. This is needed in test code to
    // ensure correct callback for weak global handles.
    static void PerformScavenge();
@@ -808,6 +815,7 @@
    static int scavenge_count_;

    static int always_allocate_scope_depth_;
+  static bool context_disposed_pending_;

    static const int kMaxMapSpaceSize = 8*MB;


Modified: branches/bleeding_edge/src/v8-counters.h
==============================================================================
--- branches/bleeding_edge/src/v8-counters.h    (original)
+++ branches/bleeding_edge/src/v8-counters.h    Thu Feb 26 04:40:50 2009
@@ -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