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
InstrumentationSavingAgent
| Modifier and Type | Class and Description |
|---|---|
| private static class | InstrumentationLoadTimeWeaver.
Decorator that only applies the given target transformer to a specific ClassLoader. |
| private static class | InstrumentationLoadTimeWeaver.
Inner class to avoid InstrumentationSavingAgent dependency. |
| Modifier and Type | Field and Description |
|---|---|
| private static final boolean | |
| private final ClassLoader | |
| private final Instrumentation | |
| private final List |
| Access | Constructor 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. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addTransformer(ClassFileTransformer
the transformer)ClassFileTransformer to addImplements org. Add a |
| public ClassLoader | getInstrumentableClassLoader()
Implements org. 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, ornull if none foundObtain the Instrumentation instance for the current VM, if available. |
| public ClassLoader | getThrowawayClassLoader()
Implements org. This implementation always returns a |
| public static boolean | isInstrumentationAvailable()
Check whether an Instrumentation instance is available for the current VM. |
| public void |
| AGENT_CLASS_PRESENT | back to summary |
|---|---|
| private static final boolean AGENT_CLASS_PRESENT | |
| classLoader | back to summary |
|---|---|
| private final ClassLoader classLoader
| |
| instrumentation | back to summary |
|---|---|
| private final Instrumentation instrumentation
| |
| transformers | back to summary |
|---|---|
| private final List<ClassFileTransformer> transformers | |
| InstrumentationLoadTimeWeaver | back to summary |
|---|---|
| public InstrumentationLoadTimeWeaver() Create a new InstrumentationLoadTimeWeaver for the default ClassLoader. | |
| InstrumentationLoadTimeWeaver | back to summary |
|---|---|
| public InstrumentationLoadTimeWeaver(ClassLoader classLoader) Create a new InstrumentationLoadTimeWeaver for the given ClassLoader.
| |
| addTransformer | back to summary |
|---|---|
| public void addTransformer(ClassFileTransformer transformer) Implements org. Doc from org. Add a
| |
| getInstrumentableClassLoader | back to summary |
|---|---|
| public ClassLoader getInstrumentableClassLoader() Implements org. 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.
| |
| getInstrumentation | back to summary |
|---|---|
| private static Instrumentation getInstrumentation() Obtain the Instrumentation instance for the current VM, if available.
| |
| getThrowawayClassLoader | back to summary |
|---|---|
| public ClassLoader getThrowawayClassLoader() Implements org. This implementation always returns a
| |
| isInstrumentationAvailable | back to summary |
|---|---|
| public static boolean isInstrumentationAvailable() Check whether an Instrumentation instance is available for the current VM.
| |
| removeTransformers | back to summary |
|---|---|
| public void removeTransformers() Remove all registered transformers, in inverse order of registration. | |
| Modifier and Type | Field and Description |
|---|---|
| private final ClassLoader | |
| private final ClassFileTransformer |
| Access | Constructor and Description |
|---|---|
| public | FilteringClassFileTransformer(ClassFileTransformer targetTransformer, ClassLoader targetClassLoader)
|
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public byte[] | transform(ClassLoader
the defining loader of the class to be transformed,
may be loader, String null if the bootstrap loaderthe 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, className, Class<?> "java/util/List".if this is triggered by a redefine or retransform,
the class being redefined or retransformed;
if this is a class load, classBeingRedefined, ProtectionDomain nullthe 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. Transforms the given class file and returns a new replacement class file. |
| targetClassLoader | back to summary |
|---|---|
| private final ClassLoader targetClassLoader
| |
| targetTransformer | back to summary |
|---|---|
| private final ClassFileTransformer targetTransformer | |
| FilteringClassFileTransformer | back to summary |
|---|---|
| public FilteringClassFileTransformer(ClassFileTransformer targetTransformer, ClassLoader targetClassLoader) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| transform | back to summary |
|---|---|
| public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException Overrides default java. Doc from java. Transforms the given class file and returns a new replacement class file.
This method is invoked when the
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Instrumentation |
| InstrumentationAccessor | back to summary |
|---|---|
| private InstrumentationAccessor() | |
| getInstrumentation | back to summary |
|---|---|
| public static Instrumentation getInstrumentation() | |