Fix incorrect interface bit in call graph construction
This leads to incorrectly concluding that some calls do not resolve when member rebinding is disabled.
Bug: b/182129249
Change-Id: Id8b34380bad9905a4a6540263626c7204b0743d3
diff --git a/src/main/java/com/android/tools/r8/R8.java b/src/main/java/com/android/tools/r8/R8.java
index 087c305..98be063 100644
--- a/src/main/java/com/android/tools/r8/R8.java
+++ b/src/main/java/com/android/tools/r8/R8.java
@@ -508,7 +508,11 @@
appView.setGraphLens(
MemberRebindingIdentityLensFactory.create(appViewWithLiveness, executorService));
- new MemberRebindingAnalysis(appViewWithLiveness).run(executorService);
+ if (options.getTestingOptions().enableMemberRebindingAnalysis) {
+ new MemberRebindingAnalysis(appViewWithLiveness).run(executorService);
+ } else {
+ appViewWithLiveness.appInfo().getFieldAccessInfoCollection().flattenAccessContexts();
+ }
appViewWithLiveness.appInfo().notifyMemberRebindingFinished(appViewWithLiveness);
assert ArtProfileCompletenessChecker.verify(appView);
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/callgraph/InvokeExtractor.java b/src/main/java/com/android/tools/r8/ir/conversion/callgraph/InvokeExtractor.java
index c0705e4..62b4527 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/callgraph/InvokeExtractor.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/callgraph/InvokeExtractor.java
@@ -1,7 +1,6 @@
// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-
package com.android.tools.r8.ir.conversion.callgraph;
import static com.android.tools.r8.graph.DexClassAndMethod.asProgramMethodOrNull;
@@ -14,6 +13,7 @@
import com.android.tools.r8.graph.DexMethod;
import com.android.tools.r8.graph.LookupResult;
import com.android.tools.r8.graph.MethodResolutionResult;
+import com.android.tools.r8.graph.MethodResolutionResult.SingleResolutionResult;
import com.android.tools.r8.graph.ProgramMethod;
import com.android.tools.r8.graph.lens.MethodLookupResult;
import com.android.tools.r8.ir.code.InvokeType;
@@ -86,7 +86,7 @@
}
if (type.isInterface() || type.isVirtual()) {
// For virtual and interface calls add all potential targets that could be called.
- processInvokeWithDynamicDispatch(type, resolutionResult.getResolutionPair(), context);
+ processInvokeWithDynamicDispatch(type, resolutionResult.asSingleResolution(), context);
} else {
ProgramMethod singleTarget =
asProgramMethodOrNull(
@@ -113,9 +113,10 @@
}
protected void processInvokeWithDynamicDispatch(
- InvokeType type, DexClassAndMethod encodedTarget, ProgramMethod context) {
- DexMethod target = encodedTarget.getReference();
- DexClass clazz = encodedTarget.getHolder();
+ InvokeType type, SingleResolutionResult<?> resolutionResult, ProgramMethod context) {
+ DexClassAndMethod resolvedMethod = resolutionResult.getResolutionPair();
+ DexMethod target = resolvedMethod.getReference();
+ DexClass clazz = resolvedMethod.getHolder();
if (!appViewWithLiveness.options().testing.addCallEdgesForLibraryInvokes) {
if (clazz.isLibraryClass()) {
// Likely to have many possible targets.
@@ -123,16 +124,13 @@
}
}
- boolean isInterface = type == InvokeType.INTERFACE;
ProgramMethodSet possibleProgramTargets =
possibleProgramTargetsCache.computeIfAbsent(
target,
method -> {
- MethodResolutionResult resolution =
- appViewWithLiveness.appInfo().resolveMethodLegacy(method, isInterface);
- if (resolution.isVirtualTarget()) {
+ if (resolvedMethod.getDefinition().isVirtualMethod()) {
LookupResult lookupResult =
- resolution.lookupVirtualDispatchTargets(
+ resolutionResult.lookupVirtualDispatchTargets(
context.getHolder(), appViewWithLiveness);
if (lookupResult.isLookupResultSuccess()) {
ProgramMethodSet targets = ProgramMethodSet.create();
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/inliner/multicallerinliner/MultiCallerInlinerInvokeRegistry.java b/src/main/java/com/android/tools/r8/ir/optimize/inliner/multicallerinliner/MultiCallerInlinerInvokeRegistry.java
index 17413a4..eeb1448 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/inliner/multicallerinliner/MultiCallerInlinerInvokeRegistry.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/inliner/multicallerinliner/MultiCallerInlinerInvokeRegistry.java
@@ -9,6 +9,7 @@
import com.android.tools.r8.graph.AppView;
import com.android.tools.r8.graph.DexClassAndMethod;
import com.android.tools.r8.graph.DexMethod;
+import com.android.tools.r8.graph.MethodResolutionResult.SingleResolutionResult;
import com.android.tools.r8.graph.ProgramMethod;
import com.android.tools.r8.graph.lens.GraphLens;
import com.android.tools.r8.ir.code.InvokeType;
@@ -35,10 +36,11 @@
@Override
protected void processInvokeWithDynamicDispatch(
- InvokeType type, DexClassAndMethod resolutionResult, ProgramMethod context) {
+ InvokeType type, SingleResolutionResult<?> resolutionResult, ProgramMethod context) {
// Skip calls that dispatch to library methods or library method overrides.
- if (resolutionResult.isProgramMethod()
- && resolutionResult.getDefinition().isLibraryMethodOverride().isPossiblyFalse()) {
+ DexClassAndMethod resolvedMethod = resolutionResult.getResolutionPair();
+ if (resolvedMethod.isProgramMethod()
+ && resolvedMethod.getDefinition().isLibraryMethodOverride().isPossiblyFalse()) {
super.processInvokeWithDynamicDispatch(type, resolutionResult, context);
}
}
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 8bf530b..b7da0fc 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -2333,6 +2333,7 @@
public boolean enableInvokeSuperToInvokeVirtualRewriting = true;
public boolean enableLegacyClassDefOrdering =
System.getProperty("com.android.tools.r8.enableLegacyClassDefOrdering") != null;
+ public boolean enableMemberRebindingAnalysis = true;
public boolean enableMultiANewArrayDesugaringForClassFiles = false;
public boolean enableStrictFrameVerification = false;
public boolean enableSyntheticSharing = true;