2

As far as i understand jvm is something between interpreter and compiler. Bytecode can't be executed directly, but at the same time JIT compiler doesn't compile all the bytecode into the native code in advance, but choose the most used parts and compile only them. My question is why not to compile all the bytecode code into the native code in advance, for example before the first run? (The reason is that native code is faster to execute.)

Some Name
  • 8,555
  • 5
  • 27
  • 77
Ekaterina
  • 1,642
  • 3
  • 19
  • 36
  • 4
    One reason is that JIT is optimizing compiler and some of the optimizations can only be done after runtime profiling. – yegodm Feb 02 '19 at 20:19
  • The Hiotspot JVM is not a JIT. There were JIT compilers in the 1990s that behaved as you described. They suffered from code bloat and excessive memory usage. The Hotspot JVM is a response to that problem, via selective compilation of the important bits. – user207421 Feb 02 '19 at 20:31
  • Please note: there are quite some efforts going on to significantly rework the (legacy and extremely complicated) jit implementation. One part of that is to also enable pre compilation. See for ahead of time compilation : https://www.google.com/amp/s/www.infoworld.com/article/3192105/java/java-9s-aot-compiler-use-at-your-own-risk.amp.html for example. – GhostCat Feb 02 '19 at 20:31
  • The JIT knows more than any ahead-of-time compiler can about how the code is going to be used, what patterns will appear in calls (e.g. which implementations of interfaces are most used), and can optimize _better_ than an ahead of time compiler with that information. – Louis Wasserman Feb 02 '19 at 22:03
  • For the record, an implementation of Java (a JVM) need not have a JIT nor an interpreter. That is an implementation detail left open by the [Java specifications](https://docs.oracle.com/javase/specs/). – Basil Bourque Feb 02 '19 at 23:44
  • @user207421 Your comment is incorrect: **HotSpot most certainly is a JIT**. [See Wikipedia](https://en.wikipedia.org/wiki/HotSpot). Or see the [Oracle site describing HotSpot](https://www.oracle.com/technetwork/java/javase/tech/index-jsp-136373.html) – Basil Bourque Feb 02 '19 at 23:46

0 Answers0