I’ve been talking with Andrew more about using gcj as a JIT. This
seems not only feasible, but attractive, at this point.
First, we can easily hook into libgcj. We simply override
ClassLoader.defineClass
to call into our special code.
There we compute a crypto hash of the class and use this to look in a
cache for the corresponding shared library.
If we don’t find the library, we write out and compile the class
file. We do this by adding a special mode to gcj so that it doesn’t
have to load any extra classes. It just compiles exactly what is in
the class file with very little interpretation.
We can make this safe quite easily. First, we do as much
verification as possible in gcj itself. However, we don’t do any
checking of reference types — in fact we can’t do this, since the
compile time environment might be different from the runtime
environment. Instead we have the gcj verifier emit a list of
verification assertions, and then when loading the shared object we
run through this list and check each one. This means that the class
cache is perfectly safe even if we load the class via a strange class
loader.