Class DynamicTransformer

  • All Implemented Interfaces:
    ClassFileTransformer

    public class DynamicTransformer
    extends Object
    implements ClassFileTransformer
    Uses the ClassVisitor to dynamically instrument Java constructors and methods during the class loading process. When executed, the injected code will call the ExecutionMonitor to collect and upload runtime information to the Vulas backend.

    The name has been chosen to contrast with static instrumentation, which can be done with help of the Vulas Maven plugin (goal vulas:instr).

    • Method Detail

      • isTransformationEnabled

        public boolean isTransformationEnabled()

        isTransformationEnabled.

        Returns:
        a boolean.
      • setTransformationEnabled

        public void setTransformationEnabled​(boolean transformationEnabled)

        Setter for the field transformationEnabled.

        Parameters:
        transformationEnabled - a boolean.
      • transform

        public byte[] transform​(ClassLoader loader,
                                String className,
                                Class<?> classBeingRedefined,
                                ProtectionDomain protectionDomain,
                                byte[] classfileBuffer)
                         throws IllegalClassFormatException
        Adds instrumentation code to all constructors and methods of all classes (thereby considering certain blacklists and whitelists read from the configuration file).

        The method is called by the JRE class loading process and returns the instrumented bytecode for a given class.

        Specified by:
        transform in interface ClassFileTransformer
        Parameters:
        loader - a ClassLoader object.
        className - a String object.
        classBeingRedefined - a Class object.
        protectionDomain - a ProtectionDomain object.
        classfileBuffer - an array of byte objects.
        Returns:
        the instrumented bytecode
        Throws:
        IllegalClassFormatException - if any.
      • getInstance

        public static DynamicTransformer getInstance()
        Singleton method: Creates (if necessary) and returns the single instance that can be created for this class.
        Returns:
        a DynamicTransformer object.
      • isInstantiated

        public static boolean isInstantiated()
        Returns true if the Singleton has been created.
        Returns:
        a boolean.