Remove handling of shared synthetics in output
Change-Id: Ic1ec70f078e00ecda18b355f4878f8505ca8b0d2
diff --git a/src/main/java/com/android/tools/r8/dex/ApplicationWriter.java b/src/main/java/com/android/tools/r8/dex/ApplicationWriter.java
index fa7e21d..90af811 100644
--- a/src/main/java/com/android/tools/r8/dex/ApplicationWriter.java
+++ b/src/main/java/com/android/tools/r8/dex/ApplicationWriter.java
@@ -641,12 +641,11 @@
}
// At least one method needs a jumbo string in which case we construct a thread local mapping
// for all code objects and write the processed results into that map.
+ // TODO(b/181636450): Reconsider the code mapping setup now that synthetics are never duplicated
+ // in outputs.
Map<DexEncodedMethod, DexCode> codeMapping = new IdentityHashMap<>();
for (DexProgramClass clazz : classes) {
- // TODO(b/181636450): Reconsider the code mapping setup now that synthetics are never
- // duplicated in outputs.
- boolean isSharedSynthetic =
- appView.getSyntheticItems().getSynthesizingContexts(clazz.getType()).size() > 1;
+ assert !appView.getSyntheticItems().isSharedSynthetic(clazz);
clazz.forEachMethod(
method -> {
DexCode code =
@@ -655,12 +654,10 @@
application.dexItemFactory,
options.testing.forceJumboStringProcessing);
codeMapping.put(method, code);
- if (!isSharedSynthetic) {
- // If the class is not a shared class the mapping now has ownership of the methods
- // code object. This ensures freeing of code resources once the map entry is cleared
- // and also ensures that we don't end up using the incorrect code pointer again later!
- method.removeCode();
- }
+ // The mapping now has ownership of the methods code object. This ensures freeing of
+ // code resources once the map entry is cleared and also ensures that we don't end up
+ // using the incorrect code pointer again later!
+ method.removeCode();
});
}
return MethodToCodeObjectMapping.fromMapBacking(codeMapping);
diff --git a/src/main/java/com/android/tools/r8/dex/FileWriter.java b/src/main/java/com/android/tools/r8/dex/FileWriter.java
index 889fc27..56a6e0c 100644
--- a/src/main/java/com/android/tools/r8/dex/FileWriter.java
+++ b/src/main/java/com/android/tools/r8/dex/FileWriter.java
@@ -653,8 +653,7 @@
}
}
- private void writeEncodedMethods(
- Iterable<DexEncodedMethod> unsortedMethods, boolean isSharedSynthetic) {
+ private void writeEncodedMethods(Iterable<DexEncodedMethod> unsortedMethods) {
List<DexEncodedMethod> methods = IterableUtils.toNewArrayList(unsortedMethods);
methods.sort(
(a, b) ->
@@ -675,7 +674,7 @@
dest.putUleb128(mixedSectionOffsets.getOffsetFor(code));
// Writing the methods starts to take up memory so we are going to flush the
// code objects since they are no longer necessary after this.
- codeMapping.clearCode(method, isSharedSynthetic);
+ codeMapping.clearCode(method);
}
}
}
@@ -689,10 +688,9 @@
dest.putUleb128(clazz.getMethodCollection().numberOfVirtualMethods());
writeEncodedFields(clazz.staticFields());
writeEncodedFields(clazz.instanceFields());
- boolean isSharedSynthetic =
- appInfo.getSyntheticItems().getSynthesizingContexts(clazz.getType()).size() > 1;
- writeEncodedMethods(clazz.directMethods(), isSharedSynthetic);
- writeEncodedMethods(clazz.virtualMethods(), isSharedSynthetic);
+ assert !appInfo.getSyntheticItems().isSharedSynthetic(clazz);
+ writeEncodedMethods(clazz.directMethods());
+ writeEncodedMethods(clazz.virtualMethods());
}
private void addStaticFieldValues(DexProgramClass clazz) {
diff --git a/src/main/java/com/android/tools/r8/dex/MethodToCodeObjectMapping.java b/src/main/java/com/android/tools/r8/dex/MethodToCodeObjectMapping.java
index feeb64b..5541398 100644
--- a/src/main/java/com/android/tools/r8/dex/MethodToCodeObjectMapping.java
+++ b/src/main/java/com/android/tools/r8/dex/MethodToCodeObjectMapping.java
@@ -13,7 +13,7 @@
public abstract DexCode getCode(DexEncodedMethod method);
- public abstract void clearCode(DexEncodedMethod method, boolean isSharedSynthetic);
+ public abstract void clearCode(DexEncodedMethod method);
public abstract boolean verifyCodeObjects(Collection<DexCode> codes);
@@ -37,11 +37,8 @@
}
@Override
- public void clearCode(DexEncodedMethod method, boolean isSharedSynthetic) {
- // When using methods directly any shared class needs to maintain its methods as read-only.
- if (!isSharedSynthetic) {
- method.removeCode();
- }
+ public void clearCode(DexEncodedMethod method) {
+ method.removeCode();
}
@Override
@@ -64,7 +61,7 @@
}
@Override
- public void clearCode(DexEncodedMethod method, boolean isSharedSynthetic) {
+ public void clearCode(DexEncodedMethod method) {
// We can safely clear the thread local pointer to even shared methods.
codes.put(method, null);
}
diff --git a/src/main/java/com/android/tools/r8/dex/VirtualFile.java b/src/main/java/com/android/tools/r8/dex/VirtualFile.java
index e44973a..a11e0ab 100644
--- a/src/main/java/com/android/tools/r8/dex/VirtualFile.java
+++ b/src/main/java/com/android/tools/r8/dex/VirtualFile.java
@@ -329,11 +329,10 @@
Collection<DexProgramClass> synthetics = new ArrayList<>();
// Assign dedicated virtual files for all program classes.
for (DexProgramClass clazz : appView.appInfo().classes()) {
- Collection<DexType> contexts =
- appView.getSyntheticItems().getSynthesizingContexts(clazz.getType());
// TODO(b/181636450): Simplify this making use of the assumption that synthetics are never
// duplicated.
- if (!combineSyntheticClassesWithPrimaryClass || contexts.isEmpty()) {
+ if (!combineSyntheticClassesWithPrimaryClass
+ || !appView.getSyntheticItems().isSyntheticClass(clazz)) {
VirtualFile file =
new VirtualFile(
virtualFiles.size(),
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
index d6c93aa..28401a5 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
@@ -267,6 +267,10 @@
return Collections.emptyList();
}
+ public boolean isSharedSynthetic(DexProgramClass clazz) {
+ return getSynthesizingContexts(clazz.getType()).size() >= 2;
+ }
+
// TODO(b/180091213): Implement this and remove client provided the oracle.
public Set<DexReference> getSynthesizingContexts(
DexProgramClass clazz, SynthesizingContextOracle oracle) {