Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Just-in-time compilation

  1. Sep 28, 2009 #1
    Does "JIT" only occur when translating some intermediate form of the program into native code? Or can it also occur in other ways? For example, say you have a compiler that kind of acts like an interpreter in that for each line it compiles that source code into native code and immediately after compiling that line it executes it.

    So for each line, you go through these steps:
    1) Compile
    2) Execute

    To me it seems that something like this would be slow because constantly compiling & executing seems like a pretty inefficient way of computing. But, it was the only example I could think of.

    Thanks,

    --Jonathan
     
  2. jcsd
  3. Sep 28, 2009 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Chromium,

    It would be very inefficient to "compile" one line of code at a time. Instead, entire modules or classes are just-in-time compiled before being used.

    - Warren
     
  4. Oct 8, 2009 #3

    harborsparrow

    User Avatar
    Gold Member

    Also, already-compiled classes and modules are kept loaded (in executable form) in memory (as long as enough memory is available) so that if they are called again, no compilation is needed. This causes programs to "warm up"--once most parts of a program have been JIT-compiled, it runs about as fast as a native executable that is entirely pre-compiled.
     
  5. Oct 23, 2009 #4
    JITing usually occurs at the subroutine level or higher. Compilation (or interpretation) produces an intermediate form (a tree usually) that represents the source statements. It is common for these syntax trees to span entire subroutines, that way they can refer to each other. For example an 'if' statement will refer to the 'else' part. Therefore when compiling the whole tree is done at once. JITing (in the .NET or Java sense) refers to taking an intermediate form (IL or byte codes) and compiling them into machine code. At this level there is no source code as it has already been compiled away.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Just-in-time compilation
  1. Difficulty Compiling (Replies: 3)

Loading...