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 ---
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;
i::Handle<i::FunctionTemplateInfo> global_constructor;
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;
}
+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);
Shrink();
Counters::objs_since_last_full.Set(0);
+ context_disposed_pending_ = false;
}
// 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();
static int scavenge_count_;
static int always_allocate_scope_depth_;
+ static bool context_disposed_pending_;
static const int kMaxMapSpaceSize = 8*MB;
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