Interface TypeInstrumentation
InstrumentationModule.
Classes implementing TypeInstrumentation should be public and non-final so that it's
possible to extend and reuse them in vendor distributions.
-
Method Summary
Modifier and TypeMethodDescriptiondefault net.bytebuddy.matcher.ElementMatcher<ClassLoader> An optimization to short circuit matching in the case where the instrumented library is not even present on the class path.voidtransform(TypeTransformer transformer) Define transformations that should be applied to classes matched bytypeMatcher(), for example: apply advice classes to chosen methods (TypeTransformer.applyAdviceToMethod(ElementMatcher, String).net.bytebuddy.matcher.ElementMatcher<net.bytebuddy.description.type.TypeDescription> Returns a type matcher defining which classes should undergo transformations defined in thetransform(TypeTransformer)method.
-
Method Details
-
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 thetransform(TypeTransformer)method. -
transform
Define transformations that should be applied to classes matched bytypeMatcher(), for example: apply advice classes to chosen methods (TypeTransformer.applyAdviceToMethod(ElementMatcher, String).
-