mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Merge pull request #371 from cowboyd/4.5/add-memory-testing
add back the basics of memory testing.
This commit is contained in:
commit
78c841c6b6
7 changed files with 30 additions and 29 deletions
|
@ -24,6 +24,7 @@ script:
|
||||||
- bundle exec rake compile
|
- bundle exec rake compile
|
||||||
- bundle exec rspec spec/c
|
- bundle exec rspec spec/c
|
||||||
- bundle exec rspec spec/v8/context_spec.rb
|
- bundle exec rspec spec/v8/context_spec.rb
|
||||||
|
- bundle exec rspec spec/mem
|
||||||
sudo: false
|
sudo: false
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace rr {
|
||||||
ClassBuilder("Isolate").
|
ClassBuilder("Isolate").
|
||||||
defineSingletonMethod("New", &New).
|
defineSingletonMethod("New", &New).
|
||||||
|
|
||||||
defineMethod("Dispose", &Isolate::Dispose).
|
defineMethod("IdleNotificationDeadline", &IdleNotificationDeadline).
|
||||||
|
|
||||||
store(&Class);
|
store(&Class);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ namespace rr {
|
||||||
create_params.array_buffer_allocator = &data->array_buffer_allocator;
|
create_params.array_buffer_allocator = &data->array_buffer_allocator;
|
||||||
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
||||||
|
|
||||||
|
|
||||||
isolate->SetData(0, data);
|
isolate->SetData(0, data);
|
||||||
isolate->AddGCPrologueCallback(&clearReferences);
|
isolate->AddGCPrologueCallback(&clearReferences);
|
||||||
|
|
||||||
|
@ -34,9 +33,10 @@ namespace rr {
|
||||||
return Isolate(isolate);
|
return Isolate(isolate);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Isolate::Dispose(VALUE self) {
|
|
||||||
|
VALUE Isolate::IdleNotificationDeadline(VALUE self, VALUE deadline_in_seconds) {
|
||||||
Isolate isolate(self);
|
Isolate isolate(self);
|
||||||
isolate->Dispose();
|
Locker lock(isolate);
|
||||||
return Qnil;
|
return Bool(isolate->IdleNotificationDeadline(NUM2DBL(deadline_in_seconds)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ namespace rr {
|
||||||
*/
|
*/
|
||||||
static void destroy(IsolateData* data) {
|
static void destroy(IsolateData* data) {
|
||||||
Isolate isolate(data);
|
Isolate isolate(data);
|
||||||
|
isolate->Dispose();
|
||||||
isolate.decrementTotalReferences();
|
isolate.decrementTotalReferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +160,15 @@ namespace rr {
|
||||||
while (data->rb_release_queue.try_dequeue(object)) {
|
while (data->rb_release_queue.try_dequeue(object)) {
|
||||||
isolate.releaseObject(object);
|
isolate.releaseObject(object);
|
||||||
}
|
}
|
||||||
rb_gc_mark(data->retained_objects);
|
//TODO: This should not be necessary since sometimes the
|
||||||
|
//instance of V8::RetainedObjects appears to magically be of
|
||||||
|
//type T_NONE instead of T_OBJECT. Later, it will be T_OBJECT,
|
||||||
|
//but if called while T_NONE, it will cause rb_gc_mark to dump
|
||||||
|
//core.
|
||||||
|
//See https://bugs.ruby-lang.org/issues/10803
|
||||||
|
if (TYPE(data->retained_objects) != T_NONE) {
|
||||||
|
rb_gc_mark(data->retained_objects);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,7 +186,7 @@ namespace rr {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static VALUE Dispose(VALUE self);
|
static VALUE IdleNotificationDeadline(VALUE self, VALUE deadline_in_seconds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recent versions of V8 will segfault unless you pass in an
|
* Recent versions of V8 will segfault unless you pass in an
|
||||||
|
|
|
@ -6,8 +6,4 @@ describe V8::C::Isolate do
|
||||||
it 'can create a new isolate' do
|
it 'can create a new isolate' do
|
||||||
expect(isolate).to be
|
expect(isolate).to be
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can be disposed of" do
|
|
||||||
isolate.Dispose()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,8 +23,6 @@ module V8ContextHelpers
|
||||||
@ctx.Exit
|
@ctx.Exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
@isolate.Dispose()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe "A Very blunt test to make sure that we aren't doing stupid leaks", :me
|
||||||
end
|
end
|
||||||
#allocate a single context to make sure that v8 loads its snapshot and
|
#allocate a single context to make sure that v8 loads its snapshot and
|
||||||
#we pay the overhead.
|
#we pay the overhead.
|
||||||
V8::Context.new
|
V8::Isolate.new
|
||||||
@start_memory = process_memory
|
@start_memory = process_memory
|
||||||
GC.stress = true
|
GC.stress = true
|
||||||
end
|
end
|
||||||
|
@ -15,23 +15,27 @@ describe "A Very blunt test to make sure that we aren't doing stupid leaks", :me
|
||||||
after do
|
after do
|
||||||
GC.stress = false
|
GC.stress = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can create 3 isolates in a row" do
|
||||||
|
3.times { V8::Isolate.new }
|
||||||
|
end
|
||||||
|
|
||||||
it "won't increase process memory by more than 50% no matter how many contexts we create" do
|
it "won't increase process memory by more than 50% no matter how many contexts we create" do
|
||||||
500.times do
|
250.times do
|
||||||
V8::Context.new
|
isolate = V8::Context.new.isolate.native
|
||||||
run_v8_gc
|
isolate.IdleNotificationDeadline(0.1)
|
||||||
end
|
end
|
||||||
process_memory.should <= @start_memory * 1.5
|
expect(process_memory).to be <= @start_memory * 1.5
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can eval simple value passing statements repeatedly without significantly increasing memory" do
|
it "can eval simple value passing statements repeatedly without significantly increasing memory" do
|
||||||
V8::C::Locker() do
|
V8::Context.new do |cxt|
|
||||||
cxt = V8::Context.new
|
|
||||||
500.times do
|
500.times do
|
||||||
cxt.eval('7 * 6')
|
cxt.eval('7 * 6')
|
||||||
run_v8_gc
|
cxt.isolate.native.IdleNotificationDeadline(0.1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
process_memory.should <= @start_memory * 1.1
|
expect(process_memory).to be <= @start_memory * 1.1
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_memory
|
def process_memory
|
||||||
|
@ -39,4 +43,3 @@ describe "A Very blunt test to make sure that we aren't doing stupid leaks", :me
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
require 'v8'
|
require 'v8'
|
||||||
|
|
||||||
def run_v8_gc
|
|
||||||
V8::C::V8::LowMemoryNotification()
|
|
||||||
while !V8::C::V8::IdleNotification() do
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def rputs(msg)
|
def rputs(msg)
|
||||||
puts "<pre>#{ERB::Util.h(msg)}</pre>"
|
puts "<pre>#{ERB::Util.h(msg)}</pre>"
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
|
|
Loading…
Add table
Reference in a new issue