Class ModifiedSystemClassRuntime
java.lang.Object
org.jacoco.core.runtime.AbstractRuntime
org.jacoco.core.runtime.ModifiedSystemClassRuntime
- All Implemented Interfaces:
IExecutionDataAccessorGenerator, IRuntime
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.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final Stringprivate final Class<?> private final StringFields inherited from class AbstractRuntime
data -
Constructor Summary
ConstructorsConstructorDescriptionModifiedSystemClassRuntime(Class<?> systemClass, String accessFieldName) Creates a new runtime based on the given class and members. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcreateDataField(org.objectweb.asm.ClassVisitor visitor, String dataField) static IRuntimecreateFor(Instrumentation inst, String className) Creates a newModifiedSystemClassRuntimeusing the given class as the data container.static IRuntimecreateFor(Instrumentation inst, String className, String accessFieldName) Creates a newModifiedSystemClassRuntimeusing the given class as the data container.intgenerateDataAccessor(long classid, 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, String accessFieldName) Adds the static data field to the given class definition.voidshutdown()Allows the coverage runtime to cleanup internals.voidstartup(RuntimeData data) Subclasses must call this method when overwriting it.Methods inherited from class AbstractRuntime
createRandomId
-
Field Details
-
ACCESS_FIELD_TYPE
- See Also:
-
systemClass
-
systemClassName
-
accessFieldName
-
-
Constructor Details
-
ModifiedSystemClassRuntime
-
-
Method Details
-
startup
Description copied from class:AbstractRuntimeSubclasses must call this method when overwriting it.- Specified by:
startupin interfaceIRuntime- Overrides:
startupin classAbstractRuntime- Parameters:
data- the execution data for this runtime- Throws:
Exception- any internal problem during startup
-
shutdown
public void shutdown()Description copied from interface:IRuntimeAllows 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, String classname, int probecount, org.objectweb.asm.MethodVisitor mv) Description copied from interface:IExecutionDataAccessorGeneratorThis 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 aboolean[]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 classclassname- VM class nameprobecount- probe count for this classmv- 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 newModifiedSystemClassRuntimeusing 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 interfaceclassName- 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 accessFieldName) throws ClassNotFoundException Creates a newModifiedSystemClassRuntimeusing the given class as the data container. The given class must not have been loaded before by the agent.- Parameters:
inst- instrumentation interfaceclassName- VM name of the class to useaccessFieldName- name of the added runtime access field- Returns:
- new runtime instance
- Throws:
ClassNotFoundException- if the given class can not be found
-
instrument
Adds the static data field to the given class definition.- Parameters:
source- class definition sourceaccessFieldName- name of the runtime access field- Returns:
- instrumented version with added members
-
createDataField
-