Skip to content

ClassFileApiBackend (Java 26+): @Return, @TargetInstance, @Duration handlers not implemented #837

Description

@jbachorik

Summary

ClassFileApiBackend — introduced to handle class files with major version > 69 (Java 26+) using the JDK ClassFile API — silently skips probe handlers that use @Return, @TargetInstance, or @Duration parameters. This causes probes targeting Java 26+ classes to fire without those values, or to be dropped entirely, with only a debug-level log message.

The ASM backend (Instrumentor.java, used for class file versions ≤ 69) fully supports all three. The ClassFileApiBackend was introduced as a replacement for ASM on Java 26+ but was shipped without parity for these parameter types.

@Self was fixed in PR #836.

Affected parameter types

Annotation getSelfParameter() Status
@Self slot 0 (this) ✅ Fixed in PR #836
@Return return value captured before return ❌ Not implemented
@TargetInstance target object of a call site ❌ Not implemented (requires Kind.CALL support)
@Duration elapsed nanos between ENTRY and RETURN ❌ Not implemented

Why each is non-trivial

@Return
Requires capturing the return value at the RETURN point before it leaves the operand stack:

  • dup (reference) or dup2 (long/double) to preserve the value
  • Store in a temp local, call the handler, reload — or call with value on stack depending on descriptor
  • Must know the return type from the method descriptor at code-generation time

@Duration
Requires timing across two injection points:

  • At ENTRY: inject long __btrace_start = System.nanoTime(); stored in a new local variable slot
  • At RETURN: inject long __btrace_dur = System.nanoTime() - __btrace_start; and pass to handler
  • Adding a local variable requires updating the LocalVariableTable and stack map frames

@TargetInstance
Only relevant for Kind.CALL (call-site instrumentation), which ClassFileApiBackend does not support yet. Blocked on adding Kind.CALL support first.

Reproduction

Any @BTrace probe targeting a Java 26+ class (e.g. JDK internal classes when running on Java 27+) with:

@OnMethod(clazz = "some.Java27Class", method = "someMethod")
public static void handler(@Return Object ret) { ... }  // silently dropped

On Java 25 (ASM backend): probe fires and ret is populated.
On Java 27 (ClassFileApiBackend): probe handler is silently skipped — no output, no error.

Location

btrace-agent/src/main/java24/io/btrace/instr/ClassFileApiBackend.javaemitProbeCall() method.

The @Self fix (PR #836) shows the pattern for adding a new parameter type: thread a context flag through buildClassTransform → buildMethodTransform → buildCodeTransform → emitProbeCall and emit the appropriate bytecode instruction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions