Release persistent handles inside v8 GC

This commit is contained in:
Charles Lowell 2012-05-03 10:56:41 -07:00
parent 73d363c11a
commit 663d4f35ea
5 changed files with 28 additions and 6 deletions

View File

@ -38,5 +38,6 @@ namespace rr {
}
void GC::Init() {
queue = new GC::Queue();
v8::V8::AddGCPrologueCallback(GC::Drain);
}
}

View File

@ -9,6 +9,7 @@ using namespace rr;
extern "C" {
void Init_init() {
GC::Init();
V8::Init();
Context::Init();
String::Init();
Script::Init();

View File

@ -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);

13
ext/v8/v8.cc Normal file
View File

@ -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);
}
}

View File

@ -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