org.springframework.instrument.classloading

Class InstrumentationLoadTimeWeaver

  • java.lang.Object
    • org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver
  • All Implemented Interfaces:
    LoadTimeWeaver


    public class InstrumentationLoadTimeWeaver
    extends java.lang.Object
    implements LoadTimeWeaver
    LoadTimeWeaver relying on VM Instrumentation.

    Start the JVM specifying the Java agent to be used, like as follows:

    -javaagent:path/to/org.springframework.instrument.jar

    where org.springframework.instrument.jar is a JAR file containing the InstrumentationSavingAgent class, as shipped with Spring.

    In Eclipse, for example, set the "Run configuration"'s JVM args to be of the form:

    -javaagent:${project_loc}/lib/org.springframework.instrument.jar

    Since:
    2.0
    Author:
    Rod Johnson, Juergen Hoeller
    See Also:
    InstrumentationSavingAgent
    • Constructor Summary

      Constructors 
      Constructor and Description
      InstrumentationLoadTimeWeaver()
      Create a new InstrumentationLoadTimeWeaver for the default ClassLoader.
      InstrumentationLoadTimeWeaver(java.lang.ClassLoader classLoader)
      Create a new InstrumentationLoadTimeWeaver for the given ClassLoader.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addTransformer(java.lang.instrument.ClassFileTransformer transformer)
      Add a ClassFileTransformer to be applied by this LoadTimeWeaver.
      java.lang.ClassLoader 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.
      java.lang.ClassLoader getThrowawayClassLoader()
      This implementation always returns a SimpleThrowawayClassLoader.
      static boolean isInstrumentationAvailable()
      Check whether an Instrumentation instance is available for the current VM.
      void removeTransformers()
      Remove all registered transformers, in inverse order of registration.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InstrumentationLoadTimeWeaver

        public InstrumentationLoadTimeWeaver()
        Create a new InstrumentationLoadTimeWeaver for the default ClassLoader.
      • InstrumentationLoadTimeWeaver

        public InstrumentationLoadTimeWeaver(@Nullable
                                             java.lang.ClassLoader classLoader)
        Create a new InstrumentationLoadTimeWeaver for the given ClassLoader.
        Parameters:
        classLoader - the ClassLoader that registered transformers are supposed to apply to
    • Method Detail

      • addTransformer

        public void addTransformer(java.lang.instrument.ClassFileTransformer transformer)
        Description copied from interface: LoadTimeWeaver
        Add a ClassFileTransformer to be applied by this LoadTimeWeaver.
        Specified by:
        addTransformer in interface LoadTimeWeaver
        Parameters:
        transformer - the ClassFileTransformer to add
      • getInstrumentableClassLoader

        public java.lang.ClassLoader 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.
        Specified by:
        getInstrumentableClassLoader in interface LoadTimeWeaver
        Returns:
        the ClassLoader which will expose instrumented classes according to the registered transformers
      • getThrowawayClassLoader

        public java.lang.ClassLoader getThrowawayClassLoader()
        This implementation always returns a SimpleThrowawayClassLoader.
        Specified by:
        getThrowawayClassLoader in interface LoadTimeWeaver
        Returns:
        a temporary throwaway ClassLoader; should return a new instance for each call, with no existing state
      • removeTransformers

        public void removeTransformers()
        Remove all registered transformers, in inverse order of registration.
      • isInstrumentationAvailable

        public static boolean isInstrumentationAvailable()
        Check whether an Instrumentation instance is available for the current VM.
        See Also:
        getInstrumentation()