6 ms·
Why did Java stay with a JIT for so long, anyway? Java is hard-compilable, and GCC can compile Java. The original reason for a JIT was to speed up applets runn
by Animats 11y ago
Why did Java stay with a JIT for so long, anyway? Java is hard-compilable, and GCC can compile Java. The original reason for a JIT was to speed up applets running in the browser. (Anyone remember those?) Server side, there was never much point.
- Kristine1975 11y agoCynical answer: It wouldn't fit the "write once, run anywhere" slogan used to market Java.
- jerven 11y agoJIT gives you more information about how the program is actually run. This allows a large number of optimistic optimizations that GCC etc... can not make. This in theory allows faster code to be generated. Than ahead of time compilers can. In practice this is destroyed by the pointer chasing default datastructure in java. If you are executing "C" using JVM techniques then a research JVM JITing C code gets within 15% of GCC on a reasonable set of benchmarks. (http://chrisseaton.com/plas15/safec.pdf http://chrisseaton.com/plas15/safec.pdf). These benchmarks are favorable for the AOT GCC as they have few function pointers, startup configuration switches and little dataflow variety. I suspect that specific compiler optimizations on the C code for the dense matrix transform in GCC are bigger part of why GCC is faster than the fact that it is AOT instead of JIT. There are also a number of AOT compilers for Java e.g. excelsior. But I have not seen superior performance with that over an equivalent hotspot release.
- masklinn 11y ago> JIT gives you more information about how the program is actually run. This allows a large number of optimistic optimizations that GCC etc... can not make. They'd be surprised to learn that considering GCC supports profile-guided optimisation.
- Kristine1975 11y agoHowever a JIT can actually optimize the code for the current usage profile, whereas profile-guided optimizations in AOT compilation cannot.
- pron 11y agoModern JITs basically are very sophisticated profile-guided optimizing compilers. Unlike AOT PGOs, though, JITs can adapt to changing program phases, that are common in server applications (e.g. when certain monitoring/troubleshooting/graceful-degradation features are turned on). On the whole, JITs can produce better code. But this, too, is a tradeoff. Some JITs (like JS's in the browser) require fast compilation, so some optimizations are ruled out. Very sophisticated optimizations require time, and therefore are often useful when you have tiered compilation (i.e. a fast JIT followed by an optimizing JIT), and tiered compilation is yet another complication that makes JITs hard to implement.
- jules 11y agoAn AOT compiler can decide to compile a JIT code generator into the binary, so even in theory AOT beats JIT. In practice it almost never makes sense to do this for a language that isn't full of gratuitous dynamism.
- pron 11y ago> An AOT compiler can decide to compile a JIT code generator into the binary, so even in theory AOT beats JIT That is not AOT. That is compiling some code AOT and some JIT[1]. It's not a contest. Those are two very common compilation strategies, each with its own pros and cons. > In practice it almost never makes sense to do this for a language that isn't full of gratuitous dynamism. What you call "gratuitous dynamism" others call simple, general abstractions. BTW, even Haskell/ML-style pattern matching qualifies as "dynamism" in this case, as this is something a JIT optimizes just as it does virtual dispatch (the two are duals). [1]: Also, a compiler doesn't generally insert huge chunks of static code into its output. That's the job of a linker. What you've described is a system comprised of an AOT compiler, a JIT compiler, and a linker that links the JIT compiler and the AOT-compiled code into the binary. Yeah, such a system is at least as powerful as just the JIT component alone, but such a system is not called an AOT compiler.
- 1ris 11y agoOne could distribute JARs (or JARs with type annotations) and do AOT compilation on demand. As in: Compile on programm startup.
- pjmlp 11y agoAlmost all commercial JVMs do that. And you can do that in the reference JDK by setting the execution threshold to 0.
- pron 11y agoOn the contrary. See me other comment: https://news.ycombinator.com/item?id=10344886 https://news.ycombinator.com/item?id=10344886
- pjmlp 11y ago> Why did Java stay with a JIT for so long, anyway? I read in some forum once, that it was political. At certain point it became kind of heresy at Sun to suggest AOT compilation. Hence why all Java AOT compilers are only available from third party JVM vendors. If someone from those days at Sun can confirm or deny it, please do. I imagine it took Oracle some beating in high performance trading, from the companies wanting to move from C++ to Java, to really change their mind. This is what triggered the value types, JNI replacement work. So AOT was the next checkpoint in the list I guess.