Remove sorting of live methods from liveness info.
Bug: 132593519
Change-Id: I389e544fdcf1f8d3718cd67149905fc2ce9ccb03
diff --git a/src/main/java/com/android/tools/r8/graph/InnerClassAttribute.java b/src/main/java/com/android/tools/r8/graph/InnerClassAttribute.java
index d54bc7b..bb0fbf8 100644
--- a/src/main/java/com/android/tools/r8/graph/InnerClassAttribute.java
+++ b/src/main/java/com/android/tools/r8/graph/InnerClassAttribute.java
@@ -107,7 +107,7 @@
context = enclosingMethodAttribute.getEnclosingClass();
} else {
DexMethod enclosingMethod = enclosingMethodAttribute.getEnclosingMethod();
- if (!appView.appInfo().liveMethods.contains(enclosingMethod)) {
+ if (!appView.appInfo().isLiveMethod(enclosingMethod)) {
// EnclosingMethodAttribute will be pruned as it references the pruned method.
// Hence, the current InnerClassAttribute will be removed too. No live context.
return null;
diff --git a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
index bed6243..7e55643 100644
--- a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
+++ b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
@@ -117,7 +117,7 @@
* Set of methods that belong to live classes and can be reached by invokes. These need to be
* kept.
*/
- public final SortedSet<DexMethod> liveMethods;
+ private final Set<DexMethod> liveMethods;
/**
* Information about all fields that are accessed by the program. The information includes whether
* a given field is read/written by the program, and it also includes all indirect accesses to
@@ -211,7 +211,7 @@
Set<DexMethod> bootstrapMethods,
Set<DexMethod> methodsTargetedByInvokeDynamic,
Set<DexMethod> virtualMethodsTargetedByInvokeDirect,
- SortedSet<DexMethod> liveMethods,
+ Set<DexMethod> liveMethods,
FieldAccessInfoCollectionImpl fieldAccessInfoCollection,
MethodAccessInfoCollection methodAccessInfoCollection,
ObjectAllocationInfoCollectionImpl objectAllocationInfoCollection,
@@ -627,6 +627,10 @@
return clazz == null || !clazz.isProgramClass();
}
+ public boolean isLiveMethod(DexMethod method) {
+ return liveMethods.contains(method);
+ }
+
public boolean isTargetedMethod(DexMethod method) {
return targetedMethods.contains(method);
}
@@ -1041,7 +1045,7 @@
lens.rewriteMethods(bootstrapMethods),
lens.rewriteMethods(methodsTargetedByInvokeDynamic),
lens.rewriteMethods(virtualMethodsTargetedByInvokeDirect),
- lens.rewriteMethodsSorted(liveMethods),
+ lens.rewriteMethods(liveMethods),
fieldAccessInfoCollection.rewrittenWithLens(definitionSupplier, lens),
methodAccessInfoCollection.rewrittenWithLens(definitionSupplier, lens),
objectAllocationInfoCollection.rewrittenWithLens(definitionSupplier, lens),
diff --git a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
index 87ef664..0841cfb 100644
--- a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
+++ b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
@@ -3179,7 +3179,7 @@
Collections.unmodifiableSet(bootstrapMethods),
Collections.unmodifiableSet(methodsTargetedByInvokeDynamic),
Collections.unmodifiableSet(virtualMethodsTargetedByInvokeDirect),
- toSortedDescriptorSet(liveMethods.getItems()),
+ toDescriptorSet(liveMethods.getItems()),
// Filter out library fields and pinned fields, because these are read by default.
fieldAccessInfoCollection,
methodAccessInfoCollection.build(),
diff --git a/src/main/java/com/android/tools/r8/shaking/RootSetBuilder.java b/src/main/java/com/android/tools/r8/shaking/RootSetBuilder.java
index 8b623e3..7267bac 100644
--- a/src/main/java/com/android/tools/r8/shaking/RootSetBuilder.java
+++ b/src/main/java/com/android/tools/r8/shaking/RootSetBuilder.java
@@ -1975,7 +1975,7 @@
DexEncodedMethod method =
appInfo.definitionForHolder(reference).lookupMethod(reference);
if (!method.isAbstract() && isKeptDirectlyOrIndirectly(method.holder(), appInfo)) {
- assert appInfo.liveMethods.contains(reference)
+ assert appInfo.isLiveMethod(reference)
: "Expected non-abstract kept method `"
+ reference.toSourceString()
+ "` to be live";
diff --git a/src/main/java/com/android/tools/r8/shaking/TreePruner.java b/src/main/java/com/android/tools/r8/shaking/TreePruner.java
index 67680af..2c9d57a 100644
--- a/src/main/java/com/android/tools/r8/shaking/TreePruner.java
+++ b/src/main/java/com/android/tools/r8/shaking/TreePruner.java
@@ -249,8 +249,7 @@
private boolean isAttributeReferencingPrunedItem(EnclosingMethodAttribute attr) {
AppInfoWithLiveness appInfo = appView.appInfo();
return (attr.getEnclosingClass() != null && !isTypeLive(attr.getEnclosingClass()))
- || (attr.getEnclosingMethod() != null
- && !appInfo.liveMethods.contains(attr.getEnclosingMethod()));
+ || (attr.getEnclosingMethod() != null && !appInfo.isLiveMethod(attr.getEnclosingMethod()));
}
private boolean isAttributeReferencingMissingOrPrunedType(InnerClassAttribute attr) {
@@ -279,7 +278,7 @@
AppInfoWithLiveness appInfo = appView.appInfo();
InternalOptions options = appView.options();
int firstUnreachable =
- firstUnreachableIndex(methods, method -> appInfo.liveMethods.contains(method.method));
+ firstUnreachableIndex(methods, method -> appInfo.isLiveMethod(method.method));
// Return the original array if all methods are used.
if (firstUnreachable == -1) {
return null;
@@ -290,7 +289,7 @@
}
for (int i = firstUnreachable; i < methods.size(); i++) {
DexEncodedMethod method = methods.get(i);
- if (appInfo.liveMethods.contains(method.getReference())) {
+ if (appInfo.isLiveMethod(method.getReference())) {
reachableMethods.add(method);
} else if (options.configurationDebugging) {
// Keep the method but rewrite its body, if it has one.