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

JIT....?

santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
how JIT (Just in Time) helps, the Java Virtual Machine to increase the execution speed. ?

Creativity is nothing but Breaking Rules
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

Did you google? Did you get any results?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
No i did not get any information regarding how JIT improves performance
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

Strange.
I got this as the first hit.
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
i had gone that document previously but did not get clear information
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14348
    
  22

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?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
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

Joined: Aug 16, 2005
Posts: 14348
    
  22

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

    Joined: Oct 13, 2005
    Posts: 39851
        
      28
    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

    Joined: Apr 06, 2009
    Posts: 296

    " 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
    Sheriff

    Joined: Sep 28, 2004
    Posts: 18991
        
      40

    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

    Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: JIT....?