Saturday, 30 April 2011

Jato is a JIT-only JVM. This means that every piece of code executed is converted to native code before executing (i.e no interpretation is done). In the following discussion, we add dummy line numbers to code to make the discussion easier.
Concepts

We look at the how JIT-compiling is done in Jato. We compile a method only when it is called for the first time. When a method foo is called for the first time, we compile it into a call to a trampoline function.

10: a.foo()

1000: call trampoline

2000: trampoline:
2001: foobin = compile(foo)
2002: modify call trampoline at 1000 to call foobin

3000: foobin:
code for foo() generated by the trampoline

The trampoline function compiles the method body and jumps to the compiled method. The trampoline also backpatches the call site to point to the native code of the method. Note that one trampoline works for all functions. The method to be compiled and address of the call site are "parameters" to the trampoline function.

Implementation

The trampoline function is jit/trampoline.c: jit_magic_trampoline(). The function arch/x86/fixup.c: fixup_direct_calls() method implements call site back-patching once the compilation is completed.

No comments:

Post a Comment