diff --git a/ext/v8/gc.cc b/ext/v8/gc.cc index 1616544..9412e9b 100644 --- a/ext/v8/gc.cc +++ b/ext/v8/gc.cc @@ -38,5 +38,6 @@ namespace rr { } void GC::Init() { queue = new GC::Queue(); + v8::V8::AddGCPrologueCallback(GC::Drain); } } \ No newline at end of file diff --git a/ext/v8/init.cc b/ext/v8/init.cc index b08b135..15a0cd1 100644 --- a/ext/v8/init.cc +++ b/ext/v8/init.cc @@ -9,6 +9,7 @@ using namespace rr; extern "C" { void Init_init() { GC::Init(); + V8::Init(); Context::Init(); String::Init(); Script::Init(); diff --git a/ext/v8/rr.h b/ext/v8/rr.h index 7656f6b..1ed9b07 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -116,6 +116,10 @@ public: static void Init(); }; +class V8 { +public: + static void Init(); +}; VALUE defineClass(const char *name, VALUE superclass = rb_cObject); VALUE defineModule(const char *name); diff --git a/ext/v8/v8.cc b/ext/v8/v8.cc new file mode 100644 index 0000000..71a4910 --- /dev/null +++ b/ext/v8/v8.cc @@ -0,0 +1,13 @@ +#include "rr.h" + +namespace rr { +namespace { + VALUE IdleNotification(VALUE self) { + return v8::V8::IdleNotification() ? Qtrue : Qfalse; + } +} +void V8::Init() { + VALUE V8Class = defineClass("V8"); + RR_DEFINE_SINGLETON_METHOD(V8Class, "IdleNotification", &IdleNotification, 0); +} +} \ No newline at end of file diff --git a/spec/mem/blunt_spec.rb b/spec/mem/blunt_spec.rb index c9f4799..2f9e9bd 100644 --- a/spec/mem/blunt_spec.rb +++ b/spec/mem/blunt_spec.rb @@ -2,6 +2,9 @@ require 'spec_helper' describe "A Very blunt test to make sure that we aren't doing stupid leaks" do before do + #allocate a single context to make sure that v8 loads its snapshot and + #we pay the overhead. + V8::Context.new @start_memory = process_memory GC.stress = true end @@ -9,12 +12,12 @@ describe "A Very blunt test to make sure that we aren't doing stupid leaks" do after do GC.stress = false end - it "won't leak the context" do - 500.times do - # V8::Context.new + it "won't increase process memory by more than 20% no matter how many contexts we create" do + 5000.times do + V8::Context.new + gc_completely end - gc_completely - process_memory.should <= @start_memory * 1.05 + process_memory.should <= @start_memory * 1.2 end def process_memory @@ -22,7 +25,7 @@ describe "A Very blunt test to make sure that we aren't doing stupid leaks" do end def gc_completely - + loop while !V8::C::V8::IdleNotification() end end