Top Description Inners Fields Constructors Methods
org.springframework.instrument.classloading

public Class InstrumentationLoadTimeWeaver

extends Object
implements LoadTimeWeaver
Class Inheritance
All Implemented Interfaces
org.springframework.instrument.classloading.LoadTimeWeaver
Imports
java.lang.instrument.ClassFileTransformer, .IllegalClassFormatException, .Instrumentation, java.security.ProtectionDomain, java.util.ArrayList, .List, org.springframework.instrument.InstrumentationSavingAgent, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils

LoadTimeWeaver relying on VM Instrumentation.

Start the JVM specifying the Java agent to be used — for example, as follows where spring-instrument-{version}.jar is a JAR file containing the InstrumentationSavingAgent class shipped with Spring and where {version} is the release version of the Spring Framework (e.g., 5.1.5.RELEASE).

-javaagent:path/to/spring-instrument-{version}.jar

In Eclipse, for example, add something similar to the following to the JVM arguments for the Eclipse "Run configuration":

-javaagent:${project_loc}/lib/spring-instrument-{version}.jar

Authors
Rod Johnson, Juergen Hoeller
Since
2.0
See Also
InstrumentationSavingAgent

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
InstrumentationLoadTimeWeaver.FilteringClassFileTransformer

Decorator that only applies the given target transformer to a specific ClassLoader.

private static class
InstrumentationLoadTimeWeaver.InstrumentationAccessor

Inner class to avoid InstrumentationSavingAgent dependency.

Field Summary

Modifier and TypeField and Description
private static final boolean
private final ClassLoader
private final Instrumentation
private final List<ClassFileTransformer>

Constructor Summary

AccessConstructor and Description
public
InstrumentationLoadTimeWeaver()

Create a new InstrumentationLoadTimeWeaver for the default ClassLoader.

public
InstrumentationLoadTimeWeaver(ClassLoader
the ClassLoader that registered transformers are supposed to apply to
classLoader
)

Create a new InstrumentationLoadTimeWeaver for the given ClassLoader.

Method Summary

Modifier and TypeMethod and Description
public void
addTransformer(ClassFileTransformer
the ClassFileTransformer to add
transformer
)

Implements org.springframework.instrument.classloading.LoadTimeWeaver.addTransformer.

Add a ClassFileTransformer to be applied by this LoadTimeWeaver.
public ClassLoader
getInstrumentableClassLoader()

Implements org.springframework.instrument.classloading.LoadTimeWeaver.getInstrumentableClassLoader.

We have the ability to weave the current class loader when starting the JVM in this way, so the instrumentable class loader will always be the current loader.
private static Instrumentation

Returns:

the Instrumentation instance, or null if none found
getInstrumentation
()

Obtain the Instrumentation instance for the current VM, if available.

public ClassLoader
public static boolean
isInstrumentationAvailable()

Check whether an Instrumentation instance is available for the current VM.

public void
removeTransformers()

Remove all registered transformers, in inverse order of registration.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AGENT_CLASS_PRESENTback to summary
private static final boolean AGENT_CLASS_PRESENT
classLoaderback to summary
private final ClassLoader classLoader
Annotations
@Nullable
instrumentationback to summary
private final Instrumentation instrumentation
Annotations
@Nullable
transformersback to summary
private final List<ClassFileTransformer> transformers

Constructor Detail

InstrumentationLoadTimeWeaverback to summary
public InstrumentationLoadTimeWeaver()

Create a new InstrumentationLoadTimeWeaver for the default ClassLoader.

InstrumentationLoadTimeWeaverback to summary
public InstrumentationLoadTimeWeaver(ClassLoader classLoader)

Create a new InstrumentationLoadTimeWeaver for the given ClassLoader.

Parameters
classLoader:ClassLoader

the ClassLoader that registered transformers are supposed to apply to

Method Detail

addTransformerback to summary
public void addTransformer(ClassFileTransformer transformer)

Implements org.springframework.instrument.classloading.LoadTimeWeaver.addTransformer.

Doc from org.springframework.instrument.classloading.LoadTimeWeaver.addTransformer.

Add a ClassFileTransformer to be applied by this LoadTimeWeaver.

Parameters
transformer:ClassFileTransformer

the ClassFileTransformer to add

Annotations
@Override
getInstrumentableClassLoaderback to summary
public ClassLoader getInstrumentableClassLoader()

Implements org.springframework.instrument.classloading.LoadTimeWeaver.getInstrumentableClassLoader.

We have the ability to weave the current class loader when starting the JVM in this way, so the instrumentable class loader will always be the current loader.

Returns:ClassLoader

Doc from org.springframework.instrument.classloading.LoadTimeWeaver.getInstrumentableClassLoader.

the ClassLoader which will expose instrumented classes according to the registered transformers

Annotations
@Override
getInstrumentationback to summary
private static Instrumentation getInstrumentation()

Obtain the Instrumentation instance for the current VM, if available.

Returns:Instrumentation

the Instrumentation instance, or null if none found

Annotations
@Nullable
See Also
isInstrumentationAvailable()
getThrowawayClassLoaderback to summary
public ClassLoader getThrowawayClassLoader()

Implements org.springframework.instrument.classloading.LoadTimeWeaver.getThrowawayClassLoader.

This implementation always returns a SimpleThrowawayClassLoader.

Returns:ClassLoader

Doc from org.springframework.instrument.classloading.LoadTimeWeaver.getThrowawayClassLoader.

a temporary throwaway ClassLoader; should return a new instance for each call, with no existing state

Annotations
@Override
isInstrumentationAvailableback to summary
public static boolean isInstrumentationAvailable()

Check whether an Instrumentation instance is available for the current VM.

See Also
getInstrumentation()
removeTransformersback to summary
public void removeTransformers()

Remove all registered transformers, in inverse order of registration.

org.springframework.instrument.classloading back to summary

private Class InstrumentationLoadTimeWeaver.FilteringClassFileTransformer

extends Object
implements ClassFileTransformer
Class Inheritance
  • java.lang.Object
  • org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver.FilteringClassFileTransformer
All Implemented Interfaces
java.lang.instrument.ClassFileTransformer

Decorator that only applies the given target transformer to a specific ClassLoader.

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private final ClassFileTransformer

Constructor Summary

AccessConstructor and Description
public
FilteringClassFileTransformer(ClassFileTransformer targetTransformer, ClassLoader targetClassLoader)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public byte[]
transform(ClassLoader
the defining loader of the class to be transformed, may be null if the bootstrap loader
loader
,
String
the name of the class in the internal form of fully qualified class and interface names as defined in The Java Virtual Machine Specification. For example, "java/util/List".
className
,
Class<?>
if this is triggered by a redefine or retransform, the class being redefined or retransformed; if this is a class load, null
classBeingRedefined
,
ProtectionDomain
the protection domain of the class being defined or redefined
protectionDomain
,
byte[]
the input byte buffer in class file format - must not be modified
classfileBuffer
)

Overrides default java.lang.instrument.ClassFileTransformer.transform.

Transforms the given class file and returns a new replacement class file.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

targetClassLoaderback to summary
private final ClassLoader targetClassLoader
Annotations
@Nullable
targetTransformerback to summary
private final ClassFileTransformer targetTransformer

Constructor Detail

FilteringClassFileTransformerback to summary
public FilteringClassFileTransformer(ClassFileTransformer targetTransformer, ClassLoader targetClassLoader)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
transformback to summary
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException

Overrides default java.lang.instrument.ClassFileTransformer.transform.

Doc from java.lang.instrument.ClassFileTransformer.transform.

Transforms the given class file and returns a new replacement class file. This method is invoked when the Module bearing transform is not overridden.

Parameters
loader:ClassLoader

the defining loader of the class to be transformed, may be null if the bootstrap loader

className:String

the name of the class in the internal form of fully qualified class and interface names as defined in The Java Virtual Machine Specification. For example, "java/util/List".

classBeingRedefined:Class<?>

if this is triggered by a redefine or retransform, the class being redefined or retransformed; if this is a class load, null

protectionDomain:ProtectionDomain

the protection domain of the class being defined or redefined

classfileBuffer:byte[]

the input byte buffer in class file format - must not be modified

Returns:byte[]

a well-formed class file buffer (the result of the transform), or null if no transform is performed

Annotations
@Override
@Nullable
Exceptions
IllegalClassFormatException:
if the input does not represent a well-formed class file
org.springframework.instrument.classloading back to summary

private Class InstrumentationLoadTimeWeaver.InstrumentationAccessor

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver.InstrumentationAccessor

Inner class to avoid InstrumentationSavingAgent dependency.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Instrumentation
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

InstrumentationAccessorback to summary
private InstrumentationAccessor()

Method Detail

getInstrumentationback to summary
public static Instrumentation getInstrumentation()