blob: 87976bef0e2fe882d7da1edfe362de9413c50a41 [file] [log] [blame] [view]
Ian Zernye85345e2020-12-17 11:19:30 +01001# Compiler-input dumps
2
3The D8 and R8 compilers support generating a compiler-input dump for use in
4reproducing compiler issues.
5
6
7## The content of a dump
8
9The dump contains almost all of the inputs that are given to the compiler as
10part of compilation. In particular, it contains *all* class definitions in the
11form of Java classfiles (i.e., bytecode, not the Java source files).
Rico Wind82080972024-09-27 07:36:03 +020012If resource shrinking is enabled, the dump also contains *all* resources (i.e.,
13the manifest, all res folder entries in proto and raw format, and any other
14file flowing into resource shrinking).
Ian Zernye85345e2020-12-17 11:19:30 +010015In addition to the classfiles, the dump also includes Java resources, the
16compiler type, version, and flags, such as `--debug` or `--release`,
17main-dex lists or rules, and more. For R8 the dump also contains the full
18concatenation of all keep rules.
19
20The dump is a zip file containing the above. You should unzip it and review
Rico Wind82080972024-09-27 07:36:03 +020021the content locally. The program, classpath, library and resource content will be in
Ian Zernye85345e2020-12-17 11:19:30 +010022nested zip files. The remaining content is in plain text files.
23
24
25## Generating a dump
26
27To generate a dump file, run the compiler with the
28`com.android.tools.r8.dumpinputtofile` system property set:
29
30```
31java -cp r8.jar -Dcom.android.tools.r8.dumpinputtofile=mydump.zip com.android.tools.r8.D8 <other-compiler-args>
32```
33
34This will generate a dump file `mydump.zip` and exit the compiler with a
35non-zero exit value printing an error message about the location of the dump
36file that was written.
37
38For some builds, there may be many compilations taking place which cannot be
39easily isolated as individual compilation steps. If so, the system property
40`com.android.tools.r8.dumpinputtodirectory` can be set to a directory instead.
41Doing so will dump the inputs of each compilation to the directory in
42individual zip files and they will be named using a timestamp in an attempt
43to maintain an order. The compiler will compile as usual thus not disrupting
44the build.
45
46### Generating a dump with Gradle and the Android Studio Plugin
47
48To generate a dump from studio, the system property should be set for the
49build command. This can typically be done by amending the command-line gradle
50build-target command. Say your build target is `assembleRelease`, you would run:
51
52```
Søren Gjesse0ff19c82023-06-09 14:28:30 +020053./gradlew assembleRelease -Dorg.gradle.caching=false -Dcom.android.tools.r8.dumpinputtofile=mydump.zip --no-daemon
Ian Zernye85345e2020-12-17 11:19:30 +010054```
55
56If the build is a debug build, such as `assembleDebug`, then it will likely be an
57incremental D8 build in which case the best option is to provide a dump
58directory and then locate the particular dump file associated with the
59problematic compilation (if the compilation fails, the interesting dump will
60hopefully be the last dump):
61
62```
Søren Gjesse0ff19c82023-06-09 14:28:30 +020063./gradlew assembleDebug -Dorg.gradle.caching=false -Dcom.android.tools.r8.dumpinputtodirectory=mydumps/ --no-daemon
Ian Zernye85345e2020-12-17 11:19:30 +010064```
65
Rico Wind2c072092024-10-02 09:38:57 +020066### Generating a dump in AOSP
67For R8 compilations you can generate dumps with the R8_DUMP_DIRECTORY environment variable.
68This will put dumps for all R8 compilations leading up to the target that you are building.
69For a specific target you can do:
70
71```
72mkdir /tmp/dumps
73R8_DUMP_DIRECTORY=/tmp/dumps m -j77 SystemUI
74```
75The actual dump file for SystemUI will be the last dump in /tmp/dumps.
76
Ian Zernye85345e2020-12-17 11:19:30 +010077
78## Reproducing using a dump
79
80To reproduce a compiler issue with a dump use the script `tools/compiledump.py`
81from the R8 repository. Note that the script is *not* a standalone script so you
82will need a full checkout of the R8 project.
83
84Reproducing should then be just:
85```
86./tools/compiledump.py -d mydump.zip
87```
88
89Depending on the compiler version that generated the dump additional flags may
90be needed to specify the compiler and its version. Run `--help` for a list of
91options.
92
93The flags can also be used to override the setting specified in the dump.
94Doing so allows compiling with other compiler versions, or other settings.
Rico Wind2c072092024-10-02 09:38:57 +020095