diff --git a/ext/v8/constraints.cc b/ext/v8/constraints.cc new file mode 100644 index 0000000..9da053e --- /dev/null +++ b/ext/v8/constraints.cc @@ -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; } + +} \ No newline at end of file diff --git a/ext/v8/heap.cc b/ext/v8/heap.cc new file mode 100644 index 0000000..3ab4d46 --- /dev/null +++ b/ext/v8/heap.cc @@ -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()); + } +} \ No newline at end of file diff --git a/ext/v8/init.cc b/ext/v8/init.cc index 1a4d6a0..96efcbc 100644 --- a/ext/v8/init.cc +++ b/ext/v8/init.cc @@ -31,5 +31,7 @@ extern "C" { Message::Init(); TryCatch::Init(); Locker::Init(); + ResourceConstraints::Init(); + HeapStatistics::Init(); } } \ No newline at end of file diff --git a/ext/v8/rr.h b/ext/v8/rr.h index 6a2af62..c9e6552 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -683,6 +683,40 @@ public: static VALUE doUnlockCall(VALUE code); }; +class HeapStatistics : public Pointer { +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(stats) {} + inline HeapStatistics(VALUE value) { + Data_Get_Struct(value, class v8::HeapStatistics, pointer); + } +}; + +class ResourceConstraints : Pointer { +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(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 { diff --git a/ext/v8/v8.cc b/ext/v8/v8.cc index 517538a..43bfc1c 100644 --- a/ext/v8/v8.cc +++ b/ext/v8/v8.cc @@ -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))); +} + } \ No newline at end of file