Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does not JAVA compile its IL into Native code right after Install? [duplicate]

Tags:

java

jvm

jit

I just read C++ performance vs Java/C#.

As already said in the previous posts, JIT can compile IL/bytecode into native code at runtime. The cost of that was mentionned, but not to its conclusion:

JIT has one massive problem is that it can't compile everything: JIT compiling takes time, so the JIT will compile only some parts of the code, whereas a static compiler will produce a full native binary: For some kind of programs, the static compiler will simply easily outperform the JIT.

And I got a curiosity why java doesn't compile everything while installing it in device.

If it does, we don't need to think about performance loss with compilation time, and conform to diverse devices.

like image 798
Jeonghan Joo Avatar asked Mar 05 '26 00:03

Jeonghan Joo


1 Answers

Actually it's JVM dependent. The new Google's JVM uses AOT:

ART uses an ahead-of-time (AOT) compiler that compiles to machine code when you install the app.

If you're asking why former Sun, now Oracle's JVM doesn't use AOT - it was Sun's engineers choice at the time. For desktop Java there is (usually) no step of installation of the application that would allow to do the AOT and compiling the whole classpath upon load is too time consuming.

More here and of course at Google android site.

like image 91
MirMasej Avatar answered Mar 07 '26 13:03

MirMasej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!