This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JIT....?

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how JIT (Just in Time) helps, the Java Virtual Machine to increase the execution speed. ?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you google? Did you get any results?
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i did not get any information regarding how JIT improves performance
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange.
I got this as the first hit.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had gone that document previously but did not get clear information
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Wikipedia article is quite long and explains in detail how a JIT compiler works to improve performance.

What exactly in the article did you not understand?
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we know interpretor and JIT both will translate our byte code to native code what is the use of both any how both will do the same job wright.if not when does both will share work?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interpreter and a JIT work in slightly different ways.

This is what an interpreter does:

  • Get the next byte code.
  • Lookup what the operation belonging to that byte code is.
  • Execute the operation.
  • Go back to step 1.

  • And this is what a JIT does (simplified) when a Java method is called:

  • Check if we already have generated native machine instructions for this method. If yes, then execute those native instructions, and we're done.
  • Otherwise: Translate the byte code in the method to native machine instructions, store those machine instructions and execute them.

  • By using an interpreter, the JVM has to find out what operations to perform every time you call a method. By using a JIT, the byte code only needs to be translated to native machine instructions once, and then the native code can be called many times.

    Translating byte code to machine instructions costs time, so the first time when this has to be done, it takes more time to execute the method. But when you call the method for the second time, third time etc., it can be executed very quickly.

    I don't know why Java uses both an interpreter and the JIT. Probably this is because letting the JIT compile the whole program at once when you start it would take too much time. It's probably done as a trade-off between having your Java program start quickly and having it running quicky.
     
    Campbell Ritchie
    Sheriff
    Posts: 48424
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Jesper Young wrote: . . . letting the JIT compile the whole program at once when you start it would take too much time. . . .
    Better explanation than in WikiPedia There may be no point in compiling all the code to machine code; some methods in classes may not be used by this particular application.
     
    santhosh.R gowda
    Ranch Hand
    Posts: 296
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    " Jesper Young wrote:

    I don't know why Java uses both an interpreter and the JIT


    Dear sir Finally you had not cleared my doubt
     
    Henry Wong
    author
    Marshal
    Pie
    Posts: 20894
    76
    C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I don't know why Java uses both an interpreter and the JIT. Probably this is because letting the JIT compile the whole program at once when you start it would take too much time. It's probably done as a trade-off between having your Java program start quickly and having it running quicky.


    I think it has to do with options.... the current JVM actually has 2 different JITs and the interpreter. If you have a very short term program that may load a lot of classes and use them only a few times. The client JIT (-client) is great as it just compiles and runs.

    If you have a very long running program, which constantly run specific classes, such as a servlet in an app server, then the combination of interpreter and server JIT (-server) is great as it collects data about the classes (profiles it) and then does an optimized compile to native code later.

    There is even one JVM (Azul) that does a client JIT that can profile, and then later does the server JIT.

    Henry
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic