JUDCon 2013:Brazil
invokewat?
JVM?
Java?
I've got 99 problems
Java ain't one
stack-based
Virtual Machine
OO
taken to the next level
writing this in Java
IRubyObject +(IRubyObject o){}
Java
Y U NO
OPERATOR OVERLOADING
Java (language) is
limited
(and that's ok)
writing this in Java
IRubyObject op_plus(IRubyObject o){}
verbose
1 + 2
IRubyObject x = // 1
IRubyObject y = // 2
x.op_plus(y);
everything is an object
requires
ALL THE TYPES
during compilation
do you know
where
methods live?
Object.methods()
classes!
so
{:+ => #<Object:0x007f95329a4510>, ...}
map!
let's call it
IRubyObject x = //;
x.+(); // fails
x.callMethod(context, "+"); // works
steps
- gets the object
- hash lookup
- context lookup
- actual invocation
- profit?
we could teach
the JVM
on how to reach the method instance we want?
we could give
the JVM
more hints about the code it runs?
bytecode
method handles
bootstrap method
target method
MethodHandles
int (*foo)(int)
bytecode - standard invoke
INVOKEVIRTUAL #39, #42
#39 is method name, #42 is the signature with types
bytecode - invokedynamic
INVOKEDYNAMIC name, #42, BSM, BSM_SIG
Bootstrap Method
returns a CallSite
a CallSite has a
Method Handle
which points to the
TargetMethod
SwitchPoint
case study: Ruby inconstants
jitescript
internal DSL for bytecode generation
jitescript
defineMethod("main",..,sig),
new CodeBlock() {{
ldc("helloWorld");
getstatic(p(System.class), "out", ci(PrintStream.class));
swap();
invokevirtual(p(PrintStream.class), "println", sig(void.class, Object.class));
voidreturn();
}});
invokebinder
(MethodHandle API for mortals)
inter-language
no serialization