0

I'm not getting the distinction between bytecode interpretation and JIT compilation. I've read many, many, many, many postings and articles on this topic.

One Javaworld.com article that I found on Java compilers provides this explanation:

The simplest form of bytecode compilation is called interpretation. An interpreter simply looks up the hardware instructions for every bytecode instruction and sends it off to be executed by the CPU.

You could think of interpretation similar to using a dictionary: for a specific word (bytecode instruction) there is an exact translation (machine code instruction).

So consider this example of bytcode interpretation (from the same article):

A. Java application code:

static int add7( int x ) {
      return x+7;
}

B. javac compiler compiles the program from A into Java byte code

iload0
 bipush 7
 iadd
 ireturn

C. java interpreter translates the bytecode from B into native machine instruction code (e.g. Intel x86). Below is some assembly code representing machine code.

lea rax,[rdx+7]
  ret

My understanding is that going from step B to step C requires compiling, right? The definition of a compiler is a software component that translates from one (high level) language to another (lower level) language. That is exactly what is going on between step B to C.

So, assuming that my understanding is correct, then what is the major difference between interpreting (which is compiling) and JIT compiling? I get that the JIT compiler can do things like add performance counters and optimizations (e.g. inlining), but if we leave those out, aren't the interpreter and the JIT compiler doing the same thing?

Community
  • 1
  • 1
stackoverflowuser2010
  • 38,621
  • 48
  • 169
  • 217
  • Interpretation is *not* compilation. Anyone saying that is misinformed. E.g. [Wikipedia](https://en.wikipedia.org/wiki/Interpreter_%28computing%29) starts out saying: *In computer science, an interpreter is a computer program that directly executes, i.e. performs, instructions written in a programming or scripting language, **without previously compiling them** into a machine language program.* – Andreas May 06 '16 at 20:38
  • The interpreter isn't translating B into native machine instructions; the interpreter is built out of machine instructions which interpret `B`. – Louis Wasserman May 06 '16 at 20:40
  • Your step C is what JIT does. It is *not* what an interpreter does. – Andreas May 06 '16 at 20:43
  • These kind of questions always seem to come down to semantics. You're absolutely correct about the important thing: if you look at a compliant JVM as a black box, there is no way to know if it is doing JIT compilation or is just an interpreter. The inputs to and outputs from the system are the same regardless of whether the specific JVM implementation chooses to optimize via compilation. So JIT compilation is not a functional aspect of the JVM *specification*, it's a technical consideration in JVM *implementation*. – Mark Peters May 06 '16 at 20:52

0 Answers0