org.jacoco.core.runtime
Class ModifiedSystemClassRuntime

java.lang.Object
  extended by org.jacoco.core.runtime.AbstractRuntime
      extended by org.jacoco.core.runtime.ModifiedSystemClassRuntime
All Implemented Interfaces:
IRuntime

public class ModifiedSystemClassRuntime
extends AbstractRuntime

This IRuntime implementation works with a modified system class. A new static method 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.

Version:
$Revision: $
Author:
Marc R. Hoffmann

Field Summary
 
Fields inherited from class org.jacoco.core.runtime.AbstractRuntime
store
 
Constructor Summary
ModifiedSystemClassRuntime(Class<?> systemClass, String accessMethod, String dataField)
          Creates a new runtime based on the given class and members.
 
Method Summary
static IRuntime createFor(Instrumentation inst, String className)
          Creates a new ModifiedSystemClassRuntime using the given class as the data container.
static IRuntime createFor(Instrumentation inst, String className, String accessMethod, String dataField)
          Creates a new ModifiedSystemClassRuntime using the given class as the data container.
 int generateDataAccessor(long classid, 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, String accessMethod, String dataField)
          Adds the static access method and data field to the given class definition.
 void shutdown()
          Allows the coverage runtime to cleanup internals.
 void startup()
          Starts the coverage runtime.
 
Methods inherited from class org.jacoco.core.runtime.AbstractRuntime
collect, registerClass, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModifiedSystemClassRuntime

public ModifiedSystemClassRuntime(Class<?> systemClass,
                                  String accessMethod,
                                  String dataField)
Creates a new runtime based on the given class and members.

Parameters:
systemClass - system class that contains the execution data
accessMethod - name of the public static access method
dataField - name of the public static data field
Method Detail

startup

public void startup()
             throws Exception
Description copied from interface: IRuntime
Starts the coverage runtime. This method MUST be called before any class instrumented for this runtime is loaded.

Throws:
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,
                                MethodVisitor mv)
Description copied from interface: IRuntime
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.

Parameters:
classid - identifier of the class
mv - code output
Returns:
additional stack size required by the implementation, including the instance pushed to the stack

createFor

public static IRuntime createFor(Instrumentation inst,
                                 String className)
                          throws ClassNotFoundException
Creates a new ModifiedSystemClassRuntime using the given class as the data container. Members are creates with internal default names. 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:
ClassNotFoundException - id the given class can not be found

createFor

public static IRuntime createFor(Instrumentation inst,
                                 String className,
                                 String accessMethod,
                                 String dataField)
                          throws 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
accessMethod - name of the added access method
dataField - name of the added data field
Returns:
new runtime instance
Throws:
ClassNotFoundException - id the given class can not be found

instrument

public static byte[] instrument(byte[] source,
                                String accessMethod,
                                String dataField)
Adds the static access method and data field to the given class definition.

Parameters:
source - class definition source
accessMethod - name of the access method
dataField - name of the data field
Returns:
instrumented version with added members