private E[] elements; ... } List<complex> list= new ArrayList<complex>(); The JIT will generate the specialization ! Will work with primitive types too List<int> list = new ArrayList<int>();
the JIT generates the JNI Stubs – Make unsafe offheap access safe Need metadata to describe – C structs layout in memory – Calling conventions Access C heap safely through interfaces
auto- vectorisation of loop over arrays of primitives Add API to access to SIMD/AVX ops – Need to define 128/256/512 bits int/double ? Use value types (but defined in JDK) – Intrinsics for the VM
SIMD/AVX – stealth valhalla: Value types in the VM let JRuby, Groovy, Scala, etc play with it first Java 11 – full valhalla: Value types + Specialized Generics
list = new ArrayList<String>(); use super type: var anonymous = new Object() { int x; }; not supported: var lambda = x -> x + 2; var ref = String::length;
_) { ... Lambda parameters open a new scope var cache = new HashMap<String, Info>(); var name = ... var info = cache.computeIfAbsent(name, name -> new Info(name));
to represent ‘structured’ data – Abstraction “it’s just a data class” – Less boiler plate Generate (at runtime ?) – equals, hashCode, toString, getters ? – Value types also need that too !
{ return switch(expr) { case Add(Value(var v1), Value(var v2)) -> new Value(v1 + v2)) case Add(var e1, var e2) -> simplify(...) case Value value -> value }; }
! public Expr simplify(Expr expr) { return switch(expr) { case Add(Value(var v1), Value(var v2)) -> new Value(v1 + v2)) case Add(var e1, var e2) -> simplify(...) case Value _ -> expr }; } Use of local variable (non final)
of pairs Pattern / Action • A text transformed as an automata at runtime • Action: a static method to call if the pattern match No instanceof guardWithTest is a typecheck on runtime classes
may match the same pattern switch(expr) { case Iadd(IValue(var v1), IValue(var v2)) -> // 1 case Iadd(var e1, var e2) -> // 2 IAdd IValue IValue extract expr v1 v2 action1 action2
-> ... case Iadd(var e1, var e2) - > ... IAdd IValue IValue extract expr v1 v2 action1 action2 Add Add Value Value Value Create the matching data structure at runtime
are objects) data class Add { private final Expr left; private final Expr right; ... public Optional<Tuple<Expr, Expr>> unapply() { return Some((left, right)); } } Extract the values => 2 object creations
the help of the VM Reify the stackframe as an object var frame = StackFrame.alloc(LExpr;LExpr;II) add.deconstructor(frame.refAt(0), frame.refAt(1)); … action.invokeWithStackFrame(frame, 2); a prototype is currently developed :)
Java – Testing is not fun :( The Java compiler is not able to propagate constants – Macro ? => add Intrinisics.ldc/invokedynamic + a mechanism to propagate constant (Constable?)
types, use the double switch trick ! String s; int index = invokedynamic(expr); recipe […] switch(index) { case 0: s = "JSObject"; break; case 1: s = "JSArray"; break; default: s = "other"; } return s;