Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix the object allocation profile mode on Ruby 2.x

The object allocation profiler currently works by patching the
rb_newobj function in Ruby. This function is no longer directly used
in Ruby 2.x - rb_newobj_of is used instead.

This change patches either rb_newobj or rb_newobj_of, depending on
whether the targeted Ruby version has rb_newobj_of available.
  • Loading branch information...
commit e1beb6b498e56e283dea8f79d757d78a20838ca0 1 parent deb2947
@benweint benweint authored
Showing with 13 additions and 3 deletions.
  1. +4 −0 ext/extconf.rb
  2. +9 −3 ext/perftools.c
View
4 ext/extconf.rb
@@ -98,6 +98,10 @@ def add_define(name)
if RUBY_VERSION >= "1.9"
add_define 'RUBY19'
+ if RUBY_VERSION >= "2.0"
+ add_define 'HAVE_RB_NEWOBJ_OF'
+ end
+
hdrs = proc {
have_header("method.h") # exists on 1.9.2
have_header("vm_core.h") and
View
12 ext/perftools.c
@@ -38,6 +38,12 @@ static VALUE Isend;
result[depth++] = (void*) (method == ID_ALLOCATOR ? Iallocate : method); \
}
+#ifdef HAVE_RB_NEWOBJ_OF
+ #define NEWOBJ_FUNC rb_newobj_of
+#else
+ #define NEWOBJ_FUNC rb_newobj
+#endif
+
#ifdef RUBY18
#include <env.h>
#include <node.h>
@@ -492,11 +498,11 @@ objprofiler_setup()
sigemptyset(&sig.sa_mask);
sigaction(SIGTRAP, &sig, NULL);
- unprotect_page((char*)rb_newobj);
+ unprotect_page((char*)NEWOBJ_FUNC);
for (i=0; i<NUM_ORIG_BYTES; i++) {
- orig_bytes[i].location = (char *)rb_newobj + i;
- orig_bytes[i].value = ((unsigned char*)rb_newobj)[i];
+ orig_bytes[i].location = (char *)NEWOBJ_FUNC + i;
+ orig_bytes[i].value = ((unsigned char*)NEWOBJ_FUNC)[i];
orig_bytes[i].location[0] = '\xCC';
}
Please sign in to comment.
Something went wrong with that request. Please try again.