Alex Rivera | Logout

JIT compiler vs offline compilers

Asked 2009-02-11T18:12:02.470
46

Are there scenarios where JIT compiler is faster than other compilers like C++?

Do you think in the future JIT compiler will just see minor optimizations, features but follow a similar performance, or will there be breakthroughs that will make it infinitely superior to other compilers?

It looks like the multi core paradigm has some promise but it's not universal magic.

Any insights?

Edit
Report

2 Answers

53

Yes, there certainly are such scenarios.

  • JIT compilation can use runtime profiling to optimize specific cases based on measurement of the characteristics of what the code is actually doing at the moment, and can recompile "hot" code as necessary. That's not theoretical; Java's HotSpot actually does this.
  • JITters can optimize for the specific CPU and memory configuration in use on the actual hardware where the program happens to be executing. For example, many .NET applications will run in either 32-bit or 64-bit code, depending upon where they are JITted. On 64 bit hardware they will use more registers, memory, and a better instruction set.
  • Virtual method calls inside of a tight loop can be replaced with static calls based on runtime knowledge of the type of the reference.

I think there will be breakthroughs in the future. In particular, I think that the combination of JIT compilation and dynamic typing will be significantly improved. We are already seeing this in the JavaScript space with Chrome's V8 and TraceMonkey. I expect to see other improvements of similar magnitude in the not-too-distant future. This is important because even so-called "statically typed" languages tend to have a number of dynamic features.

answered 2009-02-11T18:22:44.003
1

Lots of people answered maybe I am skimming (maybe I have have the wrong end of the stick) but for me they are two different things:

AFAIK there is nothing stopping you JIT'ing compiled c++ for example project Dynamo JIT'ed machine code:

http://arstechnica.com/reviews/1q00/dynamo/dynamo-1.html

And it did actually provide speed improvements under certain circumstances.

Compiling code, in the sense of a c++ compiler means taking code written in a language and turning it into a set of instructions (or in some cases another language to then be compiled again) that can be executed by some kind of logical device.

e.g. c++ compiling to assembly (I think ;-) or c# compiling to IL or Java compiling to byte code

JIT is a process that happens during execution. The machine executing the code analyses it to see if it can improve it. Java and C# are able to make use of both as the compiler prepares commands for the VM and then the VM has the opportunity at least to have another go at optimising it.

Some programs are not compiled they are interpreted, meaning the machine that runs them reads the exact code you wrote. These machines have the oppourtunity to do some JIT, but remember they can also be statically compiled, potentially be a third party vendor in ways that the original designer of the language never intended.

So to answer your question I don't think JIT will replace static compilers. I think there will always (as long as there is programming at least) be a place for taking a representation of a program and converting that into an set of instructions for a machine of some type. (potentially optimising while it does it)

HOWEVER, I do think that JIT may become a bigger part of the story, as the Java run time and .net run time evolve I am sure JIT will get better and given things like project Dynamo I guess there is

answered 2010-11-08T07:33:17.537

Your Answer