What are the advantages of just-in-time compilation versus ahead-of-time compilation?

  1. Greater portability: The
    deliverable (byte-code) stays
    portable

  2. At the same time, more platform-specific: Because the
    JIT-compilation takes place on the
    same system that the code runs, it
    can be very, very fine-tuned for
    that particular system. If you do
    ahead-of-time compilation (and still
    want to ship the same package to
    everyone), you have to compromise.

  3. Improvements in compiler technology can have an impact on
    existing programs. A better C
    compiler does not help you at all
    with programs already deployed. A
    better JIT-compiler will improve the
    performance of existing programs.
    The Java code you wrote ten years ago will run faster today.

  4. Adapting to run-time metrics. A JIT-compiler can not only look at
    the code and the target system, but
    also at how the code is used. It can
    instrument the running code, and
    make decisions about how to optimize
    according to, for example, what
    values the method parameters usually
    happen to have.

You are right that JIT adds to start-up cost, and so there is a time-constraint for it,
whereas ahead-of-time compilation can take all the time that it wants. This makes it
more appropriate for server-type applications, where start-up time is not so important
and a “warm-up phase” before the code gets really fast is acceptable.

I suppose it would be possible to store the result of a JIT compilation somewhere, so that it could be re-used the next time. That would give you “ahead-of-time” compilation for the second program run. Maybe the clever folks at Sun and Microsoft are of the opinion that a fresh JIT is already good enough and the extra complexity is not worth the trouble.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)