aspose file tools*
The moose likes Performance and the fly likes Byte code interpretation Vs JIT Compilation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Byte code interpretation Vs JIT Compilation" Watch "Byte code interpretation Vs JIT Compilation" New topic
Author

Byte code interpretation Vs JIT Compilation

Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
Hello All

I am newbie as far as Java Performance topic is concerned.
I came across the below lines as I was going through an article and trying to understand it.
Here are the question that I have . Any help is highly appreciated.

"The original JVMs interpreted bytecodes one at a time. Second-generation JVMs added a JIT compiler, which compiles each method to native code upon first execution, then executes the native code"

1. 'JVMs interpreted bytecodes' , will this mean that the byte code is never converted to machine language ? what does 'interpreted' actually mean ?

2. 'JVMs interpreted bytecodes one at a time', what does 'one at a time' mean ?

Any help is highly appreciated.
Lingan.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

Let me answer the easy one: "One at a time" means what it usually means in English. If you eat nuts "one at a time" then you pick up a nut and eat it, then pick up another nut and eat it, and so on.
Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
Ok .

I understand that JIT converts the byte code to native code only when the particular piece of code is executed.
Now in this context , when it is said that the interpretation happens one at a time , is it like each of line of code is interpreted one by one ? then to me it is almost like JIT . I know this cant be the case hence my question.

Thanks
Lingan
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

Lingan Rajan wrote:
Now in this context , when it is said that the interpretation happens one at a time , is it like each of line of code is interpreted one by one ? then to me it is almost like JIT . I know this cant be the case hence my question.


Apart from the fact that a line of code would be compiled into more than one bytecode, yes. Interpretation happens one bytecode at a time.

Sure it's just like JIT in that it happens one bytecode at a time. I don't see why two similar things shouldn't operate in similar ways.
Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
Thanks for answering that part.

So I think 'interpreted' actually means that the byte code are being compiled to machine code right ?

In case of a stand alone program run with JVM without JIT , are all the classes's byte code interpreted to machine code in one shot and then executed line by line ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

Lingan Rajan wrote:So I think 'interpreted' actually means that the byte code are being compiled to machine code right ?


No. In fact the implication is that the byte codes are NOT compiled to machine code.

You seem to have missed finding out what a "virtual machine" (as in JVM = Java Virtual Machine) actually does. Go back and find that out.
Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
I went through the JVM spec , still could not get that clarified.
Could you give me a explanation or point to some links ?

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

Lingan Rajan wrote:I went through the JVM spec , still could not get that clarified.


Of course not. The JVM spec assumes you already know what a virtual machine is, its purpose is to explain how this particular virtual machine should work. If you're looking for a link which explains what a virtual machine is, you could start with the Wikipedia article Virtual machine.
dominic dumo
Greenhorn

Joined: Sep 11, 2011
Posts: 1
When the interpreted method is used every time a line of bytecode is to be executed it is converted to machine code and then executed.

When the JIT method is used every time a method is called the entire method is optimized, converted to machine code, and then cached. Next time that same method is called the JIT will use the cached code instead of re-compiling it.

You can probably see how JITed code would run much quicker.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
When the interpreted method is used every time a line of bytecode is to be executed it is converted to machine code and then executed.


No, go back and read about how a Virtual Machine works. In a strict interpreter there is NO conversion to machine code, instead a single byte code is used to select an existing machine code routine which executes in the context of the Thread. Then the interpreter move to the next byte code - the term "line of byte code" makes no sense.

In fact, there is yet another layer of indirection - a "machine code" instruction causes execution of Microcode embedded in the CPU design.

Bill

Java Resources at www.wbrogden.com
Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
Hello All
I did go through articles on Virtual Machines and Interpretation/Compiled languages.
I will greatly appreciate if some one can give me a clarification on the below and verify if my understanding is right.

1. Java Virtual Machines have instruction sets of their own.
During normal interpretation these instruction sets are used to execute the statements.
Byte codes are not compiled to the machine code in this scenario

2. During JIT compilation parts of the code are compiled to machine code.
In this case the JVM instruction sets are not used at all.

Thanks
Lingan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Byte code interpretation Vs JIT Compilation
 
Similar Threads
JIT Compiler
jit vs. interpreter
JIT Question
What does JIT compiler do ?
Java code and JIT compilation