xref: /aosp_15_r20/external/jacoco/README.android (revision 7e63c1270baf9bfa84f5b6aecf17bd0c1a75af94)
1*7e63c127SSorin BascaWe build an equivalent of the jacoco-agent.jar which contains classes from org.jacoco.core,
2*7e63c127SSorin Bascaorg.jacoco.agent and org.jacoco.agent.rt packages but also classes from asm 5.0.1.
3*7e63c127SSorin Basca
4*7e63c127SSorin BascaHowever, Jacoco depends on classes that do not exist in Android (java.lang.instrument.* or
5*7e63c127SSorin Bascajavax.management.*) for runtime instrumentation only. The ART compiler would reject those classes
6*7e63c127SSorin Bascawhen they are either in the bootclasspath (core, frameworks, ...) or system apps.
7*7e63c127SSorin Basca
8*7e63c127SSorin BascaSince we only use offline instrumentation for code coverage (using Jack) and do not execute these
9*7e63c127SSorin Bascaclasses at runtime, we simply not compile them here.
10*7e63c127SSorin Basca
11*7e63c127SSorin BascaWe also need to modify the source code to cut dependencies to the classes that we exclude from the
12*7e63c127SSorin Bascacompilation. The changes are surrounded by "BEGIN android-change" and "END android-change". Here
13*7e63c127SSorin Bascais the list of the changes:
14*7e63c127SSorin Basca
15*7e63c127SSorin Basca1) Remove the creation of JmxRegistration in org.jacoco.agent.rt.internal.Agent.
16*7e63c127SSorin Basca2) Change default OutputMode to none in org.jacoco.core.runtime.AgentOptions
17*7e63c127SSorin Basca3) Change the runtime to reduce dependencies on core libraries.
18*7e63c127SSorin Basca   Previously, Offline's static initializer would eagerly create an
19*7e63c127SSorin Basca   Agent, a process which has lots of dependencies. With this change,
20*7e63c127SSorin Basca   Offline only eagerly creates a Map<Long, ExecutionData>, which is much
21*7e63c127SSorin Basca   more lightweight. The Agent is only created when it's actually
22*7e63c127SSorin Basca   needed. This makes it possible to instrument a lot of more core
23*7e63c127SSorin Basca   libraries without creating a circular dependency at runtime.
24*7e63c127SSorin Basca4) Disable use of 'constant dynamic' bytecode in
25*7e63c127SSorin Basca   org.jacoco.core.internal.instr.ProbeArrayStrategyFactory, because R8/D8 doesn't support it.
26*7e63c127SSorin Basca   (https://issuetracker.google.com/178172809)
27