diff options
author | Pete Gillin <peteg@google.com> | 2018-01-24 13:55:55 +0000 |
---|---|---|
committer | Pete Gillin <peteg@google.com> | 2018-01-24 18:11:58 +0000 |
commit | 6c3ded30e516793d3bdfdead872ceb3700be8453 (patch) | |
tree | 90e5bca003a6d95e154221aeb2f94b4ca30b38ca | |
parent | 04f25e91a87fb5314e2e7ad979641dd453e43dda (diff) | |
download | jacoco-6c3ded30e516793d3bdfdead872ceb3700be8453.tar.gz |
Further modify jacoco runtime to reduce deps on core libs.
This changes it from eagerly creating an ExecutionDataStore to only
eagerly creating a HashMap<Long, ExecutionData>, which was one of the
two fields in ExecutionDataStore.
This makes it possible to instrument 7 of the 10 previously
blacklisted classes in java.util without creating a circular
dependency at runtime.
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: I30dfeab8922b7d53f82fdab81020e4a7f0ef4e3e
-rw-r--r-- | org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java | 2 | ||||
-rw-r--r-- | org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Offline.java | 40 |
2 files changed, 30 insertions, 12 deletions
diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java index f6c1e767..b4dd0c10 100644 --- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java +++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java @@ -82,6 +82,8 @@ public class Agent implements IAgent { /** * Returns a global instance which is already started. If an agent has not * been initialized then one will be created via {@link Offline#createAgent()}. + * This will capture any data written via {@link Offline#getProbes} prior to + * this call, but not subsequently. * * @return global instance * @throws IllegalStateException 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 21a78bbd..7eac19fa 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 @@ -11,8 +11,11 @@ *******************************************************************************/ package org.jacoco.agent.rt.internal; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; +import org.jacoco.core.data.ExecutionData; import org.jacoco.core.data.ExecutionDataStore; import org.jacoco.core.runtime.AgentOptions; import org.jacoco.core.runtime.RuntimeData; @@ -25,18 +28,17 @@ public final class Offline { // BEGIN android-change // private static final RuntimeData DATA; - private static final ExecutionDataStore DATA; + private static final Map<Long, ExecutionData> DATA = new HashMap<Long, ExecutionData>(); // END android-change private static final String CONFIG_RESOURCE = "/jacoco-agent.properties"; - static { - // 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 - } + // BEGIN android-change + // static { + // final Properties config = ConfigLoader.load(CONFIG_RESOURCE, + // System.getProperties()); + // DATA = Agent.getInstance(new AgentOptions(config)).getData(); + // } + // END android-change private Offline() { // no instances @@ -59,7 +61,14 @@ public final class Offline { // return DATA.getExecutionData(Long.valueOf(classid), classname, // probecount).getProbes(); synchronized (DATA) { - return DATA.get(classid, classname, probecount).getProbes(); + ExecutionData entry = DATA.get(classid); + if (entry == null) { + entry = new ExecutionData(classid, classname, probecount); + DATA.put(classid, entry); + } else { + entry.assertCompatibility(classid, classname, probecount); + } + return entry.getProbes(); } // END android-change } @@ -68,14 +77,21 @@ public final class Offline { /** * 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. + * the probes up until this call is made (subsequent probe updates will not be reflected in + * this agent). * * @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)); + synchronized (DATA) { + ExecutionDataStore store = new ExecutionDataStore(); + for (ExecutionData data : DATA.values()) { + store.put(data); + } + return Agent.getInstance(new AgentOptions(config), new RuntimeData(store)); + } } // END android-change } |