Version française
Home     About     Download     Resources     Contact us    
Browse thread
JIT-compilation for OCaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <frisch@c...>
Subject: Re: JIT-compilation for OCaml?
Hello,

my 0.02 euros ideas about a JIT for OCaml:

There are basically two ways to JIT-compile a bytecode program: at
startup or during runtime.

Compiling the bytecode at startup makes sense for instance for web
distributed code (applets). Otherwise, if the code is to be used more than
once by a given user, it's better to convert statically the bytecode to
native code. Hacking ocamlrun to produce native code simply by expanding
each opcode from the abstract machine seems fairly easy. Some
optimizations are lost. Another idea would be to make the compiler
outputs the "lambda" intermediate code (shared between ocamlc and
ocamlopt) and distribute it, maybe with some modification to
prevent reverse engineering. The backend of ocamlopt (code generation)
is run by the user to produce an executable program.

Compiling the code really during runtime opens the door to further
optimizations (I guess this is how Java JIT compilers work, but I have no
idea). For instance, it is possible to watch conditionnal jumps and
reorganize the code so that the most taken branches don't need any jump.
The GC and the memory allocator have the opportunity to adapt themselves
to the application. Of course, this only makes sense for long running
applications. The user should be able to record the optimization
information collected. Actually, there are two operations involved: a
profiler (a bytecode interpreter that also collects optimization
information) and a bytecode-to-nativecode converter as in the previous
paragraph. I don't see the advantage of mixing them in a complex JIT
compiler (which will be slow for a long time after startup if the
optimizations are non trivial).


Happy new year to everybody !


-- 
  Alain Frisch