aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java
diff options
context:
space:
mode:
authorPete Gillin <peteg@google.com>2018-01-22 18:29:50 +0000
committerPete Gillin <peteg@google.com>2018-01-23 12:13:03 +0000
commit04f25e91a87fb5314e2e7ad979641dd453e43dda (patch)
tree586e0e7876c2d34a63ce91ea6981e5d42a83f51d /org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java
parent3fa3e608ee2aee9ac2087162bdaf03ec8bc46ea1 (diff)
downloadjacoco-04f25e91a87fb5314e2e7ad979641dd453e43dda.tar.gz
Modify jacoco runtime to reduce dependencies on core libs.
Previously, Offline's static initializer would eagerly create an Agent, a process which has lots of dependencies. With this change, Offline only eagerly creates an ExecutionDataStore, which is much more lightweight. The Agent is only created when it's actually needed. This makes it possible to instrument a lot of more core libraries without creating a circular dependency at runtime (e.g. all of java.io and java.nio, and most of java.util). Bug: 64836607 Test: mvn clean install -Djdk.version=1.9 -Dbytecode.version=1.9 (in org.jacoco.build/) Test: `cts-tradefed run cts-dev -m CtsLibcoreTestCases --test-arg com.android.compatibility.testtype.LibcoreTest:coverage:true` on a build with EMMA_INSTRUMENT=true and EMMA_INSTRUMENT_FRAMEWORK=true Change-Id: Ib1bd1adcd1ea58935a588f442dc57f958841c6aa
Diffstat (limited to 'org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java')
-rw-r--r--org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java38
1 files changed, 32 insertions, 6 deletions
diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java
index 8b8b40c0..21a78bbd 100644
--- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java
+++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java
@@ -13,6 +13,7 @@ package org.jacoco.agent.rt.internal;
import java.util.Properties;
+import org.jacoco.core.data.ExecutionDataStore;
import org.jacoco.core.runtime.AgentOptions;
import org.jacoco.core.runtime.RuntimeData;
@@ -22,13 +23,19 @@ import org.jacoco.core.runtime.RuntimeData;
*/
public final class Offline {
- private static final RuntimeData DATA;
+ // BEGIN android-change
+ // private static final RuntimeData DATA;
+ private static final ExecutionDataStore DATA;
+ // END android-change
private static final String CONFIG_RESOURCE = "/jacoco-agent.properties";
static {
- final Properties config = ConfigLoader.load(CONFIG_RESOURCE,
- System.getProperties());
- DATA = Agent.getInstance(new AgentOptions(config)).getData();
+ // BEGIN android-change
+ // final Properties config = ConfigLoader.load(CONFIG_RESOURCE,
+ // System.getProperties());
+ // DATA = Agent.getInstance(new AgentOptions(config)).getData();
+ DATA = new ExecutionDataStore();
+ // END android-change
}
private Offline() {
@@ -48,8 +55,27 @@ public final class Offline {
*/
public static boolean[] getProbes(final long classid,
final String classname, final int probecount) {
- return DATA.getExecutionData(Long.valueOf(classid), classname,
- probecount).getProbes();
+ // BEGIN android-change
+ // return DATA.getExecutionData(Long.valueOf(classid), classname,
+ // probecount).getProbes();
+ synchronized (DATA) {
+ return DATA.get(classid, classname, probecount).getProbes();
+ }
+ // END android-change
}
+ // BEGIN android-change
+ /**
+ * Creates a default agent, using config loaded from the classpath resource and the system
+ * properties, and a runtime data instance populated with the execution data accumulated by
+ * the probes.
+ *
+ * @return the new agent
+ */
+ static Agent createAgent() {
+ final Properties config = ConfigLoader.load(CONFIG_RESOURCE,
+ System.getProperties());
+ return Agent.getInstance(new AgentOptions(config), new RuntimeData(DATA));
+ }
+ // END android-change
}