Rafi Kamal
Rafi Kamal

Reputation: 4600

Why JIT compilers can't be used to produce binary?

JIT compilers are used to convert java byte-code into native machine language. And as far as I know, there is no program which can directly convert java byte-code into binary file such as .exe files. So why JIT compilers can't be used to produce binary from the byte-code?

Upvotes: 4

Views: 1100

Answers (5)

Dmitry Leskov
Dmitry Leskov

Reputation: 3155

IBM Java Runtime is capable of storing the results of dynamic bytecode to native code compilation in its shared data cache and sharing it between JVMs (prooflink).

Upvotes: 0

Tobias
Tobias

Reputation: 3110

The aims of JITs and compilers are normally different, I think that is the main reason.

That said, the Maxine VM contains a JIT written in Java that is used to compile the entire VM itself and the output is written to a so-called bootimage, essentially being a binary. However, even this binary needs an executable, called loader, to start.

So, there is at least one example for a JIT that is used to produce a binary, but normally, the aims of a JIT do simply not include producing a binary.

Upvotes: 1

aravindKrishna
aravindKrishna

Reputation: 440

Jit is a re compiler, so for any particular system platform, it compiles the bytecode into the particular system code. So we cannot directly use the Jit to turn Java-byte code into binary executables.

When the jit produces binary code, its binary format will not support another platform. The main usage of a Jit-compiler is fast compilation as a second compiler for Java. Therefore Jit can't produce binaries from Java bytecode.

Upvotes: 0

user1252434
user1252434

Reputation: 2121

JIT = Just In Time. An *.exe is compiled way before of execution. </nitpick> ;)

As others said, there is more to a JVM than just compiling bytecode to native machine code. However, these parts of a JVM can be put into a native library ("dll").

There is at least one project to generate native binaries out of java code: GCJ (http://en.wikipedia.org/wiki/Gcj). I don't know how good it is and whether there is a windows version available. There might also be other Java-to-native compilers out there.

Upvotes: 2

Peter Lawrey
Peter Lawrey

Reputation: 533462

The JIT compiler, compiles the code dynamically.

  • It generates different code for different flavours of CPU.
  • It generates different code for different memory models, e.g. For tyhe 64-bit JVM, if the maximum heap size is < 4 GB, < 24 GB, < 32 GB or more, you will produce different code in each case.
  • It will re-compile code as classes are loaded and unloaded.
  • It will re-optimise code based on how it is used. e.g. if a flag which used to be off is not on and visa-versa.

A static compiler cannot do these things.

Upvotes: 5

Related Questions