Class IndyBootstrap

java.lang.Object
io.opentelemetry.javaagent.tooling.instrumentation.indy.IndyBootstrap

public class IndyBootstrap extends Object
We instruct Byte Buddy (via Advice.WithCustomMapping.bootstrap(java.lang.reflect.Method)) to dispatch non-inlined advices via an invokedynamic (indy) instruction. The target method is linked to a dynamically created instrumentation module class loader that is specific to an instrumentation module and the class loader of the instrumented method.

The first invocation of an INVOKEDYNAMIC causes the JVM to dynamically link a CallSite. In this case, it will use the bootstrap(MethodHandles.Lookup, String, MethodType, Object[]) method to do that. This will also create the InstrumentationModuleClassLoader.


  Bootstrap CL ←──────────────────────────── Agent CL
      ↑ └───────── IndyBootstrapDispatcher ─ ↑ ──→ └────────────── bootstrap(MethodHandles.Lookup, String, MethodType, Object[])
    Ext/Platform CL               ↑          │                        ╷
      ↑                           ╷          │                        ↓
    System CL                     ╷          │        IndyModuleRegistry.getInstrumentationClassLoader(String, ClassLoader)
      ↑                           ╷          │                        ╷
    Common               linking of CallSite │                        ╷
    ↑    ↑             (on first invocation) │                        ╷
WebApp1  WebApp2                  ╷          │                     creates
         ↑ - InstrumentedClass    ╷          │                        ╷
         │                ╷       ╷          │                        ╷
         │                INVOKEDYNAMIC      │                        ↓
         └────────────────┼──────────────────InstrumentationModuleClassLoader
                          └╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶→├ AdviceClass
                                                 ├ AdviceHelper
                                                 └ LookupExposer

Legend:
 ╶╶→ method calls
 ──→ class loader parent/child relationships
  • Method Details

    • getIndyBootstrapMethod

      public static Method getIndyBootstrapMethod()
    • emitIndyStaticCall

      public static void emitIndyStaticCall(org.objectweb.asm.MethodVisitor mv, String name, String descriptor, Class<?> instrumentationModule, String helperClassDotName)
      Emit invokedynamic instruction that will call the given helper class static method.