Why is the JIT bytecode compiled at runtime rather than at install time?

Compiling a program into bytecode instead of native code provides a certain level of portability, so there is a fairly suitable virtual machine.

But I'm a little surprised, why delay compilation? Why not just compile the byte code when installing the application?

And if this is done, why not port it to languages ​​that are directly compiled into native code? Compile them into an intermediate format, distribute the "JIT" compiler with the installer, and compile it on the target machine.

The only thing I can think of is optimizing runtime. This is the only thing that cannot be done during installation. Thoughts?

+7
source share
3 answers

Often it is precompiled. Consider, for example, precompiling.NET code with NGEN .

One reason for not precompiling everything would be expansion. Consider those languages ​​that allow reflection to be used to load additional code at run time.

+1
source

Some JIT compilers (like Java HotSpot) use an inlining based feedback type . They keep track of which types are actually used in the program, and calls to built-in functions based on the assumption that what they saw earlier is what they will see later. For this to work, they need to run the program through a series of iterations of their "hot loop" to find out what types are used.

This optimization is completely unavailable during installation.

+1
source

The bytecode was compiled , and C ++ code was compiled as well.

Also the JIT compiler, i.e...NET and Java, are massive and dynamic; And you cannot predict in a program that uses applications, so you need an entire runtime.

You also need to understand that a language oriented to a virtual machine has completely different design goals than a language oriented to bare metal.

Take C ++ and Java.

  • C ++ will not work in a virtual machine. In particular, most of the C ++ language design is RAII oriented.
  • Java will not work on bare metal for many reasons. primitive types for one.

EDIT: As Delnan correctly points out; JIT and similar technologies, although extremely effective for bytecode performance, are most likely not to be available during installation. Also compiling for a virtual machine is very different from compiling to native code.

0
source

All Articles