Compiling to Java as a target language
11 points by abhin4v
11 points by abhin4v
I didn't see any section that clearly calls out what the advantages are to compiling to Java rather than compiling for the JVM. Obviously, Java is a much higher level language than JVM bytecode. Is that it?
edit: sorry, I mis-read your comment. good question. I suppose it's easier to generate Java if you're familiar with it, since most people haven't looked at JVM code?
Each time you go down from n to n + 1 on this ladder, performance will go up, but implementation code size and complexity will go up by about a factor of two.
It turns out that Java occupies a sweet spot: relatively low implementation complexity, but the biggest percentage-wise gain in performance.
An interesting approach compared to Clojure, which compiles directly to JVM bytecode. This can make it a little complicated to debug (you have to either use a decompiler or learn to read the bytecode), but it bypasses a lot of the issues with generating correct java code (which is a dense language).
When I tried playing with assembling some Dalvik bytecode, I was surprised to discover that Java is actually not far from just being a syntax sugar for the JVM architecture. Made some sense in retrospect, but FWIW I didn't know until then that one can even make a virtual machine be so high-level. I wonder if the course linked in the OP could also include progressing from compiling to Java to compiling to JVM bytecode indeed. Seeing the small differences between Java and JVM was what made me finally understand what's the problem that "register allocation" algorithms are needed to solve.