dynjs

(almost) 100% invokedynamic JS implementation

JUDCon 2012:Boston

whoami

@qmx

dynjs
JRuby

dynjs?

history

BrazilJS 2011

Rhino

why not?

3 rules

\o/

learn something

new

beautiful code

problem

@qmx on parsers

@porcelli joins

what goes next?

programming language design 101

parse

the code

build an

AST

generate the desired

bytecode

output

(at least that was I've wanted)

profit?

bytecode

is hard to grasp

Rhino

DIY

bytecode generation

ASM4

supports invokedynamic

too low-level

jitescript

DSL for bytecode generation

jitescript

						// calls the default constructor
  invokespecial(p(Car.class),
    "<init>", sig(void.class));
  // calls the "honk" method
  invokevirtual(p(Car.class), 
    "honk", sig(void.class));

					

next step?

avoiding reflection

int (*foo)(int)

Method Handles

strong roots on

functional

programming

MethodHandles

						MethodHandle honk = MethodHandles
  .lookup()
  .findVirtual(Car.class, "honk", 
MethodType.methodType(void.class));
honk.invoke(new Car());
					

reflection is slow because of

security checks

at each call

MethodHandles do all

security checks

during creation

(and they are immutable too :))

unfortunately

you need to think

spɹɐʍʞɔɐq

to fully exploit the API

invokebinder

(MethodHandles for mortals)

invokebinder

						mh = Binder.from(void.class, Object.class)
.invokeVirtual(lookup(), "run");
					

way better!

what next?

safety net

(aka specs)

what next?

dynjs-spec

11474 tests failing!

what next?

dynalink

MOP

not sure

closing

demo

?

thanks!