mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Release persistent handles inside v8 GC
This commit is contained in:
parent
73d363c11a
commit
663d4f35ea
5 changed files with 28 additions and 6 deletions
|
@ -38,5 +38,6 @@ namespace rr {
|
|||
}
|
||||
void GC::Init() {
|
||||
queue = new GC::Queue();
|
||||
v8::V8::AddGCPrologueCallback(GC::Drain);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ using namespace rr;
|
|||
extern "C" {
|
||||
void Init_init() {
|
||||
GC::Init();
|
||||
V8::Init();
|
||||
Context::Init();
|
||||
String::Init();
|
||||
Script::Init();
|
||||
|
|
|
@ -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
13
ext/v8/v8.cc
Normal 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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue