opentelemetry-java-instrumentation icon indicating copy to clipboard operation
opentelemetry-java-instrumentation copied to clipboard

Allow any types in invokedynamic advice method signatures

Open JonasKunz opened this issue 7 months ago • 0 comments

Before this PR, instrumentations whic hare dispatched via invokedynamic would cause problems if they used certain types as return or paramter types:

When inserting the invokedynamic instruction, it is associated with a MethodType of the called method for the bytecode verifier to perform its job. If that MethodType contains references to types not visible to the instrumented class, it would make it unloadable after instrumentation.

This PR lifts this restriction by replacing all non java.* type references in the MethodType with java.lang.Object. This is an implementation for this discussion.

Unfortunately bytebuddy doesn't support this kind of transformation yet, so we have to manually erase the types via ASM before giving the advice to bytebuddy.

I'll open a feature request there to eventually allow us to do this directly with bytebuddy, in order to avoid the overhead of having to transform the advice bytecode.

JonasKunz avatar Jul 22 '24 07:07 JonasKunz