3 ms·
Just to add a bit of color to what you're saying, Java has (historically at least) worked fairly hard to NOT do any optimization in the first pass. JVM bytecode
by kjeetgill 8y ago
Just to add a bit of color to what you're saying, Java has (historically at least) worked fairly hard to NOT do any optimization in the first pass. JVM bytecode is a fairly straightforward trivial translation of Java code.
JITs do have much more information to leverage for optimization. But they have 2 balancing acts:
1) All the tracking, profiling, and compilation machinery they need to operate concurrently need to cost less than the advantages they bring. There's amortization here in longer running programs.
2) Much of that optimisation goes into bringing languages UP to speed, let alone pull ahead. JITed languages don't just have more information at runtime but typically have much less at compile time.
Take Java and C++ for example. In Java, every call is a virtual call and worse, any call outside of your class can look completly different at runtime (besides the signature) than it did at compile time. Then add all the classloading/bytecode weaving that's actually common. C++ on the other hand knows what's virtual, what's not, what's linked from another lib up front.
- nineteen999 8y agoThanks for your informative reply. I'm not much of a Java programmer (my experience is mainly C and more recently C++, plus a lot of traditional scripting languages) - when you say C++ knows what's linked from another library, are you referring to the dynamic linking process, where ld at least looks at all the libraries and resolves the references at link time, is that correct? Whereas Java has to resolve all its references to stuff in .jar files at runtime?
- kjeetgill 8y agoYep, that's exactly what I was referring to. Java will treat every other class as distant as C++ will with a .so ... But it can also in line into these java classes at runtime.