Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jit

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?

like image 845
Rafi Kamal Avatar asked Oct 20 '25 09:10

Rafi Kamal


2 Answers

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.

like image 111
Peter Lawrey Avatar answered Oct 23 '25 00:10

Peter Lawrey


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.

like image 34
user1252434 Avatar answered Oct 22 '25 23:10

user1252434