blob: 2db569a6fdb06a45d212dc760df54effb666e5e9 [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).
12In addition to the classfiles, the dump also includes Java resources, the
13compiler type, version, and flags, such as `--debug` or `--release`,
14main-dex lists or rules, and more. For R8 the dump also contains the full
15concatenation of all keep rules.
16
17The dump is a zip file containing the above. You should unzip it and review
18the content locally. The program, classpath and library content will be in
19nested zip files. The remaining content is in plain text files.
20
21
22## Generating a dump
23
24To generate a dump file, run the compiler with the
25`com.android.tools.r8.dumpinputtofile` system property set:
26
27```
28java -cp r8.jar -Dcom.android.tools.r8.dumpinputtofile=mydump.zip com.android.tools.r8.D8 <other-compiler-args>
29```
30
31This will generate a dump file `mydump.zip` and exit the compiler with a
32non-zero exit value printing an error message about the location of the dump
33file that was written.
34
35For some builds, there may be many compilations taking place which cannot be
36easily isolated as individual compilation steps. If so, the system property
37`com.android.tools.r8.dumpinputtodirectory` can be set to a directory instead.
38Doing so will dump the inputs of each compilation to the directory in
39individual zip files and they will be named using a timestamp in an attempt
40to maintain an order. The compiler will compile as usual thus not disrupting
41the build.
42
43### Generating a dump with Gradle and the Android Studio Plugin
44
45To generate a dump from studio, the system property should be set for the
46build command. This can typically be done by amending the command-line gradle
47build-target command. Say your build target is `assembleRelease`, you would run:
48
49```
50./gradlew assembleRelease -Dcom.android.tools.r8.dumpinputtofile=mydump.zip --no-daemon
51```
52
53If the build is a debug build, such as `assembleDebug`, then it will likely be an
54incremental D8 build in which case the best option is to provide a dump
55directory and then locate the particular dump file associated with the
56problematic compilation (if the compilation fails, the interesting dump will
57hopefully be the last dump):
58
59```
60./gradlew assembleDebug -Dcom.android.tools.r8.dumpinputtodirectory=mydumps/ --no-daemon
61```
62
63
64## Reproducing using a dump
65
66To reproduce a compiler issue with a dump use the script `tools/compiledump.py`
67from the R8 repository. Note that the script is *not* a standalone script so you
68will need a full checkout of the R8 project.
69
70Reproducing should then be just:
71```
72./tools/compiledump.py -d mydump.zip
73```
74
75Depending on the compiler version that generated the dump additional flags may
76be needed to specify the compiler and its version. Run `--help` for a list of
77options.
78
79The flags can also be used to override the setting specified in the dump.
80Doing so allows compiling with other compiler versions, or other settings.