rubinius/rubinius — pull request #3214 by YorickPeterse (2014-11-14 21:14:10+00:00)
Title: DTrace/SystemTap object allocation hooks plus some housekeeping

**NOTE:** This pull-request is still a work in progress, I'm creating it to get some early feedback.

This pull-request adds the following:

1. A setup for tracing object allocations using DTrace/SystemTap (plus a few calls to these hooks)
2. A change that replaces `RBX_DTRACE_CONST char*` with just `RBX_DTRACE_CHAR`

The former is the most interesting: it allows you to trace allocations using the "object__allocate" probe. For example (this is a SystemTap script):

```cpp
global allocations

probe process("rbx").mark("object__allocate")
{
klass = user_string($arg1)
file = user_string($arg2)

allocations[klass, file] <<< 1
}

probe end
{
printf("%-40s %-6s %s\n", "Class", "Amount", "File")

foreach ( [klass, file] in allocations- )
{
printf("%-40s %-6d %s\n", klass, @count(allocations[klass, file]), file)
}

delete allocations
}
```

This would count the amount of object allocations per class and file and display the results upon exiting SystemTap. While still in an early stage this has already proven useful in finding allocation patterns for #3205 .

Right now there are hooks for the following classes:

* Array (given `Array::allocate` is used)
* Generic Ruby objects (those allocated by `Class::allocate`)
* String (given `String::allocate` is used)

The tricky part here, and this is something I'll need some feedback on, is to where exactly add the hooks. Some C++ classes have an `allocate` methods while others use a `create` method, sometimes even both. Ideally _all_ allocated objects that are exposed to Ruby should be traceable using these hooks. Because I'm not really sure where exactly to add the hooks I've so far only added them to the classes noted above.

The second thing changes is the introduction of `RBX_DTRACE_CHAR`. This is mostly a cleanup thing. I got tired of having to type `RBX_DTRACE_CONST char*` all the time, thus I introduced this little macro.