1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

configure resource constraints and get heap stats

This commit is contained in:
Charles Lowell 2012-06-08 06:06:49 -05:00
parent ae448321e8
commit bc5e24760f
5 changed files with 121 additions and 1 deletions

49
ext/v8/constraints.cc Normal file
View file

@ -0,0 +1,49 @@
#include "rr.h"
namespace rr {
void ResourceConstraints::Init() {
ClassBuilder("ResourceConstraints").
defineSingletonMethod("new", &initialize).
defineMethod("max_young_space_size", &max_young_space_size).
defineMethod("set_max_young_space_size", &set_max_young_space_size).
defineMethod("max_old_space_size", &max_old_space_size).
defineMethod("set_max_old_space_size", &set_max_old_space_size).
defineMethod("max_executable_size", &set_max_executable_size).
defineMethod("set_max_executable_size", &set_max_executable_size).
store(&Class);
ModuleBuilder("V8::C").
defineSingletonMethod("SetResourceConstraints", &SetResourceConstraints);
}
VALUE ResourceConstraints::SetResourceConstraints(VALUE self, VALUE constraints) {
Void(v8::SetResourceConstraints(ResourceConstraints(constraints)));
}
VALUE ResourceConstraints::initialize(VALUE self) {
return ResourceConstraints(new v8::ResourceConstraints());
}
VALUE ResourceConstraints::max_young_space_size(VALUE self) {
return INT2FIX(ResourceConstraints(self)->max_young_space_size());
}
VALUE ResourceConstraints::set_max_young_space_size(VALUE self, VALUE value) {
Void(ResourceConstraints(self)->set_max_young_space_size(NUM2INT(value)));
}
VALUE ResourceConstraints::max_old_space_size(VALUE self) {
return INT2FIX(ResourceConstraints(self)->max_old_space_size());
}
VALUE ResourceConstraints::set_max_old_space_size(VALUE self, VALUE value) {
Void(ResourceConstraints(self)->set_max_old_space_size(NUM2INT(value)));
}
VALUE ResourceConstraints::max_executable_size(VALUE self) {
return INT2FIX(ResourceConstraints(self)->max_executable_size());
}
VALUE ResourceConstraints::set_max_executable_size(VALUE self, VALUE value) {
Void(ResourceConstraints(self)->set_max_executable_size(NUM2INT(value)));
}
// What do these even mean?
// uint32_t* stack_limit() const { return stack_limit_; }
// // Sets an address beyond which the VM's stack may not grow.
// void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
}

29
ext/v8/heap.cc Normal file
View file

@ -0,0 +1,29 @@
#include "rr.h"
namespace rr {
void HeapStatistics::Init() {
ClassBuilder("HeapStatistics").
defineSingletonMethod("new", &initialize).
defineMethod("total_heap_size", &total_heap_size).
defineMethod("total_heap_size_executable", &total_heap_size_executable).
defineMethod("used_heap_size", &used_heap_size).
defineMethod("heap_size_limit", &heap_size_limit).
store(&Class);
}
VALUE HeapStatistics::initialize(VALUE self) {
return HeapStatistics(new v8::HeapStatistics());
}
VALUE HeapStatistics::total_heap_size(VALUE self) {
return SIZET2NUM(HeapStatistics(self)->total_heap_size());
}
VALUE HeapStatistics::total_heap_size_executable(VALUE self) {
return SIZET2NUM(HeapStatistics(self)->total_heap_size_executable());
}
VALUE HeapStatistics::used_heap_size(VALUE self) {
return SIZET2NUM(HeapStatistics(self)->used_heap_size());
}
VALUE HeapStatistics::heap_size_limit(VALUE self) {
return SIZET2NUM(HeapStatistics(self)->heap_size_limit());
}
}

View file

@ -31,5 +31,7 @@ extern "C" {
Message::Init();
TryCatch::Init();
Locker::Init();
ResourceConstraints::Init();
HeapStatistics::Init();
}
}

View file

@ -683,6 +683,40 @@ public:
static VALUE doUnlockCall(VALUE code);
};
class HeapStatistics : public Pointer<v8::HeapStatistics> {
public:
static void Init();
static VALUE initialize(VALUE self);
static VALUE total_heap_size(VALUE self);
static VALUE total_heap_size_executable(VALUE self);
static VALUE used_heap_size(VALUE self);
static VALUE heap_size_limit(VALUE self);
inline HeapStatistics(v8::HeapStatistics* stats) : Pointer<v8::HeapStatistics>(stats) {}
inline HeapStatistics(VALUE value) {
Data_Get_Struct(value, class v8::HeapStatistics, pointer);
}
};
class ResourceConstraints : Pointer<v8::ResourceConstraints> {
public:
static void Init();
static VALUE initialize(VALUE self);
static VALUE max_young_space_size(VALUE self);
static VALUE set_max_young_space_size(VALUE self, VALUE value);
static VALUE max_old_space_size(VALUE self);
static VALUE set_max_old_space_size(VALUE self, VALUE value);
static VALUE max_executable_size(VALUE self);
static VALUE set_max_executable_size(VALUE self, VALUE value);
static VALUE SetResourceConstraints(VALUE self, VALUE constraints);
inline ResourceConstraints(v8::ResourceConstraints* o) : Pointer<v8::ResourceConstraints>(o) {};
inline ResourceConstraints(VALUE value) {
Data_Get_Struct(value, class v8::ResourceConstraints, pointer);
}
};
class Constants {
public:
static void Init();
@ -709,6 +743,7 @@ public:
static void Init();
static VALUE IdleNotification(int argc, VALUE argv[], VALUE self);
static VALUE SetCaptureStackTraceForUncaughtExceptions(int argc, VALUE argv[], VALUE self);
static VALUE GetHeapStatistics(VALUE self, VALUE statistics_ptr);
};
class ClassBuilder {

View file

@ -5,7 +5,8 @@ namespace rr {
void V8::Init() {
ClassBuilder("V8").
defineSingletonMethod("IdleNotification", &IdleNotification).
defineSingletonMethod("SetCaptureStackTraceForUncaughtExceptions", &SetCaptureStackTraceForUncaughtExceptions);
defineSingletonMethod("SetCaptureStackTraceForUncaughtExceptions", &SetCaptureStackTraceForUncaughtExceptions).
defineSingletonMethod("GetHeapStatistics", &GetHeapStatistics);
}
VALUE V8::IdleNotification(int argc, VALUE argv[], VALUE self) {
@ -25,4 +26,8 @@ VALUE V8::SetCaptureStackTraceForUncaughtExceptions(int argc, VALUE argv[], VALU
Void(v8::V8::SetCaptureStackTraceForUncaughtExceptions(Bool(should_capture), limit, Stack::Trace::StackTraceOptions(options)));
}
VALUE V8::GetHeapStatistics(VALUE self, VALUE statistics_ptr) {
Void(v8::V8::GetHeapStatistics(HeapStatistics(statistics_ptr)));
}
}