Annotation Interface CompilerDirectives.EarlyInline
- Enclosing class:
CompilerDirectives
@Retention(RUNTIME)
@Target({METHOD,CONSTRUCTOR})
public static @interface CompilerDirectives.EarlyInline
Marks a method or constructor as a candidate for early inlining during Truffle compilation.
Methods annotated with @EarlyInline are considered by a dedicated early inlining
phase before partial evaluation. This exposes the helper's control flow and state updates
directly in the caller so that other Truffle directives such as ExplodeLoop and
CompilerDirectives.EarlyEscapeAnalysis can see and optimize them.
Only direct calls whose target method is annotated are considered, and normal inlining preconditions still apply. Indirect calls, native methods, and methods that cannot be inlined are ignored.
Typical use cases
- Inlining small branch or bytecode handlers into a
merge-explodedinterpreter loop so that loop explosion can merge state across the helper call. - Inlining helpers that update non-escaping state objects in methods annotated with
CompilerDirectives.EarlyEscapeAnalysis, improving escape analysis and scalar replacement.
Example: early inlining of a branch handler
@CompilationFinal(dimensions = 1) private final byte[] bytecodes = new byte[]{0, 1, 4, 2, 3};
@ExplodeLoop(kind = LoopExplosionKind.MERGE_EXPLODE)
int execute(Boolean v) {
byte[] bc = this.bytecodes;
int bci = 0;
while (true) {
CompilerAsserts.partialEvaluationConstant(bci);
switch (bc[bci]) {
case 0:
bci++;
break;
case 1:
// {@code branchTrue} is inlined before partial evaluation.
bci = branchTrue(bc, bci, v);
break;
case 2:
return 41;
case 3:
return 42;
default:
throw CompilerDirectives.shouldNotReachHere();
}
}
}
@EarlyInline
private static int branchTrue(byte[] bc, int bci, Boolean v) {
if (v) {
return bc[bci + 1];
} else {
return bci + 2;
}
}
- Since:
- 25.1