-
Notifications
You must be signed in to change notification settings - Fork 0
CompiledIMT
Architecture-specific compiled IMT dispatch code for fast interface calls.
The CompiledIMT is the machine-code form of the IMT (Interface Method Table), generated by the JIT compiler to optimize interface method dispatch. Where the Java-side IMT uses hash-based array lookup with potential collision list traversal, the CompiledIMT compiles this logic into a direct jump table, eliminating the overhead of Java method calls and memory indirection.
Interface dispatch via the IMT involves:
- Loading the IMT array from the TIB
- Computing
selector % 64 - Branching on whether the slot holds a single method or collision list
- Potentially searching a collision list
Each step involves Java heap access and virtual method dispatch. The CompiledIMT collapses all of this into a single direct jump from method selector to method entry point.
| Class / File | Role |
|---|---|
core/src/core/org/jnode/vm/compiler/CompiledIMT.java |
Abstract base class defining getIMTAddress()
|
core/src/core/org/jnode/vm/compiler/IMTCompiler.java |
Abstract compiler that generates CompiledIMT bytecode |
core/src/core/org/jnode/vm/x86/compiler/X86CompiledIMT.java |
x86-specific implementation holding compiled bytecode array |
core/src/core/org/jnode/vm/x86/compiler/X86Assembler.java |
Bytecode emitter for x86 machine code generation |
public abstract class CompiledIMT {
public abstract Word getIMTAddress();
}The abstract base provides the compiled IMT address. Each architecture implements this with its own bytecode array and address computation.
public final class X86CompiledIMT extends CompiledIMT {
private final byte[] code;
private final int address;
public X86CompiledIMT(byte[] code, int address) {
this.code = code;
this.address = address;
}
@Override
public Word getIMTAddress() {
return Word.factory().create(address);
}
}public abstract class IMTCompiler {
public abstract CompiledIMT compileIMT(IMTBuilder builder);
protected byte[] generateJumpTable(IMTBuilder builder) {
// For each of 64 slots, emit:
// - Direct jump to method if single method
// - Hash check + jump if collision list
}
}- During class preparation,
VmClassType.prepareTIB()builds the IMT viaIMTBuilder - If IMT compilation is enabled, the VM calls
imtCompiler.compileIMT(imtBuilder) -
IMTCompileranalyzes each of the 64 IMT slots:- If single method: emit direct
jmpto method entry - If collision list: emit selector check + indirect jump
- If single method: emit direct
- The generated bytecode array is wrapped in a
CompiledIMTinstance - The compiled address is stored in TIB at
COMPILED_IMT_INDEX
invokeinterface Foo.bar()
→ load this object's TIB[COMPILED_IMT_INDEX]
→ if non-null: jump to compiled IMT address
→ if null: fall back to Java-side IMT lookup
The compiled form maps selector values directly to entry points:
IMT Entry (per selector):
selector_low = selector & 0x3F // selector % 64
jmp [compiledIMT_base + selector_low * 4] // 4-byte absolute address
This provides O(1) dispatch with a single memory load and indirect jump.
See IMT and Object-Layout for the TIB layout:
TIB[index] Layout:
[0] VmType reference
[1] IMT (Object[])
[2] IMT collision flags (boolean[])
[3] CompiledIMT — this page
[4] Superclasses array
[5..N] vtable
The CompiledIMT at index 3 may be null if compilation failed or is disabled.
- CompiledIMT is optional: If TIB[3] is null, the runtime falls back to Java-side IMT lookup. Some architectures or build configurations may not implement CompiledIMT.
- Architecture-specific: CompiledIMT is generated per-target architecture (x86, x86_64, etc.). The bytecode format is architecture-dependent.
-
JIT must use it correctly: The JIT's
visit_invokeinterfacemust check for CompiledIMT availability and emit appropriate dispatch code. - Collision handling inlined: The compiled form typically handles common cases (no collision) with direct jumps and falls back for collision lists.
- IMT — Java-side interface method table with hash collision handling
- Virtual-Methods — Overview of method dispatch including vtable, IMT, and CompiledIMT
- TIB — Type Information Block containing IMT and CompiledIMT
- JIT-Compilers — How compilers generate and use CompiledIMT
- Object-Layout — TIB structure and memory layout