jacoco core.runtime包源码分析

1 IExecutionDataAccessorGenerator


被 instrument 的类需要一段代码,该代码从运行时获取 boolean[]实例。
该机制是针对于运行时的,因此由该接口抽象。 实现由 IRuntime 实现提供,并由 instrumentation process过程使用。

唯一方法

	/**
	 * 此方法生成获得具有给定id的类的coverage数据结构所需的字节码。 通常,instrumentation 过程会将此代码嵌入到在类初始化时调用的方法中。甚至可以在目标VM外部随时调用此方法。
	 *
	 * 生成的代码必须将 boolean[] 实例推入操作数栈。 除此结果对象外,生成的代码不得对嵌入方法或类的结构进行任何假设。 生成的代码不得使用或分配局部变量。
	 *
	 * @param classid
	 * @param classname
	 *            VM class name
	 * @param probecount
	 *            probe count for this class
	 * @param mv
	 *            code output
	 * @return additional stack size required by the implementation, including
	 *         the instance pushed to the stack
	 */
	int generateDataAccessor(long classid, String classname, int probecount,
			MethodVisitor mv);

IRuntime 实现类

package org.jacoco.core.runtime;

/**
 * 此接口表示一种特定的机制,用于在运行时收集目标VM中的执行信息。
 */
public interface IRuntime extends IExecutionDataAccessorGenerator {

	/**
	 * start coverage runtime. 
	 * This method MUST be called before any class instrumented for this runtime is loaded.
	 * 必须在加载为此运行时检测到的任何类之前调用此方法。
	 *
	 * @param data
	 *            the execution data for this runtime
	 * @throws Exception
	 *             any internal problem during startup
	 */
	void startup(RuntimeData data) throws Exception;

	/**
	 * Allows the coverage runtime to cleanup internals. This class should be
	 * called when classes instrumented for this runtime are not used any more.
	 * 允许coverage运行时清理内部。 当不再使用为此运行时检测的类时,应调用该类。
	 */
	void shutdown();

}

发布了412 篇原创文章 · 获赞 1072 · 访问量 53万+

猜你喜欢

转载自blog.csdn.net/qq_33589510/article/details/105264876