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