Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is bytecode JIT compiled at execution time and not at installation time?

Compiling a program to bytecode instead of native code enables a certain level of portability, so long a fitting Virtual Machine exists.

But I'm kinda wondering, why delay the compilation? Why not simply compile the byte code when installing an application?

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

The only thing I can think of is runtime optimization. That's about the only major thing that can't be done at installation time. Thoughts?

like image 786
Xeo Avatar asked Jun 18 '11 23:06

Xeo


People also ask

Is Java bytecode JIT compiled?

The JIT compiler is enabled by default, and is activated when a Java method is called. The JIT compiler compiles the bytecodes of that method into native machine code, compiling it "just in time" to run. When a method has been compiled, the JVM calls the compiled code of that method directly instead of interpreting it.

Why do web based languages use just in time compilation?

The advantages of a JIT are due to the fact, that since the compilation takes place in run time, a JIT compiler has access to dynamic runtime information enabling it to make better optimizations (such as inlining functions).

What is the use of JIT just in time compiler?

The Just-In-Time (JIT) compiler is a component of the runtime environment that improves the performance of Java™ applications by compiling bytecodes to native machine code at run time.

How many times does JIT compiler in runtime?

Just In Time Compiler (JIT) : The above loop code runs for 10 times if the value of i is 0. It is not necessary to compile the bytecode for 10 times again and again as the same instruction is going to execute for 10 times.


1 Answers

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

One reason for not precompiling everything would be extensibility. Consider those languages which allow use of reflection to load additional code at runtime.

like image 92
Dark Falcon Avatar answered Oct 07 '22 00:10

Dark Falcon