Interface TypeInstrumentation


public interface TypeInstrumentation
Interface representing a single type instrumentation. Part of an InstrumentationModule.

Classes implementing TypeInstrumentation should be public and non-final so that it's possible to extend and reuse them in vendor distributions.

  • Method Details

    • classLoaderOptimization

      default net.bytebuddy.matcher.ElementMatcher<ClassLoader> classLoaderOptimization()
      An optimization to short circuit matching in the case where the instrumented library is not even present on the class path.

      Most applications have only a small subset of libraries on their class path, so this ends up being a very useful optimization.

      Some background on type matcher performance:

      Type matchers that only match against the type name are fast, e.g. ElementMatchers.named(String).

      All other type matchers require some level of bytecode inspection, e.g. ElementMatchers.isAnnotatedWith(ElementMatcher).

      Type matchers that need to inspect the super class hierarchy are even more expensive, e.g. AgentElementMatchers.implementsInterface(ElementMatcher). This is because they require inspecting multiple super classes/interfaces as well (which may not even be loaded yet in which case their bytecode has to be read and inspected).

      Returns:
      A type matcher that rejects classloaders that do not contain desired interfaces or base classes.
    • typeMatcher

      net.bytebuddy.matcher.ElementMatcher<net.bytebuddy.description.type.TypeDescription> typeMatcher()
      Returns a type matcher defining which classes should undergo transformations defined in the transform(TypeTransformer) method.
    • transform

      void transform(TypeTransformer transformer)
      Define transformations that should be applied to classes matched by typeMatcher(), for example: apply advice classes to chosen methods (TypeTransformer.applyAdviceToMethod(ElementMatcher, String).