On Aug 3, 2016, at 1:22 PM, Remi Forax <fo...@univ-mlv.fr> wrote:
> Charles ask if we can make a fast register interpreter in Java,
> here is my take on a threaded-like interpreter
> https://gist.github.com/forax/f38b533e089217cfc4d0ae3c6e2de9c9

Nicely done.  We were talking last night at dinner about making
bytecode interpreters go fast, and this is helpful.

I think there may be a combinator here, for bytecode dispatch loops.
(This feels like the PIC combinator, both fundamental and tricky to get right.)
A "bytecode" dispatch combinator might provide a pattern like the following:

MethodHandle init, pred, step, fini, index;
@NonNull MethodHandle[] tab;
R dispatch(A… a) {
   V v = init(a…);  // one here; there might be many v…
   while (pred(a…)) {
      v = step(v, a…);
      // execute one "instruction":
      int i = index(v, a…);
      tab[i].invokeExact(v, a…);
   return fini(V, a…);

The explicit table would be recopied internally to an @Stable array for 
constant folding.
The various index values could be tracked and turned into traces (or some other 
driven structure) which would be compiled together, in specialized segments of 
the unrolled
interpreter loop.

Or maybe just the table lookup part alone makes a good combinator, to be paired
with the loop combinators?

Comments welcome…

— John

P.S. Another new RFE:
experimental hook for creating heisenboxes
mlvm-dev mailing list

Reply via email to