On Tue, Oct 25, 2011 at 5:19 AM, Rm Mz [email protected] wrote:
I’m trying to understand the JVM bytecode generated from a JRuby file
using the jrubyc tool. One of the first things that springs to attention
is the fact that method names are mangled to include a set prefix of
has a method signature in bytecode that matches:
public static org.jruby.runtime.builtin.IRubyObject
can anyone provide any insights as to why this might be necessary?
There’s a couple reasons.
The method_ prefix is to identify for (my) debugging purposes that
this JVM method corresponds to a Ruby method. There’s also block_ and
a couple other prefixes.
The number following method_ is the index of the method in this
particular compilation unit (e.g. Nth method in this file). They are
numbered to avoid name conflicts, since Ruby allows you to define the
same method many times in the same file (and even in the same class)
but they will need different JVM methods to represent the body of the
RUBY indicates to the backtrace-generating logic that this is a
compiled Ruby method that should be included in a Ruby backtrace.
You will also see that the method names get mangled as in the following
def [email protected](a); a + 1; end
The method name used in the compiled JVM method is “plus” and 40, the
character code for @.