Commit c7c95963 authored by kasperl@chromium.org's avatar kasperl@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1375 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 20a9e9b0
...@@ -376,7 +376,9 @@ bool V8::IsGlobalWeak(void** obj) { ...@@ -376,7 +376,9 @@ bool V8::IsGlobalWeak(void** obj) {
void V8::DisposeGlobal(void** obj) { void V8::DisposeGlobal(void** obj) {
LOG_API("DisposeGlobal"); LOG_API("DisposeGlobal");
if (has_shut_down) return; 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 --- // --- H a n d l e s ---
...@@ -2207,6 +2209,9 @@ Persistent<Context> v8::Context::New( ...@@ -2207,6 +2209,9 @@ Persistent<Context> v8::Context::New(
LOG_API("Context::New"); LOG_API("Context::New");
ON_BAILOUT("v8::Context::New()", return Persistent<Context>()); 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; v8::Handle<ObjectTemplate> proxy_template = global_template;
i::Handle<i::FunctionTemplateInfo> proxy_constructor; i::Handle<i::FunctionTemplateInfo> proxy_constructor;
i::Handle<i::FunctionTemplateInfo> global_constructor; i::Handle<i::FunctionTemplateInfo> global_constructor;
......
...@@ -97,6 +97,7 @@ int Heap::mc_count_ = 0; ...@@ -97,6 +97,7 @@ int Heap::mc_count_ = 0;
int Heap::gc_count_ = 0; int Heap::gc_count_ = 0;
int Heap::always_allocate_scope_depth_ = 0; int Heap::always_allocate_scope_depth_ = 0;
bool Heap::context_disposed_pending_ = false;
#ifdef DEBUG #ifdef DEBUG
bool Heap::allocation_allowed_ = true; bool Heap::allocation_allowed_ = true;
...@@ -293,6 +294,20 @@ void Heap::CollectAllGarbage() { ...@@ -293,6 +294,20 @@ void Heap::CollectAllGarbage() {
} }
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) { bool Heap::CollectGarbage(int requested_size, AllocationSpace space) {
// The VM is in the GC state until exiting this function. // The VM is in the GC state until exiting this function.
VMState state(GC); VMState state(GC);
...@@ -436,6 +451,7 @@ void Heap::MarkCompact(GCTracer* tracer) { ...@@ -436,6 +451,7 @@ void Heap::MarkCompact(GCTracer* tracer) {
Shrink(); Shrink();
Counters::objs_since_last_full.Set(0); Counters::objs_since_last_full.Set(0);
context_disposed_pending_ = false;
} }
......
...@@ -606,6 +606,13 @@ class Heap : public AllStatic { ...@@ -606,6 +606,13 @@ class Heap : public AllStatic {
// Performs a full garbage collection. // Performs a full garbage collection.
static void CollectAllGarbage(); 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 // Utility to invoke the scavenger. This is needed in test code to
// ensure correct callback for weak global handles. // ensure correct callback for weak global handles.
static void PerformScavenge(); static void PerformScavenge();
...@@ -808,6 +815,7 @@ class Heap : public AllStatic { ...@@ -808,6 +815,7 @@ class Heap : public AllStatic {
static int scavenge_count_; static int scavenge_count_;
static int always_allocate_scope_depth_; static int always_allocate_scope_depth_;
static bool context_disposed_pending_;
static const int kMaxMapSpaceSize = 8*MB; static const int kMaxMapSpaceSize = 8*MB;
......
...@@ -32,14 +32,15 @@ ...@@ -32,14 +32,15 @@
namespace v8 { namespace internal { namespace v8 { namespace internal {
#define STATS_RATE_LIST(SR) \ #define STATS_RATE_LIST(SR) \
SR(gc_compactor, V8.GCCompactor) /* GC Compactor time */ \ SR(gc_compactor, V8.GCCompactor) /* GC Compactor time */ \
SR(gc_scavenger, V8.GCScavenger) /* GC Scavenger time */ \ SR(gc_scavenger, V8.GCScavenger) /* GC Scavenger time */ \
SR(compile, V8.Compile) /* Compile time*/ \ SR(gc_context, V8.GCContext) /* GC context cleanup time */ \
SR(compile_eval, V8.CompileEval) /* Eval compile time */ \ SR(compile, V8.Compile) /* Compile time*/ \
SR(compile_lazy, V8.CompileLazy) /* Lazy compile time */ \ SR(compile_eval, V8.CompileEval) /* Eval compile time */ \
SR(parse, V8.Parse) /* Parse time */ \ SR(compile_lazy, V8.CompileLazy) /* Lazy compile time */ \
SR(parse_lazy, V8.ParseLazy) /* Lazy parse time */ \ SR(parse, V8.Parse) /* Parse time */ \
SR(parse_lazy, V8.ParseLazy) /* Lazy parse time */ \
SR(pre_parse, V8.PreParse) /* Pre-parse time */ SR(pre_parse, V8.PreParse) /* Pre-parse time */
// WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment