Class ModifiedSystemClassRuntime

  • All Implemented Interfaces:
    IExecutionDataAccessorGenerator, IRuntime

    public class ModifiedSystemClassRuntime
    extends AbstractRuntime
    This IRuntime implementation works with a modified system class. A new static field is added to a bootstrap class that will be used by instrumented classes. As the system class itself needs to be instrumented this runtime requires a Java agent.
    • Constructor Summary

      Constructors 
      Constructor Description
      ModifiedSystemClassRuntime​(java.lang.Class<?> systemClass, java.lang.String accessFieldName)
      Creates a new runtime based on the given class and members.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static IRuntime createFor​(java.lang.instrument.Instrumentation inst, java.lang.String className)
      Creates a new ModifiedSystemClassRuntime using the given class as the data container.
      static IRuntime createFor​(java.lang.instrument.Instrumentation inst, java.lang.String className, java.lang.String accessFieldName)
      Creates a new ModifiedSystemClassRuntime using the given class as the data container.
      int generateDataAccessor​(long classid, java.lang.String classname, int probecount, org.objectweb.asm.MethodVisitor mv)
      This method generates the byte code required to obtain the coverage data structure for the class with the given id.
      static byte[] instrument​(byte[] source, java.lang.String accessFieldName)
      Adds the static data field to the given class definition.
      void shutdown()
      Allows the coverage runtime to cleanup internals.
      void startup​(RuntimeData data)
      Subclasses must call this method when overwriting it.
      • Methods inherited from class java.lang.Object

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

      • ModifiedSystemClassRuntime

        public ModifiedSystemClassRuntime​(java.lang.Class<?> systemClass,
                                          java.lang.String accessFieldName)
        Creates a new runtime based on the given class and members.
        Parameters:
        systemClass - system class that contains the execution data
        accessFieldName - name of the public static runtime access field
    • Method Detail

      • startup

        public void startup​(RuntimeData data)
                     throws java.lang.Exception
        Description copied from class: AbstractRuntime
        Subclasses must call this method when overwriting it.
        Specified by:
        startup in interface IRuntime
        Overrides:
        startup in class AbstractRuntime
        Parameters:
        data - the execution data for this runtime
        Throws:
        java.lang.Exception - any internal problem during startup
      • shutdown

        public void shutdown()
        Description copied from interface: IRuntime
        Allows the coverage runtime to cleanup internals. This class should be called when classes instrumented for this runtime are not used any more.
      • generateDataAccessor

        public int generateDataAccessor​(long classid,
                                        java.lang.String classname,
                                        int probecount,
                                        org.objectweb.asm.MethodVisitor mv)
        Description copied from interface: IExecutionDataAccessorGenerator
        This method generates the byte code required to obtain the coverage data structure for the class with the given id. Typically the instrumentation process will embed this code into a method that is called on class initialization. This method can be called at any time even outside the target VM. The generated code must push a boolean[] instance to the operand stack. Except this result object the generated code must not make any assumptions about the structure of the embedding method or class. The generated code must not use or allocate local variables.
        Parameters:
        classid - identifier of the class
        classname - VM class name
        probecount - probe count for this class
        mv - code output
        Returns:
        additional stack size required by the implementation, including the instance pushed to the stack
      • createFor

        public static IRuntime createFor​(java.lang.instrument.Instrumentation inst,
                                         java.lang.String className)
                                  throws java.lang.ClassNotFoundException
        Creates a new ModifiedSystemClassRuntime using the given class as the data container. Member is created with internal default name. The given class must not have been loaded before by the agent.
        Parameters:
        inst - instrumentation interface
        className - VM name of the class to use
        Returns:
        new runtime instance
        Throws:
        java.lang.ClassNotFoundException - id the given class can not be found
      • createFor

        public static IRuntime createFor​(java.lang.instrument.Instrumentation inst,
                                         java.lang.String className,
                                         java.lang.String accessFieldName)
                                  throws java.lang.ClassNotFoundException
        Creates a new ModifiedSystemClassRuntime using the given class as the data container. The given class must not have been loaded before by the agent.
        Parameters:
        inst - instrumentation interface
        className - VM name of the class to use
        accessFieldName - name of the added runtime access field
        Returns:
        new runtime instance
        Throws:
        java.lang.ClassNotFoundException - if the given class can not be found
      • instrument

        public static byte[] instrument​(byte[] source,
                                        java.lang.String accessFieldName)
        Adds the static data field to the given class definition.
        Parameters:
        source - class definition source
        accessFieldName - name of the runtime access field
        Returns:
        instrumented version with added members