jit

  • java bytecode is a intermediate code, not the native code, it need to be converted to native code in order to run it
  • jit will convert bytecode to native code
  • just-in-time (JIT) compilation, also known as dynamic translation, is compilation done during execution of a program – at run time – rather than prior to execution.[1] Most often this consists of translation to machine code, which is then executed directly, but can also refer to translation to another format.

    JIT compilation is a combination of the two traditional approaches to translation to machine code – ahead-of-time compilation (AOT), and interpretation – and combines some advantages and drawbacks of both.[1] Roughly, JIT compilation combines the speed of compiled code with the flexibility of interpretation, with the overhead of an interpreter and the additional overhead of compiling (not just interpreting). JIT compilation is a form of dynamic compilation, and allows adaptive optimization such as dynamic recompilation – thus in theory JIT compilation can yield faster execution than static compilation. Interpretation and JIT compilation are particularly suited for dynamic programming languages, as the runtime system can handle late-bound data types and enforce security guarantees.

  • why jit for java?
    • A JIT compiler runs after the program has started and compiles the code (usually bytecode or some kind of VM instructions) on the fly (or just-in-time, as it’s called) into a form that’s usually faster, typically the host CPU’s native instruction set. A JIT has access to dynamic runtime information whereas a standard compiler doesn’t and can make better optimizations like inlining functions that are used frequently.

      This is in contrast to a traditional compiler that compiles all the code to machine language beforethe program is first run.

  • we can also compile all the java code to machine code, but will lost some advantage:
    • Compiling at install time requires an installation 🙂 With a VM, only the VM is installed, and applications are download-and-run
    • If a VM has a bug in the JIT, upgrading the VM fixes all programs that hit the bug. If you compile at installation, upgrading your Java/.NET installation requires recompiling all of your installed programs using that platform.
    • Some optimizations are available to a JIT that are difficult to do with ahead-of-time compilation, like dynamically optimizing a hot path through multiple functions based on the current application’s workload.

    Of course, there are advantages to ahead-of-time, too, like not paying the cost of JIT compiling every time you run a program.

Advertisements
This entry was posted in Knowledge. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s