Skip to content

Instantly share code, notes, and snippets.

View headius's full-sized avatar

Charles Oliver Nutter headius

View GitHub Profile
<p>The Java platform has largely catered to the needs of the Java language and Java developers. Its APIs are tailored to a JVM-centric view of the world, where Strings are always UTF-16, languages are static, and native libraries do not exist. But a majority of developers do not live in this world. They live in a world of variable string encodings. A world where dynamic languages work side-by-side with static languages. A world of heterogeneity, where every application combines libraries written in many different languages: sometimes native, sometimes interpreted.</p>
<p>JRuby is an implementation of Ruby for the JVM, but it's much more than simply an alternative JVM language. Ruby has its own community, its own standard implementation, and its own expectations about how a language runtime should interoperate with the system. Because of this, JRuby more than any other JVM language implementation has stretched the capabilities of the JVM in unexpected ways.</p>
<p>In this talk we'll explore the many libr
public __file__(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
@Lorg/jruby/anno/JRubyMethod;(name="__file__", frame=true, required=0, optional=0, rest=-1)
ALOAD 1
INVOKEVIRTUAL org/jruby/runtime/ThreadContext.getRuntime ()Lorg/jruby/Ruby;
DUP
ASTORE 5
INVOKEVIRTUAL org/jruby/Ruby.getNil ()Lorg/jruby/runtime/builtin/IRubyObject;
ASTORE 7
L0
NOP
BEFORE
◆ jruby -rffi/times -rbenchmark -e "def foo; @a ||= 1; end; 10.times { puts Benchmark.measure { 1_000_000.times { foo; foo; foo; foo; foo } } }"
0.830000 0.050000 0.880000 ( 0.719009)
0.410000 0.000000 0.410000 ( 0.425828)
0.400000 0.010000 0.410000 ( 0.410051)
0.400000 0.000000 0.400000 ( 0.412562)
0.420000 0.010000 0.430000 ( 0.421808)
0.400000 0.000000 0.400000 ( 0.415000)
0.420000 0.010000 0.430000 ( 0.429045)
public class TestClass {
public static void main(String[] args) {
NewClass nc = new NewClass();
System.out.println(nc.foo(args[0]));
System.out.println(NewClass.bar(args.length));
}
}
class Foo
XXX = 1
end
module Bar
class Baz < Foo
def self.get_it
XXX
end
end
{method}
- klass: {other class}
- method holder: 'bench/bench_fib_recursiveInvokermethod__0$RUBY$fib_rubyFixed1'
- constants: 0x06b82a64{constant pool}
- access: 0x81000001 public
- name: 'call'
- signature: '(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/RubyModule;Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;'
- max stack: 5
- max locals: 7
- size of params: 7
{method}
- klass: {other class}
- method holder: 'bench/bench_fib_recursive'
- constants: 0x06b82a64{constant pool}
- access: 0x81000001 public
- name: 'method__0$RUBY$fib_ruby'
- signature: '(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;'
- max stack: 13
- max locals: 12
- size of params: 5
BEFORE
ALOAD 0
GETFIELD ruby/__dash_e__._0 : Lorg/jruby/RubyRegexp;
IFNONNULL L1
ALOAD 5
LDC "foo"
ICONST_0
INVOKESTATIC org/jruby/RubyRegexp.newRegexp (Lorg/jruby/Ruby;Ljava/lang/String;I)Lorg/jruby/RubyRegexp;
ALOAD 0
// access flags 18
private final Ljava/lang/Class; $class
// access flags 1
public <init>()V
ALOAD 0
INVOKESPECIAL org/jruby/ast/executable/AbstractScript.<init> ()V
ALOAD 0
LDC "ruby.__dash_e__"
INVOKESTATIC java/lang/Class.forName (Ljava/lang/String;)Ljava/lang/Class;
OLD BINDING LOGIC
IN METHOD BODY ITSELF:
ALOAD 0
ALOAD 1
INVOKEVIRTUAL ruby/__dash_e__.getClosure__0 (Lorg/jruby/runtime/ThreadContext;)Lorg/jruby/runtime/BlockBody;
// access flags 4098
private getClosure__0(Lorg/jruby/runtime/ThreadContext;)Lorg/jruby/runtime/BlockBody;