Class AgentBuilder.DescriptionStrategy.SuperTypeLoading.Asynchronous
- All Implemented Interfaces:
AgentBuilder.DescriptionStrategy
- Enclosing class:
AgentBuilder.DescriptionStrategy.SuperTypeLoading
A description strategy that enforces the loading of any super type of a type description but delegates the actual type description to another description strategy.
Note: This description strategy delegates class loading to another thread in order to enforce the instrumentation of any
unloaded super type. This requires the executor service to supply at least as many threads as the deepest type hierarchy within the
application minus one for the instrumented type as class loading blocks any thread until all of its super types are loaded. These
threads are typically short lived which predestines the use of a Executors.newCachedThreadPool()
without any upper bound
for the maximum number of created threads.
Important: This strategy can dead-lock under two circumstances:
-
Classes declare circularities: Under normal circumstances, such scenarios result in a
ClassCircularityError
but can result in dead-locks when using this instrumentation strategy. - Class loaders declare custom locks: If a class loader locks another lock but itself during class loading, this lock cannot be released by this strategy.
For the above reasons, it is not recommended to use this strategy when the target class loader is unknown or if the target application might contain corrupt class files.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A class loading delegate that delegates loading of the super type to another thread.Nested classes/interfaces inherited from interface net.bytebuddy.agent.builder.AgentBuilder.DescriptionStrategy
AgentBuilder.DescriptionStrategy.Default, AgentBuilder.DescriptionStrategy.SuperTypeLoading
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AgentBuilder.DescriptionStrategy
The delegate description strategy.private final ExecutorService
The executor service to use for loading super types. -
Constructor Summary
ConstructorsConstructorDescriptionAsynchronous
(AgentBuilder.DescriptionStrategy delegate, ExecutorService executorService) Creates a new description strategy that enforces super type loading from another thread. -
Method Summary
Modifier and TypeMethodDescriptionapply
(String name, Class<?> type, TypePool typePool, AgentBuilder.CircularityLock circularityLock, ClassLoader classLoader, JavaModule module) Describes the given type.boolean
Indicates if this description strategy makes use of loaded type information and yields a different type description if no loaded type is available.
-
Field Details
-
delegate
The delegate description strategy. -
executorService
The executor service to use for loading super types.
-
-
Constructor Details
-
Asynchronous
Creates a new description strategy that enforces super type loading from another thread.- Parameters:
delegate
- The delegate description strategy.executorService
- The executor service to use for loading super types.
-
-
Method Details
-
isLoadedFirst
public boolean isLoadedFirst()Indicates if this description strategy makes use of loaded type information and yields a different type description if no loaded type is available.- Specified by:
isLoadedFirst
in interfaceAgentBuilder.DescriptionStrategy
- Returns:
true
if this description strategy prefers loaded type information when describing a type and only uses a type pool if loaded type information is not available.
-
apply
public TypeDescription apply(String name, @MaybeNull Class<?> type, TypePool typePool, AgentBuilder.CircularityLock circularityLock, @MaybeNull ClassLoader classLoader, @MaybeNull JavaModule module) Describes the given type.- Specified by:
apply
in interfaceAgentBuilder.DescriptionStrategy
- Parameters:
name
- The binary name of the type to describe.type
- The type that is being redefined, if a redefinition is applied ornull
if no redefined type is available.typePool
- The type pool to use for locating a type if required.circularityLock
- The currently used circularity lock.classLoader
- The type's class loader wherenull
represents the bootstrap class loader.module
- The type's module ornull
if the current VM does not support modules.- Returns:
- An appropriate type description.
-