Class InjectedClassRuntime

  • All Implemented Interfaces:
    IExecutionDataAccessorGenerator, IRuntime

    public class InjectedClassRuntime
    extends AbstractRuntime
    IRuntime which defines a new class using java.lang.invoke.MethodHandles.Lookup.defineClass introduced in Java 9. Module where class will be defined must be opened to at least module of this class.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  InjectedClassRuntime.Lookup
      Provides access to classes java.lang.invoke.MethodHandles and java.lang.invoke.MethodHandles.Lookup introduced in Java 8.
    • Constructor Summary

      Constructors 
      Constructor Description
      InjectedClassRuntime​(java.lang.Class<?> locator, java.lang.String simpleClassName)
      Creates a new runtime which will define a class to the same class loader and in the same package and protection domain as given class.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static byte[] createClass​(java.lang.String name)  
      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.
      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
    • Field Detail

      • locator

        private final java.lang.Class<?> locator
      • injectedClassName

        private final java.lang.String injectedClassName
    • Constructor Detail

      • InjectedClassRuntime

        public InjectedClassRuntime​(java.lang.Class<?> locator,
                                    java.lang.String simpleClassName)
        Creates a new runtime which will define a class to the same class loader and in the same package and protection domain as given class.
        Parameters:
        locator - class to identify the target class loader and package
        simpleClassName - simple name of the class to be defined
    • 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
      • createClass

        private static byte[] createClass​(java.lang.String name)