hosting
dynamic
languages &
apps
on the
JVM
computers?
languages?
movl %eax, -35(%rbp)
abstractions
spoiled
our generation
so...
you want to implement a
JVM-based
language?
reality check
abstractions
considered
harmful?
JVM?
Java?
I've got 99 problems
Java ain't one
CPU
movl %eax, -36(%rbp)
register-based
stack-based
Virtual Machine
what
statically
typed
means?
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
AOT vs JIT
speaker notes remind me to troll the CLR
optimize
Here be Dragons
IR
S
tatic
S
ingle
A
ssignment
Ruby Numb3rs
1.9.3-p362 :010 > (2**2**5).class
=> Fixnum
1.9.3-p362 :011 > (4**2**5).class
=> Bignum
back to sanity?
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
- get 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 hint
the JVM
about this very codepath
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
CallSite
a CallSite has a
Method Handle
which points to the
TargetMethod
invokedynamic's
"friends"
aka
APIs
SwitchPoint
case study:
Ruby inconstants
Ruby inconstants
1.9.3-p362 :001 > THING="hello"
=> "hello"
1.9.3-p362 :002 > THING="hellow"
(irb):2: warning: already initialized constant THING
=> "hellow"
invokedynamic
partial solution
METACIRCULAR
language runtime framework
uncle Ben's
with great
productivity
comes great
responsibility
optimizing dynlangs
is hard
but doable
@headius guaranteed
having
structure
is a must
check
async polyglot framework
we love
dynamic
languages
but there's
NO
silver language
take your daily
abstraction
fix
just don't be
spoiled
by it
that's all, folks!
thanks!