Skip to content

Commit

Permalink
Android: Roll R8
Browse files Browse the repository at this point in the history
Keeping R8 revision the same, but updated local modifications:
* Expose dexsplitter-related R8 flags
   * Taken from reverted change:
     https://chromium-review.googlesource.com/c/chromium/src/+/2014309
* Disable stateless lambda "optimization"
* Makes horizontal & vertical class merging separate flags.
* Make --file-per-class use DexFilePerClassFile rather than
  DexFilePerClass (fixes incremental dexing /w desugar_with_d8).

Also updates update instructions.

Bug: 1032609
Change-Id: I1553785fa103ed3164206e0397fe320cce980f61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127512
Reviewed-by: Sam Maier <smaier@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755098}
  • Loading branch information
agrieve authored and Commit Bot committed Mar 31, 2020
1 parent 3de4e18 commit 92f162c
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/r8',
'version': 'C28ypVbWD-R2M9x9fH7QniIsYjJrKoUhxqEV_cZR4qgC',
'version': 'QBuWB80TzI5JFXtwaZQbr91Ry3Lb0AmRl8kBchm5FY0C',
},
],
'condition': 'checkout_android',
Expand Down
13 changes: 5 additions & 8 deletions build/config/android/internal_rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -1375,14 +1375,11 @@ if (enable_java_templates) {
} else if (enable_incremental_d8 &&
!(defined(invoker.disable_incremental) &&
invoker.disable_incremental)) {
# TODO(crbug.com/1015559): Fix incremental builds when d8 is desugaring.
if (!desugar_with_d8) {
# Don't use incremental dexing for ProGuarded inputs as a precaution.
args += [
"--incremental-dir",
rebase_path("$target_out_dir/$target_name", root_build_dir),
]
}
# Don't use incremental dexing for ProGuarded inputs as a precaution.
args += [
"--incremental-dir",
rebase_path("$target_out_dir/$target_name", root_build_dir),
]
}

if (_enable_multidex) {
Expand Down
27 changes: 25 additions & 2 deletions third_party/r8/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ Turning off outlining because it caused issues when synchronized proguarding
Trichrome due to illegal dex references (crbug.com/956839). Will only be used
for android_apk() targets that set `disable_r8_outlining = true`):

Increase callGraphCycleEliminatorMaxDepthThreshold (b/143685705).
Added --feature-jar flag for doing dex splitting.

Patch is located at //third_party/r8/local_modifications.diff.
local_modifications.diff created via:
git diff >local_modifications.diff

Update Instructions:
# Download R8:
git clone https://r8.googlesource.com/r8
cd r8
# Apply the patch:
git apply $CHROMIUM_SRC/third_party/r8/local_modifications.diff
# Build:
tools/gradle.py r8
# Shrink (improves r8/d8 launch time):
java -jar build/libs/r8.jar --debug --classfile --output r8.jar \
--lib $CHROMIUM_SRC/third_party/jdk/current --pg-conf src/main/keep.txt \
--no-minification --no-desugaring build/libs/r8.jar
rm $CHROMIUM_SRC/third_party/r8/libs/r8.jar
cp r8.jar $CHROMIUM_SRC/third_party/r8/libs/r8.jar

# Upload to CIPD:
cipd create --pkg-def cipd.yaml # Make note of the instance ID

# Manually update:
* README.chromium (version number via "java -jar lib/r8.jar --version")
* //DEPS (instance ID output by cipd create)
17 changes: 2 additions & 15 deletions third_party/r8/cipd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Example for updating r8 in the current dir:
# Run:
# cd <r8 code directory>
# tools/gradle.py r8 # Building R8
# cd -
#
# cipd auth-login
# rm lib/r8.jar
# cp <r8 code directory>/build/libs/r8.jar lib/r8.jar
# java -jar lib/r8.jar --version
# cipd create --pkg-def cipd.yaml # Make note of the instance ID
# Manually update:
# README.chromium (version number)
# //DEPS (instance ID output by cipd create)

# To create CIPD package run the following command.
# cipd create --pkg-def cipd.yaml
package: chromium/third_party/r8
description: >
R8 is a proguard-like optimizer that also has the option to dex.
Expand Down
102 changes: 99 additions & 3 deletions third_party/r8/local_modifications.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,84 @@
diff --git a/src/main/java/com/android/tools/r8/D8CommandParser.java b/src/main/java/com/android/tools/r8/D8CommandParser.java
index f66fff8f3..c63f4f566 100644
--- a/src/main/java/com/android/tools/r8/D8CommandParser.java
+++ b/src/main/java/com/android/tools/r8/D8CommandParser.java
@@ -205,7 +205,7 @@ public class D8CommandParser extends BaseCompilerCommandParser<D8Command, D8Comm
}
compilationMode = CompilationMode.RELEASE;
} else if (arg.equals("--file-per-class")) {
- outputMode = OutputMode.DexFilePerClass;
+ outputMode = OutputMode.DexFilePerClassFile;
} else if (arg.equals("--output")) {
if (outputPath != null) {
builder.error(
diff --git a/src/main/java/com/android/tools/r8/R8Command.java b/src/main/java/com/android/tools/r8/R8Command.java
index 4051f9cef..6d034d5b8 100644
--- a/src/main/java/com/android/tools/r8/R8Command.java
+++ b/src/main/java/com/android/tools/r8/R8Command.java
@@ -42,6 +42,8 @@ import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;

+import com.android.tools.r8.DexIndexedConsumer.DirectoryConsumer;
+
/**
* Immutable command structure for an invocation of the {@link R8} compiler.
*
@@ -234,6 +236,15 @@ public final class R8Command extends BaseCompilerCommand {
return self();
}

+ public Builder addFeatureJar(Path inputJarPath, Path outputPath) {
+ addFeatureSplit(splitBuilder ->
+ splitBuilder
+ .addProgramResourceProvider(ArchiveProgramResourceProvider.fromArchive(inputJarPath))
+ .setProgramConsumer(new DirectoryConsumer(outputPath))
+ .build());
+ return self();
+ }
+
/**
* Set a consumer for receiving the proguard-map content.
*
diff --git a/src/main/java/com/android/tools/r8/R8CommandParser.java b/src/main/java/com/android/tools/r8/R8CommandParser.java
index 22ebb5e42..b53e4c59e 100644
--- a/src/main/java/com/android/tools/r8/R8CommandParser.java
+++ b/src/main/java/com/android/tools/r8/R8CommandParser.java
@@ -24,6 +24,7 @@ public class R8CommandParser extends BaseCompilerCommandParser<R8Command, R8Comm
"--min-api",
"--main-dex-rules",
"--main-dex-list",
+ "--feature-jar",
"--main-dex-list-output",
"--pg-conf",
"--pg-map-output",
@@ -205,6 +206,11 @@ public class R8CommandParser extends BaseCompilerCommandParser<R8Command, R8Comm
builder.setDisableDesugaring(true);
} else if (arg.equals("--main-dex-rules")) {
builder.addMainDexRulesFiles(Paths.get(nextArg));
+ } else if (arg.equals("--feature-jar")) {
+ String[] argParts = nextArg.split(":");
+ String featureJarInputPath = argParts[0];
+ String featureJarOutputPath = argParts[1];
+ builder.addFeatureJar(Paths.get(featureJarInputPath), Paths.get(featureJarOutputPath));
} else if (arg.equals("--main-dex-list")) {
builder.addMainDexListFiles(Paths.get(nextArg));
} else if (arg.equals("--main-dex-list-output")) {
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/LambdaClass.java b/src/main/java/com/android/tools/r8/ir/desugar/LambdaClass.java
index 0831e6d93..49c1a202b 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/LambdaClass.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/LambdaClass.java
@@ -206,7 +206,7 @@ public final class LambdaClass {
}

public final boolean isStateless() {
- return descriptor.isStateless();
+ return false; // descriptor.isStateless();
}

void addSynthesizedFrom(DexProgramClass clazz) {
diff --git a/src/main/java/com/android/tools/r8/utils/InternalOptions.java b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
index 232b54a54..5c3a227b3 100644
index 232b54a54..fd45dfe36 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -198,8 +198,8 @@ public class InternalOptions {
Expand All @@ -8,8 +87,8 @@ index 232b54a54..5c3a227b3 100644
System.getProperty("com.android.tools.r8.fieldBitAccessAnalysis") != null;
- public boolean enableHorizontalClassMerging = true;
- public boolean enableVerticalClassMerging = true;
+ public boolean enableHorizontalClassMerging = System.getProperty("com.android.tools.r8.enableClassMerging") != null;
+ public boolean enableVerticalClassMerging = System.getProperty("com.android.tools.r8.enableClassMerging") != null;
+ public boolean enableHorizontalClassMerging = System.getProperty("com.android.tools.r8.enableHorizontalClassMerging") != null;
+ public boolean enableVerticalClassMerging = System.getProperty("com.android.tools.r8.enableVerticalClassMerging") != null;
public boolean enableArgumentRemoval = true;
public boolean enableUnusedArgumentRemoval = true;
public boolean enableUnusedInterfaceRemoval = true;
Expand All @@ -22,3 +101,20 @@ index 232b54a54..5c3a227b3 100644
public int minSize = 3;
public int maxSize = 99;
public int threshold = 20;
diff --git a/src/main/keep.txt b/src/main/keep.txt
index b0c58c916..5e4405175 100644
--- a/src/main/keep.txt
+++ b/src/main/keep.txt
@@ -27,4 +27,10 @@
-keep public class com.android.tools.r8.compatproguard.CompatProguard { public static void main(java.lang.String[]); }

# Compatibility command line program used by in google3.
--keep public class com.android.tools.r8.compatdx.CompatDx { public static void main(java.lang.String[]); }
\ No newline at end of file
+-keep public class com.android.tools.r8.compatdx.CompatDx { public static void main(java.lang.String[]); }
+
+-keep public class com.android.tools.r8.SwissArmyKnife { *; }
+
+# Chrome: We want to maintain stack traces from the R8 tool, so disable
+# optimizations.
+-dontoptimize

0 comments on commit 92f162c

Please sign in to comment.