aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/runtime/OfflineInstrumentationAccessGenerator.java
blob: a5e88b604d8e3e9bd43fa048cc5a42db24746011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*******************************************************************************
 * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Marc R. Hoffmann - initial API and implementation
 *    
 *******************************************************************************/
package org.jacoco.core.runtime;

import org.jacoco.core.JaCoCo;
import org.jacoco.core.internal.instr.InstrSupport;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
 * This implementation of {@link IExecutionDataAccessorGenerator} generate a
 * direct dependency to the JaCoCo runtime agent to initialize the runtime and
 * obtain probe arrays. This generator is designed for offline instrumentation
 * only.
 */
public class OfflineInstrumentationAccessGenerator implements
		IExecutionDataAccessorGenerator {

	private final String runtimeClassName;

	/**
	 * Creates a new instance for offline instrumentation.
	 */
	public OfflineInstrumentationAccessGenerator() {
		this(JaCoCo.RUNTIMEPACKAGE.replace('.', '/') + "/Offline");
	}

	/**
	 * Creates a new instance with the given runtime class name for testing
	 * purposes
	 * 
	 * @param runtimeClassName
	 *            VM name of the runtime class
	 */
	OfflineInstrumentationAccessGenerator(final String runtimeClassName) {
		this.runtimeClassName = runtimeClassName;
	}

	public int generateDataAccessor(final long classid, final String classname,
			final int probecount, final MethodVisitor mv) {
		mv.visitLdcInsn(Long.valueOf(classid));
		mv.visitLdcInsn(classname);
		InstrSupport.push(mv, probecount);
		// BEGIN android-change
		mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeClassName, "getExecutionData",
				"(JLjava/lang/String;I)Lorg/jacoco/core/data/IExecutionData;", false);
		// END android-change
		return 4;
	}

}