File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Byte code interpretation Vs JIT Compilation

 
Lingan Rajan
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20208
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20208
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20208
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20208
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Lingan Rajan
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic