Change dex partition to reduce LinearAlloc usage
Attempt to partition classes among dex files to limit linking errors
during DexOpt and when it's not possible to avoid then, ensure that they
won't cause LinearAlloc over usage.
This is achieved by ensuring that each class in a secondary dex has all
it's hierachy (super classes and interfaces) either in the bootclasspath
in the same secondary dex. Then if it's not possible to respect this
constraint for some classes, instead ensure that those classes are put in
a different secondary dex than all their link dependents (i.e. subclasses,
implementations or sub interfaces), those classes will failed to link
during DexOpt but they will be loaded only once.
Bug: 73108937
Change-Id: Ib4af372732232d20814ebaad2e2265c99622de6a
diff --git a/src/main/java/com/android/tools/r8/BaseCompilerCommand.java b/src/main/java/com/android/tools/r8/BaseCompilerCommand.java
index 9a260ea..6c43c7b 100644
--- a/src/main/java/com/android/tools/r8/BaseCompilerCommand.java
+++ b/src/main/java/com/android/tools/r8/BaseCompilerCommand.java
@@ -30,6 +30,7 @@
private final int minApiLevel;
private final Reporter reporter;
private final boolean enableDesugaring;
+ private final boolean optimizeMultidexForLinearAlloc;
BaseCompilerCommand(boolean printHelp, boolean printVersion) {
super(printHelp, printVersion);
@@ -38,6 +39,7 @@
minApiLevel = 0;
reporter = new Reporter(new DefaultDiagnosticsHandler());
enableDesugaring = true;
+ optimizeMultidexForLinearAlloc = false;
}
BaseCompilerCommand(
@@ -46,7 +48,8 @@
ProgramConsumer programConsumer,
int minApiLevel,
Reporter reporter,
- boolean enableDesugaring) {
+ boolean enableDesugaring,
+ boolean optimizeMultidexForLinearAlloc) {
super(app);
assert minApiLevel > 0;
assert mode != null;
@@ -55,6 +58,7 @@
this.minApiLevel = minApiLevel;
this.reporter = reporter;
this.enableDesugaring = enableDesugaring;
+ this.optimizeMultidexForLinearAlloc = optimizeMultidexForLinearAlloc;
}
/**
@@ -84,6 +88,14 @@
return enableDesugaring;
}
+ /**
+ * If true, legacy multidex partitioning will be optimized to reduce LinearAlloc usage during
+ * Dalvik DexOpt.
+ */
+ public boolean isOptimizeMultidexForLinearAlloc() {
+ return optimizeMultidexForLinearAlloc;
+ }
+
Reporter getReporter() {
return reporter;
}
@@ -105,6 +117,7 @@
private CompilationMode mode;
private int minApiLevel = 0;
private boolean disableDesugaring = false;
+ private boolean optimizeMultidexForLinearAlloc = false;
Builder() {}
@@ -170,6 +183,24 @@
}
/**
+ * If set to true, legacy multidex partitioning will be optimized to reduce LinearAlloc usage
+ * during Dalvik DexOpt. Has no effect when compiling for a target with native multidex support
+ * or without main dex list specification.
+ */
+ public B setOptimizeMultidexForLinearAlloc(boolean optimizeMultidexForLinearAlloc) {
+ this.optimizeMultidexForLinearAlloc = optimizeMultidexForLinearAlloc;
+ return self();
+ }
+
+ /**
+ * If true, legacy multidex partitioning will be optimized to reduce LinearAlloc usage during
+ * Dalvik DexOpt.
+ */
+ protected boolean isOptimizeMultidexForLinearAlloc() {
+ return optimizeMultidexForLinearAlloc;
+ }
+
+ /**
* Set the program consumer.
*
* <p>Setting the program consumer will override any previous set consumer or any previous set